blob: 37cd71cd114442e54db8ef204024bdb937582e97 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenosafbf30a2005-08-25 00:05:33 -05003 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
James Ketrenoscf1b4792005-10-20 16:35:24 -050036#define IPW2200_VERSION "git-1.0.8"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
James Ketrenos2b184d52005-08-03 20:33:14 -050038#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060039#define DRV_VERSION IPW2200_VERSION
40
James Ketrenosb095c382005-08-24 22:04:42 -050041#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
James Ketrenos43f66a62005-03-25 12:31:53 -060043MODULE_DESCRIPTION(DRV_DESCRIPTION);
44MODULE_VERSION(DRV_VERSION);
45MODULE_AUTHOR(DRV_COPYRIGHT);
46MODULE_LICENSE("GPL");
47
James Ketrenosf6c5cb72005-08-25 00:39:09 -050048static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060049static int debug = 0;
50static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060051static int mode = 0;
52
53static u32 ipw_debug_level;
54static int associate = 1;
55static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050056static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060057static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080058static int bt_coexist = 0;
James Ketrenosb095c382005-08-24 22:04:42 -050059static int hwcrypto = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060060static const char ipw_modes[] = {
61 'a', 'b', 'g', '?'
62};
63
James Ketrenosb095c382005-08-24 22:04:42 -050064#ifdef CONFIG_IPW_QOS
65static int qos_enable = 0;
66static int qos_burst_enable = 0;
67static int qos_no_ack_mask = 0;
68static int burst_duration_CCK = 0;
69static int burst_duration_OFDM = 0;
70
71static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
72 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
73 QOS_TX3_CW_MIN_OFDM},
74 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
75 QOS_TX3_CW_MAX_OFDM},
76 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
77 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
78 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
79 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
80};
81
82static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
83 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
84 QOS_TX3_CW_MIN_CCK},
85 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
86 QOS_TX3_CW_MAX_CCK},
87 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
88 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
89 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
90 QOS_TX3_TXOP_LIMIT_CCK}
91};
92
93static struct ieee80211_qos_parameters def_parameters_OFDM = {
94 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
95 DEF_TX3_CW_MIN_OFDM},
96 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
97 DEF_TX3_CW_MAX_OFDM},
98 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
99 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
100 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
101 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
102};
103
104static struct ieee80211_qos_parameters def_parameters_CCK = {
105 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
106 DEF_TX3_CW_MIN_CCK},
107 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
108 DEF_TX3_CW_MAX_CCK},
109 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
110 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
111 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
112 DEF_TX3_TXOP_LIMIT_CCK}
113};
114
115static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
116
117static int from_priority_to_tx_queue[] = {
118 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
119 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
120};
121
122static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
123
124static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
125 *qos_param);
126static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
127 *qos_param);
128#endif /* CONFIG_IPW_QOS */
129
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000130static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500131static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600132static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400133static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600134 struct clx2_tx_queue *txq, int qindex);
135static int ipw_queue_reset(struct ipw_priv *priv);
136
137static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
138 int len, int sync);
139
140static void ipw_tx_queue_free(struct ipw_priv *);
141
142static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
143static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
144static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600145static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500146static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600147static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500148static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600149static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400150static int init_supported_rates(struct ipw_priv *priv,
151 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500152static void ipw_set_hwcrypto_keys(struct ipw_priv *);
153static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600154
Liu Hong1fe0adb2005-08-19 09:33:10 -0500155static int ipw_is_valid_channel(struct ieee80211_device *, u8);
156static int ipw_channel_to_index(struct ieee80211_device *, u8);
157static u8 ipw_freq_to_channel(struct ieee80211_device *, u32);
158static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *);
159static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600160
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500161static int snprint_line(char *buf, size_t count,
162 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600163{
164 int out, i, j, l;
165 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400166
James Ketrenos43f66a62005-03-25 12:31:53 -0600167 out = snprintf(buf, count, "%08X", ofs);
168
169 for (l = 0, i = 0; i < 2; i++) {
170 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400171 for (j = 0; j < 8 && l < len; j++, l++)
172 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600173 data[(i * 8 + j)]);
174 for (; j < 8; j++)
175 out += snprintf(buf + out, count - out, " ");
176 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400177
James Ketrenos43f66a62005-03-25 12:31:53 -0600178 out += snprintf(buf + out, count - out, " ");
179 for (l = 0, i = 0; i < 2; i++) {
180 out += snprintf(buf + out, count - out, " ");
181 for (j = 0; j < 8 && l < len; j++, l++) {
182 c = data[(i * 8 + j)];
183 if (!isascii(c) || !isprint(c))
184 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400185
James Ketrenos43f66a62005-03-25 12:31:53 -0600186 out += snprintf(buf + out, count - out, "%c", c);
187 }
188
189 for (; j < 8; j++)
190 out += snprintf(buf + out, count - out, " ");
191 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400192
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500193 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600194}
195
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400196static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600197{
198 char line[81];
199 u32 ofs = 0;
200 if (!(ipw_debug_level & level))
201 return;
202
203 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500204 snprint_line(line, sizeof(line), &data[ofs],
205 min(len, 16U), ofs);
206 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600207 ofs += 16;
208 len -= min(len, 16U);
209 }
210}
211
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500212static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
213{
214 size_t out = size;
215 u32 ofs = 0;
216 int total = 0;
217
218 while (size && len) {
219 out = snprint_line(output, size, &data[ofs],
220 min_t(size_t, len, 16U), ofs);
221
222 ofs += 16;
223 output += out;
224 size -= out;
225 len -= min_t(size_t, len, 16U);
226 total += out;
227 }
228 return total;
229}
230
Zhu Yic8fe6672006-01-24 16:36:36 +0800231/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600232static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
233#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
234
Zhu Yic8fe6672006-01-24 16:36:36 +0800235/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600236static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
237#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
238
Zhu Yic8fe6672006-01-24 16:36:36 +0800239/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600240static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
241static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
242{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400243 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
244 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600245 _ipw_write_reg8(a, b, c);
246}
247
Zhu Yic8fe6672006-01-24 16:36:36 +0800248/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600249static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
250static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
251{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400252 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
253 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600254 _ipw_write_reg16(a, b, c);
255}
256
Zhu Yic8fe6672006-01-24 16:36:36 +0800257/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600258static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
259static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
260{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400261 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
262 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600263 _ipw_write_reg32(a, b, c);
264}
265
Zhu Yic8fe6672006-01-24 16:36:36 +0800266/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600267#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800268
269/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600270#define ipw_write8(ipw, ofs, val) \
271 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
272 _ipw_write8(ipw, ofs, val)
273
Zhu Yic8fe6672006-01-24 16:36:36 +0800274
275/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600276#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800277
278/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600279#define ipw_write16(ipw, ofs, val) \
280 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
281 _ipw_write16(ipw, ofs, val)
282
Zhu Yic8fe6672006-01-24 16:36:36 +0800283
284/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600285#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800286
287/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600288#define ipw_write32(ipw, ofs, val) \
289 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
290 _ipw_write32(ipw, ofs, val)
291
Zhu Yic8fe6672006-01-24 16:36:36 +0800292
293/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600294#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800295
296/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400297static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
298{
299 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600300 return _ipw_read8(ipw, ofs);
301}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400302
Zhu Yic8fe6672006-01-24 16:36:36 +0800303/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600304#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
305
Zhu Yic8fe6672006-01-24 16:36:36 +0800306
307/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600308#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800309
310/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400311static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
312{
313 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600314 return _ipw_read16(ipw, ofs);
315}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400316
Zhu Yic8fe6672006-01-24 16:36:36 +0800317/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600318#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
319
Zhu Yic8fe6672006-01-24 16:36:36 +0800320
321/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600322#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800323
324/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400325static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
326{
327 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600328 return _ipw_read32(ipw, ofs);
329}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400330
Zhu Yic8fe6672006-01-24 16:36:36 +0800331/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600332#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
333
Zhu Yic8fe6672006-01-24 16:36:36 +0800334
335/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600336static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500337static inline void __ipw_read_indirect(const char *f, int l,
338 struct ipw_priv *a, u32 b, u8 * c, int d)
339{
340 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
341 d);
342 _ipw_read_indirect(a, b, c, d);
343}
344
Zhu Yic8fe6672006-01-24 16:36:36 +0800345/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500346#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600347
Zhu Yic8fe6672006-01-24 16:36:36 +0800348/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400349static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
350 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600351#define ipw_write_indirect(a, b, c, d) \
352 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500353 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600354
Zhu Yic8fe6672006-01-24 16:36:36 +0800355/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400356static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600357{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400358 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500359 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
360 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600361}
362
Zhu Yic8fe6672006-01-24 16:36:36 +0800363/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600364static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
365{
Zhu Yic8fe6672006-01-24 16:36:36 +0800366 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
367 u32 dif_len = reg - aligned_addr;
368
James Ketrenos43f66a62005-03-25 12:31:53 -0600369 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800370 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
371 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600372}
373
Zhu Yic8fe6672006-01-24 16:36:36 +0800374/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400375static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600376{
Zhu Yic8fe6672006-01-24 16:36:36 +0800377 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
378 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
379
James Ketrenos43f66a62005-03-25 12:31:53 -0600380 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800381 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
382 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600383}
384
James Ketrenos43f66a62005-03-25 12:31:53 -0600385
Zhu Yic8fe6672006-01-24 16:36:36 +0800386/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600387static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
388{
389 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500390 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600391 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500392 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400393 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600394}
395
Zhu Yic8fe6672006-01-24 16:36:36 +0800396/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600397static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
398{
399 u32 value;
400
401 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
402
James Ketrenosb095c382005-08-24 22:04:42 -0500403 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
404 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600405 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
406 return value;
407}
408
Zhu Yic8fe6672006-01-24 16:36:36 +0800409/* General purpose, no alignment requirement, iterative (multi-byte) read, */
410/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600411static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
412 int num)
413{
Zhu Yic8fe6672006-01-24 16:36:36 +0800414 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600415 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600416 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400417
James Ketrenos43f66a62005-03-25 12:31:53 -0600418 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
419
James Ketrenosea2b26e2005-08-24 21:25:16 -0500420 if (num <= 0) {
421 return;
422 }
423
Zhu Yic8fe6672006-01-24 16:36:36 +0800424 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600425 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500426 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600427 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500428 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500429 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600430 aligned_addr += 4;
431 }
432
Zhu Yic8fe6672006-01-24 16:36:36 +0800433 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500434 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500435 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500436 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400437
Zhu Yic8fe6672006-01-24 16:36:36 +0800438 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500439 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500440 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500441 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500442 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500443 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600444}
445
Zhu Yic8fe6672006-01-24 16:36:36 +0800446/* General purpose, no alignment requirement, iterative (multi-byte) write, */
447/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400448static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 int num)
450{
Zhu Yic8fe6672006-01-24 16:36:36 +0800451 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600452 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600453 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400454
James Ketrenos43f66a62005-03-25 12:31:53 -0600455 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400456
James Ketrenosea2b26e2005-08-24 21:25:16 -0500457 if (num <= 0) {
458 return;
459 }
460
Zhu Yic8fe6672006-01-24 16:36:36 +0800461 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600462 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500463 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800464 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500465 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500466 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600467 aligned_addr += 4;
468 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400469
Zhu Yic8fe6672006-01-24 16:36:36 +0800470 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500471 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500472 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400474
Zhu Yic8fe6672006-01-24 16:36:36 +0800475 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500476 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500477 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500478 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500479 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500480 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600481}
482
Zhu Yic8fe6672006-01-24 16:36:36 +0800483/* General purpose, no alignment requirement, iterative (multi-byte) write, */
484/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400485static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 int num)
487{
488 memcpy_toio((priv->hw_base + addr), buf, num);
489}
490
Zhu Yic8fe6672006-01-24 16:36:36 +0800491/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600492static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
493{
494 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
495}
496
Zhu Yic8fe6672006-01-24 16:36:36 +0800497/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600498static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
499{
500 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
501}
502
503static inline void ipw_enable_interrupts(struct ipw_priv *priv)
504{
505 if (priv->status & STATUS_INT_ENABLED)
506 return;
507 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500508 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600509}
510
511static inline void ipw_disable_interrupts(struct ipw_priv *priv)
512{
513 if (!(priv->status & STATUS_INT_ENABLED))
514 return;
515 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500516 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600517}
518
Brice Goglin0f52bf92005-12-01 01:41:46 -0800519#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600520static char *ipw_error_desc(u32 val)
521{
522 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400523 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400525 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600526 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400527 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600528 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400529 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600530 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400531 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500532 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400533 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500534 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400535 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500536 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400537 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500538 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400539 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500540 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400541 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500542 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400543 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500544 return "DMA_STATUS";
545 case IPW_FW_ERROR_DINO_ERROR:
546 return "DINO_ERROR";
547 case IPW_FW_ERROR_EEPROM_ERROR:
548 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400549 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500550 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400551 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500552 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400553 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500554 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600555 }
556}
557
James Ketrenosb39860c2005-08-12 09:36:32 -0500558static void ipw_dump_error_log(struct ipw_priv *priv,
559 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600560{
James Ketrenosb39860c2005-08-12 09:36:32 -0500561 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600562
James Ketrenosb39860c2005-08-12 09:36:32 -0500563 if (!error) {
564 IPW_ERROR("Error allocating and capturing error log. "
565 "Nothing to dump.\n");
566 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600567 }
568
James Ketrenosb39860c2005-08-12 09:36:32 -0500569 IPW_ERROR("Start IPW Error Log Dump:\n");
570 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
571 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600572
James Ketrenosb39860c2005-08-12 09:36:32 -0500573 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400574 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500575 ipw_error_desc(error->elem[i].desc),
576 error->elem[i].time,
577 error->elem[i].blink1,
578 error->elem[i].blink2,
579 error->elem[i].link1,
580 error->elem[i].link2, error->elem[i].data);
581 for (i = 0; i < error->log_len; i++)
582 IPW_ERROR("%i\t0x%08x\t%i\n",
583 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500584 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600585}
James Ketrenos43f66a62005-03-25 12:31:53 -0600586#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600587
James Ketrenosc848d0a2005-08-24 21:56:24 -0500588static inline int ipw_is_init(struct ipw_priv *priv)
589{
590 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600591}
592
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400593static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600594{
595 u32 addr, field_info, field_len, field_count, total_len;
596
597 IPW_DEBUG_ORD("ordinal = %i\n", ord);
598
599 if (!priv || !val || !len) {
600 IPW_DEBUG_ORD("Invalid argument\n");
601 return -EINVAL;
602 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400603
James Ketrenos43f66a62005-03-25 12:31:53 -0600604 /* verify device ordinal tables have been initialized */
605 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
606 IPW_DEBUG_ORD("Access ordinals before initialization\n");
607 return -EINVAL;
608 }
609
610 switch (IPW_ORD_TABLE_ID_MASK & ord) {
611 case IPW_ORD_TABLE_0_MASK:
612 /*
613 * TABLE 0: Direct access to a table of 32 bit values
614 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400615 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600616 * read from the table
617 */
618
619 /* remove the table id from the ordinal */
620 ord &= IPW_ORD_TABLE_VALUE_MASK;
621
622 /* boundary check */
623 if (ord > priv->table0_len) {
624 IPW_DEBUG_ORD("ordinal value (%i) longer then "
625 "max (%i)\n", ord, priv->table0_len);
626 return -EINVAL;
627 }
628
629 /* verify we have enough room to store the value */
630 if (*len < sizeof(u32)) {
631 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200632 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600633 return -EINVAL;
634 }
635
636 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400637 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600638
639 *len = sizeof(u32);
640 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400641 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600642 break;
643
644 case IPW_ORD_TABLE_1_MASK:
645 /*
646 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400647 *
648 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600649 * representing starting addr for the data (which is
650 * also a u32)
651 */
652
653 /* remove the table id from the ordinal */
654 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400655
James Ketrenos43f66a62005-03-25 12:31:53 -0600656 /* boundary check */
657 if (ord > priv->table1_len) {
658 IPW_DEBUG_ORD("ordinal value too long\n");
659 return -EINVAL;
660 }
661
662 /* verify we have enough room to store the value */
663 if (*len < sizeof(u32)) {
664 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200665 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600666 return -EINVAL;
667 }
668
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400669 *((u32 *) val) =
670 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600671 *len = sizeof(u32);
672 break;
673
674 case IPW_ORD_TABLE_2_MASK:
675 /*
676 * TABLE 2: Indirect access to a table of variable sized values
677 *
678 * This table consist of six values, each containing
679 * - dword containing the starting offset of the data
680 * - dword containing the lengh in the first 16bits
681 * and the count in the second 16bits
682 */
683
684 /* remove the table id from the ordinal */
685 ord &= IPW_ORD_TABLE_VALUE_MASK;
686
687 /* boundary check */
688 if (ord > priv->table2_len) {
689 IPW_DEBUG_ORD("ordinal value too long\n");
690 return -EINVAL;
691 }
692
693 /* get the address of statistic */
694 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400695
696 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600697 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400698 field_info =
699 ipw_read_reg32(priv,
700 priv->table2_addr + (ord << 3) +
701 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400702
James Ketrenos43f66a62005-03-25 12:31:53 -0600703 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400704 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400705
James Ketrenos43f66a62005-03-25 12:31:53 -0600706 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400707 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400708
James Ketrenos43f66a62005-03-25 12:31:53 -0600709 /* abort if not enought memory */
710 total_len = field_len * field_count;
711 if (total_len > *len) {
712 *len = total_len;
713 return -EINVAL;
714 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400715
James Ketrenos43f66a62005-03-25 12:31:53 -0600716 *len = total_len;
717 if (!total_len)
718 return 0;
719
720 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400721 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600722 addr, total_len, field_info);
723 ipw_read_indirect(priv, addr, val, total_len);
724 break;
725
726 default:
727 IPW_DEBUG_ORD("Invalid ordinal!\n");
728 return -EINVAL;
729
730 }
731
James Ketrenos43f66a62005-03-25 12:31:53 -0600732 return 0;
733}
734
735static void ipw_init_ordinals(struct ipw_priv *priv)
736{
737 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400738 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600739
740 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
741 priv->table0_addr, priv->table0_len);
742
743 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
744 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
745
746 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
747 priv->table1_addr, priv->table1_len);
748
749 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
750 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400751 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600752
753 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
754 priv->table2_addr, priv->table2_len);
755
756}
757
Adrian Bunka73e22b2006-01-21 01:39:42 +0100758static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500759{
James Ketrenosb095c382005-08-24 22:04:42 -0500760 reg &= ~IPW_START_STANDBY;
761 if (reg & IPW_GATE_ODMA)
762 reg &= ~IPW_GATE_ODMA;
763 if (reg & IPW_GATE_IDMA)
764 reg &= ~IPW_GATE_IDMA;
765 if (reg & IPW_GATE_ADMA)
766 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500767 return reg;
768}
769
770/*
771 * LED behavior:
772 * - On radio ON, turn on any LEDs that require to be on during start
773 * - On initialization, start unassociated blink
774 * - On association, disable unassociated blink
775 * - On disassociation, start unassociated blink
776 * - On radio OFF, turn off any LEDs started during radio on
777 *
778 */
Zhu Yiede61112006-01-24 16:37:10 +0800779#define LD_TIME_LINK_ON msecs_to_jiffies(300)
780#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
781#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500782
Adrian Bunka73e22b2006-01-21 01:39:42 +0100783static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500784{
785 unsigned long flags;
786 u32 led;
787
788 /* If configured to not use LEDs, or nic_type is 1,
789 * then we don't toggle a LINK led */
790 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
791 return;
792
793 spin_lock_irqsave(&priv->lock, flags);
794
795 if (!(priv->status & STATUS_RF_KILL_MASK) &&
796 !(priv->status & STATUS_LED_LINK_ON)) {
797 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500798 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500799 led |= priv->led_association_on;
800
801 led = ipw_register_toggle(led);
802
803 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500804 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500805
806 priv->status |= STATUS_LED_LINK_ON;
807
808 /* If we aren't associated, schedule turning the LED off */
809 if (!(priv->status & STATUS_ASSOCIATED))
810 queue_delayed_work(priv->workqueue,
811 &priv->led_link_off,
812 LD_TIME_LINK_ON);
813 }
814
815 spin_unlock_irqrestore(&priv->lock, flags);
816}
817
James Ketrenosc848d0a2005-08-24 21:56:24 -0500818static void ipw_bg_led_link_on(void *data)
819{
820 struct ipw_priv *priv = data;
821 down(&priv->sem);
822 ipw_led_link_on(data);
823 up(&priv->sem);
824}
825
Adrian Bunka73e22b2006-01-21 01:39:42 +0100826static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500827{
828 unsigned long flags;
829 u32 led;
830
831 /* If configured not to use LEDs, or nic type is 1,
832 * then we don't goggle the LINK led. */
833 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
834 return;
835
836 spin_lock_irqsave(&priv->lock, flags);
837
838 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500839 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500840 led &= priv->led_association_off;
841 led = ipw_register_toggle(led);
842
843 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500844 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500845
846 IPW_DEBUG_LED("Link LED Off\n");
847
848 priv->status &= ~STATUS_LED_LINK_ON;
849
850 /* If we aren't associated and the radio is on, schedule
851 * turning the LED on (blink while unassociated) */
852 if (!(priv->status & STATUS_RF_KILL_MASK) &&
853 !(priv->status & STATUS_ASSOCIATED))
854 queue_delayed_work(priv->workqueue, &priv->led_link_on,
855 LD_TIME_LINK_OFF);
856
857 }
858
859 spin_unlock_irqrestore(&priv->lock, flags);
860}
861
James Ketrenosc848d0a2005-08-24 21:56:24 -0500862static void ipw_bg_led_link_off(void *data)
863{
864 struct ipw_priv *priv = data;
865 down(&priv->sem);
866 ipw_led_link_off(data);
867 up(&priv->sem);
868}
869
Arjan van de Ven858119e2006-01-14 13:20:43 -0800870static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500871{
James Ketrenosa613bff2005-08-24 21:43:11 -0500872 u32 led;
873
874 if (priv->config & CFG_NO_LED)
875 return;
876
James Ketrenosb095c382005-08-24 22:04:42 -0500877 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500878 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500879
880 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500881 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500882 led |= priv->led_activity_on;
883
884 led = ipw_register_toggle(led);
885
886 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500887 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500888
889 IPW_DEBUG_LED("Activity LED On\n");
890
891 priv->status |= STATUS_LED_ACT_ON;
892
James Ketrenosc848d0a2005-08-24 21:56:24 -0500893 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500894 queue_delayed_work(priv->workqueue, &priv->led_act_off,
895 LD_TIME_ACT_ON);
896 } else {
897 /* Reschedule LED off for full time period */
898 cancel_delayed_work(&priv->led_act_off);
899 queue_delayed_work(priv->workqueue, &priv->led_act_off,
900 LD_TIME_ACT_ON);
901 }
James Ketrenosb095c382005-08-24 22:04:42 -0500902}
James Ketrenosa613bff2005-08-24 21:43:11 -0500903
Adrian Bunka73e22b2006-01-21 01:39:42 +0100904#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500905void ipw_led_activity_on(struct ipw_priv *priv)
906{
907 unsigned long flags;
908 spin_lock_irqsave(&priv->lock, flags);
909 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500910 spin_unlock_irqrestore(&priv->lock, flags);
911}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100912#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500913
Adrian Bunka73e22b2006-01-21 01:39:42 +0100914static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500915{
916 unsigned long flags;
917 u32 led;
918
919 if (priv->config & CFG_NO_LED)
920 return;
921
922 spin_lock_irqsave(&priv->lock, flags);
923
924 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500925 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500926 led &= priv->led_activity_off;
927
928 led = ipw_register_toggle(led);
929
930 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500931 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500932
933 IPW_DEBUG_LED("Activity LED Off\n");
934
935 priv->status &= ~STATUS_LED_ACT_ON;
936 }
937
938 spin_unlock_irqrestore(&priv->lock, flags);
939}
940
James Ketrenosc848d0a2005-08-24 21:56:24 -0500941static void ipw_bg_led_activity_off(void *data)
942{
943 struct ipw_priv *priv = data;
944 down(&priv->sem);
945 ipw_led_activity_off(data);
946 up(&priv->sem);
947}
948
Adrian Bunka73e22b2006-01-21 01:39:42 +0100949static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500950{
951 unsigned long flags;
952 u32 led;
953
954 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500955 if (priv->config & CFG_NO_LED ||
956 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500957 return;
958
959 spin_lock_irqsave(&priv->lock, flags);
960
James Ketrenosb095c382005-08-24 22:04:42 -0500961 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500962 if (priv->assoc_network->mode == IEEE_A) {
963 led |= priv->led_ofdm_on;
964 led &= priv->led_association_off;
965 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
966 } else if (priv->assoc_network->mode == IEEE_G) {
967 led |= priv->led_ofdm_on;
968 led |= priv->led_association_on;
969 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
970 } else {
971 led &= priv->led_ofdm_off;
972 led |= priv->led_association_on;
973 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
974 }
975
976 led = ipw_register_toggle(led);
977
978 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500979 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500980
981 spin_unlock_irqrestore(&priv->lock, flags);
982}
983
Adrian Bunka73e22b2006-01-21 01:39:42 +0100984static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500985{
986 unsigned long flags;
987 u32 led;
988
989 /* Only nic type 1 supports mode LEDs */
990 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
991 return;
992
993 spin_lock_irqsave(&priv->lock, flags);
994
James Ketrenosb095c382005-08-24 22:04:42 -0500995 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500996 led &= priv->led_ofdm_off;
997 led &= priv->led_association_off;
998
999 led = ipw_register_toggle(led);
1000
1001 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001002 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001003
1004 spin_unlock_irqrestore(&priv->lock, flags);
1005}
1006
Adrian Bunka73e22b2006-01-21 01:39:42 +01001007static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001008{
1009 ipw_led_link_on(priv);
1010}
1011
Adrian Bunka73e22b2006-01-21 01:39:42 +01001012static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001013{
1014 ipw_led_activity_off(priv);
1015 ipw_led_link_off(priv);
1016}
1017
Adrian Bunka73e22b2006-01-21 01:39:42 +01001018static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001019{
1020 /* Set the Link Led on for all nic types */
1021 ipw_led_link_on(priv);
1022}
1023
Adrian Bunka73e22b2006-01-21 01:39:42 +01001024static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001025{
1026 ipw_led_activity_off(priv);
1027 ipw_led_link_off(priv);
1028
1029 if (priv->status & STATUS_RF_KILL_MASK)
1030 ipw_led_radio_off(priv);
1031}
1032
Adrian Bunka73e22b2006-01-21 01:39:42 +01001033static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001034{
1035 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1036
1037 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001038 priv->led_activity_on = IPW_ACTIVITY_LED;
1039 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001040
James Ketrenosb095c382005-08-24 22:04:42 -05001041 priv->led_association_on = IPW_ASSOCIATED_LED;
1042 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001043
1044 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001045 priv->led_ofdm_on = IPW_OFDM_LED;
1046 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001047
1048 switch (priv->nic_type) {
1049 case EEPROM_NIC_TYPE_1:
1050 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001051 priv->led_activity_on = IPW_ASSOCIATED_LED;
1052 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1053 priv->led_association_on = IPW_ACTIVITY_LED;
1054 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001055
1056 if (!(priv->config & CFG_NO_LED))
1057 ipw_led_band_on(priv);
1058
1059 /* And we don't blink link LEDs for this nic, so
1060 * just return here */
1061 return;
1062
1063 case EEPROM_NIC_TYPE_3:
1064 case EEPROM_NIC_TYPE_2:
1065 case EEPROM_NIC_TYPE_4:
1066 case EEPROM_NIC_TYPE_0:
1067 break;
1068
1069 default:
1070 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1071 priv->nic_type);
1072 priv->nic_type = EEPROM_NIC_TYPE_0;
1073 break;
1074 }
1075
1076 if (!(priv->config & CFG_NO_LED)) {
1077 if (priv->status & STATUS_ASSOCIATED)
1078 ipw_led_link_on(priv);
1079 else
1080 ipw_led_link_off(priv);
1081 }
1082}
1083
Adrian Bunka73e22b2006-01-21 01:39:42 +01001084static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001085{
James Ketrenosa613bff2005-08-24 21:43:11 -05001086 ipw_led_activity_off(priv);
1087 ipw_led_link_off(priv);
1088 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001089 cancel_delayed_work(&priv->led_link_on);
1090 cancel_delayed_work(&priv->led_link_off);
1091 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001092}
1093
James Ketrenos43f66a62005-03-25 12:31:53 -06001094/*
1095 * The following adds a new attribute to the sysfs representation
1096 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1097 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001098 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001099 * See the level definitions in ipw for details.
1100 */
1101static ssize_t show_debug_level(struct device_driver *d, char *buf)
1102{
1103 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1104}
James Ketrenosa613bff2005-08-24 21:43:11 -05001105
1106static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1107 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001108{
1109 char *p = (char *)buf;
1110 u32 val;
1111
1112 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1113 p++;
1114 if (p[0] == 'x' || p[0] == 'X')
1115 p++;
1116 val = simple_strtoul(p, &p, 16);
1117 } else
1118 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001119 if (p == buf)
1120 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001121 ": %s is not in hex or decimal form.\n", buf);
1122 else
1123 ipw_debug_level = val;
1124
1125 return strnlen(buf, count);
1126}
1127
Jeff Garzikbf794512005-07-31 13:07:26 -04001128static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001129 show_debug_level, store_debug_level);
1130
James Ketrenosb39860c2005-08-12 09:36:32 -05001131static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1132{
Zhu Yic8fe6672006-01-24 16:36:36 +08001133 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001134 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1135}
1136
1137static void ipw_capture_event_log(struct ipw_priv *priv,
1138 u32 log_len, struct ipw_event *log)
1139{
1140 u32 base;
1141
1142 if (log_len) {
1143 base = ipw_read32(priv, IPW_EVENT_LOG);
1144 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1145 (u8 *) log, sizeof(*log) * log_len);
1146 }
1147}
1148
1149static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1150{
1151 struct ipw_fw_error *error;
1152 u32 log_len = ipw_get_event_log_len(priv);
1153 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1154 u32 elem_len = ipw_read_reg32(priv, base);
1155
1156 error = kmalloc(sizeof(*error) +
1157 sizeof(*error->elem) * elem_len +
1158 sizeof(*error->log) * log_len, GFP_ATOMIC);
1159 if (!error) {
1160 IPW_ERROR("Memory allocation for firmware error log "
1161 "failed.\n");
1162 return NULL;
1163 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001164 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001165 error->status = priv->status;
1166 error->config = priv->config;
1167 error->elem_len = elem_len;
1168 error->log_len = log_len;
1169 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001170 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001171
1172 ipw_capture_event_log(priv, log_len, error->log);
1173
1174 if (elem_len)
1175 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1176 sizeof(*error->elem) * elem_len);
1177
1178 return error;
1179}
1180
1181static void ipw_free_error_log(struct ipw_fw_error *error)
1182{
1183 if (error)
1184 kfree(error);
1185}
1186
1187static ssize_t show_event_log(struct device *d,
1188 struct device_attribute *attr, char *buf)
1189{
1190 struct ipw_priv *priv = dev_get_drvdata(d);
1191 u32 log_len = ipw_get_event_log_len(priv);
1192 struct ipw_event log[log_len];
1193 u32 len = 0, i;
1194
1195 ipw_capture_event_log(priv, log_len, log);
1196
1197 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1198 for (i = 0; i < log_len; i++)
1199 len += snprintf(buf + len, PAGE_SIZE - len,
1200 "\n%08X%08X%08X",
1201 log[i].time, log[i].event, log[i].data);
1202 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1203 return len;
1204}
1205
1206static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1207
1208static ssize_t show_error(struct device *d,
1209 struct device_attribute *attr, char *buf)
1210{
1211 struct ipw_priv *priv = dev_get_drvdata(d);
1212 u32 len = 0, i;
1213 if (!priv->error)
1214 return 0;
1215 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001216 "%08lX%08X%08X%08X",
1217 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001218 priv->error->status,
1219 priv->error->config, priv->error->elem_len);
1220 for (i = 0; i < priv->error->elem_len; i++)
1221 len += snprintf(buf + len, PAGE_SIZE - len,
1222 "\n%08X%08X%08X%08X%08X%08X%08X",
1223 priv->error->elem[i].time,
1224 priv->error->elem[i].desc,
1225 priv->error->elem[i].blink1,
1226 priv->error->elem[i].blink2,
1227 priv->error->elem[i].link1,
1228 priv->error->elem[i].link2,
1229 priv->error->elem[i].data);
1230
1231 len += snprintf(buf + len, PAGE_SIZE - len,
1232 "\n%08X", priv->error->log_len);
1233 for (i = 0; i < priv->error->log_len; i++)
1234 len += snprintf(buf + len, PAGE_SIZE - len,
1235 "\n%08X%08X%08X",
1236 priv->error->log[i].time,
1237 priv->error->log[i].event,
1238 priv->error->log[i].data);
1239 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1240 return len;
1241}
1242
1243static ssize_t clear_error(struct device *d,
1244 struct device_attribute *attr,
1245 const char *buf, size_t count)
1246{
1247 struct ipw_priv *priv = dev_get_drvdata(d);
1248 if (priv->error) {
1249 ipw_free_error_log(priv->error);
1250 priv->error = NULL;
1251 }
1252 return count;
1253}
1254
1255static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1256
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001257static ssize_t show_cmd_log(struct device *d,
1258 struct device_attribute *attr, char *buf)
1259{
1260 struct ipw_priv *priv = dev_get_drvdata(d);
1261 u32 len = 0, i;
1262 if (!priv->cmdlog)
1263 return 0;
1264 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1265 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1266 i = (i + 1) % priv->cmdlog_len) {
1267 len +=
1268 snprintf(buf + len, PAGE_SIZE - len,
1269 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1270 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1271 priv->cmdlog[i].cmd.len);
1272 len +=
1273 snprintk_buf(buf + len, PAGE_SIZE - len,
1274 (u8 *) priv->cmdlog[i].cmd.param,
1275 priv->cmdlog[i].cmd.len);
1276 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1277 }
1278 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1279 return len;
1280}
1281
1282static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1283
James Ketrenosa613bff2005-08-24 21:43:11 -05001284static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1285 char *buf)
1286{
1287 struct ipw_priv *priv = dev_get_drvdata(d);
1288 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1289}
1290
1291static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1292 const char *buf, size_t count)
1293{
1294 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001295#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001296 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001297#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001298 char buffer[] = "00000000";
1299 unsigned long len =
1300 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1301 unsigned long val;
1302 char *p = buffer;
1303
1304 IPW_DEBUG_INFO("enter\n");
1305
1306 strncpy(buffer, buf, len);
1307 buffer[len] = 0;
1308
1309 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1310 p++;
1311 if (p[0] == 'x' || p[0] == 'X')
1312 p++;
1313 val = simple_strtoul(p, &p, 16);
1314 } else
1315 val = simple_strtoul(p, &p, 10);
1316 if (p == buffer) {
1317 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1318 } else {
1319 priv->ieee->scan_age = val;
1320 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1321 }
1322
1323 IPW_DEBUG_INFO("exit\n");
1324 return len;
1325}
1326
1327static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1328
1329static ssize_t show_led(struct device *d, struct device_attribute *attr,
1330 char *buf)
1331{
1332 struct ipw_priv *priv = dev_get_drvdata(d);
1333 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1334}
1335
1336static ssize_t store_led(struct device *d, struct device_attribute *attr,
1337 const char *buf, size_t count)
1338{
1339 struct ipw_priv *priv = dev_get_drvdata(d);
1340
1341 IPW_DEBUG_INFO("enter\n");
1342
1343 if (count == 0)
1344 return 0;
1345
1346 if (*buf == 0) {
1347 IPW_DEBUG_LED("Disabling LED control.\n");
1348 priv->config |= CFG_NO_LED;
1349 ipw_led_shutdown(priv);
1350 } else {
1351 IPW_DEBUG_LED("Enabling LED control.\n");
1352 priv->config &= ~CFG_NO_LED;
1353 ipw_led_init(priv);
1354 }
1355
1356 IPW_DEBUG_INFO("exit\n");
1357 return count;
1358}
1359
1360static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1361
Andrew Mortonad3fee52005-06-20 14:30:36 -07001362static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001363 struct device_attribute *attr, 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->status);
1367}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001368
James Ketrenos43f66a62005-03-25 12:31:53 -06001369static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1370
Andrew Mortonad3fee52005-06-20 14:30:36 -07001371static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1372 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001373{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001374 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001375 return sprintf(buf, "0x%08x\n", (int)p->config);
1376}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001377
James Ketrenos43f66a62005-03-25 12:31:53 -06001378static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1379
Andrew Mortonad3fee52005-06-20 14:30:36 -07001380static ssize_t show_nic_type(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{
James Ketrenosa613bff2005-08-24 21:43:11 -05001383 struct ipw_priv *priv = d->driver_data;
1384 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001385}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001386
James Ketrenos43f66a62005-03-25 12:31:53 -06001387static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1388
Andrew Mortonad3fee52005-06-20 14:30:36 -07001389static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001390 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001391{
1392 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001393 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001394
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001395 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001396 return 0;
1397
1398 return sprintf(buf, "0x%08x\n", tmp);
1399}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001400
1401static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001402
Andrew Mortonad3fee52005-06-20 14:30:36 -07001403static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1404 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001405{
1406 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001407 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001408
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001409 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001410 return 0;
1411
1412 return sprintf(buf, "0x%08x\n", tmp);
1413}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001414
1415static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001416
1417/*
1418 * Add a device attribute to view/control the delay between eeprom
1419 * operations.
1420 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001421static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001422 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001423{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001424 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001425 return sprintf(buf, "%i\n", n);
1426}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001427static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001428 struct device_attribute *attr,
1429 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001430{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001431 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001432 sscanf(buf, "%i", &p->eeprom_delay);
1433 return strnlen(buf, count);
1434}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001435
1436static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1437 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001438
Andrew Mortonad3fee52005-06-20 14:30:36 -07001439static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001440 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001441{
1442 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001443 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001444
James Ketrenosb095c382005-08-24 22:04:42 -05001445 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001446 return sprintf(buf, "0x%08x\n", reg);
1447}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001448static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001449 struct device_attribute *attr,
1450 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001451{
1452 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001453 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001454
1455 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001456 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001457 return strnlen(buf, count);
1458}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001459
1460static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1461 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001462
Andrew Mortonad3fee52005-06-20 14:30:36 -07001463static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001464 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001465{
1466 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001467 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001468
1469 reg = ipw_read_reg32(p, 0x301100);
1470 return sprintf(buf, "0x%08x\n", reg);
1471}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001472static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001473 struct device_attribute *attr,
1474 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001475{
1476 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001477 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001478
1479 sscanf(buf, "%x", &reg);
1480 ipw_write_reg32(p, 0x301100, reg);
1481 return strnlen(buf, count);
1482}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001483
1484static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1485 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001486
Andrew Mortonad3fee52005-06-20 14:30:36 -07001487static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001488 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001489{
1490 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001491 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001492
Jeff Garzikbf794512005-07-31 13:07:26 -04001493 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001494 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001495 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001496 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001497
James Ketrenos43f66a62005-03-25 12:31:53 -06001498 return sprintf(buf, "0x%08x\n", reg);
1499}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001500static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001501 struct device_attribute *attr,
1502 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001503{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001504 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001505
1506 sscanf(buf, "%x", &priv->indirect_dword);
1507 priv->status |= STATUS_INDIRECT_DWORD;
1508 return strnlen(buf, count);
1509}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001510
1511static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1512 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001513
Andrew Mortonad3fee52005-06-20 14:30:36 -07001514static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001515 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001516{
1517 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001518 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001519
Jeff Garzikbf794512005-07-31 13:07:26 -04001520 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001521 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001522 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001523 reg = 0;
1524
1525 return sprintf(buf, "0x%02x\n", reg);
1526}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001527static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001528 struct device_attribute *attr,
1529 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001530{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001531 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001532
1533 sscanf(buf, "%x", &priv->indirect_byte);
1534 priv->status |= STATUS_INDIRECT_BYTE;
1535 return strnlen(buf, count);
1536}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001537
1538static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001539 show_indirect_byte, store_indirect_byte);
1540
Andrew Mortonad3fee52005-06-20 14:30:36 -07001541static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001542 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001543{
1544 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001545 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001546
Jeff Garzikbf794512005-07-31 13:07:26 -04001547 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001548 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001549 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001550 reg = 0;
1551
1552 return sprintf(buf, "0x%08x\n", reg);
1553}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001554static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001555 struct device_attribute *attr,
1556 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001557{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001558 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001559
1560 sscanf(buf, "%x", &priv->direct_dword);
1561 priv->status |= STATUS_DIRECT_DWORD;
1562 return strnlen(buf, count);
1563}
James Ketrenos43f66a62005-03-25 12:31:53 -06001564
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1566 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001567
Arjan van de Ven858119e2006-01-14 13:20:43 -08001568static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001569{
1570 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1571 priv->status |= STATUS_RF_KILL_HW;
1572 else
1573 priv->status &= ~STATUS_RF_KILL_HW;
1574
1575 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1576}
1577
Andrew Mortonad3fee52005-06-20 14:30:36 -07001578static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001579 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001580{
1581 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001582 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001583 2 - HW based RF kill active
1584 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001585 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001586 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001587 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001588 return sprintf(buf, "%i\n", val);
1589}
1590
1591static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1592{
Jeff Garzikbf794512005-07-31 13:07:26 -04001593 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001594 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001595 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001596
1597 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1598 disable_radio ? "OFF" : "ON");
1599
1600 if (disable_radio) {
1601 priv->status |= STATUS_RF_KILL_SW;
1602
James Ketrenosa613bff2005-08-24 21:43:11 -05001603 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001604 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605 queue_work(priv->workqueue, &priv->down);
1606 } else {
1607 priv->status &= ~STATUS_RF_KILL_SW;
1608 if (rf_kill_active(priv)) {
1609 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1610 "disabled by HW switch\n");
1611 /* Make sure the RF_KILL check timer is running */
1612 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001613 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001614 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001615 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001616 queue_work(priv->workqueue, &priv->up);
1617 }
1618
1619 return 1;
1620}
1621
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001622static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1623 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001624{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001625 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001626
James Ketrenos43f66a62005-03-25 12:31:53 -06001627 ipw_radio_kill_sw(priv, buf[0] == '1');
1628
1629 return count;
1630}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631
1632static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001633
James Ketrenosb095c382005-08-24 22:04:42 -05001634static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1635 char *buf)
1636{
1637 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1638 int pos = 0, len = 0;
1639 if (priv->config & CFG_SPEED_SCAN) {
1640 while (priv->speed_scan[pos] != 0)
1641 len += sprintf(&buf[len], "%d ",
1642 priv->speed_scan[pos++]);
1643 return len + sprintf(&buf[len], "\n");
1644 }
1645
1646 return sprintf(buf, "0\n");
1647}
1648
1649static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1650 const char *buf, size_t count)
1651{
1652 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1653 int channel, pos = 0;
1654 const char *p = buf;
1655
1656 /* list of space separated channels to scan, optionally ending with 0 */
1657 while ((channel = simple_strtol(p, NULL, 0))) {
1658 if (pos == MAX_SPEED_SCAN - 1) {
1659 priv->speed_scan[pos] = 0;
1660 break;
1661 }
1662
Liu Hong1fe0adb2005-08-19 09:33:10 -05001663 if (ipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001664 priv->speed_scan[pos++] = channel;
1665 else
1666 IPW_WARNING("Skipping invalid channel request: %d\n",
1667 channel);
1668 p = strchr(p, ' ');
1669 if (!p)
1670 break;
1671 while (*p == ' ' || *p == '\t')
1672 p++;
1673 }
1674
1675 if (pos == 0)
1676 priv->config &= ~CFG_SPEED_SCAN;
1677 else {
1678 priv->speed_scan_pos = 0;
1679 priv->config |= CFG_SPEED_SCAN;
1680 }
1681
1682 return count;
1683}
1684
1685static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1686 store_speed_scan);
1687
1688static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1689 char *buf)
1690{
1691 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1692 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1693}
1694
1695static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1696 const char *buf, size_t count)
1697{
1698 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1699 if (buf[0] == '1')
1700 priv->config |= CFG_NET_STATS;
1701 else
1702 priv->config &= ~CFG_NET_STATS;
1703
1704 return count;
1705}
1706
James Ketrenosafbf30a2005-08-25 00:05:33 -05001707static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1708 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001709
James Ketrenosea2b26e2005-08-24 21:25:16 -05001710static void notify_wx_assoc_event(struct ipw_priv *priv)
1711{
1712 union iwreq_data wrqu;
1713 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1714 if (priv->status & STATUS_ASSOCIATED)
1715 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1716 else
1717 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1718 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1719}
1720
James Ketrenos43f66a62005-03-25 12:31:53 -06001721static void ipw_irq_tasklet(struct ipw_priv *priv)
1722{
1723 u32 inta, inta_mask, handled = 0;
1724 unsigned long flags;
1725 int rc = 0;
1726
1727 spin_lock_irqsave(&priv->lock, flags);
1728
James Ketrenosb095c382005-08-24 22:04:42 -05001729 inta = ipw_read32(priv, IPW_INTA_RW);
1730 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1731 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001732
1733 /* Add any cached INTA values that need to be handled */
1734 inta |= priv->isr_inta;
1735
1736 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001737 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001738 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001739 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 }
1741
James Ketrenosb095c382005-08-24 22:04:42 -05001742 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001743 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001744 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001745 priv->status &= ~STATUS_HCMD_ACTIVE;
1746 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001747 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 }
1749
James Ketrenosb095c382005-08-24 22:04:42 -05001750 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001751 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001752 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001753 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001754 }
1755
James Ketrenosb095c382005-08-24 22:04:42 -05001756 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001758 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001759 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 }
1761
James Ketrenosb095c382005-08-24 22:04:42 -05001762 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001763 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001764 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001765 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 }
1767
James Ketrenosb095c382005-08-24 22:04:42 -05001768 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001769 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001770 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001771 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001772 }
1773
James Ketrenosb095c382005-08-24 22:04:42 -05001774 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001775 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001776 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001777 }
1778
James Ketrenosb095c382005-08-24 22:04:42 -05001779 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001780 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001781 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001782 }
1783
James Ketrenosb095c382005-08-24 22:04:42 -05001784 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001785 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001786 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001787 }
1788
James Ketrenosb095c382005-08-24 22:04:42 -05001789 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001790 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001791 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001792 }
1793
James Ketrenosb095c382005-08-24 22:04:42 -05001794 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001795 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001796 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001797 }
1798
James Ketrenosb095c382005-08-24 22:04:42 -05001799 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001800 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1801 priv->status |= STATUS_RF_KILL_HW;
1802 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001803 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001804 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001805 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001806 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001807 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001808 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001809
James Ketrenosb095c382005-08-24 22:04:42 -05001810 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001811 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001812 if (priv->error) {
1813 IPW_ERROR("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001814#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001815 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1816 struct ipw_fw_error *error =
1817 ipw_alloc_error_log(priv);
1818 ipw_dump_error_log(priv, error);
1819 if (error)
1820 ipw_free_error_log(error);
1821 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001822#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001823 } else {
1824 priv->error = ipw_alloc_error_log(priv);
1825 if (priv->error)
1826 IPW_ERROR("Sysfs 'error' log captured.\n");
1827 else
1828 IPW_ERROR("Error allocating sysfs 'error' "
1829 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001830#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001831 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1832 ipw_dump_error_log(priv, priv->error);
1833#endif
1834 }
1835
James Ketrenosb095c382005-08-24 22:04:42 -05001836 /* XXX: If hardware encryption is for WPA/WPA2,
1837 * we have to notify the supplicant. */
1838 if (priv->ieee->sec.encrypt) {
1839 priv->status &= ~STATUS_ASSOCIATED;
1840 notify_wx_assoc_event(priv);
1841 }
1842
1843 /* Keep the restart process from trying to send host
1844 * commands by clearing the INIT status bit */
1845 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001846
1847 /* Cancel currently queued command. */
1848 priv->status &= ~STATUS_HCMD_ACTIVE;
1849 wake_up_interruptible(&priv->wait_command_queue);
1850
James Ketrenos43f66a62005-03-25 12:31:53 -06001851 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001852 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001853 }
1854
James Ketrenosb095c382005-08-24 22:04:42 -05001855 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001856 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001857 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001858 }
1859
1860 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001861 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001862 }
1863
1864 /* enable all interrupts */
1865 ipw_enable_interrupts(priv);
1866
1867 spin_unlock_irqrestore(&priv->lock, flags);
1868}
Jeff Garzikbf794512005-07-31 13:07:26 -04001869
James Ketrenos43f66a62005-03-25 12:31:53 -06001870#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1871static char *get_cmd_string(u8 cmd)
1872{
1873 switch (cmd) {
1874 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001875 IPW_CMD(POWER_DOWN);
1876 IPW_CMD(SYSTEM_CONFIG);
1877 IPW_CMD(MULTICAST_ADDRESS);
1878 IPW_CMD(SSID);
1879 IPW_CMD(ADAPTER_ADDRESS);
1880 IPW_CMD(PORT_TYPE);
1881 IPW_CMD(RTS_THRESHOLD);
1882 IPW_CMD(FRAG_THRESHOLD);
1883 IPW_CMD(POWER_MODE);
1884 IPW_CMD(WEP_KEY);
1885 IPW_CMD(TGI_TX_KEY);
1886 IPW_CMD(SCAN_REQUEST);
1887 IPW_CMD(SCAN_REQUEST_EXT);
1888 IPW_CMD(ASSOCIATE);
1889 IPW_CMD(SUPPORTED_RATES);
1890 IPW_CMD(SCAN_ABORT);
1891 IPW_CMD(TX_FLUSH);
1892 IPW_CMD(QOS_PARAMETERS);
1893 IPW_CMD(DINO_CONFIG);
1894 IPW_CMD(RSN_CAPABILITIES);
1895 IPW_CMD(RX_KEY);
1896 IPW_CMD(CARD_DISABLE);
1897 IPW_CMD(SEED_NUMBER);
1898 IPW_CMD(TX_POWER);
1899 IPW_CMD(COUNTRY_INFO);
1900 IPW_CMD(AIRONET_INFO);
1901 IPW_CMD(AP_TX_POWER);
1902 IPW_CMD(CCKM_INFO);
1903 IPW_CMD(CCX_VER_INFO);
1904 IPW_CMD(SET_CALIBRATION);
1905 IPW_CMD(SENSITIVITY_CALIB);
1906 IPW_CMD(RETRY_LIMIT);
1907 IPW_CMD(IPW_PRE_POWER_DOWN);
1908 IPW_CMD(VAP_BEACON_TEMPLATE);
1909 IPW_CMD(VAP_DTIM_PERIOD);
1910 IPW_CMD(EXT_SUPPORTED_RATES);
1911 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1912 IPW_CMD(VAP_QUIET_INTERVALS);
1913 IPW_CMD(VAP_CHANNEL_SWITCH);
1914 IPW_CMD(VAP_MANDATORY_CHANNELS);
1915 IPW_CMD(VAP_CELL_PWR_LIMIT);
1916 IPW_CMD(VAP_CF_PARAM_SET);
1917 IPW_CMD(VAP_SET_BEACONING_STATE);
1918 IPW_CMD(MEASUREMENT);
1919 IPW_CMD(POWER_CAPABILITY);
1920 IPW_CMD(SUPPORTED_CHANNELS);
1921 IPW_CMD(TPC_REPORT);
1922 IPW_CMD(WME_INFO);
1923 IPW_CMD(PRODUCTION_COMMAND);
1924 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001925 return "UNKNOWN";
1926 }
1927}
James Ketrenos43f66a62005-03-25 12:31:53 -06001928
1929#define HOST_COMPLETE_TIMEOUT HZ
1930static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1931{
1932 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001933 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001934
James Ketrenosa613bff2005-08-24 21:43:11 -05001935 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001936 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001937 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1938 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001939 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001940 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001941 }
1942
1943 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001944
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001945 if (priv->cmdlog) {
1946 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1947 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1948 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1949 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1950 cmd->len);
1951 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1952 }
1953
James Ketrenosb095c382005-08-24 22:04:42 -05001954 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1955 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1956 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08001957
1958#ifndef DEBUG_CMD_WEP_KEY
1959 if (cmd->cmd == IPW_CMD_WEP_KEY)
1960 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1961 else
1962#endif
1963 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1964
James Ketrenos43f66a62005-03-25 12:31:53 -06001965
1966 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001967 if (rc) {
1968 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001969 IPW_ERROR("Failed to send %s: Reason %d\n",
1970 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001971 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001972 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001973 }
1974 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001975
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001976 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1977 !(priv->
1978 status & STATUS_HCMD_ACTIVE),
1979 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001980 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001981 spin_lock_irqsave(&priv->lock, flags);
1982 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001983 IPW_ERROR("Failed to send %s: Command timed out.\n",
1984 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001985 priv->status &= ~STATUS_HCMD_ACTIVE;
1986 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001987 rc = -EIO;
1988 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001989 }
1990 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001991 } else
1992 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001993
James Ketrenosb095c382005-08-24 22:04:42 -05001994 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001995 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1996 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001997 rc = -EIO;
1998 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 }
2000
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002001 exit:
2002 if (priv->cmdlog) {
2003 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2004 priv->cmdlog_pos %= priv->cmdlog_len;
2005 }
2006 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002007}
2008
2009static int ipw_send_host_complete(struct ipw_priv *priv)
2010{
2011 struct host_cmd cmd = {
2012 .cmd = IPW_CMD_HOST_COMPLETE,
2013 .len = 0
2014 };
2015
2016 if (!priv) {
2017 IPW_ERROR("Invalid args\n");
2018 return -1;
2019 }
2020
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002021 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002022}
2023
Jeff Garzikbf794512005-07-31 13:07:26 -04002024static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002025 struct ipw_sys_config *config)
2026{
2027 struct host_cmd cmd = {
2028 .cmd = IPW_CMD_SYSTEM_CONFIG,
2029 .len = sizeof(*config)
2030 };
2031
2032 if (!priv || !config) {
2033 IPW_ERROR("Invalid args\n");
2034 return -1;
2035 }
2036
James Ketrenosafbf30a2005-08-25 00:05:33 -05002037 memcpy(cmd.param, config, sizeof(*config));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002038 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002039}
2040
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002041static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002042{
2043 struct host_cmd cmd = {
2044 .cmd = IPW_CMD_SSID,
2045 .len = min(len, IW_ESSID_MAX_SIZE)
2046 };
2047
2048 if (!priv || !ssid) {
2049 IPW_ERROR("Invalid args\n");
2050 return -1;
2051 }
2052
James Ketrenosafbf30a2005-08-25 00:05:33 -05002053 memcpy(cmd.param, ssid, cmd.len);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002054 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002055}
2056
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002057static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002058{
2059 struct host_cmd cmd = {
2060 .cmd = IPW_CMD_ADAPTER_ADDRESS,
2061 .len = ETH_ALEN
2062 };
2063
2064 if (!priv || !mac) {
2065 IPW_ERROR("Invalid args\n");
2066 return -1;
2067 }
2068
2069 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2070 priv->net_dev->name, MAC_ARG(mac));
2071
James Ketrenosafbf30a2005-08-25 00:05:33 -05002072 memcpy(cmd.param, mac, ETH_ALEN);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002073 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002074}
2075
James Ketrenosa613bff2005-08-24 21:43:11 -05002076/*
2077 * NOTE: This must be executed from our workqueue as it results in udelay
2078 * being called which may corrupt the keyboard if executed on default
2079 * workqueue
2080 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002081static void ipw_adapter_restart(void *adapter)
2082{
2083 struct ipw_priv *priv = adapter;
2084
2085 if (priv->status & STATUS_RF_KILL_MASK)
2086 return;
2087
2088 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002089
2090 if (priv->assoc_network &&
2091 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2092 ipw_remove_current_network(priv);
2093
James Ketrenos43f66a62005-03-25 12:31:53 -06002094 if (ipw_up(priv)) {
2095 IPW_ERROR("Failed to up device\n");
2096 return;
2097 }
2098}
2099
James Ketrenosc848d0a2005-08-24 21:56:24 -05002100static void ipw_bg_adapter_restart(void *data)
2101{
2102 struct ipw_priv *priv = data;
2103 down(&priv->sem);
2104 ipw_adapter_restart(data);
2105 up(&priv->sem);
2106}
2107
James Ketrenos43f66a62005-03-25 12:31:53 -06002108#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2109
2110static void ipw_scan_check(void *data)
2111{
2112 struct ipw_priv *priv = data;
2113 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2114 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002115 "adapter after (%dms).\n",
2116 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002117 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002118 }
2119}
2120
James Ketrenosc848d0a2005-08-24 21:56:24 -05002121static void ipw_bg_scan_check(void *data)
2122{
2123 struct ipw_priv *priv = data;
2124 down(&priv->sem);
2125 ipw_scan_check(data);
2126 up(&priv->sem);
2127}
2128
James Ketrenos43f66a62005-03-25 12:31:53 -06002129static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2130 struct ipw_scan_request_ext *request)
2131{
2132 struct host_cmd cmd = {
2133 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
2134 .len = sizeof(*request)
2135 };
2136
James Ketrenosafbf30a2005-08-25 00:05:33 -05002137 memcpy(cmd.param, request, sizeof(*request));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002138 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002139}
2140
2141static int ipw_send_scan_abort(struct ipw_priv *priv)
2142{
2143 struct host_cmd cmd = {
2144 .cmd = IPW_CMD_SCAN_ABORT,
2145 .len = 0
2146 };
2147
2148 if (!priv) {
2149 IPW_ERROR("Invalid args\n");
2150 return -1;
2151 }
2152
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002153 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002154}
2155
2156static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2157{
2158 struct host_cmd cmd = {
2159 .cmd = IPW_CMD_SENSITIVITY_CALIB,
2160 .len = sizeof(struct ipw_sensitivity_calib)
2161 };
2162 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002163 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002164 calib->beacon_rssi_raw = sens;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002165 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002166}
2167
2168static int ipw_send_associate(struct ipw_priv *priv,
2169 struct ipw_associate *associate)
2170{
2171 struct host_cmd cmd = {
2172 .cmd = IPW_CMD_ASSOCIATE,
2173 .len = sizeof(*associate)
2174 };
2175
James Ketrenosa613bff2005-08-24 21:43:11 -05002176 struct ipw_associate tmp_associate;
2177 memcpy(&tmp_associate, associate, sizeof(*associate));
2178 tmp_associate.policy_support =
2179 cpu_to_le16(tmp_associate.policy_support);
2180 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2181 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2182 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2183 tmp_associate.listen_interval =
2184 cpu_to_le16(tmp_associate.listen_interval);
2185 tmp_associate.beacon_interval =
2186 cpu_to_le16(tmp_associate.beacon_interval);
2187 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2188
James Ketrenos43f66a62005-03-25 12:31:53 -06002189 if (!priv || !associate) {
2190 IPW_ERROR("Invalid args\n");
2191 return -1;
2192 }
2193
James Ketrenosafbf30a2005-08-25 00:05:33 -05002194 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002195 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002196}
2197
2198static int ipw_send_supported_rates(struct ipw_priv *priv,
2199 struct ipw_supported_rates *rates)
2200{
2201 struct host_cmd cmd = {
2202 .cmd = IPW_CMD_SUPPORTED_RATES,
2203 .len = sizeof(*rates)
2204 };
2205
2206 if (!priv || !rates) {
2207 IPW_ERROR("Invalid args\n");
2208 return -1;
2209 }
2210
James Ketrenosafbf30a2005-08-25 00:05:33 -05002211 memcpy(cmd.param, rates, sizeof(*rates));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002212 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002213}
2214
2215static int ipw_set_random_seed(struct ipw_priv *priv)
2216{
2217 struct host_cmd cmd = {
2218 .cmd = IPW_CMD_SEED_NUMBER,
2219 .len = sizeof(u32)
2220 };
2221
2222 if (!priv) {
2223 IPW_ERROR("Invalid args\n");
2224 return -1;
2225 }
2226
2227 get_random_bytes(&cmd.param, sizeof(u32));
2228
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002229 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002230}
2231
James Ketrenos43f66a62005-03-25 12:31:53 -06002232static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2233{
2234 struct host_cmd cmd = {
2235 .cmd = IPW_CMD_CARD_DISABLE,
2236 .len = sizeof(u32)
2237 };
2238
2239 if (!priv) {
2240 IPW_ERROR("Invalid args\n");
2241 return -1;
2242 }
2243
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002244 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06002245
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002246 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002247}
James Ketrenos43f66a62005-03-25 12:31:53 -06002248
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002249static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002250{
2251 struct host_cmd cmd = {
2252 .cmd = IPW_CMD_TX_POWER,
2253 .len = sizeof(*power)
2254 };
2255
2256 if (!priv || !power) {
2257 IPW_ERROR("Invalid args\n");
2258 return -1;
2259 }
2260
James Ketrenosafbf30a2005-08-25 00:05:33 -05002261 memcpy(cmd.param, power, sizeof(*power));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002262 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002263}
James Ketrenos43f66a62005-03-25 12:31:53 -06002264
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002265static int ipw_set_tx_power(struct ipw_priv *priv)
2266{
Liu Hong1fe0adb2005-08-19 09:33:10 -05002267 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002268 struct ipw_tx_power tx_power;
2269 s8 max_power;
2270 int i;
2271
2272 memset(&tx_power, 0, sizeof(tx_power));
2273
2274 /* configure device for 'G' band */
2275 tx_power.ieee_mode = IPW_G_MODE;
2276 tx_power.num_channels = geo->bg_channels;
2277 for (i = 0; i < geo->bg_channels; i++) {
2278 max_power = geo->bg[i].max_power;
2279 tx_power.channels_tx_power[i].channel_number =
2280 geo->bg[i].channel;
2281 tx_power.channels_tx_power[i].tx_power = max_power ?
2282 min(max_power, priv->tx_power) : priv->tx_power;
2283 }
2284 if (ipw_send_tx_power(priv, &tx_power))
2285 return -EIO;
2286
2287 /* configure device to also handle 'B' band */
2288 tx_power.ieee_mode = IPW_B_MODE;
2289 if (ipw_send_tx_power(priv, &tx_power))
2290 return -EIO;
2291
2292 /* configure device to also handle 'A' band */
2293 if (priv->ieee->abg_true) {
2294 tx_power.ieee_mode = IPW_A_MODE;
2295 tx_power.num_channels = geo->a_channels;
2296 for (i = 0; i < tx_power.num_channels; i++) {
2297 max_power = geo->a[i].max_power;
2298 tx_power.channels_tx_power[i].channel_number =
2299 geo->a[i].channel;
2300 tx_power.channels_tx_power[i].tx_power = max_power ?
2301 min(max_power, priv->tx_power) : priv->tx_power;
2302 }
2303 if (ipw_send_tx_power(priv, &tx_power))
2304 return -EIO;
2305 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002306 return 0;
2307}
2308
2309static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2310{
2311 struct ipw_rts_threshold rts_threshold = {
2312 .rts_threshold = rts,
2313 };
2314 struct host_cmd cmd = {
2315 .cmd = IPW_CMD_RTS_THRESHOLD,
2316 .len = sizeof(rts_threshold)
2317 };
2318
2319 if (!priv) {
2320 IPW_ERROR("Invalid args\n");
2321 return -1;
2322 }
2323
James Ketrenosafbf30a2005-08-25 00:05:33 -05002324 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002325 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002326}
2327
2328static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2329{
2330 struct ipw_frag_threshold frag_threshold = {
2331 .frag_threshold = frag,
2332 };
2333 struct host_cmd cmd = {
2334 .cmd = IPW_CMD_FRAG_THRESHOLD,
2335 .len = sizeof(frag_threshold)
2336 };
2337
2338 if (!priv) {
2339 IPW_ERROR("Invalid args\n");
2340 return -1;
2341 }
2342
James Ketrenosafbf30a2005-08-25 00:05:33 -05002343 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002344 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002345}
2346
2347static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2348{
2349 struct host_cmd cmd = {
2350 .cmd = IPW_CMD_POWER_MODE,
2351 .len = sizeof(u32)
2352 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002353 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002354
2355 if (!priv) {
2356 IPW_ERROR("Invalid args\n");
2357 return -1;
2358 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002359
James Ketrenos43f66a62005-03-25 12:31:53 -06002360 /* If on battery, set to 3, if AC set to CAM, else user
2361 * level */
2362 switch (mode) {
2363 case IPW_POWER_BATTERY:
2364 *param = IPW_POWER_INDEX_3;
2365 break;
2366 case IPW_POWER_AC:
2367 *param = IPW_POWER_MODE_CAM;
2368 break;
2369 default:
2370 *param = mode;
2371 break;
2372 }
2373
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002374 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002375}
2376
James Ketrenosafbf30a2005-08-25 00:05:33 -05002377static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2378{
2379 struct ipw_retry_limit retry_limit = {
2380 .short_retry_limit = slimit,
2381 .long_retry_limit = llimit
2382 };
2383 struct host_cmd cmd = {
2384 .cmd = IPW_CMD_RETRY_LIMIT,
2385 .len = sizeof(retry_limit)
2386 };
2387
2388 if (!priv) {
2389 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002390 return -1;
2391 }
2392
James Ketrenosafbf30a2005-08-25 00:05:33 -05002393 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002394 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002395}
2396
2397/*
2398 * The IPW device contains a Microwire compatible EEPROM that stores
2399 * various data like the MAC address. Usually the firmware has exclusive
2400 * access to the eeprom, but during device initialization (before the
2401 * device driver has sent the HostComplete command to the firmware) the
2402 * device driver has read access to the EEPROM by way of indirect addressing
2403 * through a couple of memory mapped registers.
2404 *
2405 * The following is a simplified implementation for pulling data out of the
2406 * the eeprom, along with some helper functions to find information in
2407 * the per device private data's copy of the eeprom.
2408 *
2409 * NOTE: To better understand how these functions work (i.e what is a chip
2410 * select and why do have to keep driving the eeprom clock?), read
2411 * just about any data sheet for a Microwire compatible EEPROM.
2412 */
2413
2414/* write a 32 bit value into the indirect accessor register */
2415static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2416{
2417 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002418
James Ketrenos43f66a62005-03-25 12:31:53 -06002419 /* the eeprom requires some time to complete the operation */
2420 udelay(p->eeprom_delay);
2421
2422 return;
2423}
2424
2425/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002426static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002427{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002428 eeprom_write_reg(priv, 0);
2429 eeprom_write_reg(priv, EEPROM_BIT_CS);
2430 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2431 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002432}
2433
2434/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002435static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002436{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002437 eeprom_write_reg(priv, EEPROM_BIT_CS);
2438 eeprom_write_reg(priv, 0);
2439 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002440}
2441
2442/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002443static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002444{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002445 int d = (bit ? EEPROM_BIT_DI : 0);
2446 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2447 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002448}
2449
2450/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002451static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002452{
2453 int i;
2454
2455 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002456 eeprom_write_bit(priv, 1);
2457 eeprom_write_bit(priv, op & 2);
2458 eeprom_write_bit(priv, op & 1);
2459 for (i = 7; i >= 0; i--) {
2460 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 }
2462}
2463
2464/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002465static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002466{
2467 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002468 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002469
James Ketrenos43f66a62005-03-25 12:31:53 -06002470 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002471 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002472
2473 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002474 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002475
2476 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002477 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002478 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002479 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2480 eeprom_write_reg(priv, EEPROM_BIT_CS);
2481 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2482 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002483 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002484
James Ketrenos43f66a62005-03-25 12:31:53 -06002485 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002486 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002487 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002488
James Ketrenos43f66a62005-03-25 12:31:53 -06002489 return r;
2490}
2491
2492/* helper function for pulling the mac address out of the private */
2493/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002494static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002495{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002496 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002497}
2498
2499/*
2500 * Either the device driver (i.e. the host) or the firmware can
2501 * load eeprom data into the designated region in SRAM. If neither
2502 * happens then the FW will shutdown with a fatal error.
2503 *
2504 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2505 * bit needs region of shared SRAM needs to be non-zero.
2506 */
2507static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2508{
2509 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002510 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002511
James Ketrenos43f66a62005-03-25 12:31:53 -06002512 IPW_DEBUG_TRACE(">>\n");
2513
2514 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002515 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002516 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002517
Jeff Garzikbf794512005-07-31 13:07:26 -04002518 /*
2519 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002520 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002521 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002522 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2524 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2525
2526 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002527 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002528 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002529
2530 /* Do not load eeprom data on fatal error or suspend */
2531 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2532 } else {
2533 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2534
2535 /* Load eeprom data on fatal error or suspend */
2536 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2537 }
2538
2539 IPW_DEBUG_TRACE("<<\n");
2540}
2541
Arjan van de Ven858119e2006-01-14 13:20:43 -08002542static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002543{
2544 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002545 if (!count)
2546 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002547 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002548 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002549 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002550}
2551
2552static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2553{
James Ketrenosb095c382005-08-24 22:04:42 -05002554 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002555 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002556 sizeof(struct command_block));
2557}
2558
2559static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002560{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002561
2562 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002563
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 /* Start the dma */
2565 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002566
James Ketrenos43f66a62005-03-25 12:31:53 -06002567 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002568 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002569
2570 IPW_DEBUG_FW("<< : \n");
2571 return 0;
2572}
2573
2574static void ipw_fw_dma_abort(struct ipw_priv *priv)
2575{
2576 u32 control = 0;
2577
2578 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002579
2580 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002581 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002582 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002583 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002584
James Ketrenos43f66a62005-03-25 12:31:53 -06002585 IPW_DEBUG_FW("<< \n");
2586}
2587
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002588static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2589 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002590{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002591 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002592 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002593 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002594 IPW_DEBUG_FW(">> :\n");
2595
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002596 ipw_write_indirect(priv, address, (u8 *) cb,
2597 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002598
2599 IPW_DEBUG_FW("<< :\n");
2600 return 0;
2601
2602}
2603
2604static int ipw_fw_dma_kick(struct ipw_priv *priv)
2605{
2606 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002607 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002608
2609 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002610
James Ketrenos43f66a62005-03-25 12:31:53 -06002611 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 ipw_fw_dma_write_command_block(priv, index,
2613 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002614
2615 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002616 ipw_clear_bit(priv, IPW_RESET_REG,
2617 IPW_RESET_REG_MASTER_DISABLED |
2618 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002619
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002620 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002621 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002622 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002623
2624 IPW_DEBUG_FW("<< :\n");
2625 return 0;
2626}
2627
2628static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2629{
2630 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002631 u32 register_value = 0;
2632 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002633
2634 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002635 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002636 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002637
2638 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002639 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2640 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002641
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002642 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002643 cb_fields_address = address;
2644 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002645 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002646
2647 cb_fields_address += sizeof(u32);
2648 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002649 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002650
2651 cb_fields_address += sizeof(u32);
2652 register_value = ipw_read_reg32(priv, cb_fields_address);
2653 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2654 register_value);
2655
2656 cb_fields_address += sizeof(u32);
2657 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 IPW_DEBUG_FW(">> :\n");
2661}
2662
2663static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2664{
2665 u32 current_cb_address = 0;
2666 u32 current_cb_index = 0;
2667
2668 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002669 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002670
James Ketrenosb095c382005-08-24 22:04:42 -05002671 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002672 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002673
James Ketrenos43f66a62005-03-25 12:31:53 -06002674 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002675 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002676
2677 IPW_DEBUG_FW(">> :\n");
2678 return current_cb_index;
2679
2680}
2681
2682static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2683 u32 src_address,
2684 u32 dest_address,
2685 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002686 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002687{
2688
Jeff Garzikbf794512005-07-31 13:07:26 -04002689 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002690 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2691 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002692 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002693 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002694
2695 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2696 src_address, dest_address, length);
2697
2698 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2699 return -1;
2700
2701 last_cb_element = priv->sram_desc.last_cb_index;
2702 cb = &priv->sram_desc.cb_list[last_cb_element];
2703 priv->sram_desc.last_cb_index++;
2704
2705 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002706 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002707 control |= CB_INT_ENABLED;
2708
2709 if (is_last)
2710 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002711
James Ketrenos43f66a62005-03-25 12:31:53 -06002712 control |= length;
2713
2714 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002715 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002716
2717 /* Copy the Source and Destination addresses */
2718 cb->dest_addr = dest_address;
2719 cb->source_addr = src_address;
2720
2721 /* Copy the Control Word last */
2722 cb->control = control;
2723
2724 return 0;
2725}
2726
2727static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002728 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002729{
2730 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002731 u32 src_offset = 0;
2732 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002733 int status = 0;
2734 IPW_DEBUG_FW(">> \n");
2735 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2736 src_phys, dest_address, length);
2737 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002738 status = ipw_fw_dma_add_command_block(priv,
2739 src_phys + src_offset,
2740 dest_address +
2741 dest_offset,
2742 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002743 if (status) {
2744 IPW_DEBUG_FW_INFO(": Failed\n");
2745 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002746 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002747 IPW_DEBUG_FW_INFO(": Added new cb\n");
2748
2749 src_offset += CB_MAX_LENGTH;
2750 dest_offset += CB_MAX_LENGTH;
2751 bytes_left -= CB_MAX_LENGTH;
2752 }
2753
2754 /* add the buffer tail */
2755 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002756 status =
2757 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2758 dest_address + dest_offset,
2759 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002760 if (status) {
2761 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2762 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002763 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002764 IPW_DEBUG_FW_INFO
2765 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002766 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002767
James Ketrenos43f66a62005-03-25 12:31:53 -06002768 IPW_DEBUG_FW("<< \n");
2769 return 0;
2770}
2771
2772static int ipw_fw_dma_wait(struct ipw_priv *priv)
2773{
2774 u32 current_index = 0;
2775 u32 watchdog = 0;
2776
2777 IPW_DEBUG_FW(">> : \n");
2778
2779 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002780 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002781 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002782
2783 while (current_index < priv->sram_desc.last_cb_index) {
2784 udelay(50);
2785 current_index = ipw_fw_dma_command_block_index(priv);
2786
2787 watchdog++;
2788
2789 if (watchdog > 400) {
2790 IPW_DEBUG_FW_INFO("Timeout\n");
2791 ipw_fw_dma_dump_command_block(priv);
2792 ipw_fw_dma_abort(priv);
2793 return -1;
2794 }
2795 }
2796
2797 ipw_fw_dma_abort(priv);
2798
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002799 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002800 ipw_set_bit(priv, IPW_RESET_REG,
2801 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002802
2803 IPW_DEBUG_FW("<< dmaWaitSync \n");
2804 return 0;
2805}
2806
Jeff Garzikbf794512005-07-31 13:07:26 -04002807static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002808{
2809 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002810 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002811 unsigned long flags;
2812
2813 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002814 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2815 network = list_entry(element, struct ieee80211_network, list);
2816 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2817 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002818 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002819 &priv->ieee->network_free_list);
2820 }
2821 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002822 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002823}
2824
2825/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002826 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002827 * Reads debug register from domain0.
2828 * If card is present, pre-defined value should
2829 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002830 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002831 * @param priv
2832 * @return 1 if card is present, 0 otherwise
2833 */
2834static inline int ipw_alive(struct ipw_priv *priv)
2835{
2836 return ipw_read32(priv, 0x90) == 0xd55555d5;
2837}
2838
Zhu Yic7b6a672006-01-24 16:37:05 +08002839/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002840static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002841 int timeout)
2842{
2843 int i = 0;
2844
2845 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002846 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002847 return i;
2848 mdelay(10);
2849 i += 10;
2850 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002851
James Ketrenos43f66a62005-03-25 12:31:53 -06002852 return -ETIME;
2853}
2854
Jeff Garzikbf794512005-07-31 13:07:26 -04002855/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 * the ipw hardware. It assumes the buffer has all the bits for the
2857 * image and the caller is handling the memory allocation and clean up.
2858 */
2859
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002860static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002861{
2862 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002863
James Ketrenos43f66a62005-03-25 12:31:53 -06002864 IPW_DEBUG_TRACE(">> \n");
2865 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002866 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002867
Zhu Yic7b6a672006-01-24 16:37:05 +08002868 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002869 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2870 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002871 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002872 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002873 return -1;
2874 }
2875
2876 IPW_DEBUG_INFO("stop master %dms\n", rc);
2877
2878 return rc;
2879}
2880
2881static void ipw_arc_release(struct ipw_priv *priv)
2882{
2883 IPW_DEBUG_TRACE(">> \n");
2884 mdelay(5);
2885
James Ketrenosb095c382005-08-24 22:04:42 -05002886 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887
2888 /* no one knows timing, for safety add some delay */
2889 mdelay(5);
2890}
2891
2892struct fw_header {
2893 u32 version;
2894 u32 mode;
2895};
2896
2897struct fw_chunk {
2898 u32 address;
2899 u32 length;
2900};
2901
2902#define IPW_FW_MAJOR_VERSION 2
James Ketrenos817153762005-08-25 01:37:28 -05002903#define IPW_FW_MINOR_VERSION 4
James Ketrenos43f66a62005-03-25 12:31:53 -06002904
2905#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2906#define IPW_FW_MAJOR(x) (x & 0xff)
2907
James Ketrenosafbf30a2005-08-25 00:05:33 -05002908#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002909
2910#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2911"." __stringify(IPW_FW_MINOR_VERSION) "-"
2912
2913#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2914#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2915#else
2916#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2917#endif
2918
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002919static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002920{
2921 int rc = 0, i, addr;
2922 u8 cr = 0;
2923 u16 *image;
2924
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002925 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002926
James Ketrenos43f66a62005-03-25 12:31:53 -06002927 IPW_DEBUG_TRACE(">> \n");
2928
2929 rc = ipw_stop_master(priv);
2930
2931 if (rc < 0)
2932 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002933
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002934// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002935
James Ketrenosb095c382005-08-24 22:04:42 -05002936 for (addr = IPW_SHARED_LOWER_BOUND;
2937 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002938 ipw_write32(priv, addr, 0);
2939 }
2940
2941 /* no ucode (yet) */
2942 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2943 /* destroy DMA queues */
2944 /* reset sequence */
2945
James Ketrenosb095c382005-08-24 22:04:42 -05002946 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002947 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002948 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002949 mdelay(1);
2950
2951 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002952 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002953 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002954
James Ketrenosb095c382005-08-24 22:04:42 -05002955 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002956 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002957
James Ketrenos43f66a62005-03-25 12:31:53 -06002958 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002959 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2960 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002961 mdelay(1);
2962
2963 /* write ucode */
2964 /**
2965 * @bug
2966 * Do NOT set indirect address register once and then
2967 * store data to indirect data register in the loop.
2968 * It seems very reasonable, but in this case DINO do not
2969 * accept ucode. It is essential to set address each time.
2970 */
2971 /* load new ipw uCode */
2972 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002973 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002974 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002975
James Ketrenos43f66a62005-03-25 12:31:53 -06002976 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002977 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2978 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002979
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002980 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002981
2982 /* wait for alive response */
2983 for (i = 0; i < 100; i++) {
2984 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002985 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002986 if (cr & DINO_RXFIFO_DATA)
2987 break;
2988 mdelay(1);
2989 }
2990
2991 if (cr & DINO_RXFIFO_DATA) {
2992 /* alive_command_responce size is NOT multiple of 4 */
2993 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002994
2995 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002996 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002997 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002998 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002999 memcpy(&priv->dino_alive, response_buffer,
3000 sizeof(priv->dino_alive));
3001 if (priv->dino_alive.alive_command == 1
3002 && priv->dino_alive.ucode_valid == 1) {
3003 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003004 IPW_DEBUG_INFO
3005 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3006 "of %02d/%02d/%02d %02d:%02d\n",
3007 priv->dino_alive.software_revision,
3008 priv->dino_alive.software_revision,
3009 priv->dino_alive.device_identifier,
3010 priv->dino_alive.device_identifier,
3011 priv->dino_alive.time_stamp[0],
3012 priv->dino_alive.time_stamp[1],
3013 priv->dino_alive.time_stamp[2],
3014 priv->dino_alive.time_stamp[3],
3015 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003016 } else {
3017 IPW_DEBUG_INFO("Microcode is not alive\n");
3018 rc = -EINVAL;
3019 }
3020 } else {
3021 IPW_DEBUG_INFO("No alive response from DINO\n");
3022 rc = -ETIME;
3023 }
3024
3025 /* disable DINO, otherwise for some reason
3026 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003027 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003028
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003029// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003030
3031 return rc;
3032}
3033
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003034static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003035{
3036 int rc = -1;
3037 int offset = 0;
3038 struct fw_chunk *chunk;
3039 dma_addr_t shared_phys;
3040 u8 *shared_virt;
3041
3042 IPW_DEBUG_TRACE("<< : \n");
3043 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3044
3045 if (!shared_virt)
3046 return -ENOMEM;
3047
3048 memmove(shared_virt, data, len);
3049
3050 /* Start the Dma */
3051 rc = ipw_fw_dma_enable(priv);
3052
3053 if (priv->sram_desc.last_cb_index > 0) {
3054 /* the DMA is already ready this would be a bug. */
3055 BUG();
3056 goto out;
3057 }
3058
3059 do {
3060 chunk = (struct fw_chunk *)(data + offset);
3061 offset += sizeof(struct fw_chunk);
3062 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003063 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003064 * offeset*/
3065 /* Dma loading */
3066 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003067 le32_to_cpu(chunk->address),
3068 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003069 if (rc) {
3070 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3071 goto out;
3072 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003073
James Ketrenosa613bff2005-08-24 21:43:11 -05003074 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003075 } while (offset < len);
3076
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003077 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003078 rc = ipw_fw_dma_kick(priv);
3079 if (rc) {
3080 IPW_ERROR("dmaKick Failed\n");
3081 goto out;
3082 }
3083
3084 rc = ipw_fw_dma_wait(priv);
3085 if (rc) {
3086 IPW_ERROR("dmaWaitSync Failed\n");
3087 goto out;
3088 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003089 out:
3090 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003091 return rc;
3092}
3093
3094/* stop nic */
3095static int ipw_stop_nic(struct ipw_priv *priv)
3096{
3097 int rc = 0;
3098
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003099 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003100 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003101
James Ketrenosb095c382005-08-24 22:04:42 -05003102 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3103 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003104 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003105 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003106 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003107 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003108
James Ketrenosb095c382005-08-24 22:04:42 -05003109 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003110
James Ketrenos43f66a62005-03-25 12:31:53 -06003111 return rc;
3112}
3113
3114static void ipw_start_nic(struct ipw_priv *priv)
3115{
3116 IPW_DEBUG_TRACE(">>\n");
3117
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003118 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003119 ipw_clear_bit(priv, IPW_RESET_REG,
3120 IPW_RESET_REG_MASTER_DISABLED |
3121 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003122 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003123
James Ketrenos43f66a62005-03-25 12:31:53 -06003124 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003125 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3126 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003127
3128 IPW_DEBUG_TRACE("<<\n");
3129}
Jeff Garzikbf794512005-07-31 13:07:26 -04003130
James Ketrenos43f66a62005-03-25 12:31:53 -06003131static int ipw_init_nic(struct ipw_priv *priv)
3132{
3133 int rc;
3134
3135 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003136 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003137 /*prvHwInitNic */
3138 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003139 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003140
3141 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003142 ipw_write32(priv, IPW_READ_INT_REGISTER,
3143 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003144
3145 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003146 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3147 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003148 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003149 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3150
3151 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003152 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003153
3154 udelay(10);
3155
3156 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003157 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003158
3159 IPW_DEBUG_TRACE(">>\n");
3160 return 0;
3161}
3162
Jeff Garzikbf794512005-07-31 13:07:26 -04003163/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003164 * Probe is an ok place to call this from.
3165 */
3166static int ipw_reset_nic(struct ipw_priv *priv)
3167{
3168 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003169 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003170
3171 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003172
James Ketrenos43f66a62005-03-25 12:31:53 -06003173 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003174
James Ketrenosa613bff2005-08-24 21:43:11 -05003175 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003176 /* Clear the 'host command active' bit... */
3177 priv->status &= ~STATUS_HCMD_ACTIVE;
3178 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003179 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3180 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003181 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003182
3183 IPW_DEBUG_TRACE("<<\n");
3184 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003185}
James Ketrenos43f66a62005-03-25 12:31:53 -06003186
Jeff Garzikbf794512005-07-31 13:07:26 -04003187static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003188 const struct firmware **fw, const char *name)
3189{
3190 struct fw_header *header;
3191 int rc;
3192
3193 /* ask firmware_class module to get the boot firmware off disk */
3194 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3195 if (rc < 0) {
3196 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3197 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003198 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003199
3200 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003201 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003202 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3203 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003204 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3205 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003206 return -EINVAL;
3207 }
3208
Jiri Bencaaa4d302005-06-07 14:58:41 +02003209 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003210 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003211 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3212 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003213 (*fw)->size - sizeof(struct fw_header));
3214 return 0;
3215}
3216
James Ketrenosb095c382005-08-24 22:04:42 -05003217#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003218
Arjan van de Ven858119e2006-01-14 13:20:43 -08003219static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 struct ipw_rx_queue *rxq)
3221{
3222 unsigned long flags;
3223 int i;
3224
3225 spin_lock_irqsave(&rxq->lock, flags);
3226
3227 INIT_LIST_HEAD(&rxq->rx_free);
3228 INIT_LIST_HEAD(&rxq->rx_used);
3229
3230 /* Fill the rx_used queue with _all_ of the Rx buffers */
3231 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3232 /* In the reset function, these buffers may have been allocated
3233 * to an SKB, so we need to unmap and free potential storage */
3234 if (rxq->pool[i].skb != NULL) {
3235 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003236 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003237 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003238 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003239 }
3240 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3241 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003242
James Ketrenos43f66a62005-03-25 12:31:53 -06003243 /* Set us so that we have processed and used all buffers, but have
3244 * not restocked the Rx queue with fresh buffers */
3245 rxq->read = rxq->write = 0;
3246 rxq->processed = RX_QUEUE_SIZE - 1;
3247 rxq->free_count = 0;
3248 spin_unlock_irqrestore(&rxq->lock, flags);
3249}
3250
3251#ifdef CONFIG_PM
3252static int fw_loaded = 0;
3253static const struct firmware *bootfw = NULL;
3254static const struct firmware *firmware = NULL;
3255static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003256
3257static void free_firmware(void)
3258{
3259 if (fw_loaded) {
3260 release_firmware(bootfw);
3261 release_firmware(ucode);
3262 release_firmware(firmware);
3263 bootfw = ucode = firmware = NULL;
3264 fw_loaded = 0;
3265 }
3266}
3267#else
3268#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003269#endif
3270
3271static int ipw_load(struct ipw_priv *priv)
3272{
3273#ifndef CONFIG_PM
3274 const struct firmware *bootfw = NULL;
3275 const struct firmware *firmware = NULL;
3276 const struct firmware *ucode = NULL;
3277#endif
3278 int rc = 0, retries = 3;
3279
3280#ifdef CONFIG_PM
3281 if (!fw_loaded) {
3282#endif
3283 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003284 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003285 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003286
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 switch (priv->ieee->iw_mode) {
3288 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003289 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003290 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003291 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003292 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003293
James Ketrenos43f66a62005-03-25 12:31:53 -06003294 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3295 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003296
James Ketrenosb095c382005-08-24 22:04:42 -05003297#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003298 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003299 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003300 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003301 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003302 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003303
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003304 rc = ipw_get_fw(priv, &firmware,
3305 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003306 break;
3307#endif
3308 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003309 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003310 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003311 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003312
James Ketrenos43f66a62005-03-25 12:31:53 -06003313 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3314 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003315
James Ketrenos43f66a62005-03-25 12:31:53 -06003316 default:
3317 rc = -EINVAL;
3318 }
3319
Jeff Garzikbf794512005-07-31 13:07:26 -04003320 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003321 goto error;
3322
3323#ifdef CONFIG_PM
3324 fw_loaded = 1;
3325 }
3326#endif
3327
3328 if (!priv->rxq)
3329 priv->rxq = ipw_rx_queue_alloc(priv);
3330 else
3331 ipw_rx_queue_reset(priv, priv->rxq);
3332 if (!priv->rxq) {
3333 IPW_ERROR("Unable to initialize Rx queue\n");
3334 goto error;
3335 }
3336
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003337 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003338 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003339 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003340 priv->status &= ~STATUS_INT_ENABLED;
3341
3342 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003343 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003344
James Ketrenos43f66a62005-03-25 12:31:53 -06003345 ipw_stop_nic(priv);
3346
3347 rc = ipw_reset_nic(priv);
3348 if (rc) {
3349 IPW_ERROR("Unable to reset NIC\n");
3350 goto error;
3351 }
3352
James Ketrenosb095c382005-08-24 22:04:42 -05003353 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3354 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003355
3356 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003357 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003358 bootfw->size - sizeof(struct fw_header));
3359 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003360 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003361 goto error;
3362 }
3363
3364 /* kick start the device */
3365 ipw_start_nic(priv);
3366
Zhu Yic7b6a672006-01-24 16:37:05 +08003367 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003368 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3369 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003370 if (rc < 0) {
3371 IPW_ERROR("device failed to boot initial fw image\n");
3372 goto error;
3373 }
3374 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3375
Jeff Garzikbf794512005-07-31 13:07:26 -04003376 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003377 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003378
3379 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003380 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003381 ucode->size - sizeof(struct fw_header));
3382 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003383 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003384 goto error;
3385 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003386
James Ketrenos43f66a62005-03-25 12:31:53 -06003387 /* stop nic */
3388 ipw_stop_nic(priv);
3389
3390 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003391 rc = ipw_load_firmware(priv, firmware->data +
3392 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003393 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003394 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003395 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 goto error;
3397 }
3398
3399 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3400
3401 rc = ipw_queue_reset(priv);
3402 if (rc) {
3403 IPW_ERROR("Unable to initialize queues\n");
3404 goto error;
3405 }
3406
3407 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003408 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003409 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003410 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003411
James Ketrenos43f66a62005-03-25 12:31:53 -06003412 /* kick start the device */
3413 ipw_start_nic(priv);
3414
James Ketrenosb095c382005-08-24 22:04:42 -05003415 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003416 if (retries > 0) {
3417 IPW_WARNING("Parity error. Retrying init.\n");
3418 retries--;
3419 goto retry;
3420 }
3421
3422 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3423 rc = -EIO;
3424 goto error;
3425 }
3426
3427 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003428 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3429 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003430 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003431 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003432 goto error;
3433 }
3434 IPW_DEBUG_INFO("device response after %dms\n", rc);
3435
3436 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003437 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003438
3439 /* read eeprom data and initialize the eeprom region of sram */
3440 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003441 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003442
3443 /* enable interrupts */
3444 ipw_enable_interrupts(priv);
3445
3446 /* Ensure our queue has valid packets */
3447 ipw_rx_queue_replenish(priv);
3448
James Ketrenosb095c382005-08-24 22:04:42 -05003449 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003450
3451 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003452 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003453
3454#ifndef CONFIG_PM
3455 release_firmware(bootfw);
3456 release_firmware(ucode);
3457 release_firmware(firmware);
3458#endif
3459 return 0;
3460
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003461 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003462 if (priv->rxq) {
3463 ipw_rx_queue_free(priv, priv->rxq);
3464 priv->rxq = NULL;
3465 }
3466 ipw_tx_queue_free(priv);
3467 if (bootfw)
3468 release_firmware(bootfw);
3469 if (ucode)
3470 release_firmware(ucode);
3471 if (firmware)
3472 release_firmware(firmware);
3473#ifdef CONFIG_PM
3474 fw_loaded = 0;
3475 bootfw = ucode = firmware = NULL;
3476#endif
3477
3478 return rc;
3479}
3480
Jeff Garzikbf794512005-07-31 13:07:26 -04003481/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003482 * DMA services
3483 *
3484 * Theory of operation
3485 *
3486 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3487 * 2 empty entries always kept in the buffer to protect from overflow.
3488 *
3489 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003490 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3491 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003492 * Tx queue resumed.
3493 *
3494 * The IPW operates with six queues, one receive queue in the device's
3495 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003496 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003497 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003498 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003499 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003500 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003501 * we only utilize the first data transmit queue (queue1).
3502 */
3503
3504/**
3505 * Driver allocates buffers of this size for Rx
3506 */
3507
3508static inline int ipw_queue_space(const struct clx2_queue *q)
3509{
3510 int s = q->last_used - q->first_empty;
3511 if (s <= 0)
3512 s += q->n_bd;
3513 s -= 2; /* keep some reserve to not confuse empty and full situations */
3514 if (s < 0)
3515 s = 0;
3516 return s;
3517}
3518
3519static inline int ipw_queue_inc_wrap(int index, int n_bd)
3520{
3521 return (++index == n_bd) ? 0 : index;
3522}
3523
3524/**
3525 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003526 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003527 * @param q queue to init
3528 * @param count Number of BD's to allocate. Should be power of 2
3529 * @param read_register Address for 'read' register
3530 * (not offset within BAR, full address)
3531 * @param write_register Address for 'write' register
3532 * (not offset within BAR, full address)
3533 * @param base_register Address for 'base' register
3534 * (not offset within BAR, full address)
3535 * @param size Address for 'size' register
3536 * (not offset within BAR, full address)
3537 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003538static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003539 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003540{
3541 q->n_bd = count;
3542
3543 q->low_mark = q->n_bd / 4;
3544 if (q->low_mark < 4)
3545 q->low_mark = 4;
3546
3547 q->high_mark = q->n_bd / 8;
3548 if (q->high_mark < 2)
3549 q->high_mark = 2;
3550
3551 q->first_empty = q->last_used = 0;
3552 q->reg_r = read;
3553 q->reg_w = write;
3554
3555 ipw_write32(priv, base, q->dma_addr);
3556 ipw_write32(priv, size, count);
3557 ipw_write32(priv, read, 0);
3558 ipw_write32(priv, write, 0);
3559
3560 _ipw_read32(priv, 0x90);
3561}
3562
Jeff Garzikbf794512005-07-31 13:07:26 -04003563static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003564 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003565 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003566{
3567 struct pci_dev *dev = priv->pci_dev;
3568
3569 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3570 if (!q->txb) {
3571 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3572 return -ENOMEM;
3573 }
3574
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003575 q->bd =
3576 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003577 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003578 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003579 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003580 kfree(q->txb);
3581 q->txb = NULL;
3582 return -ENOMEM;
3583 }
3584
3585 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3586 return 0;
3587}
3588
3589/**
3590 * Free one TFD, those at index [txq->q.last_used].
3591 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003592 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003593 * @param dev
3594 * @param txq
3595 */
3596static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3597 struct clx2_tx_queue *txq)
3598{
3599 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3600 struct pci_dev *dev = priv->pci_dev;
3601 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003602
James Ketrenos43f66a62005-03-25 12:31:53 -06003603 /* classify bd */
3604 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3605 /* nothing to cleanup after for host commands */
3606 return;
3607
3608 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003609 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3610 IPW_ERROR("Too many chunks: %i\n",
3611 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003612 /** @todo issue fatal error, it is quite serious situation */
3613 return;
3614 }
3615
3616 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003617 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3618 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3619 le16_to_cpu(bd->u.data.chunk_len[i]),
3620 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003621 if (txq->txb[txq->q.last_used]) {
3622 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3623 txq->txb[txq->q.last_used] = NULL;
3624 }
3625 }
3626}
3627
3628/**
3629 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003630 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003631 * Empty queue by removing and destroying all BD's.
3632 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003633 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003634 * @param dev
3635 * @param q
3636 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003637static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003638{
3639 struct clx2_queue *q = &txq->q;
3640 struct pci_dev *dev = priv->pci_dev;
3641
Jeff Garzikbf794512005-07-31 13:07:26 -04003642 if (q->n_bd == 0)
3643 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003644
3645 /* first, empty all BD's */
3646 for (; q->first_empty != q->last_used;
3647 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3648 ipw_queue_tx_free_tfd(priv, txq);
3649 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003650
James Ketrenos43f66a62005-03-25 12:31:53 -06003651 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003652 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003653 q->dma_addr);
3654 kfree(txq->txb);
3655
3656 /* 0 fill whole structure */
3657 memset(txq, 0, sizeof(*txq));
3658}
3659
James Ketrenos43f66a62005-03-25 12:31:53 -06003660/**
3661 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003662 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003663 * @param priv
3664 */
3665static void ipw_tx_queue_free(struct ipw_priv *priv)
3666{
3667 /* Tx CMD queue */
3668 ipw_queue_tx_free(priv, &priv->txq_cmd);
3669
3670 /* Tx queues */
3671 ipw_queue_tx_free(priv, &priv->txq[0]);
3672 ipw_queue_tx_free(priv, &priv->txq[1]);
3673 ipw_queue_tx_free(priv, &priv->txq[2]);
3674 ipw_queue_tx_free(priv, &priv->txq[3]);
3675}
3676
Arjan van de Ven858119e2006-01-14 13:20:43 -08003677static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003678{
3679 /* First 3 bytes are manufacturer */
3680 bssid[0] = priv->mac_addr[0];
3681 bssid[1] = priv->mac_addr[1];
3682 bssid[2] = priv->mac_addr[2];
3683
3684 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003685 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003686
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003687 bssid[0] &= 0xfe; /* clear multicast bit */
3688 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003689}
3690
Arjan van de Ven858119e2006-01-14 13:20:43 -08003691static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003692{
3693 struct ipw_station_entry entry;
3694 int i;
3695
3696 for (i = 0; i < priv->num_stations; i++) {
3697 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3698 /* Another node is active in network */
3699 priv->missed_adhoc_beacons = 0;
3700 if (!(priv->config & CFG_STATIC_CHANNEL))
3701 /* when other nodes drop out, we drop out */
3702 priv->config &= ~CFG_ADHOC_PERSIST;
3703
3704 return i;
3705 }
3706 }
3707
3708 if (i == MAX_STATIONS)
3709 return IPW_INVALID_STATION;
3710
3711 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3712
3713 entry.reserved = 0;
3714 entry.support_mode = 0;
3715 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3716 memcpy(priv->stations[i], bssid, ETH_ALEN);
3717 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003718 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003719 priv->num_stations++;
3720
3721 return i;
3722}
3723
Arjan van de Ven858119e2006-01-14 13:20:43 -08003724static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003725{
3726 int i;
3727
Jeff Garzikbf794512005-07-31 13:07:26 -04003728 for (i = 0; i < priv->num_stations; i++)
3729 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003730 return i;
3731
3732 return IPW_INVALID_STATION;
3733}
3734
3735static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3736{
3737 int err;
3738
Hong Liu7b996592005-08-25 17:36:13 +08003739 if (priv->status & STATUS_ASSOCIATING) {
3740 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3741 queue_work(priv->workqueue, &priv->disassociate);
3742 return;
3743 }
3744
3745 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003746 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3747 return;
3748 }
3749
3750 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3751 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003752 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003753 priv->assoc_request.channel);
3754
3755 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3756 priv->status |= STATUS_DISASSOCIATING;
3757
3758 if (quiet)
3759 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3760 else
3761 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003762
James Ketrenos43f66a62005-03-25 12:31:53 -06003763 err = ipw_send_associate(priv, &priv->assoc_request);
3764 if (err) {
3765 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3766 "failed.\n");
3767 return;
3768 }
3769
3770}
3771
James Ketrenosc848d0a2005-08-24 21:56:24 -05003772static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003773{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003774 struct ipw_priv *priv = data;
3775 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3776 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003777 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003778 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003779}
3780
James Ketrenosc848d0a2005-08-24 21:56:24 -05003781static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003782{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003783 struct ipw_priv *priv = data;
3784 down(&priv->sem);
3785 ipw_disassociate(data);
3786 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003787}
3788
Zhu Yid8bad6d2005-07-13 12:25:38 -05003789static void ipw_system_config(void *data)
3790{
3791 struct ipw_priv *priv = data;
3792 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003793}
3794
3795struct ipw_status_code {
3796 u16 status;
3797 const char *reason;
3798};
3799
3800static const struct ipw_status_code ipw_status_codes[] = {
3801 {0x00, "Successful"},
3802 {0x01, "Unspecified failure"},
3803 {0x0A, "Cannot support all requested capabilities in the "
3804 "Capability information field"},
3805 {0x0B, "Reassociation denied due to inability to confirm that "
3806 "association exists"},
3807 {0x0C, "Association denied due to reason outside the scope of this "
3808 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003809 {0x0D,
3810 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003811 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003812 {0x0E,
3813 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003814 "transaction sequence number out of expected sequence"},
3815 {0x0F, "Authentication rejected because of challenge failure"},
3816 {0x10, "Authentication rejected due to timeout waiting for next "
3817 "frame in sequence"},
3818 {0x11, "Association denied because AP is unable to handle additional "
3819 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003820 {0x12,
3821 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003822 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003823 {0x13,
3824 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003825 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003826 {0x14,
3827 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003828 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003829 {0x15,
3830 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003831 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003832 {0x19,
3833 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003834 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003835 {0x1A,
3836 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003837 "DSSS-OFDM operation"},
3838 {0x28, "Invalid Information Element"},
3839 {0x29, "Group Cipher is not valid"},
3840 {0x2A, "Pairwise Cipher is not valid"},
3841 {0x2B, "AKMP is not valid"},
3842 {0x2C, "Unsupported RSN IE version"},
3843 {0x2D, "Invalid RSN IE Capabilities"},
3844 {0x2E, "Cipher suite is rejected per security policy"},
3845};
3846
Brice Goglin0f52bf92005-12-01 01:41:46 -08003847#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003848static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003849{
3850 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003851 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003852 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003853 return ipw_status_codes[i].reason;
3854 return "Unknown status value.";
3855}
3856#endif
3857
3858static void inline average_init(struct average *avg)
3859{
3860 memset(avg, 0, sizeof(*avg));
3861}
3862
Arjan van de Ven858119e2006-01-14 13:20:43 -08003863static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003864{
3865 avg->sum -= avg->entries[avg->pos];
3866 avg->sum += val;
3867 avg->entries[avg->pos++] = val;
3868 if (unlikely(avg->pos == AVG_ENTRIES)) {
3869 avg->init = 1;
3870 avg->pos = 0;
3871 }
3872}
3873
Arjan van de Ven858119e2006-01-14 13:20:43 -08003874static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003875{
3876 if (!unlikely(avg->init)) {
3877 if (avg->pos)
3878 return avg->sum / avg->pos;
3879 return 0;
3880 }
3881
3882 return avg->sum / AVG_ENTRIES;
3883}
3884
3885static void ipw_reset_stats(struct ipw_priv *priv)
3886{
3887 u32 len = sizeof(u32);
3888
3889 priv->quality = 0;
3890
3891 average_init(&priv->average_missed_beacons);
3892 average_init(&priv->average_rssi);
3893 average_init(&priv->average_noise);
3894
3895 priv->last_rate = 0;
3896 priv->last_missed_beacons = 0;
3897 priv->last_rx_packets = 0;
3898 priv->last_tx_packets = 0;
3899 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003900
James Ketrenos43f66a62005-03-25 12:31:53 -06003901 /* Firmware managed, reset only when NIC is restarted, so we have to
3902 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003903 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003904 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003905 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003906 &priv->last_tx_failures, &len);
3907
3908 /* Driver managed, reset with each association */
3909 priv->missed_adhoc_beacons = 0;
3910 priv->missed_beacons = 0;
3911 priv->tx_packets = 0;
3912 priv->rx_packets = 0;
3913
3914}
3915
Arjan van de Ven858119e2006-01-14 13:20:43 -08003916static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003917{
3918 u32 i = 0x80000000;
3919 u32 mask = priv->rates_mask;
3920 /* If currently associated in B mode, restrict the maximum
3921 * rate match to B rates */
3922 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3923 mask &= IEEE80211_CCK_RATES_MASK;
3924
3925 /* TODO: Verify that the rate is supported by the current rates
3926 * list. */
3927
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003928 while (i && !(mask & i))
3929 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003930 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003931 case IEEE80211_CCK_RATE_1MB_MASK:
3932 return 1000000;
3933 case IEEE80211_CCK_RATE_2MB_MASK:
3934 return 2000000;
3935 case IEEE80211_CCK_RATE_5MB_MASK:
3936 return 5500000;
3937 case IEEE80211_OFDM_RATE_6MB_MASK:
3938 return 6000000;
3939 case IEEE80211_OFDM_RATE_9MB_MASK:
3940 return 9000000;
3941 case IEEE80211_CCK_RATE_11MB_MASK:
3942 return 11000000;
3943 case IEEE80211_OFDM_RATE_12MB_MASK:
3944 return 12000000;
3945 case IEEE80211_OFDM_RATE_18MB_MASK:
3946 return 18000000;
3947 case IEEE80211_OFDM_RATE_24MB_MASK:
3948 return 24000000;
3949 case IEEE80211_OFDM_RATE_36MB_MASK:
3950 return 36000000;
3951 case IEEE80211_OFDM_RATE_48MB_MASK:
3952 return 48000000;
3953 case IEEE80211_OFDM_RATE_54MB_MASK:
3954 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003955 }
3956
Jeff Garzikbf794512005-07-31 13:07:26 -04003957 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003958 return 11000000;
3959 else
3960 return 54000000;
3961}
3962
3963static u32 ipw_get_current_rate(struct ipw_priv *priv)
3964{
3965 u32 rate, len = sizeof(rate);
3966 int err;
3967
Jeff Garzikbf794512005-07-31 13:07:26 -04003968 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003969 return 0;
3970
3971 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003972 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003973 &len);
3974 if (err) {
3975 IPW_DEBUG_INFO("failed querying ordinals.\n");
3976 return 0;
3977 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003978 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 return ipw_get_max_rate(priv);
3980
3981 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003982 case IPW_TX_RATE_1MB:
3983 return 1000000;
3984 case IPW_TX_RATE_2MB:
3985 return 2000000;
3986 case IPW_TX_RATE_5MB:
3987 return 5500000;
3988 case IPW_TX_RATE_6MB:
3989 return 6000000;
3990 case IPW_TX_RATE_9MB:
3991 return 9000000;
3992 case IPW_TX_RATE_11MB:
3993 return 11000000;
3994 case IPW_TX_RATE_12MB:
3995 return 12000000;
3996 case IPW_TX_RATE_18MB:
3997 return 18000000;
3998 case IPW_TX_RATE_24MB:
3999 return 24000000;
4000 case IPW_TX_RATE_36MB:
4001 return 36000000;
4002 case IPW_TX_RATE_48MB:
4003 return 48000000;
4004 case IPW_TX_RATE_54MB:
4005 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004006 }
4007
4008 return 0;
4009}
4010
James Ketrenos43f66a62005-03-25 12:31:53 -06004011#define IPW_STATS_INTERVAL (2 * HZ)
4012static void ipw_gather_stats(struct ipw_priv *priv)
4013{
4014 u32 rx_err, rx_err_delta, rx_packets_delta;
4015 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4016 u32 missed_beacons_percent, missed_beacons_delta;
4017 u32 quality = 0;
4018 u32 len = sizeof(u32);
4019 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004020 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004021 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004022 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004023
4024 if (!(priv->status & STATUS_ASSOCIATED)) {
4025 priv->quality = 0;
4026 return;
4027 }
4028
4029 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004030 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004031 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004032 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004033 priv->last_missed_beacons = priv->missed_beacons;
4034 if (priv->assoc_request.beacon_interval) {
4035 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004036 (HZ * priv->assoc_request.beacon_interval) /
4037 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004038 } else {
4039 missed_beacons_percent = 0;
4040 }
4041 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4042
4043 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4044 rx_err_delta = rx_err - priv->last_rx_err;
4045 priv->last_rx_err = rx_err;
4046
4047 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4048 tx_failures_delta = tx_failures - priv->last_tx_failures;
4049 priv->last_tx_failures = tx_failures;
4050
4051 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4052 priv->last_rx_packets = priv->rx_packets;
4053
4054 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4055 priv->last_tx_packets = priv->tx_packets;
4056
4057 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004058 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004059 * Missed beacon: 100% = 0, 0% = 70% missed
4060 * Rate: 60% = 1Mbs, 100% = Max
4061 * Rx and Tx errors represent a straight % of total Rx/Tx
4062 * RSSI: 100% = > -50, 0% = < -80
4063 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004064 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004065 * The lowest computed quality is used.
4066 *
4067 */
4068#define BEACON_THRESHOLD 5
4069 beacon_quality = 100 - missed_beacons_percent;
4070 if (beacon_quality < BEACON_THRESHOLD)
4071 beacon_quality = 0;
4072 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004073 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004074 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004075 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004076 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004077
James Ketrenos43f66a62005-03-25 12:31:53 -06004078 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004079 max_rate = ipw_get_max_rate(priv);
4080 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004081 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4082 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004083
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004084 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004085 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004086 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004087 else
4088 rx_quality = 100;
4089 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4090 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004091
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004092 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004093 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004094 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004095 else
4096 tx_quality = 100;
4097 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4098 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004099
James Ketrenos43f66a62005-03-25 12:31:53 -06004100 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004101 signal_quality =
4102 (100 *
4103 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4104 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4105 (priv->ieee->perfect_rssi - rssi) *
4106 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4107 62 * (priv->ieee->perfect_rssi - rssi))) /
4108 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4109 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4110 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004111 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004112 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004113 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004114
James Ketrenos43f66a62005-03-25 12:31:53 -06004115 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4116 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004117
4118 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004119 min(rate_quality,
4120 min(tx_quality, min(rx_quality, signal_quality))));
4121 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004122 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4123 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004124 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004125 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4126 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004127 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004128 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4129 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004130 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004131 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4132 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004133 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004134 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4135 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004136
4137 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004138
4139 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004140 IPW_STATS_INTERVAL);
4141}
4142
James Ketrenosc848d0a2005-08-24 21:56:24 -05004143static void ipw_bg_gather_stats(void *data)
4144{
4145 struct ipw_priv *priv = data;
4146 down(&priv->sem);
4147 ipw_gather_stats(data);
4148 up(&priv->sem);
4149}
4150
Ben Cahille7582562005-10-06 15:34:41 -05004151/* Missed beacon behavior:
4152 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4153 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4154 * Above disassociate threshold, give up and stop scanning.
4155 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004156static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 int missed_count)
4158{
4159 priv->notif_missed_beacons = missed_count;
4160
James Ketrenosafbf30a2005-08-25 00:05:33 -05004161 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004162 priv->status & STATUS_ASSOCIATED) {
4163 /* If associated and we've hit the missed
4164 * beacon threshold, disassociate, turn
4165 * off roaming, and abort any active scans */
4166 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004167 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004168 "Missed beacon: %d - disassociate\n", missed_count);
4169 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004170 if (priv->status & STATUS_SCANNING) {
4171 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4172 IPW_DL_STATE,
4173 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004174 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004175 }
4176
James Ketrenosea2b26e2005-08-24 21:25:16 -05004177 queue_work(priv->workqueue, &priv->disassociate);
4178 return;
4179 }
4180
4181 if (priv->status & STATUS_ROAMING) {
4182 /* If we are currently roaming, then just
4183 * print a debug statement... */
4184 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4185 "Missed beacon: %d - roam in progress\n",
4186 missed_count);
4187 return;
4188 }
4189
Ben Cahille7582562005-10-06 15:34:41 -05004190 if (missed_count > priv->roaming_threshold &&
4191 missed_count <= priv->disassociate_threshold) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004192 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004193 * bit in the status and kick off a scan.
4194 * This can happen several times before we reach
4195 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004196 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4197 "Missed beacon: %d - initiate "
4198 "roaming\n", missed_count);
4199 if (!(priv->status & STATUS_ROAMING)) {
4200 priv->status |= STATUS_ROAMING;
4201 if (!(priv->status & STATUS_SCANNING))
4202 queue_work(priv->workqueue,
4203 &priv->request_scan);
4204 }
4205 return;
4206 }
4207
4208 if (priv->status & STATUS_SCANNING) {
4209 /* Stop scan to keep fw from getting
4210 * stuck (only if we aren't roaming --
4211 * otherwise we'll never scan more than 2 or 3
4212 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004213 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4214 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004215 queue_work(priv->workqueue, &priv->abort_scan);
4216 }
4217
4218 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4219
4220}
4221
James Ketrenos43f66a62005-03-25 12:31:53 -06004222/**
4223 * Handle host notification packet.
4224 * Called from interrupt routine
4225 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004226static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004227 struct ipw_rx_notification *notif)
4228{
James Ketrenosa613bff2005-08-24 21:43:11 -05004229 notif->size = le16_to_cpu(notif->size);
4230
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004231 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004232
James Ketrenos43f66a62005-03-25 12:31:53 -06004233 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004234 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4235 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004236
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004237 switch (assoc->state) {
4238 case CMAS_ASSOCIATED:{
4239 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4240 IPW_DL_ASSOC,
4241 "associated: '%s' " MAC_FMT
4242 " \n",
4243 escape_essid(priv->essid,
4244 priv->essid_len),
4245 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004246
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004247 switch (priv->ieee->iw_mode) {
4248 case IW_MODE_INFRA:
4249 memcpy(priv->ieee->bssid,
4250 priv->bssid, ETH_ALEN);
4251 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004252
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004253 case IW_MODE_ADHOC:
4254 memcpy(priv->ieee->bssid,
4255 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004256
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004257 /* clear out the station table */
4258 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004259
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004260 IPW_DEBUG_ASSOC
4261 ("queueing adhoc check\n");
4262 queue_delayed_work(priv->
4263 workqueue,
4264 &priv->
4265 adhoc_check,
4266 priv->
4267 assoc_request.
4268 beacon_interval);
4269 break;
4270 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004271
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004272 priv->status &= ~STATUS_ASSOCIATING;
4273 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004274 queue_work(priv->workqueue,
4275 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004276
James Ketrenosb095c382005-08-24 22:04:42 -05004277#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004278#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4279 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4280 if ((priv->status & STATUS_AUTH) &&
4281 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4282 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004283 if ((sizeof
4284 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004285 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004286 <= notif->size)
4287 && (notif->size <= 2314)) {
4288 struct
4289 ieee80211_rx_stats
4290 stats = {
4291 .len =
4292 notif->
4293 size - 1,
4294 };
4295
4296 IPW_DEBUG_QOS
4297 ("QoS Associate "
4298 "size %d\n",
4299 notif->size);
4300 ieee80211_rx_mgt(priv->
4301 ieee,
4302 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004303 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004304 *)
4305 &notif->u.raw, &stats);
4306 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004307 }
James Ketrenosb095c382005-08-24 22:04:42 -05004308#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004309
James Ketrenosa613bff2005-08-24 21:43:11 -05004310 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004311
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004312 break;
4313 }
4314
4315 case CMAS_AUTHENTICATED:{
4316 if (priv->
4317 status & (STATUS_ASSOCIATED |
4318 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004319#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004320 struct notif_authenticate *auth
4321 = &notif->u.auth;
4322 IPW_DEBUG(IPW_DL_NOTIF |
4323 IPW_DL_STATE |
4324 IPW_DL_ASSOC,
4325 "deauthenticated: '%s' "
4326 MAC_FMT
4327 ": (0x%04X) - %s \n",
4328 escape_essid(priv->
4329 essid,
4330 priv->
4331 essid_len),
4332 MAC_ARG(priv->bssid),
4333 ntohs(auth->status),
4334 ipw_get_status_code
4335 (ntohs
4336 (auth->status)));
4337#endif
4338
4339 priv->status &=
4340 ~(STATUS_ASSOCIATING |
4341 STATUS_AUTH |
4342 STATUS_ASSOCIATED);
4343
James Ketrenosa613bff2005-08-24 21:43:11 -05004344 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004345 break;
4346 }
4347
4348 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4349 IPW_DL_ASSOC,
4350 "authenticated: '%s' " MAC_FMT
4351 "\n",
4352 escape_essid(priv->essid,
4353 priv->essid_len),
4354 MAC_ARG(priv->bssid));
4355 break;
4356 }
4357
4358 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004359 if (priv->status & STATUS_AUTH) {
4360 struct
4361 ieee80211_assoc_response
4362 *resp;
4363 resp =
4364 (struct
4365 ieee80211_assoc_response
4366 *)&notif->u.raw;
4367 IPW_DEBUG(IPW_DL_NOTIF |
4368 IPW_DL_STATE |
4369 IPW_DL_ASSOC,
4370 "association failed (0x%04X): %s\n",
4371 ntohs(resp->status),
4372 ipw_get_status_code
4373 (ntohs
4374 (resp->status)));
4375 }
4376
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004377 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4378 IPW_DL_ASSOC,
4379 "disassociated: '%s' " MAC_FMT
4380 " \n",
4381 escape_essid(priv->essid,
4382 priv->essid_len),
4383 MAC_ARG(priv->bssid));
4384
4385 priv->status &=
4386 ~(STATUS_DISASSOCIATING |
4387 STATUS_ASSOCIATING |
4388 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004389 if (priv->assoc_network
4390 && (priv->assoc_network->
4391 capability &
4392 WLAN_CAPABILITY_IBSS))
4393 ipw_remove_current_network
4394 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004395
James Ketrenosa613bff2005-08-24 21:43:11 -05004396 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004397
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004398 break;
4399 }
4400
James Ketrenosb095c382005-08-24 22:04:42 -05004401 case CMAS_RX_ASSOC_RESP:
4402 break;
4403
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004404 default:
4405 IPW_ERROR("assoc: unknown (%d)\n",
4406 assoc->state);
4407 break;
4408 }
4409
James Ketrenos43f66a62005-03-25 12:31:53 -06004410 break;
4411 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004412
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004413 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4414 struct notif_authenticate *auth = &notif->u.auth;
4415 switch (auth->state) {
4416 case CMAS_AUTHENTICATED:
4417 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4418 "authenticated: '%s' " MAC_FMT " \n",
4419 escape_essid(priv->essid,
4420 priv->essid_len),
4421 MAC_ARG(priv->bssid));
4422 priv->status |= STATUS_AUTH;
4423 break;
4424
4425 case CMAS_INIT:
4426 if (priv->status & STATUS_AUTH) {
4427 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4428 IPW_DL_ASSOC,
4429 "authentication failed (0x%04X): %s\n",
4430 ntohs(auth->status),
4431 ipw_get_status_code(ntohs
4432 (auth->
4433 status)));
4434 }
4435 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4436 IPW_DL_ASSOC,
4437 "deauthenticated: '%s' " MAC_FMT "\n",
4438 escape_essid(priv->essid,
4439 priv->essid_len),
4440 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004441
4442 priv->status &= ~(STATUS_ASSOCIATING |
4443 STATUS_AUTH |
4444 STATUS_ASSOCIATED);
4445
James Ketrenosa613bff2005-08-24 21:43:11 -05004446 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004447 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004448
4449 case CMAS_TX_AUTH_SEQ_1:
4450 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4451 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4452 break;
4453 case CMAS_RX_AUTH_SEQ_2:
4454 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4455 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4456 break;
4457 case CMAS_AUTH_SEQ_1_PASS:
4458 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4459 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4460 break;
4461 case CMAS_AUTH_SEQ_1_FAIL:
4462 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4463 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4464 break;
4465 case CMAS_TX_AUTH_SEQ_3:
4466 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4467 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4468 break;
4469 case CMAS_RX_AUTH_SEQ_4:
4470 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4471 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4472 break;
4473 case CMAS_AUTH_SEQ_2_PASS:
4474 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4475 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4476 break;
4477 case CMAS_AUTH_SEQ_2_FAIL:
4478 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4479 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4480 break;
4481 case CMAS_TX_ASSOC:
4482 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4483 IPW_DL_ASSOC, "TX_ASSOC\n");
4484 break;
4485 case CMAS_RX_ASSOC_RESP:
4486 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4487 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004488
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004489 break;
4490 case CMAS_ASSOCIATED:
4491 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4492 IPW_DL_ASSOC, "ASSOCIATED\n");
4493 break;
4494 default:
4495 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4496 auth->state);
4497 break;
4498 }
4499 break;
4500 }
4501
4502 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4503 struct notif_channel_result *x =
4504 &notif->u.channel_result;
4505
4506 if (notif->size == sizeof(*x)) {
4507 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4508 x->channel_num);
4509 } else {
4510 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4511 "(should be %zd)\n",
4512 notif->size, sizeof(*x));
4513 }
4514 break;
4515 }
4516
4517 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4518 struct notif_scan_complete *x = &notif->u.scan_complete;
4519 if (notif->size == sizeof(*x)) {
4520 IPW_DEBUG_SCAN
4521 ("Scan completed: type %d, %d channels, "
4522 "%d status\n", x->scan_type,
4523 x->num_channels, x->status);
4524 } else {
4525 IPW_ERROR("Scan completed of wrong size %d "
4526 "(should be %zd)\n",
4527 notif->size, sizeof(*x));
4528 }
4529
4530 priv->status &=
4531 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4532
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004533 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004534 cancel_delayed_work(&priv->scan_check);
4535
James Ketrenosb095c382005-08-24 22:04:42 -05004536 if (priv->status & STATUS_EXIT_PENDING)
4537 break;
4538
4539 priv->ieee->scans++;
4540
4541#ifdef CONFIG_IPW2200_MONITOR
4542 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004543 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004544 queue_work(priv->workqueue,
4545 &priv->request_scan);
4546 break;
4547 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004548 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004549#endif /* CONFIG_IPW2200_MONITOR */
4550
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004551 if (!(priv->status & (STATUS_ASSOCIATED |
4552 STATUS_ASSOCIATING |
4553 STATUS_ROAMING |
4554 STATUS_DISASSOCIATING)))
4555 queue_work(priv->workqueue, &priv->associate);
4556 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004557 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4558 /* If a scan completed and we are in roam mode, then
4559 * the scan that completed was the one requested as a
4560 * result of entering roam... so, schedule the
4561 * roam work */
4562 queue_work(priv->workqueue,
4563 &priv->roam);
4564 else
4565 /* Don't schedule if we aborted the scan */
4566 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004567 } else if (priv->status & STATUS_SCAN_PENDING)
4568 queue_work(priv->workqueue,
4569 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004570 else if (priv->config & CFG_BACKGROUND_SCAN
4571 && priv->status & STATUS_ASSOCIATED)
4572 queue_delayed_work(priv->workqueue,
4573 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004574 break;
4575 }
4576
4577 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4578 struct notif_frag_length *x = &notif->u.frag_len;
4579
James Ketrenosa613bff2005-08-24 21:43:11 -05004580 if (notif->size == sizeof(*x))
4581 IPW_ERROR("Frag length: %d\n",
4582 le16_to_cpu(x->frag_length));
4583 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584 IPW_ERROR("Frag length of wrong size %d "
4585 "(should be %zd)\n",
4586 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004587 break;
4588 }
4589
4590 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4591 struct notif_link_deterioration *x =
4592 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004593
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004594 if (notif->size == sizeof(*x)) {
4595 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4596 "link deterioration: '%s' " MAC_FMT
4597 " \n", escape_essid(priv->essid,
4598 priv->essid_len),
4599 MAC_ARG(priv->bssid));
4600 memcpy(&priv->last_link_deterioration, x,
4601 sizeof(*x));
4602 } else {
4603 IPW_ERROR("Link Deterioration of wrong size %d "
4604 "(should be %zd)\n",
4605 notif->size, sizeof(*x));
4606 }
4607 break;
4608 }
4609
4610 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4611 IPW_ERROR("Dino config\n");
4612 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004613 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004615
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004616 break;
4617 }
4618
4619 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4620 struct notif_beacon_state *x = &notif->u.beacon_state;
4621 if (notif->size != sizeof(*x)) {
4622 IPW_ERROR
4623 ("Beacon state of wrong size %d (should "
4624 "be %zd)\n", notif->size, sizeof(*x));
4625 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004626 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004627
James Ketrenosa613bff2005-08-24 21:43:11 -05004628 if (le32_to_cpu(x->state) ==
4629 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4630 ipw_handle_missed_beacon(priv,
4631 le32_to_cpu(x->
4632 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004633
James Ketrenos43f66a62005-03-25 12:31:53 -06004634 break;
4635 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004636
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004637 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4638 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4639 if (notif->size == sizeof(*x)) {
4640 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4641 "0x%02x station %d\n",
4642 x->key_state, x->security_type,
4643 x->station_index);
4644 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004645 }
4646
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004647 IPW_ERROR
4648 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4649 notif->size, sizeof(*x));
4650 break;
4651 }
4652
4653 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4654 struct notif_calibration *x = &notif->u.calibration;
4655
4656 if (notif->size == sizeof(*x)) {
4657 memcpy(&priv->calib, x, sizeof(*x));
4658 IPW_DEBUG_INFO("TODO: Calibration\n");
4659 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004660 }
4661
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004662 IPW_ERROR
4663 ("Calibration of wrong size %d (should be %zd)\n",
4664 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004665 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004666 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004667
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004668 case HOST_NOTIFICATION_NOISE_STATS:{
4669 if (notif->size == sizeof(u32)) {
4670 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004671 (u8) (le32_to_cpu(notif->u.noise.value) &
4672 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004673 average_add(&priv->average_noise,
4674 priv->last_noise);
4675 break;
4676 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004678 IPW_ERROR
4679 ("Noise stat is wrong size %d (should be %zd)\n",
4680 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004681 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004682 }
4683
James Ketrenos43f66a62005-03-25 12:31:53 -06004684 default:
4685 IPW_ERROR("Unknown notification: "
4686 "subtype=%d,flags=0x%2x,size=%d\n",
4687 notif->subtype, notif->flags, notif->size);
4688 }
4689}
4690
4691/**
4692 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004693 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004694 * @param priv
4695 * @return error code
4696 */
4697static int ipw_queue_reset(struct ipw_priv *priv)
4698{
4699 int rc = 0;
4700 /** @todo customize queue sizes */
4701 int nTx = 64, nTxCmd = 8;
4702 ipw_tx_queue_free(priv);
4703 /* Tx CMD queue */
4704 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004705 IPW_TX_CMD_QUEUE_READ_INDEX,
4706 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4707 IPW_TX_CMD_QUEUE_BD_BASE,
4708 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004709 if (rc) {
4710 IPW_ERROR("Tx Cmd queue init failed\n");
4711 goto error;
4712 }
4713 /* Tx queue(s) */
4714 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004715 IPW_TX_QUEUE_0_READ_INDEX,
4716 IPW_TX_QUEUE_0_WRITE_INDEX,
4717 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004718 if (rc) {
4719 IPW_ERROR("Tx 0 queue init failed\n");
4720 goto error;
4721 }
4722 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004723 IPW_TX_QUEUE_1_READ_INDEX,
4724 IPW_TX_QUEUE_1_WRITE_INDEX,
4725 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004726 if (rc) {
4727 IPW_ERROR("Tx 1 queue init failed\n");
4728 goto error;
4729 }
4730 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004731 IPW_TX_QUEUE_2_READ_INDEX,
4732 IPW_TX_QUEUE_2_WRITE_INDEX,
4733 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004734 if (rc) {
4735 IPW_ERROR("Tx 2 queue init failed\n");
4736 goto error;
4737 }
4738 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004739 IPW_TX_QUEUE_3_READ_INDEX,
4740 IPW_TX_QUEUE_3_WRITE_INDEX,
4741 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004742 if (rc) {
4743 IPW_ERROR("Tx 3 queue init failed\n");
4744 goto error;
4745 }
4746 /* statistics */
4747 priv->rx_bufs_min = 0;
4748 priv->rx_pend_max = 0;
4749 return rc;
4750
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004751 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004752 ipw_tx_queue_free(priv);
4753 return rc;
4754}
4755
4756/**
4757 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004758 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004759 * When FW adwances 'R' index, all entries between old and
4760 * new 'R' index need to be reclaimed. As result, some free space
4761 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004762 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004763 * @note Need to protect against garbage in 'R' index
4764 * @param priv
4765 * @param txq
4766 * @param qindex
4767 * @return Number of used entries remains in the queue
4768 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004769static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004770 struct clx2_tx_queue *txq, int qindex)
4771{
4772 u32 hw_tail;
4773 int used;
4774 struct clx2_queue *q = &txq->q;
4775
4776 hw_tail = ipw_read32(priv, q->reg_r);
4777 if (hw_tail >= q->n_bd) {
4778 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004779 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4780 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004781 goto done;
4782 }
4783 for (; q->last_used != hw_tail;
4784 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4785 ipw_queue_tx_free_tfd(priv, txq);
4786 priv->tx_packets++;
4787 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004788 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004789 if ((ipw_queue_space(q) > q->low_mark) &&
4790 (qindex >= 0) &&
4791 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4792 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004793 used = q->first_empty - q->last_used;
4794 if (used < 0)
4795 used += q->n_bd;
4796
4797 return used;
4798}
4799
4800static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4801 int len, int sync)
4802{
4803 struct clx2_tx_queue *txq = &priv->txq_cmd;
4804 struct clx2_queue *q = &txq->q;
4805 struct tfd_frame *tfd;
4806
4807 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4808 IPW_ERROR("No space for Tx\n");
4809 return -EBUSY;
4810 }
4811
4812 tfd = &txq->bd[q->first_empty];
4813 txq->txb[q->first_empty] = NULL;
4814
4815 memset(tfd, 0, sizeof(*tfd));
4816 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4817 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4818 priv->hcmd_seq++;
4819 tfd->u.cmd.index = hcmd;
4820 tfd->u.cmd.length = len;
4821 memcpy(tfd->u.cmd.payload, buf, len);
4822 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4823 ipw_write32(priv, q->reg_w, q->first_empty);
4824 _ipw_read32(priv, 0x90);
4825
4826 return 0;
4827}
4828
Jeff Garzikbf794512005-07-31 13:07:26 -04004829/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004830 * Rx theory of operation
4831 *
4832 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004833 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004834 * 0 to 31
4835 *
4836 * Rx Queue Indexes
4837 * The host/firmware share two index registers for managing the Rx buffers.
4838 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004839 * The READ index maps to the first position that the firmware may be writing
4840 * to -- the driver can read up to (but not including) this position and get
4841 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004842 * The READ index is managed by the firmware once the card is enabled.
4843 *
4844 * The WRITE index maps to the last position the driver has read from -- the
4845 * position preceding WRITE is the last slot the firmware can place a packet.
4846 *
4847 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004848 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004849 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004850 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004851 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4852 *
4853 * When the firmware places a packet in a buffer it will advance the READ index
4854 * and fire the RX interrupt. The driver can then query the READ index and
4855 * process as many packets as possible, moving the WRITE index forward as it
4856 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004857 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004858 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004859 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004860 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004861 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004862 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4863 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4864 * 'processed' and 'read' driver indexes as well)
4865 * + A received packet is processed and handed to the kernel network stack,
4866 * detached from the ipw->rxq. The driver 'processed' index is updated.
4867 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004868 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4869 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004870 * were enough free buffers and RX_STALLED is set it is cleared.
4871 *
4872 *
4873 * Driver sequence:
4874 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004875 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4877 * ipw_rx_queue_restock
4878 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4879 * queue, updates firmware pointers, and updates
4880 * the WRITE index. If insufficient rx_free buffers
4881 * are available, schedules ipw_rx_queue_replenish
4882 *
4883 * -- enable interrupts --
4884 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004885 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004886 * Moves the packet buffer from queue to rx_used.
4887 * Calls ipw_rx_queue_restock to refill any empty
4888 * slots.
4889 * ...
4890 *
4891 */
4892
Jeff Garzikbf794512005-07-31 13:07:26 -04004893/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004894 * If there are slots in the RX queue that need to be restocked,
4895 * and we have free pre-allocated buffers, fill the ranks as much
4896 * as we can pulling from rx_free.
4897 *
4898 * This moves the 'write' index forward to catch up with 'processed', and
4899 * also updates the memory address in the firmware to reference the new
4900 * target buffer.
4901 */
4902static void ipw_rx_queue_restock(struct ipw_priv *priv)
4903{
4904 struct ipw_rx_queue *rxq = priv->rxq;
4905 struct list_head *element;
4906 struct ipw_rx_mem_buffer *rxb;
4907 unsigned long flags;
4908 int write;
4909
4910 spin_lock_irqsave(&rxq->lock, flags);
4911 write = rxq->write;
4912 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4913 element = rxq->rx_free.next;
4914 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4915 list_del(element);
4916
James Ketrenosb095c382005-08-24 22:04:42 -05004917 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004918 rxb->dma_addr);
4919 rxq->queue[rxq->write] = rxb;
4920 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4921 rxq->free_count--;
4922 }
4923 spin_unlock_irqrestore(&rxq->lock, flags);
4924
Jeff Garzikbf794512005-07-31 13:07:26 -04004925 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004926 * refill it */
4927 if (rxq->free_count <= RX_LOW_WATERMARK)
4928 queue_work(priv->workqueue, &priv->rx_replenish);
4929
4930 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004931 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004932 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004933}
4934
4935/*
4936 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004937 * Also restock the Rx queue via ipw_rx_queue_restock.
4938 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004939 * This is called as a scheduled work item (except for during intialization)
4940 */
4941static void ipw_rx_queue_replenish(void *data)
4942{
4943 struct ipw_priv *priv = data;
4944 struct ipw_rx_queue *rxq = priv->rxq;
4945 struct list_head *element;
4946 struct ipw_rx_mem_buffer *rxb;
4947 unsigned long flags;
4948
4949 spin_lock_irqsave(&rxq->lock, flags);
4950 while (!list_empty(&rxq->rx_used)) {
4951 element = rxq->rx_used.next;
4952 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004953 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004954 if (!rxb->skb) {
4955 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4956 priv->net_dev->name);
4957 /* We don't reschedule replenish work here -- we will
4958 * call the restock method and if it still needs
4959 * more buffers it will schedule replenish */
4960 break;
4961 }
4962 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004963
James Ketrenos43f66a62005-03-25 12:31:53 -06004964 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004965 rxb->dma_addr =
4966 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004967 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004968
James Ketrenos43f66a62005-03-25 12:31:53 -06004969 list_add_tail(&rxb->list, &rxq->rx_free);
4970 rxq->free_count++;
4971 }
4972 spin_unlock_irqrestore(&rxq->lock, flags);
4973
4974 ipw_rx_queue_restock(priv);
4975}
4976
James Ketrenosc848d0a2005-08-24 21:56:24 -05004977static void ipw_bg_rx_queue_replenish(void *data)
4978{
4979 struct ipw_priv *priv = data;
4980 down(&priv->sem);
4981 ipw_rx_queue_replenish(data);
4982 up(&priv->sem);
4983}
4984
James Ketrenos43f66a62005-03-25 12:31:53 -06004985/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08004986 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004987 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004988 * non NULL it is unmapped and freed
4989 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004990static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004991{
4992 int i;
4993
4994 if (!rxq)
4995 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004996
James Ketrenos43f66a62005-03-25 12:31:53 -06004997 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4998 if (rxq->pool[i].skb != NULL) {
4999 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005000 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005001 dev_kfree_skb(rxq->pool[i].skb);
5002 }
5003 }
5004
5005 kfree(rxq);
5006}
5007
5008static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5009{
5010 struct ipw_rx_queue *rxq;
5011 int i;
5012
Takisc75f4742005-12-01 01:41:45 -08005013 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005014 if (unlikely(!rxq)) {
5015 IPW_ERROR("memory allocation failed\n");
5016 return NULL;
5017 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005018 spin_lock_init(&rxq->lock);
5019 INIT_LIST_HEAD(&rxq->rx_free);
5020 INIT_LIST_HEAD(&rxq->rx_used);
5021
5022 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5025
5026 /* Set us so that we have processed and used all buffers, but have
5027 * not restocked the Rx queue with fresh buffers */
5028 rxq->read = rxq->write = 0;
5029 rxq->processed = RX_QUEUE_SIZE - 1;
5030 rxq->free_count = 0;
5031
5032 return rxq;
5033}
5034
5035static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5036{
5037 rate &= ~IEEE80211_BASIC_RATE_MASK;
5038 if (ieee_mode == IEEE_A) {
5039 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005040 case IEEE80211_OFDM_RATE_6MB:
5041 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005042 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005043 case IEEE80211_OFDM_RATE_9MB:
5044 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005045 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005046 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005047 return priv->
5048 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005049 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005050 return priv->
5051 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005052 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005053 return priv->
5054 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005055 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005056 return priv->
5057 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005058 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005059 return priv->
5060 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005061 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005062 return priv->
5063 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005064 default:
5065 return 0;
5066 }
5067 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005068
James Ketrenos43f66a62005-03-25 12:31:53 -06005069 /* B and G mixed */
5070 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005071 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005072 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005073 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005074 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005075 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005076 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005077 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005078 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5079 }
5080
5081 /* If we are limited to B modulations, bail at this point */
5082 if (ieee_mode == IEEE_B)
5083 return 0;
5084
5085 /* G */
5086 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005087 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005089 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005090 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005091 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005092 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005093 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005094 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005095 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005096 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005097 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005098 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005099 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005100 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005101 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005102 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5103 }
5104
5105 return 0;
5106}
5107
Jeff Garzikbf794512005-07-31 13:07:26 -04005108static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005109 const struct ieee80211_network *network,
5110 struct ipw_supported_rates *rates)
5111{
5112 int num_rates, i;
5113
5114 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005115 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 rates->num_rates = 0;
5117 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005118 if (!ipw_is_rate_in_mask(priv, network->mode,
5119 network->rates[i])) {
5120
James Ketrenosea2b26e2005-08-24 21:25:16 -05005121 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005122 IPW_DEBUG_SCAN("Adding masked mandatory "
5123 "rate %02X\n",
5124 network->rates[i]);
5125 rates->supported_rates[rates->num_rates++] =
5126 network->rates[i];
5127 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005128 }
5129
James Ketrenos43f66a62005-03-25 12:31:53 -06005130 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5131 network->rates[i], priv->rates_mask);
5132 continue;
5133 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005134
James Ketrenos43f66a62005-03-25 12:31:53 -06005135 rates->supported_rates[rates->num_rates++] = network->rates[i];
5136 }
5137
James Ketrenosa613bff2005-08-24 21:43:11 -05005138 num_rates = min(network->rates_ex_len,
5139 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005140 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005141 if (!ipw_is_rate_in_mask(priv, network->mode,
5142 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005143 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005144 IPW_DEBUG_SCAN("Adding masked mandatory "
5145 "rate %02X\n",
5146 network->rates_ex[i]);
5147 rates->supported_rates[rates->num_rates++] =
5148 network->rates[i];
5149 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005150 }
5151
James Ketrenos43f66a62005-03-25 12:31:53 -06005152 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5153 network->rates_ex[i], priv->rates_mask);
5154 continue;
5155 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005156
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005157 rates->supported_rates[rates->num_rates++] =
5158 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005159 }
5160
James Ketrenosea2b26e2005-08-24 21:25:16 -05005161 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005162}
5163
Arjan van de Ven858119e2006-01-14 13:20:43 -08005164static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005165 const struct ipw_supported_rates *src)
5166{
5167 u8 i;
5168 for (i = 0; i < src->num_rates; i++)
5169 dest->supported_rates[i] = src->supported_rates[i];
5170 dest->num_rates = src->num_rates;
5171}
5172
5173/* TODO: Look at sniffed packets in the air to determine if the basic rate
5174 * mask should ever be used -- right now all callers to add the scan rates are
5175 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5176static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005177 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005178{
Jeff Garzikbf794512005-07-31 13:07:26 -04005179 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005180 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005181
James Ketrenos43f66a62005-03-25 12:31:53 -06005182 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005184 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005185
5186 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005187 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005188 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005189
5190 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005192 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005193
5194 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005195 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005196 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005197}
5198
5199static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005200 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005201{
Jeff Garzikbf794512005-07-31 13:07:26 -04005202 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005203 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005204
5205 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005206 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005207 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005208
5209 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005210 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005211 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005212
5213 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005214 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005215 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005216
5217 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005218 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005219 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005220
5221 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005222 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005223 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005224
5225 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005226 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005227 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005228
5229 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005230 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005231 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005232
5233 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005234 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005235 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005236}
5237
5238struct ipw_network_match {
5239 struct ieee80211_network *network;
5240 struct ipw_supported_rates rates;
5241};
5242
James Ketrenosc848d0a2005-08-24 21:56:24 -05005243static int ipw_find_adhoc_network(struct ipw_priv *priv,
5244 struct ipw_network_match *match,
5245 struct ieee80211_network *network,
5246 int roaming)
5247{
5248 struct ipw_supported_rates rates;
5249
5250 /* Verify that this network's capability is compatible with the
5251 * current mode (AdHoc or Infrastructure) */
5252 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5253 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5254 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5255 "capability mismatch.\n",
5256 escape_essid(network->ssid, network->ssid_len),
5257 MAC_ARG(network->bssid));
5258 return 0;
5259 }
5260
5261 /* If we do not have an ESSID for this AP, we can not associate with
5262 * it */
5263 if (network->flags & NETWORK_EMPTY_ESSID) {
5264 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5265 "because of hidden ESSID.\n",
5266 escape_essid(network->ssid, network->ssid_len),
5267 MAC_ARG(network->bssid));
5268 return 0;
5269 }
5270
5271 if (unlikely(roaming)) {
5272 /* If we are roaming, then ensure check if this is a valid
5273 * network to try and roam to */
5274 if ((network->ssid_len != match->network->ssid_len) ||
5275 memcmp(network->ssid, match->network->ssid,
5276 network->ssid_len)) {
5277 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5278 "because of non-network ESSID.\n",
5279 escape_essid(network->ssid,
5280 network->ssid_len),
5281 MAC_ARG(network->bssid));
5282 return 0;
5283 }
5284 } else {
5285 /* If an ESSID has been configured then compare the broadcast
5286 * ESSID to ours */
5287 if ((priv->config & CFG_STATIC_ESSID) &&
5288 ((network->ssid_len != priv->essid_len) ||
5289 memcmp(network->ssid, priv->essid,
5290 min(network->ssid_len, priv->essid_len)))) {
5291 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005292
James Ketrenosc848d0a2005-08-24 21:56:24 -05005293 strncpy(escaped,
5294 escape_essid(network->ssid, network->ssid_len),
5295 sizeof(escaped));
5296 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5297 "because of ESSID mismatch: '%s'.\n",
5298 escaped, MAC_ARG(network->bssid),
5299 escape_essid(priv->essid,
5300 priv->essid_len));
5301 return 0;
5302 }
5303 }
5304
5305 /* If the old network rate is better than this one, don't bother
5306 * testing everything else. */
5307
5308 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005309 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5310 "current network.\n",
5311 escape_essid(match->network->ssid,
5312 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005313 return 0;
5314 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005315 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5316 "current network.\n",
5317 escape_essid(match->network->ssid,
5318 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005319 return 0;
5320 }
5321
5322 /* Now go through and see if the requested network is valid... */
5323 if (priv->ieee->scan_age != 0 &&
5324 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5325 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005326 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005327 escape_essid(network->ssid, network->ssid_len),
5328 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005329 jiffies_to_msecs(jiffies - network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005330 return 0;
5331 }
5332
5333 if ((priv->config & CFG_STATIC_CHANNEL) &&
5334 (network->channel != priv->channel)) {
5335 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5336 "because of channel mismatch: %d != %d.\n",
5337 escape_essid(network->ssid, network->ssid_len),
5338 MAC_ARG(network->bssid),
5339 network->channel, priv->channel);
5340 return 0;
5341 }
5342
5343 /* Verify privacy compatability */
5344 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5345 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5346 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5347 "because of privacy mismatch: %s != %s.\n",
5348 escape_essid(network->ssid, network->ssid_len),
5349 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005350 priv->
5351 capability & CAP_PRIVACY_ON ? "on" : "off",
5352 network->
5353 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5354 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005355 return 0;
5356 }
5357
5358 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5359 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5360 "because of the same BSSID match: " MAC_FMT
5361 ".\n", escape_essid(network->ssid,
5362 network->ssid_len),
5363 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5364 return 0;
5365 }
5366
5367 /* Filter out any incompatible freq / mode combinations */
5368 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5369 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5370 "because of invalid frequency/mode "
5371 "combination.\n",
5372 escape_essid(network->ssid, network->ssid_len),
5373 MAC_ARG(network->bssid));
5374 return 0;
5375 }
5376
5377 /* Ensure that the rates supported by the driver are compatible with
5378 * this AP, including verification of basic rates (mandatory) */
5379 if (!ipw_compatible_rates(priv, network, &rates)) {
5380 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5381 "because configured rate mask excludes "
5382 "AP mandatory rate.\n",
5383 escape_essid(network->ssid, network->ssid_len),
5384 MAC_ARG(network->bssid));
5385 return 0;
5386 }
5387
5388 if (rates.num_rates == 0) {
5389 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5390 "because of no compatible rates.\n",
5391 escape_essid(network->ssid, network->ssid_len),
5392 MAC_ARG(network->bssid));
5393 return 0;
5394 }
5395
5396 /* TODO: Perform any further minimal comparititive tests. We do not
5397 * want to put too much policy logic here; intelligent scan selection
5398 * should occur within a generic IEEE 802.11 user space tool. */
5399
5400 /* Set up 'new' AP to this network */
5401 ipw_copy_rates(&match->rates, &rates);
5402 match->network = network;
5403 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5404 escape_essid(network->ssid, network->ssid_len),
5405 MAC_ARG(network->bssid));
5406
5407 return 1;
5408}
5409
5410static void ipw_merge_adhoc_network(void *data)
5411{
5412 struct ipw_priv *priv = data;
5413 struct ieee80211_network *network = NULL;
5414 struct ipw_network_match match = {
5415 .network = priv->assoc_network
5416 };
5417
James Ketrenosafbf30a2005-08-25 00:05:33 -05005418 if ((priv->status & STATUS_ASSOCIATED) &&
5419 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005420 /* First pass through ROAM process -- look for a better
5421 * network */
5422 unsigned long flags;
5423
5424 spin_lock_irqsave(&priv->ieee->lock, flags);
5425 list_for_each_entry(network, &priv->ieee->network_list, list) {
5426 if (network != priv->assoc_network)
5427 ipw_find_adhoc_network(priv, &match, network,
5428 1);
5429 }
5430 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5431
5432 if (match.network == priv->assoc_network) {
5433 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5434 "merge to.\n");
5435 return;
5436 }
5437
5438 down(&priv->sem);
5439 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5440 IPW_DEBUG_MERGE("remove network %s\n",
5441 escape_essid(priv->essid,
5442 priv->essid_len));
5443 ipw_remove_current_network(priv);
5444 }
5445
5446 ipw_disassociate(priv);
5447 priv->assoc_network = match.network;
5448 up(&priv->sem);
5449 return;
5450 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005451}
5452
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005453static int ipw_best_network(struct ipw_priv *priv,
5454 struct ipw_network_match *match,
5455 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005456{
5457 struct ipw_supported_rates rates;
5458
5459 /* Verify that this network's capability is compatible with the
5460 * current mode (AdHoc or Infrastructure) */
5461 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005462 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005463 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5464 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5465 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005466 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005467 escape_essid(network->ssid, network->ssid_len),
5468 MAC_ARG(network->bssid));
5469 return 0;
5470 }
5471
5472 /* If we do not have an ESSID for this AP, we can not associate with
5473 * it */
5474 if (network->flags & NETWORK_EMPTY_ESSID) {
5475 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5476 "because of hidden ESSID.\n",
5477 escape_essid(network->ssid, network->ssid_len),
5478 MAC_ARG(network->bssid));
5479 return 0;
5480 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005481
James Ketrenos43f66a62005-03-25 12:31:53 -06005482 if (unlikely(roaming)) {
5483 /* If we are roaming, then ensure check if this is a valid
5484 * network to try and roam to */
5485 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005486 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005487 network->ssid_len)) {
5488 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5489 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005490 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005491 network->ssid_len),
5492 MAC_ARG(network->bssid));
5493 return 0;
5494 }
5495 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005496 /* If an ESSID has been configured then compare the broadcast
5497 * ESSID to ours */
5498 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005499 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005500 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005501 min(network->ssid_len, priv->essid_len)))) {
5502 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005503 strncpy(escaped,
5504 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005505 sizeof(escaped));
5506 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005507 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005508 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005509 escape_essid(priv->essid,
5510 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005511 return 0;
5512 }
5513 }
5514
5515 /* If the old network rate is better than this one, don't bother
5516 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005517 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005518 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005519 strncpy(escaped,
5520 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005521 sizeof(escaped));
5522 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5523 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5524 escaped, MAC_ARG(network->bssid),
5525 escape_essid(match->network->ssid,
5526 match->network->ssid_len),
5527 MAC_ARG(match->network->bssid));
5528 return 0;
5529 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005530
James Ketrenos43f66a62005-03-25 12:31:53 -06005531 /* If this network has already had an association attempt within the
5532 * last 3 seconds, do not try and associate again... */
5533 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005534 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005535 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005536 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005537 "assoc attempt).\n",
5538 escape_essid(network->ssid, network->ssid_len),
5539 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005540 jiffies_to_msecs(jiffies - network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005541 return 0;
5542 }
5543
5544 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005545 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005546 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005547 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005548 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005549 escape_essid(network->ssid, network->ssid_len),
5550 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005551 jiffies_to_msecs(jiffies - network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005552 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005553 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005554
Jeff Garzikbf794512005-07-31 13:07:26 -04005555 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005556 (network->channel != priv->channel)) {
5557 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5558 "because of channel mismatch: %d != %d.\n",
5559 escape_essid(network->ssid, network->ssid_len),
5560 MAC_ARG(network->bssid),
5561 network->channel, priv->channel);
5562 return 0;
5563 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005564
James Ketrenos43f66a62005-03-25 12:31:53 -06005565 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005566 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005567 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5568 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5569 "because of privacy mismatch: %s != %s.\n",
5570 escape_essid(network->ssid, network->ssid_len),
5571 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005572 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005573 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005574 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005575 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005576 return 0;
5577 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005578
Hong Liucdd1fa12005-08-31 18:14:27 +08005579 if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
5580 network->rsn_ie_len > 0)) {
5581 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5582 "because of WPA capability mismatch.\n",
5583 escape_essid(network->ssid, network->ssid_len),
5584 MAC_ARG(network->bssid));
5585 return 0;
5586 }
5587
Jeff Garzikbf794512005-07-31 13:07:26 -04005588 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005589 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5590 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5591 "because of BSSID mismatch: " MAC_FMT ".\n",
5592 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005593 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005594 return 0;
5595 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005596
James Ketrenos43f66a62005-03-25 12:31:53 -06005597 /* Filter out any incompatible freq / mode combinations */
5598 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5599 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5600 "because of invalid frequency/mode "
5601 "combination.\n",
5602 escape_essid(network->ssid, network->ssid_len),
5603 MAC_ARG(network->bssid));
5604 return 0;
5605 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005606
Liu Hong1fe0adb2005-08-19 09:33:10 -05005607 /* Filter out invalid channel in current GEO */
5608 if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5609 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5610 "because of invalid channel in current GEO\n",
5611 escape_essid(network->ssid, network->ssid_len),
5612 MAC_ARG(network->bssid));
5613 return 0;
5614 }
5615
James Ketrenosea2b26e2005-08-24 21:25:16 -05005616 /* Ensure that the rates supported by the driver are compatible with
5617 * this AP, including verification of basic rates (mandatory) */
5618 if (!ipw_compatible_rates(priv, network, &rates)) {
5619 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5620 "because configured rate mask excludes "
5621 "AP mandatory rate.\n",
5622 escape_essid(network->ssid, network->ssid_len),
5623 MAC_ARG(network->bssid));
5624 return 0;
5625 }
5626
James Ketrenos43f66a62005-03-25 12:31:53 -06005627 if (rates.num_rates == 0) {
5628 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5629 "because of no compatible rates.\n",
5630 escape_essid(network->ssid, network->ssid_len),
5631 MAC_ARG(network->bssid));
5632 return 0;
5633 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005634
James Ketrenos43f66a62005-03-25 12:31:53 -06005635 /* TODO: Perform any further minimal comparititive tests. We do not
5636 * want to put too much policy logic here; intelligent scan selection
5637 * should occur within a generic IEEE 802.11 user space tool. */
5638
5639 /* Set up 'new' AP to this network */
5640 ipw_copy_rates(&match->rates, &rates);
5641 match->network = network;
5642
5643 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5644 escape_essid(network->ssid, network->ssid_len),
5645 MAC_ARG(network->bssid));
5646
5647 return 1;
5648}
5649
Jeff Garzikbf794512005-07-31 13:07:26 -04005650static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005651 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005652{
Liu Hong1fe0adb2005-08-19 09:33:10 -05005653 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005654 int i;
5655
James Ketrenos43f66a62005-03-25 12:31:53 -06005656 /*
5657 * For the purposes of scanning, we can set our wireless mode
5658 * to trigger scans across combinations of bands, but when it
5659 * comes to creating a new ad-hoc network, we have tell the FW
5660 * exactly which band to use.
5661 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005662 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005663 * chossen band. Attempting to create a new ad-hoc network
5664 * with an invalid channel for wireless mode will trigger a
5665 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005666 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005667 */
Liu Hong1fe0adb2005-08-19 09:33:10 -05005668 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005669 case IEEE80211_52GHZ_BAND:
5670 network->mode = IEEE_A;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005671 i = ipw_channel_to_index(priv->ieee, priv->channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005672 if (i == -1)
5673 BUG();
5674 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5675 IPW_WARNING("Overriding invalid channel\n");
5676 priv->channel = geo->a[0].channel;
5677 }
5678 break;
5679
5680 case IEEE80211_24GHZ_BAND:
5681 if (priv->ieee->mode & IEEE_G)
5682 network->mode = IEEE_G;
5683 else
5684 network->mode = IEEE_B;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005685 i = ipw_channel_to_index(priv->ieee, priv->channel);
5686 if (i == -1)
5687 BUG();
5688 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5689 IPW_WARNING("Overriding invalid channel\n");
5690 priv->channel = geo->bg[0].channel;
5691 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005692 break;
5693
5694 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005695 IPW_WARNING("Overriding invalid channel\n");
5696 if (priv->ieee->mode & IEEE_A) {
5697 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005698 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005699 } else if (priv->ieee->mode & IEEE_G) {
5700 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005701 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005702 } else {
5703 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005704 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005705 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005706 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005707 }
5708
5709 network->channel = priv->channel;
5710 priv->config |= CFG_ADHOC_PERSIST;
5711 ipw_create_bssid(priv, network->bssid);
5712 network->ssid_len = priv->essid_len;
5713 memcpy(network->ssid, priv->essid, priv->essid_len);
5714 memset(&network->stats, 0, sizeof(network->stats));
5715 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005716 if (!(priv->config & CFG_PREAMBLE_LONG))
5717 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005718 if (priv->capability & CAP_PRIVACY_ON)
5719 network->capability |= WLAN_CAPABILITY_PRIVACY;
5720 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005721 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005722 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005723 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005724 &priv->rates.supported_rates[network->rates_len],
5725 network->rates_ex_len);
5726 network->last_scanned = 0;
5727 network->flags = 0;
5728 network->last_associate = 0;
5729 network->time_stamp[0] = 0;
5730 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005731 network->beacon_interval = 100; /* Default */
5732 network->listen_interval = 10; /* Default */
5733 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005734 network->wpa_ie_len = 0;
5735 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005736}
5737
James Ketrenosb095c382005-08-24 22:04:42 -05005738static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5739{
5740 struct ipw_tgi_tx_key *key;
5741 struct host_cmd cmd = {
5742 .cmd = IPW_CMD_TGI_TX_KEY,
5743 .len = sizeof(*key)
5744 };
5745
5746 if (!(priv->ieee->sec.flags & (1 << index)))
5747 return;
5748
5749 key = (struct ipw_tgi_tx_key *)&cmd.param;
5750 key->key_id = index;
5751 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5752 key->security_type = type;
5753 key->station_index = 0; /* always 0 for BSS */
5754 key->flags = 0;
5755 /* 0 for new key; previous value of counter (after fatal error) */
5756 key->tx_counter[0] = 0;
5757 key->tx_counter[1] = 0;
5758
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005759 ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05005760}
5761
5762static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005763{
5764 struct ipw_wep_key *key;
5765 int i;
5766 struct host_cmd cmd = {
5767 .cmd = IPW_CMD_WEP_KEY,
5768 .len = sizeof(*key)
5769 };
5770
5771 key = (struct ipw_wep_key *)&cmd.param;
5772 key->cmd_id = DINO_CMD_WEP_KEY;
5773 key->seq_num = 0;
5774
James Ketrenosb095c382005-08-24 22:04:42 -05005775 /* Note: AES keys cannot be set for multiple times.
5776 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005777 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005778 key->key_index = i | type;
5779 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005780 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005781 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005782 }
5783
James Ketrenosb095c382005-08-24 22:04:42 -05005784 key->key_size = priv->ieee->sec.key_sizes[i];
5785 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5786
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005787 ipw_send_cmd(priv, &cmd);
Jeff Garzikbf794512005-07-31 13:07:26 -04005788 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005789}
5790
Zhu Yi1fbfea52005-08-05 17:22:56 +08005791static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5792{
5793 if (priv->ieee->host_encrypt)
5794 return;
5795
5796 switch (level) {
5797 case SEC_LEVEL_3:
5798 priv->sys_config.disable_unicast_decryption = 0;
5799 priv->ieee->host_decrypt = 0;
5800 break;
5801 case SEC_LEVEL_2:
5802 priv->sys_config.disable_unicast_decryption = 1;
5803 priv->ieee->host_decrypt = 1;
5804 break;
5805 case SEC_LEVEL_1:
5806 priv->sys_config.disable_unicast_decryption = 0;
5807 priv->ieee->host_decrypt = 0;
5808 break;
5809 case SEC_LEVEL_0:
5810 priv->sys_config.disable_unicast_decryption = 1;
5811 break;
5812 default:
5813 break;
5814 }
5815}
5816
5817static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5818{
5819 if (priv->ieee->host_encrypt)
5820 return;
5821
5822 switch (level) {
5823 case SEC_LEVEL_3:
5824 priv->sys_config.disable_multicast_decryption = 0;
5825 break;
5826 case SEC_LEVEL_2:
5827 priv->sys_config.disable_multicast_decryption = 1;
5828 break;
5829 case SEC_LEVEL_1:
5830 priv->sys_config.disable_multicast_decryption = 0;
5831 break;
5832 case SEC_LEVEL_0:
5833 priv->sys_config.disable_multicast_decryption = 1;
5834 break;
5835 default:
5836 break;
5837 }
5838}
5839
James Ketrenosb095c382005-08-24 22:04:42 -05005840static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5841{
5842 switch (priv->ieee->sec.level) {
5843 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005844 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5845 ipw_send_tgi_tx_key(priv,
5846 DCT_FLAG_EXT_SECURITY_CCM,
5847 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005848
Hong Liu567deaf2005-08-31 18:07:22 +08005849 if (!priv->ieee->host_mc_decrypt)
5850 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005851 break;
5852 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005853 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5854 ipw_send_tgi_tx_key(priv,
5855 DCT_FLAG_EXT_SECURITY_TKIP,
5856 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005857 break;
5858 case SEC_LEVEL_1:
5859 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005860 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5861 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005862 break;
5863 case SEC_LEVEL_0:
5864 default:
5865 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005866 }
5867}
5868
5869static void ipw_adhoc_check(void *data)
5870{
5871 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005872
James Ketrenosafbf30a2005-08-25 00:05:33 -05005873 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005874 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005875 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5876 IPW_DL_STATE | IPW_DL_ASSOC,
5877 "Missed beacon: %d - disassociate\n",
5878 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005879 ipw_remove_current_network(priv);
5880 ipw_disassociate(priv);
5881 return;
5882 }
5883
Jeff Garzikbf794512005-07-31 13:07:26 -04005884 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005885 priv->assoc_request.beacon_interval);
5886}
5887
James Ketrenosc848d0a2005-08-24 21:56:24 -05005888static void ipw_bg_adhoc_check(void *data)
5889{
5890 struct ipw_priv *priv = data;
5891 down(&priv->sem);
5892 ipw_adhoc_check(data);
5893 up(&priv->sem);
5894}
5895
Brice Goglin0f52bf92005-12-01 01:41:46 -08005896#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005897static void ipw_debug_config(struct ipw_priv *priv)
5898{
5899 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5900 "[CFG 0x%08X]\n", priv->config);
5901 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005902 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005903 else
5904 IPW_DEBUG_INFO("Channel unlocked.\n");
5905 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005906 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005907 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005908 else
5909 IPW_DEBUG_INFO("ESSID unlocked.\n");
5910 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005911 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5912 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005913 else
5914 IPW_DEBUG_INFO("BSSID unlocked.\n");
5915 if (priv->capability & CAP_PRIVACY_ON)
5916 IPW_DEBUG_INFO("PRIVACY on\n");
5917 else
5918 IPW_DEBUG_INFO("PRIVACY off\n");
5919 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5920}
5921#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005922#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005923#endif
5924
Arjan van de Ven858119e2006-01-14 13:20:43 -08005925static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005926{
5927 /* TODO: Verify that this works... */
5928 struct ipw_fixed_rate fr = {
5929 .tx_rates = priv->rates_mask
5930 };
5931 u32 reg;
5932 u16 mask = 0;
5933
Jeff Garzikbf794512005-07-31 13:07:26 -04005934 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005935 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005936
James Ketrenos43f66a62005-03-25 12:31:53 -06005937 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005938 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005939 /* IEEE_A */
5940 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5941 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005942 IPW_DEBUG_WX
5943 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005944 fr.tx_rates = 0;
5945 break;
5946 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005947
James Ketrenos43f66a62005-03-25 12:31:53 -06005948 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5949 break;
5950
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005951 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005952 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005953 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005954 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5955 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005956 IPW_DEBUG_WX
5957 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005958 fr.tx_rates = 0;
5959 }
5960 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005961 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005962
5963 /* IEEE_G */
5964 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5965 IEEE80211_OFDM_RATES_MASK)) {
5966 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005967 IPW_DEBUG_WX
5968 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005969 fr.tx_rates = 0;
5970 break;
5971 }
5972
5973 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5974 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5975 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5976 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005977
James Ketrenos43f66a62005-03-25 12:31:53 -06005978 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5979 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5980 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5981 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005982
James Ketrenos43f66a62005-03-25 12:31:53 -06005983 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5984 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5985 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5986 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005987
James Ketrenos43f66a62005-03-25 12:31:53 -06005988 fr.tx_rates |= mask;
5989 break;
5990 }
5991
5992 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005993 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005994}
5995
James Ketrenosea2b26e2005-08-24 21:25:16 -05005996static void ipw_abort_scan(struct ipw_priv *priv)
5997{
5998 int err;
5999
6000 if (priv->status & STATUS_SCAN_ABORTING) {
6001 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6002 return;
6003 }
6004 priv->status |= STATUS_SCAN_ABORTING;
6005
6006 err = ipw_send_scan_abort(priv);
6007 if (err)
6008 IPW_DEBUG_HC("Request to abort scan failed.\n");
6009}
6010
James Ketrenosafbf30a2005-08-25 00:05:33 -05006011static void ipw_add_scan_channels(struct ipw_priv *priv,
6012 struct ipw_scan_request_ext *scan,
6013 int scan_type)
6014{
6015 int channel_index = 0;
6016 const struct ieee80211_geo *geo;
6017 int i;
6018
Liu Hong1fe0adb2005-08-19 09:33:10 -05006019 geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006020
6021 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6022 int start = channel_index;
6023 for (i = 0; i < geo->a_channels; i++) {
6024 if ((priv->status & STATUS_ASSOCIATED) &&
6025 geo->a[i].channel == priv->channel)
6026 continue;
6027 channel_index++;
6028 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006029 ipw_set_scan_type(scan, channel_index,
6030 geo->a[i].
6031 flags & IEEE80211_CH_PASSIVE_ONLY ?
6032 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6033 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006034 }
6035
6036 if (start != channel_index) {
6037 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6038 (channel_index - start);
6039 channel_index++;
6040 }
6041 }
6042
6043 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6044 int start = channel_index;
6045 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006046 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006047 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6048 /* nop out the list */
6049 [0] = 0
6050 };
6051
6052 u8 channel;
6053 while (channel_index < IPW_SCAN_CHANNELS) {
6054 channel =
6055 priv->speed_scan[priv->speed_scan_pos];
6056 if (channel == 0) {
6057 priv->speed_scan_pos = 0;
6058 channel = priv->speed_scan[0];
6059 }
6060 if ((priv->status & STATUS_ASSOCIATED) &&
6061 channel == priv->channel) {
6062 priv->speed_scan_pos++;
6063 continue;
6064 }
6065
6066 /* If this channel has already been
6067 * added in scan, break from loop
6068 * and this will be the first channel
6069 * in the next scan.
6070 */
6071 if (channels[channel - 1] != 0)
6072 break;
6073
6074 channels[channel - 1] = 1;
6075 priv->speed_scan_pos++;
6076 channel_index++;
6077 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006078 index =
6079 ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006080 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006081 geo->bg[index].
6082 flags &
6083 IEEE80211_CH_PASSIVE_ONLY ?
6084 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6085 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006086 }
6087 } else {
6088 for (i = 0; i < geo->bg_channels; i++) {
6089 if ((priv->status & STATUS_ASSOCIATED) &&
6090 geo->bg[i].channel == priv->channel)
6091 continue;
6092 channel_index++;
6093 scan->channels_list[channel_index] =
6094 geo->bg[i].channel;
6095 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006096 geo->bg[i].
6097 flags &
6098 IEEE80211_CH_PASSIVE_ONLY ?
6099 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6100 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006101 }
6102 }
6103
6104 if (start != channel_index) {
6105 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6106 (channel_index - start);
6107 }
6108 }
6109}
6110
James Ketrenosea2b26e2005-08-24 21:25:16 -05006111static int ipw_request_scan(struct ipw_priv *priv)
6112{
6113 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006114 int err = 0, scan_type;
6115
6116 if (!(priv->status & STATUS_INIT) ||
6117 (priv->status & STATUS_EXIT_PENDING))
6118 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006119
James Ketrenosb095c382005-08-24 22:04:42 -05006120 down(&priv->sem);
6121
James Ketrenosea2b26e2005-08-24 21:25:16 -05006122 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006123 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006124 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006125 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006126 }
6127
James Ketrenosafbf30a2005-08-25 00:05:33 -05006128 if (!(priv->status & STATUS_SCAN_FORCED) &&
6129 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006130 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6131 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006132 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006133 }
6134
6135 if (priv->status & STATUS_RF_KILL_MASK) {
6136 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6137 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006138 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006139 }
6140
6141 memset(&scan, 0, sizeof(scan));
6142
James Ketrenosb095c382005-08-24 22:04:42 -05006143 if (priv->config & CFG_SPEED_SCAN)
6144 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6145 cpu_to_le16(30);
6146 else
6147 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6148 cpu_to_le16(20);
6149
James Ketrenosa613bff2005-08-24 21:43:11 -05006150 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6151 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006152 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006153
James Ketrenosa613bff2005-08-24 21:43:11 -05006154 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006155
James Ketrenosb095c382005-08-24 22:04:42 -05006156#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006157 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006158 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006159 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006160
Liu Hong1fe0adb2005-08-19 09:33:10 -05006161 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006162 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006163 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006164 channel = priv->channel;
6165 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006166
James Ketrenosb095c382005-08-24 22:04:42 -05006167 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006168 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006169 channel = priv->channel;
6170 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006171
James Ketrenosb095c382005-08-24 22:04:42 -05006172 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006173 band = (u8) (IPW_B_MODE << 6) | 1;
6174 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006175 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006176 }
6177
James Ketrenosb095c382005-08-24 22:04:42 -05006178 scan.channels_list[0] = band;
6179 scan.channels_list[1] = channel;
6180 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006181
James Ketrenosb095c382005-08-24 22:04:42 -05006182 /* NOTE: The card will sit on this channel for this time
6183 * period. Scan aborts are timing sensitive and frequently
6184 * result in firmware restarts. As such, it is best to
6185 * set a small dwell_time here and just keep re-issuing
6186 * scans. Otherwise fast channel hopping will not actually
6187 * hop channels.
6188 *
6189 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006190 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6191 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006192 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006193#endif /* CONFIG_IPW2200_MONITOR */
6194 /* If we are roaming, then make this a directed scan for the
6195 * current network. Otherwise, ensure that every other scan
6196 * is a fast channel hop scan */
6197 if ((priv->status & STATUS_ROAMING)
6198 || (!(priv->status & STATUS_ASSOCIATED)
6199 && (priv->config & CFG_STATIC_ESSID)
6200 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006201 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6202 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006203 IPW_DEBUG_HC("Attempt to send SSID command "
6204 "failed.\n");
6205 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006206 }
6207
6208 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006209 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006210 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006211
James Ketrenosafbf30a2005-08-25 00:05:33 -05006212 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006213#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006214 }
6215#endif
6216
6217 err = ipw_send_scan_request_ext(priv, &scan);
6218 if (err) {
6219 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006220 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006221 }
6222
6223 priv->status |= STATUS_SCANNING;
6224 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006225 queue_delayed_work(priv->workqueue, &priv->scan_check,
6226 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006227 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006228 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006229 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006230}
6231
6232static void ipw_bg_abort_scan(void *data)
6233{
6234 struct ipw_priv *priv = data;
6235 down(&priv->sem);
6236 ipw_abort_scan(data);
6237 up(&priv->sem);
6238}
6239
James Ketrenosea2b26e2005-08-24 21:25:16 -05006240static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6241{
James Ketrenosb095c382005-08-24 22:04:42 -05006242 /* This is called when wpa_supplicant loads and closes the driver
6243 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006244 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006245 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006246}
6247
James Ketrenosea2b26e2005-08-24 21:25:16 -05006248static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6249{
6250 struct ieee80211_device *ieee = priv->ieee;
6251 struct ieee80211_security sec = {
6252 .flags = SEC_AUTH_MODE,
6253 };
6254 int ret = 0;
6255
James Ketrenosafbf30a2005-08-25 00:05:33 -05006256 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006257 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6258 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006259 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006260 sec.auth_mode = WLAN_AUTH_OPEN;
6261 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006262 } else if (value & IW_AUTH_ALG_LEAP) {
6263 sec.auth_mode = WLAN_AUTH_LEAP;
6264 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006265 } else
6266 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006267
6268 if (ieee->set_security)
6269 ieee->set_security(ieee->dev, &sec);
6270 else
6271 ret = -EOPNOTSUPP;
6272
6273 return ret;
6274}
6275
Adrian Bunka73e22b2006-01-21 01:39:42 +01006276static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6277 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006278{
6279 /* make sure WPA is enabled */
6280 ipw_wpa_enable(priv, 1);
6281
6282 ipw_disassociate(priv);
6283}
6284
6285static int ipw_set_rsn_capa(struct ipw_priv *priv,
6286 char *capabilities, int length)
6287{
6288 struct host_cmd cmd = {
6289 .cmd = IPW_CMD_RSN_CAPABILITIES,
6290 .len = length,
6291 };
6292
6293 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6294
6295 memcpy(cmd.param, capabilities, length);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05006296 return ipw_send_cmd(priv, &cmd);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006297}
6298
James Ketrenosafbf30a2005-08-25 00:05:33 -05006299/*
6300 * WE-18 support
6301 */
6302
6303/* SIOCSIWGENIE */
6304static int ipw_wx_set_genie(struct net_device *dev,
6305 struct iw_request_info *info,
6306 union iwreq_data *wrqu, char *extra)
6307{
6308 struct ipw_priv *priv = ieee80211_priv(dev);
6309 struct ieee80211_device *ieee = priv->ieee;
6310 u8 *buf;
6311 int err = 0;
6312
6313 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6314 (wrqu->data.length && extra == NULL))
6315 return -EINVAL;
6316
6317 //down(&priv->sem);
6318
6319 //if (!ieee->wpa_enabled) {
6320 // err = -EOPNOTSUPP;
6321 // goto out;
6322 //}
6323
6324 if (wrqu->data.length) {
6325 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6326 if (buf == NULL) {
6327 err = -ENOMEM;
6328 goto out;
6329 }
6330
6331 memcpy(buf, extra, wrqu->data.length);
6332 kfree(ieee->wpa_ie);
6333 ieee->wpa_ie = buf;
6334 ieee->wpa_ie_len = wrqu->data.length;
6335 } else {
6336 kfree(ieee->wpa_ie);
6337 ieee->wpa_ie = NULL;
6338 ieee->wpa_ie_len = 0;
6339 }
6340
6341 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6342 out:
6343 //up(&priv->sem);
6344 return err;
6345}
6346
6347/* SIOCGIWGENIE */
6348static int ipw_wx_get_genie(struct net_device *dev,
6349 struct iw_request_info *info,
6350 union iwreq_data *wrqu, char *extra)
6351{
6352 struct ipw_priv *priv = ieee80211_priv(dev);
6353 struct ieee80211_device *ieee = priv->ieee;
6354 int err = 0;
6355
6356 //down(&priv->sem);
6357
6358 //if (!ieee->wpa_enabled) {
6359 // err = -EOPNOTSUPP;
6360 // goto out;
6361 //}
6362
6363 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6364 wrqu->data.length = 0;
6365 goto out;
6366 }
6367
6368 if (wrqu->data.length < ieee->wpa_ie_len) {
6369 err = -E2BIG;
6370 goto out;
6371 }
6372
6373 wrqu->data.length = ieee->wpa_ie_len;
6374 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6375
6376 out:
6377 //up(&priv->sem);
6378 return err;
6379}
6380
Zhu Yi1fbfea52005-08-05 17:22:56 +08006381static int wext_cipher2level(int cipher)
6382{
6383 switch (cipher) {
6384 case IW_AUTH_CIPHER_NONE:
6385 return SEC_LEVEL_0;
6386 case IW_AUTH_CIPHER_WEP40:
6387 case IW_AUTH_CIPHER_WEP104:
6388 return SEC_LEVEL_1;
6389 case IW_AUTH_CIPHER_TKIP:
6390 return SEC_LEVEL_2;
6391 case IW_AUTH_CIPHER_CCMP:
6392 return SEC_LEVEL_3;
6393 default:
6394 return -1;
6395 }
6396}
6397
James Ketrenosafbf30a2005-08-25 00:05:33 -05006398/* SIOCSIWAUTH */
6399static int ipw_wx_set_auth(struct net_device *dev,
6400 struct iw_request_info *info,
6401 union iwreq_data *wrqu, char *extra)
6402{
6403 struct ipw_priv *priv = ieee80211_priv(dev);
6404 struct ieee80211_device *ieee = priv->ieee;
6405 struct iw_param *param = &wrqu->param;
6406 struct ieee80211_crypt_data *crypt;
6407 unsigned long flags;
6408 int ret = 0;
6409
6410 switch (param->flags & IW_AUTH_INDEX) {
6411 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006412 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006413 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006414 ipw_set_hw_decrypt_unicast(priv,
6415 wext_cipher2level(param->value));
6416 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006417 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006418 ipw_set_hw_decrypt_multicast(priv,
6419 wext_cipher2level(param->value));
6420 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006421 case IW_AUTH_KEY_MGMT:
6422 /*
6423 * ipw2200 does not use these parameters
6424 */
6425 break;
6426
6427 case IW_AUTH_TKIP_COUNTERMEASURES:
6428 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006429 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006430 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006431
6432 flags = crypt->ops->get_flags(crypt->priv);
6433
6434 if (param->value)
6435 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6436 else
6437 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6438
6439 crypt->ops->set_flags(flags, crypt->priv);
6440
6441 break;
6442
6443 case IW_AUTH_DROP_UNENCRYPTED:{
6444 /* HACK:
6445 *
6446 * wpa_supplicant calls set_wpa_enabled when the driver
6447 * is loaded and unloaded, regardless of if WPA is being
6448 * used. No other calls are made which can be used to
6449 * determine if encryption will be used or not prior to
6450 * association being expected. If encryption is not being
6451 * used, drop_unencrypted is set to false, else true -- we
6452 * can use this to determine if the CAP_PRIVACY_ON bit should
6453 * be set.
6454 */
6455 struct ieee80211_security sec = {
6456 .flags = SEC_ENABLED,
6457 .enabled = param->value,
6458 };
6459 priv->ieee->drop_unencrypted = param->value;
6460 /* We only change SEC_LEVEL for open mode. Others
6461 * are set by ipw_wpa_set_encryption.
6462 */
6463 if (!param->value) {
6464 sec.flags |= SEC_LEVEL;
6465 sec.level = SEC_LEVEL_0;
6466 } else {
6467 sec.flags |= SEC_LEVEL;
6468 sec.level = SEC_LEVEL_1;
6469 }
6470 if (priv->ieee->set_security)
6471 priv->ieee->set_security(priv->ieee->dev, &sec);
6472 break;
6473 }
6474
6475 case IW_AUTH_80211_AUTH_ALG:
6476 ret = ipw_wpa_set_auth_algs(priv, param->value);
6477 break;
6478
6479 case IW_AUTH_WPA_ENABLED:
6480 ret = ipw_wpa_enable(priv, param->value);
6481 break;
6482
6483 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6484 ieee->ieee802_1x = param->value;
6485 break;
6486
6487 //case IW_AUTH_ROAMING_CONTROL:
6488 case IW_AUTH_PRIVACY_INVOKED:
6489 ieee->privacy_invoked = param->value;
6490 break;
6491
6492 default:
6493 return -EOPNOTSUPP;
6494 }
6495 return ret;
6496}
6497
6498/* SIOCGIWAUTH */
6499static int ipw_wx_get_auth(struct net_device *dev,
6500 struct iw_request_info *info,
6501 union iwreq_data *wrqu, char *extra)
6502{
6503 struct ipw_priv *priv = ieee80211_priv(dev);
6504 struct ieee80211_device *ieee = priv->ieee;
6505 struct ieee80211_crypt_data *crypt;
6506 struct iw_param *param = &wrqu->param;
6507 int ret = 0;
6508
6509 switch (param->flags & IW_AUTH_INDEX) {
6510 case IW_AUTH_WPA_VERSION:
6511 case IW_AUTH_CIPHER_PAIRWISE:
6512 case IW_AUTH_CIPHER_GROUP:
6513 case IW_AUTH_KEY_MGMT:
6514 /*
6515 * wpa_supplicant will control these internally
6516 */
6517 ret = -EOPNOTSUPP;
6518 break;
6519
6520 case IW_AUTH_TKIP_COUNTERMEASURES:
6521 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006522 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006523 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006524
6525 param->value = (crypt->ops->get_flags(crypt->priv) &
6526 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6527
6528 break;
6529
6530 case IW_AUTH_DROP_UNENCRYPTED:
6531 param->value = ieee->drop_unencrypted;
6532 break;
6533
6534 case IW_AUTH_80211_AUTH_ALG:
6535 param->value = ieee->sec.auth_mode;
6536 break;
6537
6538 case IW_AUTH_WPA_ENABLED:
6539 param->value = ieee->wpa_enabled;
6540 break;
6541
6542 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6543 param->value = ieee->ieee802_1x;
6544 break;
6545
6546 case IW_AUTH_ROAMING_CONTROL:
6547 case IW_AUTH_PRIVACY_INVOKED:
6548 param->value = ieee->privacy_invoked;
6549 break;
6550
6551 default:
6552 return -EOPNOTSUPP;
6553 }
6554 return 0;
6555}
6556
6557/* SIOCSIWENCODEEXT */
6558static int ipw_wx_set_encodeext(struct net_device *dev,
6559 struct iw_request_info *info,
6560 union iwreq_data *wrqu, char *extra)
6561{
6562 struct ipw_priv *priv = ieee80211_priv(dev);
6563 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6564
6565 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006566 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006567 /* IPW HW can't build TKIP MIC,
6568 host decryption still needed */
6569 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6570 priv->ieee->host_mc_decrypt = 1;
6571 else {
6572 priv->ieee->host_encrypt = 0;
6573 priv->ieee->host_encrypt_msdu = 1;
6574 priv->ieee->host_decrypt = 1;
6575 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006576 } else {
6577 priv->ieee->host_encrypt = 0;
6578 priv->ieee->host_encrypt_msdu = 0;
6579 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006580 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006581 }
6582 }
6583
6584 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6585}
6586
6587/* SIOCGIWENCODEEXT */
6588static int ipw_wx_get_encodeext(struct net_device *dev,
6589 struct iw_request_info *info,
6590 union iwreq_data *wrqu, char *extra)
6591{
6592 struct ipw_priv *priv = ieee80211_priv(dev);
6593 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6594}
6595
6596/* SIOCSIWMLME */
6597static int ipw_wx_set_mlme(struct net_device *dev,
6598 struct iw_request_info *info,
6599 union iwreq_data *wrqu, char *extra)
6600{
6601 struct ipw_priv *priv = ieee80211_priv(dev);
6602 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6603 u16 reason;
6604
6605 reason = cpu_to_le16(mlme->reason_code);
6606
6607 switch (mlme->cmd) {
6608 case IW_MLME_DEAUTH:
6609 // silently ignore
6610 break;
6611
6612 case IW_MLME_DISASSOC:
6613 ipw_disassociate(priv);
6614 break;
6615
6616 default:
6617 return -EOPNOTSUPP;
6618 }
6619 return 0;
6620}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006621
James Ketrenosb095c382005-08-24 22:04:42 -05006622#ifdef CONFIG_IPW_QOS
6623
6624/* QoS */
6625/*
6626* get the modulation type of the current network or
6627* the card current mode
6628*/
6629u8 ipw_qos_current_mode(struct ipw_priv * priv)
6630{
6631 u8 mode = 0;
6632
6633 if (priv->status & STATUS_ASSOCIATED) {
6634 unsigned long flags;
6635
6636 spin_lock_irqsave(&priv->ieee->lock, flags);
6637 mode = priv->assoc_network->mode;
6638 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6639 } else {
6640 mode = priv->ieee->mode;
6641 }
6642 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6643 return mode;
6644}
6645
6646/*
6647* Handle management frame beacon and probe response
6648*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006649static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6650 int active_network,
6651 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006652{
6653 u32 size = sizeof(struct ieee80211_qos_parameters);
6654
James Ketrenosafbf30a2005-08-25 00:05:33 -05006655 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006656 network->qos_data.active = network->qos_data.supported;
6657
6658 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006659 if (active_network &&
6660 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006661 network->qos_data.active = network->qos_data.supported;
6662
6663 if ((network->qos_data.active == 1) && (active_network == 1) &&
6664 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6665 (network->qos_data.old_param_count !=
6666 network->qos_data.param_count)) {
6667 network->qos_data.old_param_count =
6668 network->qos_data.param_count;
6669 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006670 IPW_DEBUG_QOS("QoS parameters change call "
6671 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006672 }
6673 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006674 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6675 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006676 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006677 else
6678 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006679 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006680
James Ketrenosb095c382005-08-24 22:04:42 -05006681 if ((network->qos_data.active == 1) && (active_network == 1)) {
6682 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6683 schedule_work(&priv->qos_activate);
6684 }
6685
6686 network->qos_data.active = 0;
6687 network->qos_data.supported = 0;
6688 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006689 if ((priv->status & STATUS_ASSOCIATED) &&
6690 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6691 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6692 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6693 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006694 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006695 priv->assoc_network->ssid_len) &&
6696 !memcmp(network->ssid,
6697 priv->assoc_network->ssid,
6698 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006699 queue_work(priv->workqueue,
6700 &priv->merge_networks);
6701 }
James Ketrenosb095c382005-08-24 22:04:42 -05006702 }
6703
6704 return 0;
6705}
6706
6707/*
6708* This function set up the firmware to support QoS. It sends
6709* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6710*/
6711static int ipw_qos_activate(struct ipw_priv *priv,
6712 struct ieee80211_qos_data *qos_network_data)
6713{
6714 int err;
6715 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6716 struct ieee80211_qos_parameters *active_one = NULL;
6717 u32 size = sizeof(struct ieee80211_qos_parameters);
6718 u32 burst_duration;
6719 int i;
6720 u8 type;
6721
6722 type = ipw_qos_current_mode(priv);
6723
6724 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6725 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6726 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6727 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6728
6729 if (qos_network_data == NULL) {
6730 if (type == IEEE_B) {
6731 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6732 active_one = &def_parameters_CCK;
6733 } else
6734 active_one = &def_parameters_OFDM;
6735
James Ketrenosafbf30a2005-08-25 00:05:33 -05006736 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006737 burst_duration = ipw_qos_get_burst_duration(priv);
6738 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006739 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6740 (u16) burst_duration;
6741 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006742 if (type == IEEE_B) {
6743 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6744 type);
6745 if (priv->qos_data.qos_enable == 0)
6746 active_one = &def_parameters_CCK;
6747 else
6748 active_one = priv->qos_data.def_qos_parm_CCK;
6749 } else {
6750 if (priv->qos_data.qos_enable == 0)
6751 active_one = &def_parameters_OFDM;
6752 else
6753 active_one = priv->qos_data.def_qos_parm_OFDM;
6754 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006755 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006756 } else {
6757 unsigned long flags;
6758 int active;
6759
6760 spin_lock_irqsave(&priv->ieee->lock, flags);
6761 active_one = &(qos_network_data->parameters);
6762 qos_network_data->old_param_count =
6763 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006764 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006765 active = qos_network_data->supported;
6766 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6767
6768 if (active == 0) {
6769 burst_duration = ipw_qos_get_burst_duration(priv);
6770 for (i = 0; i < QOS_QUEUE_NUM; i++)
6771 qos_parameters[QOS_PARAM_SET_ACTIVE].
6772 tx_op_limit[i] = (u16) burst_duration;
6773 }
6774 }
6775
6776 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006777 err = ipw_send_qos_params_command(priv,
6778 (struct ieee80211_qos_parameters *)
6779 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006780 if (err)
6781 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6782
6783 return err;
6784}
6785
6786/*
6787* send IPW_CMD_WME_INFO to the firmware
6788*/
6789static int ipw_qos_set_info_element(struct ipw_priv *priv)
6790{
6791 int ret = 0;
6792 struct ieee80211_qos_information_element qos_info;
6793
6794 if (priv == NULL)
6795 return -1;
6796
6797 qos_info.elementID = QOS_ELEMENT_ID;
6798 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6799
6800 qos_info.version = QOS_VERSION_1;
6801 qos_info.ac_info = 0;
6802
6803 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6804 qos_info.qui_type = QOS_OUI_TYPE;
6805 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6806
6807 ret = ipw_send_qos_info_command(priv, &qos_info);
6808 if (ret != 0) {
6809 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6810 }
6811 return ret;
6812}
6813
6814/*
6815* Set the QoS parameter with the association request structure
6816*/
6817static int ipw_qos_association(struct ipw_priv *priv,
6818 struct ieee80211_network *network)
6819{
6820 int err = 0;
6821 struct ieee80211_qos_data *qos_data = NULL;
6822 struct ieee80211_qos_data ibss_data = {
6823 .supported = 1,
6824 .active = 1,
6825 };
6826
6827 switch (priv->ieee->iw_mode) {
6828 case IW_MODE_ADHOC:
6829 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6830 BUG();
6831
6832 qos_data = &ibss_data;
6833 break;
6834
6835 case IW_MODE_INFRA:
6836 qos_data = &network->qos_data;
6837 break;
6838
6839 default:
6840 BUG();
6841 break;
6842 }
6843
6844 err = ipw_qos_activate(priv, qos_data);
6845 if (err) {
6846 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6847 return err;
6848 }
6849
6850 if (priv->qos_data.qos_enable && qos_data->supported) {
6851 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6852 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6853 return ipw_qos_set_info_element(priv);
6854 }
6855
6856 return 0;
6857}
6858
6859/*
6860* handling the beaconing responces. if we get different QoS setting
6861* of the network from the the associated setting adjust the QoS
6862* setting
6863*/
6864static int ipw_qos_association_resp(struct ipw_priv *priv,
6865 struct ieee80211_network *network)
6866{
6867 int ret = 0;
6868 unsigned long flags;
6869 u32 size = sizeof(struct ieee80211_qos_parameters);
6870 int set_qos_param = 0;
6871
James Ketrenosafbf30a2005-08-25 00:05:33 -05006872 if ((priv == NULL) || (network == NULL) ||
6873 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006874 return ret;
6875
6876 if (!(priv->status & STATUS_ASSOCIATED))
6877 return ret;
6878
James Ketrenosafbf30a2005-08-25 00:05:33 -05006879 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006880 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006881
6882 spin_lock_irqsave(&priv->ieee->lock, flags);
6883 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006884 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006885 sizeof(struct ieee80211_qos_data));
6886 priv->assoc_network->qos_data.active = 1;
6887 if ((network->qos_data.old_param_count !=
6888 network->qos_data.param_count)) {
6889 set_qos_param = 1;
6890 network->qos_data.old_param_count =
6891 network->qos_data.param_count;
6892 }
6893
6894 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006895 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6896 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006897 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006898 else
6899 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006900 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006901 priv->assoc_network->qos_data.active = 0;
6902 priv->assoc_network->qos_data.supported = 0;
6903 set_qos_param = 1;
6904 }
6905
6906 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6907
6908 if (set_qos_param == 1)
6909 schedule_work(&priv->qos_activate);
6910
6911 return ret;
6912}
6913
6914static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6915{
6916 u32 ret = 0;
6917
6918 if ((priv == NULL))
6919 return 0;
6920
James Ketrenosafbf30a2005-08-25 00:05:33 -05006921 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006922 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006923 else
James Ketrenosb095c382005-08-24 22:04:42 -05006924 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006925
James Ketrenosb095c382005-08-24 22:04:42 -05006926 return ret;
6927}
6928
6929/*
6930* Initialize the setting of QoS global
6931*/
6932static void ipw_qos_init(struct ipw_priv *priv, int enable,
6933 int burst_enable, u32 burst_duration_CCK,
6934 u32 burst_duration_OFDM)
6935{
6936 priv->qos_data.qos_enable = enable;
6937
6938 if (priv->qos_data.qos_enable) {
6939 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6940 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6941 IPW_DEBUG_QOS("QoS is enabled\n");
6942 } else {
6943 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6944 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6945 IPW_DEBUG_QOS("QoS is not enabled\n");
6946 }
6947
6948 priv->qos_data.burst_enable = burst_enable;
6949
6950 if (burst_enable) {
6951 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6952 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6953 } else {
6954 priv->qos_data.burst_duration_CCK = 0;
6955 priv->qos_data.burst_duration_OFDM = 0;
6956 }
6957}
6958
6959/*
6960* map the packet priority to the right TX Queue
6961*/
6962static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6963{
6964 if (priority > 7 || !priv->qos_data.qos_enable)
6965 priority = 0;
6966
6967 return from_priority_to_tx_queue[priority] - 1;
6968}
6969
6970/*
6971* add QoS parameter to the TX command
6972*/
6973static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6974 u16 priority,
6975 struct tfd_data *tfd, u8 unicast)
6976{
6977 int ret = 0;
6978 int tx_queue_id = 0;
6979 struct ieee80211_qos_data *qos_data = NULL;
6980 int active, supported;
6981 unsigned long flags;
6982
6983 if (!(priv->status & STATUS_ASSOCIATED))
6984 return 0;
6985
6986 qos_data = &priv->assoc_network->qos_data;
6987
6988 spin_lock_irqsave(&priv->ieee->lock, flags);
6989
6990 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6991 if (unicast == 0)
6992 qos_data->active = 0;
6993 else
6994 qos_data->active = qos_data->supported;
6995 }
6996
6997 active = qos_data->active;
6998 supported = qos_data->supported;
6999
7000 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7001
James Ketrenosafbf30a2005-08-25 00:05:33 -05007002 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7003 "unicast %d\n",
7004 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05007005 if (active && priv->qos_data.qos_enable) {
7006 ret = from_priority_to_tx_queue[priority];
7007 tx_queue_id = ret - 1;
7008 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
7009 if (priority <= 7) {
7010 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7011 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
7012 tfd->tfd.tfd_26.mchdr.frame_ctl |=
7013 IEEE80211_STYPE_QOS_DATA;
7014
7015 if (priv->qos_data.qos_no_ack_mask &
7016 (1UL << tx_queue_id)) {
7017 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7018 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
7019 CTRL_QOS_NO_ACK;
7020 }
7021 }
7022 }
7023
7024 return ret;
7025}
7026
7027/*
7028* background support to run QoS activate functionality
7029*/
7030static void ipw_bg_qos_activate(void *data)
7031{
7032 struct ipw_priv *priv = data;
7033
7034 if (priv == NULL)
7035 return;
7036
7037 down(&priv->sem);
7038
7039 if (priv->status & STATUS_ASSOCIATED)
7040 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7041
7042 up(&priv->sem);
7043}
7044
James Ketrenos3b9990c2005-08-19 13:18:55 -05007045static int ipw_handle_probe_response(struct net_device *dev,
7046 struct ieee80211_probe_response *resp,
7047 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007048{
7049 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007050 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7051 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007052
James Ketrenos3b9990c2005-08-19 13:18:55 -05007053 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007054
James Ketrenos3b9990c2005-08-19 13:18:55 -05007055 return 0;
7056}
James Ketrenosb095c382005-08-24 22:04:42 -05007057
James Ketrenos3b9990c2005-08-19 13:18:55 -05007058static int ipw_handle_beacon(struct net_device *dev,
7059 struct ieee80211_beacon *resp,
7060 struct ieee80211_network *network)
7061{
7062 struct ipw_priv *priv = ieee80211_priv(dev);
7063 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7064 (network == priv->assoc_network));
7065
7066 ipw_qos_handle_probe_response(priv, active_network, network);
7067
7068 return 0;
7069}
7070
7071static int ipw_handle_assoc_response(struct net_device *dev,
7072 struct ieee80211_assoc_response *resp,
7073 struct ieee80211_network *network)
7074{
7075 struct ipw_priv *priv = ieee80211_priv(dev);
7076 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007077 return 0;
7078}
7079
7080static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7081 *qos_param)
7082{
7083 struct host_cmd cmd = {
7084 .cmd = IPW_CMD_QOS_PARAMETERS,
7085 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7086 };
7087
James Ketrenosafbf30a2005-08-25 00:05:33 -05007088 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007089 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007090}
7091
7092static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7093 *qos_param)
7094{
7095 struct host_cmd cmd = {
7096 .cmd = IPW_CMD_WME_INFO,
7097 .len = sizeof(*qos_param)
7098 };
7099
James Ketrenosafbf30a2005-08-25 00:05:33 -05007100 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007101 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007102}
7103
7104#endif /* CONFIG_IPW_QOS */
7105
James Ketrenos43f66a62005-03-25 12:31:53 -06007106static int ipw_associate_network(struct ipw_priv *priv,
7107 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007108 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007109{
7110 int err;
7111
7112 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007113 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007114
7115 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007116 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007117 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007118 memcpy(priv->essid, network->ssid, priv->essid_len);
7119 }
7120
7121 network->last_associate = jiffies;
7122
7123 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7124 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007125 priv->assoc_request.auth_key = 0;
7126
James Ketrenos43f66a62005-03-25 12:31:53 -06007127 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007128 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007129 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007130 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7131
Zhu Yi3e234b42006-01-24 16:36:52 +08007132 if ((priv->ieee->sec.level == SEC_LEVEL_1) &&
James Ketrenosb095c382005-08-24 22:04:42 -05007133 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7134 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007135
7136 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7137 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7138 priv->assoc_request.auth_type = AUTH_LEAP;
7139 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007140 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007141
James Ketrenosa613bff2005-08-24 21:43:11 -05007142 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007143 priv->assoc_request.policy_support = 0x02; /* RSN active */
7144 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7145 priv->ieee->wpa_ie_len);
7146 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007147
Jeff Garzikbf794512005-07-31 13:07:26 -04007148 /*
7149 * It is valid for our ieee device to support multiple modes, but
7150 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007151 * just one mode.
7152 */
7153 if (network->mode & priv->ieee->mode & IEEE_A)
7154 priv->assoc_request.ieee_mode = IPW_A_MODE;
7155 else if (network->mode & priv->ieee->mode & IEEE_G)
7156 priv->assoc_request.ieee_mode = IPW_G_MODE;
7157 else if (network->mode & priv->ieee->mode & IEEE_B)
7158 priv->assoc_request.ieee_mode = IPW_B_MODE;
7159
James Ketrenosea2b26e2005-08-24 21:25:16 -05007160 priv->assoc_request.capability = network->capability;
7161 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7162 && !(priv->config & CFG_PREAMBLE_LONG)) {
7163 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7164 } else {
7165 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7166
7167 /* Clear the short preamble if we won't be supporting it */
7168 priv->assoc_request.capability &=
7169 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7170 }
7171
James Ketrenosafbf30a2005-08-25 00:05:33 -05007172 /* Clear capability bits that aren't used in Ad Hoc */
7173 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7174 priv->assoc_request.capability &=
7175 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7176
James Ketrenos43f66a62005-03-25 12:31:53 -06007177 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007178 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007179 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007180 escape_essid(priv->essid, priv->essid_len),
7181 network->channel,
7182 ipw_modes[priv->assoc_request.ieee_mode],
7183 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007184 (priv->assoc_request.preamble_length ==
7185 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7186 network->capability &
7187 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007188 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007189 priv->capability & CAP_PRIVACY_ON ?
7190 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007191 "(open)") : "",
7192 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007193 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007194 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007195 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007196
7197 priv->assoc_request.beacon_interval = network->beacon_interval;
7198 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007199 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007200 priv->assoc_request.assoc_type = HC_IBSS_START;
7201 priv->assoc_request.assoc_tsf_msw = 0;
7202 priv->assoc_request.assoc_tsf_lsw = 0;
7203 } else {
7204 if (unlikely(roaming))
7205 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7206 else
7207 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7208 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7209 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7210 }
7211
James Ketrenosafbf30a2005-08-25 00:05:33 -05007212 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007213
7214 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7215 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7216 priv->assoc_request.atim_window = network->atim_window;
7217 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007218 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007219 priv->assoc_request.atim_window = 0;
7220 }
7221
James Ketrenos43f66a62005-03-25 12:31:53 -06007222 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007223
James Ketrenos43f66a62005-03-25 12:31:53 -06007224 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7225 if (err) {
7226 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7227 return err;
7228 }
7229
7230 rates->ieee_mode = priv->assoc_request.ieee_mode;
7231 rates->purpose = IPW_RATE_CONNECT;
7232 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007233
James Ketrenos43f66a62005-03-25 12:31:53 -06007234 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7235 priv->sys_config.dot11g_auto_detection = 1;
7236 else
7237 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007238
7239 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7240 priv->sys_config.answer_broadcast_ssid_probe = 1;
7241 else
7242 priv->sys_config.answer_broadcast_ssid_probe = 0;
7243
James Ketrenos43f66a62005-03-25 12:31:53 -06007244 err = ipw_send_system_config(priv, &priv->sys_config);
7245 if (err) {
7246 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7247 return err;
7248 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007249
James Ketrenos43f66a62005-03-25 12:31:53 -06007250 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007251 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007252 if (err) {
7253 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7254 return err;
7255 }
7256
7257 /*
7258 * If preemption is enabled, it is possible for the association
7259 * to complete before we return from ipw_send_associate. Therefore
7260 * we have to be sure and update our priviate data first.
7261 */
7262 priv->channel = network->channel;
7263 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007264 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007265 priv->status &= ~STATUS_SECURITY_UPDATED;
7266
7267 priv->assoc_network = network;
7268
James Ketrenosb095c382005-08-24 22:04:42 -05007269#ifdef CONFIG_IPW_QOS
7270 ipw_qos_association(priv, network);
7271#endif
7272
James Ketrenos43f66a62005-03-25 12:31:53 -06007273 err = ipw_send_associate(priv, &priv->assoc_request);
7274 if (err) {
7275 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7276 return err;
7277 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007278
7279 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007280 escape_essid(priv->essid, priv->essid_len),
7281 MAC_ARG(priv->bssid));
7282
7283 return 0;
7284}
7285
7286static void ipw_roam(void *data)
7287{
7288 struct ipw_priv *priv = data;
7289 struct ieee80211_network *network = NULL;
7290 struct ipw_network_match match = {
7291 .network = priv->assoc_network
7292 };
7293
7294 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007295 *
7296 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007297 * setting the status ROAM bit and requesting a scan.
7298 * 2. When the scan completes, it schedules the ROAM work
7299 * 3. The ROAM work looks at all of the known networks for one that
7300 * is a better network than the currently associated. If none
7301 * found, the ROAM process is over (ROAM bit cleared)
7302 * 4. If a better network is found, a disassociation request is
7303 * sent.
7304 * 5. When the disassociation completes, the roam work is again
7305 * scheduled. The second time through, the driver is no longer
7306 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007307 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007308 * 6. At this point ,the roaming process is complete and the ROAM
7309 * status bit is cleared.
7310 */
7311
7312 /* If we are no longer associated, and the roaming bit is no longer
7313 * set, then we are not actively roaming, so just return */
7314 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7315 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007316
James Ketrenos43f66a62005-03-25 12:31:53 -06007317 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007318 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007319 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007320 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007321 u8 rssi = priv->assoc_network->stats.rssi;
7322 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007323 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007324 list_for_each_entry(network, &priv->ieee->network_list, list) {
7325 if (network != priv->assoc_network)
7326 ipw_best_network(priv, &match, network, 1);
7327 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007328 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007329 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007330
James Ketrenos43f66a62005-03-25 12:31:53 -06007331 if (match.network == priv->assoc_network) {
7332 IPW_DEBUG_ASSOC("No better APs in this network to "
7333 "roam to.\n");
7334 priv->status &= ~STATUS_ROAMING;
7335 ipw_debug_config(priv);
7336 return;
7337 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007338
James Ketrenos43f66a62005-03-25 12:31:53 -06007339 ipw_send_disassociate(priv, 1);
7340 priv->assoc_network = match.network;
7341
7342 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007343 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007344
7345 /* Second pass through ROAM process -- request association */
7346 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7347 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7348 priv->status &= ~STATUS_ROAMING;
7349}
7350
James Ketrenosc848d0a2005-08-24 21:56:24 -05007351static void ipw_bg_roam(void *data)
7352{
7353 struct ipw_priv *priv = data;
7354 down(&priv->sem);
7355 ipw_roam(data);
7356 up(&priv->sem);
7357}
7358
7359static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007360{
7361 struct ipw_priv *priv = data;
7362
7363 struct ieee80211_network *network = NULL;
7364 struct ipw_network_match match = {
7365 .network = NULL
7366 };
7367 struct ipw_supported_rates *rates;
7368 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007369 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007370
James Ketrenosb095c382005-08-24 22:04:42 -05007371 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7372 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7373 return 0;
7374 }
7375
James Ketrenosc848d0a2005-08-24 21:56:24 -05007376 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007377 IPW_DEBUG_ASSOC("Not attempting association (already in "
7378 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007379 return 0;
7380 }
7381
Hong Liue6324722005-09-14 21:04:15 -05007382 if (priv->status & STATUS_DISASSOCIATING) {
7383 IPW_DEBUG_ASSOC("Not attempting association (in "
7384 "disassociating)\n ");
7385 queue_work(priv->workqueue, &priv->associate);
7386 return 0;
7387 }
7388
James Ketrenosc848d0a2005-08-24 21:56:24 -05007389 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007390 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7391 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007392 return 0;
7393 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007394
7395 if (!(priv->config & CFG_ASSOCIATE) &&
7396 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007397 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007398 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007399 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007400 }
7401
James Ketrenosa613bff2005-08-24 21:43:11 -05007402 /* Protect our use of the network_list */
7403 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007404 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007405 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007406
7407 network = match.network;
7408 rates = &match.rates;
7409
7410 if (network == NULL &&
7411 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7412 priv->config & CFG_ADHOC_CREATE &&
7413 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007414 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007415 !list_empty(&priv->ieee->network_free_list)) {
7416 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007417 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007418 ipw_adhoc_create(priv, network);
7419 rates = &priv->rates;
7420 list_del(element);
7421 list_add_tail(&network->list, &priv->ieee->network_list);
7422 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007423 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007424
James Ketrenos43f66a62005-03-25 12:31:53 -06007425 /* If we reached the end of the list, then we don't have any valid
7426 * matching APs */
7427 if (!network) {
7428 ipw_debug_config(priv);
7429
James Ketrenosb095c382005-08-24 22:04:42 -05007430 if (!(priv->status & STATUS_SCANNING)) {
7431 if (!(priv->config & CFG_SPEED_SCAN))
7432 queue_delayed_work(priv->workqueue,
7433 &priv->request_scan,
7434 SCAN_INTERVAL);
7435 else
7436 queue_work(priv->workqueue,
7437 &priv->request_scan);
7438 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007439
James Ketrenosc848d0a2005-08-24 21:56:24 -05007440 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007441 }
7442
7443 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007444
7445 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007446}
Jeff Garzikbf794512005-07-31 13:07:26 -04007447
James Ketrenosc848d0a2005-08-24 21:56:24 -05007448static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007449{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007450 struct ipw_priv *priv = data;
7451 down(&priv->sem);
7452 ipw_associate(data);
7453 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007454}
7455
James Ketrenosb095c382005-08-24 22:04:42 -05007456static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7457 struct sk_buff *skb)
7458{
7459 struct ieee80211_hdr *hdr;
7460 u16 fc;
7461
7462 hdr = (struct ieee80211_hdr *)skb->data;
7463 fc = le16_to_cpu(hdr->frame_ctl);
7464 if (!(fc & IEEE80211_FCTL_PROTECTED))
7465 return;
7466
7467 fc &= ~IEEE80211_FCTL_PROTECTED;
7468 hdr->frame_ctl = cpu_to_le16(fc);
7469 switch (priv->ieee->sec.level) {
7470 case SEC_LEVEL_3:
7471 /* Remove CCMP HDR */
7472 memmove(skb->data + IEEE80211_3ADDR_LEN,
7473 skb->data + IEEE80211_3ADDR_LEN + 8,
7474 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007475 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007476 break;
7477 case SEC_LEVEL_2:
7478 break;
7479 case SEC_LEVEL_1:
7480 /* Remove IV */
7481 memmove(skb->data + IEEE80211_3ADDR_LEN,
7482 skb->data + IEEE80211_3ADDR_LEN + 4,
7483 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007484 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007485 break;
7486 case SEC_LEVEL_0:
7487 break;
7488 default:
7489 printk(KERN_ERR "Unknow security level %d\n",
7490 priv->ieee->sec.level);
7491 break;
7492 }
7493}
7494
7495static void ipw_handle_data_packet(struct ipw_priv *priv,
7496 struct ipw_rx_mem_buffer *rxb,
7497 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007498{
Hong Liu567deaf2005-08-31 18:07:22 +08007499 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007500 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7501
7502 /* We received data from the HW, so stop the watchdog */
7503 priv->net_dev->trans_start = jiffies;
7504
Jeff Garzikbf794512005-07-31 13:07:26 -04007505 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007506 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007507 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007508 skb_tailroom(rxb->skb))) {
7509 priv->ieee->stats.rx_errors++;
7510 priv->wstats.discard.misc++;
7511 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7512 return;
7513 } else if (unlikely(!netif_running(priv->net_dev))) {
7514 priv->ieee->stats.rx_dropped++;
7515 priv->wstats.discard.misc++;
7516 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7517 return;
7518 }
7519
7520 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007521 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007522
7523 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007524 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007525
7526 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7527
James Ketrenosb095c382005-08-24 22:04:42 -05007528 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007529 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7530 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007531 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007532 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007533 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7534
Jeff Garzikbf794512005-07-31 13:07:26 -04007535 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007536 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007537 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007538 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007539 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007540 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007541}
7542
Mike Kershaw24a47db2005-08-26 00:41:54 -05007543#ifdef CONFIG_IEEE80211_RADIOTAP
7544static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7545 struct ipw_rx_mem_buffer *rxb,
7546 struct ieee80211_rx_stats *stats)
7547{
7548 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7549 struct ipw_rx_frame *frame = &pkt->u.frame;
7550
7551 /* initial pull of some data */
7552 u16 received_channel = frame->received_channel;
7553 u8 antennaAndPhy = frame->antennaAndPhy;
7554 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7555 u16 pktrate = frame->rate;
7556
7557 /* Magic struct that slots into the radiotap header -- no reason
7558 * to build this manually element by element, we can write it much
7559 * more efficiently than we can parse it. ORDER MATTERS HERE */
7560 struct ipw_rt_hdr {
7561 struct ieee80211_radiotap_header rt_hdr;
7562 u8 rt_flags; /* radiotap packet flags */
7563 u8 rt_rate; /* rate in 500kb/s */
7564 u16 rt_channel; /* channel in mhz */
7565 u16 rt_chbitmask; /* channel bitfield */
7566 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7567 u8 rt_antenna; /* antenna number */
7568 } *ipw_rt;
7569
7570 short len = le16_to_cpu(pkt->u.frame.length);
7571
7572 /* We received data from the HW, so stop the watchdog */
7573 priv->net_dev->trans_start = jiffies;
7574
7575 /* We only process data packets if the
7576 * interface is open */
7577 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7578 skb_tailroom(rxb->skb))) {
7579 priv->ieee->stats.rx_errors++;
7580 priv->wstats.discard.misc++;
7581 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7582 return;
7583 } else if (unlikely(!netif_running(priv->net_dev))) {
7584 priv->ieee->stats.rx_dropped++;
7585 priv->wstats.discard.misc++;
7586 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7587 return;
7588 }
7589
7590 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7591 * that now */
7592 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7593 /* FIXME: Should alloc bigger skb instead */
7594 priv->ieee->stats.rx_dropped++;
7595 priv->wstats.discard.misc++;
7596 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7597 return;
7598 }
7599
7600 /* copy the frame itself */
7601 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7602 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7603
7604 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7605 * part of our real header, saves a little time.
7606 *
7607 * No longer necessary since we fill in all our data. Purge before merging
7608 * patch officially.
7609 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7610 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7611 */
7612
7613 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7614
7615 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7616 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7617 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7618
7619 /* Big bitfield of all the fields we provide in radiotap */
7620 ipw_rt->rt_hdr.it_present =
7621 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7622 (1 << IEEE80211_RADIOTAP_RATE) |
7623 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7624 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7625 (1 << IEEE80211_RADIOTAP_ANTENNA));
7626
7627 /* Zero the flags, we'll add to them as we go */
7628 ipw_rt->rt_flags = 0;
7629
7630 /* Convert signal to DBM */
7631 ipw_rt->rt_dbmsignal = antsignal;
7632
7633 /* Convert the channel data and set the flags */
7634 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7635 if (received_channel > 14) { /* 802.11a */
7636 ipw_rt->rt_chbitmask =
7637 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7638 } else if (antennaAndPhy & 32) { /* 802.11b */
7639 ipw_rt->rt_chbitmask =
7640 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7641 } else { /* 802.11g */
7642 ipw_rt->rt_chbitmask =
7643 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7644 }
7645
7646 /* set the rate in multiples of 500k/s */
7647 switch (pktrate) {
7648 case IPW_TX_RATE_1MB:
7649 ipw_rt->rt_rate = 2;
7650 break;
7651 case IPW_TX_RATE_2MB:
7652 ipw_rt->rt_rate = 4;
7653 break;
7654 case IPW_TX_RATE_5MB:
7655 ipw_rt->rt_rate = 10;
7656 break;
7657 case IPW_TX_RATE_6MB:
7658 ipw_rt->rt_rate = 12;
7659 break;
7660 case IPW_TX_RATE_9MB:
7661 ipw_rt->rt_rate = 18;
7662 break;
7663 case IPW_TX_RATE_11MB:
7664 ipw_rt->rt_rate = 22;
7665 break;
7666 case IPW_TX_RATE_12MB:
7667 ipw_rt->rt_rate = 24;
7668 break;
7669 case IPW_TX_RATE_18MB:
7670 ipw_rt->rt_rate = 36;
7671 break;
7672 case IPW_TX_RATE_24MB:
7673 ipw_rt->rt_rate = 48;
7674 break;
7675 case IPW_TX_RATE_36MB:
7676 ipw_rt->rt_rate = 72;
7677 break;
7678 case IPW_TX_RATE_48MB:
7679 ipw_rt->rt_rate = 96;
7680 break;
7681 case IPW_TX_RATE_54MB:
7682 ipw_rt->rt_rate = 108;
7683 break;
7684 default:
7685 ipw_rt->rt_rate = 0;
7686 break;
7687 }
7688
7689 /* antenna number */
7690 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7691
7692 /* set the preamble flag if we have it */
7693 if ((antennaAndPhy & 64))
7694 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7695
7696 /* Set the size of the skb to the size of the frame */
7697 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007698
7699 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7700
7701 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7702 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007703 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007704 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007705 /* no LED during capture */
7706 }
7707}
7708#endif
7709
Arjan van de Ven858119e2006-01-14 13:20:43 -08007710static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007711 struct ieee80211_hdr_4addr *header)
7712{
7713 /* Filter incoming packets to determine if they are targetted toward
7714 * this network, discarding packets coming from ourselves */
7715 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007716 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007717 /* packets from our adapter are dropped (echo) */
7718 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7719 return 0;
7720
Peter Jones90700fd2005-08-26 16:51:06 -05007721 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007722 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007723 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007724
7725 /* packets to our adapter go through */
7726 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7727 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007728
Peter Jones90700fd2005-08-26 16:51:06 -05007729 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007730 /* packets from our adapter are dropped (echo) */
7731 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7732 return 0;
7733
Peter Jones90700fd2005-08-26 16:51:06 -05007734 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007735 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007736 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7737
7738 /* packets to our adapter go through */
7739 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7740 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007741 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007742
James Ketrenosea2b26e2005-08-24 21:25:16 -05007743 return 1;
7744}
7745
James Ketrenosafbf30a2005-08-25 00:05:33 -05007746#define IPW_PACKET_RETRY_TIME HZ
7747
Arjan van de Ven858119e2006-01-14 13:20:43 -08007748static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007749 struct ieee80211_hdr_4addr *header)
7750{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007751 u16 sc = le16_to_cpu(header->seq_ctl);
7752 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7753 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7754 u16 *last_seq, *last_frag;
7755 unsigned long *last_time;
7756
7757 switch (priv->ieee->iw_mode) {
7758 case IW_MODE_ADHOC:
7759 {
7760 struct list_head *p;
7761 struct ipw_ibss_seq *entry = NULL;
7762 u8 *mac = header->addr2;
7763 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7764
7765 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7766 entry =
7767 list_entry(p, struct ipw_ibss_seq, list);
7768 if (!memcmp(entry->mac, mac, ETH_ALEN))
7769 break;
7770 }
7771 if (p == &priv->ibss_mac_hash[index]) {
7772 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7773 if (!entry) {
7774 IPW_ERROR
7775 ("Cannot malloc new mac entry\n");
7776 return 0;
7777 }
7778 memcpy(entry->mac, mac, ETH_ALEN);
7779 entry->seq_num = seq;
7780 entry->frag_num = frag;
7781 entry->packet_time = jiffies;
7782 list_add(&entry->list,
7783 &priv->ibss_mac_hash[index]);
7784 return 0;
7785 }
7786 last_seq = &entry->seq_num;
7787 last_frag = &entry->frag_num;
7788 last_time = &entry->packet_time;
7789 break;
7790 }
7791 case IW_MODE_INFRA:
7792 last_seq = &priv->last_seq_num;
7793 last_frag = &priv->last_frag_num;
7794 last_time = &priv->last_packet_time;
7795 break;
7796 default:
7797 return 0;
7798 }
7799 if ((*last_seq == seq) &&
7800 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7801 if (*last_frag == frag)
7802 goto drop;
7803 if (*last_frag + 1 != frag)
7804 /* out-of-order fragment */
7805 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007806 } else
7807 *last_seq = seq;
7808
Zhu Yif57ce7c2005-07-13 12:22:15 -05007809 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007810 *last_time = jiffies;
7811 return 0;
7812
7813 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007814 /* Comment this line now since we observed the card receives
7815 * duplicate packets but the FCTL_RETRY bit is not set in the
7816 * IBSS mode with fragmentation enabled.
7817 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007818 return 1;
7819}
7820
James Ketrenosb095c382005-08-24 22:04:42 -05007821static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7822 struct ipw_rx_mem_buffer *rxb,
7823 struct ieee80211_rx_stats *stats)
7824{
7825 struct sk_buff *skb = rxb->skb;
7826 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7827 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7828 (skb->data + IPW_RX_FRAME_SIZE);
7829
7830 ieee80211_rx_mgt(priv->ieee, header, stats);
7831
7832 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7833 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7834 IEEE80211_STYPE_PROBE_RESP) ||
7835 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7836 IEEE80211_STYPE_BEACON))) {
7837 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7838 ipw_add_station(priv, header->addr2);
7839 }
7840
7841 if (priv->config & CFG_NET_STATS) {
7842 IPW_DEBUG_HC("sending stat packet\n");
7843
7844 /* Set the size of the skb to the size of the full
7845 * ipw header and 802.11 frame */
7846 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7847 IPW_RX_FRAME_SIZE);
7848
7849 /* Advance past the ipw packet header to the 802.11 frame */
7850 skb_pull(skb, IPW_RX_FRAME_SIZE);
7851
7852 /* Push the ieee80211_rx_stats before the 802.11 frame */
7853 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7854
7855 skb->dev = priv->ieee->dev;
7856
7857 /* Point raw at the ieee80211_stats */
7858 skb->mac.raw = skb->data;
7859
7860 skb->pkt_type = PACKET_OTHERHOST;
7861 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7862 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7863 netif_rx(skb);
7864 rxb->skb = NULL;
7865 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007866}
7867
James Ketrenos43f66a62005-03-25 12:31:53 -06007868/*
7869 * Main entry function for recieving a packet with 80211 headers. This
7870 * should be called when ever the FW has notified us that there is a new
7871 * skb in the recieve queue.
7872 */
7873static void ipw_rx(struct ipw_priv *priv)
7874{
7875 struct ipw_rx_mem_buffer *rxb;
7876 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007877 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007878 u32 r, w, i;
7879 u8 network_packet;
7880
James Ketrenosb095c382005-08-24 22:04:42 -05007881 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7882 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007883 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7884
7885 while (i != r) {
7886 rxb = priv->rxq->queue[i];
Brice Goglin0f52bf92005-12-01 01:41:46 -08007887#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06007888 if (unlikely(rxb == NULL)) {
7889 printk(KERN_CRIT "Queue not allocated!\n");
7890 break;
7891 }
7892#endif
7893 priv->rxq->queue[i] = NULL;
7894
7895 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007896 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007897 PCI_DMA_FROMDEVICE);
7898
7899 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7900 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7901 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007902 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007903
7904 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007905 case RX_FRAME_TYPE: /* 802.11 frame */ {
7906 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007907 .rssi =
7908 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007909 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007910 .signal =
7911 le16_to_cpu(pkt->u.frame.signal),
7912 .noise =
7913 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007914 .rate = pkt->u.frame.rate,
7915 .mac_time = jiffies,
7916 .received_channel =
7917 pkt->u.frame.received_channel,
7918 .freq =
7919 (pkt->u.frame.
7920 control & (1 << 0)) ?
7921 IEEE80211_24GHZ_BAND :
7922 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007923 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007924 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007925
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007926 if (stats.rssi != 0)
7927 stats.mask |= IEEE80211_STATMASK_RSSI;
7928 if (stats.signal != 0)
7929 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007930 if (stats.noise != 0)
7931 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007932 if (stats.rate != 0)
7933 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007934
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007935 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007936
James Ketrenosb095c382005-08-24 22:04:42 -05007937#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007938 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007939#ifdef CONFIG_IEEE80211_RADIOTAP
7940 ipw_handle_data_packet_monitor(priv,
7941 rxb,
7942 &stats);
7943#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007944 ipw_handle_data_packet(priv, rxb,
7945 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007946#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007947 break;
7948 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007949#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007950
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007951 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007952 (struct ieee80211_hdr_4addr *)(rxb->skb->
7953 data +
7954 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007955 /* TODO: Check Ad-Hoc dest/source and make sure
7956 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007957 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007958 * frame control of the packet and disregard
7959 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007960
James Ketrenosea2b26e2005-08-24 21:25:16 -05007961 network_packet =
7962 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007963 if (network_packet && priv->assoc_network) {
7964 priv->assoc_network->stats.rssi =
7965 stats.rssi;
7966 average_add(&priv->average_rssi,
7967 stats.rssi);
7968 priv->last_rx_rssi = stats.rssi;
7969 }
7970
7971 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007972 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007973
James Ketrenosa613bff2005-08-24 21:43:11 -05007974 if (le16_to_cpu(pkt->u.frame.length) <
7975 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007976 IPW_DEBUG_DROP
7977 ("Received packet is too small. "
7978 "Dropping.\n");
7979 priv->ieee->stats.rx_errors++;
7980 priv->wstats.discard.misc++;
7981 break;
7982 }
7983
James Ketrenosa613bff2005-08-24 21:43:11 -05007984 switch (WLAN_FC_GET_TYPE
7985 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007986
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007987 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007988 ipw_handle_mgmt_packet(priv, rxb,
7989 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007990 break;
7991
7992 case IEEE80211_FTYPE_CTL:
7993 break;
7994
7995 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007996 if (unlikely(!network_packet ||
7997 is_duplicate_packet(priv,
7998 header)))
7999 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008000 IPW_DEBUG_DROP("Dropping: "
8001 MAC_FMT ", "
8002 MAC_FMT ", "
8003 MAC_FMT "\n",
8004 MAC_ARG(header->
8005 addr1),
8006 MAC_ARG(header->
8007 addr2),
8008 MAC_ARG(header->
8009 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008010 break;
8011 }
8012
8013 ipw_handle_data_packet(priv, rxb,
8014 &stats);
8015
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008016 break;
8017 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008018 break;
8019 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008020
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008021 case RX_HOST_NOTIFICATION_TYPE:{
8022 IPW_DEBUG_RX
8023 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008024 pkt->u.notification.subtype,
8025 pkt->u.notification.flags,
8026 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008027 ipw_rx_notification(priv, &pkt->u.notification);
8028 break;
8029 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008030
8031 default:
8032 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8033 pkt->header.message_type);
8034 break;
8035 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008036
8037 /* For now we just don't re-use anything. We can tweak this
8038 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008039 * fail to Rx correctly */
8040 if (rxb->skb != NULL) {
8041 dev_kfree_skb_any(rxb->skb);
8042 rxb->skb = NULL;
8043 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008044
James Ketrenos43f66a62005-03-25 12:31:53 -06008045 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008046 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008047 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008048
James Ketrenos43f66a62005-03-25 12:31:53 -06008049 i = (i + 1) % RX_QUEUE_SIZE;
8050 }
8051
8052 /* Backtrack one entry */
8053 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8054
8055 ipw_rx_queue_restock(priv);
8056}
8057
James Ketrenosafbf30a2005-08-25 00:05:33 -05008058#define DEFAULT_RTS_THRESHOLD 2304U
8059#define MIN_RTS_THRESHOLD 1U
8060#define MAX_RTS_THRESHOLD 2304U
8061#define DEFAULT_BEACON_INTERVAL 100U
8062#define DEFAULT_SHORT_RETRY_LIMIT 7U
8063#define DEFAULT_LONG_RETRY_LIMIT 4U
8064
8065static int ipw_sw_reset(struct ipw_priv *priv, int init)
James Ketrenos43f66a62005-03-25 12:31:53 -06008066{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008067 int band, modulation;
8068 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008069
James Ketrenosafbf30a2005-08-25 00:05:33 -05008070 /* Initialize module parameter values here */
8071 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008072
James Ketrenosafbf30a2005-08-25 00:05:33 -05008073 /* We default to disabling the LED code as right now it causes
8074 * too many systems to lock up... */
8075 if (!led)
8076 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008077
James Ketrenosafbf30a2005-08-25 00:05:33 -05008078 if (associate)
8079 priv->config |= CFG_ASSOCIATE;
8080 else
8081 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008082
James Ketrenosafbf30a2005-08-25 00:05:33 -05008083 if (auto_create)
8084 priv->config |= CFG_ADHOC_CREATE;
8085 else
8086 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8087
Zhu Yi17ed0812006-01-24 16:36:31 +08008088 priv->config &= ~CFG_STATIC_ESSID;
8089 priv->essid_len = 0;
8090 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8091
James Ketrenosafbf30a2005-08-25 00:05:33 -05008092 if (disable) {
8093 priv->status |= STATUS_RF_KILL_SW;
8094 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008095 }
8096
James Ketrenosafbf30a2005-08-25 00:05:33 -05008097 if (channel != 0) {
8098 priv->config |= CFG_STATIC_CHANNEL;
8099 priv->channel = channel;
8100 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8101 /* TODO: Validate that provided channel is in range */
8102 }
8103#ifdef CONFIG_IPW_QOS
8104 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8105 burst_duration_CCK, burst_duration_OFDM);
8106#endif /* CONFIG_IPW_QOS */
8107
8108 switch (mode) {
8109 case 1:
8110 priv->ieee->iw_mode = IW_MODE_ADHOC;
8111 priv->net_dev->type = ARPHRD_ETHER;
8112
8113 break;
8114#ifdef CONFIG_IPW2200_MONITOR
8115 case 2:
8116 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008117#ifdef CONFIG_IEEE80211_RADIOTAP
8118 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8119#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008120 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008121#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008122 break;
8123#endif
8124 default:
8125 case 0:
8126 priv->net_dev->type = ARPHRD_ETHER;
8127 priv->ieee->iw_mode = IW_MODE_INFRA;
8128 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008129 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008130
James Ketrenosafbf30a2005-08-25 00:05:33 -05008131 if (hwcrypto) {
8132 priv->ieee->host_encrypt = 0;
8133 priv->ieee->host_encrypt_msdu = 0;
8134 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008135 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008136 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008137 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008138
Zhu Yie402c932005-08-05 17:20:40 +08008139 /* IPW2200/2915 is abled to do hardware fragmentation. */
8140 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008141
James Ketrenosafbf30a2005-08-25 00:05:33 -05008142 if ((priv->pci_dev->device == 0x4223) ||
8143 (priv->pci_dev->device == 0x4224)) {
8144 if (init)
8145 printk(KERN_INFO DRV_NAME
8146 ": Detected Intel PRO/Wireless 2915ABG Network "
8147 "Connection\n");
8148 priv->ieee->abg_true = 1;
8149 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8150 modulation = IEEE80211_OFDM_MODULATION |
8151 IEEE80211_CCK_MODULATION;
8152 priv->adapter = IPW_2915ABG;
8153 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008154 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008155 if (init)
8156 printk(KERN_INFO DRV_NAME
8157 ": Detected Intel PRO/Wireless 2200BG Network "
8158 "Connection\n");
8159
8160 priv->ieee->abg_true = 0;
8161 band = IEEE80211_24GHZ_BAND;
8162 modulation = IEEE80211_OFDM_MODULATION |
8163 IEEE80211_CCK_MODULATION;
8164 priv->adapter = IPW_2200BG;
8165 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008166 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008167
James Ketrenosafbf30a2005-08-25 00:05:33 -05008168 priv->ieee->freq_band = band;
8169 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008170
James Ketrenosafbf30a2005-08-25 00:05:33 -05008171 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008172
James Ketrenosafbf30a2005-08-25 00:05:33 -05008173 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8174 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008175
James Ketrenosafbf30a2005-08-25 00:05:33 -05008176 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8177 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8178 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008179
James Ketrenosafbf30a2005-08-25 00:05:33 -05008180 /* If power management is turned on, default to AC mode */
8181 priv->power_mode = IPW_POWER_AC;
8182 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008183
Zhu Yi0ece35b2005-08-05 17:26:51 +08008184 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008185}
8186
8187/*
8188 * This file defines the Wireless Extension handlers. It does not
8189 * define any methods of hardware manipulation and relies on the
8190 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008191 *
8192 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008193 * function used to poll the hardware vs. making unecessary calls.
8194 *
8195 */
8196
Jeff Garzikbf794512005-07-31 13:07:26 -04008197static int ipw_wx_get_name(struct net_device *dev,
8198 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008199 union iwreq_data *wrqu, char *extra)
8200{
8201 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008202 down(&priv->sem);
8203 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008204 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008205 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008206 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008207 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008208 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8209 ipw_modes[priv->assoc_request.ieee_mode]);
8210 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008211 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008212 return 0;
8213}
8214
8215static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8216{
8217 if (channel == 0) {
8218 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8219 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008220 IPW_DEBUG_ASSOC("Attempting to associate with new "
8221 "parameters.\n");
8222 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008223 return 0;
8224 }
8225
8226 priv->config |= CFG_STATIC_CHANNEL;
8227
8228 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008229 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8230 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008231 return 0;
8232 }
8233
8234 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8235 priv->channel = channel;
8236
James Ketrenosb095c382005-08-24 22:04:42 -05008237#ifdef CONFIG_IPW2200_MONITOR
8238 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008239 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008240 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008241 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008242 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008243 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008244 }
8245
8246 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8247 udelay(10);
8248
8249 if (priv->status & STATUS_SCANNING)
8250 IPW_DEBUG_SCAN("Still scanning...\n");
8251 else
8252 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8253 1000 - i);
8254
8255 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008256 }
James Ketrenosb095c382005-08-24 22:04:42 -05008257#endif /* CONFIG_IPW2200_MONITOR */
8258
James Ketrenosc848d0a2005-08-24 21:56:24 -05008259 /* Network configuration changed -- force [re]association */
8260 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8261 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008262 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008263
8264 return 0;
8265}
8266
Jeff Garzikbf794512005-07-31 13:07:26 -04008267static int ipw_wx_set_freq(struct net_device *dev,
8268 struct iw_request_info *info,
8269 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008270{
8271 struct ipw_priv *priv = ieee80211_priv(dev);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008272 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008273 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008274 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008275 u8 channel, flags;
8276 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008277
James Ketrenosb095c382005-08-24 22:04:42 -05008278 if (fwrq->m == 0) {
8279 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8280 down(&priv->sem);
8281 ret = ipw_set_channel(priv, 0);
8282 up(&priv->sem);
8283 return ret;
8284 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008285 /* if setting by freq convert to channel */
8286 if (fwrq->e == 1) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05008287 channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008288 if (channel == 0)
8289 return -EINVAL;
8290 } else
8291 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008292
Liu Hong1fe0adb2005-08-19 09:33:10 -05008293 if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008294 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008295
Liu Hong1fe0adb2005-08-19 09:33:10 -05008296 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8297 i = ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008298 if (i == -1)
8299 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008300
8301 flags = (band == IEEE80211_24GHZ_BAND) ?
8302 geo->bg[i].flags : geo->a[i].flags;
8303 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008304 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8305 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008306 }
8307 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008308
James Ketrenos43f66a62005-03-25 12:31:53 -06008309 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008310 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008311 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008312 up(&priv->sem);
8313 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008314}
8315
Jeff Garzikbf794512005-07-31 13:07:26 -04008316static int ipw_wx_get_freq(struct net_device *dev,
8317 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008318 union iwreq_data *wrqu, char *extra)
8319{
8320 struct ipw_priv *priv = ieee80211_priv(dev);
8321
8322 wrqu->freq.e = 0;
8323
8324 /* If we are associated, trying to associate, or have a statically
8325 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008326 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008327 if (priv->config & CFG_STATIC_CHANNEL ||
8328 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8329 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008330 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008331 wrqu->freq.m = 0;
8332
James Ketrenosc848d0a2005-08-24 21:56:24 -05008333 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008334 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8335 return 0;
8336}
8337
Jeff Garzikbf794512005-07-31 13:07:26 -04008338static int ipw_wx_set_mode(struct net_device *dev,
8339 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008340 union iwreq_data *wrqu, char *extra)
8341{
8342 struct ipw_priv *priv = ieee80211_priv(dev);
8343 int err = 0;
8344
8345 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8346
James Ketrenos43f66a62005-03-25 12:31:53 -06008347 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008348#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008349 case IW_MODE_MONITOR:
8350#endif
8351 case IW_MODE_ADHOC:
8352 case IW_MODE_INFRA:
8353 break;
8354 case IW_MODE_AUTO:
8355 wrqu->mode = IW_MODE_INFRA;
8356 break;
8357 default:
8358 return -EINVAL;
8359 }
James Ketrenosb095c382005-08-24 22:04:42 -05008360 if (wrqu->mode == priv->ieee->iw_mode)
8361 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008362
James Ketrenosb095c382005-08-24 22:04:42 -05008363 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008364
8365 ipw_sw_reset(priv, 0);
8366
James Ketrenosb095c382005-08-24 22:04:42 -05008367#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008368 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008369 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008370
8371 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008372#ifdef CONFIG_IEEE80211_RADIOTAP
8373 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8374#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008375 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008376#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008377#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008378
Jeff Garzikbf794512005-07-31 13:07:26 -04008379 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008380 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008381 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008382
8383 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008384
James Ketrenosc848d0a2005-08-24 21:56:24 -05008385 queue_work(priv->workqueue, &priv->adapter_restart);
8386 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008387 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008388}
8389
Jeff Garzikbf794512005-07-31 13:07:26 -04008390static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008391 struct iw_request_info *info,
8392 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008393{
8394 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008395 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008396 wrqu->mode = priv->ieee->iw_mode;
8397 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008398 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008399 return 0;
8400}
8401
James Ketrenos43f66a62005-03-25 12:31:53 -06008402/* Values are in microsecond */
8403static const s32 timeout_duration[] = {
8404 350000,
8405 250000,
8406 75000,
8407 37000,
8408 25000,
8409};
8410
8411static const s32 period_duration[] = {
8412 400000,
8413 700000,
8414 1000000,
8415 1000000,
8416 1000000
8417};
8418
Jeff Garzikbf794512005-07-31 13:07:26 -04008419static int ipw_wx_get_range(struct net_device *dev,
8420 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008421 union iwreq_data *wrqu, char *extra)
8422{
8423 struct ipw_priv *priv = ieee80211_priv(dev);
8424 struct iw_range *range = (struct iw_range *)extra;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008425 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008426 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008427
8428 wrqu->data.length = sizeof(*range);
8429 memset(range, 0, sizeof(*range));
8430
8431 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008432 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008433
8434 range->max_qual.qual = 100;
8435 /* TODO: Find real max RSSI and stick here */
8436 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008437 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008438 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008439
8440 range->avg_qual.qual = 70;
8441 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008442 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008443 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008444 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008445 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008446 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008447
Jeff Garzikbf794512005-07-31 13:07:26 -04008448 for (i = 0; i < range->num_bitrates; i++)
8449 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008450 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008451
James Ketrenos43f66a62005-03-25 12:31:53 -06008452 range->max_rts = DEFAULT_RTS_THRESHOLD;
8453 range->min_frag = MIN_FRAG_THRESHOLD;
8454 range->max_frag = MAX_FRAG_THRESHOLD;
8455
8456 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008457 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008458 range->num_encoding_sizes = 2;
8459 range->max_encoding_tokens = WEP_KEYS;
8460
8461 /* Set the Wireless Extension versions */
8462 range->we_version_compiled = WIRELESS_EXT;
8463 range->we_version_source = 16;
8464
James Ketrenosb095c382005-08-24 22:04:42 -05008465 i = 0;
8466 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8467 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8468 i++, j++) {
8469 range->freq[i].i = geo->bg[j].channel;
8470 range->freq[i].m = geo->bg[j].freq * 100000;
8471 range->freq[i].e = 1;
8472 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008473 }
James Ketrenosb095c382005-08-24 22:04:42 -05008474
8475 if (priv->ieee->mode & IEEE_A) {
8476 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8477 i++, j++) {
8478 range->freq[i].i = geo->a[j].channel;
8479 range->freq[i].m = geo->a[j].freq * 100000;
8480 range->freq[i].e = 1;
8481 }
8482 }
8483
8484 range->num_channels = i;
8485 range->num_frequency = i;
8486
James Ketrenosc848d0a2005-08-24 21:56:24 -05008487 up(&priv->sem);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008488
8489 /* Event capability (kernel + driver) */
8490 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8491 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8492 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8493 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008494
8495 IPW_DEBUG_WX("GET Range\n");
8496 return 0;
8497}
8498
Jeff Garzikbf794512005-07-31 13:07:26 -04008499static int ipw_wx_set_wap(struct net_device *dev,
8500 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008501 union iwreq_data *wrqu, char *extra)
8502{
8503 struct ipw_priv *priv = ieee80211_priv(dev);
8504
8505 static const unsigned char any[] = {
8506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8507 };
8508 static const unsigned char off[] = {
8509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8510 };
8511
Jeff Garzikbf794512005-07-31 13:07:26 -04008512 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008513 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008514 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008515 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8516 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8517 /* we disable mandatory BSSID association */
8518 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8519 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008520 IPW_DEBUG_ASSOC("Attempting to associate with new "
8521 "parameters.\n");
8522 ipw_associate(priv);
8523 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008524 return 0;
8525 }
8526
8527 priv->config |= CFG_STATIC_BSSID;
8528 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8529 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008530 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008531 return 0;
8532 }
8533
8534 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8535 MAC_ARG(wrqu->ap_addr.sa_data));
8536
8537 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8538
James Ketrenosc848d0a2005-08-24 21:56:24 -05008539 /* Network configuration changed -- force [re]association */
8540 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8541 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008543
James Ketrenosc848d0a2005-08-24 21:56:24 -05008544 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 return 0;
8546}
8547
Jeff Garzikbf794512005-07-31 13:07:26 -04008548static int ipw_wx_get_wap(struct net_device *dev,
8549 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008550 union iwreq_data *wrqu, char *extra)
8551{
8552 struct ipw_priv *priv = ieee80211_priv(dev);
8553 /* If we are associated, trying to associate, or have a statically
8554 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008555 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008556 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008557 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8558 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008559 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008560 } else
8561 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8562
8563 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8564 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008565 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008566 return 0;
8567}
8568
Jeff Garzikbf794512005-07-31 13:07:26 -04008569static int ipw_wx_set_essid(struct net_device *dev,
8570 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 union iwreq_data *wrqu, char *extra)
8572{
8573 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008574 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008575 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008576 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 if (wrqu->essid.flags && wrqu->essid.length) {
8578 length = wrqu->essid.length - 1;
8579 essid = extra;
8580 }
8581 if (length == 0) {
8582 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008583 if ((priv->config & CFG_STATIC_ESSID) &&
8584 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008585 STATUS_ASSOCIATING))) {
8586 IPW_DEBUG_ASSOC("Attempting to associate with new "
8587 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008588 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008589 ipw_associate(priv);
8590 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008591 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008592 return 0;
8593 }
8594
8595 length = min(length, IW_ESSID_MAX_SIZE);
8596
8597 priv->config |= CFG_STATIC_ESSID;
8598
8599 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8600 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008601 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 return 0;
8603 }
8604
8605 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8606 length);
8607
8608 priv->essid_len = length;
8609 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008610
James Ketrenosc848d0a2005-08-24 21:56:24 -05008611 /* Network configuration changed -- force [re]association */
8612 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8613 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008614 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008615
James Ketrenosc848d0a2005-08-24 21:56:24 -05008616 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008617 return 0;
8618}
8619
Jeff Garzikbf794512005-07-31 13:07:26 -04008620static int ipw_wx_get_essid(struct net_device *dev,
8621 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008622 union iwreq_data *wrqu, char *extra)
8623{
8624 struct ipw_priv *priv = ieee80211_priv(dev);
8625
8626 /* If we are associated, trying to associate, or have a statically
8627 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008628 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008629 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008630 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8631 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008632 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008633 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008634 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008635 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008636 } else {
8637 IPW_DEBUG_WX("Getting essid: ANY\n");
8638 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008639 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008640 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008641 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008642 return 0;
8643}
8644
Jeff Garzikbf794512005-07-31 13:07:26 -04008645static int ipw_wx_set_nick(struct net_device *dev,
8646 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008647 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008648{
James Ketrenos43f66a62005-03-25 12:31:53 -06008649 struct ipw_priv *priv = ieee80211_priv(dev);
8650
8651 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8652 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8653 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008654 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008655 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008656 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008657 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008658 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008659 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008660 return 0;
8661
8662}
8663
Jeff Garzikbf794512005-07-31 13:07:26 -04008664static int ipw_wx_get_nick(struct net_device *dev,
8665 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008666 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008667{
James Ketrenos43f66a62005-03-25 12:31:53 -06008668 struct ipw_priv *priv = ieee80211_priv(dev);
8669 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008670 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008671 wrqu->data.length = strlen(priv->nick) + 1;
8672 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008673 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008674 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008675 return 0;
8676}
8677
James Ketrenos43f66a62005-03-25 12:31:53 -06008678static int ipw_wx_set_rate(struct net_device *dev,
8679 struct iw_request_info *info,
8680 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008681{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008682 /* TODO: We should use semaphores or locks for access to priv */
8683 struct ipw_priv *priv = ieee80211_priv(dev);
8684 u32 target_rate = wrqu->bitrate.value;
8685 u32 fixed, mask;
8686
8687 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8688 /* value = X, fixed = 1 means only rate X */
8689 /* value = X, fixed = 0 means all rates lower equal X */
8690
8691 if (target_rate == -1) {
8692 fixed = 0;
8693 mask = IEEE80211_DEFAULT_RATES_MASK;
8694 /* Now we should reassociate */
8695 goto apply;
8696 }
8697
8698 mask = 0;
8699 fixed = wrqu->bitrate.fixed;
8700
8701 if (target_rate == 1000000 || !fixed)
8702 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8703 if (target_rate == 1000000)
8704 goto apply;
8705
8706 if (target_rate == 2000000 || !fixed)
8707 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8708 if (target_rate == 2000000)
8709 goto apply;
8710
8711 if (target_rate == 5500000 || !fixed)
8712 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8713 if (target_rate == 5500000)
8714 goto apply;
8715
8716 if (target_rate == 6000000 || !fixed)
8717 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8718 if (target_rate == 6000000)
8719 goto apply;
8720
8721 if (target_rate == 9000000 || !fixed)
8722 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8723 if (target_rate == 9000000)
8724 goto apply;
8725
8726 if (target_rate == 11000000 || !fixed)
8727 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8728 if (target_rate == 11000000)
8729 goto apply;
8730
8731 if (target_rate == 12000000 || !fixed)
8732 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8733 if (target_rate == 12000000)
8734 goto apply;
8735
8736 if (target_rate == 18000000 || !fixed)
8737 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8738 if (target_rate == 18000000)
8739 goto apply;
8740
8741 if (target_rate == 24000000 || !fixed)
8742 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8743 if (target_rate == 24000000)
8744 goto apply;
8745
8746 if (target_rate == 36000000 || !fixed)
8747 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8748 if (target_rate == 36000000)
8749 goto apply;
8750
8751 if (target_rate == 48000000 || !fixed)
8752 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8753 if (target_rate == 48000000)
8754 goto apply;
8755
8756 if (target_rate == 54000000 || !fixed)
8757 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8758 if (target_rate == 54000000)
8759 goto apply;
8760
8761 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8762 return -EINVAL;
8763
8764 apply:
8765 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8766 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008767 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008768 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008769 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008770 ipw_set_fixed_rate(priv, priv->ieee->mode);
8771 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008772 priv->config |= CFG_FIXED_RATE;
8773
James Ketrenosc848d0a2005-08-24 21:56:24 -05008774 if (priv->rates_mask == mask) {
8775 IPW_DEBUG_WX("Mask set to current mask.\n");
8776 up(&priv->sem);
8777 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008778 }
8779
James Ketrenosc848d0a2005-08-24 21:56:24 -05008780 priv->rates_mask = mask;
8781
8782 /* Network configuration changed -- force [re]association */
8783 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8784 if (!ipw_disassociate(priv))
8785 ipw_associate(priv);
8786
8787 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008788 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008789}
8790
Jeff Garzikbf794512005-07-31 13:07:26 -04008791static int ipw_wx_get_rate(struct net_device *dev,
8792 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008794{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008795 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008796 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008797 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008798 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008799 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8800 return 0;
8801}
8802
Jeff Garzikbf794512005-07-31 13:07:26 -04008803static int ipw_wx_set_rts(struct net_device *dev,
8804 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008805 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008806{
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008808 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008809 if (wrqu->rts.disabled)
8810 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8811 else {
8812 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008813 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8814 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008815 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008816 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008817 priv->rts_threshold = wrqu->rts.value;
8818 }
8819
8820 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008821 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008822 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8823 return 0;
8824}
8825
Jeff Garzikbf794512005-07-31 13:07:26 -04008826static int ipw_wx_get_rts(struct net_device *dev,
8827 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008829{
James Ketrenos43f66a62005-03-25 12:31:53 -06008830 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008831 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 wrqu->rts.value = priv->rts_threshold;
8833 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008834 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008835 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8837 return 0;
8838}
8839
Jeff Garzikbf794512005-07-31 13:07:26 -04008840static int ipw_wx_set_txpow(struct net_device *dev,
8841 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008843{
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008845 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008846
James Ketrenosc848d0a2005-08-24 21:56:24 -05008847 down(&priv->sem);
8848 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008849 err = -EINPROGRESS;
8850 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008851 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008852
James Ketrenosb095c382005-08-24 22:04:42 -05008853 if (!wrqu->power.fixed)
8854 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008855
James Ketrenosc848d0a2005-08-24 21:56:24 -05008856 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008857 err = -EINVAL;
8858 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008859 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008860
James Ketrenosb095c382005-08-24 22:04:42 -05008861 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008862 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008863 err = -EINVAL;
8864 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008865 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008866
8867 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008868 err = ipw_set_tx_power(priv);
8869 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008870 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008871 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008872}
8873
Jeff Garzikbf794512005-07-31 13:07:26 -04008874static int ipw_wx_get_txpow(struct net_device *dev,
8875 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008876 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008877{
James Ketrenos43f66a62005-03-25 12:31:53 -06008878 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008879 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008880 wrqu->power.value = priv->tx_power;
8881 wrqu->power.fixed = 1;
8882 wrqu->power.flags = IW_TXPOW_DBM;
8883 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008884 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008885
Jeff Garzikbf794512005-07-31 13:07:26 -04008886 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008887 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008888
8889 return 0;
8890}
8891
Jeff Garzikbf794512005-07-31 13:07:26 -04008892static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008893 struct iw_request_info *info,
8894 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008895{
8896 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008897 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008898 if (wrqu->frag.disabled)
8899 priv->ieee->fts = DEFAULT_FTS;
8900 else {
8901 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008902 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8903 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008904 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008905 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008906
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 priv->ieee->fts = wrqu->frag.value & ~0x1;
8908 }
8909
8910 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008911 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008912 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8913 return 0;
8914}
8915
Jeff Garzikbf794512005-07-31 13:07:26 -04008916static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008917 struct iw_request_info *info,
8918 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008919{
8920 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008921 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008922 wrqu->frag.value = priv->ieee->fts;
8923 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008924 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008925 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8927
8928 return 0;
8929}
8930
Jeff Garzikbf794512005-07-31 13:07:26 -04008931static int ipw_wx_set_retry(struct net_device *dev,
8932 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008933 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008934{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008935 struct ipw_priv *priv = ieee80211_priv(dev);
8936
8937 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8938 return -EINVAL;
8939
8940 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8941 return 0;
8942
8943 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8944 return -EINVAL;
8945
8946 down(&priv->sem);
8947 if (wrqu->retry.flags & IW_RETRY_MIN)
8948 priv->short_retry_limit = (u8) wrqu->retry.value;
8949 else if (wrqu->retry.flags & IW_RETRY_MAX)
8950 priv->long_retry_limit = (u8) wrqu->retry.value;
8951 else {
8952 priv->short_retry_limit = (u8) wrqu->retry.value;
8953 priv->long_retry_limit = (u8) wrqu->retry.value;
8954 }
8955
8956 ipw_send_retry_limit(priv, priv->short_retry_limit,
8957 priv->long_retry_limit);
8958 up(&priv->sem);
8959 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8960 priv->short_retry_limit, priv->long_retry_limit);
8961 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008962}
8963
Jeff Garzikbf794512005-07-31 13:07:26 -04008964static int ipw_wx_get_retry(struct net_device *dev,
8965 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008966 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008967{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008968 struct ipw_priv *priv = ieee80211_priv(dev);
8969
8970 down(&priv->sem);
8971 wrqu->retry.disabled = 0;
8972
8973 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8974 up(&priv->sem);
8975 return -EINVAL;
8976 }
8977
8978 if (wrqu->retry.flags & IW_RETRY_MAX) {
8979 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8980 wrqu->retry.value = priv->long_retry_limit;
8981 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8982 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8983 wrqu->retry.value = priv->short_retry_limit;
8984 } else {
8985 wrqu->retry.flags = IW_RETRY_LIMIT;
8986 wrqu->retry.value = priv->short_retry_limit;
8987 }
8988 up(&priv->sem);
8989
8990 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8991
8992 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008993}
8994
James Ketrenosafbf30a2005-08-25 00:05:33 -05008995static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8996 int essid_len)
8997{
8998 struct ipw_scan_request_ext scan;
8999 int err = 0, scan_type;
9000
Pekka Enbergefb34422005-11-16 21:55:05 +02009001 if (!(priv->status & STATUS_INIT) ||
9002 (priv->status & STATUS_EXIT_PENDING))
9003 return 0;
9004
James Ketrenosafbf30a2005-08-25 00:05:33 -05009005 down(&priv->sem);
9006
9007 if (priv->status & STATUS_RF_KILL_MASK) {
9008 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9009 priv->status |= STATUS_SCAN_PENDING;
9010 goto done;
9011 }
9012
9013 IPW_DEBUG_HC("starting request direct scan!\n");
9014
9015 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009016 /* We should not sleep here; otherwise we will block most
9017 * of the system (for instance, we hold rtnl_lock when we
9018 * get here).
9019 */
9020 err = -EAGAIN;
9021 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009022 }
9023 memset(&scan, 0, sizeof(scan));
9024
9025 if (priv->config & CFG_SPEED_SCAN)
9026 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9027 cpu_to_le16(30);
9028 else
9029 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9030 cpu_to_le16(20);
9031
9032 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9033 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009034 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009035 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9036
9037 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9038
9039 err = ipw_send_ssid(priv, essid, essid_len);
9040 if (err) {
9041 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9042 goto done;
9043 }
9044 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9045
9046 ipw_add_scan_channels(priv, &scan, scan_type);
9047
9048 err = ipw_send_scan_request_ext(priv, &scan);
9049 if (err) {
9050 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9051 goto done;
9052 }
9053
9054 priv->status |= STATUS_SCANNING;
9055
9056 done:
9057 up(&priv->sem);
9058 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009059}
9060
Jeff Garzikbf794512005-07-31 13:07:26 -04009061static int ipw_wx_set_scan(struct net_device *dev,
9062 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009063 union iwreq_data *wrqu, char *extra)
9064{
9065 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009066 struct iw_scan_req *req = NULL;
9067 if (wrqu->data.length
9068 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9069 req = (struct iw_scan_req *)extra;
9070 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9071 ipw_request_direct_scan(priv, req->essid,
9072 req->essid_len);
9073 return 0;
9074 }
9075 }
James Ketrenos8935f392005-10-05 15:59:08 -05009076
James Ketrenos43f66a62005-03-25 12:31:53 -06009077 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009078
9079 queue_work(priv->workqueue, &priv->request_scan);
9080
James Ketrenos43f66a62005-03-25 12:31:53 -06009081 return 0;
9082}
9083
Jeff Garzikbf794512005-07-31 13:07:26 -04009084static int ipw_wx_get_scan(struct net_device *dev,
9085 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009086 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009087{
James Ketrenos43f66a62005-03-25 12:31:53 -06009088 struct ipw_priv *priv = ieee80211_priv(dev);
9089 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9090}
9091
Jeff Garzikbf794512005-07-31 13:07:26 -04009092static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009093 struct iw_request_info *info,
9094 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009095{
9096 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009097 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009098 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009099
9100 down(&priv->sem);
9101 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009102
Hong Liucaeff812005-08-05 17:25:50 +08009103 /* In IBSS mode, we need to notify the firmware to update
9104 * the beacon info after we changed the capability. */
9105 if (cap != priv->capability &&
9106 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9107 priv->status & STATUS_ASSOCIATED)
9108 ipw_disassociate(priv);
9109
9110 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009111 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009112}
9113
Jeff Garzikbf794512005-07-31 13:07:26 -04009114static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009115 struct iw_request_info *info,
9116 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009117{
9118 struct ipw_priv *priv = ieee80211_priv(dev);
9119 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9120}
9121
Jeff Garzikbf794512005-07-31 13:07:26 -04009122static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009123 struct iw_request_info *info,
9124 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009125{
9126 struct ipw_priv *priv = ieee80211_priv(dev);
9127 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009128 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 if (wrqu->power.disabled) {
9130 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9131 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9132 if (err) {
9133 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009134 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009135 return err;
9136 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009138 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009139 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009140 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009141
9142 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009143 case IW_POWER_ON: /* If not specified */
9144 case IW_POWER_MODE: /* If set all mask */
9145 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009146 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009147 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9149 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009150 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009151 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009152 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009153
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 /* If the user hasn't specified a power management mode yet, default
9155 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009156 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009157 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009158 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009159 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9160 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9161 if (err) {
9162 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009163 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 return err;
9165 }
9166
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009168 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 return 0;
9170}
9171
Jeff Garzikbf794512005-07-31 13:07:26 -04009172static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009173 struct iw_request_info *info,
9174 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009175{
9176 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009177 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009178 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009179 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009180 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009181 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009182
James Ketrenosc848d0a2005-08-24 21:56:24 -05009183 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009185
James Ketrenos43f66a62005-03-25 12:31:53 -06009186 return 0;
9187}
9188
Jeff Garzikbf794512005-07-31 13:07:26 -04009189static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009190 struct iw_request_info *info,
9191 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009192{
9193 struct ipw_priv *priv = ieee80211_priv(dev);
9194 int mode = *(int *)extra;
9195 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009196 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009197 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9198 mode = IPW_POWER_AC;
9199 priv->power_mode = mode;
9200 } else {
9201 priv->power_mode = IPW_POWER_ENABLED | mode;
9202 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009203
James Ketrenos43f66a62005-03-25 12:31:53 -06009204 if (priv->power_mode != mode) {
9205 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009206
James Ketrenos43f66a62005-03-25 12:31:53 -06009207 if (err) {
9208 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009209 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009210 return err;
9211 }
9212 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009213 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009214 return 0;
9215}
9216
9217#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009218static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009219 struct iw_request_info *info,
9220 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009221{
9222 struct ipw_priv *priv = ieee80211_priv(dev);
9223 int level = IPW_POWER_LEVEL(priv->power_mode);
9224 char *p = extra;
9225
9226 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9227
9228 switch (level) {
9229 case IPW_POWER_AC:
9230 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9231 break;
9232 case IPW_POWER_BATTERY:
9233 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9234 break;
9235 default:
9236 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009237 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009238 timeout_duration[level - 1] / 1000,
9239 period_duration[level - 1] / 1000);
9240 }
9241
9242 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009243 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009244
9245 wrqu->data.length = p - extra + 1;
9246
9247 return 0;
9248}
9249
9250static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009251 struct iw_request_info *info,
9252 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009253{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009254 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009255 int mode = *(int *)extra;
9256 u8 band = 0, modulation = 0;
9257
9258 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009259 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009260 return -EINVAL;
9261 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009262 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009263 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009264 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009265 if (mode & IEEE_A) {
9266 band |= IEEE80211_52GHZ_BAND;
9267 modulation |= IEEE80211_OFDM_MODULATION;
9268 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009269 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009270 } else {
9271 if (mode & IEEE_A) {
9272 IPW_WARNING("Attempt to set 2200BG into "
9273 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009274 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009275 return -EINVAL;
9276 }
9277
James Ketrenosa33a1982005-09-14 14:28:59 -05009278 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009279 }
9280
9281 if (mode & IEEE_B) {
9282 band |= IEEE80211_24GHZ_BAND;
9283 modulation |= IEEE80211_CCK_MODULATION;
9284 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009285 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009286
James Ketrenos43f66a62005-03-25 12:31:53 -06009287 if (mode & IEEE_G) {
9288 band |= IEEE80211_24GHZ_BAND;
9289 modulation |= IEEE80211_OFDM_MODULATION;
9290 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009291 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009292
9293 priv->ieee->mode = mode;
9294 priv->ieee->freq_band = band;
9295 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009296 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009297
James Ketrenosc848d0a2005-08-24 21:56:24 -05009298 /* Network configuration changed -- force [re]association */
9299 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9300 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009301 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009302 ipw_associate(priv);
9303 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009304
James Ketrenosa613bff2005-08-24 21:43:11 -05009305 /* Update the band LEDs */
9306 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009307
Jeff Garzikbf794512005-07-31 13:07:26 -04009308 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009309 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009310 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009311 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009312 return 0;
9313}
9314
9315static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009316 struct iw_request_info *info,
9317 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009318{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009319 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009320 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009321 switch (priv->ieee->mode) {
9322 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009323 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9324 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009325 case IEEE_B:
9326 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9327 break;
9328 case IEEE_A | IEEE_B:
9329 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9330 break;
9331 case IEEE_G:
9332 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9333 break;
9334 case IEEE_A | IEEE_G:
9335 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9336 break;
9337 case IEEE_B | IEEE_G:
9338 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9339 break;
9340 case IEEE_A | IEEE_B | IEEE_G:
9341 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9342 break;
9343 default:
9344 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009345 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009346 }
9347
James Ketrenos43f66a62005-03-25 12:31:53 -06009348 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9349
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009350 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009351 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009352
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009353 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009354}
9355
James Ketrenosea2b26e2005-08-24 21:25:16 -05009356static int ipw_wx_set_preamble(struct net_device *dev,
9357 struct iw_request_info *info,
9358 union iwreq_data *wrqu, char *extra)
9359{
9360 struct ipw_priv *priv = ieee80211_priv(dev);
9361 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009362 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009363 /* Switching from SHORT -> LONG requires a disassociation */
9364 if (mode == 1) {
9365 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9366 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009367
9368 /* Network configuration changed -- force [re]association */
9369 IPW_DEBUG_ASSOC
9370 ("[re]association triggered due to preamble change.\n");
9371 if (!ipw_disassociate(priv))
9372 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009373 }
9374 goto done;
9375 }
9376
9377 if (mode == 0) {
9378 priv->config &= ~CFG_PREAMBLE_LONG;
9379 goto done;
9380 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009381 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009382 return -EINVAL;
9383
9384 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009385 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009386 return 0;
9387}
9388
9389static int ipw_wx_get_preamble(struct net_device *dev,
9390 struct iw_request_info *info,
9391 union iwreq_data *wrqu, char *extra)
9392{
9393 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009394 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009395 if (priv->config & CFG_PREAMBLE_LONG)
9396 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9397 else
9398 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009399 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009400 return 0;
9401}
9402
James Ketrenosb095c382005-08-24 22:04:42 -05009403#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009404static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009405 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009406 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009407{
James Ketrenos43f66a62005-03-25 12:31:53 -06009408 struct ipw_priv *priv = ieee80211_priv(dev);
9409 int *parms = (int *)extra;
9410 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009411 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009412 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009413 if (enable) {
9414 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009415#ifdef CONFIG_IEEE80211_RADIOTAP
9416 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9417#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009418 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009419#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009420 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009422
James Ketrenos43f66a62005-03-25 12:31:53 -06009423 ipw_set_channel(priv, parms[1]);
9424 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009425 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9426 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009427 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009428 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009429 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009430 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009431 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009432 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009433 return 0;
9434}
9435
James Ketrenosb095c382005-08-24 22:04:42 -05009436#endif // CONFIG_IPW2200_MONITOR
9437
Jeff Garzikbf794512005-07-31 13:07:26 -04009438static int ipw_wx_reset(struct net_device *dev,
9439 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009440 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009441{
James Ketrenos43f66a62005-03-25 12:31:53 -06009442 struct ipw_priv *priv = ieee80211_priv(dev);
9443 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009444 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 return 0;
9446}
James Ketrenosb095c382005-08-24 22:04:42 -05009447
James Ketrenosb095c382005-08-24 22:04:42 -05009448static int ipw_wx_sw_reset(struct net_device *dev,
9449 struct iw_request_info *info,
9450 union iwreq_data *wrqu, char *extra)
9451{
9452 struct ipw_priv *priv = ieee80211_priv(dev);
9453 union iwreq_data wrqu_sec = {
9454 .encoding = {
9455 .flags = IW_ENCODE_DISABLED,
9456 },
9457 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009458 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009459
9460 IPW_DEBUG_WX("SW_RESET\n");
9461
9462 down(&priv->sem);
9463
James Ketrenosafbf30a2005-08-25 00:05:33 -05009464 ret = ipw_sw_reset(priv, 0);
9465 if (!ret) {
9466 free_firmware();
9467 ipw_adapter_restart(priv);
9468 }
James Ketrenosb095c382005-08-24 22:04:42 -05009469
9470 /* The SW reset bit might have been toggled on by the 'disable'
9471 * module parameter, so take appropriate action */
9472 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9473
9474 up(&priv->sem);
9475 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9476 down(&priv->sem);
9477
9478 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9479 /* Configuration likely changed -- force [re]association */
9480 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9481 "reset.\n");
9482 if (!ipw_disassociate(priv))
9483 ipw_associate(priv);
9484 }
9485
9486 up(&priv->sem);
9487
9488 return 0;
9489}
James Ketrenos43f66a62005-03-25 12:31:53 -06009490
9491/* Rebase the WE IOCTLs to zero for the handler array */
9492#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009493static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009494 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9495 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9496 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9497 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9498 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9499 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9500 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9501 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9502 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9503 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9504 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9505 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9506 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9507 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9508 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9509 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9510 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9511 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9512 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9513 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9514 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9515 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9516 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9517 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9518 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9519 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9520 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9521 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009522 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9523 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9524 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9525 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009526 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9527 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9528 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9529 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9530 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9531 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9532 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009533};
9534
James Ketrenosb095c382005-08-24 22:04:42 -05009535enum {
9536 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9537 IPW_PRIV_GET_POWER,
9538 IPW_PRIV_SET_MODE,
9539 IPW_PRIV_GET_MODE,
9540 IPW_PRIV_SET_PREAMBLE,
9541 IPW_PRIV_GET_PREAMBLE,
9542 IPW_PRIV_RESET,
9543 IPW_PRIV_SW_RESET,
9544#ifdef CONFIG_IPW2200_MONITOR
9545 IPW_PRIV_SET_MONITOR,
9546#endif
9547};
James Ketrenos43f66a62005-03-25 12:31:53 -06009548
Jeff Garzikbf794512005-07-31 13:07:26 -04009549static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009550 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009551 .cmd = IPW_PRIV_SET_POWER,
9552 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9553 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009554 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009555 .cmd = IPW_PRIV_GET_POWER,
9556 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9557 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009558 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009559 .cmd = IPW_PRIV_SET_MODE,
9560 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9561 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009562 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009563 .cmd = IPW_PRIV_GET_MODE,
9564 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9565 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009566 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009567 .cmd = IPW_PRIV_SET_PREAMBLE,
9568 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9569 .name = "set_preamble"},
9570 {
9571 .cmd = IPW_PRIV_GET_PREAMBLE,
9572 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9573 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009574 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009575 IPW_PRIV_RESET,
9576 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009577 {
9578 IPW_PRIV_SW_RESET,
9579 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9580#ifdef CONFIG_IPW2200_MONITOR
9581 {
9582 IPW_PRIV_SET_MONITOR,
9583 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9584#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009585};
9586
9587static iw_handler ipw_priv_handler[] = {
9588 ipw_wx_set_powermode,
9589 ipw_wx_get_powermode,
9590 ipw_wx_set_wireless_mode,
9591 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009592 ipw_wx_set_preamble,
9593 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009594 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009595 ipw_wx_sw_reset,
9596#ifdef CONFIG_IPW2200_MONITOR
9597 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009598#endif
9599};
9600
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009601static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009602 .standard = ipw_wx_handlers,
9603 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9604 .num_private = ARRAY_SIZE(ipw_priv_handler),
9605 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9606 .private = ipw_priv_handler,
9607 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009608 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009609};
9610
James Ketrenos43f66a62005-03-25 12:31:53 -06009611/*
9612 * Get wireless statistics.
9613 * Called by /proc/net/wireless
9614 * Also called by SIOCGIWSTATS
9615 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009616static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009617{
9618 struct ipw_priv *priv = ieee80211_priv(dev);
9619 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009620
James Ketrenos43f66a62005-03-25 12:31:53 -06009621 wstats = &priv->wstats;
9622
James Ketrenosea2b26e2005-08-24 21:25:16 -05009623 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009624 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009625 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9626 * and associated; if not associcated, the values are all meaningless
9627 * anyway, so set them all to NULL and INVALID */
9628 if (!(priv->status & STATUS_ASSOCIATED)) {
9629 wstats->miss.beacon = 0;
9630 wstats->discard.retries = 0;
9631 wstats->qual.qual = 0;
9632 wstats->qual.level = 0;
9633 wstats->qual.noise = 0;
9634 wstats->qual.updated = 7;
9635 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009636 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009637 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009638 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009639
9640 wstats->qual.qual = priv->quality;
9641 wstats->qual.level = average_value(&priv->average_rssi);
9642 wstats->qual.noise = average_value(&priv->average_noise);
9643 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009644 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009645
9646 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9647 wstats->discard.retries = priv->last_tx_failures;
9648 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009649
James Ketrenos43f66a62005-03-25 12:31:53 -06009650/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9651 goto fail_get_ordinal;
9652 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009653
James Ketrenos43f66a62005-03-25 12:31:53 -06009654 return wstats;
9655}
9656
James Ketrenos43f66a62005-03-25 12:31:53 -06009657/* net device stuff */
9658
Arjan van de Ven858119e2006-01-14 13:20:43 -08009659static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009660{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009661 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009662 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 sys_config->answer_broadcast_ssid_probe = 0;
9664 sys_config->accept_all_data_frames = 0;
9665 sys_config->accept_non_directed_frames = 1;
9666 sys_config->exclude_unicast_unencrypted = 0;
9667 sys_config->disable_unicast_decryption = 1;
9668 sys_config->exclude_multicast_unencrypted = 0;
9669 sys_config->disable_multicast_decryption = 1;
9670 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009671 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009672 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009673 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009674 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009675 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009676}
9677
9678static int ipw_net_open(struct net_device *dev)
9679{
9680 struct ipw_priv *priv = ieee80211_priv(dev);
9681 IPW_DEBUG_INFO("dev->open\n");
9682 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009683 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009684 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9685 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009686 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009687 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009688 return 0;
9689}
9690
9691static int ipw_net_stop(struct net_device *dev)
9692{
9693 IPW_DEBUG_INFO("dev->close\n");
9694 netif_stop_queue(dev);
9695 return 0;
9696}
9697
9698/*
9699todo:
9700
9701modify to send one tfd per fragment instead of using chunking. otherwise
9702we need to heavily modify the ieee80211_skb_to_txb.
9703*/
9704
Arjan van de Ven858119e2006-01-14 13:20:43 -08009705static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009706 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009707{
James Ketrenos0dacca12005-09-21 12:23:41 -05009708 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009709 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009710 int i = 0;
9711 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009712#ifdef CONFIG_IPW_QOS
9713 int tx_id = ipw_get_tx_queue_number(priv, pri);
9714 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9715#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009716 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009717#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 struct clx2_queue *q = &txq->q;
9719 u8 id, hdr_len, unicast;
9720 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009721 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009722
James Ketrenos227d2dc2005-07-28 16:25:55 -05009723 /* If there isn't room in the queue, we return busy and let the
9724 * network stack requeue the packet for us */
9725 if (ipw_queue_space(q) < q->high_mark)
9726 return NETDEV_TX_BUSY;
James Ketrenos43f66a62005-03-25 12:31:53 -06009727
9728 switch (priv->ieee->iw_mode) {
9729 case IW_MODE_ADHOC:
9730 hdr_len = IEEE80211_3ADDR_LEN;
Stephen Hemminger3c190652006-01-03 15:27:38 -08009731 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009732 id = ipw_find_station(priv, hdr->addr1);
9733 if (id == IPW_INVALID_STATION) {
9734 id = ipw_add_station(priv, hdr->addr1);
9735 if (id == IPW_INVALID_STATION) {
9736 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009737 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009738 MAC_ARG(hdr->addr1));
9739 goto drop;
9740 }
9741 }
9742 break;
9743
9744 case IW_MODE_INFRA:
9745 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009746 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009747 hdr_len = IEEE80211_3ADDR_LEN;
9748 id = 0;
9749 break;
9750 }
9751
9752 tfd = &txq->bd[q->first_empty];
9753 txq->txb[q->first_empty] = txb;
9754 memset(tfd, 0, sizeof(*tfd));
9755 tfd->u.data.station_number = id;
9756
9757 tfd->control_flags.message_type = TX_FRAME_TYPE;
9758 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9759
9760 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009761 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009763
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009765 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009766 else
James Ketrenosb095c382005-08-24 22:04:42 -05009767 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009768
James Ketrenosea2b26e2005-08-24 21:25:16 -05009769 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9770 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009771
James Ketrenosc848d0a2005-08-24 21:56:24 -05009772 fc = le16_to_cpu(hdr->frame_ctl);
9773 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009774
9775 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9776
James Ketrenosb095c382005-08-24 22:04:42 -05009777 if (likely(unicast))
9778 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9779
9780 if (txb->encrypted && !priv->ieee->host_encrypt) {
9781 switch (priv->ieee->sec.level) {
9782 case SEC_LEVEL_3:
9783 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9784 IEEE80211_FCTL_PROTECTED;
9785 /* XXX: ACK flag must be set for CCMP even if it
9786 * is a multicast/broadcast packet, because CCMP
9787 * group communication encrypted by GTK is
9788 * actually done by the AP. */
9789 if (!unicast)
9790 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9791
9792 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9793 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9794 tfd->u.data.key_index = 0;
9795 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9796 break;
9797 case SEC_LEVEL_2:
9798 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9799 IEEE80211_FCTL_PROTECTED;
9800 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9801 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9802 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9803 break;
9804 case SEC_LEVEL_1:
9805 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9806 IEEE80211_FCTL_PROTECTED;
9807 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9808 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9809 40)
9810 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9811 else
9812 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9813 break;
9814 case SEC_LEVEL_0:
9815 break;
9816 default:
9817 printk(KERN_ERR "Unknow security level %d\n",
9818 priv->ieee->sec.level);
9819 break;
9820 }
9821 } else
9822 /* No hardware encryption */
9823 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9824
9825#ifdef CONFIG_IPW_QOS
9826 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9827#endif /* CONFIG_IPW_QOS */
9828
James Ketrenos43f66a62005-03-25 12:31:53 -06009829 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009830 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9831 txb->nr_frags));
9832 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9833 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9834 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9835 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9836 i, le32_to_cpu(tfd->u.data.num_chunks),
9837 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009838 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009839 i, tfd->u.data.num_chunks,
9840 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009841 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009842 txb->fragments[i]->len - hdr_len);
9843
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009844 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009845 cpu_to_le32(pci_map_single
9846 (priv->pci_dev,
9847 txb->fragments[i]->data + hdr_len,
9848 txb->fragments[i]->len - hdr_len,
9849 PCI_DMA_TODEVICE));
9850 tfd->u.data.chunk_len[i] =
9851 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009852 }
9853
9854 if (i != txb->nr_frags) {
9855 struct sk_buff *skb;
9856 u16 remaining_bytes = 0;
9857 int j;
9858
9859 for (j = i; j < txb->nr_frags; j++)
9860 remaining_bytes += txb->fragments[j]->len - hdr_len;
9861
9862 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9863 remaining_bytes);
9864 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9865 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009866 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009867 for (j = i; j < txb->nr_frags; j++) {
9868 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009869
James Ketrenos43f66a62005-03-25 12:31:53 -06009870 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009871 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009872 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009873 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009874 }
9875 dev_kfree_skb_any(txb->fragments[i]);
9876 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009877 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009878 cpu_to_le32(pci_map_single
9879 (priv->pci_dev, skb->data,
9880 tfd->u.data.chunk_len[i],
9881 PCI_DMA_TODEVICE));
9882
9883 tfd->u.data.num_chunks =
9884 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9885 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009886 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009887 }
9888
9889 /* kick DMA */
9890 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9891 ipw_write32(priv, q->reg_w, q->first_empty);
9892
James Ketrenos227d2dc2005-07-28 16:25:55 -05009893 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009894
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009895 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009896 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9897 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009898 return NETDEV_TX_OK;
9899}
9900
9901static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9902{
9903 struct ipw_priv *priv = ieee80211_priv(dev);
9904#ifdef CONFIG_IPW_QOS
9905 int tx_id = ipw_get_tx_queue_number(priv, pri);
9906 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9907#else
9908 struct clx2_tx_queue *txq = &priv->txq[0];
9909#endif /* CONFIG_IPW_QOS */
9910
9911 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9912 return 1;
9913
9914 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009915}
9916
9917static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009918 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009919{
9920 struct ipw_priv *priv = ieee80211_priv(dev);
9921 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009922 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009923
9924 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 spin_lock_irqsave(&priv->lock, flags);
9926
9927 if (!(priv->status & STATUS_ASSOCIATED)) {
9928 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9929 priv->ieee->stats.tx_carrier_errors++;
9930 netif_stop_queue(dev);
9931 goto fail_unlock;
9932 }
9933
James Ketrenos227d2dc2005-07-28 16:25:55 -05009934 ret = ipw_tx_skb(priv, txb, pri);
9935 if (ret == NETDEV_TX_OK)
9936 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009937 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009938
James Ketrenos227d2dc2005-07-28 16:25:55 -05009939 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009940
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009941 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009942 spin_unlock_irqrestore(&priv->lock, flags);
9943 return 1;
9944}
9945
9946static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9947{
9948 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009949
James Ketrenos43f66a62005-03-25 12:31:53 -06009950 priv->ieee->stats.tx_packets = priv->tx_packets;
9951 priv->ieee->stats.rx_packets = priv->rx_packets;
9952 return &priv->ieee->stats;
9953}
9954
9955static void ipw_net_set_multicast_list(struct net_device *dev)
9956{
9957
9958}
9959
9960static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9961{
9962 struct ipw_priv *priv = ieee80211_priv(dev);
9963 struct sockaddr *addr = p;
9964 if (!is_valid_ether_addr(addr->sa_data))
9965 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009966 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009967 priv->config |= CFG_CUSTOM_MAC;
9968 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9969 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9970 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009971 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009972 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009973 return 0;
9974}
9975
Jeff Garzikbf794512005-07-31 13:07:26 -04009976static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009977 struct ethtool_drvinfo *info)
9978{
9979 struct ipw_priv *p = ieee80211_priv(dev);
9980 char vers[64];
9981 char date[32];
9982 u32 len;
9983
9984 strcpy(info->driver, DRV_NAME);
9985 strcpy(info->version, DRV_VERSION);
9986
9987 len = sizeof(vers);
9988 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9989 len = sizeof(date);
9990 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9991
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009992 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009993 vers, date);
9994 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009995 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009996}
9997
9998static u32 ipw_ethtool_get_link(struct net_device *dev)
9999{
10000 struct ipw_priv *priv = ieee80211_priv(dev);
10001 return (priv->status & STATUS_ASSOCIATED) != 0;
10002}
10003
10004static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10005{
James Ketrenosb095c382005-08-24 22:04:42 -050010006 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010007}
10008
10009static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010010 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010011{
10012 struct ipw_priv *p = ieee80211_priv(dev);
10013
James Ketrenosb095c382005-08-24 22:04:42 -050010014 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010015 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010016 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010017 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010018 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010019 return 0;
10020}
10021
10022static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010023 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010024{
10025 struct ipw_priv *p = ieee80211_priv(dev);
10026 int i;
10027
James Ketrenosb095c382005-08-24 22:04:42 -050010028 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010029 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010030 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010031 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010032 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -050010033 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -060010034 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010035 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010036 return 0;
10037}
10038
10039static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010040 .get_link = ipw_ethtool_get_link,
10041 .get_drvinfo = ipw_ethtool_get_drvinfo,
10042 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10043 .get_eeprom = ipw_ethtool_get_eeprom,
10044 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010045};
10046
10047static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10048{
10049 struct ipw_priv *priv = data;
10050 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010051
James Ketrenos43f66a62005-03-25 12:31:53 -060010052 if (!priv)
10053 return IRQ_NONE;
10054
10055 spin_lock(&priv->lock);
10056
10057 if (!(priv->status & STATUS_INT_ENABLED)) {
10058 /* Shared IRQ */
10059 goto none;
10060 }
10061
James Ketrenosb095c382005-08-24 22:04:42 -050010062 inta = ipw_read32(priv, IPW_INTA_RW);
10063 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010064
James Ketrenos43f66a62005-03-25 12:31:53 -060010065 if (inta == 0xFFFFFFFF) {
10066 /* Hardware disappeared */
10067 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10068 goto none;
10069 }
10070
James Ketrenosb095c382005-08-24 22:04:42 -050010071 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010072 /* Shared interrupt */
10073 goto none;
10074 }
10075
10076 /* tell the device to stop sending interrupts */
10077 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010078
James Ketrenos43f66a62005-03-25 12:31:53 -060010079 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010080 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10081 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010082
James Ketrenos43f66a62005-03-25 12:31:53 -060010083 /* Cache INTA value for our tasklet */
10084 priv->isr_inta = inta;
10085
10086 tasklet_schedule(&priv->irq_tasklet);
10087
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010088 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010089
10090 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010091 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010092 spin_unlock(&priv->lock);
10093 return IRQ_NONE;
10094}
10095
10096static void ipw_rf_kill(void *adapter)
10097{
10098 struct ipw_priv *priv = adapter;
10099 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010100
James Ketrenos43f66a62005-03-25 12:31:53 -060010101 spin_lock_irqsave(&priv->lock, flags);
10102
10103 if (rf_kill_active(priv)) {
10104 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10105 if (priv->workqueue)
10106 queue_delayed_work(priv->workqueue,
10107 &priv->rf_kill, 2 * HZ);
10108 goto exit_unlock;
10109 }
10110
10111 /* RF Kill is now disabled, so bring the device back up */
10112
10113 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10114 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10115 "device\n");
10116
10117 /* we can not do an adapter restart while inside an irq lock */
10118 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010119 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010120 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10121 "enabled\n");
10122
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010123 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010124 spin_unlock_irqrestore(&priv->lock, flags);
10125}
10126
James Ketrenosc848d0a2005-08-24 21:56:24 -050010127static void ipw_bg_rf_kill(void *data)
10128{
10129 struct ipw_priv *priv = data;
10130 down(&priv->sem);
10131 ipw_rf_kill(data);
10132 up(&priv->sem);
10133}
10134
Adrian Bunka73e22b2006-01-21 01:39:42 +010010135static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010136{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010137 priv->last_seq_num = -1;
10138 priv->last_frag_num = -1;
10139 priv->last_packet_time = 0;
10140
James Ketrenosa613bff2005-08-24 21:43:11 -050010141 netif_carrier_on(priv->net_dev);
10142 if (netif_queue_stopped(priv->net_dev)) {
10143 IPW_DEBUG_NOTIF("waking queue\n");
10144 netif_wake_queue(priv->net_dev);
10145 } else {
10146 IPW_DEBUG_NOTIF("starting queue\n");
10147 netif_start_queue(priv->net_dev);
10148 }
10149
James Ketrenosc848d0a2005-08-24 21:56:24 -050010150 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010151 ipw_reset_stats(priv);
10152 /* Ensure the rate is updated immediately */
10153 priv->last_rate = ipw_get_current_rate(priv);
10154 ipw_gather_stats(priv);
10155 ipw_led_link_up(priv);
10156 notify_wx_assoc_event(priv);
10157
10158 if (priv->config & CFG_BACKGROUND_SCAN)
10159 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10160}
10161
James Ketrenosc848d0a2005-08-24 21:56:24 -050010162static void ipw_bg_link_up(void *data)
10163{
10164 struct ipw_priv *priv = data;
10165 down(&priv->sem);
10166 ipw_link_up(data);
10167 up(&priv->sem);
10168}
10169
Adrian Bunka73e22b2006-01-21 01:39:42 +010010170static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010171{
10172 ipw_led_link_down(priv);
10173 netif_carrier_off(priv->net_dev);
10174 netif_stop_queue(priv->net_dev);
10175 notify_wx_assoc_event(priv);
10176
10177 /* Cancel any queued work ... */
10178 cancel_delayed_work(&priv->request_scan);
10179 cancel_delayed_work(&priv->adhoc_check);
10180 cancel_delayed_work(&priv->gather_stats);
10181
10182 ipw_reset_stats(priv);
10183
James Ketrenosafbf30a2005-08-25 00:05:33 -050010184 if (!(priv->status & STATUS_EXIT_PENDING)) {
10185 /* Queue up another scan... */
10186 queue_work(priv->workqueue, &priv->request_scan);
10187 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010188}
10189
James Ketrenosc848d0a2005-08-24 21:56:24 -050010190static void ipw_bg_link_down(void *data)
10191{
10192 struct ipw_priv *priv = data;
10193 down(&priv->sem);
10194 ipw_link_down(data);
10195 up(&priv->sem);
10196}
10197
James Ketrenos43f66a62005-03-25 12:31:53 -060010198static int ipw_setup_deferred_work(struct ipw_priv *priv)
10199{
10200 int ret = 0;
10201
James Ketrenos43f66a62005-03-25 12:31:53 -060010202 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010204 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010205
James Ketrenosc848d0a2005-08-24 21:56:24 -050010206 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10207 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10208 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010209 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010210 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10211 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10212 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10213 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10214 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010215 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010216 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010217 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010218 (void (*)(void *))ipw_bg_gather_stats, priv);
10219 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10220 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10221 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10222 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10223 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10224 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010225 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010226 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010227 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010228 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10229 priv);
10230 INIT_WORK(&priv->merge_networks,
10231 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010232
James Ketrenosb095c382005-08-24 22:04:42 -050010233#ifdef CONFIG_IPW_QOS
10234 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10235 priv);
10236#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010237
10238 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10239 ipw_irq_tasklet, (unsigned long)priv);
10240
10241 return ret;
10242}
10243
James Ketrenos43f66a62005-03-25 12:31:53 -060010244static void shim__set_security(struct net_device *dev,
10245 struct ieee80211_security *sec)
10246{
10247 struct ipw_priv *priv = ieee80211_priv(dev);
10248 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010249 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010250 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010251 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010252 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010253 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010254 priv->ieee->sec.flags &= ~(1 << i);
10255 else {
10256 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010257 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010258 priv->ieee->sec.flags |= (1 << i);
10259 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010260 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010261 } else if (sec->level != SEC_LEVEL_1)
10262 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010263 }
10264
James Ketrenosb095c382005-08-24 22:04:42 -050010265 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010266 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010267 priv->ieee->sec.active_key = sec->active_key;
10268 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010269 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010270 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010271 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010272 } else
10273 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010274
10275 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010276 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10277 priv->ieee->sec.auth_mode = sec->auth_mode;
10278 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010279 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10280 priv->capability |= CAP_SHARED_KEY;
10281 else
10282 priv->capability &= ~CAP_SHARED_KEY;
10283 priv->status |= STATUS_SECURITY_UPDATED;
10284 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010285
James Ketrenosb095c382005-08-24 22:04:42 -050010286 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10287 priv->ieee->sec.flags |= SEC_ENABLED;
10288 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010289 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010290 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010291 priv->capability |= CAP_PRIVACY_ON;
10292 else
10293 priv->capability &= ~CAP_PRIVACY_ON;
10294 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010295
James Ketrenosafbf30a2005-08-25 00:05:33 -050010296 if (sec->flags & SEC_ENCRYPT)
10297 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010298
James Ketrenosb095c382005-08-24 22:04:42 -050010299 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10300 priv->ieee->sec.level = sec->level;
10301 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010302 priv->status |= STATUS_SECURITY_UPDATED;
10303 }
10304
Zhu Yi1fbfea52005-08-05 17:22:56 +080010305 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10306 ipw_set_hwcrypto_keys(priv);
10307
Jeff Garzikbf794512005-07-31 13:07:26 -040010308 /* To match current functionality of ipw2100 (which works well w/
10309 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010310 * privacy capability changes ... */
10311#if 0
10312 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010313 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010314 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010315 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010316 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010317 IPW_DEBUG_ASSOC("Disassociating due to capability "
10318 "change.\n");
10319 ipw_disassociate(priv);
10320 }
10321#endif
10322}
10323
Jeff Garzikbf794512005-07-31 13:07:26 -040010324static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010325 struct ipw_supported_rates *rates)
10326{
10327 /* TODO: Mask out rates based on priv->rates_mask */
10328
10329 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010330 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010331 switch (priv->ieee->freq_band) {
10332 case IEEE80211_52GHZ_BAND:
10333 rates->ieee_mode = IPW_A_MODE;
10334 rates->purpose = IPW_RATE_CAPABILITIES;
10335 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10336 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10337 break;
10338
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010339 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010340 rates->ieee_mode = IPW_G_MODE;
10341 rates->purpose = IPW_RATE_CAPABILITIES;
10342 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10343 IEEE80211_CCK_DEFAULT_RATES_MASK);
10344 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10345 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10346 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10347 }
10348 break;
10349 }
10350
10351 return 0;
10352}
10353
Jeff Garzikbf794512005-07-31 13:07:26 -040010354static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010355{
James Ketrenos43f66a62005-03-25 12:31:53 -060010356 /* This is only called from ipw_up, which resets/reloads the firmware
10357 so, we don't need to first disable the card before we configure
10358 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010359 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010360 goto error;
10361
10362 /* initialize adapter address */
10363 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10364 goto error;
10365
10366 /* set basic system config settings */
10367 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010368
10369 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10370 * Does not support BT priority yet (don't abort or defer our Tx) */
10371 if (bt_coexist) {
10372 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10373
10374 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10375 priv->sys_config.bt_coexistence
10376 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10377 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10378 priv->sys_config.bt_coexistence
10379 |= CFG_BT_COEXISTENCE_OOB;
10380 }
10381
James Ketrenosc848d0a2005-08-24 21:56:24 -050010382 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10383 priv->sys_config.answer_broadcast_ssid_probe = 1;
10384 else
10385 priv->sys_config.answer_broadcast_ssid_probe = 0;
10386
James Ketrenos43f66a62005-03-25 12:31:53 -060010387 if (ipw_send_system_config(priv, &priv->sys_config))
10388 goto error;
10389
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010390 init_supported_rates(priv, &priv->rates);
10391 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010392 goto error;
10393
10394 /* Set request-to-send threshold */
10395 if (priv->rts_threshold) {
10396 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10397 goto error;
10398 }
James Ketrenosb095c382005-08-24 22:04:42 -050010399#ifdef CONFIG_IPW_QOS
10400 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10401 ipw_qos_activate(priv, NULL);
10402#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010403
10404 if (ipw_set_random_seed(priv))
10405 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010406
James Ketrenos43f66a62005-03-25 12:31:53 -060010407 /* final state transition to the RUN state */
10408 if (ipw_send_host_complete(priv))
10409 goto error;
10410
James Ketrenose6666192005-08-12 09:17:04 -050010411 priv->status |= STATUS_INIT;
10412
10413 ipw_led_init(priv);
10414 ipw_led_radio_on(priv);
10415 priv->notif_missed_beacons = 0;
10416
10417 /* Set hardware WEP key if it is configured. */
10418 if ((priv->capability & CAP_PRIVACY_ON) &&
10419 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10420 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10421 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010422
10423 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010424
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010425 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010426 return -EIO;
10427}
10428
James Ketrenos4f36f802005-08-03 20:36:56 -050010429/*
10430 * NOTE:
10431 *
10432 * These tables have been tested in conjunction with the
10433 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10434 *
10435 * Altering this values, using it on other hardware, or in geographies
10436 * not intended for resale of the above mentioned Intel adapters has
10437 * not been tested.
10438 *
10439 */
10440static const struct ieee80211_geo ipw_geos[] = {
10441 { /* Restricted */
10442 "---",
10443 .bg_channels = 11,
10444 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10445 {2427, 4}, {2432, 5}, {2437, 6},
10446 {2442, 7}, {2447, 8}, {2452, 9},
10447 {2457, 10}, {2462, 11}},
10448 },
10449
10450 { /* Custom US/Canada */
10451 "ZZF",
10452 .bg_channels = 11,
10453 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10454 {2427, 4}, {2432, 5}, {2437, 6},
10455 {2442, 7}, {2447, 8}, {2452, 9},
10456 {2457, 10}, {2462, 11}},
10457 .a_channels = 8,
10458 .a = {{5180, 36},
10459 {5200, 40},
10460 {5220, 44},
10461 {5240, 48},
10462 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10463 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10464 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10465 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10466 },
10467
10468 { /* Rest of World */
10469 "ZZD",
10470 .bg_channels = 13,
10471 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10472 {2427, 4}, {2432, 5}, {2437, 6},
10473 {2442, 7}, {2447, 8}, {2452, 9},
10474 {2457, 10}, {2462, 11}, {2467, 12},
10475 {2472, 13}},
10476 },
10477
10478 { /* Custom USA & Europe & High */
10479 "ZZA",
10480 .bg_channels = 11,
10481 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10482 {2427, 4}, {2432, 5}, {2437, 6},
10483 {2442, 7}, {2447, 8}, {2452, 9},
10484 {2457, 10}, {2462, 11}},
10485 .a_channels = 13,
10486 .a = {{5180, 36},
10487 {5200, 40},
10488 {5220, 44},
10489 {5240, 48},
10490 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10491 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10492 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10493 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10494 {5745, 149},
10495 {5765, 153},
10496 {5785, 157},
10497 {5805, 161},
10498 {5825, 165}},
10499 },
10500
10501 { /* Custom NA & Europe */
10502 "ZZB",
10503 .bg_channels = 11,
10504 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10505 {2427, 4}, {2432, 5}, {2437, 6},
10506 {2442, 7}, {2447, 8}, {2452, 9},
10507 {2457, 10}, {2462, 11}},
10508 .a_channels = 13,
10509 .a = {{5180, 36},
10510 {5200, 40},
10511 {5220, 44},
10512 {5240, 48},
10513 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10514 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10515 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10516 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10517 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10518 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10519 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10520 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10521 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10522 },
10523
10524 { /* Custom Japan */
10525 "ZZC",
10526 .bg_channels = 11,
10527 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10528 {2427, 4}, {2432, 5}, {2437, 6},
10529 {2442, 7}, {2447, 8}, {2452, 9},
10530 {2457, 10}, {2462, 11}},
10531 .a_channels = 4,
10532 .a = {{5170, 34}, {5190, 38},
10533 {5210, 42}, {5230, 46}},
10534 },
10535
10536 { /* Custom */
10537 "ZZM",
10538 .bg_channels = 11,
10539 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10540 {2427, 4}, {2432, 5}, {2437, 6},
10541 {2442, 7}, {2447, 8}, {2452, 9},
10542 {2457, 10}, {2462, 11}},
10543 },
10544
10545 { /* Europe */
10546 "ZZE",
10547 .bg_channels = 13,
10548 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10549 {2427, 4}, {2432, 5}, {2437, 6},
10550 {2442, 7}, {2447, 8}, {2452, 9},
10551 {2457, 10}, {2462, 11}, {2467, 12},
10552 {2472, 13}},
10553 .a_channels = 19,
10554 .a = {{5180, 36},
10555 {5200, 40},
10556 {5220, 44},
10557 {5240, 48},
10558 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10559 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10560 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10561 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10562 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10563 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10564 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10565 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10566 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10567 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10568 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10569 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10570 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10571 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10572 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10573 },
10574
10575 { /* Custom Japan */
10576 "ZZJ",
10577 .bg_channels = 14,
10578 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10579 {2427, 4}, {2432, 5}, {2437, 6},
10580 {2442, 7}, {2447, 8}, {2452, 9},
10581 {2457, 10}, {2462, 11}, {2467, 12},
10582 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10583 .a_channels = 4,
10584 .a = {{5170, 34}, {5190, 38},
10585 {5210, 42}, {5230, 46}},
10586 },
10587
James Ketrenos03520572005-10-19 16:12:31 -050010588 { /* Rest of World */
10589 "ZZR",
10590 .bg_channels = 14,
10591 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10592 {2427, 4}, {2432, 5}, {2437, 6},
10593 {2442, 7}, {2447, 8}, {2452, 9},
10594 {2457, 10}, {2462, 11}, {2467, 12},
10595 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10596 IEEE80211_CH_PASSIVE_ONLY}},
10597 },
10598
James Ketrenos4f36f802005-08-03 20:36:56 -050010599 { /* High Band */
10600 "ZZH",
10601 .bg_channels = 13,
10602 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10603 {2427, 4}, {2432, 5}, {2437, 6},
10604 {2442, 7}, {2447, 8}, {2452, 9},
10605 {2457, 10}, {2462, 11},
10606 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10607 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10608 .a_channels = 4,
10609 .a = {{5745, 149}, {5765, 153},
10610 {5785, 157}, {5805, 161}},
10611 },
10612
10613 { /* Custom Europe */
10614 "ZZG",
10615 .bg_channels = 13,
10616 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10617 {2427, 4}, {2432, 5}, {2437, 6},
10618 {2442, 7}, {2447, 8}, {2452, 9},
10619 {2457, 10}, {2462, 11},
10620 {2467, 12}, {2472, 13}},
10621 .a_channels = 4,
10622 .a = {{5180, 36}, {5200, 40},
10623 {5220, 44}, {5240, 48}},
10624 },
10625
10626 { /* Europe */
10627 "ZZK",
10628 .bg_channels = 13,
10629 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10630 {2427, 4}, {2432, 5}, {2437, 6},
10631 {2442, 7}, {2447, 8}, {2452, 9},
10632 {2457, 10}, {2462, 11},
10633 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10634 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10635 .a_channels = 24,
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 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10645 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10646 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10647 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10648 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10649 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10650 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10651 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10652 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10653 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10654 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10655 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10656 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10657 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10658 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10659 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10660 },
10661
10662 { /* Europe */
10663 "ZZL",
10664 .bg_channels = 11,
10665 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10666 {2427, 4}, {2432, 5}, {2437, 6},
10667 {2442, 7}, {2447, 8}, {2452, 9},
10668 {2457, 10}, {2462, 11}},
10669 .a_channels = 13,
10670 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10671 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10672 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10673 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10674 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10675 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10676 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10677 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10678 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10679 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10680 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10681 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10682 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10683 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010684};
10685
Liu Hong1fe0adb2005-08-19 09:33:10 -050010686/* GEO code borrowed from ieee80211_geo.c */
10687static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
10688{
10689 int i;
10690
10691 /* Driver needs to initialize the geography map before using
10692 * these helper functions */
10693 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10694
10695 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10696 for (i = 0; i < ieee->geo.bg_channels; i++)
10697 /* NOTE: If G mode is currently supported but
10698 * this is a B only channel, we don't see it
10699 * as valid. */
10700 if ((ieee->geo.bg[i].channel == channel) &&
10701 (!(ieee->mode & IEEE_G) ||
10702 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
10703 return IEEE80211_24GHZ_BAND;
10704
10705 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10706 for (i = 0; i < ieee->geo.a_channels; i++)
10707 if (ieee->geo.a[i].channel == channel)
10708 return IEEE80211_52GHZ_BAND;
10709
10710 return 0;
10711}
10712
10713static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
10714{
10715 int i;
10716
10717 /* Driver needs to initialize the geography map before using
10718 * these helper functions */
10719 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10720
10721 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10722 for (i = 0; i < ieee->geo.bg_channels; i++)
10723 if (ieee->geo.bg[i].channel == channel)
10724 return i;
10725
10726 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10727 for (i = 0; i < ieee->geo.a_channels; i++)
10728 if (ieee->geo.a[i].channel == channel)
10729 return i;
10730
10731 return -1;
10732}
10733
10734static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
10735{
10736 int i;
10737
10738 /* Driver needs to initialize the geography map before using
10739 * these helper functions */
10740 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10741
10742 freq /= 100000;
10743
10744 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10745 for (i = 0; i < ieee->geo.bg_channels; i++)
10746 if (ieee->geo.bg[i].freq == freq)
10747 return ieee->geo.bg[i].channel;
10748
10749 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10750 for (i = 0; i < ieee->geo.a_channels; i++)
10751 if (ieee->geo.a[i].freq == freq)
10752 return ieee->geo.a[i].channel;
10753
10754 return 0;
10755}
10756
10757static int ipw_set_geo(struct ieee80211_device *ieee,
10758 const struct ieee80211_geo *geo)
10759{
10760 memcpy(ieee->geo.name, geo->name, 3);
10761 ieee->geo.name[3] = '\0';
10762 ieee->geo.bg_channels = geo->bg_channels;
10763 ieee->geo.a_channels = geo->a_channels;
10764 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
10765 sizeof(struct ieee80211_channel));
10766 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
10767 sizeof(struct ieee80211_channel));
10768 return 0;
10769}
10770
10771static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
10772{
10773 return &ieee->geo;
10774}
10775
James Ketrenos43f66a62005-03-25 12:31:53 -060010776#define MAX_HW_RESTARTS 5
10777static int ipw_up(struct ipw_priv *priv)
10778{
James Ketrenos4f36f802005-08-03 20:36:56 -050010779 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010780
10781 if (priv->status & STATUS_EXIT_PENDING)
10782 return -EIO;
10783
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010784 if (cmdlog && !priv->cmdlog) {
10785 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10786 GFP_KERNEL);
10787 if (priv->cmdlog == NULL) {
10788 IPW_ERROR("Error allocating %d command log entries.\n",
10789 cmdlog);
10790 } else {
10791 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10792 priv->cmdlog_len = cmdlog;
10793 }
10794 }
10795
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010796 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010797 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010798 * Also start the clocks. */
10799 rc = ipw_load(priv);
10800 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010801 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010802 return rc;
10803 }
10804
10805 ipw_init_ordinals(priv);
10806 if (!(priv->config & CFG_CUSTOM_MAC))
10807 eeprom_parse_mac(priv, priv->mac_addr);
10808 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10809
James Ketrenos4f36f802005-08-03 20:36:56 -050010810 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10811 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10812 ipw_geos[j].name, 3))
10813 break;
10814 }
James Ketrenos03520572005-10-19 16:12:31 -050010815 if (j == ARRAY_SIZE(ipw_geos)) {
10816 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10817 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10818 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10819 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010820 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010821 }
Liu Hong1fe0adb2005-08-19 09:33:10 -050010822 if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010823 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010824 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010825 }
10826
10827 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10828 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010829
James Ketrenosb095c382005-08-24 22:04:42 -050010830 if (priv->status & STATUS_RF_KILL_SW) {
10831 IPW_WARNING("Radio disabled by module parameter.\n");
10832 return 0;
10833 } else if (rf_kill_active(priv)) {
10834 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10835 "Kill switch must be turned off for "
10836 "wireless networking to work.\n");
10837 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10838 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010839 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010840 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010841
10842 rc = ipw_config(priv);
10843 if (!rc) {
10844 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010845
James Ketrenose6666192005-08-12 09:17:04 -050010846 /* If configure to try and auto-associate, kick
10847 * off a scan. */
10848 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010849
James Ketrenos43f66a62005-03-25 12:31:53 -060010850 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010851 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010852
James Ketrenosc848d0a2005-08-24 21:56:24 -050010853 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010854 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10855 i, MAX_HW_RESTARTS);
10856
10857 /* We had an error bringing up the hardware, so take it
10858 * all the way back down so we can try again */
10859 ipw_down(priv);
10860 }
10861
Jeff Garzikbf794512005-07-31 13:07:26 -040010862 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010863 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010864 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010865
James Ketrenos43f66a62005-03-25 12:31:53 -060010866 return -EIO;
10867}
10868
James Ketrenosc848d0a2005-08-24 21:56:24 -050010869static void ipw_bg_up(void *data)
10870{
10871 struct ipw_priv *priv = data;
10872 down(&priv->sem);
10873 ipw_up(data);
10874 up(&priv->sem);
10875}
10876
James Ketrenosb095c382005-08-24 22:04:42 -050010877static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010878{
James Ketrenosb095c382005-08-24 22:04:42 -050010879 int i;
10880
10881 if (priv->status & STATUS_SCANNING) {
10882 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10883 ipw_abort_scan(priv);
10884 }
10885
10886 if (priv->status & STATUS_ASSOCIATED) {
10887 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10888 ipw_disassociate(priv);
10889 }
10890
10891 ipw_led_shutdown(priv);
10892
10893 /* Wait up to 1s for status to change to not scanning and not
10894 * associated (disassociation can take a while for a ful 802.11
10895 * exchange */
10896 for (i = 1000; i && (priv->status &
10897 (STATUS_DISASSOCIATING |
10898 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10899 udelay(10);
10900
10901 if (priv->status & (STATUS_DISASSOCIATING |
10902 STATUS_ASSOCIATED | STATUS_SCANNING))
10903 IPW_DEBUG_INFO("Still associated or scanning...\n");
10904 else
10905 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10906
James Ketrenosc848d0a2005-08-24 21:56:24 -050010907 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010908 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010909
10910 priv->status &= ~STATUS_INIT;
10911}
10912
James Ketrenos43f66a62005-03-25 12:31:53 -060010913static void ipw_down(struct ipw_priv *priv)
10914{
James Ketrenosb095c382005-08-24 22:04:42 -050010915 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10916
10917 priv->status |= STATUS_EXIT_PENDING;
10918
10919 if (ipw_is_init(priv))
10920 ipw_deinit(priv);
10921
10922 /* Wipe out the EXIT_PENDING status bit if we are not actually
10923 * exiting the module */
10924 if (!exit_pending)
10925 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010926
10927 /* tell the device to stop sending interrupts */
10928 ipw_disable_interrupts(priv);
10929
10930 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010931 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010932 netif_carrier_off(priv->net_dev);
10933 netif_stop_queue(priv->net_dev);
10934
10935 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010936
10937 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010938}
10939
James Ketrenosc848d0a2005-08-24 21:56:24 -050010940static void ipw_bg_down(void *data)
10941{
10942 struct ipw_priv *priv = data;
10943 down(&priv->sem);
10944 ipw_down(data);
10945 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010946}
10947
10948/* Called by register_netdev() */
10949static int ipw_net_init(struct net_device *dev)
10950{
10951 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010952 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010953
James Ketrenosc848d0a2005-08-24 21:56:24 -050010954 if (ipw_up(priv)) {
10955 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010956 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010957 }
10958
James Ketrenosc848d0a2005-08-24 21:56:24 -050010959 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010960 return 0;
10961}
10962
10963/* PCI driver stuff */
10964static struct pci_device_id card_ids[] = {
10965 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10966 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10967 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10968 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10969 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10970 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10971 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10972 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10973 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10974 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10975 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10976 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10977 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10978 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10979 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10980 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10981 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10982 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010983 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010984 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010985 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10986 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010987
James Ketrenos43f66a62005-03-25 12:31:53 -060010988 /* required last entry */
10989 {0,}
10990};
10991
10992MODULE_DEVICE_TABLE(pci, card_ids);
10993
10994static struct attribute *ipw_sysfs_entries[] = {
10995 &dev_attr_rf_kill.attr,
10996 &dev_attr_direct_dword.attr,
10997 &dev_attr_indirect_byte.attr,
10998 &dev_attr_indirect_dword.attr,
10999 &dev_attr_mem_gpio_reg.attr,
11000 &dev_attr_command_event_reg.attr,
11001 &dev_attr_nic_type.attr,
11002 &dev_attr_status.attr,
11003 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011004 &dev_attr_error.attr,
11005 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011006 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011007 &dev_attr_eeprom_delay.attr,
11008 &dev_attr_ucode_version.attr,
11009 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011010 &dev_attr_scan_age.attr,
11011 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011012 &dev_attr_speed_scan.attr,
11013 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011014 NULL
11015};
11016
11017static struct attribute_group ipw_attribute_group = {
11018 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011019 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011020};
11021
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011022static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011023{
11024 int err = 0;
11025 struct net_device *net_dev;
11026 void __iomem *base;
11027 u32 length, val;
11028 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011029 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011030
11031 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11032 if (net_dev == NULL) {
11033 err = -ENOMEM;
11034 goto out;
11035 }
11036
11037 priv = ieee80211_priv(net_dev);
11038 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011039
James Ketrenos43f66a62005-03-25 12:31:53 -060011040 priv->net_dev = net_dev;
11041 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080011042#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011043 ipw_debug_level = debug;
11044#endif
11045 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011046 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11047 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011048
James Ketrenosc848d0a2005-08-24 21:56:24 -050011049 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011050 if (pci_enable_device(pdev)) {
11051 err = -ENODEV;
11052 goto out_free_ieee80211;
11053 }
11054
11055 pci_set_master(pdev);
11056
Tobias Klauser0e08b442005-06-20 14:28:41 -070011057 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011058 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011059 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011060 if (err) {
11061 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11062 goto out_pci_disable_device;
11063 }
11064
11065 pci_set_drvdata(pdev, priv);
11066
11067 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011068 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011069 goto out_pci_disable_device;
11070
Jeff Garzikbf794512005-07-31 13:07:26 -040011071 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011072 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011073 pci_read_config_dword(pdev, 0x40, &val);
11074 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011075 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011076
James Ketrenos43f66a62005-03-25 12:31:53 -060011077 length = pci_resource_len(pdev, 0);
11078 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011079
James Ketrenos43f66a62005-03-25 12:31:53 -060011080 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11081 if (!base) {
11082 err = -ENODEV;
11083 goto out_pci_release_regions;
11084 }
11085
11086 priv->hw_base = base;
11087 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11088 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11089
11090 err = ipw_setup_deferred_work(priv);
11091 if (err) {
11092 IPW_ERROR("Unable to setup deferred work\n");
11093 goto out_iounmap;
11094 }
11095
James Ketrenosb095c382005-08-24 22:04:42 -050011096 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011097
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011098 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011099 if (err) {
11100 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11101 goto out_destroy_workqueue;
11102 }
11103
11104 SET_MODULE_OWNER(net_dev);
11105 SET_NETDEV_DEV(net_dev, &pdev->dev);
11106
James Ketrenosc848d0a2005-08-24 21:56:24 -050011107 down(&priv->sem);
11108
James Ketrenos43f66a62005-03-25 12:31:53 -060011109 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11110 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011111 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011112
James Ketrenosb095c382005-08-24 22:04:42 -050011113#ifdef CONFIG_IPW_QOS
James Ketrenos3b9990c2005-08-19 13:18:55 -050011114 priv->ieee->handle_probe_response = ipw_handle_beacon;
11115 priv->ieee->handle_beacon = ipw_handle_probe_response;
11116 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050011117#endif /* CONFIG_IPW_QOS */
11118
James Ketrenosc848d0a2005-08-24 21:56:24 -050011119 priv->ieee->perfect_rssi = -20;
11120 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011121
11122 net_dev->open = ipw_net_open;
11123 net_dev->stop = ipw_net_stop;
11124 net_dev->init = ipw_net_init;
11125 net_dev->get_stats = ipw_net_get_stats;
11126 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11127 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011128 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011129 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011130 net_dev->wireless_handlers = &ipw_wx_handler_def;
11131 net_dev->ethtool_ops = &ipw_ethtool_ops;
11132 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011133 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011134 net_dev->mem_start = pci_resource_start(pdev, 0);
11135 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11136
11137 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11138 if (err) {
11139 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011140 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011141 goto out_release_irq;
11142 }
11143
James Ketrenosc848d0a2005-08-24 21:56:24 -050011144 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011145 err = register_netdev(net_dev);
11146 if (err) {
11147 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011148 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011149 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011150 return 0;
11151
James Ketrenosa613bff2005-08-24 21:43:11 -050011152 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011153 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011154 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011155 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011156 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011157 destroy_workqueue(priv->workqueue);
11158 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011159 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011160 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011161 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011162 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011163 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011164 pci_disable_device(pdev);
11165 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011166 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011167 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011168 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011169 return err;
11170}
11171
11172static void ipw_pci_remove(struct pci_dev *pdev)
11173{
11174 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011175 struct list_head *p, *q;
11176 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011177
James Ketrenos43f66a62005-03-25 12:31:53 -060011178 if (!priv)
11179 return;
11180
James Ketrenosb095c382005-08-24 22:04:42 -050011181 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011182
James Ketrenosafbf30a2005-08-25 00:05:33 -050011183 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011184 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011185 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11186
James Ketrenosb095c382005-08-24 22:04:42 -050011187 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011188
11189 unregister_netdev(priv->net_dev);
11190
11191 if (priv->rxq) {
11192 ipw_rx_queue_free(priv, priv->rxq);
11193 priv->rxq = NULL;
11194 }
11195 ipw_tx_queue_free(priv);
11196
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011197 if (priv->cmdlog) {
11198 kfree(priv->cmdlog);
11199 priv->cmdlog = NULL;
11200 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011201 /* ipw_down will ensure that there is no more pending work
11202 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011203 cancel_delayed_work(&priv->adhoc_check);
11204 cancel_delayed_work(&priv->gather_stats);
11205 cancel_delayed_work(&priv->request_scan);
11206 cancel_delayed_work(&priv->rf_kill);
11207 cancel_delayed_work(&priv->scan_check);
11208 destroy_workqueue(priv->workqueue);
11209 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011210
James Ketrenosafbf30a2005-08-25 00:05:33 -050011211 /* Free MAC hash list for ADHOC */
11212 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11213 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011214 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011215 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011216 }
11217 }
11218
James Ketrenosb39860c2005-08-12 09:36:32 -050011219 if (priv->error) {
11220 ipw_free_error_log(priv->error);
11221 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011222 }
11223
11224 free_irq(pdev->irq, priv);
11225 iounmap(priv->hw_base);
11226 pci_release_regions(pdev);
11227 pci_disable_device(pdev);
11228 pci_set_drvdata(pdev, NULL);
11229 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011230 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011231}
11232
James Ketrenos43f66a62005-03-25 12:31:53 -060011233#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011234static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011235{
11236 struct ipw_priv *priv = pci_get_drvdata(pdev);
11237 struct net_device *dev = priv->net_dev;
11238
11239 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11240
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011241 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011242 ipw_down(priv);
11243
11244 /* Remove the PRESENT state of the device */
11245 netif_device_detach(dev);
11246
James Ketrenos43f66a62005-03-25 12:31:53 -060011247 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011248 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011249 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011250
James Ketrenos43f66a62005-03-25 12:31:53 -060011251 return 0;
11252}
11253
11254static int ipw_pci_resume(struct pci_dev *pdev)
11255{
11256 struct ipw_priv *priv = pci_get_drvdata(pdev);
11257 struct net_device *dev = priv->net_dev;
11258 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011259
James Ketrenos43f66a62005-03-25 12:31:53 -060011260 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11261
James Ketrenosea2b26e2005-08-24 21:25:16 -050011262 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011263 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011264 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011265
James Ketrenos43f66a62005-03-25 12:31:53 -060011266 /*
11267 * Suspend/Resume resets the PCI configuration space, so we have to
11268 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11269 * from interfering with C3 CPU state. pci_restore_state won't help
11270 * here since it only restores the first 64 bytes pci config header.
11271 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011272 pci_read_config_dword(pdev, 0x40, &val);
11273 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011274 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11275
11276 /* Set the device back into the PRESENT state; this will also wake
11277 * the queue of needed */
11278 netif_device_attach(dev);
11279
11280 /* Bring the device back up */
11281 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011282
James Ketrenos43f66a62005-03-25 12:31:53 -060011283 return 0;
11284}
11285#endif
11286
11287/* driver initialization stuff */
11288static struct pci_driver ipw_driver = {
11289 .name = DRV_NAME,
11290 .id_table = card_ids,
11291 .probe = ipw_pci_probe,
11292 .remove = __devexit_p(ipw_pci_remove),
11293#ifdef CONFIG_PM
11294 .suspend = ipw_pci_suspend,
11295 .resume = ipw_pci_resume,
11296#endif
11297};
11298
11299static int __init ipw_init(void)
11300{
11301 int ret;
11302
11303 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11304 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11305
11306 ret = pci_module_init(&ipw_driver);
11307 if (ret) {
11308 IPW_ERROR("Unable to initialize PCI module\n");
11309 return ret;
11310 }
11311
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011312 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011313 if (ret) {
11314 IPW_ERROR("Unable to create driver sysfs file\n");
11315 pci_unregister_driver(&ipw_driver);
11316 return ret;
11317 }
11318
11319 return ret;
11320}
11321
11322static void __exit ipw_exit(void)
11323{
11324 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11325 pci_unregister_driver(&ipw_driver);
11326}
11327
11328module_param(disable, int, 0444);
11329MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11330
11331module_param(associate, int, 0444);
11332MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11333
11334module_param(auto_create, int, 0444);
11335MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11336
James Ketrenosa613bff2005-08-24 21:43:11 -050011337module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011338MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011339
James Ketrenos43f66a62005-03-25 12:31:53 -060011340module_param(debug, int, 0444);
11341MODULE_PARM_DESC(debug, "debug output mask");
11342
11343module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011344MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011345
James Ketrenosb095c382005-08-24 22:04:42 -050011346#ifdef CONFIG_IPW_QOS
11347module_param(qos_enable, int, 0444);
11348MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011349
James Ketrenosb095c382005-08-24 22:04:42 -050011350module_param(qos_burst_enable, int, 0444);
11351MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11352
11353module_param(qos_no_ack_mask, int, 0444);
11354MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11355
11356module_param(burst_duration_CCK, int, 0444);
11357MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11358
11359module_param(burst_duration_OFDM, int, 0444);
11360MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11361#endif /* CONFIG_IPW_QOS */
11362
11363#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011364module_param(mode, int, 0444);
11365MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11366#else
11367module_param(mode, int, 0444);
11368MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11369#endif
11370
Zhu Yi810dabd2006-01-24 16:36:59 +080011371module_param(bt_coexist, int, 0444);
11372MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11373
James Ketrenosb095c382005-08-24 22:04:42 -050011374module_param(hwcrypto, int, 0444);
11375MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11376
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011377module_param(cmdlog, int, 0444);
11378MODULE_PARM_DESC(cmdlog,
11379 "allocate a ring buffer for logging firmware commands");
11380
James Ketrenos43f66a62005-03-25 12:31:53 -060011381module_exit(ipw_exit);
11382module_init(ipw_init);