blob: 2a834deb60e8decd26c0bb22f0933e43fccb58e5 [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;
James Ketrenosb095c382005-08-24 22:04:42 -050058static int hwcrypto = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060059static const char ipw_modes[] = {
60 'a', 'b', 'g', '?'
61};
62
James Ketrenosb095c382005-08-24 22:04:42 -050063#ifdef CONFIG_IPW_QOS
64static int qos_enable = 0;
65static int qos_burst_enable = 0;
66static int qos_no_ack_mask = 0;
67static int burst_duration_CCK = 0;
68static int burst_duration_OFDM = 0;
69
70static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
71 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
72 QOS_TX3_CW_MIN_OFDM},
73 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
74 QOS_TX3_CW_MAX_OFDM},
75 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
76 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
77 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
78 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
79};
80
81static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
82 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
83 QOS_TX3_CW_MIN_CCK},
84 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
85 QOS_TX3_CW_MAX_CCK},
86 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
87 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
88 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
89 QOS_TX3_TXOP_LIMIT_CCK}
90};
91
92static struct ieee80211_qos_parameters def_parameters_OFDM = {
93 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
94 DEF_TX3_CW_MIN_OFDM},
95 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
96 DEF_TX3_CW_MAX_OFDM},
97 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
98 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
99 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
100 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
101};
102
103static struct ieee80211_qos_parameters def_parameters_CCK = {
104 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
105 DEF_TX3_CW_MIN_CCK},
106 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
107 DEF_TX3_CW_MAX_CCK},
108 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
109 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
110 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
111 DEF_TX3_TXOP_LIMIT_CCK}
112};
113
114static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
115
116static int from_priority_to_tx_queue[] = {
117 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
118 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
119};
120
121static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
122
123static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
124 *qos_param);
125static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
126 *qos_param);
127#endif /* CONFIG_IPW_QOS */
128
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000129static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500130static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600131static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400132static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600133 struct clx2_tx_queue *txq, int qindex);
134static int ipw_queue_reset(struct ipw_priv *priv);
135
136static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
137 int len, int sync);
138
139static void ipw_tx_queue_free(struct ipw_priv *);
140
141static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
142static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
143static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600144static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500145static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600146static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500147static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600148static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400149static int init_supported_rates(struct ipw_priv *priv,
150 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500151static void ipw_set_hwcrypto_keys(struct ipw_priv *);
152static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600153
Liu Hong1fe0adb2005-08-19 09:33:10 -0500154static int ipw_is_valid_channel(struct ieee80211_device *, u8);
155static int ipw_channel_to_index(struct ieee80211_device *, u8);
156static u8 ipw_freq_to_channel(struct ieee80211_device *, u32);
157static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *);
158static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600159
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500160static int snprint_line(char *buf, size_t count,
161 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600162{
163 int out, i, j, l;
164 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400165
James Ketrenos43f66a62005-03-25 12:31:53 -0600166 out = snprintf(buf, count, "%08X", ofs);
167
168 for (l = 0, i = 0; i < 2; i++) {
169 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400170 for (j = 0; j < 8 && l < len; j++, l++)
171 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600172 data[(i * 8 + j)]);
173 for (; j < 8; j++)
174 out += snprintf(buf + out, count - out, " ");
175 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400176
James Ketrenos43f66a62005-03-25 12:31:53 -0600177 out += snprintf(buf + out, count - out, " ");
178 for (l = 0, i = 0; i < 2; i++) {
179 out += snprintf(buf + out, count - out, " ");
180 for (j = 0; j < 8 && l < len; j++, l++) {
181 c = data[(i * 8 + j)];
182 if (!isascii(c) || !isprint(c))
183 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400184
James Ketrenos43f66a62005-03-25 12:31:53 -0600185 out += snprintf(buf + out, count - out, "%c", c);
186 }
187
188 for (; j < 8; j++)
189 out += snprintf(buf + out, count - out, " ");
190 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400191
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500192 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600193}
194
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400195static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600196{
197 char line[81];
198 u32 ofs = 0;
199 if (!(ipw_debug_level & level))
200 return;
201
202 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500203 snprint_line(line, sizeof(line), &data[ofs],
204 min(len, 16U), ofs);
205 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600206 ofs += 16;
207 len -= min(len, 16U);
208 }
209}
210
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500211static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
212{
213 size_t out = size;
214 u32 ofs = 0;
215 int total = 0;
216
217 while (size && len) {
218 out = snprint_line(output, size, &data[ofs],
219 min_t(size_t, len, 16U), ofs);
220
221 ofs += 16;
222 output += out;
223 size -= out;
224 len -= min_t(size_t, len, 16U);
225 total += out;
226 }
227 return total;
228}
229
James Ketrenos43f66a62005-03-25 12:31:53 -0600230static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
231#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
232
233static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
234#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
235
236static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
237static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
238{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400239 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
240 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600241 _ipw_write_reg8(a, b, c);
242}
243
244static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
245static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
246{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400247 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
248 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600249 _ipw_write_reg16(a, b, c);
250}
251
252static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
253static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
254{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400255 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
256 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600257 _ipw_write_reg32(a, b, c);
258}
259
260#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
261#define ipw_write8(ipw, ofs, val) \
262 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
263 _ipw_write8(ipw, ofs, val)
264
265#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
266#define ipw_write16(ipw, ofs, val) \
267 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
268 _ipw_write16(ipw, ofs, val)
269
270#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
271#define ipw_write32(ipw, ofs, val) \
272 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
273 _ipw_write32(ipw, ofs, val)
274
275#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400276static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
277{
278 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600279 return _ipw_read8(ipw, ofs);
280}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400281
James Ketrenos43f66a62005-03-25 12:31:53 -0600282#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
283
284#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400285static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
286{
287 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600288 return _ipw_read16(ipw, ofs);
289}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400290
James Ketrenos43f66a62005-03-25 12:31:53 -0600291#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
292
293#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400294static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
295{
296 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600297 return _ipw_read32(ipw, ofs);
298}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400299
James Ketrenos43f66a62005-03-25 12:31:53 -0600300#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
301
302static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500303static inline void __ipw_read_indirect(const char *f, int l,
304 struct ipw_priv *a, u32 b, u8 * c, int d)
305{
306 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
307 d);
308 _ipw_read_indirect(a, b, c, d);
309}
310
311#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600312
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400313static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
314 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600315#define ipw_write_indirect(a, b, c, d) \
316 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500317 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600318
319/* indirect write s */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400320static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600321{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400322 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500323 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
324 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600325}
326
James Ketrenos43f66a62005-03-25 12:31:53 -0600327static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
328{
329 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500330 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
331 _ipw_write8(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600332}
333
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400334static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600335{
336 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500337 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
338 _ipw_write16(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600339}
340
341/* indirect read s */
342
343static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
344{
345 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500346 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600347 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500348 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400349 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600350}
351
352static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
353{
354 u32 value;
355
356 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
357
James Ketrenosb095c382005-08-24 22:04:42 -0500358 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
359 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600360 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
361 return value;
362}
363
364/* iterative/auto-increment 32 bit reads and writes */
365static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
366 int num)
367{
James Ketrenosb095c382005-08-24 22:04:42 -0500368 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -0600369 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600370 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400371
James Ketrenos43f66a62005-03-25 12:31:53 -0600372 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
373
James Ketrenosea2b26e2005-08-24 21:25:16 -0500374 if (num <= 0) {
375 return;
376 }
377
James Ketrenos43f66a62005-03-25 12:31:53 -0600378 /* Read the first nibble byte by byte */
379 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500380 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600381 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500382 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500383 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600384 aligned_addr += 4;
385 }
386
James Ketrenosb095c382005-08-24 22:04:42 -0500387 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500388 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500389 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400390
James Ketrenos43f66a62005-03-25 12:31:53 -0600391 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500392 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500393 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500394 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500395 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500396 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600397}
398
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400399static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600400 int num)
401{
James Ketrenosb095c382005-08-24 22:04:42 -0500402 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600404 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400405
James Ketrenos43f66a62005-03-25 12:31:53 -0600406 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400407
James Ketrenosea2b26e2005-08-24 21:25:16 -0500408 if (num <= 0) {
409 return;
410 }
411
James Ketrenos43f66a62005-03-25 12:31:53 -0600412 /* Write the first nibble byte by byte */
413 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500414 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500415 /* Start reading at aligned_addr + dif_len */
416 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500417 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600418 aligned_addr += 4;
419 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400420
James Ketrenosb095c382005-08-24 22:04:42 -0500421 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500422 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500423 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400424
James Ketrenos43f66a62005-03-25 12:31:53 -0600425 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500426 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500427 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500428 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500429 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500430 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600431}
432
Jeff Garzikbf794512005-07-31 13:07:26 -0400433static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600434 int num)
435{
436 memcpy_toio((priv->hw_base + addr), buf, num);
437}
438
439static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
440{
441 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
442}
443
444static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
445{
446 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
447}
448
449static inline void ipw_enable_interrupts(struct ipw_priv *priv)
450{
451 if (priv->status & STATUS_INT_ENABLED)
452 return;
453 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500454 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600455}
456
457static inline void ipw_disable_interrupts(struct ipw_priv *priv)
458{
459 if (!(priv->status & STATUS_INT_ENABLED))
460 return;
461 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500462 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600463}
464
Brice Goglin0f52bf92005-12-01 01:41:46 -0800465#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600466static char *ipw_error_desc(u32 val)
467{
468 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400469 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600470 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400471 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600472 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400473 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600474 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400475 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400477 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500478 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400479 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500480 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400481 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500482 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400483 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500484 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400485 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500486 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400487 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500488 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400489 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500490 return "DMA_STATUS";
491 case IPW_FW_ERROR_DINO_ERROR:
492 return "DINO_ERROR";
493 case IPW_FW_ERROR_EEPROM_ERROR:
494 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400495 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500496 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400497 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500498 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400499 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500500 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600501 }
502}
503
James Ketrenosb39860c2005-08-12 09:36:32 -0500504static void ipw_dump_error_log(struct ipw_priv *priv,
505 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600506{
James Ketrenosb39860c2005-08-12 09:36:32 -0500507 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600508
James Ketrenosb39860c2005-08-12 09:36:32 -0500509 if (!error) {
510 IPW_ERROR("Error allocating and capturing error log. "
511 "Nothing to dump.\n");
512 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600513 }
514
James Ketrenosb39860c2005-08-12 09:36:32 -0500515 IPW_ERROR("Start IPW Error Log Dump:\n");
516 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
517 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600518
James Ketrenosb39860c2005-08-12 09:36:32 -0500519 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400520 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500521 ipw_error_desc(error->elem[i].desc),
522 error->elem[i].time,
523 error->elem[i].blink1,
524 error->elem[i].blink2,
525 error->elem[i].link1,
526 error->elem[i].link2, error->elem[i].data);
527 for (i = 0; i < error->log_len; i++)
528 IPW_ERROR("%i\t0x%08x\t%i\n",
529 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500530 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600531}
James Ketrenos43f66a62005-03-25 12:31:53 -0600532#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600533
James Ketrenosc848d0a2005-08-24 21:56:24 -0500534static inline int ipw_is_init(struct ipw_priv *priv)
535{
536 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600537}
538
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400539static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600540{
541 u32 addr, field_info, field_len, field_count, total_len;
542
543 IPW_DEBUG_ORD("ordinal = %i\n", ord);
544
545 if (!priv || !val || !len) {
546 IPW_DEBUG_ORD("Invalid argument\n");
547 return -EINVAL;
548 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400549
James Ketrenos43f66a62005-03-25 12:31:53 -0600550 /* verify device ordinal tables have been initialized */
551 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
552 IPW_DEBUG_ORD("Access ordinals before initialization\n");
553 return -EINVAL;
554 }
555
556 switch (IPW_ORD_TABLE_ID_MASK & ord) {
557 case IPW_ORD_TABLE_0_MASK:
558 /*
559 * TABLE 0: Direct access to a table of 32 bit values
560 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400561 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600562 * read from the table
563 */
564
565 /* remove the table id from the ordinal */
566 ord &= IPW_ORD_TABLE_VALUE_MASK;
567
568 /* boundary check */
569 if (ord > priv->table0_len) {
570 IPW_DEBUG_ORD("ordinal value (%i) longer then "
571 "max (%i)\n", ord, priv->table0_len);
572 return -EINVAL;
573 }
574
575 /* verify we have enough room to store the value */
576 if (*len < sizeof(u32)) {
577 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200578 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600579 return -EINVAL;
580 }
581
582 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400583 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600584
585 *len = sizeof(u32);
586 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400587 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600588 break;
589
590 case IPW_ORD_TABLE_1_MASK:
591 /*
592 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400593 *
594 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600595 * representing starting addr for the data (which is
596 * also a u32)
597 */
598
599 /* remove the table id from the ordinal */
600 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400601
James Ketrenos43f66a62005-03-25 12:31:53 -0600602 /* boundary check */
603 if (ord > priv->table1_len) {
604 IPW_DEBUG_ORD("ordinal value too long\n");
605 return -EINVAL;
606 }
607
608 /* verify we have enough room to store the value */
609 if (*len < sizeof(u32)) {
610 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200611 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600612 return -EINVAL;
613 }
614
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400615 *((u32 *) val) =
616 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600617 *len = sizeof(u32);
618 break;
619
620 case IPW_ORD_TABLE_2_MASK:
621 /*
622 * TABLE 2: Indirect access to a table of variable sized values
623 *
624 * This table consist of six values, each containing
625 * - dword containing the starting offset of the data
626 * - dword containing the lengh in the first 16bits
627 * and the count in the second 16bits
628 */
629
630 /* remove the table id from the ordinal */
631 ord &= IPW_ORD_TABLE_VALUE_MASK;
632
633 /* boundary check */
634 if (ord > priv->table2_len) {
635 IPW_DEBUG_ORD("ordinal value too long\n");
636 return -EINVAL;
637 }
638
639 /* get the address of statistic */
640 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400641
642 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600643 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400644 field_info =
645 ipw_read_reg32(priv,
646 priv->table2_addr + (ord << 3) +
647 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400648
James Ketrenos43f66a62005-03-25 12:31:53 -0600649 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400650 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400651
James Ketrenos43f66a62005-03-25 12:31:53 -0600652 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400653 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400654
James Ketrenos43f66a62005-03-25 12:31:53 -0600655 /* abort if not enought memory */
656 total_len = field_len * field_count;
657 if (total_len > *len) {
658 *len = total_len;
659 return -EINVAL;
660 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400661
James Ketrenos43f66a62005-03-25 12:31:53 -0600662 *len = total_len;
663 if (!total_len)
664 return 0;
665
666 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400667 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600668 addr, total_len, field_info);
669 ipw_read_indirect(priv, addr, val, total_len);
670 break;
671
672 default:
673 IPW_DEBUG_ORD("Invalid ordinal!\n");
674 return -EINVAL;
675
676 }
677
James Ketrenos43f66a62005-03-25 12:31:53 -0600678 return 0;
679}
680
681static void ipw_init_ordinals(struct ipw_priv *priv)
682{
683 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400684 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600685
686 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
687 priv->table0_addr, priv->table0_len);
688
689 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
690 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
691
692 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
693 priv->table1_addr, priv->table1_len);
694
695 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
696 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400697 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600698
699 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
700 priv->table2_addr, priv->table2_len);
701
702}
703
Adrian Bunka73e22b2006-01-21 01:39:42 +0100704static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500705{
James Ketrenosb095c382005-08-24 22:04:42 -0500706 reg &= ~IPW_START_STANDBY;
707 if (reg & IPW_GATE_ODMA)
708 reg &= ~IPW_GATE_ODMA;
709 if (reg & IPW_GATE_IDMA)
710 reg &= ~IPW_GATE_IDMA;
711 if (reg & IPW_GATE_ADMA)
712 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500713 return reg;
714}
715
716/*
717 * LED behavior:
718 * - On radio ON, turn on any LEDs that require to be on during start
719 * - On initialization, start unassociated blink
720 * - On association, disable unassociated blink
721 * - On disassociation, start unassociated blink
722 * - On radio OFF, turn off any LEDs started during radio on
723 *
724 */
725#define LD_TIME_LINK_ON 300
726#define LD_TIME_LINK_OFF 2700
727#define LD_TIME_ACT_ON 250
728
Adrian Bunka73e22b2006-01-21 01:39:42 +0100729static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500730{
731 unsigned long flags;
732 u32 led;
733
734 /* If configured to not use LEDs, or nic_type is 1,
735 * then we don't toggle a LINK led */
736 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
737 return;
738
739 spin_lock_irqsave(&priv->lock, flags);
740
741 if (!(priv->status & STATUS_RF_KILL_MASK) &&
742 !(priv->status & STATUS_LED_LINK_ON)) {
743 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500744 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500745 led |= priv->led_association_on;
746
747 led = ipw_register_toggle(led);
748
749 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500750 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500751
752 priv->status |= STATUS_LED_LINK_ON;
753
754 /* If we aren't associated, schedule turning the LED off */
755 if (!(priv->status & STATUS_ASSOCIATED))
756 queue_delayed_work(priv->workqueue,
757 &priv->led_link_off,
758 LD_TIME_LINK_ON);
759 }
760
761 spin_unlock_irqrestore(&priv->lock, flags);
762}
763
James Ketrenosc848d0a2005-08-24 21:56:24 -0500764static void ipw_bg_led_link_on(void *data)
765{
766 struct ipw_priv *priv = data;
767 down(&priv->sem);
768 ipw_led_link_on(data);
769 up(&priv->sem);
770}
771
Adrian Bunka73e22b2006-01-21 01:39:42 +0100772static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500773{
774 unsigned long flags;
775 u32 led;
776
777 /* If configured not to use LEDs, or nic type is 1,
778 * then we don't goggle the LINK led. */
779 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
780 return;
781
782 spin_lock_irqsave(&priv->lock, flags);
783
784 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500785 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500786 led &= priv->led_association_off;
787 led = ipw_register_toggle(led);
788
789 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500790 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500791
792 IPW_DEBUG_LED("Link LED Off\n");
793
794 priv->status &= ~STATUS_LED_LINK_ON;
795
796 /* If we aren't associated and the radio is on, schedule
797 * turning the LED on (blink while unassociated) */
798 if (!(priv->status & STATUS_RF_KILL_MASK) &&
799 !(priv->status & STATUS_ASSOCIATED))
800 queue_delayed_work(priv->workqueue, &priv->led_link_on,
801 LD_TIME_LINK_OFF);
802
803 }
804
805 spin_unlock_irqrestore(&priv->lock, flags);
806}
807
James Ketrenosc848d0a2005-08-24 21:56:24 -0500808static void ipw_bg_led_link_off(void *data)
809{
810 struct ipw_priv *priv = data;
811 down(&priv->sem);
812 ipw_led_link_off(data);
813 up(&priv->sem);
814}
815
Arjan van de Ven858119e2006-01-14 13:20:43 -0800816static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500817{
James Ketrenosa613bff2005-08-24 21:43:11 -0500818 u32 led;
819
820 if (priv->config & CFG_NO_LED)
821 return;
822
James Ketrenosb095c382005-08-24 22:04:42 -0500823 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500824 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500825
826 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500827 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500828 led |= priv->led_activity_on;
829
830 led = ipw_register_toggle(led);
831
832 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500833 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500834
835 IPW_DEBUG_LED("Activity LED On\n");
836
837 priv->status |= STATUS_LED_ACT_ON;
838
James Ketrenosc848d0a2005-08-24 21:56:24 -0500839 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500840 queue_delayed_work(priv->workqueue, &priv->led_act_off,
841 LD_TIME_ACT_ON);
842 } else {
843 /* Reschedule LED off for full time period */
844 cancel_delayed_work(&priv->led_act_off);
845 queue_delayed_work(priv->workqueue, &priv->led_act_off,
846 LD_TIME_ACT_ON);
847 }
James Ketrenosb095c382005-08-24 22:04:42 -0500848}
James Ketrenosa613bff2005-08-24 21:43:11 -0500849
Adrian Bunka73e22b2006-01-21 01:39:42 +0100850#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500851void ipw_led_activity_on(struct ipw_priv *priv)
852{
853 unsigned long flags;
854 spin_lock_irqsave(&priv->lock, flags);
855 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500856 spin_unlock_irqrestore(&priv->lock, flags);
857}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100858#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500859
Adrian Bunka73e22b2006-01-21 01:39:42 +0100860static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500861{
862 unsigned long flags;
863 u32 led;
864
865 if (priv->config & CFG_NO_LED)
866 return;
867
868 spin_lock_irqsave(&priv->lock, flags);
869
870 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500871 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500872 led &= priv->led_activity_off;
873
874 led = ipw_register_toggle(led);
875
876 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500877 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500878
879 IPW_DEBUG_LED("Activity LED Off\n");
880
881 priv->status &= ~STATUS_LED_ACT_ON;
882 }
883
884 spin_unlock_irqrestore(&priv->lock, flags);
885}
886
James Ketrenosc848d0a2005-08-24 21:56:24 -0500887static void ipw_bg_led_activity_off(void *data)
888{
889 struct ipw_priv *priv = data;
890 down(&priv->sem);
891 ipw_led_activity_off(data);
892 up(&priv->sem);
893}
894
Adrian Bunka73e22b2006-01-21 01:39:42 +0100895static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500896{
897 unsigned long flags;
898 u32 led;
899
900 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500901 if (priv->config & CFG_NO_LED ||
902 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500903 return;
904
905 spin_lock_irqsave(&priv->lock, flags);
906
James Ketrenosb095c382005-08-24 22:04:42 -0500907 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500908 if (priv->assoc_network->mode == IEEE_A) {
909 led |= priv->led_ofdm_on;
910 led &= priv->led_association_off;
911 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
912 } else if (priv->assoc_network->mode == IEEE_G) {
913 led |= priv->led_ofdm_on;
914 led |= priv->led_association_on;
915 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
916 } else {
917 led &= priv->led_ofdm_off;
918 led |= priv->led_association_on;
919 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
920 }
921
922 led = ipw_register_toggle(led);
923
924 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500925 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500926
927 spin_unlock_irqrestore(&priv->lock, flags);
928}
929
Adrian Bunka73e22b2006-01-21 01:39:42 +0100930static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500931{
932 unsigned long flags;
933 u32 led;
934
935 /* Only nic type 1 supports mode LEDs */
936 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
937 return;
938
939 spin_lock_irqsave(&priv->lock, flags);
940
James Ketrenosb095c382005-08-24 22:04:42 -0500941 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500942 led &= priv->led_ofdm_off;
943 led &= priv->led_association_off;
944
945 led = ipw_register_toggle(led);
946
947 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500948 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500949
950 spin_unlock_irqrestore(&priv->lock, flags);
951}
952
Adrian Bunka73e22b2006-01-21 01:39:42 +0100953static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500954{
955 ipw_led_link_on(priv);
956}
957
Adrian Bunka73e22b2006-01-21 01:39:42 +0100958static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500959{
960 ipw_led_activity_off(priv);
961 ipw_led_link_off(priv);
962}
963
Adrian Bunka73e22b2006-01-21 01:39:42 +0100964static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500965{
966 /* Set the Link Led on for all nic types */
967 ipw_led_link_on(priv);
968}
969
Adrian Bunka73e22b2006-01-21 01:39:42 +0100970static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500971{
972 ipw_led_activity_off(priv);
973 ipw_led_link_off(priv);
974
975 if (priv->status & STATUS_RF_KILL_MASK)
976 ipw_led_radio_off(priv);
977}
978
Adrian Bunka73e22b2006-01-21 01:39:42 +0100979static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500980{
981 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
982
983 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500984 priv->led_activity_on = IPW_ACTIVITY_LED;
985 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500986
James Ketrenosb095c382005-08-24 22:04:42 -0500987 priv->led_association_on = IPW_ASSOCIATED_LED;
988 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500989
990 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500991 priv->led_ofdm_on = IPW_OFDM_LED;
992 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500993
994 switch (priv->nic_type) {
995 case EEPROM_NIC_TYPE_1:
996 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -0500997 priv->led_activity_on = IPW_ASSOCIATED_LED;
998 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
999 priv->led_association_on = IPW_ACTIVITY_LED;
1000 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001001
1002 if (!(priv->config & CFG_NO_LED))
1003 ipw_led_band_on(priv);
1004
1005 /* And we don't blink link LEDs for this nic, so
1006 * just return here */
1007 return;
1008
1009 case EEPROM_NIC_TYPE_3:
1010 case EEPROM_NIC_TYPE_2:
1011 case EEPROM_NIC_TYPE_4:
1012 case EEPROM_NIC_TYPE_0:
1013 break;
1014
1015 default:
1016 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1017 priv->nic_type);
1018 priv->nic_type = EEPROM_NIC_TYPE_0;
1019 break;
1020 }
1021
1022 if (!(priv->config & CFG_NO_LED)) {
1023 if (priv->status & STATUS_ASSOCIATED)
1024 ipw_led_link_on(priv);
1025 else
1026 ipw_led_link_off(priv);
1027 }
1028}
1029
Adrian Bunka73e22b2006-01-21 01:39:42 +01001030static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001031{
James Ketrenosa613bff2005-08-24 21:43:11 -05001032 ipw_led_activity_off(priv);
1033 ipw_led_link_off(priv);
1034 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001035 cancel_delayed_work(&priv->led_link_on);
1036 cancel_delayed_work(&priv->led_link_off);
1037 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001038}
1039
James Ketrenos43f66a62005-03-25 12:31:53 -06001040/*
1041 * The following adds a new attribute to the sysfs representation
1042 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1043 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001044 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001045 * See the level definitions in ipw for details.
1046 */
1047static ssize_t show_debug_level(struct device_driver *d, char *buf)
1048{
1049 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1050}
James Ketrenosa613bff2005-08-24 21:43:11 -05001051
1052static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1053 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001054{
1055 char *p = (char *)buf;
1056 u32 val;
1057
1058 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1059 p++;
1060 if (p[0] == 'x' || p[0] == 'X')
1061 p++;
1062 val = simple_strtoul(p, &p, 16);
1063 } else
1064 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001065 if (p == buf)
1066 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001067 ": %s is not in hex or decimal form.\n", buf);
1068 else
1069 ipw_debug_level = val;
1070
1071 return strnlen(buf, count);
1072}
1073
Jeff Garzikbf794512005-07-31 13:07:26 -04001074static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001075 show_debug_level, store_debug_level);
1076
James Ketrenosb39860c2005-08-12 09:36:32 -05001077static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1078{
1079 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1080}
1081
1082static void ipw_capture_event_log(struct ipw_priv *priv,
1083 u32 log_len, struct ipw_event *log)
1084{
1085 u32 base;
1086
1087 if (log_len) {
1088 base = ipw_read32(priv, IPW_EVENT_LOG);
1089 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1090 (u8 *) log, sizeof(*log) * log_len);
1091 }
1092}
1093
1094static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1095{
1096 struct ipw_fw_error *error;
1097 u32 log_len = ipw_get_event_log_len(priv);
1098 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1099 u32 elem_len = ipw_read_reg32(priv, base);
1100
1101 error = kmalloc(sizeof(*error) +
1102 sizeof(*error->elem) * elem_len +
1103 sizeof(*error->log) * log_len, GFP_ATOMIC);
1104 if (!error) {
1105 IPW_ERROR("Memory allocation for firmware error log "
1106 "failed.\n");
1107 return NULL;
1108 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001109 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001110 error->status = priv->status;
1111 error->config = priv->config;
1112 error->elem_len = elem_len;
1113 error->log_len = log_len;
1114 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001115 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001116
1117 ipw_capture_event_log(priv, log_len, error->log);
1118
1119 if (elem_len)
1120 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1121 sizeof(*error->elem) * elem_len);
1122
1123 return error;
1124}
1125
1126static void ipw_free_error_log(struct ipw_fw_error *error)
1127{
1128 if (error)
1129 kfree(error);
1130}
1131
1132static ssize_t show_event_log(struct device *d,
1133 struct device_attribute *attr, char *buf)
1134{
1135 struct ipw_priv *priv = dev_get_drvdata(d);
1136 u32 log_len = ipw_get_event_log_len(priv);
1137 struct ipw_event log[log_len];
1138 u32 len = 0, i;
1139
1140 ipw_capture_event_log(priv, log_len, log);
1141
1142 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1143 for (i = 0; i < log_len; i++)
1144 len += snprintf(buf + len, PAGE_SIZE - len,
1145 "\n%08X%08X%08X",
1146 log[i].time, log[i].event, log[i].data);
1147 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1148 return len;
1149}
1150
1151static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1152
1153static ssize_t show_error(struct device *d,
1154 struct device_attribute *attr, char *buf)
1155{
1156 struct ipw_priv *priv = dev_get_drvdata(d);
1157 u32 len = 0, i;
1158 if (!priv->error)
1159 return 0;
1160 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001161 "%08lX%08X%08X%08X",
1162 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001163 priv->error->status,
1164 priv->error->config, priv->error->elem_len);
1165 for (i = 0; i < priv->error->elem_len; i++)
1166 len += snprintf(buf + len, PAGE_SIZE - len,
1167 "\n%08X%08X%08X%08X%08X%08X%08X",
1168 priv->error->elem[i].time,
1169 priv->error->elem[i].desc,
1170 priv->error->elem[i].blink1,
1171 priv->error->elem[i].blink2,
1172 priv->error->elem[i].link1,
1173 priv->error->elem[i].link2,
1174 priv->error->elem[i].data);
1175
1176 len += snprintf(buf + len, PAGE_SIZE - len,
1177 "\n%08X", priv->error->log_len);
1178 for (i = 0; i < priv->error->log_len; i++)
1179 len += snprintf(buf + len, PAGE_SIZE - len,
1180 "\n%08X%08X%08X",
1181 priv->error->log[i].time,
1182 priv->error->log[i].event,
1183 priv->error->log[i].data);
1184 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1185 return len;
1186}
1187
1188static ssize_t clear_error(struct device *d,
1189 struct device_attribute *attr,
1190 const char *buf, size_t count)
1191{
1192 struct ipw_priv *priv = dev_get_drvdata(d);
1193 if (priv->error) {
1194 ipw_free_error_log(priv->error);
1195 priv->error = NULL;
1196 }
1197 return count;
1198}
1199
1200static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1201
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001202static ssize_t show_cmd_log(struct device *d,
1203 struct device_attribute *attr, char *buf)
1204{
1205 struct ipw_priv *priv = dev_get_drvdata(d);
1206 u32 len = 0, i;
1207 if (!priv->cmdlog)
1208 return 0;
1209 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1210 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1211 i = (i + 1) % priv->cmdlog_len) {
1212 len +=
1213 snprintf(buf + len, PAGE_SIZE - len,
1214 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1215 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1216 priv->cmdlog[i].cmd.len);
1217 len +=
1218 snprintk_buf(buf + len, PAGE_SIZE - len,
1219 (u8 *) priv->cmdlog[i].cmd.param,
1220 priv->cmdlog[i].cmd.len);
1221 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1222 }
1223 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1224 return len;
1225}
1226
1227static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1228
James Ketrenosa613bff2005-08-24 21:43:11 -05001229static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1230 char *buf)
1231{
1232 struct ipw_priv *priv = dev_get_drvdata(d);
1233 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1234}
1235
1236static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1237 const char *buf, size_t count)
1238{
1239 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001240#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001241 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001242#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001243 char buffer[] = "00000000";
1244 unsigned long len =
1245 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1246 unsigned long val;
1247 char *p = buffer;
1248
1249 IPW_DEBUG_INFO("enter\n");
1250
1251 strncpy(buffer, buf, len);
1252 buffer[len] = 0;
1253
1254 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1255 p++;
1256 if (p[0] == 'x' || p[0] == 'X')
1257 p++;
1258 val = simple_strtoul(p, &p, 16);
1259 } else
1260 val = simple_strtoul(p, &p, 10);
1261 if (p == buffer) {
1262 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1263 } else {
1264 priv->ieee->scan_age = val;
1265 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1266 }
1267
1268 IPW_DEBUG_INFO("exit\n");
1269 return len;
1270}
1271
1272static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1273
1274static ssize_t show_led(struct device *d, struct device_attribute *attr,
1275 char *buf)
1276{
1277 struct ipw_priv *priv = dev_get_drvdata(d);
1278 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1279}
1280
1281static ssize_t store_led(struct device *d, struct device_attribute *attr,
1282 const char *buf, size_t count)
1283{
1284 struct ipw_priv *priv = dev_get_drvdata(d);
1285
1286 IPW_DEBUG_INFO("enter\n");
1287
1288 if (count == 0)
1289 return 0;
1290
1291 if (*buf == 0) {
1292 IPW_DEBUG_LED("Disabling LED control.\n");
1293 priv->config |= CFG_NO_LED;
1294 ipw_led_shutdown(priv);
1295 } else {
1296 IPW_DEBUG_LED("Enabling LED control.\n");
1297 priv->config &= ~CFG_NO_LED;
1298 ipw_led_init(priv);
1299 }
1300
1301 IPW_DEBUG_INFO("exit\n");
1302 return count;
1303}
1304
1305static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1306
Andrew Mortonad3fee52005-06-20 14:30:36 -07001307static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001308 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001309{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001310 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001311 return sprintf(buf, "0x%08x\n", (int)p->status);
1312}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001313
James Ketrenos43f66a62005-03-25 12:31:53 -06001314static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1315
Andrew Mortonad3fee52005-06-20 14:30:36 -07001316static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1317 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001318{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001319 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001320 return sprintf(buf, "0x%08x\n", (int)p->config);
1321}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001322
James Ketrenos43f66a62005-03-25 12:31:53 -06001323static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1324
Andrew Mortonad3fee52005-06-20 14:30:36 -07001325static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001326 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001327{
James Ketrenosa613bff2005-08-24 21:43:11 -05001328 struct ipw_priv *priv = d->driver_data;
1329 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001330}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001331
James Ketrenos43f66a62005-03-25 12:31:53 -06001332static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1333
Andrew Mortonad3fee52005-06-20 14:30:36 -07001334static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001335 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001336{
1337 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001338 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001339
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001340 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001341 return 0;
1342
1343 return sprintf(buf, "0x%08x\n", tmp);
1344}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001345
1346static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001347
Andrew Mortonad3fee52005-06-20 14:30:36 -07001348static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1349 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001350{
1351 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001352 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001353
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001354 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001355 return 0;
1356
1357 return sprintf(buf, "0x%08x\n", tmp);
1358}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001359
1360static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001361
1362/*
1363 * Add a device attribute to view/control the delay between eeprom
1364 * operations.
1365 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001366static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001367 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001368{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001369 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001370 return sprintf(buf, "%i\n", n);
1371}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001372static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001373 struct device_attribute *attr,
1374 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001375{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001376 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001377 sscanf(buf, "%i", &p->eeprom_delay);
1378 return strnlen(buf, count);
1379}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001380
1381static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1382 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001383
Andrew Mortonad3fee52005-06-20 14:30:36 -07001384static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001385 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001386{
1387 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001388 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001389
James Ketrenosb095c382005-08-24 22:04:42 -05001390 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001391 return sprintf(buf, "0x%08x\n", reg);
1392}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001393static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001394 struct device_attribute *attr,
1395 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001396{
1397 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001398 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001399
1400 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001401 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001402 return strnlen(buf, count);
1403}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001404
1405static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1406 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001407
Andrew Mortonad3fee52005-06-20 14:30:36 -07001408static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001409 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001410{
1411 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001412 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001413
1414 reg = ipw_read_reg32(p, 0x301100);
1415 return sprintf(buf, "0x%08x\n", reg);
1416}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001417static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001418 struct device_attribute *attr,
1419 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001420{
1421 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001422 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001423
1424 sscanf(buf, "%x", &reg);
1425 ipw_write_reg32(p, 0x301100, reg);
1426 return strnlen(buf, count);
1427}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001428
1429static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1430 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001431
Andrew Mortonad3fee52005-06-20 14:30:36 -07001432static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001433 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001434{
1435 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001436 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001437
Jeff Garzikbf794512005-07-31 13:07:26 -04001438 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001439 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001440 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001441 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001442
James Ketrenos43f66a62005-03-25 12:31:53 -06001443 return sprintf(buf, "0x%08x\n", reg);
1444}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001445static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001446 struct device_attribute *attr,
1447 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001448{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001449 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001450
1451 sscanf(buf, "%x", &priv->indirect_dword);
1452 priv->status |= STATUS_INDIRECT_DWORD;
1453 return strnlen(buf, count);
1454}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001455
1456static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1457 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001458
Andrew Mortonad3fee52005-06-20 14:30:36 -07001459static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001460 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001461{
1462 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001463 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001464
Jeff Garzikbf794512005-07-31 13:07:26 -04001465 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001466 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001467 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001468 reg = 0;
1469
1470 return sprintf(buf, "0x%02x\n", reg);
1471}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001472static ssize_t store_indirect_byte(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{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001476 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001477
1478 sscanf(buf, "%x", &priv->indirect_byte);
1479 priv->status |= STATUS_INDIRECT_BYTE;
1480 return strnlen(buf, count);
1481}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001482
1483static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001484 show_indirect_byte, store_indirect_byte);
1485
Andrew Mortonad3fee52005-06-20 14:30:36 -07001486static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001487 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001488{
1489 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001490 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001491
Jeff Garzikbf794512005-07-31 13:07:26 -04001492 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001493 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001494 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001495 reg = 0;
1496
1497 return sprintf(buf, "0x%08x\n", reg);
1498}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001499static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001500 struct device_attribute *attr,
1501 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001502{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001503 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001504
1505 sscanf(buf, "%x", &priv->direct_dword);
1506 priv->status |= STATUS_DIRECT_DWORD;
1507 return strnlen(buf, count);
1508}
James Ketrenos43f66a62005-03-25 12:31:53 -06001509
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001510static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1511 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001512
Arjan van de Ven858119e2006-01-14 13:20:43 -08001513static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001514{
1515 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1516 priv->status |= STATUS_RF_KILL_HW;
1517 else
1518 priv->status &= ~STATUS_RF_KILL_HW;
1519
1520 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1521}
1522
Andrew Mortonad3fee52005-06-20 14:30:36 -07001523static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001524 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001525{
1526 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001527 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001528 2 - HW based RF kill active
1529 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001530 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001531 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001532 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001533 return sprintf(buf, "%i\n", val);
1534}
1535
1536static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1537{
Jeff Garzikbf794512005-07-31 13:07:26 -04001538 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001539 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001540 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001541
1542 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1543 disable_radio ? "OFF" : "ON");
1544
1545 if (disable_radio) {
1546 priv->status |= STATUS_RF_KILL_SW;
1547
James Ketrenosa613bff2005-08-24 21:43:11 -05001548 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001549 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001550 queue_work(priv->workqueue, &priv->down);
1551 } else {
1552 priv->status &= ~STATUS_RF_KILL_SW;
1553 if (rf_kill_active(priv)) {
1554 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1555 "disabled by HW switch\n");
1556 /* Make sure the RF_KILL check timer is running */
1557 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001558 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001559 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001560 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001561 queue_work(priv->workqueue, &priv->up);
1562 }
1563
1564 return 1;
1565}
1566
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1568 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001569{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001570 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001571
James Ketrenos43f66a62005-03-25 12:31:53 -06001572 ipw_radio_kill_sw(priv, buf[0] == '1');
1573
1574 return count;
1575}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001576
1577static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001578
James Ketrenosb095c382005-08-24 22:04:42 -05001579static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1580 char *buf)
1581{
1582 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1583 int pos = 0, len = 0;
1584 if (priv->config & CFG_SPEED_SCAN) {
1585 while (priv->speed_scan[pos] != 0)
1586 len += sprintf(&buf[len], "%d ",
1587 priv->speed_scan[pos++]);
1588 return len + sprintf(&buf[len], "\n");
1589 }
1590
1591 return sprintf(buf, "0\n");
1592}
1593
1594static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1595 const char *buf, size_t count)
1596{
1597 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1598 int channel, pos = 0;
1599 const char *p = buf;
1600
1601 /* list of space separated channels to scan, optionally ending with 0 */
1602 while ((channel = simple_strtol(p, NULL, 0))) {
1603 if (pos == MAX_SPEED_SCAN - 1) {
1604 priv->speed_scan[pos] = 0;
1605 break;
1606 }
1607
Liu Hong1fe0adb2005-08-19 09:33:10 -05001608 if (ipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001609 priv->speed_scan[pos++] = channel;
1610 else
1611 IPW_WARNING("Skipping invalid channel request: %d\n",
1612 channel);
1613 p = strchr(p, ' ');
1614 if (!p)
1615 break;
1616 while (*p == ' ' || *p == '\t')
1617 p++;
1618 }
1619
1620 if (pos == 0)
1621 priv->config &= ~CFG_SPEED_SCAN;
1622 else {
1623 priv->speed_scan_pos = 0;
1624 priv->config |= CFG_SPEED_SCAN;
1625 }
1626
1627 return count;
1628}
1629
1630static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1631 store_speed_scan);
1632
1633static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1634 char *buf)
1635{
1636 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1637 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1638}
1639
1640static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1641 const char *buf, size_t count)
1642{
1643 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1644 if (buf[0] == '1')
1645 priv->config |= CFG_NET_STATS;
1646 else
1647 priv->config &= ~CFG_NET_STATS;
1648
1649 return count;
1650}
1651
James Ketrenosafbf30a2005-08-25 00:05:33 -05001652static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1653 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001654
James Ketrenosea2b26e2005-08-24 21:25:16 -05001655static void notify_wx_assoc_event(struct ipw_priv *priv)
1656{
1657 union iwreq_data wrqu;
1658 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1659 if (priv->status & STATUS_ASSOCIATED)
1660 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1661 else
1662 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1663 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1664}
1665
James Ketrenos43f66a62005-03-25 12:31:53 -06001666static void ipw_irq_tasklet(struct ipw_priv *priv)
1667{
1668 u32 inta, inta_mask, handled = 0;
1669 unsigned long flags;
1670 int rc = 0;
1671
1672 spin_lock_irqsave(&priv->lock, flags);
1673
James Ketrenosb095c382005-08-24 22:04:42 -05001674 inta = ipw_read32(priv, IPW_INTA_RW);
1675 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1676 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001677
1678 /* Add any cached INTA values that need to be handled */
1679 inta |= priv->isr_inta;
1680
1681 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001682 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001683 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001684 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001685 }
1686
James Ketrenosb095c382005-08-24 22:04:42 -05001687 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001688 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001689 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001690 priv->status &= ~STATUS_HCMD_ACTIVE;
1691 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001692 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001693 }
1694
James Ketrenosb095c382005-08-24 22:04:42 -05001695 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001696 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001697 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001698 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001699 }
1700
James Ketrenosb095c382005-08-24 22:04:42 -05001701 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001702 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001703 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001704 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001705 }
1706
James Ketrenosb095c382005-08-24 22:04:42 -05001707 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001708 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001709 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001710 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001711 }
1712
James Ketrenosb095c382005-08-24 22:04:42 -05001713 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001714 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001715 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001716 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001717 }
1718
James Ketrenosb095c382005-08-24 22:04:42 -05001719 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001720 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001721 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001722 }
1723
James Ketrenosb095c382005-08-24 22:04:42 -05001724 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001725 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001726 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001727 }
1728
James Ketrenosb095c382005-08-24 22:04:42 -05001729 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001730 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001731 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001732 }
1733
James Ketrenosb095c382005-08-24 22:04:42 -05001734 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001735 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001736 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001737 }
1738
James Ketrenosb095c382005-08-24 22:04:42 -05001739 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001741 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 }
1743
James Ketrenosb095c382005-08-24 22:04:42 -05001744 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001745 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1746 priv->status |= STATUS_RF_KILL_HW;
1747 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001748 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001749 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001750 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001751 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001752 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001753 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001754
James Ketrenosb095c382005-08-24 22:04:42 -05001755 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001756 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001757 if (priv->error) {
1758 IPW_ERROR("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001759#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001760 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1761 struct ipw_fw_error *error =
1762 ipw_alloc_error_log(priv);
1763 ipw_dump_error_log(priv, error);
1764 if (error)
1765 ipw_free_error_log(error);
1766 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001767#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001768 } else {
1769 priv->error = ipw_alloc_error_log(priv);
1770 if (priv->error)
1771 IPW_ERROR("Sysfs 'error' log captured.\n");
1772 else
1773 IPW_ERROR("Error allocating sysfs 'error' "
1774 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001775#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001776 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1777 ipw_dump_error_log(priv, priv->error);
1778#endif
1779 }
1780
James Ketrenosb095c382005-08-24 22:04:42 -05001781 /* XXX: If hardware encryption is for WPA/WPA2,
1782 * we have to notify the supplicant. */
1783 if (priv->ieee->sec.encrypt) {
1784 priv->status &= ~STATUS_ASSOCIATED;
1785 notify_wx_assoc_event(priv);
1786 }
1787
1788 /* Keep the restart process from trying to send host
1789 * commands by clearing the INIT status bit */
1790 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001791
1792 /* Cancel currently queued command. */
1793 priv->status &= ~STATUS_HCMD_ACTIVE;
1794 wake_up_interruptible(&priv->wait_command_queue);
1795
James Ketrenos43f66a62005-03-25 12:31:53 -06001796 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001797 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001798 }
1799
James Ketrenosb095c382005-08-24 22:04:42 -05001800 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001801 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001802 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001803 }
1804
1805 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001806 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001807 }
1808
1809 /* enable all interrupts */
1810 ipw_enable_interrupts(priv);
1811
1812 spin_unlock_irqrestore(&priv->lock, flags);
1813}
Jeff Garzikbf794512005-07-31 13:07:26 -04001814
James Ketrenos43f66a62005-03-25 12:31:53 -06001815#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1816static char *get_cmd_string(u8 cmd)
1817{
1818 switch (cmd) {
1819 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001820 IPW_CMD(POWER_DOWN);
1821 IPW_CMD(SYSTEM_CONFIG);
1822 IPW_CMD(MULTICAST_ADDRESS);
1823 IPW_CMD(SSID);
1824 IPW_CMD(ADAPTER_ADDRESS);
1825 IPW_CMD(PORT_TYPE);
1826 IPW_CMD(RTS_THRESHOLD);
1827 IPW_CMD(FRAG_THRESHOLD);
1828 IPW_CMD(POWER_MODE);
1829 IPW_CMD(WEP_KEY);
1830 IPW_CMD(TGI_TX_KEY);
1831 IPW_CMD(SCAN_REQUEST);
1832 IPW_CMD(SCAN_REQUEST_EXT);
1833 IPW_CMD(ASSOCIATE);
1834 IPW_CMD(SUPPORTED_RATES);
1835 IPW_CMD(SCAN_ABORT);
1836 IPW_CMD(TX_FLUSH);
1837 IPW_CMD(QOS_PARAMETERS);
1838 IPW_CMD(DINO_CONFIG);
1839 IPW_CMD(RSN_CAPABILITIES);
1840 IPW_CMD(RX_KEY);
1841 IPW_CMD(CARD_DISABLE);
1842 IPW_CMD(SEED_NUMBER);
1843 IPW_CMD(TX_POWER);
1844 IPW_CMD(COUNTRY_INFO);
1845 IPW_CMD(AIRONET_INFO);
1846 IPW_CMD(AP_TX_POWER);
1847 IPW_CMD(CCKM_INFO);
1848 IPW_CMD(CCX_VER_INFO);
1849 IPW_CMD(SET_CALIBRATION);
1850 IPW_CMD(SENSITIVITY_CALIB);
1851 IPW_CMD(RETRY_LIMIT);
1852 IPW_CMD(IPW_PRE_POWER_DOWN);
1853 IPW_CMD(VAP_BEACON_TEMPLATE);
1854 IPW_CMD(VAP_DTIM_PERIOD);
1855 IPW_CMD(EXT_SUPPORTED_RATES);
1856 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1857 IPW_CMD(VAP_QUIET_INTERVALS);
1858 IPW_CMD(VAP_CHANNEL_SWITCH);
1859 IPW_CMD(VAP_MANDATORY_CHANNELS);
1860 IPW_CMD(VAP_CELL_PWR_LIMIT);
1861 IPW_CMD(VAP_CF_PARAM_SET);
1862 IPW_CMD(VAP_SET_BEACONING_STATE);
1863 IPW_CMD(MEASUREMENT);
1864 IPW_CMD(POWER_CAPABILITY);
1865 IPW_CMD(SUPPORTED_CHANNELS);
1866 IPW_CMD(TPC_REPORT);
1867 IPW_CMD(WME_INFO);
1868 IPW_CMD(PRODUCTION_COMMAND);
1869 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001870 return "UNKNOWN";
1871 }
1872}
James Ketrenos43f66a62005-03-25 12:31:53 -06001873
1874#define HOST_COMPLETE_TIMEOUT HZ
1875static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1876{
1877 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001878 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001879
James Ketrenosa613bff2005-08-24 21:43:11 -05001880 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001881 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001882 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1883 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001884 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001885 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001886 }
1887
1888 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001889
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001890 if (priv->cmdlog) {
1891 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1892 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1893 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1894 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1895 cmd->len);
1896 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1897 }
1898
James Ketrenosb095c382005-08-24 22:04:42 -05001899 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1900 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1901 priv->status);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001902 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001903
1904 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001905 if (rc) {
1906 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001907 IPW_ERROR("Failed to send %s: Reason %d\n",
1908 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001909 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001910 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001911 }
1912 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001913
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001914 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1915 !(priv->
1916 status & STATUS_HCMD_ACTIVE),
1917 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001918 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001919 spin_lock_irqsave(&priv->lock, flags);
1920 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001921 IPW_ERROR("Failed to send %s: Command timed out.\n",
1922 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001923 priv->status &= ~STATUS_HCMD_ACTIVE;
1924 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001925 rc = -EIO;
1926 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001927 }
1928 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001929 } else
1930 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001931
James Ketrenosb095c382005-08-24 22:04:42 -05001932 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001933 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1934 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001935 rc = -EIO;
1936 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06001937 }
1938
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001939 exit:
1940 if (priv->cmdlog) {
1941 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1942 priv->cmdlog_pos %= priv->cmdlog_len;
1943 }
1944 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06001945}
1946
1947static int ipw_send_host_complete(struct ipw_priv *priv)
1948{
1949 struct host_cmd cmd = {
1950 .cmd = IPW_CMD_HOST_COMPLETE,
1951 .len = 0
1952 };
1953
1954 if (!priv) {
1955 IPW_ERROR("Invalid args\n");
1956 return -1;
1957 }
1958
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001959 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001960}
1961
Jeff Garzikbf794512005-07-31 13:07:26 -04001962static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001963 struct ipw_sys_config *config)
1964{
1965 struct host_cmd cmd = {
1966 .cmd = IPW_CMD_SYSTEM_CONFIG,
1967 .len = sizeof(*config)
1968 };
1969
1970 if (!priv || !config) {
1971 IPW_ERROR("Invalid args\n");
1972 return -1;
1973 }
1974
James Ketrenosafbf30a2005-08-25 00:05:33 -05001975 memcpy(cmd.param, config, sizeof(*config));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001976 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001977}
1978
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001979static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001980{
1981 struct host_cmd cmd = {
1982 .cmd = IPW_CMD_SSID,
1983 .len = min(len, IW_ESSID_MAX_SIZE)
1984 };
1985
1986 if (!priv || !ssid) {
1987 IPW_ERROR("Invalid args\n");
1988 return -1;
1989 }
1990
James Ketrenosafbf30a2005-08-25 00:05:33 -05001991 memcpy(cmd.param, ssid, cmd.len);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001992 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001993}
1994
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001995static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001996{
1997 struct host_cmd cmd = {
1998 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1999 .len = ETH_ALEN
2000 };
2001
2002 if (!priv || !mac) {
2003 IPW_ERROR("Invalid args\n");
2004 return -1;
2005 }
2006
2007 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2008 priv->net_dev->name, MAC_ARG(mac));
2009
James Ketrenosafbf30a2005-08-25 00:05:33 -05002010 memcpy(cmd.param, mac, ETH_ALEN);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002011 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002012}
2013
James Ketrenosa613bff2005-08-24 21:43:11 -05002014/*
2015 * NOTE: This must be executed from our workqueue as it results in udelay
2016 * being called which may corrupt the keyboard if executed on default
2017 * workqueue
2018 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002019static void ipw_adapter_restart(void *adapter)
2020{
2021 struct ipw_priv *priv = adapter;
2022
2023 if (priv->status & STATUS_RF_KILL_MASK)
2024 return;
2025
2026 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002027
2028 if (priv->assoc_network &&
2029 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2030 ipw_remove_current_network(priv);
2031
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 if (ipw_up(priv)) {
2033 IPW_ERROR("Failed to up device\n");
2034 return;
2035 }
2036}
2037
James Ketrenosc848d0a2005-08-24 21:56:24 -05002038static void ipw_bg_adapter_restart(void *data)
2039{
2040 struct ipw_priv *priv = data;
2041 down(&priv->sem);
2042 ipw_adapter_restart(data);
2043 up(&priv->sem);
2044}
2045
James Ketrenos43f66a62005-03-25 12:31:53 -06002046#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2047
2048static void ipw_scan_check(void *data)
2049{
2050 struct ipw_priv *priv = data;
2051 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2052 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04002053 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002054 IPW_SCAN_CHECK_WATCHDOG / 100);
James Ketrenosa613bff2005-08-24 21:43:11 -05002055 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002056 }
2057}
2058
James Ketrenosc848d0a2005-08-24 21:56:24 -05002059static void ipw_bg_scan_check(void *data)
2060{
2061 struct ipw_priv *priv = data;
2062 down(&priv->sem);
2063 ipw_scan_check(data);
2064 up(&priv->sem);
2065}
2066
James Ketrenos43f66a62005-03-25 12:31:53 -06002067static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2068 struct ipw_scan_request_ext *request)
2069{
2070 struct host_cmd cmd = {
2071 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
2072 .len = sizeof(*request)
2073 };
2074
James Ketrenosafbf30a2005-08-25 00:05:33 -05002075 memcpy(cmd.param, request, sizeof(*request));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002076 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002077}
2078
2079static int ipw_send_scan_abort(struct ipw_priv *priv)
2080{
2081 struct host_cmd cmd = {
2082 .cmd = IPW_CMD_SCAN_ABORT,
2083 .len = 0
2084 };
2085
2086 if (!priv) {
2087 IPW_ERROR("Invalid args\n");
2088 return -1;
2089 }
2090
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002091 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002092}
2093
2094static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2095{
2096 struct host_cmd cmd = {
2097 .cmd = IPW_CMD_SENSITIVITY_CALIB,
2098 .len = sizeof(struct ipw_sensitivity_calib)
2099 };
2100 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002101 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002102 calib->beacon_rssi_raw = sens;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002103 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002104}
2105
2106static int ipw_send_associate(struct ipw_priv *priv,
2107 struct ipw_associate *associate)
2108{
2109 struct host_cmd cmd = {
2110 .cmd = IPW_CMD_ASSOCIATE,
2111 .len = sizeof(*associate)
2112 };
2113
James Ketrenosa613bff2005-08-24 21:43:11 -05002114 struct ipw_associate tmp_associate;
2115 memcpy(&tmp_associate, associate, sizeof(*associate));
2116 tmp_associate.policy_support =
2117 cpu_to_le16(tmp_associate.policy_support);
2118 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2119 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2120 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2121 tmp_associate.listen_interval =
2122 cpu_to_le16(tmp_associate.listen_interval);
2123 tmp_associate.beacon_interval =
2124 cpu_to_le16(tmp_associate.beacon_interval);
2125 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2126
James Ketrenos43f66a62005-03-25 12:31:53 -06002127 if (!priv || !associate) {
2128 IPW_ERROR("Invalid args\n");
2129 return -1;
2130 }
2131
James Ketrenosafbf30a2005-08-25 00:05:33 -05002132 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002133 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002134}
2135
2136static int ipw_send_supported_rates(struct ipw_priv *priv,
2137 struct ipw_supported_rates *rates)
2138{
2139 struct host_cmd cmd = {
2140 .cmd = IPW_CMD_SUPPORTED_RATES,
2141 .len = sizeof(*rates)
2142 };
2143
2144 if (!priv || !rates) {
2145 IPW_ERROR("Invalid args\n");
2146 return -1;
2147 }
2148
James Ketrenosafbf30a2005-08-25 00:05:33 -05002149 memcpy(cmd.param, rates, sizeof(*rates));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002150 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002151}
2152
2153static int ipw_set_random_seed(struct ipw_priv *priv)
2154{
2155 struct host_cmd cmd = {
2156 .cmd = IPW_CMD_SEED_NUMBER,
2157 .len = sizeof(u32)
2158 };
2159
2160 if (!priv) {
2161 IPW_ERROR("Invalid args\n");
2162 return -1;
2163 }
2164
2165 get_random_bytes(&cmd.param, sizeof(u32));
2166
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002167 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002168}
2169
James Ketrenos43f66a62005-03-25 12:31:53 -06002170static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2171{
2172 struct host_cmd cmd = {
2173 .cmd = IPW_CMD_CARD_DISABLE,
2174 .len = sizeof(u32)
2175 };
2176
2177 if (!priv) {
2178 IPW_ERROR("Invalid args\n");
2179 return -1;
2180 }
2181
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002182 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06002183
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002184 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002185}
James Ketrenos43f66a62005-03-25 12:31:53 -06002186
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002187static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002188{
2189 struct host_cmd cmd = {
2190 .cmd = IPW_CMD_TX_POWER,
2191 .len = sizeof(*power)
2192 };
2193
2194 if (!priv || !power) {
2195 IPW_ERROR("Invalid args\n");
2196 return -1;
2197 }
2198
James Ketrenosafbf30a2005-08-25 00:05:33 -05002199 memcpy(cmd.param, power, sizeof(*power));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002200 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002201}
James Ketrenos43f66a62005-03-25 12:31:53 -06002202
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002203static int ipw_set_tx_power(struct ipw_priv *priv)
2204{
Liu Hong1fe0adb2005-08-19 09:33:10 -05002205 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002206 struct ipw_tx_power tx_power;
2207 s8 max_power;
2208 int i;
2209
2210 memset(&tx_power, 0, sizeof(tx_power));
2211
2212 /* configure device for 'G' band */
2213 tx_power.ieee_mode = IPW_G_MODE;
2214 tx_power.num_channels = geo->bg_channels;
2215 for (i = 0; i < geo->bg_channels; i++) {
2216 max_power = geo->bg[i].max_power;
2217 tx_power.channels_tx_power[i].channel_number =
2218 geo->bg[i].channel;
2219 tx_power.channels_tx_power[i].tx_power = max_power ?
2220 min(max_power, priv->tx_power) : priv->tx_power;
2221 }
2222 if (ipw_send_tx_power(priv, &tx_power))
2223 return -EIO;
2224
2225 /* configure device to also handle 'B' band */
2226 tx_power.ieee_mode = IPW_B_MODE;
2227 if (ipw_send_tx_power(priv, &tx_power))
2228 return -EIO;
2229
2230 /* configure device to also handle 'A' band */
2231 if (priv->ieee->abg_true) {
2232 tx_power.ieee_mode = IPW_A_MODE;
2233 tx_power.num_channels = geo->a_channels;
2234 for (i = 0; i < tx_power.num_channels; i++) {
2235 max_power = geo->a[i].max_power;
2236 tx_power.channels_tx_power[i].channel_number =
2237 geo->a[i].channel;
2238 tx_power.channels_tx_power[i].tx_power = max_power ?
2239 min(max_power, priv->tx_power) : priv->tx_power;
2240 }
2241 if (ipw_send_tx_power(priv, &tx_power))
2242 return -EIO;
2243 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002244 return 0;
2245}
2246
2247static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2248{
2249 struct ipw_rts_threshold rts_threshold = {
2250 .rts_threshold = rts,
2251 };
2252 struct host_cmd cmd = {
2253 .cmd = IPW_CMD_RTS_THRESHOLD,
2254 .len = sizeof(rts_threshold)
2255 };
2256
2257 if (!priv) {
2258 IPW_ERROR("Invalid args\n");
2259 return -1;
2260 }
2261
James Ketrenosafbf30a2005-08-25 00:05:33 -05002262 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002263 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002264}
2265
2266static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2267{
2268 struct ipw_frag_threshold frag_threshold = {
2269 .frag_threshold = frag,
2270 };
2271 struct host_cmd cmd = {
2272 .cmd = IPW_CMD_FRAG_THRESHOLD,
2273 .len = sizeof(frag_threshold)
2274 };
2275
2276 if (!priv) {
2277 IPW_ERROR("Invalid args\n");
2278 return -1;
2279 }
2280
James Ketrenosafbf30a2005-08-25 00:05:33 -05002281 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002282 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002283}
2284
2285static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2286{
2287 struct host_cmd cmd = {
2288 .cmd = IPW_CMD_POWER_MODE,
2289 .len = sizeof(u32)
2290 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002291 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002292
2293 if (!priv) {
2294 IPW_ERROR("Invalid args\n");
2295 return -1;
2296 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002297
James Ketrenos43f66a62005-03-25 12:31:53 -06002298 /* If on battery, set to 3, if AC set to CAM, else user
2299 * level */
2300 switch (mode) {
2301 case IPW_POWER_BATTERY:
2302 *param = IPW_POWER_INDEX_3;
2303 break;
2304 case IPW_POWER_AC:
2305 *param = IPW_POWER_MODE_CAM;
2306 break;
2307 default:
2308 *param = mode;
2309 break;
2310 }
2311
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002312 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002313}
2314
James Ketrenosafbf30a2005-08-25 00:05:33 -05002315static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2316{
2317 struct ipw_retry_limit retry_limit = {
2318 .short_retry_limit = slimit,
2319 .long_retry_limit = llimit
2320 };
2321 struct host_cmd cmd = {
2322 .cmd = IPW_CMD_RETRY_LIMIT,
2323 .len = sizeof(retry_limit)
2324 };
2325
2326 if (!priv) {
2327 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002328 return -1;
2329 }
2330
James Ketrenosafbf30a2005-08-25 00:05:33 -05002331 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002332 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002333}
2334
2335/*
2336 * The IPW device contains a Microwire compatible EEPROM that stores
2337 * various data like the MAC address. Usually the firmware has exclusive
2338 * access to the eeprom, but during device initialization (before the
2339 * device driver has sent the HostComplete command to the firmware) the
2340 * device driver has read access to the EEPROM by way of indirect addressing
2341 * through a couple of memory mapped registers.
2342 *
2343 * The following is a simplified implementation for pulling data out of the
2344 * the eeprom, along with some helper functions to find information in
2345 * the per device private data's copy of the eeprom.
2346 *
2347 * NOTE: To better understand how these functions work (i.e what is a chip
2348 * select and why do have to keep driving the eeprom clock?), read
2349 * just about any data sheet for a Microwire compatible EEPROM.
2350 */
2351
2352/* write a 32 bit value into the indirect accessor register */
2353static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2354{
2355 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002356
James Ketrenos43f66a62005-03-25 12:31:53 -06002357 /* the eeprom requires some time to complete the operation */
2358 udelay(p->eeprom_delay);
2359
2360 return;
2361}
2362
2363/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002364static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002365{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002366 eeprom_write_reg(priv, 0);
2367 eeprom_write_reg(priv, EEPROM_BIT_CS);
2368 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2369 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002370}
2371
2372/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002373static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002374{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002375 eeprom_write_reg(priv, EEPROM_BIT_CS);
2376 eeprom_write_reg(priv, 0);
2377 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002378}
2379
2380/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002381static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002382{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002383 int d = (bit ? EEPROM_BIT_DI : 0);
2384 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2385 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002386}
2387
2388/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002389static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002390{
2391 int i;
2392
2393 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002394 eeprom_write_bit(priv, 1);
2395 eeprom_write_bit(priv, op & 2);
2396 eeprom_write_bit(priv, op & 1);
2397 for (i = 7; i >= 0; i--) {
2398 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002399 }
2400}
2401
2402/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002403static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002404{
2405 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002406 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002407
James Ketrenos43f66a62005-03-25 12:31:53 -06002408 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002409 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002410
2411 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002412 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002413
2414 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002415 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002416 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002417 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2418 eeprom_write_reg(priv, EEPROM_BIT_CS);
2419 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2420 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002421 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002422
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002424 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002425 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002426
James Ketrenos43f66a62005-03-25 12:31:53 -06002427 return r;
2428}
2429
2430/* helper function for pulling the mac address out of the private */
2431/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002432static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002433{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002434 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002435}
2436
2437/*
2438 * Either the device driver (i.e. the host) or the firmware can
2439 * load eeprom data into the designated region in SRAM. If neither
2440 * happens then the FW will shutdown with a fatal error.
2441 *
2442 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2443 * bit needs region of shared SRAM needs to be non-zero.
2444 */
2445static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2446{
2447 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002448 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002449
James Ketrenos43f66a62005-03-25 12:31:53 -06002450 IPW_DEBUG_TRACE(">>\n");
2451
2452 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002453 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002454 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002455
Jeff Garzikbf794512005-07-31 13:07:26 -04002456 /*
2457 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 copy. Otherwise let the firmware know to perform the operation
2459 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002460 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2462 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2463
2464 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002465 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002466 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002467
2468 /* Do not load eeprom data on fatal error or suspend */
2469 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2470 } else {
2471 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2472
2473 /* Load eeprom data on fatal error or suspend */
2474 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2475 }
2476
2477 IPW_DEBUG_TRACE("<<\n");
2478}
2479
Arjan van de Ven858119e2006-01-14 13:20:43 -08002480static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002481{
2482 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002483 if (!count)
2484 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002485 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002486 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002487 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002488}
2489
2490static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2491{
James Ketrenosb095c382005-08-24 22:04:42 -05002492 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002493 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002494 sizeof(struct command_block));
2495}
2496
2497static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002498{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002499
2500 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002501
James Ketrenos43f66a62005-03-25 12:31:53 -06002502 /* Start the dma */
2503 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002504
James Ketrenos43f66a62005-03-25 12:31:53 -06002505 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002506 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002507
2508 IPW_DEBUG_FW("<< : \n");
2509 return 0;
2510}
2511
2512static void ipw_fw_dma_abort(struct ipw_priv *priv)
2513{
2514 u32 control = 0;
2515
2516 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002517
2518 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002519 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002520 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002521 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002522
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 IPW_DEBUG_FW("<< \n");
2524}
2525
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002526static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2527 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002528{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002529 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002530 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002531 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002532 IPW_DEBUG_FW(">> :\n");
2533
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002534 ipw_write_indirect(priv, address, (u8 *) cb,
2535 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002536
2537 IPW_DEBUG_FW("<< :\n");
2538 return 0;
2539
2540}
2541
2542static int ipw_fw_dma_kick(struct ipw_priv *priv)
2543{
2544 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002545 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002546
2547 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002548
James Ketrenos43f66a62005-03-25 12:31:53 -06002549 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002550 ipw_fw_dma_write_command_block(priv, index,
2551 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002552
2553 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002554 ipw_clear_bit(priv, IPW_RESET_REG,
2555 IPW_RESET_REG_MASTER_DISABLED |
2556 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002557
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002558 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002559 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002560 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002561
2562 IPW_DEBUG_FW("<< :\n");
2563 return 0;
2564}
2565
2566static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2567{
2568 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002569 u32 register_value = 0;
2570 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002571
2572 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002573 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002574 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002575
2576 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002577 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2578 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002579
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002580 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002581 cb_fields_address = address;
2582 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002583 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002584
2585 cb_fields_address += sizeof(u32);
2586 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002587 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002588
2589 cb_fields_address += sizeof(u32);
2590 register_value = ipw_read_reg32(priv, cb_fields_address);
2591 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2592 register_value);
2593
2594 cb_fields_address += sizeof(u32);
2595 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002596 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002597
2598 IPW_DEBUG_FW(">> :\n");
2599}
2600
2601static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2602{
2603 u32 current_cb_address = 0;
2604 u32 current_cb_index = 0;
2605
2606 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002607 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002608
James Ketrenosb095c382005-08-24 22:04:42 -05002609 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002610 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002611
James Ketrenos43f66a62005-03-25 12:31:53 -06002612 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002613 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002614
2615 IPW_DEBUG_FW(">> :\n");
2616 return current_cb_index;
2617
2618}
2619
2620static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2621 u32 src_address,
2622 u32 dest_address,
2623 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002624 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002625{
2626
Jeff Garzikbf794512005-07-31 13:07:26 -04002627 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002628 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2629 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002630 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002631 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002632
2633 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2634 src_address, dest_address, length);
2635
2636 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2637 return -1;
2638
2639 last_cb_element = priv->sram_desc.last_cb_index;
2640 cb = &priv->sram_desc.cb_list[last_cb_element];
2641 priv->sram_desc.last_cb_index++;
2642
2643 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002644 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002645 control |= CB_INT_ENABLED;
2646
2647 if (is_last)
2648 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002649
James Ketrenos43f66a62005-03-25 12:31:53 -06002650 control |= length;
2651
2652 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002653 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002654
2655 /* Copy the Source and Destination addresses */
2656 cb->dest_addr = dest_address;
2657 cb->source_addr = src_address;
2658
2659 /* Copy the Control Word last */
2660 cb->control = control;
2661
2662 return 0;
2663}
2664
2665static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002666 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002667{
2668 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002669 u32 src_offset = 0;
2670 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 int status = 0;
2672 IPW_DEBUG_FW(">> \n");
2673 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2674 src_phys, dest_address, length);
2675 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002676 status = ipw_fw_dma_add_command_block(priv,
2677 src_phys + src_offset,
2678 dest_address +
2679 dest_offset,
2680 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002681 if (status) {
2682 IPW_DEBUG_FW_INFO(": Failed\n");
2683 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002684 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002685 IPW_DEBUG_FW_INFO(": Added new cb\n");
2686
2687 src_offset += CB_MAX_LENGTH;
2688 dest_offset += CB_MAX_LENGTH;
2689 bytes_left -= CB_MAX_LENGTH;
2690 }
2691
2692 /* add the buffer tail */
2693 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002694 status =
2695 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2696 dest_address + dest_offset,
2697 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002698 if (status) {
2699 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2700 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002701 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 IPW_DEBUG_FW_INFO
2703 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002704 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002705
James Ketrenos43f66a62005-03-25 12:31:53 -06002706 IPW_DEBUG_FW("<< \n");
2707 return 0;
2708}
2709
2710static int ipw_fw_dma_wait(struct ipw_priv *priv)
2711{
2712 u32 current_index = 0;
2713 u32 watchdog = 0;
2714
2715 IPW_DEBUG_FW(">> : \n");
2716
2717 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002718 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002719 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002720
2721 while (current_index < priv->sram_desc.last_cb_index) {
2722 udelay(50);
2723 current_index = ipw_fw_dma_command_block_index(priv);
2724
2725 watchdog++;
2726
2727 if (watchdog > 400) {
2728 IPW_DEBUG_FW_INFO("Timeout\n");
2729 ipw_fw_dma_dump_command_block(priv);
2730 ipw_fw_dma_abort(priv);
2731 return -1;
2732 }
2733 }
2734
2735 ipw_fw_dma_abort(priv);
2736
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002737 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002738 ipw_set_bit(priv, IPW_RESET_REG,
2739 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002740
2741 IPW_DEBUG_FW("<< dmaWaitSync \n");
2742 return 0;
2743}
2744
Jeff Garzikbf794512005-07-31 13:07:26 -04002745static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002746{
2747 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002748 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002749 unsigned long flags;
2750
2751 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002752 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2753 network = list_entry(element, struct ieee80211_network, list);
2754 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2755 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002756 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002757 &priv->ieee->network_free_list);
2758 }
2759 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002760 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002761}
2762
2763/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002764 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002765 * Reads debug register from domain0.
2766 * If card is present, pre-defined value should
2767 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002768 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002769 * @param priv
2770 * @return 1 if card is present, 0 otherwise
2771 */
2772static inline int ipw_alive(struct ipw_priv *priv)
2773{
2774 return ipw_read32(priv, 0x90) == 0xd55555d5;
2775}
2776
Arjan van de Ven858119e2006-01-14 13:20:43 -08002777static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002778 int timeout)
2779{
2780 int i = 0;
2781
2782 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002783 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002784 return i;
2785 mdelay(10);
2786 i += 10;
2787 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002788
James Ketrenos43f66a62005-03-25 12:31:53 -06002789 return -ETIME;
2790}
2791
Jeff Garzikbf794512005-07-31 13:07:26 -04002792/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002793 * the ipw hardware. It assumes the buffer has all the bits for the
2794 * image and the caller is handling the memory allocation and clean up.
2795 */
2796
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002797static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002798{
2799 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002800
James Ketrenos43f66a62005-03-25 12:31:53 -06002801 IPW_DEBUG_TRACE(">> \n");
2802 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002803 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002804
James Ketrenosb095c382005-08-24 22:04:42 -05002805 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2806 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002807 if (rc < 0) {
2808 IPW_ERROR("stop master failed in 10ms\n");
2809 return -1;
2810 }
2811
2812 IPW_DEBUG_INFO("stop master %dms\n", rc);
2813
2814 return rc;
2815}
2816
2817static void ipw_arc_release(struct ipw_priv *priv)
2818{
2819 IPW_DEBUG_TRACE(">> \n");
2820 mdelay(5);
2821
James Ketrenosb095c382005-08-24 22:04:42 -05002822 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002823
2824 /* no one knows timing, for safety add some delay */
2825 mdelay(5);
2826}
2827
2828struct fw_header {
2829 u32 version;
2830 u32 mode;
2831};
2832
2833struct fw_chunk {
2834 u32 address;
2835 u32 length;
2836};
2837
2838#define IPW_FW_MAJOR_VERSION 2
James Ketrenos81715372005-08-25 01:37:28 -05002839#define IPW_FW_MINOR_VERSION 4
James Ketrenos43f66a62005-03-25 12:31:53 -06002840
2841#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2842#define IPW_FW_MAJOR(x) (x & 0xff)
2843
James Ketrenosafbf30a2005-08-25 00:05:33 -05002844#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002845
2846#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2847"." __stringify(IPW_FW_MINOR_VERSION) "-"
2848
2849#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2850#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2851#else
2852#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2853#endif
2854
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002855static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002856{
2857 int rc = 0, i, addr;
2858 u8 cr = 0;
2859 u16 *image;
2860
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002861 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002862
James Ketrenos43f66a62005-03-25 12:31:53 -06002863 IPW_DEBUG_TRACE(">> \n");
2864
2865 rc = ipw_stop_master(priv);
2866
2867 if (rc < 0)
2868 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002869
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002870// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002871
James Ketrenosb095c382005-08-24 22:04:42 -05002872 for (addr = IPW_SHARED_LOWER_BOUND;
2873 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002874 ipw_write32(priv, addr, 0);
2875 }
2876
2877 /* no ucode (yet) */
2878 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2879 /* destroy DMA queues */
2880 /* reset sequence */
2881
James Ketrenosb095c382005-08-24 22:04:42 -05002882 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002884 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002885 mdelay(1);
2886
2887 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002888 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002889 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002890
James Ketrenosb095c382005-08-24 22:04:42 -05002891 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002893
James Ketrenos43f66a62005-03-25 12:31:53 -06002894 /* enable ucode store */
2895 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2896 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2897 mdelay(1);
2898
2899 /* write ucode */
2900 /**
2901 * @bug
2902 * Do NOT set indirect address register once and then
2903 * store data to indirect data register in the loop.
2904 * It seems very reasonable, but in this case DINO do not
2905 * accept ucode. It is essential to set address each time.
2906 */
2907 /* load new ipw uCode */
2908 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002909 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002910 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002911
James Ketrenos43f66a62005-03-25 12:31:53 -06002912 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002913 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2914 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002915
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002916 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002917
2918 /* wait for alive response */
2919 for (i = 0; i < 100; i++) {
2920 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002921 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002922 if (cr & DINO_RXFIFO_DATA)
2923 break;
2924 mdelay(1);
2925 }
2926
2927 if (cr & DINO_RXFIFO_DATA) {
2928 /* alive_command_responce size is NOT multiple of 4 */
2929 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002930
2931 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002933 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002934 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002935 memcpy(&priv->dino_alive, response_buffer,
2936 sizeof(priv->dino_alive));
2937 if (priv->dino_alive.alive_command == 1
2938 && priv->dino_alive.ucode_valid == 1) {
2939 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002940 IPW_DEBUG_INFO
2941 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2942 "of %02d/%02d/%02d %02d:%02d\n",
2943 priv->dino_alive.software_revision,
2944 priv->dino_alive.software_revision,
2945 priv->dino_alive.device_identifier,
2946 priv->dino_alive.device_identifier,
2947 priv->dino_alive.time_stamp[0],
2948 priv->dino_alive.time_stamp[1],
2949 priv->dino_alive.time_stamp[2],
2950 priv->dino_alive.time_stamp[3],
2951 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002952 } else {
2953 IPW_DEBUG_INFO("Microcode is not alive\n");
2954 rc = -EINVAL;
2955 }
2956 } else {
2957 IPW_DEBUG_INFO("No alive response from DINO\n");
2958 rc = -ETIME;
2959 }
2960
2961 /* disable DINO, otherwise for some reason
2962 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002963 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002964
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002965// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002966
2967 return rc;
2968}
2969
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002970static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002971{
2972 int rc = -1;
2973 int offset = 0;
2974 struct fw_chunk *chunk;
2975 dma_addr_t shared_phys;
2976 u8 *shared_virt;
2977
2978 IPW_DEBUG_TRACE("<< : \n");
2979 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2980
2981 if (!shared_virt)
2982 return -ENOMEM;
2983
2984 memmove(shared_virt, data, len);
2985
2986 /* Start the Dma */
2987 rc = ipw_fw_dma_enable(priv);
2988
2989 if (priv->sram_desc.last_cb_index > 0) {
2990 /* the DMA is already ready this would be a bug. */
2991 BUG();
2992 goto out;
2993 }
2994
2995 do {
2996 chunk = (struct fw_chunk *)(data + offset);
2997 offset += sizeof(struct fw_chunk);
2998 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002999 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 * offeset*/
3001 /* Dma loading */
3002 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003003 le32_to_cpu(chunk->address),
3004 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003005 if (rc) {
3006 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3007 goto out;
3008 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003009
James Ketrenosa613bff2005-08-24 21:43:11 -05003010 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003011 } while (offset < len);
3012
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003013 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003014 rc = ipw_fw_dma_kick(priv);
3015 if (rc) {
3016 IPW_ERROR("dmaKick Failed\n");
3017 goto out;
3018 }
3019
3020 rc = ipw_fw_dma_wait(priv);
3021 if (rc) {
3022 IPW_ERROR("dmaWaitSync Failed\n");
3023 goto out;
3024 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003025 out:
3026 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003027 return rc;
3028}
3029
3030/* stop nic */
3031static int ipw_stop_nic(struct ipw_priv *priv)
3032{
3033 int rc = 0;
3034
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003035 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003036 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003037
James Ketrenosb095c382005-08-24 22:04:42 -05003038 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3039 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003040 if (rc < 0) {
3041 IPW_ERROR("wait for reg master disabled failed\n");
3042 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003043 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003044
James Ketrenosb095c382005-08-24 22:04:42 -05003045 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003046
James Ketrenos43f66a62005-03-25 12:31:53 -06003047 return rc;
3048}
3049
3050static void ipw_start_nic(struct ipw_priv *priv)
3051{
3052 IPW_DEBUG_TRACE(">>\n");
3053
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003054 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003055 ipw_clear_bit(priv, IPW_RESET_REG,
3056 IPW_RESET_REG_MASTER_DISABLED |
3057 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003058 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003059
James Ketrenos43f66a62005-03-25 12:31:53 -06003060 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003061 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3062 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003063
3064 IPW_DEBUG_TRACE("<<\n");
3065}
Jeff Garzikbf794512005-07-31 13:07:26 -04003066
James Ketrenos43f66a62005-03-25 12:31:53 -06003067static int ipw_init_nic(struct ipw_priv *priv)
3068{
3069 int rc;
3070
3071 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003072 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003073 /*prvHwInitNic */
3074 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003075 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003076
3077 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003078 ipw_write32(priv, IPW_READ_INT_REGISTER,
3079 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003080
3081 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003082 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3083 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003084 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003085 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3086
3087 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003088 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003089
3090 udelay(10);
3091
3092 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003093 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003094
3095 IPW_DEBUG_TRACE(">>\n");
3096 return 0;
3097}
3098
Jeff Garzikbf794512005-07-31 13:07:26 -04003099/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003100 * Probe is an ok place to call this from.
3101 */
3102static int ipw_reset_nic(struct ipw_priv *priv)
3103{
3104 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003105 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003106
3107 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003108
James Ketrenos43f66a62005-03-25 12:31:53 -06003109 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003110
James Ketrenosa613bff2005-08-24 21:43:11 -05003111 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003112 /* Clear the 'host command active' bit... */
3113 priv->status &= ~STATUS_HCMD_ACTIVE;
3114 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003115 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3116 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003117 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003118
3119 IPW_DEBUG_TRACE("<<\n");
3120 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003121}
James Ketrenos43f66a62005-03-25 12:31:53 -06003122
Jeff Garzikbf794512005-07-31 13:07:26 -04003123static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003124 const struct firmware **fw, const char *name)
3125{
3126 struct fw_header *header;
3127 int rc;
3128
3129 /* ask firmware_class module to get the boot firmware off disk */
3130 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3131 if (rc < 0) {
3132 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3133 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003134 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003135
3136 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003137 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003138 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3139 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003140 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3141 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 return -EINVAL;
3143 }
3144
Jiri Bencaaa4d302005-06-07 14:58:41 +02003145 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003146 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003147 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3148 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003149 (*fw)->size - sizeof(struct fw_header));
3150 return 0;
3151}
3152
James Ketrenosb095c382005-08-24 22:04:42 -05003153#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003154
Arjan van de Ven858119e2006-01-14 13:20:43 -08003155static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003156 struct ipw_rx_queue *rxq)
3157{
3158 unsigned long flags;
3159 int i;
3160
3161 spin_lock_irqsave(&rxq->lock, flags);
3162
3163 INIT_LIST_HEAD(&rxq->rx_free);
3164 INIT_LIST_HEAD(&rxq->rx_used);
3165
3166 /* Fill the rx_used queue with _all_ of the Rx buffers */
3167 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3168 /* In the reset function, these buffers may have been allocated
3169 * to an SKB, so we need to unmap and free potential storage */
3170 if (rxq->pool[i].skb != NULL) {
3171 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003172 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003173 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003174 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003175 }
3176 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3177 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003178
James Ketrenos43f66a62005-03-25 12:31:53 -06003179 /* Set us so that we have processed and used all buffers, but have
3180 * not restocked the Rx queue with fresh buffers */
3181 rxq->read = rxq->write = 0;
3182 rxq->processed = RX_QUEUE_SIZE - 1;
3183 rxq->free_count = 0;
3184 spin_unlock_irqrestore(&rxq->lock, flags);
3185}
3186
3187#ifdef CONFIG_PM
3188static int fw_loaded = 0;
3189static const struct firmware *bootfw = NULL;
3190static const struct firmware *firmware = NULL;
3191static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003192
3193static void free_firmware(void)
3194{
3195 if (fw_loaded) {
3196 release_firmware(bootfw);
3197 release_firmware(ucode);
3198 release_firmware(firmware);
3199 bootfw = ucode = firmware = NULL;
3200 fw_loaded = 0;
3201 }
3202}
3203#else
3204#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003205#endif
3206
3207static int ipw_load(struct ipw_priv *priv)
3208{
3209#ifndef CONFIG_PM
3210 const struct firmware *bootfw = NULL;
3211 const struct firmware *firmware = NULL;
3212 const struct firmware *ucode = NULL;
3213#endif
3214 int rc = 0, retries = 3;
3215
3216#ifdef CONFIG_PM
3217 if (!fw_loaded) {
3218#endif
3219 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003220 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003221 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003222
James Ketrenos43f66a62005-03-25 12:31:53 -06003223 switch (priv->ieee->iw_mode) {
3224 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003225 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003227 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003228 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003229
James Ketrenos43f66a62005-03-25 12:31:53 -06003230 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3231 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003232
James Ketrenosb095c382005-08-24 22:04:42 -05003233#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003234 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003235 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003236 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003237 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003238 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003239
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003240 rc = ipw_get_fw(priv, &firmware,
3241 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003242 break;
3243#endif
3244 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003245 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003246 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003248
James Ketrenos43f66a62005-03-25 12:31:53 -06003249 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3250 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003251
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 default:
3253 rc = -EINVAL;
3254 }
3255
Jeff Garzikbf794512005-07-31 13:07:26 -04003256 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003257 goto error;
3258
3259#ifdef CONFIG_PM
3260 fw_loaded = 1;
3261 }
3262#endif
3263
3264 if (!priv->rxq)
3265 priv->rxq = ipw_rx_queue_alloc(priv);
3266 else
3267 ipw_rx_queue_reset(priv, priv->rxq);
3268 if (!priv->rxq) {
3269 IPW_ERROR("Unable to initialize Rx queue\n");
3270 goto error;
3271 }
3272
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003273 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003274 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003275 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003276 priv->status &= ~STATUS_INT_ENABLED;
3277
3278 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003279 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003280
James Ketrenos43f66a62005-03-25 12:31:53 -06003281 ipw_stop_nic(priv);
3282
3283 rc = ipw_reset_nic(priv);
3284 if (rc) {
3285 IPW_ERROR("Unable to reset NIC\n");
3286 goto error;
3287 }
3288
James Ketrenosb095c382005-08-24 22:04:42 -05003289 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3290 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003291
3292 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003293 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003294 bootfw->size - sizeof(struct fw_header));
3295 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003296 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003297 goto error;
3298 }
3299
3300 /* kick start the device */
3301 ipw_start_nic(priv);
3302
3303 /* wait for the device to finish it's initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003304 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3305 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003306 if (rc < 0) {
3307 IPW_ERROR("device failed to boot initial fw image\n");
3308 goto error;
3309 }
3310 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3311
Jeff Garzikbf794512005-07-31 13:07:26 -04003312 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003313 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003314
3315 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003316 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003317 ucode->size - sizeof(struct fw_header));
3318 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003319 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 goto error;
3321 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003322
James Ketrenos43f66a62005-03-25 12:31:53 -06003323 /* stop nic */
3324 ipw_stop_nic(priv);
3325
3326 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003327 rc = ipw_load_firmware(priv, firmware->data +
3328 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003329 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003330 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003331 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 goto error;
3333 }
3334
3335 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3336
3337 rc = ipw_queue_reset(priv);
3338 if (rc) {
3339 IPW_ERROR("Unable to initialize queues\n");
3340 goto error;
3341 }
3342
3343 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003344 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003345 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003346 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003347
James Ketrenos43f66a62005-03-25 12:31:53 -06003348 /* kick start the device */
3349 ipw_start_nic(priv);
3350
James Ketrenosb095c382005-08-24 22:04:42 -05003351 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003352 if (retries > 0) {
3353 IPW_WARNING("Parity error. Retrying init.\n");
3354 retries--;
3355 goto retry;
3356 }
3357
3358 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3359 rc = -EIO;
3360 goto error;
3361 }
3362
3363 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003364 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3365 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003366 if (rc < 0) {
3367 IPW_ERROR("device failed to start after 500ms\n");
3368 goto error;
3369 }
3370 IPW_DEBUG_INFO("device response after %dms\n", rc);
3371
3372 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003373 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003374
3375 /* read eeprom data and initialize the eeprom region of sram */
3376 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003377 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003378
3379 /* enable interrupts */
3380 ipw_enable_interrupts(priv);
3381
3382 /* Ensure our queue has valid packets */
3383 ipw_rx_queue_replenish(priv);
3384
James Ketrenosb095c382005-08-24 22:04:42 -05003385 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003386
3387 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003388 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003389
3390#ifndef CONFIG_PM
3391 release_firmware(bootfw);
3392 release_firmware(ucode);
3393 release_firmware(firmware);
3394#endif
3395 return 0;
3396
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003397 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003398 if (priv->rxq) {
3399 ipw_rx_queue_free(priv, priv->rxq);
3400 priv->rxq = NULL;
3401 }
3402 ipw_tx_queue_free(priv);
3403 if (bootfw)
3404 release_firmware(bootfw);
3405 if (ucode)
3406 release_firmware(ucode);
3407 if (firmware)
3408 release_firmware(firmware);
3409#ifdef CONFIG_PM
3410 fw_loaded = 0;
3411 bootfw = ucode = firmware = NULL;
3412#endif
3413
3414 return rc;
3415}
3416
Jeff Garzikbf794512005-07-31 13:07:26 -04003417/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003418 * DMA services
3419 *
3420 * Theory of operation
3421 *
3422 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3423 * 2 empty entries always kept in the buffer to protect from overflow.
3424 *
3425 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003426 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3427 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003428 * Tx queue resumed.
3429 *
3430 * The IPW operates with six queues, one receive queue in the device's
3431 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003432 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003433 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003434 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003435 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003436 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003437 * we only utilize the first data transmit queue (queue1).
3438 */
3439
3440/**
3441 * Driver allocates buffers of this size for Rx
3442 */
3443
3444static inline int ipw_queue_space(const struct clx2_queue *q)
3445{
3446 int s = q->last_used - q->first_empty;
3447 if (s <= 0)
3448 s += q->n_bd;
3449 s -= 2; /* keep some reserve to not confuse empty and full situations */
3450 if (s < 0)
3451 s = 0;
3452 return s;
3453}
3454
3455static inline int ipw_queue_inc_wrap(int index, int n_bd)
3456{
3457 return (++index == n_bd) ? 0 : index;
3458}
3459
3460/**
3461 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003462 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003463 * @param q queue to init
3464 * @param count Number of BD's to allocate. Should be power of 2
3465 * @param read_register Address for 'read' register
3466 * (not offset within BAR, full address)
3467 * @param write_register Address for 'write' register
3468 * (not offset within BAR, full address)
3469 * @param base_register Address for 'base' register
3470 * (not offset within BAR, full address)
3471 * @param size Address for 'size' register
3472 * (not offset within BAR, full address)
3473 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003474static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003475 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003476{
3477 q->n_bd = count;
3478
3479 q->low_mark = q->n_bd / 4;
3480 if (q->low_mark < 4)
3481 q->low_mark = 4;
3482
3483 q->high_mark = q->n_bd / 8;
3484 if (q->high_mark < 2)
3485 q->high_mark = 2;
3486
3487 q->first_empty = q->last_used = 0;
3488 q->reg_r = read;
3489 q->reg_w = write;
3490
3491 ipw_write32(priv, base, q->dma_addr);
3492 ipw_write32(priv, size, count);
3493 ipw_write32(priv, read, 0);
3494 ipw_write32(priv, write, 0);
3495
3496 _ipw_read32(priv, 0x90);
3497}
3498
Jeff Garzikbf794512005-07-31 13:07:26 -04003499static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003500 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003501 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003502{
3503 struct pci_dev *dev = priv->pci_dev;
3504
3505 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3506 if (!q->txb) {
3507 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3508 return -ENOMEM;
3509 }
3510
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003511 q->bd =
3512 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003513 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003514 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003515 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003516 kfree(q->txb);
3517 q->txb = NULL;
3518 return -ENOMEM;
3519 }
3520
3521 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3522 return 0;
3523}
3524
3525/**
3526 * Free one TFD, those at index [txq->q.last_used].
3527 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003528 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003529 * @param dev
3530 * @param txq
3531 */
3532static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3533 struct clx2_tx_queue *txq)
3534{
3535 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3536 struct pci_dev *dev = priv->pci_dev;
3537 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003538
James Ketrenos43f66a62005-03-25 12:31:53 -06003539 /* classify bd */
3540 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3541 /* nothing to cleanup after for host commands */
3542 return;
3543
3544 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003545 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3546 IPW_ERROR("Too many chunks: %i\n",
3547 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003548 /** @todo issue fatal error, it is quite serious situation */
3549 return;
3550 }
3551
3552 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003553 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3554 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3555 le16_to_cpu(bd->u.data.chunk_len[i]),
3556 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 if (txq->txb[txq->q.last_used]) {
3558 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3559 txq->txb[txq->q.last_used] = NULL;
3560 }
3561 }
3562}
3563
3564/**
3565 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003566 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003567 * Empty queue by removing and destroying all BD's.
3568 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003569 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003570 * @param dev
3571 * @param q
3572 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003573static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003574{
3575 struct clx2_queue *q = &txq->q;
3576 struct pci_dev *dev = priv->pci_dev;
3577
Jeff Garzikbf794512005-07-31 13:07:26 -04003578 if (q->n_bd == 0)
3579 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003580
3581 /* first, empty all BD's */
3582 for (; q->first_empty != q->last_used;
3583 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3584 ipw_queue_tx_free_tfd(priv, txq);
3585 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003586
James Ketrenos43f66a62005-03-25 12:31:53 -06003587 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003588 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003589 q->dma_addr);
3590 kfree(txq->txb);
3591
3592 /* 0 fill whole structure */
3593 memset(txq, 0, sizeof(*txq));
3594}
3595
James Ketrenos43f66a62005-03-25 12:31:53 -06003596/**
3597 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003598 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003599 * @param priv
3600 */
3601static void ipw_tx_queue_free(struct ipw_priv *priv)
3602{
3603 /* Tx CMD queue */
3604 ipw_queue_tx_free(priv, &priv->txq_cmd);
3605
3606 /* Tx queues */
3607 ipw_queue_tx_free(priv, &priv->txq[0]);
3608 ipw_queue_tx_free(priv, &priv->txq[1]);
3609 ipw_queue_tx_free(priv, &priv->txq[2]);
3610 ipw_queue_tx_free(priv, &priv->txq[3]);
3611}
3612
Arjan van de Ven858119e2006-01-14 13:20:43 -08003613static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003614{
3615 /* First 3 bytes are manufacturer */
3616 bssid[0] = priv->mac_addr[0];
3617 bssid[1] = priv->mac_addr[1];
3618 bssid[2] = priv->mac_addr[2];
3619
3620 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003621 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003622
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003623 bssid[0] &= 0xfe; /* clear multicast bit */
3624 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003625}
3626
Arjan van de Ven858119e2006-01-14 13:20:43 -08003627static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003628{
3629 struct ipw_station_entry entry;
3630 int i;
3631
3632 for (i = 0; i < priv->num_stations; i++) {
3633 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3634 /* Another node is active in network */
3635 priv->missed_adhoc_beacons = 0;
3636 if (!(priv->config & CFG_STATIC_CHANNEL))
3637 /* when other nodes drop out, we drop out */
3638 priv->config &= ~CFG_ADHOC_PERSIST;
3639
3640 return i;
3641 }
3642 }
3643
3644 if (i == MAX_STATIONS)
3645 return IPW_INVALID_STATION;
3646
3647 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3648
3649 entry.reserved = 0;
3650 entry.support_mode = 0;
3651 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3652 memcpy(priv->stations[i], bssid, ETH_ALEN);
3653 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003654 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003655 priv->num_stations++;
3656
3657 return i;
3658}
3659
Arjan van de Ven858119e2006-01-14 13:20:43 -08003660static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003661{
3662 int i;
3663
Jeff Garzikbf794512005-07-31 13:07:26 -04003664 for (i = 0; i < priv->num_stations; i++)
3665 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003666 return i;
3667
3668 return IPW_INVALID_STATION;
3669}
3670
3671static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3672{
3673 int err;
3674
Hong Liu7b996592005-08-25 17:36:13 +08003675 if (priv->status & STATUS_ASSOCIATING) {
3676 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3677 queue_work(priv->workqueue, &priv->disassociate);
3678 return;
3679 }
3680
3681 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003682 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3683 return;
3684 }
3685
3686 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3687 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003688 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003689 priv->assoc_request.channel);
3690
3691 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3692 priv->status |= STATUS_DISASSOCIATING;
3693
3694 if (quiet)
3695 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3696 else
3697 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003698
James Ketrenos43f66a62005-03-25 12:31:53 -06003699 err = ipw_send_associate(priv, &priv->assoc_request);
3700 if (err) {
3701 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3702 "failed.\n");
3703 return;
3704 }
3705
3706}
3707
James Ketrenosc848d0a2005-08-24 21:56:24 -05003708static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003709{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003710 struct ipw_priv *priv = data;
3711 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3712 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003713 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003714 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003715}
3716
James Ketrenosc848d0a2005-08-24 21:56:24 -05003717static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003718{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003719 struct ipw_priv *priv = data;
3720 down(&priv->sem);
3721 ipw_disassociate(data);
3722 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003723}
3724
Zhu Yid8bad6d2005-07-13 12:25:38 -05003725static void ipw_system_config(void *data)
3726{
3727 struct ipw_priv *priv = data;
3728 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003729}
3730
3731struct ipw_status_code {
3732 u16 status;
3733 const char *reason;
3734};
3735
3736static const struct ipw_status_code ipw_status_codes[] = {
3737 {0x00, "Successful"},
3738 {0x01, "Unspecified failure"},
3739 {0x0A, "Cannot support all requested capabilities in the "
3740 "Capability information field"},
3741 {0x0B, "Reassociation denied due to inability to confirm that "
3742 "association exists"},
3743 {0x0C, "Association denied due to reason outside the scope of this "
3744 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003745 {0x0D,
3746 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003747 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003748 {0x0E,
3749 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003750 "transaction sequence number out of expected sequence"},
3751 {0x0F, "Authentication rejected because of challenge failure"},
3752 {0x10, "Authentication rejected due to timeout waiting for next "
3753 "frame in sequence"},
3754 {0x11, "Association denied because AP is unable to handle additional "
3755 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003756 {0x12,
3757 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003758 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003759 {0x13,
3760 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003761 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003762 {0x14,
3763 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003764 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003765 {0x15,
3766 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003767 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003768 {0x19,
3769 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003770 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003771 {0x1A,
3772 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003773 "DSSS-OFDM operation"},
3774 {0x28, "Invalid Information Element"},
3775 {0x29, "Group Cipher is not valid"},
3776 {0x2A, "Pairwise Cipher is not valid"},
3777 {0x2B, "AKMP is not valid"},
3778 {0x2C, "Unsupported RSN IE version"},
3779 {0x2D, "Invalid RSN IE Capabilities"},
3780 {0x2E, "Cipher suite is rejected per security policy"},
3781};
3782
Brice Goglin0f52bf92005-12-01 01:41:46 -08003783#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003784static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003785{
3786 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003787 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003788 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003789 return ipw_status_codes[i].reason;
3790 return "Unknown status value.";
3791}
3792#endif
3793
3794static void inline average_init(struct average *avg)
3795{
3796 memset(avg, 0, sizeof(*avg));
3797}
3798
Arjan van de Ven858119e2006-01-14 13:20:43 -08003799static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003800{
3801 avg->sum -= avg->entries[avg->pos];
3802 avg->sum += val;
3803 avg->entries[avg->pos++] = val;
3804 if (unlikely(avg->pos == AVG_ENTRIES)) {
3805 avg->init = 1;
3806 avg->pos = 0;
3807 }
3808}
3809
Arjan van de Ven858119e2006-01-14 13:20:43 -08003810static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003811{
3812 if (!unlikely(avg->init)) {
3813 if (avg->pos)
3814 return avg->sum / avg->pos;
3815 return 0;
3816 }
3817
3818 return avg->sum / AVG_ENTRIES;
3819}
3820
3821static void ipw_reset_stats(struct ipw_priv *priv)
3822{
3823 u32 len = sizeof(u32);
3824
3825 priv->quality = 0;
3826
3827 average_init(&priv->average_missed_beacons);
3828 average_init(&priv->average_rssi);
3829 average_init(&priv->average_noise);
3830
3831 priv->last_rate = 0;
3832 priv->last_missed_beacons = 0;
3833 priv->last_rx_packets = 0;
3834 priv->last_tx_packets = 0;
3835 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003836
James Ketrenos43f66a62005-03-25 12:31:53 -06003837 /* Firmware managed, reset only when NIC is restarted, so we have to
3838 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003839 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003840 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003841 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003842 &priv->last_tx_failures, &len);
3843
3844 /* Driver managed, reset with each association */
3845 priv->missed_adhoc_beacons = 0;
3846 priv->missed_beacons = 0;
3847 priv->tx_packets = 0;
3848 priv->rx_packets = 0;
3849
3850}
3851
Arjan van de Ven858119e2006-01-14 13:20:43 -08003852static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003853{
3854 u32 i = 0x80000000;
3855 u32 mask = priv->rates_mask;
3856 /* If currently associated in B mode, restrict the maximum
3857 * rate match to B rates */
3858 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3859 mask &= IEEE80211_CCK_RATES_MASK;
3860
3861 /* TODO: Verify that the rate is supported by the current rates
3862 * list. */
3863
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003864 while (i && !(mask & i))
3865 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003866 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003867 case IEEE80211_CCK_RATE_1MB_MASK:
3868 return 1000000;
3869 case IEEE80211_CCK_RATE_2MB_MASK:
3870 return 2000000;
3871 case IEEE80211_CCK_RATE_5MB_MASK:
3872 return 5500000;
3873 case IEEE80211_OFDM_RATE_6MB_MASK:
3874 return 6000000;
3875 case IEEE80211_OFDM_RATE_9MB_MASK:
3876 return 9000000;
3877 case IEEE80211_CCK_RATE_11MB_MASK:
3878 return 11000000;
3879 case IEEE80211_OFDM_RATE_12MB_MASK:
3880 return 12000000;
3881 case IEEE80211_OFDM_RATE_18MB_MASK:
3882 return 18000000;
3883 case IEEE80211_OFDM_RATE_24MB_MASK:
3884 return 24000000;
3885 case IEEE80211_OFDM_RATE_36MB_MASK:
3886 return 36000000;
3887 case IEEE80211_OFDM_RATE_48MB_MASK:
3888 return 48000000;
3889 case IEEE80211_OFDM_RATE_54MB_MASK:
3890 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003891 }
3892
Jeff Garzikbf794512005-07-31 13:07:26 -04003893 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003894 return 11000000;
3895 else
3896 return 54000000;
3897}
3898
3899static u32 ipw_get_current_rate(struct ipw_priv *priv)
3900{
3901 u32 rate, len = sizeof(rate);
3902 int err;
3903
Jeff Garzikbf794512005-07-31 13:07:26 -04003904 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003905 return 0;
3906
3907 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003908 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003909 &len);
3910 if (err) {
3911 IPW_DEBUG_INFO("failed querying ordinals.\n");
3912 return 0;
3913 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003914 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 return ipw_get_max_rate(priv);
3916
3917 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003918 case IPW_TX_RATE_1MB:
3919 return 1000000;
3920 case IPW_TX_RATE_2MB:
3921 return 2000000;
3922 case IPW_TX_RATE_5MB:
3923 return 5500000;
3924 case IPW_TX_RATE_6MB:
3925 return 6000000;
3926 case IPW_TX_RATE_9MB:
3927 return 9000000;
3928 case IPW_TX_RATE_11MB:
3929 return 11000000;
3930 case IPW_TX_RATE_12MB:
3931 return 12000000;
3932 case IPW_TX_RATE_18MB:
3933 return 18000000;
3934 case IPW_TX_RATE_24MB:
3935 return 24000000;
3936 case IPW_TX_RATE_36MB:
3937 return 36000000;
3938 case IPW_TX_RATE_48MB:
3939 return 48000000;
3940 case IPW_TX_RATE_54MB:
3941 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003942 }
3943
3944 return 0;
3945}
3946
James Ketrenos43f66a62005-03-25 12:31:53 -06003947#define IPW_STATS_INTERVAL (2 * HZ)
3948static void ipw_gather_stats(struct ipw_priv *priv)
3949{
3950 u32 rx_err, rx_err_delta, rx_packets_delta;
3951 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3952 u32 missed_beacons_percent, missed_beacons_delta;
3953 u32 quality = 0;
3954 u32 len = sizeof(u32);
3955 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003956 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003957 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003958 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003959
3960 if (!(priv->status & STATUS_ASSOCIATED)) {
3961 priv->quality = 0;
3962 return;
3963 }
3964
3965 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003966 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003967 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003968 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003969 priv->last_missed_beacons = priv->missed_beacons;
3970 if (priv->assoc_request.beacon_interval) {
3971 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003972 (HZ * priv->assoc_request.beacon_interval) /
3973 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 } else {
3975 missed_beacons_percent = 0;
3976 }
3977 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3978
3979 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3980 rx_err_delta = rx_err - priv->last_rx_err;
3981 priv->last_rx_err = rx_err;
3982
3983 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3984 tx_failures_delta = tx_failures - priv->last_tx_failures;
3985 priv->last_tx_failures = tx_failures;
3986
3987 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3988 priv->last_rx_packets = priv->rx_packets;
3989
3990 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3991 priv->last_tx_packets = priv->tx_packets;
3992
3993 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003994 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003995 * Missed beacon: 100% = 0, 0% = 70% missed
3996 * Rate: 60% = 1Mbs, 100% = Max
3997 * Rx and Tx errors represent a straight % of total Rx/Tx
3998 * RSSI: 100% = > -50, 0% = < -80
3999 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004000 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004001 * The lowest computed quality is used.
4002 *
4003 */
4004#define BEACON_THRESHOLD 5
4005 beacon_quality = 100 - missed_beacons_percent;
4006 if (beacon_quality < BEACON_THRESHOLD)
4007 beacon_quality = 0;
4008 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004009 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004010 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004011 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004012 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004013
James Ketrenos43f66a62005-03-25 12:31:53 -06004014 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004015 max_rate = ipw_get_max_rate(priv);
4016 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004017 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4018 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004019
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004020 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004021 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004022 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004023 else
4024 rx_quality = 100;
4025 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4026 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004027
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004028 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004029 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004030 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004031 else
4032 tx_quality = 100;
4033 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4034 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004035
James Ketrenos43f66a62005-03-25 12:31:53 -06004036 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004037 signal_quality =
4038 (100 *
4039 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4040 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4041 (priv->ieee->perfect_rssi - rssi) *
4042 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4043 62 * (priv->ieee->perfect_rssi - rssi))) /
4044 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4045 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4046 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004047 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004048 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004049 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004050
James Ketrenos43f66a62005-03-25 12:31:53 -06004051 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4052 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004053
4054 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004055 min(rate_quality,
4056 min(tx_quality, min(rx_quality, signal_quality))));
4057 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004058 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4059 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004060 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004061 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4062 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004063 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004064 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4065 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004066 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004067 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4068 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004070 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4071 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004072
4073 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004074
4075 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004076 IPW_STATS_INTERVAL);
4077}
4078
James Ketrenosc848d0a2005-08-24 21:56:24 -05004079static void ipw_bg_gather_stats(void *data)
4080{
4081 struct ipw_priv *priv = data;
4082 down(&priv->sem);
4083 ipw_gather_stats(data);
4084 up(&priv->sem);
4085}
4086
Ben Cahille7582562005-10-06 15:34:41 -05004087/* Missed beacon behavior:
4088 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4089 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4090 * Above disassociate threshold, give up and stop scanning.
4091 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004092static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004093 int missed_count)
4094{
4095 priv->notif_missed_beacons = missed_count;
4096
James Ketrenosafbf30a2005-08-25 00:05:33 -05004097 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004098 priv->status & STATUS_ASSOCIATED) {
4099 /* If associated and we've hit the missed
4100 * beacon threshold, disassociate, turn
4101 * off roaming, and abort any active scans */
4102 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004103 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004104 "Missed beacon: %d - disassociate\n", missed_count);
4105 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004106 if (priv->status & STATUS_SCANNING) {
4107 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4108 IPW_DL_STATE,
4109 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004110 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004111 }
4112
James Ketrenosea2b26e2005-08-24 21:25:16 -05004113 queue_work(priv->workqueue, &priv->disassociate);
4114 return;
4115 }
4116
4117 if (priv->status & STATUS_ROAMING) {
4118 /* If we are currently roaming, then just
4119 * print a debug statement... */
4120 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4121 "Missed beacon: %d - roam in progress\n",
4122 missed_count);
4123 return;
4124 }
4125
Ben Cahille7582562005-10-06 15:34:41 -05004126 if (missed_count > priv->roaming_threshold &&
4127 missed_count <= priv->disassociate_threshold) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004128 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004129 * bit in the status and kick off a scan.
4130 * This can happen several times before we reach
4131 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004132 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4133 "Missed beacon: %d - initiate "
4134 "roaming\n", missed_count);
4135 if (!(priv->status & STATUS_ROAMING)) {
4136 priv->status |= STATUS_ROAMING;
4137 if (!(priv->status & STATUS_SCANNING))
4138 queue_work(priv->workqueue,
4139 &priv->request_scan);
4140 }
4141 return;
4142 }
4143
4144 if (priv->status & STATUS_SCANNING) {
4145 /* Stop scan to keep fw from getting
4146 * stuck (only if we aren't roaming --
4147 * otherwise we'll never scan more than 2 or 3
4148 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004149 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4150 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004151 queue_work(priv->workqueue, &priv->abort_scan);
4152 }
4153
4154 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4155
4156}
4157
James Ketrenos43f66a62005-03-25 12:31:53 -06004158/**
4159 * Handle host notification packet.
4160 * Called from interrupt routine
4161 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004162static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004163 struct ipw_rx_notification *notif)
4164{
James Ketrenosa613bff2005-08-24 21:43:11 -05004165 notif->size = le16_to_cpu(notif->size);
4166
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004167 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004168
James Ketrenos43f66a62005-03-25 12:31:53 -06004169 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004170 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4171 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004172
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004173 switch (assoc->state) {
4174 case CMAS_ASSOCIATED:{
4175 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4176 IPW_DL_ASSOC,
4177 "associated: '%s' " MAC_FMT
4178 " \n",
4179 escape_essid(priv->essid,
4180 priv->essid_len),
4181 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004182
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004183 switch (priv->ieee->iw_mode) {
4184 case IW_MODE_INFRA:
4185 memcpy(priv->ieee->bssid,
4186 priv->bssid, ETH_ALEN);
4187 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004188
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004189 case IW_MODE_ADHOC:
4190 memcpy(priv->ieee->bssid,
4191 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 /* clear out the station table */
4194 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004195
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004196 IPW_DEBUG_ASSOC
4197 ("queueing adhoc check\n");
4198 queue_delayed_work(priv->
4199 workqueue,
4200 &priv->
4201 adhoc_check,
4202 priv->
4203 assoc_request.
4204 beacon_interval);
4205 break;
4206 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004207
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004208 priv->status &= ~STATUS_ASSOCIATING;
4209 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004210 queue_work(priv->workqueue,
4211 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004212
James Ketrenosb095c382005-08-24 22:04:42 -05004213#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004214#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4215 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4216 if ((priv->status & STATUS_AUTH) &&
4217 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4218 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004219 if ((sizeof
4220 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004221 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004222 <= notif->size)
4223 && (notif->size <= 2314)) {
4224 struct
4225 ieee80211_rx_stats
4226 stats = {
4227 .len =
4228 notif->
4229 size - 1,
4230 };
4231
4232 IPW_DEBUG_QOS
4233 ("QoS Associate "
4234 "size %d\n",
4235 notif->size);
4236 ieee80211_rx_mgt(priv->
4237 ieee,
4238 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004239 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004240 *)
4241 &notif->u.raw, &stats);
4242 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004243 }
James Ketrenosb095c382005-08-24 22:04:42 -05004244#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004245
James Ketrenosa613bff2005-08-24 21:43:11 -05004246 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004247
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004248 break;
4249 }
4250
4251 case CMAS_AUTHENTICATED:{
4252 if (priv->
4253 status & (STATUS_ASSOCIATED |
4254 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004255#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004256 struct notif_authenticate *auth
4257 = &notif->u.auth;
4258 IPW_DEBUG(IPW_DL_NOTIF |
4259 IPW_DL_STATE |
4260 IPW_DL_ASSOC,
4261 "deauthenticated: '%s' "
4262 MAC_FMT
4263 ": (0x%04X) - %s \n",
4264 escape_essid(priv->
4265 essid,
4266 priv->
4267 essid_len),
4268 MAC_ARG(priv->bssid),
4269 ntohs(auth->status),
4270 ipw_get_status_code
4271 (ntohs
4272 (auth->status)));
4273#endif
4274
4275 priv->status &=
4276 ~(STATUS_ASSOCIATING |
4277 STATUS_AUTH |
4278 STATUS_ASSOCIATED);
4279
James Ketrenosa613bff2005-08-24 21:43:11 -05004280 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004281 break;
4282 }
4283
4284 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4285 IPW_DL_ASSOC,
4286 "authenticated: '%s' " MAC_FMT
4287 "\n",
4288 escape_essid(priv->essid,
4289 priv->essid_len),
4290 MAC_ARG(priv->bssid));
4291 break;
4292 }
4293
4294 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004295 if (priv->status & STATUS_AUTH) {
4296 struct
4297 ieee80211_assoc_response
4298 *resp;
4299 resp =
4300 (struct
4301 ieee80211_assoc_response
4302 *)&notif->u.raw;
4303 IPW_DEBUG(IPW_DL_NOTIF |
4304 IPW_DL_STATE |
4305 IPW_DL_ASSOC,
4306 "association failed (0x%04X): %s\n",
4307 ntohs(resp->status),
4308 ipw_get_status_code
4309 (ntohs
4310 (resp->status)));
4311 }
4312
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004313 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4314 IPW_DL_ASSOC,
4315 "disassociated: '%s' " MAC_FMT
4316 " \n",
4317 escape_essid(priv->essid,
4318 priv->essid_len),
4319 MAC_ARG(priv->bssid));
4320
4321 priv->status &=
4322 ~(STATUS_DISASSOCIATING |
4323 STATUS_ASSOCIATING |
4324 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004325 if (priv->assoc_network
4326 && (priv->assoc_network->
4327 capability &
4328 WLAN_CAPABILITY_IBSS))
4329 ipw_remove_current_network
4330 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331
James Ketrenosa613bff2005-08-24 21:43:11 -05004332 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004333
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004334 break;
4335 }
4336
James Ketrenosb095c382005-08-24 22:04:42 -05004337 case CMAS_RX_ASSOC_RESP:
4338 break;
4339
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004340 default:
4341 IPW_ERROR("assoc: unknown (%d)\n",
4342 assoc->state);
4343 break;
4344 }
4345
James Ketrenos43f66a62005-03-25 12:31:53 -06004346 break;
4347 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004348
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004349 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4350 struct notif_authenticate *auth = &notif->u.auth;
4351 switch (auth->state) {
4352 case CMAS_AUTHENTICATED:
4353 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4354 "authenticated: '%s' " MAC_FMT " \n",
4355 escape_essid(priv->essid,
4356 priv->essid_len),
4357 MAC_ARG(priv->bssid));
4358 priv->status |= STATUS_AUTH;
4359 break;
4360
4361 case CMAS_INIT:
4362 if (priv->status & STATUS_AUTH) {
4363 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4364 IPW_DL_ASSOC,
4365 "authentication failed (0x%04X): %s\n",
4366 ntohs(auth->status),
4367 ipw_get_status_code(ntohs
4368 (auth->
4369 status)));
4370 }
4371 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4372 IPW_DL_ASSOC,
4373 "deauthenticated: '%s' " MAC_FMT "\n",
4374 escape_essid(priv->essid,
4375 priv->essid_len),
4376 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004377
4378 priv->status &= ~(STATUS_ASSOCIATING |
4379 STATUS_AUTH |
4380 STATUS_ASSOCIATED);
4381
James Ketrenosa613bff2005-08-24 21:43:11 -05004382 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004383 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004384
4385 case CMAS_TX_AUTH_SEQ_1:
4386 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4387 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4388 break;
4389 case CMAS_RX_AUTH_SEQ_2:
4390 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4391 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4392 break;
4393 case CMAS_AUTH_SEQ_1_PASS:
4394 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4395 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4396 break;
4397 case CMAS_AUTH_SEQ_1_FAIL:
4398 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4399 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4400 break;
4401 case CMAS_TX_AUTH_SEQ_3:
4402 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4403 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4404 break;
4405 case CMAS_RX_AUTH_SEQ_4:
4406 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4407 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4408 break;
4409 case CMAS_AUTH_SEQ_2_PASS:
4410 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4411 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4412 break;
4413 case CMAS_AUTH_SEQ_2_FAIL:
4414 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4415 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4416 break;
4417 case CMAS_TX_ASSOC:
4418 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4419 IPW_DL_ASSOC, "TX_ASSOC\n");
4420 break;
4421 case CMAS_RX_ASSOC_RESP:
4422 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4423 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004424
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004425 break;
4426 case CMAS_ASSOCIATED:
4427 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4428 IPW_DL_ASSOC, "ASSOCIATED\n");
4429 break;
4430 default:
4431 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4432 auth->state);
4433 break;
4434 }
4435 break;
4436 }
4437
4438 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4439 struct notif_channel_result *x =
4440 &notif->u.channel_result;
4441
4442 if (notif->size == sizeof(*x)) {
4443 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4444 x->channel_num);
4445 } else {
4446 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4447 "(should be %zd)\n",
4448 notif->size, sizeof(*x));
4449 }
4450 break;
4451 }
4452
4453 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4454 struct notif_scan_complete *x = &notif->u.scan_complete;
4455 if (notif->size == sizeof(*x)) {
4456 IPW_DEBUG_SCAN
4457 ("Scan completed: type %d, %d channels, "
4458 "%d status\n", x->scan_type,
4459 x->num_channels, x->status);
4460 } else {
4461 IPW_ERROR("Scan completed of wrong size %d "
4462 "(should be %zd)\n",
4463 notif->size, sizeof(*x));
4464 }
4465
4466 priv->status &=
4467 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4468
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004469 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004470 cancel_delayed_work(&priv->scan_check);
4471
James Ketrenosb095c382005-08-24 22:04:42 -05004472 if (priv->status & STATUS_EXIT_PENDING)
4473 break;
4474
4475 priv->ieee->scans++;
4476
4477#ifdef CONFIG_IPW2200_MONITOR
4478 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004479 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004480 queue_work(priv->workqueue,
4481 &priv->request_scan);
4482 break;
4483 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004484 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004485#endif /* CONFIG_IPW2200_MONITOR */
4486
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004487 if (!(priv->status & (STATUS_ASSOCIATED |
4488 STATUS_ASSOCIATING |
4489 STATUS_ROAMING |
4490 STATUS_DISASSOCIATING)))
4491 queue_work(priv->workqueue, &priv->associate);
4492 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004493 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4494 /* If a scan completed and we are in roam mode, then
4495 * the scan that completed was the one requested as a
4496 * result of entering roam... so, schedule the
4497 * roam work */
4498 queue_work(priv->workqueue,
4499 &priv->roam);
4500 else
4501 /* Don't schedule if we aborted the scan */
4502 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 } else if (priv->status & STATUS_SCAN_PENDING)
4504 queue_work(priv->workqueue,
4505 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004506 else if (priv->config & CFG_BACKGROUND_SCAN
4507 && priv->status & STATUS_ASSOCIATED)
4508 queue_delayed_work(priv->workqueue,
4509 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004510 break;
4511 }
4512
4513 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4514 struct notif_frag_length *x = &notif->u.frag_len;
4515
James Ketrenosa613bff2005-08-24 21:43:11 -05004516 if (notif->size == sizeof(*x))
4517 IPW_ERROR("Frag length: %d\n",
4518 le16_to_cpu(x->frag_length));
4519 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 IPW_ERROR("Frag length of wrong size %d "
4521 "(should be %zd)\n",
4522 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004523 break;
4524 }
4525
4526 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4527 struct notif_link_deterioration *x =
4528 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004529
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004530 if (notif->size == sizeof(*x)) {
4531 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4532 "link deterioration: '%s' " MAC_FMT
4533 " \n", escape_essid(priv->essid,
4534 priv->essid_len),
4535 MAC_ARG(priv->bssid));
4536 memcpy(&priv->last_link_deterioration, x,
4537 sizeof(*x));
4538 } else {
4539 IPW_ERROR("Link Deterioration of wrong size %d "
4540 "(should be %zd)\n",
4541 notif->size, sizeof(*x));
4542 }
4543 break;
4544 }
4545
4546 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4547 IPW_ERROR("Dino config\n");
4548 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004549 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004550 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 break;
4553 }
4554
4555 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4556 struct notif_beacon_state *x = &notif->u.beacon_state;
4557 if (notif->size != sizeof(*x)) {
4558 IPW_ERROR
4559 ("Beacon state of wrong size %d (should "
4560 "be %zd)\n", notif->size, sizeof(*x));
4561 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004562 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004563
James Ketrenosa613bff2005-08-24 21:43:11 -05004564 if (le32_to_cpu(x->state) ==
4565 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4566 ipw_handle_missed_beacon(priv,
4567 le32_to_cpu(x->
4568 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004569
James Ketrenos43f66a62005-03-25 12:31:53 -06004570 break;
4571 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004572
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004573 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4574 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4575 if (notif->size == sizeof(*x)) {
4576 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4577 "0x%02x station %d\n",
4578 x->key_state, x->security_type,
4579 x->station_index);
4580 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004581 }
4582
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004583 IPW_ERROR
4584 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4585 notif->size, sizeof(*x));
4586 break;
4587 }
4588
4589 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4590 struct notif_calibration *x = &notif->u.calibration;
4591
4592 if (notif->size == sizeof(*x)) {
4593 memcpy(&priv->calib, x, sizeof(*x));
4594 IPW_DEBUG_INFO("TODO: Calibration\n");
4595 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004596 }
4597
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004598 IPW_ERROR
4599 ("Calibration of wrong size %d (should be %zd)\n",
4600 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004601 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004602 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004603
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004604 case HOST_NOTIFICATION_NOISE_STATS:{
4605 if (notif->size == sizeof(u32)) {
4606 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004607 (u8) (le32_to_cpu(notif->u.noise.value) &
4608 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004609 average_add(&priv->average_noise,
4610 priv->last_noise);
4611 break;
4612 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004613
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614 IPW_ERROR
4615 ("Noise stat is wrong size %d (should be %zd)\n",
4616 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004617 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004618 }
4619
James Ketrenos43f66a62005-03-25 12:31:53 -06004620 default:
4621 IPW_ERROR("Unknown notification: "
4622 "subtype=%d,flags=0x%2x,size=%d\n",
4623 notif->subtype, notif->flags, notif->size);
4624 }
4625}
4626
4627/**
4628 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004629 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004630 * @param priv
4631 * @return error code
4632 */
4633static int ipw_queue_reset(struct ipw_priv *priv)
4634{
4635 int rc = 0;
4636 /** @todo customize queue sizes */
4637 int nTx = 64, nTxCmd = 8;
4638 ipw_tx_queue_free(priv);
4639 /* Tx CMD queue */
4640 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004641 IPW_TX_CMD_QUEUE_READ_INDEX,
4642 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4643 IPW_TX_CMD_QUEUE_BD_BASE,
4644 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004645 if (rc) {
4646 IPW_ERROR("Tx Cmd queue init failed\n");
4647 goto error;
4648 }
4649 /* Tx queue(s) */
4650 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004651 IPW_TX_QUEUE_0_READ_INDEX,
4652 IPW_TX_QUEUE_0_WRITE_INDEX,
4653 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004654 if (rc) {
4655 IPW_ERROR("Tx 0 queue init failed\n");
4656 goto error;
4657 }
4658 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004659 IPW_TX_QUEUE_1_READ_INDEX,
4660 IPW_TX_QUEUE_1_WRITE_INDEX,
4661 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004662 if (rc) {
4663 IPW_ERROR("Tx 1 queue init failed\n");
4664 goto error;
4665 }
4666 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004667 IPW_TX_QUEUE_2_READ_INDEX,
4668 IPW_TX_QUEUE_2_WRITE_INDEX,
4669 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004670 if (rc) {
4671 IPW_ERROR("Tx 2 queue init failed\n");
4672 goto error;
4673 }
4674 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004675 IPW_TX_QUEUE_3_READ_INDEX,
4676 IPW_TX_QUEUE_3_WRITE_INDEX,
4677 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004678 if (rc) {
4679 IPW_ERROR("Tx 3 queue init failed\n");
4680 goto error;
4681 }
4682 /* statistics */
4683 priv->rx_bufs_min = 0;
4684 priv->rx_pend_max = 0;
4685 return rc;
4686
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004687 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004688 ipw_tx_queue_free(priv);
4689 return rc;
4690}
4691
4692/**
4693 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004694 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004695 * When FW adwances 'R' index, all entries between old and
4696 * new 'R' index need to be reclaimed. As result, some free space
4697 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004698 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004699 * @note Need to protect against garbage in 'R' index
4700 * @param priv
4701 * @param txq
4702 * @param qindex
4703 * @return Number of used entries remains in the queue
4704 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004705static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004706 struct clx2_tx_queue *txq, int qindex)
4707{
4708 u32 hw_tail;
4709 int used;
4710 struct clx2_queue *q = &txq->q;
4711
4712 hw_tail = ipw_read32(priv, q->reg_r);
4713 if (hw_tail >= q->n_bd) {
4714 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004715 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4716 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 goto done;
4718 }
4719 for (; q->last_used != hw_tail;
4720 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4721 ipw_queue_tx_free_tfd(priv, txq);
4722 priv->tx_packets++;
4723 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004724 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004725 if ((ipw_queue_space(q) > q->low_mark) &&
4726 (qindex >= 0) &&
4727 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4728 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004729 used = q->first_empty - q->last_used;
4730 if (used < 0)
4731 used += q->n_bd;
4732
4733 return used;
4734}
4735
4736static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4737 int len, int sync)
4738{
4739 struct clx2_tx_queue *txq = &priv->txq_cmd;
4740 struct clx2_queue *q = &txq->q;
4741 struct tfd_frame *tfd;
4742
4743 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4744 IPW_ERROR("No space for Tx\n");
4745 return -EBUSY;
4746 }
4747
4748 tfd = &txq->bd[q->first_empty];
4749 txq->txb[q->first_empty] = NULL;
4750
4751 memset(tfd, 0, sizeof(*tfd));
4752 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4753 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4754 priv->hcmd_seq++;
4755 tfd->u.cmd.index = hcmd;
4756 tfd->u.cmd.length = len;
4757 memcpy(tfd->u.cmd.payload, buf, len);
4758 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4759 ipw_write32(priv, q->reg_w, q->first_empty);
4760 _ipw_read32(priv, 0x90);
4761
4762 return 0;
4763}
4764
Jeff Garzikbf794512005-07-31 13:07:26 -04004765/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004766 * Rx theory of operation
4767 *
4768 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004769 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004770 * 0 to 31
4771 *
4772 * Rx Queue Indexes
4773 * The host/firmware share two index registers for managing the Rx buffers.
4774 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004775 * The READ index maps to the first position that the firmware may be writing
4776 * to -- the driver can read up to (but not including) this position and get
4777 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004778 * The READ index is managed by the firmware once the card is enabled.
4779 *
4780 * The WRITE index maps to the last position the driver has read from -- the
4781 * position preceding WRITE is the last slot the firmware can place a packet.
4782 *
4783 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004784 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004785 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004786 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004787 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4788 *
4789 * When the firmware places a packet in a buffer it will advance the READ index
4790 * and fire the RX interrupt. The driver can then query the READ index and
4791 * process as many packets as possible, moving the WRITE index forward as it
4792 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004793 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004794 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004795 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004796 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004797 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004798 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4799 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4800 * 'processed' and 'read' driver indexes as well)
4801 * + A received packet is processed and handed to the kernel network stack,
4802 * detached from the ipw->rxq. The driver 'processed' index is updated.
4803 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004804 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4805 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004806 * were enough free buffers and RX_STALLED is set it is cleared.
4807 *
4808 *
4809 * Driver sequence:
4810 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004811 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004812 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4813 * ipw_rx_queue_restock
4814 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4815 * queue, updates firmware pointers, and updates
4816 * the WRITE index. If insufficient rx_free buffers
4817 * are available, schedules ipw_rx_queue_replenish
4818 *
4819 * -- enable interrupts --
4820 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004821 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004822 * Moves the packet buffer from queue to rx_used.
4823 * Calls ipw_rx_queue_restock to refill any empty
4824 * slots.
4825 * ...
4826 *
4827 */
4828
Jeff Garzikbf794512005-07-31 13:07:26 -04004829/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004830 * If there are slots in the RX queue that need to be restocked,
4831 * and we have free pre-allocated buffers, fill the ranks as much
4832 * as we can pulling from rx_free.
4833 *
4834 * This moves the 'write' index forward to catch up with 'processed', and
4835 * also updates the memory address in the firmware to reference the new
4836 * target buffer.
4837 */
4838static void ipw_rx_queue_restock(struct ipw_priv *priv)
4839{
4840 struct ipw_rx_queue *rxq = priv->rxq;
4841 struct list_head *element;
4842 struct ipw_rx_mem_buffer *rxb;
4843 unsigned long flags;
4844 int write;
4845
4846 spin_lock_irqsave(&rxq->lock, flags);
4847 write = rxq->write;
4848 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4849 element = rxq->rx_free.next;
4850 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4851 list_del(element);
4852
James Ketrenosb095c382005-08-24 22:04:42 -05004853 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004854 rxb->dma_addr);
4855 rxq->queue[rxq->write] = rxb;
4856 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4857 rxq->free_count--;
4858 }
4859 spin_unlock_irqrestore(&rxq->lock, flags);
4860
Jeff Garzikbf794512005-07-31 13:07:26 -04004861 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004862 * refill it */
4863 if (rxq->free_count <= RX_LOW_WATERMARK)
4864 queue_work(priv->workqueue, &priv->rx_replenish);
4865
4866 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004867 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004868 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004869}
4870
4871/*
4872 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004873 * Also restock the Rx queue via ipw_rx_queue_restock.
4874 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004875 * This is called as a scheduled work item (except for during intialization)
4876 */
4877static void ipw_rx_queue_replenish(void *data)
4878{
4879 struct ipw_priv *priv = data;
4880 struct ipw_rx_queue *rxq = priv->rxq;
4881 struct list_head *element;
4882 struct ipw_rx_mem_buffer *rxb;
4883 unsigned long flags;
4884
4885 spin_lock_irqsave(&rxq->lock, flags);
4886 while (!list_empty(&rxq->rx_used)) {
4887 element = rxq->rx_used.next;
4888 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004889 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004890 if (!rxb->skb) {
4891 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4892 priv->net_dev->name);
4893 /* We don't reschedule replenish work here -- we will
4894 * call the restock method and if it still needs
4895 * more buffers it will schedule replenish */
4896 break;
4897 }
4898 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004899
James Ketrenos43f66a62005-03-25 12:31:53 -06004900 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004901 rxb->dma_addr =
4902 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004903 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004904
James Ketrenos43f66a62005-03-25 12:31:53 -06004905 list_add_tail(&rxb->list, &rxq->rx_free);
4906 rxq->free_count++;
4907 }
4908 spin_unlock_irqrestore(&rxq->lock, flags);
4909
4910 ipw_rx_queue_restock(priv);
4911}
4912
James Ketrenosc848d0a2005-08-24 21:56:24 -05004913static void ipw_bg_rx_queue_replenish(void *data)
4914{
4915 struct ipw_priv *priv = data;
4916 down(&priv->sem);
4917 ipw_rx_queue_replenish(data);
4918 up(&priv->sem);
4919}
4920
James Ketrenos43f66a62005-03-25 12:31:53 -06004921/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4922 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004923 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004924 * non NULL it is unmapped and freed
4925 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004926static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004927{
4928 int i;
4929
4930 if (!rxq)
4931 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004932
James Ketrenos43f66a62005-03-25 12:31:53 -06004933 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4934 if (rxq->pool[i].skb != NULL) {
4935 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004936 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004937 dev_kfree_skb(rxq->pool[i].skb);
4938 }
4939 }
4940
4941 kfree(rxq);
4942}
4943
4944static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4945{
4946 struct ipw_rx_queue *rxq;
4947 int i;
4948
Takisc75f4742005-12-01 01:41:45 -08004949 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004950 if (unlikely(!rxq)) {
4951 IPW_ERROR("memory allocation failed\n");
4952 return NULL;
4953 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004954 spin_lock_init(&rxq->lock);
4955 INIT_LIST_HEAD(&rxq->rx_free);
4956 INIT_LIST_HEAD(&rxq->rx_used);
4957
4958 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004959 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004960 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4961
4962 /* Set us so that we have processed and used all buffers, but have
4963 * not restocked the Rx queue with fresh buffers */
4964 rxq->read = rxq->write = 0;
4965 rxq->processed = RX_QUEUE_SIZE - 1;
4966 rxq->free_count = 0;
4967
4968 return rxq;
4969}
4970
4971static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4972{
4973 rate &= ~IEEE80211_BASIC_RATE_MASK;
4974 if (ieee_mode == IEEE_A) {
4975 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004976 case IEEE80211_OFDM_RATE_6MB:
4977 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004978 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004979 case IEEE80211_OFDM_RATE_9MB:
4980 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004981 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004982 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004983 return priv->
4984 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004985 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004986 return priv->
4987 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004988 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004989 return priv->
4990 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004991 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004992 return priv->
4993 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004994 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004995 return priv->
4996 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004997 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004998 return priv->
4999 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005000 default:
5001 return 0;
5002 }
5003 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005004
James Ketrenos43f66a62005-03-25 12:31:53 -06005005 /* B and G mixed */
5006 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005007 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005008 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005009 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005010 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005011 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005012 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005013 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005014 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5015 }
5016
5017 /* If we are limited to B modulations, bail at this point */
5018 if (ieee_mode == IEEE_B)
5019 return 0;
5020
5021 /* G */
5022 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005025 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005026 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005027 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005029 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005030 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005031 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005032 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005033 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005034 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005035 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005036 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005037 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005038 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5039 }
5040
5041 return 0;
5042}
5043
Jeff Garzikbf794512005-07-31 13:07:26 -04005044static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005045 const struct ieee80211_network *network,
5046 struct ipw_supported_rates *rates)
5047{
5048 int num_rates, i;
5049
5050 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005051 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005052 rates->num_rates = 0;
5053 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005054 if (!ipw_is_rate_in_mask(priv, network->mode,
5055 network->rates[i])) {
5056
James Ketrenosea2b26e2005-08-24 21:25:16 -05005057 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005058 IPW_DEBUG_SCAN("Adding masked mandatory "
5059 "rate %02X\n",
5060 network->rates[i]);
5061 rates->supported_rates[rates->num_rates++] =
5062 network->rates[i];
5063 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005064 }
5065
James Ketrenos43f66a62005-03-25 12:31:53 -06005066 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5067 network->rates[i], priv->rates_mask);
5068 continue;
5069 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005070
James Ketrenos43f66a62005-03-25 12:31:53 -06005071 rates->supported_rates[rates->num_rates++] = network->rates[i];
5072 }
5073
James Ketrenosa613bff2005-08-24 21:43:11 -05005074 num_rates = min(network->rates_ex_len,
5075 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005076 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005077 if (!ipw_is_rate_in_mask(priv, network->mode,
5078 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005079 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005080 IPW_DEBUG_SCAN("Adding masked mandatory "
5081 "rate %02X\n",
5082 network->rates_ex[i]);
5083 rates->supported_rates[rates->num_rates++] =
5084 network->rates[i];
5085 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005086 }
5087
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5089 network->rates_ex[i], priv->rates_mask);
5090 continue;
5091 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005092
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005093 rates->supported_rates[rates->num_rates++] =
5094 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 }
5096
James Ketrenosea2b26e2005-08-24 21:25:16 -05005097 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005098}
5099
Arjan van de Ven858119e2006-01-14 13:20:43 -08005100static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005101 const struct ipw_supported_rates *src)
5102{
5103 u8 i;
5104 for (i = 0; i < src->num_rates; i++)
5105 dest->supported_rates[i] = src->supported_rates[i];
5106 dest->num_rates = src->num_rates;
5107}
5108
5109/* TODO: Look at sniffed packets in the air to determine if the basic rate
5110 * mask should ever be used -- right now all callers to add the scan rates are
5111 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5112static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005113 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005114{
Jeff Garzikbf794512005-07-31 13:07:26 -04005115 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005116 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005117
James Ketrenos43f66a62005-03-25 12:31:53 -06005118 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005119 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005120 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005121
5122 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005123 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005124 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005125
5126 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005127 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005128 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005129
5130 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005131 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005132 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005133}
5134
5135static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005136 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005137{
Jeff Garzikbf794512005-07-31 13:07:26 -04005138 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005139 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005140
5141 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005142 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005143 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005144
5145 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005146 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005147 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005148
5149 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005150 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005151 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005152
5153 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005154 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005155 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005156
5157 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005158 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005159 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005160
5161 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005162 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005163 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005164
5165 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005166 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005167 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005168
5169 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005170 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005171 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005172}
5173
5174struct ipw_network_match {
5175 struct ieee80211_network *network;
5176 struct ipw_supported_rates rates;
5177};
5178
James Ketrenosc848d0a2005-08-24 21:56:24 -05005179static int ipw_find_adhoc_network(struct ipw_priv *priv,
5180 struct ipw_network_match *match,
5181 struct ieee80211_network *network,
5182 int roaming)
5183{
5184 struct ipw_supported_rates rates;
5185
5186 /* Verify that this network's capability is compatible with the
5187 * current mode (AdHoc or Infrastructure) */
5188 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5189 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5190 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5191 "capability mismatch.\n",
5192 escape_essid(network->ssid, network->ssid_len),
5193 MAC_ARG(network->bssid));
5194 return 0;
5195 }
5196
5197 /* If we do not have an ESSID for this AP, we can not associate with
5198 * it */
5199 if (network->flags & NETWORK_EMPTY_ESSID) {
5200 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5201 "because of hidden ESSID.\n",
5202 escape_essid(network->ssid, network->ssid_len),
5203 MAC_ARG(network->bssid));
5204 return 0;
5205 }
5206
5207 if (unlikely(roaming)) {
5208 /* If we are roaming, then ensure check if this is a valid
5209 * network to try and roam to */
5210 if ((network->ssid_len != match->network->ssid_len) ||
5211 memcmp(network->ssid, match->network->ssid,
5212 network->ssid_len)) {
5213 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5214 "because of non-network ESSID.\n",
5215 escape_essid(network->ssid,
5216 network->ssid_len),
5217 MAC_ARG(network->bssid));
5218 return 0;
5219 }
5220 } else {
5221 /* If an ESSID has been configured then compare the broadcast
5222 * ESSID to ours */
5223 if ((priv->config & CFG_STATIC_ESSID) &&
5224 ((network->ssid_len != priv->essid_len) ||
5225 memcmp(network->ssid, priv->essid,
5226 min(network->ssid_len, priv->essid_len)))) {
5227 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005228
James Ketrenosc848d0a2005-08-24 21:56:24 -05005229 strncpy(escaped,
5230 escape_essid(network->ssid, network->ssid_len),
5231 sizeof(escaped));
5232 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5233 "because of ESSID mismatch: '%s'.\n",
5234 escaped, MAC_ARG(network->bssid),
5235 escape_essid(priv->essid,
5236 priv->essid_len));
5237 return 0;
5238 }
5239 }
5240
5241 /* If the old network rate is better than this one, don't bother
5242 * testing everything else. */
5243
5244 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005245 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5246 "current network.\n",
5247 escape_essid(match->network->ssid,
5248 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005249 return 0;
5250 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005251 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5252 "current network.\n",
5253 escape_essid(match->network->ssid,
5254 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005255 return 0;
5256 }
5257
5258 /* Now go through and see if the requested network is valid... */
5259 if (priv->ieee->scan_age != 0 &&
5260 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5261 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5262 "because of age: %lums.\n",
5263 escape_essid(network->ssid, network->ssid_len),
5264 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005265 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005266 return 0;
5267 }
5268
5269 if ((priv->config & CFG_STATIC_CHANNEL) &&
5270 (network->channel != priv->channel)) {
5271 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5272 "because of channel mismatch: %d != %d.\n",
5273 escape_essid(network->ssid, network->ssid_len),
5274 MAC_ARG(network->bssid),
5275 network->channel, priv->channel);
5276 return 0;
5277 }
5278
5279 /* Verify privacy compatability */
5280 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5281 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5282 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5283 "because of privacy mismatch: %s != %s.\n",
5284 escape_essid(network->ssid, network->ssid_len),
5285 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005286 priv->
5287 capability & CAP_PRIVACY_ON ? "on" : "off",
5288 network->
5289 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5290 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005291 return 0;
5292 }
5293
5294 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5295 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5296 "because of the same BSSID match: " MAC_FMT
5297 ".\n", escape_essid(network->ssid,
5298 network->ssid_len),
5299 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5300 return 0;
5301 }
5302
5303 /* Filter out any incompatible freq / mode combinations */
5304 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5305 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5306 "because of invalid frequency/mode "
5307 "combination.\n",
5308 escape_essid(network->ssid, network->ssid_len),
5309 MAC_ARG(network->bssid));
5310 return 0;
5311 }
5312
5313 /* Ensure that the rates supported by the driver are compatible with
5314 * this AP, including verification of basic rates (mandatory) */
5315 if (!ipw_compatible_rates(priv, network, &rates)) {
5316 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5317 "because configured rate mask excludes "
5318 "AP mandatory rate.\n",
5319 escape_essid(network->ssid, network->ssid_len),
5320 MAC_ARG(network->bssid));
5321 return 0;
5322 }
5323
5324 if (rates.num_rates == 0) {
5325 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5326 "because of no compatible rates.\n",
5327 escape_essid(network->ssid, network->ssid_len),
5328 MAC_ARG(network->bssid));
5329 return 0;
5330 }
5331
5332 /* TODO: Perform any further minimal comparititive tests. We do not
5333 * want to put too much policy logic here; intelligent scan selection
5334 * should occur within a generic IEEE 802.11 user space tool. */
5335
5336 /* Set up 'new' AP to this network */
5337 ipw_copy_rates(&match->rates, &rates);
5338 match->network = network;
5339 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5340 escape_essid(network->ssid, network->ssid_len),
5341 MAC_ARG(network->bssid));
5342
5343 return 1;
5344}
5345
5346static void ipw_merge_adhoc_network(void *data)
5347{
5348 struct ipw_priv *priv = data;
5349 struct ieee80211_network *network = NULL;
5350 struct ipw_network_match match = {
5351 .network = priv->assoc_network
5352 };
5353
James Ketrenosafbf30a2005-08-25 00:05:33 -05005354 if ((priv->status & STATUS_ASSOCIATED) &&
5355 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005356 /* First pass through ROAM process -- look for a better
5357 * network */
5358 unsigned long flags;
5359
5360 spin_lock_irqsave(&priv->ieee->lock, flags);
5361 list_for_each_entry(network, &priv->ieee->network_list, list) {
5362 if (network != priv->assoc_network)
5363 ipw_find_adhoc_network(priv, &match, network,
5364 1);
5365 }
5366 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5367
5368 if (match.network == priv->assoc_network) {
5369 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5370 "merge to.\n");
5371 return;
5372 }
5373
5374 down(&priv->sem);
5375 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5376 IPW_DEBUG_MERGE("remove network %s\n",
5377 escape_essid(priv->essid,
5378 priv->essid_len));
5379 ipw_remove_current_network(priv);
5380 }
5381
5382 ipw_disassociate(priv);
5383 priv->assoc_network = match.network;
5384 up(&priv->sem);
5385 return;
5386 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005387}
5388
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005389static int ipw_best_network(struct ipw_priv *priv,
5390 struct ipw_network_match *match,
5391 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005392{
5393 struct ipw_supported_rates rates;
5394
5395 /* Verify that this network's capability is compatible with the
5396 * current mode (AdHoc or Infrastructure) */
5397 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005398 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005399 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5400 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5401 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005402 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005403 escape_essid(network->ssid, network->ssid_len),
5404 MAC_ARG(network->bssid));
5405 return 0;
5406 }
5407
5408 /* If we do not have an ESSID for this AP, we can not associate with
5409 * it */
5410 if (network->flags & NETWORK_EMPTY_ESSID) {
5411 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5412 "because of hidden ESSID.\n",
5413 escape_essid(network->ssid, network->ssid_len),
5414 MAC_ARG(network->bssid));
5415 return 0;
5416 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005417
James Ketrenos43f66a62005-03-25 12:31:53 -06005418 if (unlikely(roaming)) {
5419 /* If we are roaming, then ensure check if this is a valid
5420 * network to try and roam to */
5421 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005422 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005423 network->ssid_len)) {
5424 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5425 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005426 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005427 network->ssid_len),
5428 MAC_ARG(network->bssid));
5429 return 0;
5430 }
5431 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005432 /* If an ESSID has been configured then compare the broadcast
5433 * ESSID to ours */
5434 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005435 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005436 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005437 min(network->ssid_len, priv->essid_len)))) {
5438 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005439 strncpy(escaped,
5440 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005441 sizeof(escaped));
5442 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005443 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005444 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005445 escape_essid(priv->essid,
5446 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005447 return 0;
5448 }
5449 }
5450
5451 /* If the old network rate is better than this one, don't bother
5452 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005453 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005454 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005455 strncpy(escaped,
5456 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005457 sizeof(escaped));
5458 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5459 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5460 escaped, MAC_ARG(network->bssid),
5461 escape_essid(match->network->ssid,
5462 match->network->ssid_len),
5463 MAC_ARG(match->network->bssid));
5464 return 0;
5465 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005466
James Ketrenos43f66a62005-03-25 12:31:53 -06005467 /* If this network has already had an association attempt within the
5468 * last 3 seconds, do not try and associate again... */
5469 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005470 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005471 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
James Ketrenosafbf30a2005-08-25 00:05:33 -05005472 "because of storming (%lus since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005473 "assoc attempt).\n",
5474 escape_essid(network->ssid, network->ssid_len),
5475 MAC_ARG(network->bssid),
5476 (jiffies - network->last_associate) / HZ);
5477 return 0;
5478 }
5479
5480 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005481 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005482 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005483 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5484 "because of age: %lums.\n",
5485 escape_essid(network->ssid, network->ssid_len),
5486 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005487 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06005488 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005489 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005490
Jeff Garzikbf794512005-07-31 13:07:26 -04005491 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005492 (network->channel != priv->channel)) {
5493 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5494 "because of channel mismatch: %d != %d.\n",
5495 escape_essid(network->ssid, network->ssid_len),
5496 MAC_ARG(network->bssid),
5497 network->channel, priv->channel);
5498 return 0;
5499 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005500
James Ketrenos43f66a62005-03-25 12:31:53 -06005501 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005502 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005503 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5504 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5505 "because of privacy mismatch: %s != %s.\n",
5506 escape_essid(network->ssid, network->ssid_len),
5507 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005508 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005509 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005510 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005511 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005512 return 0;
5513 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005514
Hong Liucdd1fa12005-08-31 18:14:27 +08005515 if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
5516 network->rsn_ie_len > 0)) {
5517 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5518 "because of WPA capability mismatch.\n",
5519 escape_essid(network->ssid, network->ssid_len),
5520 MAC_ARG(network->bssid));
5521 return 0;
5522 }
5523
Jeff Garzikbf794512005-07-31 13:07:26 -04005524 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005525 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5526 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5527 "because of BSSID mismatch: " MAC_FMT ".\n",
5528 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005529 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 return 0;
5531 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005532
James Ketrenos43f66a62005-03-25 12:31:53 -06005533 /* Filter out any incompatible freq / mode combinations */
5534 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5535 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5536 "because of invalid frequency/mode "
5537 "combination.\n",
5538 escape_essid(network->ssid, network->ssid_len),
5539 MAC_ARG(network->bssid));
5540 return 0;
5541 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005542
Liu Hong1fe0adb2005-08-19 09:33:10 -05005543 /* Filter out invalid channel in current GEO */
5544 if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5545 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5546 "because of invalid channel in current GEO\n",
5547 escape_essid(network->ssid, network->ssid_len),
5548 MAC_ARG(network->bssid));
5549 return 0;
5550 }
5551
James Ketrenosea2b26e2005-08-24 21:25:16 -05005552 /* Ensure that the rates supported by the driver are compatible with
5553 * this AP, including verification of basic rates (mandatory) */
5554 if (!ipw_compatible_rates(priv, network, &rates)) {
5555 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5556 "because configured rate mask excludes "
5557 "AP mandatory rate.\n",
5558 escape_essid(network->ssid, network->ssid_len),
5559 MAC_ARG(network->bssid));
5560 return 0;
5561 }
5562
James Ketrenos43f66a62005-03-25 12:31:53 -06005563 if (rates.num_rates == 0) {
5564 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5565 "because of no compatible rates.\n",
5566 escape_essid(network->ssid, network->ssid_len),
5567 MAC_ARG(network->bssid));
5568 return 0;
5569 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005570
James Ketrenos43f66a62005-03-25 12:31:53 -06005571 /* TODO: Perform any further minimal comparititive tests. We do not
5572 * want to put too much policy logic here; intelligent scan selection
5573 * should occur within a generic IEEE 802.11 user space tool. */
5574
5575 /* Set up 'new' AP to this network */
5576 ipw_copy_rates(&match->rates, &rates);
5577 match->network = network;
5578
5579 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5580 escape_essid(network->ssid, network->ssid_len),
5581 MAC_ARG(network->bssid));
5582
5583 return 1;
5584}
5585
Jeff Garzikbf794512005-07-31 13:07:26 -04005586static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005587 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005588{
Liu Hong1fe0adb2005-08-19 09:33:10 -05005589 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005590 int i;
5591
James Ketrenos43f66a62005-03-25 12:31:53 -06005592 /*
5593 * For the purposes of scanning, we can set our wireless mode
5594 * to trigger scans across combinations of bands, but when it
5595 * comes to creating a new ad-hoc network, we have tell the FW
5596 * exactly which band to use.
5597 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005598 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005599 * chossen band. Attempting to create a new ad-hoc network
5600 * with an invalid channel for wireless mode will trigger a
5601 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005602 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005603 */
Liu Hong1fe0adb2005-08-19 09:33:10 -05005604 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005605 case IEEE80211_52GHZ_BAND:
5606 network->mode = IEEE_A;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005607 i = ipw_channel_to_index(priv->ieee, priv->channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005608 if (i == -1)
5609 BUG();
5610 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5611 IPW_WARNING("Overriding invalid channel\n");
5612 priv->channel = geo->a[0].channel;
5613 }
5614 break;
5615
5616 case IEEE80211_24GHZ_BAND:
5617 if (priv->ieee->mode & IEEE_G)
5618 network->mode = IEEE_G;
5619 else
5620 network->mode = IEEE_B;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005621 i = ipw_channel_to_index(priv->ieee, priv->channel);
5622 if (i == -1)
5623 BUG();
5624 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5625 IPW_WARNING("Overriding invalid channel\n");
5626 priv->channel = geo->bg[0].channel;
5627 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005628 break;
5629
5630 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005631 IPW_WARNING("Overriding invalid channel\n");
5632 if (priv->ieee->mode & IEEE_A) {
5633 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005634 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005635 } else if (priv->ieee->mode & IEEE_G) {
5636 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005637 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005638 } else {
5639 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005640 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005641 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005642 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005643 }
5644
5645 network->channel = priv->channel;
5646 priv->config |= CFG_ADHOC_PERSIST;
5647 ipw_create_bssid(priv, network->bssid);
5648 network->ssid_len = priv->essid_len;
5649 memcpy(network->ssid, priv->essid, priv->essid_len);
5650 memset(&network->stats, 0, sizeof(network->stats));
5651 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005652 if (!(priv->config & CFG_PREAMBLE_LONG))
5653 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005654 if (priv->capability & CAP_PRIVACY_ON)
5655 network->capability |= WLAN_CAPABILITY_PRIVACY;
5656 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005657 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005658 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005659 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005660 &priv->rates.supported_rates[network->rates_len],
5661 network->rates_ex_len);
5662 network->last_scanned = 0;
5663 network->flags = 0;
5664 network->last_associate = 0;
5665 network->time_stamp[0] = 0;
5666 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005667 network->beacon_interval = 100; /* Default */
5668 network->listen_interval = 10; /* Default */
5669 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005670 network->wpa_ie_len = 0;
5671 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005672}
5673
James Ketrenosb095c382005-08-24 22:04:42 -05005674static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5675{
5676 struct ipw_tgi_tx_key *key;
5677 struct host_cmd cmd = {
5678 .cmd = IPW_CMD_TGI_TX_KEY,
5679 .len = sizeof(*key)
5680 };
5681
5682 if (!(priv->ieee->sec.flags & (1 << index)))
5683 return;
5684
5685 key = (struct ipw_tgi_tx_key *)&cmd.param;
5686 key->key_id = index;
5687 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5688 key->security_type = type;
5689 key->station_index = 0; /* always 0 for BSS */
5690 key->flags = 0;
5691 /* 0 for new key; previous value of counter (after fatal error) */
5692 key->tx_counter[0] = 0;
5693 key->tx_counter[1] = 0;
5694
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005695 ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05005696}
5697
5698static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005699{
5700 struct ipw_wep_key *key;
5701 int i;
5702 struct host_cmd cmd = {
5703 .cmd = IPW_CMD_WEP_KEY,
5704 .len = sizeof(*key)
5705 };
5706
5707 key = (struct ipw_wep_key *)&cmd.param;
5708 key->cmd_id = DINO_CMD_WEP_KEY;
5709 key->seq_num = 0;
5710
James Ketrenosb095c382005-08-24 22:04:42 -05005711 /* Note: AES keys cannot be set for multiple times.
5712 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005713 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005714 key->key_index = i | type;
5715 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005716 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005717 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005718 }
5719
James Ketrenosb095c382005-08-24 22:04:42 -05005720 key->key_size = priv->ieee->sec.key_sizes[i];
5721 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5722
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005723 ipw_send_cmd(priv, &cmd);
Jeff Garzikbf794512005-07-31 13:07:26 -04005724 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005725}
5726
Zhu Yi1fbfea52005-08-05 17:22:56 +08005727static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5728{
5729 if (priv->ieee->host_encrypt)
5730 return;
5731
5732 switch (level) {
5733 case SEC_LEVEL_3:
5734 priv->sys_config.disable_unicast_decryption = 0;
5735 priv->ieee->host_decrypt = 0;
5736 break;
5737 case SEC_LEVEL_2:
5738 priv->sys_config.disable_unicast_decryption = 1;
5739 priv->ieee->host_decrypt = 1;
5740 break;
5741 case SEC_LEVEL_1:
5742 priv->sys_config.disable_unicast_decryption = 0;
5743 priv->ieee->host_decrypt = 0;
5744 break;
5745 case SEC_LEVEL_0:
5746 priv->sys_config.disable_unicast_decryption = 1;
5747 break;
5748 default:
5749 break;
5750 }
5751}
5752
5753static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5754{
5755 if (priv->ieee->host_encrypt)
5756 return;
5757
5758 switch (level) {
5759 case SEC_LEVEL_3:
5760 priv->sys_config.disable_multicast_decryption = 0;
5761 break;
5762 case SEC_LEVEL_2:
5763 priv->sys_config.disable_multicast_decryption = 1;
5764 break;
5765 case SEC_LEVEL_1:
5766 priv->sys_config.disable_multicast_decryption = 0;
5767 break;
5768 case SEC_LEVEL_0:
5769 priv->sys_config.disable_multicast_decryption = 1;
5770 break;
5771 default:
5772 break;
5773 }
5774}
5775
James Ketrenosb095c382005-08-24 22:04:42 -05005776static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5777{
5778 switch (priv->ieee->sec.level) {
5779 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005780 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5781 ipw_send_tgi_tx_key(priv,
5782 DCT_FLAG_EXT_SECURITY_CCM,
5783 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005784
Hong Liu567deaf2005-08-31 18:07:22 +08005785 if (!priv->ieee->host_mc_decrypt)
5786 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005787 break;
5788 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005789 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5790 ipw_send_tgi_tx_key(priv,
5791 DCT_FLAG_EXT_SECURITY_TKIP,
5792 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005793 break;
5794 case SEC_LEVEL_1:
5795 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005796 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5797 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005798 break;
5799 case SEC_LEVEL_0:
5800 default:
5801 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005802 }
5803}
5804
5805static void ipw_adhoc_check(void *data)
5806{
5807 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005808
James Ketrenosafbf30a2005-08-25 00:05:33 -05005809 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005810 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005811 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5812 IPW_DL_STATE | IPW_DL_ASSOC,
5813 "Missed beacon: %d - disassociate\n",
5814 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 ipw_remove_current_network(priv);
5816 ipw_disassociate(priv);
5817 return;
5818 }
5819
Jeff Garzikbf794512005-07-31 13:07:26 -04005820 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 priv->assoc_request.beacon_interval);
5822}
5823
James Ketrenosc848d0a2005-08-24 21:56:24 -05005824static void ipw_bg_adhoc_check(void *data)
5825{
5826 struct ipw_priv *priv = data;
5827 down(&priv->sem);
5828 ipw_adhoc_check(data);
5829 up(&priv->sem);
5830}
5831
Brice Goglin0f52bf92005-12-01 01:41:46 -08005832#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005833static void ipw_debug_config(struct ipw_priv *priv)
5834{
5835 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5836 "[CFG 0x%08X]\n", priv->config);
5837 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005838 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005839 else
5840 IPW_DEBUG_INFO("Channel unlocked.\n");
5841 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005842 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005843 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 else
5845 IPW_DEBUG_INFO("ESSID unlocked.\n");
5846 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005847 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5848 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005849 else
5850 IPW_DEBUG_INFO("BSSID unlocked.\n");
5851 if (priv->capability & CAP_PRIVACY_ON)
5852 IPW_DEBUG_INFO("PRIVACY on\n");
5853 else
5854 IPW_DEBUG_INFO("PRIVACY off\n");
5855 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5856}
5857#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005858#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005859#endif
5860
Arjan van de Ven858119e2006-01-14 13:20:43 -08005861static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005862{
5863 /* TODO: Verify that this works... */
5864 struct ipw_fixed_rate fr = {
5865 .tx_rates = priv->rates_mask
5866 };
5867 u32 reg;
5868 u16 mask = 0;
5869
Jeff Garzikbf794512005-07-31 13:07:26 -04005870 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005871 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005872
James Ketrenos43f66a62005-03-25 12:31:53 -06005873 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005874 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005875 /* IEEE_A */
5876 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5877 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005878 IPW_DEBUG_WX
5879 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005880 fr.tx_rates = 0;
5881 break;
5882 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005883
James Ketrenos43f66a62005-03-25 12:31:53 -06005884 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5885 break;
5886
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005887 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005888 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005889 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005890 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5891 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005892 IPW_DEBUG_WX
5893 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005894 fr.tx_rates = 0;
5895 }
5896 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005897 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005898
5899 /* IEEE_G */
5900 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5901 IEEE80211_OFDM_RATES_MASK)) {
5902 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005903 IPW_DEBUG_WX
5904 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005905 fr.tx_rates = 0;
5906 break;
5907 }
5908
5909 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5910 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5911 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5912 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005913
James Ketrenos43f66a62005-03-25 12:31:53 -06005914 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5915 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5916 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5917 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005918
James Ketrenos43f66a62005-03-25 12:31:53 -06005919 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5920 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5921 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5922 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005923
James Ketrenos43f66a62005-03-25 12:31:53 -06005924 fr.tx_rates |= mask;
5925 break;
5926 }
5927
5928 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005929 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005930}
5931
James Ketrenosea2b26e2005-08-24 21:25:16 -05005932static void ipw_abort_scan(struct ipw_priv *priv)
5933{
5934 int err;
5935
5936 if (priv->status & STATUS_SCAN_ABORTING) {
5937 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5938 return;
5939 }
5940 priv->status |= STATUS_SCAN_ABORTING;
5941
5942 err = ipw_send_scan_abort(priv);
5943 if (err)
5944 IPW_DEBUG_HC("Request to abort scan failed.\n");
5945}
5946
James Ketrenosafbf30a2005-08-25 00:05:33 -05005947static void ipw_add_scan_channels(struct ipw_priv *priv,
5948 struct ipw_scan_request_ext *scan,
5949 int scan_type)
5950{
5951 int channel_index = 0;
5952 const struct ieee80211_geo *geo;
5953 int i;
5954
Liu Hong1fe0adb2005-08-19 09:33:10 -05005955 geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005956
5957 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5958 int start = channel_index;
5959 for (i = 0; i < geo->a_channels; i++) {
5960 if ((priv->status & STATUS_ASSOCIATED) &&
5961 geo->a[i].channel == priv->channel)
5962 continue;
5963 channel_index++;
5964 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005965 ipw_set_scan_type(scan, channel_index,
5966 geo->a[i].
5967 flags & IEEE80211_CH_PASSIVE_ONLY ?
5968 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5969 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005970 }
5971
5972 if (start != channel_index) {
5973 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5974 (channel_index - start);
5975 channel_index++;
5976 }
5977 }
5978
5979 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5980 int start = channel_index;
5981 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005982 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005983 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5984 /* nop out the list */
5985 [0] = 0
5986 };
5987
5988 u8 channel;
5989 while (channel_index < IPW_SCAN_CHANNELS) {
5990 channel =
5991 priv->speed_scan[priv->speed_scan_pos];
5992 if (channel == 0) {
5993 priv->speed_scan_pos = 0;
5994 channel = priv->speed_scan[0];
5995 }
5996 if ((priv->status & STATUS_ASSOCIATED) &&
5997 channel == priv->channel) {
5998 priv->speed_scan_pos++;
5999 continue;
6000 }
6001
6002 /* If this channel has already been
6003 * added in scan, break from loop
6004 * and this will be the first channel
6005 * in the next scan.
6006 */
6007 if (channels[channel - 1] != 0)
6008 break;
6009
6010 channels[channel - 1] = 1;
6011 priv->speed_scan_pos++;
6012 channel_index++;
6013 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006014 index =
6015 ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006016 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006017 geo->bg[index].
6018 flags &
6019 IEEE80211_CH_PASSIVE_ONLY ?
6020 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6021 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006022 }
6023 } else {
6024 for (i = 0; i < geo->bg_channels; i++) {
6025 if ((priv->status & STATUS_ASSOCIATED) &&
6026 geo->bg[i].channel == priv->channel)
6027 continue;
6028 channel_index++;
6029 scan->channels_list[channel_index] =
6030 geo->bg[i].channel;
6031 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006032 geo->bg[i].
6033 flags &
6034 IEEE80211_CH_PASSIVE_ONLY ?
6035 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6036 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006037 }
6038 }
6039
6040 if (start != channel_index) {
6041 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6042 (channel_index - start);
6043 }
6044 }
6045}
6046
James Ketrenosea2b26e2005-08-24 21:25:16 -05006047static int ipw_request_scan(struct ipw_priv *priv)
6048{
6049 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006050 int err = 0, scan_type;
6051
6052 if (!(priv->status & STATUS_INIT) ||
6053 (priv->status & STATUS_EXIT_PENDING))
6054 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006055
James Ketrenosb095c382005-08-24 22:04:42 -05006056 down(&priv->sem);
6057
James Ketrenosea2b26e2005-08-24 21:25:16 -05006058 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006059 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006060 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006061 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006062 }
6063
James Ketrenosafbf30a2005-08-25 00:05:33 -05006064 if (!(priv->status & STATUS_SCAN_FORCED) &&
6065 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006066 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6067 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006068 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006069 }
6070
6071 if (priv->status & STATUS_RF_KILL_MASK) {
6072 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6073 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006074 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006075 }
6076
6077 memset(&scan, 0, sizeof(scan));
6078
James Ketrenosb095c382005-08-24 22:04:42 -05006079 if (priv->config & CFG_SPEED_SCAN)
6080 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6081 cpu_to_le16(30);
6082 else
6083 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6084 cpu_to_le16(20);
6085
James Ketrenosa613bff2005-08-24 21:43:11 -05006086 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6087 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006088 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006089
James Ketrenosa613bff2005-08-24 21:43:11 -05006090 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006091
James Ketrenosb095c382005-08-24 22:04:42 -05006092#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006093 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006094 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006095 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006096
Liu Hong1fe0adb2005-08-19 09:33:10 -05006097 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006098 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006099 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006100 channel = priv->channel;
6101 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006102
James Ketrenosb095c382005-08-24 22:04:42 -05006103 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006104 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006105 channel = priv->channel;
6106 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006107
James Ketrenosb095c382005-08-24 22:04:42 -05006108 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006109 band = (u8) (IPW_B_MODE << 6) | 1;
6110 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006111 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006112 }
6113
James Ketrenosb095c382005-08-24 22:04:42 -05006114 scan.channels_list[0] = band;
6115 scan.channels_list[1] = channel;
6116 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006117
James Ketrenosb095c382005-08-24 22:04:42 -05006118 /* NOTE: The card will sit on this channel for this time
6119 * period. Scan aborts are timing sensitive and frequently
6120 * result in firmware restarts. As such, it is best to
6121 * set a small dwell_time here and just keep re-issuing
6122 * scans. Otherwise fast channel hopping will not actually
6123 * hop channels.
6124 *
6125 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006126 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6127 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006128 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006129#endif /* CONFIG_IPW2200_MONITOR */
6130 /* If we are roaming, then make this a directed scan for the
6131 * current network. Otherwise, ensure that every other scan
6132 * is a fast channel hop scan */
6133 if ((priv->status & STATUS_ROAMING)
6134 || (!(priv->status & STATUS_ASSOCIATED)
6135 && (priv->config & CFG_STATIC_ESSID)
6136 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006137 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6138 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006139 IPW_DEBUG_HC("Attempt to send SSID command "
6140 "failed.\n");
6141 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006142 }
6143
6144 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006145 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006146 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006147
James Ketrenosafbf30a2005-08-25 00:05:33 -05006148 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006149#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006150 }
6151#endif
6152
6153 err = ipw_send_scan_request_ext(priv, &scan);
6154 if (err) {
6155 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006156 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006157 }
6158
6159 priv->status |= STATUS_SCANNING;
6160 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006161 queue_delayed_work(priv->workqueue, &priv->scan_check,
6162 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006163 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006164 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006165 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006166}
6167
6168static void ipw_bg_abort_scan(void *data)
6169{
6170 struct ipw_priv *priv = data;
6171 down(&priv->sem);
6172 ipw_abort_scan(data);
6173 up(&priv->sem);
6174}
6175
James Ketrenosea2b26e2005-08-24 21:25:16 -05006176static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6177{
James Ketrenosb095c382005-08-24 22:04:42 -05006178 /* This is called when wpa_supplicant loads and closes the driver
6179 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006180 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006181 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006182}
6183
James Ketrenosea2b26e2005-08-24 21:25:16 -05006184static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6185{
6186 struct ieee80211_device *ieee = priv->ieee;
6187 struct ieee80211_security sec = {
6188 .flags = SEC_AUTH_MODE,
6189 };
6190 int ret = 0;
6191
James Ketrenosafbf30a2005-08-25 00:05:33 -05006192 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006193 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6194 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006195 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006196 sec.auth_mode = WLAN_AUTH_OPEN;
6197 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006198 } else
6199 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006200
6201 if (ieee->set_security)
6202 ieee->set_security(ieee->dev, &sec);
6203 else
6204 ret = -EOPNOTSUPP;
6205
6206 return ret;
6207}
6208
Adrian Bunka73e22b2006-01-21 01:39:42 +01006209static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6210 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006211{
6212 /* make sure WPA is enabled */
6213 ipw_wpa_enable(priv, 1);
6214
6215 ipw_disassociate(priv);
6216}
6217
6218static int ipw_set_rsn_capa(struct ipw_priv *priv,
6219 char *capabilities, int length)
6220{
6221 struct host_cmd cmd = {
6222 .cmd = IPW_CMD_RSN_CAPABILITIES,
6223 .len = length,
6224 };
6225
6226 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6227
6228 memcpy(cmd.param, capabilities, length);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05006229 return ipw_send_cmd(priv, &cmd);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006230}
6231
James Ketrenosafbf30a2005-08-25 00:05:33 -05006232/*
6233 * WE-18 support
6234 */
6235
6236/* SIOCSIWGENIE */
6237static int ipw_wx_set_genie(struct net_device *dev,
6238 struct iw_request_info *info,
6239 union iwreq_data *wrqu, char *extra)
6240{
6241 struct ipw_priv *priv = ieee80211_priv(dev);
6242 struct ieee80211_device *ieee = priv->ieee;
6243 u8 *buf;
6244 int err = 0;
6245
6246 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6247 (wrqu->data.length && extra == NULL))
6248 return -EINVAL;
6249
6250 //down(&priv->sem);
6251
6252 //if (!ieee->wpa_enabled) {
6253 // err = -EOPNOTSUPP;
6254 // goto out;
6255 //}
6256
6257 if (wrqu->data.length) {
6258 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6259 if (buf == NULL) {
6260 err = -ENOMEM;
6261 goto out;
6262 }
6263
6264 memcpy(buf, extra, wrqu->data.length);
6265 kfree(ieee->wpa_ie);
6266 ieee->wpa_ie = buf;
6267 ieee->wpa_ie_len = wrqu->data.length;
6268 } else {
6269 kfree(ieee->wpa_ie);
6270 ieee->wpa_ie = NULL;
6271 ieee->wpa_ie_len = 0;
6272 }
6273
6274 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6275 out:
6276 //up(&priv->sem);
6277 return err;
6278}
6279
6280/* SIOCGIWGENIE */
6281static int ipw_wx_get_genie(struct net_device *dev,
6282 struct iw_request_info *info,
6283 union iwreq_data *wrqu, char *extra)
6284{
6285 struct ipw_priv *priv = ieee80211_priv(dev);
6286 struct ieee80211_device *ieee = priv->ieee;
6287 int err = 0;
6288
6289 //down(&priv->sem);
6290
6291 //if (!ieee->wpa_enabled) {
6292 // err = -EOPNOTSUPP;
6293 // goto out;
6294 //}
6295
6296 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6297 wrqu->data.length = 0;
6298 goto out;
6299 }
6300
6301 if (wrqu->data.length < ieee->wpa_ie_len) {
6302 err = -E2BIG;
6303 goto out;
6304 }
6305
6306 wrqu->data.length = ieee->wpa_ie_len;
6307 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6308
6309 out:
6310 //up(&priv->sem);
6311 return err;
6312}
6313
Zhu Yi1fbfea52005-08-05 17:22:56 +08006314static int wext_cipher2level(int cipher)
6315{
6316 switch (cipher) {
6317 case IW_AUTH_CIPHER_NONE:
6318 return SEC_LEVEL_0;
6319 case IW_AUTH_CIPHER_WEP40:
6320 case IW_AUTH_CIPHER_WEP104:
6321 return SEC_LEVEL_1;
6322 case IW_AUTH_CIPHER_TKIP:
6323 return SEC_LEVEL_2;
6324 case IW_AUTH_CIPHER_CCMP:
6325 return SEC_LEVEL_3;
6326 default:
6327 return -1;
6328 }
6329}
6330
James Ketrenosafbf30a2005-08-25 00:05:33 -05006331/* SIOCSIWAUTH */
6332static int ipw_wx_set_auth(struct net_device *dev,
6333 struct iw_request_info *info,
6334 union iwreq_data *wrqu, char *extra)
6335{
6336 struct ipw_priv *priv = ieee80211_priv(dev);
6337 struct ieee80211_device *ieee = priv->ieee;
6338 struct iw_param *param = &wrqu->param;
6339 struct ieee80211_crypt_data *crypt;
6340 unsigned long flags;
6341 int ret = 0;
6342
6343 switch (param->flags & IW_AUTH_INDEX) {
6344 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006345 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006346 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006347 ipw_set_hw_decrypt_unicast(priv,
6348 wext_cipher2level(param->value));
6349 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006350 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006351 ipw_set_hw_decrypt_multicast(priv,
6352 wext_cipher2level(param->value));
6353 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006354 case IW_AUTH_KEY_MGMT:
6355 /*
6356 * ipw2200 does not use these parameters
6357 */
6358 break;
6359
6360 case IW_AUTH_TKIP_COUNTERMEASURES:
6361 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006362 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006363 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006364
6365 flags = crypt->ops->get_flags(crypt->priv);
6366
6367 if (param->value)
6368 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6369 else
6370 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6371
6372 crypt->ops->set_flags(flags, crypt->priv);
6373
6374 break;
6375
6376 case IW_AUTH_DROP_UNENCRYPTED:{
6377 /* HACK:
6378 *
6379 * wpa_supplicant calls set_wpa_enabled when the driver
6380 * is loaded and unloaded, regardless of if WPA is being
6381 * used. No other calls are made which can be used to
6382 * determine if encryption will be used or not prior to
6383 * association being expected. If encryption is not being
6384 * used, drop_unencrypted is set to false, else true -- we
6385 * can use this to determine if the CAP_PRIVACY_ON bit should
6386 * be set.
6387 */
6388 struct ieee80211_security sec = {
6389 .flags = SEC_ENABLED,
6390 .enabled = param->value,
6391 };
6392 priv->ieee->drop_unencrypted = param->value;
6393 /* We only change SEC_LEVEL for open mode. Others
6394 * are set by ipw_wpa_set_encryption.
6395 */
6396 if (!param->value) {
6397 sec.flags |= SEC_LEVEL;
6398 sec.level = SEC_LEVEL_0;
6399 } else {
6400 sec.flags |= SEC_LEVEL;
6401 sec.level = SEC_LEVEL_1;
6402 }
6403 if (priv->ieee->set_security)
6404 priv->ieee->set_security(priv->ieee->dev, &sec);
6405 break;
6406 }
6407
6408 case IW_AUTH_80211_AUTH_ALG:
6409 ret = ipw_wpa_set_auth_algs(priv, param->value);
6410 break;
6411
6412 case IW_AUTH_WPA_ENABLED:
6413 ret = ipw_wpa_enable(priv, param->value);
6414 break;
6415
6416 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6417 ieee->ieee802_1x = param->value;
6418 break;
6419
6420 //case IW_AUTH_ROAMING_CONTROL:
6421 case IW_AUTH_PRIVACY_INVOKED:
6422 ieee->privacy_invoked = param->value;
6423 break;
6424
6425 default:
6426 return -EOPNOTSUPP;
6427 }
6428 return ret;
6429}
6430
6431/* SIOCGIWAUTH */
6432static int ipw_wx_get_auth(struct net_device *dev,
6433 struct iw_request_info *info,
6434 union iwreq_data *wrqu, char *extra)
6435{
6436 struct ipw_priv *priv = ieee80211_priv(dev);
6437 struct ieee80211_device *ieee = priv->ieee;
6438 struct ieee80211_crypt_data *crypt;
6439 struct iw_param *param = &wrqu->param;
6440 int ret = 0;
6441
6442 switch (param->flags & IW_AUTH_INDEX) {
6443 case IW_AUTH_WPA_VERSION:
6444 case IW_AUTH_CIPHER_PAIRWISE:
6445 case IW_AUTH_CIPHER_GROUP:
6446 case IW_AUTH_KEY_MGMT:
6447 /*
6448 * wpa_supplicant will control these internally
6449 */
6450 ret = -EOPNOTSUPP;
6451 break;
6452
6453 case IW_AUTH_TKIP_COUNTERMEASURES:
6454 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006455 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006456 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006457
6458 param->value = (crypt->ops->get_flags(crypt->priv) &
6459 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6460
6461 break;
6462
6463 case IW_AUTH_DROP_UNENCRYPTED:
6464 param->value = ieee->drop_unencrypted;
6465 break;
6466
6467 case IW_AUTH_80211_AUTH_ALG:
6468 param->value = ieee->sec.auth_mode;
6469 break;
6470
6471 case IW_AUTH_WPA_ENABLED:
6472 param->value = ieee->wpa_enabled;
6473 break;
6474
6475 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6476 param->value = ieee->ieee802_1x;
6477 break;
6478
6479 case IW_AUTH_ROAMING_CONTROL:
6480 case IW_AUTH_PRIVACY_INVOKED:
6481 param->value = ieee->privacy_invoked;
6482 break;
6483
6484 default:
6485 return -EOPNOTSUPP;
6486 }
6487 return 0;
6488}
6489
6490/* SIOCSIWENCODEEXT */
6491static int ipw_wx_set_encodeext(struct net_device *dev,
6492 struct iw_request_info *info,
6493 union iwreq_data *wrqu, char *extra)
6494{
6495 struct ipw_priv *priv = ieee80211_priv(dev);
6496 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6497
6498 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006499 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006500 /* IPW HW can't build TKIP MIC,
6501 host decryption still needed */
6502 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6503 priv->ieee->host_mc_decrypt = 1;
6504 else {
6505 priv->ieee->host_encrypt = 0;
6506 priv->ieee->host_encrypt_msdu = 1;
6507 priv->ieee->host_decrypt = 1;
6508 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006509 } else {
6510 priv->ieee->host_encrypt = 0;
6511 priv->ieee->host_encrypt_msdu = 0;
6512 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006513 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006514 }
6515 }
6516
6517 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6518}
6519
6520/* SIOCGIWENCODEEXT */
6521static int ipw_wx_get_encodeext(struct net_device *dev,
6522 struct iw_request_info *info,
6523 union iwreq_data *wrqu, char *extra)
6524{
6525 struct ipw_priv *priv = ieee80211_priv(dev);
6526 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6527}
6528
6529/* SIOCSIWMLME */
6530static int ipw_wx_set_mlme(struct net_device *dev,
6531 struct iw_request_info *info,
6532 union iwreq_data *wrqu, char *extra)
6533{
6534 struct ipw_priv *priv = ieee80211_priv(dev);
6535 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6536 u16 reason;
6537
6538 reason = cpu_to_le16(mlme->reason_code);
6539
6540 switch (mlme->cmd) {
6541 case IW_MLME_DEAUTH:
6542 // silently ignore
6543 break;
6544
6545 case IW_MLME_DISASSOC:
6546 ipw_disassociate(priv);
6547 break;
6548
6549 default:
6550 return -EOPNOTSUPP;
6551 }
6552 return 0;
6553}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006554
James Ketrenosb095c382005-08-24 22:04:42 -05006555#ifdef CONFIG_IPW_QOS
6556
6557/* QoS */
6558/*
6559* get the modulation type of the current network or
6560* the card current mode
6561*/
6562u8 ipw_qos_current_mode(struct ipw_priv * priv)
6563{
6564 u8 mode = 0;
6565
6566 if (priv->status & STATUS_ASSOCIATED) {
6567 unsigned long flags;
6568
6569 spin_lock_irqsave(&priv->ieee->lock, flags);
6570 mode = priv->assoc_network->mode;
6571 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6572 } else {
6573 mode = priv->ieee->mode;
6574 }
6575 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6576 return mode;
6577}
6578
6579/*
6580* Handle management frame beacon and probe response
6581*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006582static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6583 int active_network,
6584 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006585{
6586 u32 size = sizeof(struct ieee80211_qos_parameters);
6587
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006589 network->qos_data.active = network->qos_data.supported;
6590
6591 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006592 if (active_network &&
6593 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006594 network->qos_data.active = network->qos_data.supported;
6595
6596 if ((network->qos_data.active == 1) && (active_network == 1) &&
6597 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6598 (network->qos_data.old_param_count !=
6599 network->qos_data.param_count)) {
6600 network->qos_data.old_param_count =
6601 network->qos_data.param_count;
6602 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006603 IPW_DEBUG_QOS("QoS parameters change call "
6604 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006605 }
6606 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006607 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6608 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006609 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006610 else
6611 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006612 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006613
James Ketrenosb095c382005-08-24 22:04:42 -05006614 if ((network->qos_data.active == 1) && (active_network == 1)) {
6615 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6616 schedule_work(&priv->qos_activate);
6617 }
6618
6619 network->qos_data.active = 0;
6620 network->qos_data.supported = 0;
6621 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006622 if ((priv->status & STATUS_ASSOCIATED) &&
6623 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6624 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6625 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6626 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006627 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006628 priv->assoc_network->ssid_len) &&
6629 !memcmp(network->ssid,
6630 priv->assoc_network->ssid,
6631 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006632 queue_work(priv->workqueue,
6633 &priv->merge_networks);
6634 }
James Ketrenosb095c382005-08-24 22:04:42 -05006635 }
6636
6637 return 0;
6638}
6639
6640/*
6641* This function set up the firmware to support QoS. It sends
6642* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6643*/
6644static int ipw_qos_activate(struct ipw_priv *priv,
6645 struct ieee80211_qos_data *qos_network_data)
6646{
6647 int err;
6648 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6649 struct ieee80211_qos_parameters *active_one = NULL;
6650 u32 size = sizeof(struct ieee80211_qos_parameters);
6651 u32 burst_duration;
6652 int i;
6653 u8 type;
6654
6655 type = ipw_qos_current_mode(priv);
6656
6657 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6658 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6659 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6660 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6661
6662 if (qos_network_data == NULL) {
6663 if (type == IEEE_B) {
6664 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6665 active_one = &def_parameters_CCK;
6666 } else
6667 active_one = &def_parameters_OFDM;
6668
James Ketrenosafbf30a2005-08-25 00:05:33 -05006669 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006670 burst_duration = ipw_qos_get_burst_duration(priv);
6671 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006672 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6673 (u16) burst_duration;
6674 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006675 if (type == IEEE_B) {
6676 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6677 type);
6678 if (priv->qos_data.qos_enable == 0)
6679 active_one = &def_parameters_CCK;
6680 else
6681 active_one = priv->qos_data.def_qos_parm_CCK;
6682 } else {
6683 if (priv->qos_data.qos_enable == 0)
6684 active_one = &def_parameters_OFDM;
6685 else
6686 active_one = priv->qos_data.def_qos_parm_OFDM;
6687 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006688 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006689 } else {
6690 unsigned long flags;
6691 int active;
6692
6693 spin_lock_irqsave(&priv->ieee->lock, flags);
6694 active_one = &(qos_network_data->parameters);
6695 qos_network_data->old_param_count =
6696 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006697 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006698 active = qos_network_data->supported;
6699 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6700
6701 if (active == 0) {
6702 burst_duration = ipw_qos_get_burst_duration(priv);
6703 for (i = 0; i < QOS_QUEUE_NUM; i++)
6704 qos_parameters[QOS_PARAM_SET_ACTIVE].
6705 tx_op_limit[i] = (u16) burst_duration;
6706 }
6707 }
6708
6709 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006710 err = ipw_send_qos_params_command(priv,
6711 (struct ieee80211_qos_parameters *)
6712 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006713 if (err)
6714 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6715
6716 return err;
6717}
6718
6719/*
6720* send IPW_CMD_WME_INFO to the firmware
6721*/
6722static int ipw_qos_set_info_element(struct ipw_priv *priv)
6723{
6724 int ret = 0;
6725 struct ieee80211_qos_information_element qos_info;
6726
6727 if (priv == NULL)
6728 return -1;
6729
6730 qos_info.elementID = QOS_ELEMENT_ID;
6731 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6732
6733 qos_info.version = QOS_VERSION_1;
6734 qos_info.ac_info = 0;
6735
6736 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6737 qos_info.qui_type = QOS_OUI_TYPE;
6738 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6739
6740 ret = ipw_send_qos_info_command(priv, &qos_info);
6741 if (ret != 0) {
6742 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6743 }
6744 return ret;
6745}
6746
6747/*
6748* Set the QoS parameter with the association request structure
6749*/
6750static int ipw_qos_association(struct ipw_priv *priv,
6751 struct ieee80211_network *network)
6752{
6753 int err = 0;
6754 struct ieee80211_qos_data *qos_data = NULL;
6755 struct ieee80211_qos_data ibss_data = {
6756 .supported = 1,
6757 .active = 1,
6758 };
6759
6760 switch (priv->ieee->iw_mode) {
6761 case IW_MODE_ADHOC:
6762 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6763 BUG();
6764
6765 qos_data = &ibss_data;
6766 break;
6767
6768 case IW_MODE_INFRA:
6769 qos_data = &network->qos_data;
6770 break;
6771
6772 default:
6773 BUG();
6774 break;
6775 }
6776
6777 err = ipw_qos_activate(priv, qos_data);
6778 if (err) {
6779 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6780 return err;
6781 }
6782
6783 if (priv->qos_data.qos_enable && qos_data->supported) {
6784 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6785 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6786 return ipw_qos_set_info_element(priv);
6787 }
6788
6789 return 0;
6790}
6791
6792/*
6793* handling the beaconing responces. if we get different QoS setting
6794* of the network from the the associated setting adjust the QoS
6795* setting
6796*/
6797static int ipw_qos_association_resp(struct ipw_priv *priv,
6798 struct ieee80211_network *network)
6799{
6800 int ret = 0;
6801 unsigned long flags;
6802 u32 size = sizeof(struct ieee80211_qos_parameters);
6803 int set_qos_param = 0;
6804
James Ketrenosafbf30a2005-08-25 00:05:33 -05006805 if ((priv == NULL) || (network == NULL) ||
6806 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006807 return ret;
6808
6809 if (!(priv->status & STATUS_ASSOCIATED))
6810 return ret;
6811
James Ketrenosafbf30a2005-08-25 00:05:33 -05006812 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006813 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006814
6815 spin_lock_irqsave(&priv->ieee->lock, flags);
6816 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006817 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006818 sizeof(struct ieee80211_qos_data));
6819 priv->assoc_network->qos_data.active = 1;
6820 if ((network->qos_data.old_param_count !=
6821 network->qos_data.param_count)) {
6822 set_qos_param = 1;
6823 network->qos_data.old_param_count =
6824 network->qos_data.param_count;
6825 }
6826
6827 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006828 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6829 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006830 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006831 else
6832 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006833 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006834 priv->assoc_network->qos_data.active = 0;
6835 priv->assoc_network->qos_data.supported = 0;
6836 set_qos_param = 1;
6837 }
6838
6839 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6840
6841 if (set_qos_param == 1)
6842 schedule_work(&priv->qos_activate);
6843
6844 return ret;
6845}
6846
6847static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6848{
6849 u32 ret = 0;
6850
6851 if ((priv == NULL))
6852 return 0;
6853
James Ketrenosafbf30a2005-08-25 00:05:33 -05006854 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006855 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006856 else
James Ketrenosb095c382005-08-24 22:04:42 -05006857 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006858
James Ketrenosb095c382005-08-24 22:04:42 -05006859 return ret;
6860}
6861
6862/*
6863* Initialize the setting of QoS global
6864*/
6865static void ipw_qos_init(struct ipw_priv *priv, int enable,
6866 int burst_enable, u32 burst_duration_CCK,
6867 u32 burst_duration_OFDM)
6868{
6869 priv->qos_data.qos_enable = enable;
6870
6871 if (priv->qos_data.qos_enable) {
6872 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6873 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6874 IPW_DEBUG_QOS("QoS is enabled\n");
6875 } else {
6876 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6877 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6878 IPW_DEBUG_QOS("QoS is not enabled\n");
6879 }
6880
6881 priv->qos_data.burst_enable = burst_enable;
6882
6883 if (burst_enable) {
6884 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6885 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6886 } else {
6887 priv->qos_data.burst_duration_CCK = 0;
6888 priv->qos_data.burst_duration_OFDM = 0;
6889 }
6890}
6891
6892/*
6893* map the packet priority to the right TX Queue
6894*/
6895static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6896{
6897 if (priority > 7 || !priv->qos_data.qos_enable)
6898 priority = 0;
6899
6900 return from_priority_to_tx_queue[priority] - 1;
6901}
6902
6903/*
6904* add QoS parameter to the TX command
6905*/
6906static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6907 u16 priority,
6908 struct tfd_data *tfd, u8 unicast)
6909{
6910 int ret = 0;
6911 int tx_queue_id = 0;
6912 struct ieee80211_qos_data *qos_data = NULL;
6913 int active, supported;
6914 unsigned long flags;
6915
6916 if (!(priv->status & STATUS_ASSOCIATED))
6917 return 0;
6918
6919 qos_data = &priv->assoc_network->qos_data;
6920
6921 spin_lock_irqsave(&priv->ieee->lock, flags);
6922
6923 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6924 if (unicast == 0)
6925 qos_data->active = 0;
6926 else
6927 qos_data->active = qos_data->supported;
6928 }
6929
6930 active = qos_data->active;
6931 supported = qos_data->supported;
6932
6933 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6934
James Ketrenosafbf30a2005-08-25 00:05:33 -05006935 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6936 "unicast %d\n",
6937 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05006938 if (active && priv->qos_data.qos_enable) {
6939 ret = from_priority_to_tx_queue[priority];
6940 tx_queue_id = ret - 1;
6941 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6942 if (priority <= 7) {
6943 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6944 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6945 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6946 IEEE80211_STYPE_QOS_DATA;
6947
6948 if (priv->qos_data.qos_no_ack_mask &
6949 (1UL << tx_queue_id)) {
6950 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6951 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6952 CTRL_QOS_NO_ACK;
6953 }
6954 }
6955 }
6956
6957 return ret;
6958}
6959
6960/*
6961* background support to run QoS activate functionality
6962*/
6963static void ipw_bg_qos_activate(void *data)
6964{
6965 struct ipw_priv *priv = data;
6966
6967 if (priv == NULL)
6968 return;
6969
6970 down(&priv->sem);
6971
6972 if (priv->status & STATUS_ASSOCIATED)
6973 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6974
6975 up(&priv->sem);
6976}
6977
James Ketrenos3b9990c2005-08-19 13:18:55 -05006978static int ipw_handle_probe_response(struct net_device *dev,
6979 struct ieee80211_probe_response *resp,
6980 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006981{
6982 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05006983 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6984 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05006985
James Ketrenos3b9990c2005-08-19 13:18:55 -05006986 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05006987
James Ketrenos3b9990c2005-08-19 13:18:55 -05006988 return 0;
6989}
James Ketrenosb095c382005-08-24 22:04:42 -05006990
James Ketrenos3b9990c2005-08-19 13:18:55 -05006991static int ipw_handle_beacon(struct net_device *dev,
6992 struct ieee80211_beacon *resp,
6993 struct ieee80211_network *network)
6994{
6995 struct ipw_priv *priv = ieee80211_priv(dev);
6996 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6997 (network == priv->assoc_network));
6998
6999 ipw_qos_handle_probe_response(priv, active_network, network);
7000
7001 return 0;
7002}
7003
7004static int ipw_handle_assoc_response(struct net_device *dev,
7005 struct ieee80211_assoc_response *resp,
7006 struct ieee80211_network *network)
7007{
7008 struct ipw_priv *priv = ieee80211_priv(dev);
7009 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007010 return 0;
7011}
7012
7013static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7014 *qos_param)
7015{
7016 struct host_cmd cmd = {
7017 .cmd = IPW_CMD_QOS_PARAMETERS,
7018 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7019 };
7020
James Ketrenosafbf30a2005-08-25 00:05:33 -05007021 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007022 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007023}
7024
7025static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7026 *qos_param)
7027{
7028 struct host_cmd cmd = {
7029 .cmd = IPW_CMD_WME_INFO,
7030 .len = sizeof(*qos_param)
7031 };
7032
James Ketrenosafbf30a2005-08-25 00:05:33 -05007033 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007034 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007035}
7036
7037#endif /* CONFIG_IPW_QOS */
7038
James Ketrenos43f66a62005-03-25 12:31:53 -06007039static int ipw_associate_network(struct ipw_priv *priv,
7040 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007041 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007042{
7043 int err;
7044
7045 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007046 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007047
7048 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007049 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007050 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007051 memcpy(priv->essid, network->ssid, priv->essid_len);
7052 }
7053
7054 network->last_associate = jiffies;
7055
7056 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7057 priv->assoc_request.channel = network->channel;
7058 if ((priv->capability & CAP_PRIVACY_ON) &&
7059 (priv->capability & CAP_SHARED_KEY)) {
7060 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007061 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7062
7063 if ((priv->capability & CAP_PRIVACY_ON) &&
7064 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7065 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7066 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenos43f66a62005-03-25 12:31:53 -06007067 } else {
7068 priv->assoc_request.auth_type = AUTH_OPEN;
7069 priv->assoc_request.auth_key = 0;
7070 }
7071
James Ketrenosa613bff2005-08-24 21:43:11 -05007072 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007073 priv->assoc_request.policy_support = 0x02; /* RSN active */
7074 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7075 priv->ieee->wpa_ie_len);
7076 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007077
Jeff Garzikbf794512005-07-31 13:07:26 -04007078 /*
7079 * It is valid for our ieee device to support multiple modes, but
7080 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007081 * just one mode.
7082 */
7083 if (network->mode & priv->ieee->mode & IEEE_A)
7084 priv->assoc_request.ieee_mode = IPW_A_MODE;
7085 else if (network->mode & priv->ieee->mode & IEEE_G)
7086 priv->assoc_request.ieee_mode = IPW_G_MODE;
7087 else if (network->mode & priv->ieee->mode & IEEE_B)
7088 priv->assoc_request.ieee_mode = IPW_B_MODE;
7089
James Ketrenosea2b26e2005-08-24 21:25:16 -05007090 priv->assoc_request.capability = network->capability;
7091 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7092 && !(priv->config & CFG_PREAMBLE_LONG)) {
7093 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7094 } else {
7095 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7096
7097 /* Clear the short preamble if we won't be supporting it */
7098 priv->assoc_request.capability &=
7099 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7100 }
7101
James Ketrenosafbf30a2005-08-25 00:05:33 -05007102 /* Clear capability bits that aren't used in Ad Hoc */
7103 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7104 priv->assoc_request.capability &=
7105 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7106
James Ketrenos43f66a62005-03-25 12:31:53 -06007107 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007108 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007109 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007110 escape_essid(priv->essid, priv->essid_len),
7111 network->channel,
7112 ipw_modes[priv->assoc_request.ieee_mode],
7113 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007114 (priv->assoc_request.preamble_length ==
7115 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7116 network->capability &
7117 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007118 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007119 priv->capability & CAP_PRIVACY_ON ?
7120 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007121 "(open)") : "",
7122 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007123 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007124 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007125 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007126
7127 priv->assoc_request.beacon_interval = network->beacon_interval;
7128 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007129 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007130 priv->assoc_request.assoc_type = HC_IBSS_START;
7131 priv->assoc_request.assoc_tsf_msw = 0;
7132 priv->assoc_request.assoc_tsf_lsw = 0;
7133 } else {
7134 if (unlikely(roaming))
7135 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7136 else
7137 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7138 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7139 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7140 }
7141
James Ketrenosafbf30a2005-08-25 00:05:33 -05007142 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007143
7144 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7145 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7146 priv->assoc_request.atim_window = network->atim_window;
7147 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007148 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007149 priv->assoc_request.atim_window = 0;
7150 }
7151
James Ketrenos43f66a62005-03-25 12:31:53 -06007152 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007153
James Ketrenos43f66a62005-03-25 12:31:53 -06007154 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7155 if (err) {
7156 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7157 return err;
7158 }
7159
7160 rates->ieee_mode = priv->assoc_request.ieee_mode;
7161 rates->purpose = IPW_RATE_CONNECT;
7162 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007163
James Ketrenos43f66a62005-03-25 12:31:53 -06007164 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7165 priv->sys_config.dot11g_auto_detection = 1;
7166 else
7167 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007168
7169 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7170 priv->sys_config.answer_broadcast_ssid_probe = 1;
7171 else
7172 priv->sys_config.answer_broadcast_ssid_probe = 0;
7173
James Ketrenos43f66a62005-03-25 12:31:53 -06007174 err = ipw_send_system_config(priv, &priv->sys_config);
7175 if (err) {
7176 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7177 return err;
7178 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007179
James Ketrenos43f66a62005-03-25 12:31:53 -06007180 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007181 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007182 if (err) {
7183 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7184 return err;
7185 }
7186
7187 /*
7188 * If preemption is enabled, it is possible for the association
7189 * to complete before we return from ipw_send_associate. Therefore
7190 * we have to be sure and update our priviate data first.
7191 */
7192 priv->channel = network->channel;
7193 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007194 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007195 priv->status &= ~STATUS_SECURITY_UPDATED;
7196
7197 priv->assoc_network = network;
7198
James Ketrenosb095c382005-08-24 22:04:42 -05007199#ifdef CONFIG_IPW_QOS
7200 ipw_qos_association(priv, network);
7201#endif
7202
James Ketrenos43f66a62005-03-25 12:31:53 -06007203 err = ipw_send_associate(priv, &priv->assoc_request);
7204 if (err) {
7205 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7206 return err;
7207 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007208
7209 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007210 escape_essid(priv->essid, priv->essid_len),
7211 MAC_ARG(priv->bssid));
7212
7213 return 0;
7214}
7215
7216static void ipw_roam(void *data)
7217{
7218 struct ipw_priv *priv = data;
7219 struct ieee80211_network *network = NULL;
7220 struct ipw_network_match match = {
7221 .network = priv->assoc_network
7222 };
7223
7224 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007225 *
7226 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007227 * setting the status ROAM bit and requesting a scan.
7228 * 2. When the scan completes, it schedules the ROAM work
7229 * 3. The ROAM work looks at all of the known networks for one that
7230 * is a better network than the currently associated. If none
7231 * found, the ROAM process is over (ROAM bit cleared)
7232 * 4. If a better network is found, a disassociation request is
7233 * sent.
7234 * 5. When the disassociation completes, the roam work is again
7235 * scheduled. The second time through, the driver is no longer
7236 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007237 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007238 * 6. At this point ,the roaming process is complete and the ROAM
7239 * status bit is cleared.
7240 */
7241
7242 /* If we are no longer associated, and the roaming bit is no longer
7243 * set, then we are not actively roaming, so just return */
7244 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7245 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007246
James Ketrenos43f66a62005-03-25 12:31:53 -06007247 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007248 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007249 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007250 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007251 u8 rssi = priv->assoc_network->stats.rssi;
7252 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007253 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007254 list_for_each_entry(network, &priv->ieee->network_list, list) {
7255 if (network != priv->assoc_network)
7256 ipw_best_network(priv, &match, network, 1);
7257 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007258 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007259 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007260
James Ketrenos43f66a62005-03-25 12:31:53 -06007261 if (match.network == priv->assoc_network) {
7262 IPW_DEBUG_ASSOC("No better APs in this network to "
7263 "roam to.\n");
7264 priv->status &= ~STATUS_ROAMING;
7265 ipw_debug_config(priv);
7266 return;
7267 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007268
James Ketrenos43f66a62005-03-25 12:31:53 -06007269 ipw_send_disassociate(priv, 1);
7270 priv->assoc_network = match.network;
7271
7272 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007273 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007274
7275 /* Second pass through ROAM process -- request association */
7276 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7277 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7278 priv->status &= ~STATUS_ROAMING;
7279}
7280
James Ketrenosc848d0a2005-08-24 21:56:24 -05007281static void ipw_bg_roam(void *data)
7282{
7283 struct ipw_priv *priv = data;
7284 down(&priv->sem);
7285 ipw_roam(data);
7286 up(&priv->sem);
7287}
7288
7289static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007290{
7291 struct ipw_priv *priv = data;
7292
7293 struct ieee80211_network *network = NULL;
7294 struct ipw_network_match match = {
7295 .network = NULL
7296 };
7297 struct ipw_supported_rates *rates;
7298 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007299 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007300
James Ketrenosb095c382005-08-24 22:04:42 -05007301 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7302 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7303 return 0;
7304 }
7305
James Ketrenosc848d0a2005-08-24 21:56:24 -05007306 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007307 IPW_DEBUG_ASSOC("Not attempting association (already in "
7308 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007309 return 0;
7310 }
7311
Hong Liue6324722005-09-14 21:04:15 -05007312 if (priv->status & STATUS_DISASSOCIATING) {
7313 IPW_DEBUG_ASSOC("Not attempting association (in "
7314 "disassociating)\n ");
7315 queue_work(priv->workqueue, &priv->associate);
7316 return 0;
7317 }
7318
James Ketrenosc848d0a2005-08-24 21:56:24 -05007319 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007320 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7321 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007322 return 0;
7323 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007324
7325 if (!(priv->config & CFG_ASSOCIATE) &&
7326 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007327 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007328 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007329 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007330 }
7331
James Ketrenosa613bff2005-08-24 21:43:11 -05007332 /* Protect our use of the network_list */
7333 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007334 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007335 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007336
7337 network = match.network;
7338 rates = &match.rates;
7339
7340 if (network == NULL &&
7341 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7342 priv->config & CFG_ADHOC_CREATE &&
7343 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007344 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007345 !list_empty(&priv->ieee->network_free_list)) {
7346 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007347 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007348 ipw_adhoc_create(priv, network);
7349 rates = &priv->rates;
7350 list_del(element);
7351 list_add_tail(&network->list, &priv->ieee->network_list);
7352 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007353 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007354
James Ketrenos43f66a62005-03-25 12:31:53 -06007355 /* If we reached the end of the list, then we don't have any valid
7356 * matching APs */
7357 if (!network) {
7358 ipw_debug_config(priv);
7359
James Ketrenosb095c382005-08-24 22:04:42 -05007360 if (!(priv->status & STATUS_SCANNING)) {
7361 if (!(priv->config & CFG_SPEED_SCAN))
7362 queue_delayed_work(priv->workqueue,
7363 &priv->request_scan,
7364 SCAN_INTERVAL);
7365 else
7366 queue_work(priv->workqueue,
7367 &priv->request_scan);
7368 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007369
James Ketrenosc848d0a2005-08-24 21:56:24 -05007370 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007371 }
7372
7373 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007374
7375 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007376}
Jeff Garzikbf794512005-07-31 13:07:26 -04007377
James Ketrenosc848d0a2005-08-24 21:56:24 -05007378static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007379{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007380 struct ipw_priv *priv = data;
7381 down(&priv->sem);
7382 ipw_associate(data);
7383 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007384}
7385
James Ketrenosb095c382005-08-24 22:04:42 -05007386static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7387 struct sk_buff *skb)
7388{
7389 struct ieee80211_hdr *hdr;
7390 u16 fc;
7391
7392 hdr = (struct ieee80211_hdr *)skb->data;
7393 fc = le16_to_cpu(hdr->frame_ctl);
7394 if (!(fc & IEEE80211_FCTL_PROTECTED))
7395 return;
7396
7397 fc &= ~IEEE80211_FCTL_PROTECTED;
7398 hdr->frame_ctl = cpu_to_le16(fc);
7399 switch (priv->ieee->sec.level) {
7400 case SEC_LEVEL_3:
7401 /* Remove CCMP HDR */
7402 memmove(skb->data + IEEE80211_3ADDR_LEN,
7403 skb->data + IEEE80211_3ADDR_LEN + 8,
7404 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007405 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007406 break;
7407 case SEC_LEVEL_2:
7408 break;
7409 case SEC_LEVEL_1:
7410 /* Remove IV */
7411 memmove(skb->data + IEEE80211_3ADDR_LEN,
7412 skb->data + IEEE80211_3ADDR_LEN + 4,
7413 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007414 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007415 break;
7416 case SEC_LEVEL_0:
7417 break;
7418 default:
7419 printk(KERN_ERR "Unknow security level %d\n",
7420 priv->ieee->sec.level);
7421 break;
7422 }
7423}
7424
7425static void ipw_handle_data_packet(struct ipw_priv *priv,
7426 struct ipw_rx_mem_buffer *rxb,
7427 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007428{
Hong Liu567deaf2005-08-31 18:07:22 +08007429 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007430 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7431
7432 /* We received data from the HW, so stop the watchdog */
7433 priv->net_dev->trans_start = jiffies;
7434
Jeff Garzikbf794512005-07-31 13:07:26 -04007435 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007437 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007438 skb_tailroom(rxb->skb))) {
7439 priv->ieee->stats.rx_errors++;
7440 priv->wstats.discard.misc++;
7441 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7442 return;
7443 } else if (unlikely(!netif_running(priv->net_dev))) {
7444 priv->ieee->stats.rx_dropped++;
7445 priv->wstats.discard.misc++;
7446 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7447 return;
7448 }
7449
7450 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007451 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007452
7453 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007454 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007455
7456 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7457
James Ketrenosb095c382005-08-24 22:04:42 -05007458 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007459 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7460 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007461 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007462 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007463 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7464
Jeff Garzikbf794512005-07-31 13:07:26 -04007465 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007466 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007467 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007468 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007469 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007470 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007471}
7472
Mike Kershaw24a47db2005-08-26 00:41:54 -05007473#ifdef CONFIG_IEEE80211_RADIOTAP
7474static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7475 struct ipw_rx_mem_buffer *rxb,
7476 struct ieee80211_rx_stats *stats)
7477{
7478 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7479 struct ipw_rx_frame *frame = &pkt->u.frame;
7480
7481 /* initial pull of some data */
7482 u16 received_channel = frame->received_channel;
7483 u8 antennaAndPhy = frame->antennaAndPhy;
7484 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7485 u16 pktrate = frame->rate;
7486
7487 /* Magic struct that slots into the radiotap header -- no reason
7488 * to build this manually element by element, we can write it much
7489 * more efficiently than we can parse it. ORDER MATTERS HERE */
7490 struct ipw_rt_hdr {
7491 struct ieee80211_radiotap_header rt_hdr;
7492 u8 rt_flags; /* radiotap packet flags */
7493 u8 rt_rate; /* rate in 500kb/s */
7494 u16 rt_channel; /* channel in mhz */
7495 u16 rt_chbitmask; /* channel bitfield */
7496 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7497 u8 rt_antenna; /* antenna number */
7498 } *ipw_rt;
7499
7500 short len = le16_to_cpu(pkt->u.frame.length);
7501
7502 /* We received data from the HW, so stop the watchdog */
7503 priv->net_dev->trans_start = jiffies;
7504
7505 /* We only process data packets if the
7506 * interface is open */
7507 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7508 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 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7521 * that now */
7522 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7523 /* FIXME: Should alloc bigger skb instead */
7524 priv->ieee->stats.rx_dropped++;
7525 priv->wstats.discard.misc++;
7526 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7527 return;
7528 }
7529
7530 /* copy the frame itself */
7531 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7532 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7533
7534 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7535 * part of our real header, saves a little time.
7536 *
7537 * No longer necessary since we fill in all our data. Purge before merging
7538 * patch officially.
7539 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7540 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7541 */
7542
7543 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7544
7545 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7546 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7547 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7548
7549 /* Big bitfield of all the fields we provide in radiotap */
7550 ipw_rt->rt_hdr.it_present =
7551 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7552 (1 << IEEE80211_RADIOTAP_RATE) |
7553 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7554 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7555 (1 << IEEE80211_RADIOTAP_ANTENNA));
7556
7557 /* Zero the flags, we'll add to them as we go */
7558 ipw_rt->rt_flags = 0;
7559
7560 /* Convert signal to DBM */
7561 ipw_rt->rt_dbmsignal = antsignal;
7562
7563 /* Convert the channel data and set the flags */
7564 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7565 if (received_channel > 14) { /* 802.11a */
7566 ipw_rt->rt_chbitmask =
7567 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7568 } else if (antennaAndPhy & 32) { /* 802.11b */
7569 ipw_rt->rt_chbitmask =
7570 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7571 } else { /* 802.11g */
7572 ipw_rt->rt_chbitmask =
7573 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7574 }
7575
7576 /* set the rate in multiples of 500k/s */
7577 switch (pktrate) {
7578 case IPW_TX_RATE_1MB:
7579 ipw_rt->rt_rate = 2;
7580 break;
7581 case IPW_TX_RATE_2MB:
7582 ipw_rt->rt_rate = 4;
7583 break;
7584 case IPW_TX_RATE_5MB:
7585 ipw_rt->rt_rate = 10;
7586 break;
7587 case IPW_TX_RATE_6MB:
7588 ipw_rt->rt_rate = 12;
7589 break;
7590 case IPW_TX_RATE_9MB:
7591 ipw_rt->rt_rate = 18;
7592 break;
7593 case IPW_TX_RATE_11MB:
7594 ipw_rt->rt_rate = 22;
7595 break;
7596 case IPW_TX_RATE_12MB:
7597 ipw_rt->rt_rate = 24;
7598 break;
7599 case IPW_TX_RATE_18MB:
7600 ipw_rt->rt_rate = 36;
7601 break;
7602 case IPW_TX_RATE_24MB:
7603 ipw_rt->rt_rate = 48;
7604 break;
7605 case IPW_TX_RATE_36MB:
7606 ipw_rt->rt_rate = 72;
7607 break;
7608 case IPW_TX_RATE_48MB:
7609 ipw_rt->rt_rate = 96;
7610 break;
7611 case IPW_TX_RATE_54MB:
7612 ipw_rt->rt_rate = 108;
7613 break;
7614 default:
7615 ipw_rt->rt_rate = 0;
7616 break;
7617 }
7618
7619 /* antenna number */
7620 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7621
7622 /* set the preamble flag if we have it */
7623 if ((antennaAndPhy & 64))
7624 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7625
7626 /* Set the size of the skb to the size of the frame */
7627 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007628
7629 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7630
7631 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7632 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007633 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007634 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007635 /* no LED during capture */
7636 }
7637}
7638#endif
7639
Arjan van de Ven858119e2006-01-14 13:20:43 -08007640static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007641 struct ieee80211_hdr_4addr *header)
7642{
7643 /* Filter incoming packets to determine if they are targetted toward
7644 * this network, discarding packets coming from ourselves */
7645 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007646 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007647 /* packets from our adapter are dropped (echo) */
7648 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7649 return 0;
7650
Peter Jones90700fd2005-08-26 16:51:06 -05007651 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007652 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007653 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007654
7655 /* packets to our adapter go through */
7656 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7657 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007658
Peter Jones90700fd2005-08-26 16:51:06 -05007659 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007660 /* packets from our adapter are dropped (echo) */
7661 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7662 return 0;
7663
Peter Jones90700fd2005-08-26 16:51:06 -05007664 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007665 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007666 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7667
7668 /* packets to our adapter go through */
7669 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7670 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007671 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007672
James Ketrenosea2b26e2005-08-24 21:25:16 -05007673 return 1;
7674}
7675
James Ketrenosafbf30a2005-08-25 00:05:33 -05007676#define IPW_PACKET_RETRY_TIME HZ
7677
Arjan van de Ven858119e2006-01-14 13:20:43 -08007678static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007679 struct ieee80211_hdr_4addr *header)
7680{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007681 u16 sc = le16_to_cpu(header->seq_ctl);
7682 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7683 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7684 u16 *last_seq, *last_frag;
7685 unsigned long *last_time;
7686
7687 switch (priv->ieee->iw_mode) {
7688 case IW_MODE_ADHOC:
7689 {
7690 struct list_head *p;
7691 struct ipw_ibss_seq *entry = NULL;
7692 u8 *mac = header->addr2;
7693 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7694
7695 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7696 entry =
7697 list_entry(p, struct ipw_ibss_seq, list);
7698 if (!memcmp(entry->mac, mac, ETH_ALEN))
7699 break;
7700 }
7701 if (p == &priv->ibss_mac_hash[index]) {
7702 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7703 if (!entry) {
7704 IPW_ERROR
7705 ("Cannot malloc new mac entry\n");
7706 return 0;
7707 }
7708 memcpy(entry->mac, mac, ETH_ALEN);
7709 entry->seq_num = seq;
7710 entry->frag_num = frag;
7711 entry->packet_time = jiffies;
7712 list_add(&entry->list,
7713 &priv->ibss_mac_hash[index]);
7714 return 0;
7715 }
7716 last_seq = &entry->seq_num;
7717 last_frag = &entry->frag_num;
7718 last_time = &entry->packet_time;
7719 break;
7720 }
7721 case IW_MODE_INFRA:
7722 last_seq = &priv->last_seq_num;
7723 last_frag = &priv->last_frag_num;
7724 last_time = &priv->last_packet_time;
7725 break;
7726 default:
7727 return 0;
7728 }
7729 if ((*last_seq == seq) &&
7730 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7731 if (*last_frag == frag)
7732 goto drop;
7733 if (*last_frag + 1 != frag)
7734 /* out-of-order fragment */
7735 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007736 } else
7737 *last_seq = seq;
7738
Zhu Yif57ce7c2005-07-13 12:22:15 -05007739 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007740 *last_time = jiffies;
7741 return 0;
7742
7743 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007744 /* Comment this line now since we observed the card receives
7745 * duplicate packets but the FCTL_RETRY bit is not set in the
7746 * IBSS mode with fragmentation enabled.
7747 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007748 return 1;
7749}
7750
James Ketrenosb095c382005-08-24 22:04:42 -05007751static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7752 struct ipw_rx_mem_buffer *rxb,
7753 struct ieee80211_rx_stats *stats)
7754{
7755 struct sk_buff *skb = rxb->skb;
7756 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7757 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7758 (skb->data + IPW_RX_FRAME_SIZE);
7759
7760 ieee80211_rx_mgt(priv->ieee, header, stats);
7761
7762 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7763 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7764 IEEE80211_STYPE_PROBE_RESP) ||
7765 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7766 IEEE80211_STYPE_BEACON))) {
7767 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7768 ipw_add_station(priv, header->addr2);
7769 }
7770
7771 if (priv->config & CFG_NET_STATS) {
7772 IPW_DEBUG_HC("sending stat packet\n");
7773
7774 /* Set the size of the skb to the size of the full
7775 * ipw header and 802.11 frame */
7776 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7777 IPW_RX_FRAME_SIZE);
7778
7779 /* Advance past the ipw packet header to the 802.11 frame */
7780 skb_pull(skb, IPW_RX_FRAME_SIZE);
7781
7782 /* Push the ieee80211_rx_stats before the 802.11 frame */
7783 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7784
7785 skb->dev = priv->ieee->dev;
7786
7787 /* Point raw at the ieee80211_stats */
7788 skb->mac.raw = skb->data;
7789
7790 skb->pkt_type = PACKET_OTHERHOST;
7791 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7792 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7793 netif_rx(skb);
7794 rxb->skb = NULL;
7795 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007796}
7797
James Ketrenos43f66a62005-03-25 12:31:53 -06007798/*
7799 * Main entry function for recieving a packet with 80211 headers. This
7800 * should be called when ever the FW has notified us that there is a new
7801 * skb in the recieve queue.
7802 */
7803static void ipw_rx(struct ipw_priv *priv)
7804{
7805 struct ipw_rx_mem_buffer *rxb;
7806 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007807 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007808 u32 r, w, i;
7809 u8 network_packet;
7810
James Ketrenosb095c382005-08-24 22:04:42 -05007811 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7812 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007813 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7814
7815 while (i != r) {
7816 rxb = priv->rxq->queue[i];
Brice Goglin0f52bf92005-12-01 01:41:46 -08007817#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06007818 if (unlikely(rxb == NULL)) {
7819 printk(KERN_CRIT "Queue not allocated!\n");
7820 break;
7821 }
7822#endif
7823 priv->rxq->queue[i] = NULL;
7824
7825 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007826 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007827 PCI_DMA_FROMDEVICE);
7828
7829 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7830 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7831 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007832 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007833
7834 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007835 case RX_FRAME_TYPE: /* 802.11 frame */ {
7836 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007837 .rssi =
7838 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007839 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007840 .signal =
7841 le16_to_cpu(pkt->u.frame.signal),
7842 .noise =
7843 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007844 .rate = pkt->u.frame.rate,
7845 .mac_time = jiffies,
7846 .received_channel =
7847 pkt->u.frame.received_channel,
7848 .freq =
7849 (pkt->u.frame.
7850 control & (1 << 0)) ?
7851 IEEE80211_24GHZ_BAND :
7852 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007853 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007854 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007855
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007856 if (stats.rssi != 0)
7857 stats.mask |= IEEE80211_STATMASK_RSSI;
7858 if (stats.signal != 0)
7859 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007860 if (stats.noise != 0)
7861 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007862 if (stats.rate != 0)
7863 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007864
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007865 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007866
James Ketrenosb095c382005-08-24 22:04:42 -05007867#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007868 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007869#ifdef CONFIG_IEEE80211_RADIOTAP
7870 ipw_handle_data_packet_monitor(priv,
7871 rxb,
7872 &stats);
7873#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007874 ipw_handle_data_packet(priv, rxb,
7875 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007876#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007877 break;
7878 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007879#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007880
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007881 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007882 (struct ieee80211_hdr_4addr *)(rxb->skb->
7883 data +
7884 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007885 /* TODO: Check Ad-Hoc dest/source and make sure
7886 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007887 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007888 * frame control of the packet and disregard
7889 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007890
James Ketrenosea2b26e2005-08-24 21:25:16 -05007891 network_packet =
7892 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007893 if (network_packet && priv->assoc_network) {
7894 priv->assoc_network->stats.rssi =
7895 stats.rssi;
7896 average_add(&priv->average_rssi,
7897 stats.rssi);
7898 priv->last_rx_rssi = stats.rssi;
7899 }
7900
7901 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007902 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007903
James Ketrenosa613bff2005-08-24 21:43:11 -05007904 if (le16_to_cpu(pkt->u.frame.length) <
7905 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007906 IPW_DEBUG_DROP
7907 ("Received packet is too small. "
7908 "Dropping.\n");
7909 priv->ieee->stats.rx_errors++;
7910 priv->wstats.discard.misc++;
7911 break;
7912 }
7913
James Ketrenosa613bff2005-08-24 21:43:11 -05007914 switch (WLAN_FC_GET_TYPE
7915 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007917 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007918 ipw_handle_mgmt_packet(priv, rxb,
7919 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007920 break;
7921
7922 case IEEE80211_FTYPE_CTL:
7923 break;
7924
7925 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007926 if (unlikely(!network_packet ||
7927 is_duplicate_packet(priv,
7928 header)))
7929 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007930 IPW_DEBUG_DROP("Dropping: "
7931 MAC_FMT ", "
7932 MAC_FMT ", "
7933 MAC_FMT "\n",
7934 MAC_ARG(header->
7935 addr1),
7936 MAC_ARG(header->
7937 addr2),
7938 MAC_ARG(header->
7939 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05007940 break;
7941 }
7942
7943 ipw_handle_data_packet(priv, rxb,
7944 &stats);
7945
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007946 break;
7947 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007948 break;
7949 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007950
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007951 case RX_HOST_NOTIFICATION_TYPE:{
7952 IPW_DEBUG_RX
7953 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007954 pkt->u.notification.subtype,
7955 pkt->u.notification.flags,
7956 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007957 ipw_rx_notification(priv, &pkt->u.notification);
7958 break;
7959 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007960
7961 default:
7962 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7963 pkt->header.message_type);
7964 break;
7965 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007966
7967 /* For now we just don't re-use anything. We can tweak this
7968 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06007969 * fail to Rx correctly */
7970 if (rxb->skb != NULL) {
7971 dev_kfree_skb_any(rxb->skb);
7972 rxb->skb = NULL;
7973 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007974
James Ketrenos43f66a62005-03-25 12:31:53 -06007975 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007976 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007977 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04007978
James Ketrenos43f66a62005-03-25 12:31:53 -06007979 i = (i + 1) % RX_QUEUE_SIZE;
7980 }
7981
7982 /* Backtrack one entry */
7983 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7984
7985 ipw_rx_queue_restock(priv);
7986}
7987
James Ketrenosafbf30a2005-08-25 00:05:33 -05007988#define DEFAULT_RTS_THRESHOLD 2304U
7989#define MIN_RTS_THRESHOLD 1U
7990#define MAX_RTS_THRESHOLD 2304U
7991#define DEFAULT_BEACON_INTERVAL 100U
7992#define DEFAULT_SHORT_RETRY_LIMIT 7U
7993#define DEFAULT_LONG_RETRY_LIMIT 4U
7994
7995static int ipw_sw_reset(struct ipw_priv *priv, int init)
James Ketrenos43f66a62005-03-25 12:31:53 -06007996{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007997 int band, modulation;
7998 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06007999
James Ketrenosafbf30a2005-08-25 00:05:33 -05008000 /* Initialize module parameter values here */
8001 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008002
James Ketrenosafbf30a2005-08-25 00:05:33 -05008003 /* We default to disabling the LED code as right now it causes
8004 * too many systems to lock up... */
8005 if (!led)
8006 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008007
James Ketrenosafbf30a2005-08-25 00:05:33 -05008008 if (associate)
8009 priv->config |= CFG_ASSOCIATE;
8010 else
8011 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008012
James Ketrenosafbf30a2005-08-25 00:05:33 -05008013 if (auto_create)
8014 priv->config |= CFG_ADHOC_CREATE;
8015 else
8016 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8017
Zhu Yi17ed0812006-01-24 16:36:31 +08008018 priv->config &= ~CFG_STATIC_ESSID;
8019 priv->essid_len = 0;
8020 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8021
James Ketrenosafbf30a2005-08-25 00:05:33 -05008022 if (disable) {
8023 priv->status |= STATUS_RF_KILL_SW;
8024 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008025 }
8026
James Ketrenosafbf30a2005-08-25 00:05:33 -05008027 if (channel != 0) {
8028 priv->config |= CFG_STATIC_CHANNEL;
8029 priv->channel = channel;
8030 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8031 /* TODO: Validate that provided channel is in range */
8032 }
8033#ifdef CONFIG_IPW_QOS
8034 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8035 burst_duration_CCK, burst_duration_OFDM);
8036#endif /* CONFIG_IPW_QOS */
8037
8038 switch (mode) {
8039 case 1:
8040 priv->ieee->iw_mode = IW_MODE_ADHOC;
8041 priv->net_dev->type = ARPHRD_ETHER;
8042
8043 break;
8044#ifdef CONFIG_IPW2200_MONITOR
8045 case 2:
8046 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008047#ifdef CONFIG_IEEE80211_RADIOTAP
8048 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8049#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008050 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008051#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008052 break;
8053#endif
8054 default:
8055 case 0:
8056 priv->net_dev->type = ARPHRD_ETHER;
8057 priv->ieee->iw_mode = IW_MODE_INFRA;
8058 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008059 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008060
James Ketrenosafbf30a2005-08-25 00:05:33 -05008061 if (hwcrypto) {
8062 priv->ieee->host_encrypt = 0;
8063 priv->ieee->host_encrypt_msdu = 0;
8064 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008065 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008066 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008067 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008068
Zhu Yie402c932005-08-05 17:20:40 +08008069 /* IPW2200/2915 is abled to do hardware fragmentation. */
8070 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008071
James Ketrenosafbf30a2005-08-25 00:05:33 -05008072 if ((priv->pci_dev->device == 0x4223) ||
8073 (priv->pci_dev->device == 0x4224)) {
8074 if (init)
8075 printk(KERN_INFO DRV_NAME
8076 ": Detected Intel PRO/Wireless 2915ABG Network "
8077 "Connection\n");
8078 priv->ieee->abg_true = 1;
8079 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8080 modulation = IEEE80211_OFDM_MODULATION |
8081 IEEE80211_CCK_MODULATION;
8082 priv->adapter = IPW_2915ABG;
8083 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008084 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008085 if (init)
8086 printk(KERN_INFO DRV_NAME
8087 ": Detected Intel PRO/Wireless 2200BG Network "
8088 "Connection\n");
8089
8090 priv->ieee->abg_true = 0;
8091 band = IEEE80211_24GHZ_BAND;
8092 modulation = IEEE80211_OFDM_MODULATION |
8093 IEEE80211_CCK_MODULATION;
8094 priv->adapter = IPW_2200BG;
8095 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008096 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008097
James Ketrenosafbf30a2005-08-25 00:05:33 -05008098 priv->ieee->freq_band = band;
8099 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008100
James Ketrenosafbf30a2005-08-25 00:05:33 -05008101 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008102
James Ketrenosafbf30a2005-08-25 00:05:33 -05008103 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8104 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008105
James Ketrenosafbf30a2005-08-25 00:05:33 -05008106 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8107 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8108 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008109
James Ketrenosafbf30a2005-08-25 00:05:33 -05008110 /* If power management is turned on, default to AC mode */
8111 priv->power_mode = IPW_POWER_AC;
8112 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008113
Zhu Yi0ece35b2005-08-05 17:26:51 +08008114 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008115}
8116
8117/*
8118 * This file defines the Wireless Extension handlers. It does not
8119 * define any methods of hardware manipulation and relies on the
8120 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008121 *
8122 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008123 * function used to poll the hardware vs. making unecessary calls.
8124 *
8125 */
8126
Jeff Garzikbf794512005-07-31 13:07:26 -04008127static int ipw_wx_get_name(struct net_device *dev,
8128 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008129 union iwreq_data *wrqu, char *extra)
8130{
8131 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008132 down(&priv->sem);
8133 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008134 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008135 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008136 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008137 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008138 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8139 ipw_modes[priv->assoc_request.ieee_mode]);
8140 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008141 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008142 return 0;
8143}
8144
8145static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8146{
8147 if (channel == 0) {
8148 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8149 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008150 IPW_DEBUG_ASSOC("Attempting to associate with new "
8151 "parameters.\n");
8152 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008153 return 0;
8154 }
8155
8156 priv->config |= CFG_STATIC_CHANNEL;
8157
8158 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008159 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8160 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008161 return 0;
8162 }
8163
8164 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8165 priv->channel = channel;
8166
James Ketrenosb095c382005-08-24 22:04:42 -05008167#ifdef CONFIG_IPW2200_MONITOR
8168 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008169 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008170 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008171 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008172 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008173 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008174 }
8175
8176 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8177 udelay(10);
8178
8179 if (priv->status & STATUS_SCANNING)
8180 IPW_DEBUG_SCAN("Still scanning...\n");
8181 else
8182 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8183 1000 - i);
8184
8185 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008186 }
James Ketrenosb095c382005-08-24 22:04:42 -05008187#endif /* CONFIG_IPW2200_MONITOR */
8188
James Ketrenosc848d0a2005-08-24 21:56:24 -05008189 /* Network configuration changed -- force [re]association */
8190 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8191 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008192 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008193
8194 return 0;
8195}
8196
Jeff Garzikbf794512005-07-31 13:07:26 -04008197static int ipw_wx_set_freq(struct net_device *dev,
8198 struct iw_request_info *info,
8199 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008200{
8201 struct ipw_priv *priv = ieee80211_priv(dev);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008202 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008203 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008204 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008205 u8 channel, flags;
8206 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008207
James Ketrenosb095c382005-08-24 22:04:42 -05008208 if (fwrq->m == 0) {
8209 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8210 down(&priv->sem);
8211 ret = ipw_set_channel(priv, 0);
8212 up(&priv->sem);
8213 return ret;
8214 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008215 /* if setting by freq convert to channel */
8216 if (fwrq->e == 1) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05008217 channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008218 if (channel == 0)
8219 return -EINVAL;
8220 } else
8221 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008222
Liu Hong1fe0adb2005-08-19 09:33:10 -05008223 if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008224 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008225
Liu Hong1fe0adb2005-08-19 09:33:10 -05008226 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8227 i = ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008228 if (i == -1)
8229 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008230
8231 flags = (band == IEEE80211_24GHZ_BAND) ?
8232 geo->bg[i].flags : geo->a[i].flags;
8233 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008234 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8235 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008236 }
8237 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008238
James Ketrenos43f66a62005-03-25 12:31:53 -06008239 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008240 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008241 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008242 up(&priv->sem);
8243 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008244}
8245
Jeff Garzikbf794512005-07-31 13:07:26 -04008246static int ipw_wx_get_freq(struct net_device *dev,
8247 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008248 union iwreq_data *wrqu, char *extra)
8249{
8250 struct ipw_priv *priv = ieee80211_priv(dev);
8251
8252 wrqu->freq.e = 0;
8253
8254 /* If we are associated, trying to associate, or have a statically
8255 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008256 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008257 if (priv->config & CFG_STATIC_CHANNEL ||
8258 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8259 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008260 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008261 wrqu->freq.m = 0;
8262
James Ketrenosc848d0a2005-08-24 21:56:24 -05008263 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008264 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8265 return 0;
8266}
8267
Jeff Garzikbf794512005-07-31 13:07:26 -04008268static int ipw_wx_set_mode(struct net_device *dev,
8269 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008270 union iwreq_data *wrqu, char *extra)
8271{
8272 struct ipw_priv *priv = ieee80211_priv(dev);
8273 int err = 0;
8274
8275 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8276
James Ketrenos43f66a62005-03-25 12:31:53 -06008277 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008278#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008279 case IW_MODE_MONITOR:
8280#endif
8281 case IW_MODE_ADHOC:
8282 case IW_MODE_INFRA:
8283 break;
8284 case IW_MODE_AUTO:
8285 wrqu->mode = IW_MODE_INFRA;
8286 break;
8287 default:
8288 return -EINVAL;
8289 }
James Ketrenosb095c382005-08-24 22:04:42 -05008290 if (wrqu->mode == priv->ieee->iw_mode)
8291 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008292
James Ketrenosb095c382005-08-24 22:04:42 -05008293 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008294
8295 ipw_sw_reset(priv, 0);
8296
James Ketrenosb095c382005-08-24 22:04:42 -05008297#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008298 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008299 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008300
8301 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008302#ifdef CONFIG_IEEE80211_RADIOTAP
8303 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8304#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008305 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008306#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008307#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008308
Jeff Garzikbf794512005-07-31 13:07:26 -04008309 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008310 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008311 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008312
8313 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008314
James Ketrenosc848d0a2005-08-24 21:56:24 -05008315 queue_work(priv->workqueue, &priv->adapter_restart);
8316 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008317 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008318}
8319
Jeff Garzikbf794512005-07-31 13:07:26 -04008320static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008321 struct iw_request_info *info,
8322 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008323{
8324 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008325 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008326 wrqu->mode = priv->ieee->iw_mode;
8327 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008328 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008329 return 0;
8330}
8331
James Ketrenos43f66a62005-03-25 12:31:53 -06008332/* Values are in microsecond */
8333static const s32 timeout_duration[] = {
8334 350000,
8335 250000,
8336 75000,
8337 37000,
8338 25000,
8339};
8340
8341static const s32 period_duration[] = {
8342 400000,
8343 700000,
8344 1000000,
8345 1000000,
8346 1000000
8347};
8348
Jeff Garzikbf794512005-07-31 13:07:26 -04008349static int ipw_wx_get_range(struct net_device *dev,
8350 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008351 union iwreq_data *wrqu, char *extra)
8352{
8353 struct ipw_priv *priv = ieee80211_priv(dev);
8354 struct iw_range *range = (struct iw_range *)extra;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008355 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008356 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008357
8358 wrqu->data.length = sizeof(*range);
8359 memset(range, 0, sizeof(*range));
8360
8361 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008362 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008363
8364 range->max_qual.qual = 100;
8365 /* TODO: Find real max RSSI and stick here */
8366 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008367 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008368 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008369
8370 range->avg_qual.qual = 70;
8371 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008372 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008373 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008374 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008375 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008376 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008377
Jeff Garzikbf794512005-07-31 13:07:26 -04008378 for (i = 0; i < range->num_bitrates; i++)
8379 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008380 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008381
James Ketrenos43f66a62005-03-25 12:31:53 -06008382 range->max_rts = DEFAULT_RTS_THRESHOLD;
8383 range->min_frag = MIN_FRAG_THRESHOLD;
8384 range->max_frag = MAX_FRAG_THRESHOLD;
8385
8386 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008387 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008388 range->num_encoding_sizes = 2;
8389 range->max_encoding_tokens = WEP_KEYS;
8390
8391 /* Set the Wireless Extension versions */
8392 range->we_version_compiled = WIRELESS_EXT;
8393 range->we_version_source = 16;
8394
James Ketrenosb095c382005-08-24 22:04:42 -05008395 i = 0;
8396 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8397 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8398 i++, j++) {
8399 range->freq[i].i = geo->bg[j].channel;
8400 range->freq[i].m = geo->bg[j].freq * 100000;
8401 range->freq[i].e = 1;
8402 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008403 }
James Ketrenosb095c382005-08-24 22:04:42 -05008404
8405 if (priv->ieee->mode & IEEE_A) {
8406 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8407 i++, j++) {
8408 range->freq[i].i = geo->a[j].channel;
8409 range->freq[i].m = geo->a[j].freq * 100000;
8410 range->freq[i].e = 1;
8411 }
8412 }
8413
8414 range->num_channels = i;
8415 range->num_frequency = i;
8416
James Ketrenosc848d0a2005-08-24 21:56:24 -05008417 up(&priv->sem);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008418
8419 /* Event capability (kernel + driver) */
8420 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8421 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8422 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8423 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008424
8425 IPW_DEBUG_WX("GET Range\n");
8426 return 0;
8427}
8428
Jeff Garzikbf794512005-07-31 13:07:26 -04008429static int ipw_wx_set_wap(struct net_device *dev,
8430 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008431 union iwreq_data *wrqu, char *extra)
8432{
8433 struct ipw_priv *priv = ieee80211_priv(dev);
8434
8435 static const unsigned char any[] = {
8436 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8437 };
8438 static const unsigned char off[] = {
8439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8440 };
8441
Jeff Garzikbf794512005-07-31 13:07:26 -04008442 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008443 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008444 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008445 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8446 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8447 /* we disable mandatory BSSID association */
8448 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8449 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008450 IPW_DEBUG_ASSOC("Attempting to associate with new "
8451 "parameters.\n");
8452 ipw_associate(priv);
8453 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008454 return 0;
8455 }
8456
8457 priv->config |= CFG_STATIC_BSSID;
8458 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8459 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008460 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008461 return 0;
8462 }
8463
8464 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8465 MAC_ARG(wrqu->ap_addr.sa_data));
8466
8467 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8468
James Ketrenosc848d0a2005-08-24 21:56:24 -05008469 /* Network configuration changed -- force [re]association */
8470 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8471 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008472 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008473
James Ketrenosc848d0a2005-08-24 21:56:24 -05008474 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008475 return 0;
8476}
8477
Jeff Garzikbf794512005-07-31 13:07:26 -04008478static int ipw_wx_get_wap(struct net_device *dev,
8479 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008480 union iwreq_data *wrqu, char *extra)
8481{
8482 struct ipw_priv *priv = ieee80211_priv(dev);
8483 /* If we are associated, trying to associate, or have a statically
8484 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008485 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008486 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008487 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8488 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008489 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008490 } else
8491 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8492
8493 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8494 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008495 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008496 return 0;
8497}
8498
Jeff Garzikbf794512005-07-31 13:07:26 -04008499static int ipw_wx_set_essid(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);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008504 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008506 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008507 if (wrqu->essid.flags && wrqu->essid.length) {
8508 length = wrqu->essid.length - 1;
8509 essid = extra;
8510 }
8511 if (length == 0) {
8512 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008513 if ((priv->config & CFG_STATIC_ESSID) &&
8514 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008515 STATUS_ASSOCIATING))) {
8516 IPW_DEBUG_ASSOC("Attempting to associate with new "
8517 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008518 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008519 ipw_associate(priv);
8520 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008521 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008522 return 0;
8523 }
8524
8525 length = min(length, IW_ESSID_MAX_SIZE);
8526
8527 priv->config |= CFG_STATIC_ESSID;
8528
8529 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8530 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008531 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008532 return 0;
8533 }
8534
8535 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8536 length);
8537
8538 priv->essid_len = length;
8539 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008540
James Ketrenosc848d0a2005-08-24 21:56:24 -05008541 /* Network configuration changed -- force [re]association */
8542 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8543 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008544 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008545
James Ketrenosc848d0a2005-08-24 21:56:24 -05008546 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008547 return 0;
8548}
8549
Jeff Garzikbf794512005-07-31 13:07:26 -04008550static int ipw_wx_get_essid(struct net_device *dev,
8551 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008552 union iwreq_data *wrqu, char *extra)
8553{
8554 struct ipw_priv *priv = ieee80211_priv(dev);
8555
8556 /* If we are associated, trying to associate, or have a statically
8557 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008558 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008559 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008560 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8561 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008563 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008564 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008565 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008566 } else {
8567 IPW_DEBUG_WX("Getting essid: ANY\n");
8568 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008569 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008570 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008571 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008572 return 0;
8573}
8574
Jeff Garzikbf794512005-07-31 13:07:26 -04008575static int ipw_wx_set_nick(struct net_device *dev,
8576 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008578{
James Ketrenos43f66a62005-03-25 12:31:53 -06008579 struct ipw_priv *priv = ieee80211_priv(dev);
8580
8581 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8582 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8583 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008584 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008585 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008586 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008587 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008588 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008589 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008590 return 0;
8591
8592}
8593
Jeff Garzikbf794512005-07-31 13:07:26 -04008594static int ipw_wx_get_nick(struct net_device *dev,
8595 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008597{
James Ketrenos43f66a62005-03-25 12:31:53 -06008598 struct ipw_priv *priv = ieee80211_priv(dev);
8599 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008600 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008601 wrqu->data.length = strlen(priv->nick) + 1;
8602 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008603 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008604 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008605 return 0;
8606}
8607
James Ketrenos43f66a62005-03-25 12:31:53 -06008608static int ipw_wx_set_rate(struct net_device *dev,
8609 struct iw_request_info *info,
8610 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008611{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008612 /* TODO: We should use semaphores or locks for access to priv */
8613 struct ipw_priv *priv = ieee80211_priv(dev);
8614 u32 target_rate = wrqu->bitrate.value;
8615 u32 fixed, mask;
8616
8617 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8618 /* value = X, fixed = 1 means only rate X */
8619 /* value = X, fixed = 0 means all rates lower equal X */
8620
8621 if (target_rate == -1) {
8622 fixed = 0;
8623 mask = IEEE80211_DEFAULT_RATES_MASK;
8624 /* Now we should reassociate */
8625 goto apply;
8626 }
8627
8628 mask = 0;
8629 fixed = wrqu->bitrate.fixed;
8630
8631 if (target_rate == 1000000 || !fixed)
8632 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8633 if (target_rate == 1000000)
8634 goto apply;
8635
8636 if (target_rate == 2000000 || !fixed)
8637 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8638 if (target_rate == 2000000)
8639 goto apply;
8640
8641 if (target_rate == 5500000 || !fixed)
8642 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8643 if (target_rate == 5500000)
8644 goto apply;
8645
8646 if (target_rate == 6000000 || !fixed)
8647 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8648 if (target_rate == 6000000)
8649 goto apply;
8650
8651 if (target_rate == 9000000 || !fixed)
8652 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8653 if (target_rate == 9000000)
8654 goto apply;
8655
8656 if (target_rate == 11000000 || !fixed)
8657 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8658 if (target_rate == 11000000)
8659 goto apply;
8660
8661 if (target_rate == 12000000 || !fixed)
8662 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8663 if (target_rate == 12000000)
8664 goto apply;
8665
8666 if (target_rate == 18000000 || !fixed)
8667 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8668 if (target_rate == 18000000)
8669 goto apply;
8670
8671 if (target_rate == 24000000 || !fixed)
8672 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8673 if (target_rate == 24000000)
8674 goto apply;
8675
8676 if (target_rate == 36000000 || !fixed)
8677 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8678 if (target_rate == 36000000)
8679 goto apply;
8680
8681 if (target_rate == 48000000 || !fixed)
8682 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8683 if (target_rate == 48000000)
8684 goto apply;
8685
8686 if (target_rate == 54000000 || !fixed)
8687 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8688 if (target_rate == 54000000)
8689 goto apply;
8690
8691 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8692 return -EINVAL;
8693
8694 apply:
8695 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8696 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008697 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008698 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008699 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008700 ipw_set_fixed_rate(priv, priv->ieee->mode);
8701 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008702 priv->config |= CFG_FIXED_RATE;
8703
James Ketrenosc848d0a2005-08-24 21:56:24 -05008704 if (priv->rates_mask == mask) {
8705 IPW_DEBUG_WX("Mask set to current mask.\n");
8706 up(&priv->sem);
8707 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008708 }
8709
James Ketrenosc848d0a2005-08-24 21:56:24 -05008710 priv->rates_mask = mask;
8711
8712 /* Network configuration changed -- force [re]association */
8713 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8714 if (!ipw_disassociate(priv))
8715 ipw_associate(priv);
8716
8717 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008718 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008719}
8720
Jeff Garzikbf794512005-07-31 13:07:26 -04008721static int ipw_wx_get_rate(struct net_device *dev,
8722 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008723 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008724{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008725 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008726 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008727 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008728 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008729 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8730 return 0;
8731}
8732
Jeff Garzikbf794512005-07-31 13:07:26 -04008733static int ipw_wx_set_rts(struct net_device *dev,
8734 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008735 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008736{
James Ketrenos43f66a62005-03-25 12:31:53 -06008737 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008738 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 if (wrqu->rts.disabled)
8740 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8741 else {
8742 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008743 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8744 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008745 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008746 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008747 priv->rts_threshold = wrqu->rts.value;
8748 }
8749
8750 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008751 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008752 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8753 return 0;
8754}
8755
Jeff Garzikbf794512005-07-31 13:07:26 -04008756static int ipw_wx_get_rts(struct net_device *dev,
8757 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008758 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008759{
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008761 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008762 wrqu->rts.value = priv->rts_threshold;
8763 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008764 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008765 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008766 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8767 return 0;
8768}
8769
Jeff Garzikbf794512005-07-31 13:07:26 -04008770static int ipw_wx_set_txpow(struct net_device *dev,
8771 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008773{
James Ketrenos43f66a62005-03-25 12:31:53 -06008774 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008775 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008776
James Ketrenosc848d0a2005-08-24 21:56:24 -05008777 down(&priv->sem);
8778 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008779 err = -EINPROGRESS;
8780 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008781 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008782
James Ketrenosb095c382005-08-24 22:04:42 -05008783 if (!wrqu->power.fixed)
8784 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008785
James Ketrenosc848d0a2005-08-24 21:56:24 -05008786 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008787 err = -EINVAL;
8788 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008789 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008790
James Ketrenosb095c382005-08-24 22:04:42 -05008791 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008792 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008793 err = -EINVAL;
8794 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008795 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008796
8797 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008798 err = ipw_set_tx_power(priv);
8799 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008800 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008801 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008802}
8803
Jeff Garzikbf794512005-07-31 13:07:26 -04008804static int ipw_wx_get_txpow(struct net_device *dev,
8805 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008806 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008807{
James Ketrenos43f66a62005-03-25 12:31:53 -06008808 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008809 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 wrqu->power.value = priv->tx_power;
8811 wrqu->power.fixed = 1;
8812 wrqu->power.flags = IW_TXPOW_DBM;
8813 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008814 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008815
Jeff Garzikbf794512005-07-31 13:07:26 -04008816 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008817 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008818
8819 return 0;
8820}
8821
Jeff Garzikbf794512005-07-31 13:07:26 -04008822static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008823 struct iw_request_info *info,
8824 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008825{
8826 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008827 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 if (wrqu->frag.disabled)
8829 priv->ieee->fts = DEFAULT_FTS;
8830 else {
8831 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008832 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8833 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008834 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008835 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008836
James Ketrenos43f66a62005-03-25 12:31:53 -06008837 priv->ieee->fts = wrqu->frag.value & ~0x1;
8838 }
8839
8840 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008841 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8843 return 0;
8844}
8845
Jeff Garzikbf794512005-07-31 13:07:26 -04008846static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008847 struct iw_request_info *info,
8848 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008849{
8850 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008851 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 wrqu->frag.value = priv->ieee->fts;
8853 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008854 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008855 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008856 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8857
8858 return 0;
8859}
8860
Jeff Garzikbf794512005-07-31 13:07:26 -04008861static int ipw_wx_set_retry(struct net_device *dev,
8862 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008863 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008864{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008865 struct ipw_priv *priv = ieee80211_priv(dev);
8866
8867 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8868 return -EINVAL;
8869
8870 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8871 return 0;
8872
8873 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8874 return -EINVAL;
8875
8876 down(&priv->sem);
8877 if (wrqu->retry.flags & IW_RETRY_MIN)
8878 priv->short_retry_limit = (u8) wrqu->retry.value;
8879 else if (wrqu->retry.flags & IW_RETRY_MAX)
8880 priv->long_retry_limit = (u8) wrqu->retry.value;
8881 else {
8882 priv->short_retry_limit = (u8) wrqu->retry.value;
8883 priv->long_retry_limit = (u8) wrqu->retry.value;
8884 }
8885
8886 ipw_send_retry_limit(priv, priv->short_retry_limit,
8887 priv->long_retry_limit);
8888 up(&priv->sem);
8889 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8890 priv->short_retry_limit, priv->long_retry_limit);
8891 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008892}
8893
Jeff Garzikbf794512005-07-31 13:07:26 -04008894static int ipw_wx_get_retry(struct net_device *dev,
8895 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008896 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008897{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008898 struct ipw_priv *priv = ieee80211_priv(dev);
8899
8900 down(&priv->sem);
8901 wrqu->retry.disabled = 0;
8902
8903 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8904 up(&priv->sem);
8905 return -EINVAL;
8906 }
8907
8908 if (wrqu->retry.flags & IW_RETRY_MAX) {
8909 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8910 wrqu->retry.value = priv->long_retry_limit;
8911 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8912 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8913 wrqu->retry.value = priv->short_retry_limit;
8914 } else {
8915 wrqu->retry.flags = IW_RETRY_LIMIT;
8916 wrqu->retry.value = priv->short_retry_limit;
8917 }
8918 up(&priv->sem);
8919
8920 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8921
8922 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008923}
8924
James Ketrenosafbf30a2005-08-25 00:05:33 -05008925static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8926 int essid_len)
8927{
8928 struct ipw_scan_request_ext scan;
8929 int err = 0, scan_type;
8930
Pekka Enbergefb34422005-11-16 21:55:05 +02008931 if (!(priv->status & STATUS_INIT) ||
8932 (priv->status & STATUS_EXIT_PENDING))
8933 return 0;
8934
James Ketrenosafbf30a2005-08-25 00:05:33 -05008935 down(&priv->sem);
8936
8937 if (priv->status & STATUS_RF_KILL_MASK) {
8938 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8939 priv->status |= STATUS_SCAN_PENDING;
8940 goto done;
8941 }
8942
8943 IPW_DEBUG_HC("starting request direct scan!\n");
8944
8945 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01008946 /* We should not sleep here; otherwise we will block most
8947 * of the system (for instance, we hold rtnl_lock when we
8948 * get here).
8949 */
8950 err = -EAGAIN;
8951 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008952 }
8953 memset(&scan, 0, sizeof(scan));
8954
8955 if (priv->config & CFG_SPEED_SCAN)
8956 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8957 cpu_to_le16(30);
8958 else
8959 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8960 cpu_to_le16(20);
8961
8962 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8963 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008964 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008965 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8966
8967 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8968
8969 err = ipw_send_ssid(priv, essid, essid_len);
8970 if (err) {
8971 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8972 goto done;
8973 }
8974 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8975
8976 ipw_add_scan_channels(priv, &scan, scan_type);
8977
8978 err = ipw_send_scan_request_ext(priv, &scan);
8979 if (err) {
8980 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8981 goto done;
8982 }
8983
8984 priv->status |= STATUS_SCANNING;
8985
8986 done:
8987 up(&priv->sem);
8988 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008989}
8990
Jeff Garzikbf794512005-07-31 13:07:26 -04008991static int ipw_wx_set_scan(struct net_device *dev,
8992 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008993 union iwreq_data *wrqu, char *extra)
8994{
8995 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008996 struct iw_scan_req *req = NULL;
8997 if (wrqu->data.length
8998 && wrqu->data.length == sizeof(struct iw_scan_req)) {
8999 req = (struct iw_scan_req *)extra;
9000 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9001 ipw_request_direct_scan(priv, req->essid,
9002 req->essid_len);
9003 return 0;
9004 }
9005 }
James Ketrenos8935f392005-10-05 15:59:08 -05009006
James Ketrenos43f66a62005-03-25 12:31:53 -06009007 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009008
9009 queue_work(priv->workqueue, &priv->request_scan);
9010
James Ketrenos43f66a62005-03-25 12:31:53 -06009011 return 0;
9012}
9013
Jeff Garzikbf794512005-07-31 13:07:26 -04009014static int ipw_wx_get_scan(struct net_device *dev,
9015 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009016 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009017{
James Ketrenos43f66a62005-03-25 12:31:53 -06009018 struct ipw_priv *priv = ieee80211_priv(dev);
9019 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9020}
9021
Jeff Garzikbf794512005-07-31 13:07:26 -04009022static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009023 struct iw_request_info *info,
9024 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009025{
9026 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009027 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009028 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009029
9030 down(&priv->sem);
9031 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009032
Hong Liucaeff812005-08-05 17:25:50 +08009033 /* In IBSS mode, we need to notify the firmware to update
9034 * the beacon info after we changed the capability. */
9035 if (cap != priv->capability &&
9036 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9037 priv->status & STATUS_ASSOCIATED)
9038 ipw_disassociate(priv);
9039
9040 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009041 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009042}
9043
Jeff Garzikbf794512005-07-31 13:07:26 -04009044static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009045 struct iw_request_info *info,
9046 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009047{
9048 struct ipw_priv *priv = ieee80211_priv(dev);
9049 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9050}
9051
Jeff Garzikbf794512005-07-31 13:07:26 -04009052static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009053 struct iw_request_info *info,
9054 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009055{
9056 struct ipw_priv *priv = ieee80211_priv(dev);
9057 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009058 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009059 if (wrqu->power.disabled) {
9060 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9061 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9062 if (err) {
9063 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009064 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009065 return err;
9066 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009067 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009068 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009070 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009071
9072 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009073 case IW_POWER_ON: /* If not specified */
9074 case IW_POWER_MODE: /* If set all mask */
9075 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009076 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009077 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009078 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9079 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009080 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009081 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009082 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009083
James Ketrenos43f66a62005-03-25 12:31:53 -06009084 /* If the user hasn't specified a power management mode yet, default
9085 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009086 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009087 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009088 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009089 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9090 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9091 if (err) {
9092 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009093 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009094 return err;
9095 }
9096
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009097 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009098 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009099 return 0;
9100}
9101
Jeff Garzikbf794512005-07-31 13:07:26 -04009102static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009103 struct iw_request_info *info,
9104 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009105{
9106 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009107 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009108 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009110 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009111 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009112
James Ketrenosc848d0a2005-08-24 21:56:24 -05009113 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009114 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009115
James Ketrenos43f66a62005-03-25 12:31:53 -06009116 return 0;
9117}
9118
Jeff Garzikbf794512005-07-31 13:07:26 -04009119static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009120 struct iw_request_info *info,
9121 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009122{
9123 struct ipw_priv *priv = ieee80211_priv(dev);
9124 int mode = *(int *)extra;
9125 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009126 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009127 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9128 mode = IPW_POWER_AC;
9129 priv->power_mode = mode;
9130 } else {
9131 priv->power_mode = IPW_POWER_ENABLED | mode;
9132 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009133
James Ketrenos43f66a62005-03-25 12:31:53 -06009134 if (priv->power_mode != mode) {
9135 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009136
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 if (err) {
9138 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009139 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 return err;
9141 }
9142 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009143 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 return 0;
9145}
9146
9147#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009148static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009149 struct iw_request_info *info,
9150 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009151{
9152 struct ipw_priv *priv = ieee80211_priv(dev);
9153 int level = IPW_POWER_LEVEL(priv->power_mode);
9154 char *p = extra;
9155
9156 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9157
9158 switch (level) {
9159 case IPW_POWER_AC:
9160 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9161 break;
9162 case IPW_POWER_BATTERY:
9163 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9164 break;
9165 default:
9166 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009167 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009168 timeout_duration[level - 1] / 1000,
9169 period_duration[level - 1] / 1000);
9170 }
9171
9172 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009173 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009174
9175 wrqu->data.length = p - extra + 1;
9176
9177 return 0;
9178}
9179
9180static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009181 struct iw_request_info *info,
9182 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009183{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009184 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009185 int mode = *(int *)extra;
9186 u8 band = 0, modulation = 0;
9187
9188 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009189 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009190 return -EINVAL;
9191 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009192 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009193 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009194 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009195 if (mode & IEEE_A) {
9196 band |= IEEE80211_52GHZ_BAND;
9197 modulation |= IEEE80211_OFDM_MODULATION;
9198 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009199 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009200 } else {
9201 if (mode & IEEE_A) {
9202 IPW_WARNING("Attempt to set 2200BG into "
9203 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009204 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009205 return -EINVAL;
9206 }
9207
James Ketrenosa33a1982005-09-14 14:28:59 -05009208 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009209 }
9210
9211 if (mode & IEEE_B) {
9212 band |= IEEE80211_24GHZ_BAND;
9213 modulation |= IEEE80211_CCK_MODULATION;
9214 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009215 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009216
James Ketrenos43f66a62005-03-25 12:31:53 -06009217 if (mode & IEEE_G) {
9218 band |= IEEE80211_24GHZ_BAND;
9219 modulation |= IEEE80211_OFDM_MODULATION;
9220 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009221 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009222
9223 priv->ieee->mode = mode;
9224 priv->ieee->freq_band = band;
9225 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009226 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009227
James Ketrenosc848d0a2005-08-24 21:56:24 -05009228 /* Network configuration changed -- force [re]association */
9229 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9230 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009232 ipw_associate(priv);
9233 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009234
James Ketrenosa613bff2005-08-24 21:43:11 -05009235 /* Update the band LEDs */
9236 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009237
Jeff Garzikbf794512005-07-31 13:07:26 -04009238 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009239 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009240 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009241 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009242 return 0;
9243}
9244
9245static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009246 struct iw_request_info *info,
9247 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009248{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009249 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009250 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009251 switch (priv->ieee->mode) {
9252 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009253 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9254 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009255 case IEEE_B:
9256 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9257 break;
9258 case IEEE_A | IEEE_B:
9259 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9260 break;
9261 case IEEE_G:
9262 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9263 break;
9264 case IEEE_A | IEEE_G:
9265 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9266 break;
9267 case IEEE_B | IEEE_G:
9268 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9269 break;
9270 case IEEE_A | IEEE_B | IEEE_G:
9271 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9272 break;
9273 default:
9274 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009275 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009276 }
9277
James Ketrenos43f66a62005-03-25 12:31:53 -06009278 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9279
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009280 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009281 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009282
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009283 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009284}
9285
James Ketrenosea2b26e2005-08-24 21:25:16 -05009286static int ipw_wx_set_preamble(struct net_device *dev,
9287 struct iw_request_info *info,
9288 union iwreq_data *wrqu, char *extra)
9289{
9290 struct ipw_priv *priv = ieee80211_priv(dev);
9291 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009292 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009293 /* Switching from SHORT -> LONG requires a disassociation */
9294 if (mode == 1) {
9295 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9296 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009297
9298 /* Network configuration changed -- force [re]association */
9299 IPW_DEBUG_ASSOC
9300 ("[re]association triggered due to preamble change.\n");
9301 if (!ipw_disassociate(priv))
9302 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009303 }
9304 goto done;
9305 }
9306
9307 if (mode == 0) {
9308 priv->config &= ~CFG_PREAMBLE_LONG;
9309 goto done;
9310 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009311 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009312 return -EINVAL;
9313
9314 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009315 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009316 return 0;
9317}
9318
9319static int ipw_wx_get_preamble(struct net_device *dev,
9320 struct iw_request_info *info,
9321 union iwreq_data *wrqu, char *extra)
9322{
9323 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009324 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009325 if (priv->config & CFG_PREAMBLE_LONG)
9326 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9327 else
9328 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009329 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009330 return 0;
9331}
9332
James Ketrenosb095c382005-08-24 22:04:42 -05009333#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009334static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009335 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009336 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009337{
James Ketrenos43f66a62005-03-25 12:31:53 -06009338 struct ipw_priv *priv = ieee80211_priv(dev);
9339 int *parms = (int *)extra;
9340 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009341 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009342 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009343 if (enable) {
9344 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009345#ifdef CONFIG_IEEE80211_RADIOTAP
9346 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9347#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009348 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009349#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009350 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009352
James Ketrenos43f66a62005-03-25 12:31:53 -06009353 ipw_set_channel(priv, parms[1]);
9354 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009355 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9356 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009357 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009358 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009359 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009360 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009362 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 return 0;
9364}
9365
James Ketrenosb095c382005-08-24 22:04:42 -05009366#endif // CONFIG_IPW2200_MONITOR
9367
Jeff Garzikbf794512005-07-31 13:07:26 -04009368static int ipw_wx_reset(struct net_device *dev,
9369 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009370 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009371{
James Ketrenos43f66a62005-03-25 12:31:53 -06009372 struct ipw_priv *priv = ieee80211_priv(dev);
9373 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009374 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 return 0;
9376}
James Ketrenosb095c382005-08-24 22:04:42 -05009377
James Ketrenosb095c382005-08-24 22:04:42 -05009378static int ipw_wx_sw_reset(struct net_device *dev,
9379 struct iw_request_info *info,
9380 union iwreq_data *wrqu, char *extra)
9381{
9382 struct ipw_priv *priv = ieee80211_priv(dev);
9383 union iwreq_data wrqu_sec = {
9384 .encoding = {
9385 .flags = IW_ENCODE_DISABLED,
9386 },
9387 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009388 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009389
9390 IPW_DEBUG_WX("SW_RESET\n");
9391
9392 down(&priv->sem);
9393
James Ketrenosafbf30a2005-08-25 00:05:33 -05009394 ret = ipw_sw_reset(priv, 0);
9395 if (!ret) {
9396 free_firmware();
9397 ipw_adapter_restart(priv);
9398 }
James Ketrenosb095c382005-08-24 22:04:42 -05009399
9400 /* The SW reset bit might have been toggled on by the 'disable'
9401 * module parameter, so take appropriate action */
9402 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9403
9404 up(&priv->sem);
9405 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9406 down(&priv->sem);
9407
9408 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9409 /* Configuration likely changed -- force [re]association */
9410 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9411 "reset.\n");
9412 if (!ipw_disassociate(priv))
9413 ipw_associate(priv);
9414 }
9415
9416 up(&priv->sem);
9417
9418 return 0;
9419}
James Ketrenos43f66a62005-03-25 12:31:53 -06009420
9421/* Rebase the WE IOCTLs to zero for the handler array */
9422#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009423static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009424 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9425 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9426 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9427 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9428 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9429 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9430 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9431 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9432 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9433 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9434 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9435 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9436 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9437 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9438 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9439 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9440 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9441 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9442 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9443 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9444 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9445 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9446 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9447 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9448 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9449 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9450 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9451 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009452 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9453 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9454 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9455 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009456 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9457 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9458 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9459 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9460 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9461 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9462 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009463};
9464
James Ketrenosb095c382005-08-24 22:04:42 -05009465enum {
9466 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9467 IPW_PRIV_GET_POWER,
9468 IPW_PRIV_SET_MODE,
9469 IPW_PRIV_GET_MODE,
9470 IPW_PRIV_SET_PREAMBLE,
9471 IPW_PRIV_GET_PREAMBLE,
9472 IPW_PRIV_RESET,
9473 IPW_PRIV_SW_RESET,
9474#ifdef CONFIG_IPW2200_MONITOR
9475 IPW_PRIV_SET_MONITOR,
9476#endif
9477};
James Ketrenos43f66a62005-03-25 12:31:53 -06009478
Jeff Garzikbf794512005-07-31 13:07:26 -04009479static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009480 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009481 .cmd = IPW_PRIV_SET_POWER,
9482 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9483 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009484 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009485 .cmd = IPW_PRIV_GET_POWER,
9486 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9487 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009488 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009489 .cmd = IPW_PRIV_SET_MODE,
9490 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9491 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009492 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009493 .cmd = IPW_PRIV_GET_MODE,
9494 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9495 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009496 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009497 .cmd = IPW_PRIV_SET_PREAMBLE,
9498 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9499 .name = "set_preamble"},
9500 {
9501 .cmd = IPW_PRIV_GET_PREAMBLE,
9502 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9503 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009504 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009505 IPW_PRIV_RESET,
9506 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009507 {
9508 IPW_PRIV_SW_RESET,
9509 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9510#ifdef CONFIG_IPW2200_MONITOR
9511 {
9512 IPW_PRIV_SET_MONITOR,
9513 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9514#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009515};
9516
9517static iw_handler ipw_priv_handler[] = {
9518 ipw_wx_set_powermode,
9519 ipw_wx_get_powermode,
9520 ipw_wx_set_wireless_mode,
9521 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009522 ipw_wx_set_preamble,
9523 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009524 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009525 ipw_wx_sw_reset,
9526#ifdef CONFIG_IPW2200_MONITOR
9527 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009528#endif
9529};
9530
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009531static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009532 .standard = ipw_wx_handlers,
9533 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9534 .num_private = ARRAY_SIZE(ipw_priv_handler),
9535 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9536 .private = ipw_priv_handler,
9537 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009538 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009539};
9540
James Ketrenos43f66a62005-03-25 12:31:53 -06009541/*
9542 * Get wireless statistics.
9543 * Called by /proc/net/wireless
9544 * Also called by SIOCGIWSTATS
9545 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009546static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009547{
9548 struct ipw_priv *priv = ieee80211_priv(dev);
9549 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009550
James Ketrenos43f66a62005-03-25 12:31:53 -06009551 wstats = &priv->wstats;
9552
James Ketrenosea2b26e2005-08-24 21:25:16 -05009553 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009554 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009555 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9556 * and associated; if not associcated, the values are all meaningless
9557 * anyway, so set them all to NULL and INVALID */
9558 if (!(priv->status & STATUS_ASSOCIATED)) {
9559 wstats->miss.beacon = 0;
9560 wstats->discard.retries = 0;
9561 wstats->qual.qual = 0;
9562 wstats->qual.level = 0;
9563 wstats->qual.noise = 0;
9564 wstats->qual.updated = 7;
9565 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009566 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009567 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009568 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009569
9570 wstats->qual.qual = priv->quality;
9571 wstats->qual.level = average_value(&priv->average_rssi);
9572 wstats->qual.noise = average_value(&priv->average_noise);
9573 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009574 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009575
9576 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9577 wstats->discard.retries = priv->last_tx_failures;
9578 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009579
James Ketrenos43f66a62005-03-25 12:31:53 -06009580/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9581 goto fail_get_ordinal;
9582 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009583
James Ketrenos43f66a62005-03-25 12:31:53 -06009584 return wstats;
9585}
9586
James Ketrenos43f66a62005-03-25 12:31:53 -06009587/* net device stuff */
9588
Arjan van de Ven858119e2006-01-14 13:20:43 -08009589static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009590{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009591 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9592 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06009593 sys_config->answer_broadcast_ssid_probe = 0;
9594 sys_config->accept_all_data_frames = 0;
9595 sys_config->accept_non_directed_frames = 1;
9596 sys_config->exclude_unicast_unencrypted = 0;
9597 sys_config->disable_unicast_decryption = 1;
9598 sys_config->exclude_multicast_unencrypted = 0;
9599 sys_config->disable_multicast_decryption = 1;
9600 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009601 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009602 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009603 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009604 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009605 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009606}
9607
9608static int ipw_net_open(struct net_device *dev)
9609{
9610 struct ipw_priv *priv = ieee80211_priv(dev);
9611 IPW_DEBUG_INFO("dev->open\n");
9612 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009613 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009614 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9615 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009616 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009617 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009618 return 0;
9619}
9620
9621static int ipw_net_stop(struct net_device *dev)
9622{
9623 IPW_DEBUG_INFO("dev->close\n");
9624 netif_stop_queue(dev);
9625 return 0;
9626}
9627
9628/*
9629todo:
9630
9631modify to send one tfd per fragment instead of using chunking. otherwise
9632we need to heavily modify the ieee80211_skb_to_txb.
9633*/
9634
Arjan van de Ven858119e2006-01-14 13:20:43 -08009635static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009636 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009637{
James Ketrenos0dacca12005-09-21 12:23:41 -05009638 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009639 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009640 int i = 0;
9641 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009642#ifdef CONFIG_IPW_QOS
9643 int tx_id = ipw_get_tx_queue_number(priv, pri);
9644 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9645#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009646 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009647#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009648 struct clx2_queue *q = &txq->q;
9649 u8 id, hdr_len, unicast;
9650 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009651 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009652
James Ketrenos227d2dc2005-07-28 16:25:55 -05009653 /* If there isn't room in the queue, we return busy and let the
9654 * network stack requeue the packet for us */
9655 if (ipw_queue_space(q) < q->high_mark)
9656 return NETDEV_TX_BUSY;
James Ketrenos43f66a62005-03-25 12:31:53 -06009657
9658 switch (priv->ieee->iw_mode) {
9659 case IW_MODE_ADHOC:
9660 hdr_len = IEEE80211_3ADDR_LEN;
Stephen Hemminger3c190652006-01-03 15:27:38 -08009661 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009662 id = ipw_find_station(priv, hdr->addr1);
9663 if (id == IPW_INVALID_STATION) {
9664 id = ipw_add_station(priv, hdr->addr1);
9665 if (id == IPW_INVALID_STATION) {
9666 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009667 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 MAC_ARG(hdr->addr1));
9669 goto drop;
9670 }
9671 }
9672 break;
9673
9674 case IW_MODE_INFRA:
9675 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009676 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009677 hdr_len = IEEE80211_3ADDR_LEN;
9678 id = 0;
9679 break;
9680 }
9681
9682 tfd = &txq->bd[q->first_empty];
9683 txq->txb[q->first_empty] = txb;
9684 memset(tfd, 0, sizeof(*tfd));
9685 tfd->u.data.station_number = id;
9686
9687 tfd->control_flags.message_type = TX_FRAME_TYPE;
9688 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9689
9690 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009691 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009693
James Ketrenos43f66a62005-03-25 12:31:53 -06009694 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009695 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009696 else
James Ketrenosb095c382005-08-24 22:04:42 -05009697 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009698
James Ketrenosea2b26e2005-08-24 21:25:16 -05009699 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9700 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009701
James Ketrenosc848d0a2005-08-24 21:56:24 -05009702 fc = le16_to_cpu(hdr->frame_ctl);
9703 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009704
9705 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9706
James Ketrenosb095c382005-08-24 22:04:42 -05009707 if (likely(unicast))
9708 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9709
9710 if (txb->encrypted && !priv->ieee->host_encrypt) {
9711 switch (priv->ieee->sec.level) {
9712 case SEC_LEVEL_3:
9713 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9714 IEEE80211_FCTL_PROTECTED;
9715 /* XXX: ACK flag must be set for CCMP even if it
9716 * is a multicast/broadcast packet, because CCMP
9717 * group communication encrypted by GTK is
9718 * actually done by the AP. */
9719 if (!unicast)
9720 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9721
9722 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9723 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9724 tfd->u.data.key_index = 0;
9725 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9726 break;
9727 case SEC_LEVEL_2:
9728 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9729 IEEE80211_FCTL_PROTECTED;
9730 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9731 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9732 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9733 break;
9734 case SEC_LEVEL_1:
9735 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9736 IEEE80211_FCTL_PROTECTED;
9737 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9738 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9739 40)
9740 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9741 else
9742 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9743 break;
9744 case SEC_LEVEL_0:
9745 break;
9746 default:
9747 printk(KERN_ERR "Unknow security level %d\n",
9748 priv->ieee->sec.level);
9749 break;
9750 }
9751 } else
9752 /* No hardware encryption */
9753 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9754
9755#ifdef CONFIG_IPW_QOS
9756 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9757#endif /* CONFIG_IPW_QOS */
9758
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009760 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9761 txb->nr_frags));
9762 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9763 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9764 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9765 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9766 i, le32_to_cpu(tfd->u.data.num_chunks),
9767 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009768 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009769 i, tfd->u.data.num_chunks,
9770 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009771 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009772 txb->fragments[i]->len - hdr_len);
9773
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009774 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009775 cpu_to_le32(pci_map_single
9776 (priv->pci_dev,
9777 txb->fragments[i]->data + hdr_len,
9778 txb->fragments[i]->len - hdr_len,
9779 PCI_DMA_TODEVICE));
9780 tfd->u.data.chunk_len[i] =
9781 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 }
9783
9784 if (i != txb->nr_frags) {
9785 struct sk_buff *skb;
9786 u16 remaining_bytes = 0;
9787 int j;
9788
9789 for (j = i; j < txb->nr_frags; j++)
9790 remaining_bytes += txb->fragments[j]->len - hdr_len;
9791
9792 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9793 remaining_bytes);
9794 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9795 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009796 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009797 for (j = i; j < txb->nr_frags; j++) {
9798 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009799
James Ketrenos43f66a62005-03-25 12:31:53 -06009800 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009801 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009802 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009803 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009804 }
9805 dev_kfree_skb_any(txb->fragments[i]);
9806 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009807 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009808 cpu_to_le32(pci_map_single
9809 (priv->pci_dev, skb->data,
9810 tfd->u.data.chunk_len[i],
9811 PCI_DMA_TODEVICE));
9812
9813 tfd->u.data.num_chunks =
9814 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9815 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009816 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009817 }
9818
9819 /* kick DMA */
9820 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9821 ipw_write32(priv, q->reg_w, q->first_empty);
9822
James Ketrenos227d2dc2005-07-28 16:25:55 -05009823 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009824
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009825 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009826 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9827 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009828 return NETDEV_TX_OK;
9829}
9830
9831static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9832{
9833 struct ipw_priv *priv = ieee80211_priv(dev);
9834#ifdef CONFIG_IPW_QOS
9835 int tx_id = ipw_get_tx_queue_number(priv, pri);
9836 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9837#else
9838 struct clx2_tx_queue *txq = &priv->txq[0];
9839#endif /* CONFIG_IPW_QOS */
9840
9841 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9842 return 1;
9843
9844 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009845}
9846
9847static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009848 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009849{
9850 struct ipw_priv *priv = ieee80211_priv(dev);
9851 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009852 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009853
9854 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009855 spin_lock_irqsave(&priv->lock, flags);
9856
9857 if (!(priv->status & STATUS_ASSOCIATED)) {
9858 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9859 priv->ieee->stats.tx_carrier_errors++;
9860 netif_stop_queue(dev);
9861 goto fail_unlock;
9862 }
9863
James Ketrenos227d2dc2005-07-28 16:25:55 -05009864 ret = ipw_tx_skb(priv, txb, pri);
9865 if (ret == NETDEV_TX_OK)
9866 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009867 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009868
James Ketrenos227d2dc2005-07-28 16:25:55 -05009869 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009870
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009871 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009872 spin_unlock_irqrestore(&priv->lock, flags);
9873 return 1;
9874}
9875
9876static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9877{
9878 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009879
James Ketrenos43f66a62005-03-25 12:31:53 -06009880 priv->ieee->stats.tx_packets = priv->tx_packets;
9881 priv->ieee->stats.rx_packets = priv->rx_packets;
9882 return &priv->ieee->stats;
9883}
9884
9885static void ipw_net_set_multicast_list(struct net_device *dev)
9886{
9887
9888}
9889
9890static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9891{
9892 struct ipw_priv *priv = ieee80211_priv(dev);
9893 struct sockaddr *addr = p;
9894 if (!is_valid_ether_addr(addr->sa_data))
9895 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009896 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009897 priv->config |= CFG_CUSTOM_MAC;
9898 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9899 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9900 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009901 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009902 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009903 return 0;
9904}
9905
Jeff Garzikbf794512005-07-31 13:07:26 -04009906static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009907 struct ethtool_drvinfo *info)
9908{
9909 struct ipw_priv *p = ieee80211_priv(dev);
9910 char vers[64];
9911 char date[32];
9912 u32 len;
9913
9914 strcpy(info->driver, DRV_NAME);
9915 strcpy(info->version, DRV_VERSION);
9916
9917 len = sizeof(vers);
9918 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9919 len = sizeof(date);
9920 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9921
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009922 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009923 vers, date);
9924 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009925 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009926}
9927
9928static u32 ipw_ethtool_get_link(struct net_device *dev)
9929{
9930 struct ipw_priv *priv = ieee80211_priv(dev);
9931 return (priv->status & STATUS_ASSOCIATED) != 0;
9932}
9933
9934static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9935{
James Ketrenosb095c382005-08-24 22:04:42 -05009936 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009937}
9938
9939static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009940 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009941{
9942 struct ipw_priv *p = ieee80211_priv(dev);
9943
James Ketrenosb095c382005-08-24 22:04:42 -05009944 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009945 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009946 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009947 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009948 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009949 return 0;
9950}
9951
9952static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009953 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009954{
9955 struct ipw_priv *p = ieee80211_priv(dev);
9956 int i;
9957
James Ketrenosb095c382005-08-24 22:04:42 -05009958 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009959 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009960 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009961 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009962 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -05009963 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06009964 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009965 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009966 return 0;
9967}
9968
9969static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009970 .get_link = ipw_ethtool_get_link,
9971 .get_drvinfo = ipw_ethtool_get_drvinfo,
9972 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9973 .get_eeprom = ipw_ethtool_get_eeprom,
9974 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06009975};
9976
9977static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9978{
9979 struct ipw_priv *priv = data;
9980 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04009981
James Ketrenos43f66a62005-03-25 12:31:53 -06009982 if (!priv)
9983 return IRQ_NONE;
9984
9985 spin_lock(&priv->lock);
9986
9987 if (!(priv->status & STATUS_INT_ENABLED)) {
9988 /* Shared IRQ */
9989 goto none;
9990 }
9991
James Ketrenosb095c382005-08-24 22:04:42 -05009992 inta = ipw_read32(priv, IPW_INTA_RW);
9993 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04009994
James Ketrenos43f66a62005-03-25 12:31:53 -06009995 if (inta == 0xFFFFFFFF) {
9996 /* Hardware disappeared */
9997 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
9998 goto none;
9999 }
10000
James Ketrenosb095c382005-08-24 22:04:42 -050010001 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010002 /* Shared interrupt */
10003 goto none;
10004 }
10005
10006 /* tell the device to stop sending interrupts */
10007 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010008
James Ketrenos43f66a62005-03-25 12:31:53 -060010009 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010010 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10011 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010012
James Ketrenos43f66a62005-03-25 12:31:53 -060010013 /* Cache INTA value for our tasklet */
10014 priv->isr_inta = inta;
10015
10016 tasklet_schedule(&priv->irq_tasklet);
10017
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010018 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010019
10020 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010021 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010022 spin_unlock(&priv->lock);
10023 return IRQ_NONE;
10024}
10025
10026static void ipw_rf_kill(void *adapter)
10027{
10028 struct ipw_priv *priv = adapter;
10029 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010030
James Ketrenos43f66a62005-03-25 12:31:53 -060010031 spin_lock_irqsave(&priv->lock, flags);
10032
10033 if (rf_kill_active(priv)) {
10034 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10035 if (priv->workqueue)
10036 queue_delayed_work(priv->workqueue,
10037 &priv->rf_kill, 2 * HZ);
10038 goto exit_unlock;
10039 }
10040
10041 /* RF Kill is now disabled, so bring the device back up */
10042
10043 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10044 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10045 "device\n");
10046
10047 /* we can not do an adapter restart while inside an irq lock */
10048 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010049 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10051 "enabled\n");
10052
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010053 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 spin_unlock_irqrestore(&priv->lock, flags);
10055}
10056
James Ketrenosc848d0a2005-08-24 21:56:24 -050010057static void ipw_bg_rf_kill(void *data)
10058{
10059 struct ipw_priv *priv = data;
10060 down(&priv->sem);
10061 ipw_rf_kill(data);
10062 up(&priv->sem);
10063}
10064
Adrian Bunka73e22b2006-01-21 01:39:42 +010010065static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010066{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010067 priv->last_seq_num = -1;
10068 priv->last_frag_num = -1;
10069 priv->last_packet_time = 0;
10070
James Ketrenosa613bff2005-08-24 21:43:11 -050010071 netif_carrier_on(priv->net_dev);
10072 if (netif_queue_stopped(priv->net_dev)) {
10073 IPW_DEBUG_NOTIF("waking queue\n");
10074 netif_wake_queue(priv->net_dev);
10075 } else {
10076 IPW_DEBUG_NOTIF("starting queue\n");
10077 netif_start_queue(priv->net_dev);
10078 }
10079
James Ketrenosc848d0a2005-08-24 21:56:24 -050010080 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010081 ipw_reset_stats(priv);
10082 /* Ensure the rate is updated immediately */
10083 priv->last_rate = ipw_get_current_rate(priv);
10084 ipw_gather_stats(priv);
10085 ipw_led_link_up(priv);
10086 notify_wx_assoc_event(priv);
10087
10088 if (priv->config & CFG_BACKGROUND_SCAN)
10089 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10090}
10091
James Ketrenosc848d0a2005-08-24 21:56:24 -050010092static void ipw_bg_link_up(void *data)
10093{
10094 struct ipw_priv *priv = data;
10095 down(&priv->sem);
10096 ipw_link_up(data);
10097 up(&priv->sem);
10098}
10099
Adrian Bunka73e22b2006-01-21 01:39:42 +010010100static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010101{
10102 ipw_led_link_down(priv);
10103 netif_carrier_off(priv->net_dev);
10104 netif_stop_queue(priv->net_dev);
10105 notify_wx_assoc_event(priv);
10106
10107 /* Cancel any queued work ... */
10108 cancel_delayed_work(&priv->request_scan);
10109 cancel_delayed_work(&priv->adhoc_check);
10110 cancel_delayed_work(&priv->gather_stats);
10111
10112 ipw_reset_stats(priv);
10113
James Ketrenosafbf30a2005-08-25 00:05:33 -050010114 if (!(priv->status & STATUS_EXIT_PENDING)) {
10115 /* Queue up another scan... */
10116 queue_work(priv->workqueue, &priv->request_scan);
10117 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010118}
10119
James Ketrenosc848d0a2005-08-24 21:56:24 -050010120static void ipw_bg_link_down(void *data)
10121{
10122 struct ipw_priv *priv = data;
10123 down(&priv->sem);
10124 ipw_link_down(data);
10125 up(&priv->sem);
10126}
10127
James Ketrenos43f66a62005-03-25 12:31:53 -060010128static int ipw_setup_deferred_work(struct ipw_priv *priv)
10129{
10130 int ret = 0;
10131
James Ketrenos43f66a62005-03-25 12:31:53 -060010132 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010133 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010134 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010135
James Ketrenosc848d0a2005-08-24 21:56:24 -050010136 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10137 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10138 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010139 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010140 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10141 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10142 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10143 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10144 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010145 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010146 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010147 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010148 (void (*)(void *))ipw_bg_gather_stats, priv);
10149 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10150 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10151 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10152 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10153 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10154 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010155 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010156 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010157 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010158 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10159 priv);
10160 INIT_WORK(&priv->merge_networks,
10161 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010162
James Ketrenosb095c382005-08-24 22:04:42 -050010163#ifdef CONFIG_IPW_QOS
10164 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10165 priv);
10166#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010167
10168 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10169 ipw_irq_tasklet, (unsigned long)priv);
10170
10171 return ret;
10172}
10173
James Ketrenos43f66a62005-03-25 12:31:53 -060010174static void shim__set_security(struct net_device *dev,
10175 struct ieee80211_security *sec)
10176{
10177 struct ipw_priv *priv = ieee80211_priv(dev);
10178 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010179 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010181 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010182 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010183 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010184 priv->ieee->sec.flags &= ~(1 << i);
10185 else {
10186 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010187 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010188 priv->ieee->sec.flags |= (1 << i);
10189 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010190 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010191 } else if (sec->level != SEC_LEVEL_1)
10192 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010193 }
10194
James Ketrenosb095c382005-08-24 22:04:42 -050010195 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010196 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010197 priv->ieee->sec.active_key = sec->active_key;
10198 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010199 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010200 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010201 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010202 } else
10203 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010204
10205 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010206 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10207 priv->ieee->sec.auth_mode = sec->auth_mode;
10208 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010209 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10210 priv->capability |= CAP_SHARED_KEY;
10211 else
10212 priv->capability &= ~CAP_SHARED_KEY;
10213 priv->status |= STATUS_SECURITY_UPDATED;
10214 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010215
James Ketrenosb095c382005-08-24 22:04:42 -050010216 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10217 priv->ieee->sec.flags |= SEC_ENABLED;
10218 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010219 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010220 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010221 priv->capability |= CAP_PRIVACY_ON;
10222 else
10223 priv->capability &= ~CAP_PRIVACY_ON;
10224 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010225
James Ketrenosafbf30a2005-08-25 00:05:33 -050010226 if (sec->flags & SEC_ENCRYPT)
10227 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010228
James Ketrenosb095c382005-08-24 22:04:42 -050010229 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10230 priv->ieee->sec.level = sec->level;
10231 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010232 priv->status |= STATUS_SECURITY_UPDATED;
10233 }
10234
Zhu Yi1fbfea52005-08-05 17:22:56 +080010235 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10236 ipw_set_hwcrypto_keys(priv);
10237
Jeff Garzikbf794512005-07-31 13:07:26 -040010238 /* To match current functionality of ipw2100 (which works well w/
10239 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010240 * privacy capability changes ... */
10241#if 0
10242 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010243 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010244 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010245 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010246 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010247 IPW_DEBUG_ASSOC("Disassociating due to capability "
10248 "change.\n");
10249 ipw_disassociate(priv);
10250 }
10251#endif
10252}
10253
Jeff Garzikbf794512005-07-31 13:07:26 -040010254static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010255 struct ipw_supported_rates *rates)
10256{
10257 /* TODO: Mask out rates based on priv->rates_mask */
10258
10259 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010260 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010261 switch (priv->ieee->freq_band) {
10262 case IEEE80211_52GHZ_BAND:
10263 rates->ieee_mode = IPW_A_MODE;
10264 rates->purpose = IPW_RATE_CAPABILITIES;
10265 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10266 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10267 break;
10268
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010269 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010270 rates->ieee_mode = IPW_G_MODE;
10271 rates->purpose = IPW_RATE_CAPABILITIES;
10272 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10273 IEEE80211_CCK_DEFAULT_RATES_MASK);
10274 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10275 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10276 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10277 }
10278 break;
10279 }
10280
10281 return 0;
10282}
10283
Jeff Garzikbf794512005-07-31 13:07:26 -040010284static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010285{
James Ketrenos43f66a62005-03-25 12:31:53 -060010286 /* This is only called from ipw_up, which resets/reloads the firmware
10287 so, we don't need to first disable the card before we configure
10288 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010289 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010290 goto error;
10291
10292 /* initialize adapter address */
10293 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10294 goto error;
10295
10296 /* set basic system config settings */
10297 init_sys_config(&priv->sys_config);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010298 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10299 priv->sys_config.answer_broadcast_ssid_probe = 1;
10300 else
10301 priv->sys_config.answer_broadcast_ssid_probe = 0;
10302
James Ketrenos43f66a62005-03-25 12:31:53 -060010303 if (ipw_send_system_config(priv, &priv->sys_config))
10304 goto error;
10305
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010306 init_supported_rates(priv, &priv->rates);
10307 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010308 goto error;
10309
10310 /* Set request-to-send threshold */
10311 if (priv->rts_threshold) {
10312 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10313 goto error;
10314 }
James Ketrenosb095c382005-08-24 22:04:42 -050010315#ifdef CONFIG_IPW_QOS
10316 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10317 ipw_qos_activate(priv, NULL);
10318#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010319
10320 if (ipw_set_random_seed(priv))
10321 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010322
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 /* final state transition to the RUN state */
10324 if (ipw_send_host_complete(priv))
10325 goto error;
10326
James Ketrenose6666192005-08-12 09:17:04 -050010327 priv->status |= STATUS_INIT;
10328
10329 ipw_led_init(priv);
10330 ipw_led_radio_on(priv);
10331 priv->notif_missed_beacons = 0;
10332
10333 /* Set hardware WEP key if it is configured. */
10334 if ((priv->capability & CAP_PRIVACY_ON) &&
10335 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10336 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10337 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010338
10339 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010340
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010341 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010342 return -EIO;
10343}
10344
James Ketrenos4f36f802005-08-03 20:36:56 -050010345/*
10346 * NOTE:
10347 *
10348 * These tables have been tested in conjunction with the
10349 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10350 *
10351 * Altering this values, using it on other hardware, or in geographies
10352 * not intended for resale of the above mentioned Intel adapters has
10353 * not been tested.
10354 *
10355 */
10356static const struct ieee80211_geo ipw_geos[] = {
10357 { /* Restricted */
10358 "---",
10359 .bg_channels = 11,
10360 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10361 {2427, 4}, {2432, 5}, {2437, 6},
10362 {2442, 7}, {2447, 8}, {2452, 9},
10363 {2457, 10}, {2462, 11}},
10364 },
10365
10366 { /* Custom US/Canada */
10367 "ZZF",
10368 .bg_channels = 11,
10369 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10370 {2427, 4}, {2432, 5}, {2437, 6},
10371 {2442, 7}, {2447, 8}, {2452, 9},
10372 {2457, 10}, {2462, 11}},
10373 .a_channels = 8,
10374 .a = {{5180, 36},
10375 {5200, 40},
10376 {5220, 44},
10377 {5240, 48},
10378 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10379 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10380 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10381 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10382 },
10383
10384 { /* Rest of World */
10385 "ZZD",
10386 .bg_channels = 13,
10387 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10388 {2427, 4}, {2432, 5}, {2437, 6},
10389 {2442, 7}, {2447, 8}, {2452, 9},
10390 {2457, 10}, {2462, 11}, {2467, 12},
10391 {2472, 13}},
10392 },
10393
10394 { /* Custom USA & Europe & High */
10395 "ZZA",
10396 .bg_channels = 11,
10397 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10398 {2427, 4}, {2432, 5}, {2437, 6},
10399 {2442, 7}, {2447, 8}, {2452, 9},
10400 {2457, 10}, {2462, 11}},
10401 .a_channels = 13,
10402 .a = {{5180, 36},
10403 {5200, 40},
10404 {5220, 44},
10405 {5240, 48},
10406 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10407 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10408 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10409 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10410 {5745, 149},
10411 {5765, 153},
10412 {5785, 157},
10413 {5805, 161},
10414 {5825, 165}},
10415 },
10416
10417 { /* Custom NA & Europe */
10418 "ZZB",
10419 .bg_channels = 11,
10420 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10421 {2427, 4}, {2432, 5}, {2437, 6},
10422 {2442, 7}, {2447, 8}, {2452, 9},
10423 {2457, 10}, {2462, 11}},
10424 .a_channels = 13,
10425 .a = {{5180, 36},
10426 {5200, 40},
10427 {5220, 44},
10428 {5240, 48},
10429 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10430 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10431 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10432 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10433 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10434 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10435 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10436 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10437 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10438 },
10439
10440 { /* Custom Japan */
10441 "ZZC",
10442 .bg_channels = 11,
10443 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10444 {2427, 4}, {2432, 5}, {2437, 6},
10445 {2442, 7}, {2447, 8}, {2452, 9},
10446 {2457, 10}, {2462, 11}},
10447 .a_channels = 4,
10448 .a = {{5170, 34}, {5190, 38},
10449 {5210, 42}, {5230, 46}},
10450 },
10451
10452 { /* Custom */
10453 "ZZM",
10454 .bg_channels = 11,
10455 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10456 {2427, 4}, {2432, 5}, {2437, 6},
10457 {2442, 7}, {2447, 8}, {2452, 9},
10458 {2457, 10}, {2462, 11}},
10459 },
10460
10461 { /* Europe */
10462 "ZZE",
10463 .bg_channels = 13,
10464 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10465 {2427, 4}, {2432, 5}, {2437, 6},
10466 {2442, 7}, {2447, 8}, {2452, 9},
10467 {2457, 10}, {2462, 11}, {2467, 12},
10468 {2472, 13}},
10469 .a_channels = 19,
10470 .a = {{5180, 36},
10471 {5200, 40},
10472 {5220, 44},
10473 {5240, 48},
10474 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10475 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10476 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10477 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10478 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10479 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10480 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10481 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10482 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10483 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10484 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10485 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10486 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10487 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10488 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10489 },
10490
10491 { /* Custom Japan */
10492 "ZZJ",
10493 .bg_channels = 14,
10494 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10495 {2427, 4}, {2432, 5}, {2437, 6},
10496 {2442, 7}, {2447, 8}, {2452, 9},
10497 {2457, 10}, {2462, 11}, {2467, 12},
10498 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10499 .a_channels = 4,
10500 .a = {{5170, 34}, {5190, 38},
10501 {5210, 42}, {5230, 46}},
10502 },
10503
James Ketrenos03520572005-10-19 16:12:31 -050010504 { /* Rest of World */
10505 "ZZR",
10506 .bg_channels = 14,
10507 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10508 {2427, 4}, {2432, 5}, {2437, 6},
10509 {2442, 7}, {2447, 8}, {2452, 9},
10510 {2457, 10}, {2462, 11}, {2467, 12},
10511 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10512 IEEE80211_CH_PASSIVE_ONLY}},
10513 },
10514
James Ketrenos4f36f802005-08-03 20:36:56 -050010515 { /* High Band */
10516 "ZZH",
10517 .bg_channels = 13,
10518 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10519 {2427, 4}, {2432, 5}, {2437, 6},
10520 {2442, 7}, {2447, 8}, {2452, 9},
10521 {2457, 10}, {2462, 11},
10522 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10523 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10524 .a_channels = 4,
10525 .a = {{5745, 149}, {5765, 153},
10526 {5785, 157}, {5805, 161}},
10527 },
10528
10529 { /* Custom Europe */
10530 "ZZG",
10531 .bg_channels = 13,
10532 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10533 {2427, 4}, {2432, 5}, {2437, 6},
10534 {2442, 7}, {2447, 8}, {2452, 9},
10535 {2457, 10}, {2462, 11},
10536 {2467, 12}, {2472, 13}},
10537 .a_channels = 4,
10538 .a = {{5180, 36}, {5200, 40},
10539 {5220, 44}, {5240, 48}},
10540 },
10541
10542 { /* Europe */
10543 "ZZK",
10544 .bg_channels = 13,
10545 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10546 {2427, 4}, {2432, 5}, {2437, 6},
10547 {2442, 7}, {2447, 8}, {2452, 9},
10548 {2457, 10}, {2462, 11},
10549 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10550 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10551 .a_channels = 24,
10552 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10553 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10554 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10555 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10556 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10557 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10558 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10559 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10560 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10561 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10562 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10563 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10564 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10565 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10566 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10567 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10568 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10569 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10570 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10571 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10572 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10573 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10574 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10575 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10576 },
10577
10578 { /* Europe */
10579 "ZZL",
10580 .bg_channels = 11,
10581 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10582 {2427, 4}, {2432, 5}, {2437, 6},
10583 {2442, 7}, {2447, 8}, {2452, 9},
10584 {2457, 10}, {2462, 11}},
10585 .a_channels = 13,
10586 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10587 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10588 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10589 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10590 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10591 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10592 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10593 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10594 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10595 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10596 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10597 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10598 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10599 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010600};
10601
Liu Hong1fe0adb2005-08-19 09:33:10 -050010602/* GEO code borrowed from ieee80211_geo.c */
10603static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
10604{
10605 int i;
10606
10607 /* Driver needs to initialize the geography map before using
10608 * these helper functions */
10609 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10610
10611 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10612 for (i = 0; i < ieee->geo.bg_channels; i++)
10613 /* NOTE: If G mode is currently supported but
10614 * this is a B only channel, we don't see it
10615 * as valid. */
10616 if ((ieee->geo.bg[i].channel == channel) &&
10617 (!(ieee->mode & IEEE_G) ||
10618 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
10619 return IEEE80211_24GHZ_BAND;
10620
10621 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10622 for (i = 0; i < ieee->geo.a_channels; i++)
10623 if (ieee->geo.a[i].channel == channel)
10624 return IEEE80211_52GHZ_BAND;
10625
10626 return 0;
10627}
10628
10629static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
10630{
10631 int i;
10632
10633 /* Driver needs to initialize the geography map before using
10634 * these helper functions */
10635 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10636
10637 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10638 for (i = 0; i < ieee->geo.bg_channels; i++)
10639 if (ieee->geo.bg[i].channel == channel)
10640 return i;
10641
10642 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10643 for (i = 0; i < ieee->geo.a_channels; i++)
10644 if (ieee->geo.a[i].channel == channel)
10645 return i;
10646
10647 return -1;
10648}
10649
10650static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
10651{
10652 int i;
10653
10654 /* Driver needs to initialize the geography map before using
10655 * these helper functions */
10656 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10657
10658 freq /= 100000;
10659
10660 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10661 for (i = 0; i < ieee->geo.bg_channels; i++)
10662 if (ieee->geo.bg[i].freq == freq)
10663 return ieee->geo.bg[i].channel;
10664
10665 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10666 for (i = 0; i < ieee->geo.a_channels; i++)
10667 if (ieee->geo.a[i].freq == freq)
10668 return ieee->geo.a[i].channel;
10669
10670 return 0;
10671}
10672
10673static int ipw_set_geo(struct ieee80211_device *ieee,
10674 const struct ieee80211_geo *geo)
10675{
10676 memcpy(ieee->geo.name, geo->name, 3);
10677 ieee->geo.name[3] = '\0';
10678 ieee->geo.bg_channels = geo->bg_channels;
10679 ieee->geo.a_channels = geo->a_channels;
10680 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
10681 sizeof(struct ieee80211_channel));
10682 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
10683 sizeof(struct ieee80211_channel));
10684 return 0;
10685}
10686
10687static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
10688{
10689 return &ieee->geo;
10690}
10691
James Ketrenos43f66a62005-03-25 12:31:53 -060010692#define MAX_HW_RESTARTS 5
10693static int ipw_up(struct ipw_priv *priv)
10694{
James Ketrenos4f36f802005-08-03 20:36:56 -050010695 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010696
10697 if (priv->status & STATUS_EXIT_PENDING)
10698 return -EIO;
10699
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010700 if (cmdlog && !priv->cmdlog) {
10701 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10702 GFP_KERNEL);
10703 if (priv->cmdlog == NULL) {
10704 IPW_ERROR("Error allocating %d command log entries.\n",
10705 cmdlog);
10706 } else {
10707 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10708 priv->cmdlog_len = cmdlog;
10709 }
10710 }
10711
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010712 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010713 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010714 * Also start the clocks. */
10715 rc = ipw_load(priv);
10716 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010717 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010718 return rc;
10719 }
10720
10721 ipw_init_ordinals(priv);
10722 if (!(priv->config & CFG_CUSTOM_MAC))
10723 eeprom_parse_mac(priv, priv->mac_addr);
10724 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10725
James Ketrenos4f36f802005-08-03 20:36:56 -050010726 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10727 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10728 ipw_geos[j].name, 3))
10729 break;
10730 }
James Ketrenos03520572005-10-19 16:12:31 -050010731 if (j == ARRAY_SIZE(ipw_geos)) {
10732 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10733 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10734 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10735 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010736 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010737 }
Liu Hong1fe0adb2005-08-19 09:33:10 -050010738 if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010739 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010740 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010741 }
10742
10743 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10744 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010745
James Ketrenosb095c382005-08-24 22:04:42 -050010746 if (priv->status & STATUS_RF_KILL_SW) {
10747 IPW_WARNING("Radio disabled by module parameter.\n");
10748 return 0;
10749 } else if (rf_kill_active(priv)) {
10750 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10751 "Kill switch must be turned off for "
10752 "wireless networking to work.\n");
10753 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10754 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010755 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010756 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010757
10758 rc = ipw_config(priv);
10759 if (!rc) {
10760 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010761
James Ketrenose6666192005-08-12 09:17:04 -050010762 /* If configure to try and auto-associate, kick
10763 * off a scan. */
10764 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010765
James Ketrenos43f66a62005-03-25 12:31:53 -060010766 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010767 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010768
James Ketrenosc848d0a2005-08-24 21:56:24 -050010769 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010770 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10771 i, MAX_HW_RESTARTS);
10772
10773 /* We had an error bringing up the hardware, so take it
10774 * all the way back down so we can try again */
10775 ipw_down(priv);
10776 }
10777
Jeff Garzikbf794512005-07-31 13:07:26 -040010778 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010779 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010780 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010781
James Ketrenos43f66a62005-03-25 12:31:53 -060010782 return -EIO;
10783}
10784
James Ketrenosc848d0a2005-08-24 21:56:24 -050010785static void ipw_bg_up(void *data)
10786{
10787 struct ipw_priv *priv = data;
10788 down(&priv->sem);
10789 ipw_up(data);
10790 up(&priv->sem);
10791}
10792
James Ketrenosb095c382005-08-24 22:04:42 -050010793static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010794{
James Ketrenosb095c382005-08-24 22:04:42 -050010795 int i;
10796
10797 if (priv->status & STATUS_SCANNING) {
10798 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10799 ipw_abort_scan(priv);
10800 }
10801
10802 if (priv->status & STATUS_ASSOCIATED) {
10803 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10804 ipw_disassociate(priv);
10805 }
10806
10807 ipw_led_shutdown(priv);
10808
10809 /* Wait up to 1s for status to change to not scanning and not
10810 * associated (disassociation can take a while for a ful 802.11
10811 * exchange */
10812 for (i = 1000; i && (priv->status &
10813 (STATUS_DISASSOCIATING |
10814 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10815 udelay(10);
10816
10817 if (priv->status & (STATUS_DISASSOCIATING |
10818 STATUS_ASSOCIATED | STATUS_SCANNING))
10819 IPW_DEBUG_INFO("Still associated or scanning...\n");
10820 else
10821 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10822
James Ketrenosc848d0a2005-08-24 21:56:24 -050010823 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010824 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010825
10826 priv->status &= ~STATUS_INIT;
10827}
10828
James Ketrenos43f66a62005-03-25 12:31:53 -060010829static void ipw_down(struct ipw_priv *priv)
10830{
James Ketrenosb095c382005-08-24 22:04:42 -050010831 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10832
10833 priv->status |= STATUS_EXIT_PENDING;
10834
10835 if (ipw_is_init(priv))
10836 ipw_deinit(priv);
10837
10838 /* Wipe out the EXIT_PENDING status bit if we are not actually
10839 * exiting the module */
10840 if (!exit_pending)
10841 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010842
10843 /* tell the device to stop sending interrupts */
10844 ipw_disable_interrupts(priv);
10845
10846 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010847 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010848 netif_carrier_off(priv->net_dev);
10849 netif_stop_queue(priv->net_dev);
10850
10851 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010852
10853 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010854}
10855
James Ketrenosc848d0a2005-08-24 21:56:24 -050010856static void ipw_bg_down(void *data)
10857{
10858 struct ipw_priv *priv = data;
10859 down(&priv->sem);
10860 ipw_down(data);
10861 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010862}
10863
10864/* Called by register_netdev() */
10865static int ipw_net_init(struct net_device *dev)
10866{
10867 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010868 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010869
James Ketrenosc848d0a2005-08-24 21:56:24 -050010870 if (ipw_up(priv)) {
10871 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010872 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010873 }
10874
James Ketrenosc848d0a2005-08-24 21:56:24 -050010875 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010876 return 0;
10877}
10878
10879/* PCI driver stuff */
10880static struct pci_device_id card_ids[] = {
10881 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10882 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10883 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10884 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10885 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10886 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10887 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10888 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10889 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10890 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10891 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10892 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10893 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10894 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10895 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10896 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10897 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10898 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010899 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010900 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010901 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10902 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010903
James Ketrenos43f66a62005-03-25 12:31:53 -060010904 /* required last entry */
10905 {0,}
10906};
10907
10908MODULE_DEVICE_TABLE(pci, card_ids);
10909
10910static struct attribute *ipw_sysfs_entries[] = {
10911 &dev_attr_rf_kill.attr,
10912 &dev_attr_direct_dword.attr,
10913 &dev_attr_indirect_byte.attr,
10914 &dev_attr_indirect_dword.attr,
10915 &dev_attr_mem_gpio_reg.attr,
10916 &dev_attr_command_event_reg.attr,
10917 &dev_attr_nic_type.attr,
10918 &dev_attr_status.attr,
10919 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010920 &dev_attr_error.attr,
10921 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010922 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010923 &dev_attr_eeprom_delay.attr,
10924 &dev_attr_ucode_version.attr,
10925 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010926 &dev_attr_scan_age.attr,
10927 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010928 &dev_attr_speed_scan.attr,
10929 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010930 NULL
10931};
10932
10933static struct attribute_group ipw_attribute_group = {
10934 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010935 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010936};
10937
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010938static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010939{
10940 int err = 0;
10941 struct net_device *net_dev;
10942 void __iomem *base;
10943 u32 length, val;
10944 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010945 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010946
10947 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10948 if (net_dev == NULL) {
10949 err = -ENOMEM;
10950 goto out;
10951 }
10952
10953 priv = ieee80211_priv(net_dev);
10954 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010955
James Ketrenos43f66a62005-03-25 12:31:53 -060010956 priv->net_dev = net_dev;
10957 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080010958#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060010959 ipw_debug_level = debug;
10960#endif
10961 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010962 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10963 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010964
James Ketrenosc848d0a2005-08-24 21:56:24 -050010965 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010966 if (pci_enable_device(pdev)) {
10967 err = -ENODEV;
10968 goto out_free_ieee80211;
10969 }
10970
10971 pci_set_master(pdev);
10972
Tobias Klauser0e08b442005-06-20 14:28:41 -070010973 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010974 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010975 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010976 if (err) {
10977 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10978 goto out_pci_disable_device;
10979 }
10980
10981 pci_set_drvdata(pdev, priv);
10982
10983 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040010984 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060010985 goto out_pci_disable_device;
10986
Jeff Garzikbf794512005-07-31 13:07:26 -040010987 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060010988 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040010989 pci_read_config_dword(pdev, 0x40, &val);
10990 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060010991 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040010992
James Ketrenos43f66a62005-03-25 12:31:53 -060010993 length = pci_resource_len(pdev, 0);
10994 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040010995
James Ketrenos43f66a62005-03-25 12:31:53 -060010996 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
10997 if (!base) {
10998 err = -ENODEV;
10999 goto out_pci_release_regions;
11000 }
11001
11002 priv->hw_base = base;
11003 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11004 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11005
11006 err = ipw_setup_deferred_work(priv);
11007 if (err) {
11008 IPW_ERROR("Unable to setup deferred work\n");
11009 goto out_iounmap;
11010 }
11011
James Ketrenosb095c382005-08-24 22:04:42 -050011012 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011013
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011014 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011015 if (err) {
11016 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11017 goto out_destroy_workqueue;
11018 }
11019
11020 SET_MODULE_OWNER(net_dev);
11021 SET_NETDEV_DEV(net_dev, &pdev->dev);
11022
James Ketrenosc848d0a2005-08-24 21:56:24 -050011023 down(&priv->sem);
11024
James Ketrenos43f66a62005-03-25 12:31:53 -060011025 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11026 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011027 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011028
James Ketrenosb095c382005-08-24 22:04:42 -050011029#ifdef CONFIG_IPW_QOS
James Ketrenos3b9990c2005-08-19 13:18:55 -050011030 priv->ieee->handle_probe_response = ipw_handle_beacon;
11031 priv->ieee->handle_beacon = ipw_handle_probe_response;
11032 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050011033#endif /* CONFIG_IPW_QOS */
11034
James Ketrenosc848d0a2005-08-24 21:56:24 -050011035 priv->ieee->perfect_rssi = -20;
11036 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011037
11038 net_dev->open = ipw_net_open;
11039 net_dev->stop = ipw_net_stop;
11040 net_dev->init = ipw_net_init;
11041 net_dev->get_stats = ipw_net_get_stats;
11042 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11043 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011044 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011045 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011046 net_dev->wireless_handlers = &ipw_wx_handler_def;
11047 net_dev->ethtool_ops = &ipw_ethtool_ops;
11048 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011049 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011050 net_dev->mem_start = pci_resource_start(pdev, 0);
11051 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11052
11053 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11054 if (err) {
11055 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011056 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011057 goto out_release_irq;
11058 }
11059
James Ketrenosc848d0a2005-08-24 21:56:24 -050011060 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011061 err = register_netdev(net_dev);
11062 if (err) {
11063 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011064 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011065 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011066 return 0;
11067
James Ketrenosa613bff2005-08-24 21:43:11 -050011068 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011069 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011070 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011071 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011072 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011073 destroy_workqueue(priv->workqueue);
11074 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011075 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011076 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011077 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011078 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011079 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011080 pci_disable_device(pdev);
11081 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011082 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011083 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011084 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011085 return err;
11086}
11087
11088static void ipw_pci_remove(struct pci_dev *pdev)
11089{
11090 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011091 struct list_head *p, *q;
11092 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011093
James Ketrenos43f66a62005-03-25 12:31:53 -060011094 if (!priv)
11095 return;
11096
James Ketrenosb095c382005-08-24 22:04:42 -050011097 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011098
James Ketrenosafbf30a2005-08-25 00:05:33 -050011099 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011100 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011101 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11102
James Ketrenosb095c382005-08-24 22:04:42 -050011103 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011104
11105 unregister_netdev(priv->net_dev);
11106
11107 if (priv->rxq) {
11108 ipw_rx_queue_free(priv, priv->rxq);
11109 priv->rxq = NULL;
11110 }
11111 ipw_tx_queue_free(priv);
11112
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011113 if (priv->cmdlog) {
11114 kfree(priv->cmdlog);
11115 priv->cmdlog = NULL;
11116 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011117 /* ipw_down will ensure that there is no more pending work
11118 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011119 cancel_delayed_work(&priv->adhoc_check);
11120 cancel_delayed_work(&priv->gather_stats);
11121 cancel_delayed_work(&priv->request_scan);
11122 cancel_delayed_work(&priv->rf_kill);
11123 cancel_delayed_work(&priv->scan_check);
11124 destroy_workqueue(priv->workqueue);
11125 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011126
James Ketrenosafbf30a2005-08-25 00:05:33 -050011127 /* Free MAC hash list for ADHOC */
11128 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11129 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011130 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011131 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011132 }
11133 }
11134
James Ketrenosb39860c2005-08-12 09:36:32 -050011135 if (priv->error) {
11136 ipw_free_error_log(priv->error);
11137 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011138 }
11139
11140 free_irq(pdev->irq, priv);
11141 iounmap(priv->hw_base);
11142 pci_release_regions(pdev);
11143 pci_disable_device(pdev);
11144 pci_set_drvdata(pdev, NULL);
11145 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011146 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011147}
11148
James Ketrenos43f66a62005-03-25 12:31:53 -060011149#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011150static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011151{
11152 struct ipw_priv *priv = pci_get_drvdata(pdev);
11153 struct net_device *dev = priv->net_dev;
11154
11155 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11156
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011157 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011158 ipw_down(priv);
11159
11160 /* Remove the PRESENT state of the device */
11161 netif_device_detach(dev);
11162
James Ketrenos43f66a62005-03-25 12:31:53 -060011163 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011164 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011165 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011166
James Ketrenos43f66a62005-03-25 12:31:53 -060011167 return 0;
11168}
11169
11170static int ipw_pci_resume(struct pci_dev *pdev)
11171{
11172 struct ipw_priv *priv = pci_get_drvdata(pdev);
11173 struct net_device *dev = priv->net_dev;
11174 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011175
James Ketrenos43f66a62005-03-25 12:31:53 -060011176 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11177
James Ketrenosea2b26e2005-08-24 21:25:16 -050011178 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011179 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011180 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011181
James Ketrenos43f66a62005-03-25 12:31:53 -060011182 /*
11183 * Suspend/Resume resets the PCI configuration space, so we have to
11184 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11185 * from interfering with C3 CPU state. pci_restore_state won't help
11186 * here since it only restores the first 64 bytes pci config header.
11187 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011188 pci_read_config_dword(pdev, 0x40, &val);
11189 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011190 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11191
11192 /* Set the device back into the PRESENT state; this will also wake
11193 * the queue of needed */
11194 netif_device_attach(dev);
11195
11196 /* Bring the device back up */
11197 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011198
James Ketrenos43f66a62005-03-25 12:31:53 -060011199 return 0;
11200}
11201#endif
11202
11203/* driver initialization stuff */
11204static struct pci_driver ipw_driver = {
11205 .name = DRV_NAME,
11206 .id_table = card_ids,
11207 .probe = ipw_pci_probe,
11208 .remove = __devexit_p(ipw_pci_remove),
11209#ifdef CONFIG_PM
11210 .suspend = ipw_pci_suspend,
11211 .resume = ipw_pci_resume,
11212#endif
11213};
11214
11215static int __init ipw_init(void)
11216{
11217 int ret;
11218
11219 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11220 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11221
11222 ret = pci_module_init(&ipw_driver);
11223 if (ret) {
11224 IPW_ERROR("Unable to initialize PCI module\n");
11225 return ret;
11226 }
11227
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011228 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011229 if (ret) {
11230 IPW_ERROR("Unable to create driver sysfs file\n");
11231 pci_unregister_driver(&ipw_driver);
11232 return ret;
11233 }
11234
11235 return ret;
11236}
11237
11238static void __exit ipw_exit(void)
11239{
11240 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11241 pci_unregister_driver(&ipw_driver);
11242}
11243
11244module_param(disable, int, 0444);
11245MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11246
11247module_param(associate, int, 0444);
11248MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11249
11250module_param(auto_create, int, 0444);
11251MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11252
James Ketrenosa613bff2005-08-24 21:43:11 -050011253module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011254MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011255
James Ketrenos43f66a62005-03-25 12:31:53 -060011256module_param(debug, int, 0444);
11257MODULE_PARM_DESC(debug, "debug output mask");
11258
11259module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011260MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011261
James Ketrenosb095c382005-08-24 22:04:42 -050011262#ifdef CONFIG_IPW_QOS
11263module_param(qos_enable, int, 0444);
11264MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011265
James Ketrenosb095c382005-08-24 22:04:42 -050011266module_param(qos_burst_enable, int, 0444);
11267MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11268
11269module_param(qos_no_ack_mask, int, 0444);
11270MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11271
11272module_param(burst_duration_CCK, int, 0444);
11273MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11274
11275module_param(burst_duration_OFDM, int, 0444);
11276MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11277#endif /* CONFIG_IPW_QOS */
11278
11279#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011280module_param(mode, int, 0444);
11281MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11282#else
11283module_param(mode, int, 0444);
11284MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11285#endif
11286
James Ketrenosb095c382005-08-24 22:04:42 -050011287module_param(hwcrypto, int, 0444);
11288MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11289
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011290module_param(cmdlog, int, 0444);
11291MODULE_PARM_DESC(cmdlog,
11292 "allocate a ring buffer for logging firmware commands");
11293
James Ketrenos43f66a62005-03-25 12:31:53 -060011294module_exit(ipw_exit);
11295module_init(ipw_init);