blob: 734d2cb1de064f33dd17b289eed6461b8cbd64c5 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenosafbf30a2005-08-25 00:05:33 -05003 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
Zhu Yi7c97eb32006-01-24 16:37:47 +080036#define IPW2200_VERSION "git-1.0.10"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
James Ketrenos2b184d52005-08-03 20:33:14 -050038#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060039#define DRV_VERSION IPW2200_VERSION
40
James Ketrenosb095c382005-08-24 22:04:42 -050041#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
James Ketrenos43f66a62005-03-25 12:31:53 -060043MODULE_DESCRIPTION(DRV_DESCRIPTION);
44MODULE_VERSION(DRV_VERSION);
45MODULE_AUTHOR(DRV_COPYRIGHT);
46MODULE_LICENSE("GPL");
47
James Ketrenosf6c5cb72005-08-25 00:39:09 -050048static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060049static int debug = 0;
50static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060051static int mode = 0;
52
53static u32 ipw_debug_level;
54static int associate = 1;
55static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050056static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060057static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080058static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080059static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080060static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060061static const char ipw_modes[] = {
62 'a', 'b', 'g', '?'
63};
64
James Ketrenosb095c382005-08-24 22:04:42 -050065#ifdef CONFIG_IPW_QOS
66static int qos_enable = 0;
67static int qos_burst_enable = 0;
68static int qos_no_ack_mask = 0;
69static int burst_duration_CCK = 0;
70static int burst_duration_OFDM = 0;
71
72static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
73 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
74 QOS_TX3_CW_MIN_OFDM},
75 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
76 QOS_TX3_CW_MAX_OFDM},
77 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
78 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
79 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
80 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
81};
82
83static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
84 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
85 QOS_TX3_CW_MIN_CCK},
86 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
87 QOS_TX3_CW_MAX_CCK},
88 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
89 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
90 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
91 QOS_TX3_TXOP_LIMIT_CCK}
92};
93
94static struct ieee80211_qos_parameters def_parameters_OFDM = {
95 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
96 DEF_TX3_CW_MIN_OFDM},
97 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
98 DEF_TX3_CW_MAX_OFDM},
99 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
100 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
101 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
102 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
103};
104
105static struct ieee80211_qos_parameters def_parameters_CCK = {
106 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
107 DEF_TX3_CW_MIN_CCK},
108 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
109 DEF_TX3_CW_MAX_CCK},
110 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
111 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
112 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
113 DEF_TX3_TXOP_LIMIT_CCK}
114};
115
116static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
117
118static int from_priority_to_tx_queue[] = {
119 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
120 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
121};
122
123static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
124
125static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
126 *qos_param);
127static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
128 *qos_param);
129#endif /* CONFIG_IPW_QOS */
130
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000131static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500132static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600133static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400134static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600135 struct clx2_tx_queue *txq, int qindex);
136static int ipw_queue_reset(struct ipw_priv *priv);
137
138static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
139 int len, int sync);
140
141static void ipw_tx_queue_free(struct ipw_priv *);
142
143static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
144static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
145static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600146static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500147static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600148static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500149static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600150static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400151static int init_supported_rates(struct ipw_priv *priv,
152 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500153static void ipw_set_hwcrypto_keys(struct ipw_priv *);
154static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600155
Liu Hong1fe0adb2005-08-19 09:33:10 -0500156static int ipw_is_valid_channel(struct ieee80211_device *, u8);
157static int ipw_channel_to_index(struct ieee80211_device *, u8);
158static u8 ipw_freq_to_channel(struct ieee80211_device *, u32);
159static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *);
160static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600161
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500162static int snprint_line(char *buf, size_t count,
163 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600164{
165 int out, i, j, l;
166 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400167
James Ketrenos43f66a62005-03-25 12:31:53 -0600168 out = snprintf(buf, count, "%08X", ofs);
169
170 for (l = 0, i = 0; i < 2; i++) {
171 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400172 for (j = 0; j < 8 && l < len; j++, l++)
173 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600174 data[(i * 8 + j)]);
175 for (; j < 8; j++)
176 out += snprintf(buf + out, count - out, " ");
177 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400178
James Ketrenos43f66a62005-03-25 12:31:53 -0600179 out += snprintf(buf + out, count - out, " ");
180 for (l = 0, i = 0; i < 2; i++) {
181 out += snprintf(buf + out, count - out, " ");
182 for (j = 0; j < 8 && l < len; j++, l++) {
183 c = data[(i * 8 + j)];
184 if (!isascii(c) || !isprint(c))
185 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400186
James Ketrenos43f66a62005-03-25 12:31:53 -0600187 out += snprintf(buf + out, count - out, "%c", c);
188 }
189
190 for (; j < 8; j++)
191 out += snprintf(buf + out, count - out, " ");
192 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400193
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500194 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600195}
196
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400197static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600198{
199 char line[81];
200 u32 ofs = 0;
201 if (!(ipw_debug_level & level))
202 return;
203
204 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500205 snprint_line(line, sizeof(line), &data[ofs],
206 min(len, 16U), ofs);
207 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600208 ofs += 16;
209 len -= min(len, 16U);
210 }
211}
212
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500213static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
214{
215 size_t out = size;
216 u32 ofs = 0;
217 int total = 0;
218
219 while (size && len) {
220 out = snprint_line(output, size, &data[ofs],
221 min_t(size_t, len, 16U), ofs);
222
223 ofs += 16;
224 output += out;
225 size -= out;
226 len -= min_t(size_t, len, 16U);
227 total += out;
228 }
229 return total;
230}
231
Zhu Yic8fe6672006-01-24 16:36:36 +0800232/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600233static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
234#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
235
Zhu Yic8fe6672006-01-24 16:36:36 +0800236/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600237static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
238#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
239
Zhu Yic8fe6672006-01-24 16:36:36 +0800240/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600241static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
242static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
243{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400244 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
245 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600246 _ipw_write_reg8(a, b, c);
247}
248
Zhu Yic8fe6672006-01-24 16:36:36 +0800249/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600250static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
251static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
252{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400253 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
254 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600255 _ipw_write_reg16(a, b, c);
256}
257
Zhu Yic8fe6672006-01-24 16:36:36 +0800258/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600259static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
260static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
261{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400262 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
263 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600264 _ipw_write_reg32(a, b, c);
265}
266
Zhu Yic8fe6672006-01-24 16:36:36 +0800267/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600268#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800269
270/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600271#define ipw_write8(ipw, ofs, val) \
272 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
273 _ipw_write8(ipw, ofs, val)
274
Zhu Yic8fe6672006-01-24 16:36:36 +0800275/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600276#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800277
278/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600279#define ipw_write16(ipw, ofs, val) \
280 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
281 _ipw_write16(ipw, ofs, val)
282
Zhu Yic8fe6672006-01-24 16:36:36 +0800283/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600284#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800285
286/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600287#define ipw_write32(ipw, ofs, val) \
288 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
289 _ipw_write32(ipw, ofs, val)
290
Zhu Yic8fe6672006-01-24 16:36:36 +0800291/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600292#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800293
294/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400295static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
296{
297 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600298 return _ipw_read8(ipw, ofs);
299}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400300
Zhu Yic8fe6672006-01-24 16:36:36 +0800301/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600302#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
303
Zhu Yic8fe6672006-01-24 16:36:36 +0800304/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600305#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800306
307/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400308static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
309{
310 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600311 return _ipw_read16(ipw, ofs);
312}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400313
Zhu Yic8fe6672006-01-24 16:36:36 +0800314/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600315#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
316
Zhu Yic8fe6672006-01-24 16:36:36 +0800317/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600318#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800319
320/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400321static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
322{
323 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600324 return _ipw_read32(ipw, ofs);
325}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400326
Zhu Yic8fe6672006-01-24 16:36:36 +0800327/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600328#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
329
Zhu Yic8fe6672006-01-24 16:36:36 +0800330/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600331static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500332static inline void __ipw_read_indirect(const char *f, int l,
333 struct ipw_priv *a, u32 b, u8 * c, int d)
334{
335 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
336 d);
337 _ipw_read_indirect(a, b, c, d);
338}
339
Zhu Yic8fe6672006-01-24 16:36:36 +0800340/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500341#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600342
Zhu Yic8fe6672006-01-24 16:36:36 +0800343/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400344static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
345 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600346#define ipw_write_indirect(a, b, c, d) \
347 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500348 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600349
Zhu Yic8fe6672006-01-24 16:36:36 +0800350/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400351static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600352{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400353 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500354 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
355 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600356}
357
Zhu Yic8fe6672006-01-24 16:36:36 +0800358/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600359static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
360{
Zhu Yi2638bc32006-01-24 16:37:52 +0800361 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800362 u32 dif_len = reg - aligned_addr;
363
James Ketrenos43f66a62005-03-25 12:31:53 -0600364 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800365 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
366 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600367}
368
Zhu Yic8fe6672006-01-24 16:36:36 +0800369/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400370static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600371{
Zhu Yi2638bc32006-01-24 16:37:52 +0800372 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800373 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
374
James Ketrenos43f66a62005-03-25 12:31:53 -0600375 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800376 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
377 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600378}
379
Zhu Yic8fe6672006-01-24 16:36:36 +0800380/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600381static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
382{
383 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500384 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600385 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500386 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400387 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600388}
389
Zhu Yic8fe6672006-01-24 16:36:36 +0800390/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600391static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
392{
393 u32 value;
394
395 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
396
James Ketrenosb095c382005-08-24 22:04:42 -0500397 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
398 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600399 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
400 return value;
401}
402
Zhu Yic8fe6672006-01-24 16:36:36 +0800403/* General purpose, no alignment requirement, iterative (multi-byte) read, */
404/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600405static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
406 int num)
407{
Zhu Yi2638bc32006-01-24 16:37:52 +0800408 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600409 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600410 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400411
James Ketrenos43f66a62005-03-25 12:31:53 -0600412 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
413
James Ketrenosea2b26e2005-08-24 21:25:16 -0500414 if (num <= 0) {
415 return;
416 }
417
Zhu Yic8fe6672006-01-24 16:36:36 +0800418 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600419 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500420 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600421 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500422 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500423 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600424 aligned_addr += 4;
425 }
426
Zhu Yic8fe6672006-01-24 16:36:36 +0800427 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500428 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500429 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500430 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400431
Zhu Yic8fe6672006-01-24 16:36:36 +0800432 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500433 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500434 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500435 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500436 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500437 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600438}
439
Zhu Yic8fe6672006-01-24 16:36:36 +0800440/* General purpose, no alignment requirement, iterative (multi-byte) write, */
441/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400442static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600443 int num)
444{
Zhu Yi2638bc32006-01-24 16:37:52 +0800445 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600446 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600447 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400448
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400450
James Ketrenosea2b26e2005-08-24 21:25:16 -0500451 if (num <= 0) {
452 return;
453 }
454
Zhu Yic8fe6672006-01-24 16:36:36 +0800455 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600456 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500457 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800458 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500459 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500460 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600461 aligned_addr += 4;
462 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400463
Zhu Yic8fe6672006-01-24 16:36:36 +0800464 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500465 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500466 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400468
Zhu Yic8fe6672006-01-24 16:36:36 +0800469 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500470 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500471 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500472 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500474 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600475}
476
Zhu Yic8fe6672006-01-24 16:36:36 +0800477/* General purpose, no alignment requirement, iterative (multi-byte) write, */
478/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400479static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600480 int num)
481{
482 memcpy_toio((priv->hw_base + addr), buf, num);
483}
484
Zhu Yic8fe6672006-01-24 16:36:36 +0800485/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600486static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
487{
488 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
489}
490
Zhu Yic8fe6672006-01-24 16:36:36 +0800491/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600492static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
493{
494 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
495}
496
497static inline void ipw_enable_interrupts(struct ipw_priv *priv)
498{
499 if (priv->status & STATUS_INT_ENABLED)
500 return;
501 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500502 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600503}
504
505static inline void ipw_disable_interrupts(struct ipw_priv *priv)
506{
507 if (!(priv->status & STATUS_INT_ENABLED))
508 return;
509 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500510 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600511}
512
Brice Goglin0f52bf92005-12-01 01:41:46 -0800513#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600514static char *ipw_error_desc(u32 val)
515{
516 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400517 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600518 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400519 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600520 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400521 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600522 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400523 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400525 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500526 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400527 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500528 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400529 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500530 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400531 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500532 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400533 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500534 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400535 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500536 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400537 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500538 return "DMA_STATUS";
539 case IPW_FW_ERROR_DINO_ERROR:
540 return "DINO_ERROR";
541 case IPW_FW_ERROR_EEPROM_ERROR:
542 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400543 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500544 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400545 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500546 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400547 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500548 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600549 }
550}
551
James Ketrenosb39860c2005-08-12 09:36:32 -0500552static void ipw_dump_error_log(struct ipw_priv *priv,
553 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600554{
James Ketrenosb39860c2005-08-12 09:36:32 -0500555 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600556
James Ketrenosb39860c2005-08-12 09:36:32 -0500557 if (!error) {
558 IPW_ERROR("Error allocating and capturing error log. "
559 "Nothing to dump.\n");
560 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600561 }
562
James Ketrenosb39860c2005-08-12 09:36:32 -0500563 IPW_ERROR("Start IPW Error Log Dump:\n");
564 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
565 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600566
James Ketrenosb39860c2005-08-12 09:36:32 -0500567 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400568 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500569 ipw_error_desc(error->elem[i].desc),
570 error->elem[i].time,
571 error->elem[i].blink1,
572 error->elem[i].blink2,
573 error->elem[i].link1,
574 error->elem[i].link2, error->elem[i].data);
575 for (i = 0; i < error->log_len; i++)
576 IPW_ERROR("%i\t0x%08x\t%i\n",
577 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500578 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600579}
James Ketrenos43f66a62005-03-25 12:31:53 -0600580#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600581
James Ketrenosc848d0a2005-08-24 21:56:24 -0500582static inline int ipw_is_init(struct ipw_priv *priv)
583{
584 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600585}
586
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400587static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600588{
589 u32 addr, field_info, field_len, field_count, total_len;
590
591 IPW_DEBUG_ORD("ordinal = %i\n", ord);
592
593 if (!priv || !val || !len) {
594 IPW_DEBUG_ORD("Invalid argument\n");
595 return -EINVAL;
596 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400597
James Ketrenos43f66a62005-03-25 12:31:53 -0600598 /* verify device ordinal tables have been initialized */
599 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
600 IPW_DEBUG_ORD("Access ordinals before initialization\n");
601 return -EINVAL;
602 }
603
604 switch (IPW_ORD_TABLE_ID_MASK & ord) {
605 case IPW_ORD_TABLE_0_MASK:
606 /*
607 * TABLE 0: Direct access to a table of 32 bit values
608 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400609 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600610 * read from the table
611 */
612
613 /* remove the table id from the ordinal */
614 ord &= IPW_ORD_TABLE_VALUE_MASK;
615
616 /* boundary check */
617 if (ord > priv->table0_len) {
618 IPW_DEBUG_ORD("ordinal value (%i) longer then "
619 "max (%i)\n", ord, priv->table0_len);
620 return -EINVAL;
621 }
622
623 /* verify we have enough room to store the value */
624 if (*len < sizeof(u32)) {
625 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200626 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600627 return -EINVAL;
628 }
629
630 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400631 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600632
633 *len = sizeof(u32);
634 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400635 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600636 break;
637
638 case IPW_ORD_TABLE_1_MASK:
639 /*
640 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400641 *
642 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600643 * representing starting addr for the data (which is
644 * also a u32)
645 */
646
647 /* remove the table id from the ordinal */
648 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400649
James Ketrenos43f66a62005-03-25 12:31:53 -0600650 /* boundary check */
651 if (ord > priv->table1_len) {
652 IPW_DEBUG_ORD("ordinal value too long\n");
653 return -EINVAL;
654 }
655
656 /* verify we have enough room to store the value */
657 if (*len < sizeof(u32)) {
658 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200659 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600660 return -EINVAL;
661 }
662
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400663 *((u32 *) val) =
664 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600665 *len = sizeof(u32);
666 break;
667
668 case IPW_ORD_TABLE_2_MASK:
669 /*
670 * TABLE 2: Indirect access to a table of variable sized values
671 *
672 * This table consist of six values, each containing
673 * - dword containing the starting offset of the data
674 * - dword containing the lengh in the first 16bits
675 * and the count in the second 16bits
676 */
677
678 /* remove the table id from the ordinal */
679 ord &= IPW_ORD_TABLE_VALUE_MASK;
680
681 /* boundary check */
682 if (ord > priv->table2_len) {
683 IPW_DEBUG_ORD("ordinal value too long\n");
684 return -EINVAL;
685 }
686
687 /* get the address of statistic */
688 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400689
690 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600691 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400692 field_info =
693 ipw_read_reg32(priv,
694 priv->table2_addr + (ord << 3) +
695 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400696
James Ketrenos43f66a62005-03-25 12:31:53 -0600697 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400698 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400699
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400701 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400702
James Ketrenos43f66a62005-03-25 12:31:53 -0600703 /* abort if not enought memory */
704 total_len = field_len * field_count;
705 if (total_len > *len) {
706 *len = total_len;
707 return -EINVAL;
708 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400709
James Ketrenos43f66a62005-03-25 12:31:53 -0600710 *len = total_len;
711 if (!total_len)
712 return 0;
713
714 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400715 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600716 addr, total_len, field_info);
717 ipw_read_indirect(priv, addr, val, total_len);
718 break;
719
720 default:
721 IPW_DEBUG_ORD("Invalid ordinal!\n");
722 return -EINVAL;
723
724 }
725
James Ketrenos43f66a62005-03-25 12:31:53 -0600726 return 0;
727}
728
729static void ipw_init_ordinals(struct ipw_priv *priv)
730{
731 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400732 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600733
734 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
735 priv->table0_addr, priv->table0_len);
736
737 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
738 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
739
740 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
741 priv->table1_addr, priv->table1_len);
742
743 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
744 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400745 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600746
747 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
748 priv->table2_addr, priv->table2_len);
749
750}
751
Adrian Bunka73e22b2006-01-21 01:39:42 +0100752static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500753{
James Ketrenosb095c382005-08-24 22:04:42 -0500754 reg &= ~IPW_START_STANDBY;
755 if (reg & IPW_GATE_ODMA)
756 reg &= ~IPW_GATE_ODMA;
757 if (reg & IPW_GATE_IDMA)
758 reg &= ~IPW_GATE_IDMA;
759 if (reg & IPW_GATE_ADMA)
760 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500761 return reg;
762}
763
764/*
765 * LED behavior:
766 * - On radio ON, turn on any LEDs that require to be on during start
767 * - On initialization, start unassociated blink
768 * - On association, disable unassociated blink
769 * - On disassociation, start unassociated blink
770 * - On radio OFF, turn off any LEDs started during radio on
771 *
772 */
Zhu Yiede61112006-01-24 16:37:10 +0800773#define LD_TIME_LINK_ON msecs_to_jiffies(300)
774#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
775#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500776
Adrian Bunka73e22b2006-01-21 01:39:42 +0100777static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500778{
779 unsigned long flags;
780 u32 led;
781
782 /* If configured to not use LEDs, or nic_type is 1,
783 * then we don't toggle a LINK led */
784 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
785 return;
786
787 spin_lock_irqsave(&priv->lock, flags);
788
789 if (!(priv->status & STATUS_RF_KILL_MASK) &&
790 !(priv->status & STATUS_LED_LINK_ON)) {
791 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500792 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500793 led |= priv->led_association_on;
794
795 led = ipw_register_toggle(led);
796
797 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500798 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500799
800 priv->status |= STATUS_LED_LINK_ON;
801
802 /* If we aren't associated, schedule turning the LED off */
803 if (!(priv->status & STATUS_ASSOCIATED))
804 queue_delayed_work(priv->workqueue,
805 &priv->led_link_off,
806 LD_TIME_LINK_ON);
807 }
808
809 spin_unlock_irqrestore(&priv->lock, flags);
810}
811
James Ketrenosc848d0a2005-08-24 21:56:24 -0500812static void ipw_bg_led_link_on(void *data)
813{
814 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800815 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500816 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800817 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500818}
819
Adrian Bunka73e22b2006-01-21 01:39:42 +0100820static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500821{
822 unsigned long flags;
823 u32 led;
824
825 /* If configured not to use LEDs, or nic type is 1,
826 * then we don't goggle the LINK led. */
827 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
828 return;
829
830 spin_lock_irqsave(&priv->lock, flags);
831
832 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500833 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500834 led &= priv->led_association_off;
835 led = ipw_register_toggle(led);
836
837 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500838 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500839
840 IPW_DEBUG_LED("Link LED Off\n");
841
842 priv->status &= ~STATUS_LED_LINK_ON;
843
844 /* If we aren't associated and the radio is on, schedule
845 * turning the LED on (blink while unassociated) */
846 if (!(priv->status & STATUS_RF_KILL_MASK) &&
847 !(priv->status & STATUS_ASSOCIATED))
848 queue_delayed_work(priv->workqueue, &priv->led_link_on,
849 LD_TIME_LINK_OFF);
850
851 }
852
853 spin_unlock_irqrestore(&priv->lock, flags);
854}
855
James Ketrenosc848d0a2005-08-24 21:56:24 -0500856static void ipw_bg_led_link_off(void *data)
857{
858 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800859 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500860 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800861 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500862}
863
Arjan van de Ven858119e2006-01-14 13:20:43 -0800864static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500865{
James Ketrenosa613bff2005-08-24 21:43:11 -0500866 u32 led;
867
868 if (priv->config & CFG_NO_LED)
869 return;
870
James Ketrenosb095c382005-08-24 22:04:42 -0500871 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500872 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500873
874 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500875 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500876 led |= priv->led_activity_on;
877
878 led = ipw_register_toggle(led);
879
880 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500881 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500882
883 IPW_DEBUG_LED("Activity LED On\n");
884
885 priv->status |= STATUS_LED_ACT_ON;
886
James Ketrenosc848d0a2005-08-24 21:56:24 -0500887 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500888 queue_delayed_work(priv->workqueue, &priv->led_act_off,
889 LD_TIME_ACT_ON);
890 } else {
891 /* Reschedule LED off for full time period */
892 cancel_delayed_work(&priv->led_act_off);
893 queue_delayed_work(priv->workqueue, &priv->led_act_off,
894 LD_TIME_ACT_ON);
895 }
James Ketrenosb095c382005-08-24 22:04:42 -0500896}
James Ketrenosa613bff2005-08-24 21:43:11 -0500897
Adrian Bunka73e22b2006-01-21 01:39:42 +0100898#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500899void ipw_led_activity_on(struct ipw_priv *priv)
900{
901 unsigned long flags;
902 spin_lock_irqsave(&priv->lock, flags);
903 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500904 spin_unlock_irqrestore(&priv->lock, flags);
905}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100906#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500907
Adrian Bunka73e22b2006-01-21 01:39:42 +0100908static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500909{
910 unsigned long flags;
911 u32 led;
912
913 if (priv->config & CFG_NO_LED)
914 return;
915
916 spin_lock_irqsave(&priv->lock, flags);
917
918 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500919 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500920 led &= priv->led_activity_off;
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 IPW_DEBUG_LED("Activity LED Off\n");
928
929 priv->status &= ~STATUS_LED_ACT_ON;
930 }
931
932 spin_unlock_irqrestore(&priv->lock, flags);
933}
934
James Ketrenosc848d0a2005-08-24 21:56:24 -0500935static void ipw_bg_led_activity_off(void *data)
936{
937 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800938 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500939 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800940 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500941}
942
Adrian Bunka73e22b2006-01-21 01:39:42 +0100943static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500944{
945 unsigned long flags;
946 u32 led;
947
948 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500949 if (priv->config & CFG_NO_LED ||
950 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500951 return;
952
953 spin_lock_irqsave(&priv->lock, flags);
954
James Ketrenosb095c382005-08-24 22:04:42 -0500955 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500956 if (priv->assoc_network->mode == IEEE_A) {
957 led |= priv->led_ofdm_on;
958 led &= priv->led_association_off;
959 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
960 } else if (priv->assoc_network->mode == IEEE_G) {
961 led |= priv->led_ofdm_on;
962 led |= priv->led_association_on;
963 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
964 } else {
965 led &= priv->led_ofdm_off;
966 led |= priv->led_association_on;
967 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
968 }
969
970 led = ipw_register_toggle(led);
971
972 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500973 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500974
975 spin_unlock_irqrestore(&priv->lock, flags);
976}
977
Adrian Bunka73e22b2006-01-21 01:39:42 +0100978static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500979{
980 unsigned long flags;
981 u32 led;
982
983 /* Only nic type 1 supports mode LEDs */
984 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
985 return;
986
987 spin_lock_irqsave(&priv->lock, flags);
988
James Ketrenosb095c382005-08-24 22:04:42 -0500989 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500990 led &= priv->led_ofdm_off;
991 led &= priv->led_association_off;
992
993 led = ipw_register_toggle(led);
994
995 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500996 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500997
998 spin_unlock_irqrestore(&priv->lock, flags);
999}
1000
Adrian Bunka73e22b2006-01-21 01:39:42 +01001001static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001002{
1003 ipw_led_link_on(priv);
1004}
1005
Adrian Bunka73e22b2006-01-21 01:39:42 +01001006static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001007{
1008 ipw_led_activity_off(priv);
1009 ipw_led_link_off(priv);
1010}
1011
Adrian Bunka73e22b2006-01-21 01:39:42 +01001012static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001013{
1014 /* Set the Link Led on for all nic types */
1015 ipw_led_link_on(priv);
1016}
1017
Adrian Bunka73e22b2006-01-21 01:39:42 +01001018static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001019{
1020 ipw_led_activity_off(priv);
1021 ipw_led_link_off(priv);
1022
1023 if (priv->status & STATUS_RF_KILL_MASK)
1024 ipw_led_radio_off(priv);
1025}
1026
Adrian Bunka73e22b2006-01-21 01:39:42 +01001027static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001028{
1029 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1030
1031 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001032 priv->led_activity_on = IPW_ACTIVITY_LED;
1033 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001034
James Ketrenosb095c382005-08-24 22:04:42 -05001035 priv->led_association_on = IPW_ASSOCIATED_LED;
1036 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001037
1038 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001039 priv->led_ofdm_on = IPW_OFDM_LED;
1040 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001041
1042 switch (priv->nic_type) {
1043 case EEPROM_NIC_TYPE_1:
1044 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001045 priv->led_activity_on = IPW_ASSOCIATED_LED;
1046 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1047 priv->led_association_on = IPW_ACTIVITY_LED;
1048 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001049
1050 if (!(priv->config & CFG_NO_LED))
1051 ipw_led_band_on(priv);
1052
1053 /* And we don't blink link LEDs for this nic, so
1054 * just return here */
1055 return;
1056
1057 case EEPROM_NIC_TYPE_3:
1058 case EEPROM_NIC_TYPE_2:
1059 case EEPROM_NIC_TYPE_4:
1060 case EEPROM_NIC_TYPE_0:
1061 break;
1062
1063 default:
1064 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1065 priv->nic_type);
1066 priv->nic_type = EEPROM_NIC_TYPE_0;
1067 break;
1068 }
1069
1070 if (!(priv->config & CFG_NO_LED)) {
1071 if (priv->status & STATUS_ASSOCIATED)
1072 ipw_led_link_on(priv);
1073 else
1074 ipw_led_link_off(priv);
1075 }
1076}
1077
Adrian Bunka73e22b2006-01-21 01:39:42 +01001078static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001079{
James Ketrenosa613bff2005-08-24 21:43:11 -05001080 ipw_led_activity_off(priv);
1081 ipw_led_link_off(priv);
1082 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001083 cancel_delayed_work(&priv->led_link_on);
1084 cancel_delayed_work(&priv->led_link_off);
1085 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001086}
1087
James Ketrenos43f66a62005-03-25 12:31:53 -06001088/*
1089 * The following adds a new attribute to the sysfs representation
1090 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1091 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001092 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001093 * See the level definitions in ipw for details.
1094 */
1095static ssize_t show_debug_level(struct device_driver *d, char *buf)
1096{
1097 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1098}
James Ketrenosa613bff2005-08-24 21:43:11 -05001099
1100static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1101 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001102{
1103 char *p = (char *)buf;
1104 u32 val;
1105
1106 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1107 p++;
1108 if (p[0] == 'x' || p[0] == 'X')
1109 p++;
1110 val = simple_strtoul(p, &p, 16);
1111 } else
1112 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001113 if (p == buf)
1114 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001115 ": %s is not in hex or decimal form.\n", buf);
1116 else
1117 ipw_debug_level = val;
1118
1119 return strnlen(buf, count);
1120}
1121
Jeff Garzikbf794512005-07-31 13:07:26 -04001122static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001123 show_debug_level, store_debug_level);
1124
James Ketrenosb39860c2005-08-12 09:36:32 -05001125static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1126{
Zhu Yic8fe6672006-01-24 16:36:36 +08001127 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001128 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1129}
1130
1131static void ipw_capture_event_log(struct ipw_priv *priv,
1132 u32 log_len, struct ipw_event *log)
1133{
1134 u32 base;
1135
1136 if (log_len) {
1137 base = ipw_read32(priv, IPW_EVENT_LOG);
1138 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1139 (u8 *) log, sizeof(*log) * log_len);
1140 }
1141}
1142
1143static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1144{
1145 struct ipw_fw_error *error;
1146 u32 log_len = ipw_get_event_log_len(priv);
1147 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1148 u32 elem_len = ipw_read_reg32(priv, base);
1149
1150 error = kmalloc(sizeof(*error) +
1151 sizeof(*error->elem) * elem_len +
1152 sizeof(*error->log) * log_len, GFP_ATOMIC);
1153 if (!error) {
1154 IPW_ERROR("Memory allocation for firmware error log "
1155 "failed.\n");
1156 return NULL;
1157 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001158 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001159 error->status = priv->status;
1160 error->config = priv->config;
1161 error->elem_len = elem_len;
1162 error->log_len = log_len;
1163 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001164 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001165
1166 ipw_capture_event_log(priv, log_len, error->log);
1167
1168 if (elem_len)
1169 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1170 sizeof(*error->elem) * elem_len);
1171
1172 return error;
1173}
1174
1175static void ipw_free_error_log(struct ipw_fw_error *error)
1176{
1177 if (error)
1178 kfree(error);
1179}
1180
1181static ssize_t show_event_log(struct device *d,
1182 struct device_attribute *attr, char *buf)
1183{
1184 struct ipw_priv *priv = dev_get_drvdata(d);
1185 u32 log_len = ipw_get_event_log_len(priv);
1186 struct ipw_event log[log_len];
1187 u32 len = 0, i;
1188
1189 ipw_capture_event_log(priv, log_len, log);
1190
1191 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1192 for (i = 0; i < log_len; i++)
1193 len += snprintf(buf + len, PAGE_SIZE - len,
1194 "\n%08X%08X%08X",
1195 log[i].time, log[i].event, log[i].data);
1196 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1197 return len;
1198}
1199
1200static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1201
1202static ssize_t show_error(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->error)
1208 return 0;
1209 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001210 "%08lX%08X%08X%08X",
1211 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001212 priv->error->status,
1213 priv->error->config, priv->error->elem_len);
1214 for (i = 0; i < priv->error->elem_len; i++)
1215 len += snprintf(buf + len, PAGE_SIZE - len,
1216 "\n%08X%08X%08X%08X%08X%08X%08X",
1217 priv->error->elem[i].time,
1218 priv->error->elem[i].desc,
1219 priv->error->elem[i].blink1,
1220 priv->error->elem[i].blink2,
1221 priv->error->elem[i].link1,
1222 priv->error->elem[i].link2,
1223 priv->error->elem[i].data);
1224
1225 len += snprintf(buf + len, PAGE_SIZE - len,
1226 "\n%08X", priv->error->log_len);
1227 for (i = 0; i < priv->error->log_len; i++)
1228 len += snprintf(buf + len, PAGE_SIZE - len,
1229 "\n%08X%08X%08X",
1230 priv->error->log[i].time,
1231 priv->error->log[i].event,
1232 priv->error->log[i].data);
1233 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1234 return len;
1235}
1236
1237static ssize_t clear_error(struct device *d,
1238 struct device_attribute *attr,
1239 const char *buf, size_t count)
1240{
1241 struct ipw_priv *priv = dev_get_drvdata(d);
1242 if (priv->error) {
1243 ipw_free_error_log(priv->error);
1244 priv->error = NULL;
1245 }
1246 return count;
1247}
1248
1249static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1250
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001251static ssize_t show_cmd_log(struct device *d,
1252 struct device_attribute *attr, char *buf)
1253{
1254 struct ipw_priv *priv = dev_get_drvdata(d);
1255 u32 len = 0, i;
1256 if (!priv->cmdlog)
1257 return 0;
1258 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1259 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1260 i = (i + 1) % priv->cmdlog_len) {
1261 len +=
1262 snprintf(buf + len, PAGE_SIZE - len,
1263 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1264 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1265 priv->cmdlog[i].cmd.len);
1266 len +=
1267 snprintk_buf(buf + len, PAGE_SIZE - len,
1268 (u8 *) priv->cmdlog[i].cmd.param,
1269 priv->cmdlog[i].cmd.len);
1270 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1271 }
1272 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1273 return len;
1274}
1275
1276static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1277
James Ketrenosa613bff2005-08-24 21:43:11 -05001278static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1279 char *buf)
1280{
1281 struct ipw_priv *priv = dev_get_drvdata(d);
1282 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1283}
1284
1285static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1286 const char *buf, size_t count)
1287{
1288 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001289#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001290 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001291#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001292 char buffer[] = "00000000";
1293 unsigned long len =
1294 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1295 unsigned long val;
1296 char *p = buffer;
1297
1298 IPW_DEBUG_INFO("enter\n");
1299
1300 strncpy(buffer, buf, len);
1301 buffer[len] = 0;
1302
1303 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1304 p++;
1305 if (p[0] == 'x' || p[0] == 'X')
1306 p++;
1307 val = simple_strtoul(p, &p, 16);
1308 } else
1309 val = simple_strtoul(p, &p, 10);
1310 if (p == buffer) {
1311 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1312 } else {
1313 priv->ieee->scan_age = val;
1314 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1315 }
1316
1317 IPW_DEBUG_INFO("exit\n");
1318 return len;
1319}
1320
1321static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1322
1323static ssize_t show_led(struct device *d, struct device_attribute *attr,
1324 char *buf)
1325{
1326 struct ipw_priv *priv = dev_get_drvdata(d);
1327 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1328}
1329
1330static ssize_t store_led(struct device *d, struct device_attribute *attr,
1331 const char *buf, size_t count)
1332{
1333 struct ipw_priv *priv = dev_get_drvdata(d);
1334
1335 IPW_DEBUG_INFO("enter\n");
1336
1337 if (count == 0)
1338 return 0;
1339
1340 if (*buf == 0) {
1341 IPW_DEBUG_LED("Disabling LED control.\n");
1342 priv->config |= CFG_NO_LED;
1343 ipw_led_shutdown(priv);
1344 } else {
1345 IPW_DEBUG_LED("Enabling LED control.\n");
1346 priv->config &= ~CFG_NO_LED;
1347 ipw_led_init(priv);
1348 }
1349
1350 IPW_DEBUG_INFO("exit\n");
1351 return count;
1352}
1353
1354static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1355
Andrew Mortonad3fee52005-06-20 14:30:36 -07001356static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001357 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001358{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001359 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001360 return sprintf(buf, "0x%08x\n", (int)p->status);
1361}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001362
James Ketrenos43f66a62005-03-25 12:31:53 -06001363static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1364
Andrew Mortonad3fee52005-06-20 14:30:36 -07001365static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1366 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001367{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001368 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001369 return sprintf(buf, "0x%08x\n", (int)p->config);
1370}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001371
James Ketrenos43f66a62005-03-25 12:31:53 -06001372static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1373
Andrew Mortonad3fee52005-06-20 14:30:36 -07001374static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001375 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001376{
James Ketrenosa613bff2005-08-24 21:43:11 -05001377 struct ipw_priv *priv = d->driver_data;
1378 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001379}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001380
James Ketrenos43f66a62005-03-25 12:31:53 -06001381static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1382
Andrew Mortonad3fee52005-06-20 14:30:36 -07001383static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001384 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001385{
1386 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001387 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001388
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001389 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001390 return 0;
1391
1392 return sprintf(buf, "0x%08x\n", tmp);
1393}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001394
1395static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001396
Andrew Mortonad3fee52005-06-20 14:30:36 -07001397static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1398 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001399{
1400 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001401 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001402
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001403 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001404 return 0;
1405
1406 return sprintf(buf, "0x%08x\n", tmp);
1407}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001408
1409static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001410
1411/*
1412 * Add a device attribute to view/control the delay between eeprom
1413 * operations.
1414 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001415static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001416 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001417{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001418 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001419 return sprintf(buf, "%i\n", n);
1420}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001421static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001422 struct device_attribute *attr,
1423 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001424{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001425 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001426 sscanf(buf, "%i", &p->eeprom_delay);
1427 return strnlen(buf, count);
1428}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001429
1430static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1431 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001432
Andrew Mortonad3fee52005-06-20 14:30:36 -07001433static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001434 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001435{
1436 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001437 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001438
James Ketrenosb095c382005-08-24 22:04:42 -05001439 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001440 return sprintf(buf, "0x%08x\n", reg);
1441}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001442static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001443 struct device_attribute *attr,
1444 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001445{
1446 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001447 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001448
1449 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001450 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001451 return strnlen(buf, count);
1452}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001453
1454static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1455 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001456
Andrew Mortonad3fee52005-06-20 14:30:36 -07001457static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001458 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001459{
1460 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001461 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001462
1463 reg = ipw_read_reg32(p, 0x301100);
1464 return sprintf(buf, "0x%08x\n", reg);
1465}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001466static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001467 struct device_attribute *attr,
1468 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001469{
1470 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001471 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001472
1473 sscanf(buf, "%x", &reg);
1474 ipw_write_reg32(p, 0x301100, reg);
1475 return strnlen(buf, count);
1476}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001477
1478static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1479 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001480
Andrew Mortonad3fee52005-06-20 14:30:36 -07001481static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001482 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001483{
1484 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001485 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001486
Jeff Garzikbf794512005-07-31 13:07:26 -04001487 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001488 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001489 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001490 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001491
James Ketrenos43f66a62005-03-25 12:31:53 -06001492 return sprintf(buf, "0x%08x\n", reg);
1493}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001494static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001495 struct device_attribute *attr,
1496 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001497{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001498 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001499
1500 sscanf(buf, "%x", &priv->indirect_dword);
1501 priv->status |= STATUS_INDIRECT_DWORD;
1502 return strnlen(buf, count);
1503}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001504
1505static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1506 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001507
Andrew Mortonad3fee52005-06-20 14:30:36 -07001508static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001509 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001510{
1511 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001512 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001513
Jeff Garzikbf794512005-07-31 13:07:26 -04001514 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001515 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001516 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001517 reg = 0;
1518
1519 return sprintf(buf, "0x%02x\n", reg);
1520}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001521static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001522 struct device_attribute *attr,
1523 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001524{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001525 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001526
1527 sscanf(buf, "%x", &priv->indirect_byte);
1528 priv->status |= STATUS_INDIRECT_BYTE;
1529 return strnlen(buf, count);
1530}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001531
1532static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001533 show_indirect_byte, store_indirect_byte);
1534
Andrew Mortonad3fee52005-06-20 14:30:36 -07001535static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001536 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001537{
1538 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001539 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001540
Jeff Garzikbf794512005-07-31 13:07:26 -04001541 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001542 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001543 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001544 reg = 0;
1545
1546 return sprintf(buf, "0x%08x\n", reg);
1547}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001548static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001549 struct device_attribute *attr,
1550 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001551{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001552 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001553
1554 sscanf(buf, "%x", &priv->direct_dword);
1555 priv->status |= STATUS_DIRECT_DWORD;
1556 return strnlen(buf, count);
1557}
James Ketrenos43f66a62005-03-25 12:31:53 -06001558
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001559static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1560 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001561
Arjan van de Ven858119e2006-01-14 13:20:43 -08001562static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001563{
1564 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1565 priv->status |= STATUS_RF_KILL_HW;
1566 else
1567 priv->status &= ~STATUS_RF_KILL_HW;
1568
1569 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1570}
1571
Andrew Mortonad3fee52005-06-20 14:30:36 -07001572static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001573 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001574{
1575 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001576 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001577 2 - HW based RF kill active
1578 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001579 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001580 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001581 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001582 return sprintf(buf, "%i\n", val);
1583}
1584
1585static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1586{
Jeff Garzikbf794512005-07-31 13:07:26 -04001587 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001588 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001589 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001590
1591 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1592 disable_radio ? "OFF" : "ON");
1593
1594 if (disable_radio) {
1595 priv->status |= STATUS_RF_KILL_SW;
1596
James Ketrenosa613bff2005-08-24 21:43:11 -05001597 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001598 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001599 queue_work(priv->workqueue, &priv->down);
1600 } else {
1601 priv->status &= ~STATUS_RF_KILL_SW;
1602 if (rf_kill_active(priv)) {
1603 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1604 "disabled by HW switch\n");
1605 /* Make sure the RF_KILL check timer is running */
1606 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001607 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001608 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001609 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001610 queue_work(priv->workqueue, &priv->up);
1611 }
1612
1613 return 1;
1614}
1615
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001616static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1617 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001618{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001619 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001620
James Ketrenos43f66a62005-03-25 12:31:53 -06001621 ipw_radio_kill_sw(priv, buf[0] == '1');
1622
1623 return count;
1624}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001625
1626static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001627
James Ketrenosb095c382005-08-24 22:04:42 -05001628static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1629 char *buf)
1630{
1631 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1632 int pos = 0, len = 0;
1633 if (priv->config & CFG_SPEED_SCAN) {
1634 while (priv->speed_scan[pos] != 0)
1635 len += sprintf(&buf[len], "%d ",
1636 priv->speed_scan[pos++]);
1637 return len + sprintf(&buf[len], "\n");
1638 }
1639
1640 return sprintf(buf, "0\n");
1641}
1642
1643static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1644 const char *buf, size_t count)
1645{
1646 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1647 int channel, pos = 0;
1648 const char *p = buf;
1649
1650 /* list of space separated channels to scan, optionally ending with 0 */
1651 while ((channel = simple_strtol(p, NULL, 0))) {
1652 if (pos == MAX_SPEED_SCAN - 1) {
1653 priv->speed_scan[pos] = 0;
1654 break;
1655 }
1656
Liu Hong1fe0adb2005-08-19 09:33:10 -05001657 if (ipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001658 priv->speed_scan[pos++] = channel;
1659 else
1660 IPW_WARNING("Skipping invalid channel request: %d\n",
1661 channel);
1662 p = strchr(p, ' ');
1663 if (!p)
1664 break;
1665 while (*p == ' ' || *p == '\t')
1666 p++;
1667 }
1668
1669 if (pos == 0)
1670 priv->config &= ~CFG_SPEED_SCAN;
1671 else {
1672 priv->speed_scan_pos = 0;
1673 priv->config |= CFG_SPEED_SCAN;
1674 }
1675
1676 return count;
1677}
1678
1679static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1680 store_speed_scan);
1681
1682static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1683 char *buf)
1684{
1685 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1686 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1687}
1688
1689static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1690 const char *buf, size_t count)
1691{
1692 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1693 if (buf[0] == '1')
1694 priv->config |= CFG_NET_STATS;
1695 else
1696 priv->config &= ~CFG_NET_STATS;
1697
1698 return count;
1699}
1700
James Ketrenosafbf30a2005-08-25 00:05:33 -05001701static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1702 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001703
James Ketrenosea2b26e2005-08-24 21:25:16 -05001704static void notify_wx_assoc_event(struct ipw_priv *priv)
1705{
1706 union iwreq_data wrqu;
1707 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1708 if (priv->status & STATUS_ASSOCIATED)
1709 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1710 else
1711 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1712 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1713}
1714
James Ketrenos43f66a62005-03-25 12:31:53 -06001715static void ipw_irq_tasklet(struct ipw_priv *priv)
1716{
1717 u32 inta, inta_mask, handled = 0;
1718 unsigned long flags;
1719 int rc = 0;
1720
1721 spin_lock_irqsave(&priv->lock, flags);
1722
James Ketrenosb095c382005-08-24 22:04:42 -05001723 inta = ipw_read32(priv, IPW_INTA_RW);
1724 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1725 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001726
1727 /* Add any cached INTA values that need to be handled */
1728 inta |= priv->isr_inta;
1729
1730 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001731 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001732 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001733 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001734 }
1735
James Ketrenosb095c382005-08-24 22:04:42 -05001736 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001737 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001738 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 priv->status &= ~STATUS_HCMD_ACTIVE;
1740 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001741 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 }
1743
James Ketrenosb095c382005-08-24 22:04:42 -05001744 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001745 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001746 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001747 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 }
1749
James Ketrenosb095c382005-08-24 22:04:42 -05001750 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001751 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001752 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001753 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001754 }
1755
James Ketrenosb095c382005-08-24 22:04:42 -05001756 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001758 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001759 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 }
1761
James Ketrenosb095c382005-08-24 22:04:42 -05001762 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001763 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001764 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001765 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 }
1767
James Ketrenosb095c382005-08-24 22:04:42 -05001768 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001769 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001770 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001771 }
1772
James Ketrenosb095c382005-08-24 22:04:42 -05001773 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001774 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001775 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 }
1777
James Ketrenosb095c382005-08-24 22:04:42 -05001778 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001779 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001780 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 }
1782
James Ketrenosb095c382005-08-24 22:04:42 -05001783 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001784 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001785 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001786 }
1787
James Ketrenosb095c382005-08-24 22:04:42 -05001788 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001789 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001790 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001791 }
1792
James Ketrenosb095c382005-08-24 22:04:42 -05001793 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001794 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1795 priv->status |= STATUS_RF_KILL_HW;
1796 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001797 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001798 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001799 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001800 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001801 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001802 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001803
James Ketrenosb095c382005-08-24 22:04:42 -05001804 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001805 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001806 if (priv->error) {
1807 IPW_ERROR("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001808#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001809 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1810 struct ipw_fw_error *error =
1811 ipw_alloc_error_log(priv);
1812 ipw_dump_error_log(priv, error);
1813 if (error)
1814 ipw_free_error_log(error);
1815 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001816#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001817 } else {
1818 priv->error = ipw_alloc_error_log(priv);
1819 if (priv->error)
1820 IPW_ERROR("Sysfs 'error' log captured.\n");
1821 else
1822 IPW_ERROR("Error allocating sysfs 'error' "
1823 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001824#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001825 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1826 ipw_dump_error_log(priv, priv->error);
1827#endif
1828 }
1829
James Ketrenosb095c382005-08-24 22:04:42 -05001830 /* XXX: If hardware encryption is for WPA/WPA2,
1831 * we have to notify the supplicant. */
1832 if (priv->ieee->sec.encrypt) {
1833 priv->status &= ~STATUS_ASSOCIATED;
1834 notify_wx_assoc_event(priv);
1835 }
1836
1837 /* Keep the restart process from trying to send host
1838 * commands by clearing the INIT status bit */
1839 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001840
1841 /* Cancel currently queued command. */
1842 priv->status &= ~STATUS_HCMD_ACTIVE;
1843 wake_up_interruptible(&priv->wait_command_queue);
1844
James Ketrenos43f66a62005-03-25 12:31:53 -06001845 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001846 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001847 }
1848
James Ketrenosb095c382005-08-24 22:04:42 -05001849 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001850 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001851 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001852 }
1853
1854 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001855 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001856 }
1857
1858 /* enable all interrupts */
1859 ipw_enable_interrupts(priv);
1860
1861 spin_unlock_irqrestore(&priv->lock, flags);
1862}
Jeff Garzikbf794512005-07-31 13:07:26 -04001863
James Ketrenos43f66a62005-03-25 12:31:53 -06001864#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1865static char *get_cmd_string(u8 cmd)
1866{
1867 switch (cmd) {
1868 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001869 IPW_CMD(POWER_DOWN);
1870 IPW_CMD(SYSTEM_CONFIG);
1871 IPW_CMD(MULTICAST_ADDRESS);
1872 IPW_CMD(SSID);
1873 IPW_CMD(ADAPTER_ADDRESS);
1874 IPW_CMD(PORT_TYPE);
1875 IPW_CMD(RTS_THRESHOLD);
1876 IPW_CMD(FRAG_THRESHOLD);
1877 IPW_CMD(POWER_MODE);
1878 IPW_CMD(WEP_KEY);
1879 IPW_CMD(TGI_TX_KEY);
1880 IPW_CMD(SCAN_REQUEST);
1881 IPW_CMD(SCAN_REQUEST_EXT);
1882 IPW_CMD(ASSOCIATE);
1883 IPW_CMD(SUPPORTED_RATES);
1884 IPW_CMD(SCAN_ABORT);
1885 IPW_CMD(TX_FLUSH);
1886 IPW_CMD(QOS_PARAMETERS);
1887 IPW_CMD(DINO_CONFIG);
1888 IPW_CMD(RSN_CAPABILITIES);
1889 IPW_CMD(RX_KEY);
1890 IPW_CMD(CARD_DISABLE);
1891 IPW_CMD(SEED_NUMBER);
1892 IPW_CMD(TX_POWER);
1893 IPW_CMD(COUNTRY_INFO);
1894 IPW_CMD(AIRONET_INFO);
1895 IPW_CMD(AP_TX_POWER);
1896 IPW_CMD(CCKM_INFO);
1897 IPW_CMD(CCX_VER_INFO);
1898 IPW_CMD(SET_CALIBRATION);
1899 IPW_CMD(SENSITIVITY_CALIB);
1900 IPW_CMD(RETRY_LIMIT);
1901 IPW_CMD(IPW_PRE_POWER_DOWN);
1902 IPW_CMD(VAP_BEACON_TEMPLATE);
1903 IPW_CMD(VAP_DTIM_PERIOD);
1904 IPW_CMD(EXT_SUPPORTED_RATES);
1905 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1906 IPW_CMD(VAP_QUIET_INTERVALS);
1907 IPW_CMD(VAP_CHANNEL_SWITCH);
1908 IPW_CMD(VAP_MANDATORY_CHANNELS);
1909 IPW_CMD(VAP_CELL_PWR_LIMIT);
1910 IPW_CMD(VAP_CF_PARAM_SET);
1911 IPW_CMD(VAP_SET_BEACONING_STATE);
1912 IPW_CMD(MEASUREMENT);
1913 IPW_CMD(POWER_CAPABILITY);
1914 IPW_CMD(SUPPORTED_CHANNELS);
1915 IPW_CMD(TPC_REPORT);
1916 IPW_CMD(WME_INFO);
1917 IPW_CMD(PRODUCTION_COMMAND);
1918 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001919 return "UNKNOWN";
1920 }
1921}
James Ketrenos43f66a62005-03-25 12:31:53 -06001922
1923#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001924
1925static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06001926{
1927 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001928 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001929
James Ketrenosa613bff2005-08-24 21:43:11 -05001930 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001931 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001932 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1933 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001934 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001935 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001936 }
1937
1938 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001939
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001940 if (priv->cmdlog) {
1941 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1942 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1943 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1944 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1945 cmd->len);
1946 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1947 }
1948
James Ketrenosb095c382005-08-24 22:04:42 -05001949 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1950 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1951 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08001952
1953#ifndef DEBUG_CMD_WEP_KEY
1954 if (cmd->cmd == IPW_CMD_WEP_KEY)
1955 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1956 else
1957#endif
1958 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1959
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001960 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001961 if (rc) {
1962 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001963 IPW_ERROR("Failed to send %s: Reason %d\n",
1964 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001965 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001966 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001967 }
1968 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001969
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001970 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1971 !(priv->
1972 status & STATUS_HCMD_ACTIVE),
1973 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001974 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001975 spin_lock_irqsave(&priv->lock, flags);
1976 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001977 IPW_ERROR("Failed to send %s: Command timed out.\n",
1978 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001979 priv->status &= ~STATUS_HCMD_ACTIVE;
1980 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001981 rc = -EIO;
1982 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001983 }
1984 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001985 } else
1986 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001987
James Ketrenosb095c382005-08-24 22:04:42 -05001988 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001989 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1990 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001991 rc = -EIO;
1992 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06001993 }
1994
Zhu Yi2638bc32006-01-24 16:37:52 +08001995 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001996 if (priv->cmdlog) {
1997 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1998 priv->cmdlog_pos %= priv->cmdlog_len;
1999 }
2000 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002001}
2002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002003static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002004{
2005 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002006 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002007 };
2008
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002009 return __ipw_send_cmd(priv, &cmd);
2010}
2011
2012static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2013 void *data)
2014{
2015 struct host_cmd cmd = {
2016 .cmd = command,
2017 .len = len,
2018 .param = data,
2019 };
2020
2021 return __ipw_send_cmd(priv, &cmd);
2022}
2023
2024static int ipw_send_host_complete(struct ipw_priv *priv)
2025{
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 if (!priv) {
2027 IPW_ERROR("Invalid args\n");
2028 return -1;
2029 }
2030
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002031 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002032}
2033
Jeff Garzikbf794512005-07-31 13:07:26 -04002034static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002035 struct ipw_sys_config *config)
2036{
James Ketrenos43f66a62005-03-25 12:31:53 -06002037 if (!priv || !config) {
2038 IPW_ERROR("Invalid args\n");
2039 return -1;
2040 }
2041
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002042 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
Zhu Yi2638bc32006-01-24 16:37:52 +08002043 config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002044}
2045
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002046static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002047{
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 if (!priv || !ssid) {
2049 IPW_ERROR("Invalid args\n");
2050 return -1;
2051 }
2052
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002053 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002054 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002055}
2056
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002057static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002058{
James Ketrenos43f66a62005-03-25 12:31:53 -06002059 if (!priv || !mac) {
2060 IPW_ERROR("Invalid args\n");
2061 return -1;
2062 }
2063
2064 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2065 priv->net_dev->name, MAC_ARG(mac));
2066
Zhu Yi2638bc32006-01-24 16:37:52 +08002067 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002068}
2069
James Ketrenosa613bff2005-08-24 21:43:11 -05002070/*
2071 * NOTE: This must be executed from our workqueue as it results in udelay
2072 * being called which may corrupt the keyboard if executed on default
2073 * workqueue
2074 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002075static void ipw_adapter_restart(void *adapter)
2076{
2077 struct ipw_priv *priv = adapter;
2078
2079 if (priv->status & STATUS_RF_KILL_MASK)
2080 return;
2081
2082 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002083
2084 if (priv->assoc_network &&
2085 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2086 ipw_remove_current_network(priv);
2087
James Ketrenos43f66a62005-03-25 12:31:53 -06002088 if (ipw_up(priv)) {
2089 IPW_ERROR("Failed to up device\n");
2090 return;
2091 }
2092}
2093
James Ketrenosc848d0a2005-08-24 21:56:24 -05002094static void ipw_bg_adapter_restart(void *data)
2095{
2096 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002097 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002098 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002099 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002100}
2101
James Ketrenos43f66a62005-03-25 12:31:53 -06002102#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2103
2104static void ipw_scan_check(void *data)
2105{
2106 struct ipw_priv *priv = data;
2107 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2108 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002109 "adapter after (%dms).\n",
2110 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002111 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002112 }
2113}
2114
James Ketrenosc848d0a2005-08-24 21:56:24 -05002115static void ipw_bg_scan_check(void *data)
2116{
2117 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002118 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002119 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002120 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002121}
2122
James Ketrenos43f66a62005-03-25 12:31:53 -06002123static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2124 struct ipw_scan_request_ext *request)
2125{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002126 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002127 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002128}
2129
2130static int ipw_send_scan_abort(struct ipw_priv *priv)
2131{
James Ketrenos43f66a62005-03-25 12:31:53 -06002132 if (!priv) {
2133 IPW_ERROR("Invalid args\n");
2134 return -1;
2135 }
2136
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002137 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002138}
2139
2140static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2141{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002142 struct ipw_sensitivity_calib calib = {
2143 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002144 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002145
2146 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002147 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002148}
2149
2150static int ipw_send_associate(struct ipw_priv *priv,
2151 struct ipw_associate *associate)
2152{
James Ketrenosa613bff2005-08-24 21:43:11 -05002153 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002154
2155 if (!priv || !associate) {
2156 IPW_ERROR("Invalid args\n");
2157 return -1;
2158 }
2159
James Ketrenosa613bff2005-08-24 21:43:11 -05002160 memcpy(&tmp_associate, associate, sizeof(*associate));
2161 tmp_associate.policy_support =
2162 cpu_to_le16(tmp_associate.policy_support);
2163 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2164 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2165 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2166 tmp_associate.listen_interval =
2167 cpu_to_le16(tmp_associate.listen_interval);
2168 tmp_associate.beacon_interval =
2169 cpu_to_le16(tmp_associate.beacon_interval);
2170 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2171
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002172 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002173 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002174}
2175
2176static int ipw_send_supported_rates(struct ipw_priv *priv,
2177 struct ipw_supported_rates *rates)
2178{
James Ketrenos43f66a62005-03-25 12:31:53 -06002179 if (!priv || !rates) {
2180 IPW_ERROR("Invalid args\n");
2181 return -1;
2182 }
2183
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002184 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002185 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002186}
2187
2188static int ipw_set_random_seed(struct ipw_priv *priv)
2189{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002190 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002191
2192 if (!priv) {
2193 IPW_ERROR("Invalid args\n");
2194 return -1;
2195 }
2196
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002197 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002198
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002199 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002200}
2201
James Ketrenos43f66a62005-03-25 12:31:53 -06002202static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2203{
James Ketrenos43f66a62005-03-25 12:31:53 -06002204 if (!priv) {
2205 IPW_ERROR("Invalid args\n");
2206 return -1;
2207 }
2208
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002209 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002210 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002211}
James Ketrenos43f66a62005-03-25 12:31:53 -06002212
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002213static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002214{
James Ketrenos43f66a62005-03-25 12:31:53 -06002215 if (!priv || !power) {
2216 IPW_ERROR("Invalid args\n");
2217 return -1;
2218 }
2219
Zhu Yi2638bc32006-01-24 16:37:52 +08002220 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002221}
James Ketrenos43f66a62005-03-25 12:31:53 -06002222
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002223static int ipw_set_tx_power(struct ipw_priv *priv)
2224{
Liu Hong1fe0adb2005-08-19 09:33:10 -05002225 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002226 struct ipw_tx_power tx_power;
2227 s8 max_power;
2228 int i;
2229
2230 memset(&tx_power, 0, sizeof(tx_power));
2231
2232 /* configure device for 'G' band */
2233 tx_power.ieee_mode = IPW_G_MODE;
2234 tx_power.num_channels = geo->bg_channels;
2235 for (i = 0; i < geo->bg_channels; i++) {
2236 max_power = geo->bg[i].max_power;
2237 tx_power.channels_tx_power[i].channel_number =
2238 geo->bg[i].channel;
2239 tx_power.channels_tx_power[i].tx_power = max_power ?
2240 min(max_power, priv->tx_power) : priv->tx_power;
2241 }
2242 if (ipw_send_tx_power(priv, &tx_power))
2243 return -EIO;
2244
2245 /* configure device to also handle 'B' band */
2246 tx_power.ieee_mode = IPW_B_MODE;
2247 if (ipw_send_tx_power(priv, &tx_power))
2248 return -EIO;
2249
2250 /* configure device to also handle 'A' band */
2251 if (priv->ieee->abg_true) {
2252 tx_power.ieee_mode = IPW_A_MODE;
2253 tx_power.num_channels = geo->a_channels;
2254 for (i = 0; i < tx_power.num_channels; i++) {
2255 max_power = geo->a[i].max_power;
2256 tx_power.channels_tx_power[i].channel_number =
2257 geo->a[i].channel;
2258 tx_power.channels_tx_power[i].tx_power = max_power ?
2259 min(max_power, priv->tx_power) : priv->tx_power;
2260 }
2261 if (ipw_send_tx_power(priv, &tx_power))
2262 return -EIO;
2263 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002264 return 0;
2265}
2266
2267static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2268{
2269 struct ipw_rts_threshold rts_threshold = {
2270 .rts_threshold = rts,
2271 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002272
2273 if (!priv) {
2274 IPW_ERROR("Invalid args\n");
2275 return -1;
2276 }
2277
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002278 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2279 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002280}
2281
2282static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2283{
2284 struct ipw_frag_threshold frag_threshold = {
2285 .frag_threshold = frag,
2286 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002287
2288 if (!priv) {
2289 IPW_ERROR("Invalid args\n");
2290 return -1;
2291 }
2292
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002293 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2294 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002295}
2296
2297static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2298{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002299 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002300
2301 if (!priv) {
2302 IPW_ERROR("Invalid args\n");
2303 return -1;
2304 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002305
James Ketrenos43f66a62005-03-25 12:31:53 -06002306 /* If on battery, set to 3, if AC set to CAM, else user
2307 * level */
2308 switch (mode) {
2309 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002310 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002311 break;
2312 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002313 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002314 break;
2315 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002316 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002317 break;
2318 }
2319
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002320 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002321 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002322}
2323
James Ketrenosafbf30a2005-08-25 00:05:33 -05002324static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2325{
2326 struct ipw_retry_limit retry_limit = {
2327 .short_retry_limit = slimit,
2328 .long_retry_limit = llimit
2329 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002330
2331 if (!priv) {
2332 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002333 return -1;
2334 }
2335
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002336 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002337 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002338}
2339
2340/*
2341 * The IPW device contains a Microwire compatible EEPROM that stores
2342 * various data like the MAC address. Usually the firmware has exclusive
2343 * access to the eeprom, but during device initialization (before the
2344 * device driver has sent the HostComplete command to the firmware) the
2345 * device driver has read access to the EEPROM by way of indirect addressing
2346 * through a couple of memory mapped registers.
2347 *
2348 * The following is a simplified implementation for pulling data out of the
2349 * the eeprom, along with some helper functions to find information in
2350 * the per device private data's copy of the eeprom.
2351 *
2352 * NOTE: To better understand how these functions work (i.e what is a chip
2353 * select and why do have to keep driving the eeprom clock?), read
2354 * just about any data sheet for a Microwire compatible EEPROM.
2355 */
2356
2357/* write a 32 bit value into the indirect accessor register */
2358static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2359{
2360 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002361
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 /* the eeprom requires some time to complete the operation */
2363 udelay(p->eeprom_delay);
2364
2365 return;
2366}
2367
2368/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002369static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002370{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002371 eeprom_write_reg(priv, 0);
2372 eeprom_write_reg(priv, EEPROM_BIT_CS);
2373 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2374 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002375}
2376
2377/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002378static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002379{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002380 eeprom_write_reg(priv, EEPROM_BIT_CS);
2381 eeprom_write_reg(priv, 0);
2382 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002383}
2384
2385/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002386static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002387{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002388 int d = (bit ? EEPROM_BIT_DI : 0);
2389 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2390 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002391}
2392
2393/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002394static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002395{
2396 int i;
2397
2398 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002399 eeprom_write_bit(priv, 1);
2400 eeprom_write_bit(priv, op & 2);
2401 eeprom_write_bit(priv, op & 1);
2402 for (i = 7; i >= 0; i--) {
2403 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002404 }
2405}
2406
2407/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002408static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002409{
2410 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002411 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002412
James Ketrenos43f66a62005-03-25 12:31:53 -06002413 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002414 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002415
2416 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002417 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002418
2419 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002420 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002421 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002422 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2423 eeprom_write_reg(priv, EEPROM_BIT_CS);
2424 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2425 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002426 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002427
James Ketrenos43f66a62005-03-25 12:31:53 -06002428 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002429 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002430 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002431
James Ketrenos43f66a62005-03-25 12:31:53 -06002432 return r;
2433}
2434
2435/* helper function for pulling the mac address out of the private */
2436/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002437static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002438{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002439 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002440}
2441
2442/*
2443 * Either the device driver (i.e. the host) or the firmware can
2444 * load eeprom data into the designated region in SRAM. If neither
2445 * happens then the FW will shutdown with a fatal error.
2446 *
2447 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2448 * bit needs region of shared SRAM needs to be non-zero.
2449 */
2450static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2451{
2452 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002453 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002454
James Ketrenos43f66a62005-03-25 12:31:53 -06002455 IPW_DEBUG_TRACE(">>\n");
2456
2457 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002458 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002459 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002460
Jeff Garzikbf794512005-07-31 13:07:26 -04002461 /*
2462 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002463 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002464 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002465 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002466 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2467 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2468
2469 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002470 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002471 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002472
2473 /* Do not load eeprom data on fatal error or suspend */
2474 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2475 } else {
2476 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2477
2478 /* Load eeprom data on fatal error or suspend */
2479 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2480 }
2481
2482 IPW_DEBUG_TRACE("<<\n");
2483}
2484
Arjan van de Ven858119e2006-01-14 13:20:43 -08002485static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002486{
2487 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002488 if (!count)
2489 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002490 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002491 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002492 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002493}
2494
2495static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2496{
James Ketrenosb095c382005-08-24 22:04:42 -05002497 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002498 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002499 sizeof(struct command_block));
2500}
2501
2502static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002503{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002504
2505 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002506
James Ketrenos43f66a62005-03-25 12:31:53 -06002507 /* Start the dma */
2508 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002509
James Ketrenos43f66a62005-03-25 12:31:53 -06002510 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002511 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002512
2513 IPW_DEBUG_FW("<< : \n");
2514 return 0;
2515}
2516
2517static void ipw_fw_dma_abort(struct ipw_priv *priv)
2518{
2519 u32 control = 0;
2520
2521 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002522
2523 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002524 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002525 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002526 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002527
James Ketrenos43f66a62005-03-25 12:31:53 -06002528 IPW_DEBUG_FW("<< \n");
2529}
2530
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002531static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2532 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002533{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002534 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002535 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002536 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002537 IPW_DEBUG_FW(">> :\n");
2538
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002539 ipw_write_indirect(priv, address, (u8 *) cb,
2540 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002541
2542 IPW_DEBUG_FW("<< :\n");
2543 return 0;
2544
2545}
2546
2547static int ipw_fw_dma_kick(struct ipw_priv *priv)
2548{
2549 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002550 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002551
2552 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002553
James Ketrenos43f66a62005-03-25 12:31:53 -06002554 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002555 ipw_fw_dma_write_command_block(priv, index,
2556 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002557
2558 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002559 ipw_clear_bit(priv, IPW_RESET_REG,
2560 IPW_RESET_REG_MASTER_DISABLED |
2561 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002562
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002563 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002565 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002566
2567 IPW_DEBUG_FW("<< :\n");
2568 return 0;
2569}
2570
2571static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2572{
2573 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002574 u32 register_value = 0;
2575 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002576
2577 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002578 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002579 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002580
2581 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002582 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2583 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002584
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002585 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002586 cb_fields_address = address;
2587 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002588 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002589
2590 cb_fields_address += sizeof(u32);
2591 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002592 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002593
2594 cb_fields_address += sizeof(u32);
2595 register_value = ipw_read_reg32(priv, cb_fields_address);
2596 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2597 register_value);
2598
2599 cb_fields_address += sizeof(u32);
2600 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002601 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002602
2603 IPW_DEBUG_FW(">> :\n");
2604}
2605
2606static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2607{
2608 u32 current_cb_address = 0;
2609 u32 current_cb_index = 0;
2610
2611 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002612 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002613
James Ketrenosb095c382005-08-24 22:04:42 -05002614 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002615 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002616
James Ketrenos43f66a62005-03-25 12:31:53 -06002617 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002618 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002619
2620 IPW_DEBUG_FW(">> :\n");
2621 return current_cb_index;
2622
2623}
2624
2625static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2626 u32 src_address,
2627 u32 dest_address,
2628 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002629 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002630{
2631
Jeff Garzikbf794512005-07-31 13:07:26 -04002632 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002633 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2634 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002635 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002636 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002637
2638 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2639 src_address, dest_address, length);
2640
2641 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2642 return -1;
2643
2644 last_cb_element = priv->sram_desc.last_cb_index;
2645 cb = &priv->sram_desc.cb_list[last_cb_element];
2646 priv->sram_desc.last_cb_index++;
2647
2648 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002649 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002650 control |= CB_INT_ENABLED;
2651
2652 if (is_last)
2653 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002654
James Ketrenos43f66a62005-03-25 12:31:53 -06002655 control |= length;
2656
2657 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 /* Copy the Source and Destination addresses */
2661 cb->dest_addr = dest_address;
2662 cb->source_addr = src_address;
2663
2664 /* Copy the Control Word last */
2665 cb->control = control;
2666
2667 return 0;
2668}
2669
2670static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002671 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002672{
2673 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002674 u32 src_offset = 0;
2675 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002676 int status = 0;
2677 IPW_DEBUG_FW(">> \n");
2678 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2679 src_phys, dest_address, length);
2680 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002681 status = ipw_fw_dma_add_command_block(priv,
2682 src_phys + src_offset,
2683 dest_address +
2684 dest_offset,
2685 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002686 if (status) {
2687 IPW_DEBUG_FW_INFO(": Failed\n");
2688 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002689 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002690 IPW_DEBUG_FW_INFO(": Added new cb\n");
2691
2692 src_offset += CB_MAX_LENGTH;
2693 dest_offset += CB_MAX_LENGTH;
2694 bytes_left -= CB_MAX_LENGTH;
2695 }
2696
2697 /* add the buffer tail */
2698 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002699 status =
2700 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2701 dest_address + dest_offset,
2702 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002703 if (status) {
2704 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2705 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002706 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002707 IPW_DEBUG_FW_INFO
2708 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002709 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002710
James Ketrenos43f66a62005-03-25 12:31:53 -06002711 IPW_DEBUG_FW("<< \n");
2712 return 0;
2713}
2714
2715static int ipw_fw_dma_wait(struct ipw_priv *priv)
2716{
Zhu Yi397ae122006-01-24 16:37:22 +08002717 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002718 u32 watchdog = 0;
2719
2720 IPW_DEBUG_FW(">> : \n");
2721
2722 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002723 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002724 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002725
2726 while (current_index < priv->sram_desc.last_cb_index) {
2727 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002728 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002729 current_index = ipw_fw_dma_command_block_index(priv);
2730
Zhu Yi397ae122006-01-24 16:37:22 +08002731 if (previous_index < current_index) {
2732 watchdog = 0;
2733 continue;
2734 }
2735 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002736 IPW_DEBUG_FW_INFO("Timeout\n");
2737 ipw_fw_dma_dump_command_block(priv);
2738 ipw_fw_dma_abort(priv);
2739 return -1;
2740 }
2741 }
2742
2743 ipw_fw_dma_abort(priv);
2744
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002745 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002746 ipw_set_bit(priv, IPW_RESET_REG,
2747 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002748
2749 IPW_DEBUG_FW("<< dmaWaitSync \n");
2750 return 0;
2751}
2752
Jeff Garzikbf794512005-07-31 13:07:26 -04002753static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002754{
2755 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002756 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002757 unsigned long flags;
2758
2759 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002760 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2761 network = list_entry(element, struct ieee80211_network, list);
2762 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2763 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002764 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002765 &priv->ieee->network_free_list);
2766 }
2767 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002768 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002769}
2770
2771/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002772 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002773 * Reads debug register from domain0.
2774 * If card is present, pre-defined value should
2775 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002776 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002777 * @param priv
2778 * @return 1 if card is present, 0 otherwise
2779 */
2780static inline int ipw_alive(struct ipw_priv *priv)
2781{
2782 return ipw_read32(priv, 0x90) == 0xd55555d5;
2783}
2784
Zhu Yic7b6a672006-01-24 16:37:05 +08002785/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002786static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 int timeout)
2788{
2789 int i = 0;
2790
2791 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002792 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002793 return i;
2794 mdelay(10);
2795 i += 10;
2796 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002797
James Ketrenos43f66a62005-03-25 12:31:53 -06002798 return -ETIME;
2799}
2800
Jeff Garzikbf794512005-07-31 13:07:26 -04002801/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002802 * the ipw hardware. It assumes the buffer has all the bits for the
2803 * image and the caller is handling the memory allocation and clean up.
2804 */
2805
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002806static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002807{
2808 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002809
James Ketrenos43f66a62005-03-25 12:31:53 -06002810 IPW_DEBUG_TRACE(">> \n");
2811 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002812 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002813
Zhu Yic7b6a672006-01-24 16:37:05 +08002814 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002815 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2816 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002817 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002818 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002819 return -1;
2820 }
2821
2822 IPW_DEBUG_INFO("stop master %dms\n", rc);
2823
2824 return rc;
2825}
2826
2827static void ipw_arc_release(struct ipw_priv *priv)
2828{
2829 IPW_DEBUG_TRACE(">> \n");
2830 mdelay(5);
2831
James Ketrenosb095c382005-08-24 22:04:42 -05002832 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002833
2834 /* no one knows timing, for safety add some delay */
2835 mdelay(5);
2836}
2837
2838struct fw_header {
2839 u32 version;
2840 u32 mode;
2841};
2842
2843struct fw_chunk {
2844 u32 address;
2845 u32 length;
2846};
2847
2848#define IPW_FW_MAJOR_VERSION 2
James Ketrenos817153762005-08-25 01:37:28 -05002849#define IPW_FW_MINOR_VERSION 4
James Ketrenos43f66a62005-03-25 12:31:53 -06002850
2851#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2852#define IPW_FW_MAJOR(x) (x & 0xff)
2853
James Ketrenosafbf30a2005-08-25 00:05:33 -05002854#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002855
2856#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2857"." __stringify(IPW_FW_MINOR_VERSION) "-"
2858
2859#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2860#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2861#else
2862#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2863#endif
2864
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002865static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002866{
2867 int rc = 0, i, addr;
2868 u8 cr = 0;
2869 u16 *image;
2870
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002871 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002872
James Ketrenos43f66a62005-03-25 12:31:53 -06002873 IPW_DEBUG_TRACE(">> \n");
2874
2875 rc = ipw_stop_master(priv);
2876
2877 if (rc < 0)
2878 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002879
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002880// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002881
James Ketrenosb095c382005-08-24 22:04:42 -05002882 for (addr = IPW_SHARED_LOWER_BOUND;
2883 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002884 ipw_write32(priv, addr, 0);
2885 }
2886
2887 /* no ucode (yet) */
2888 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2889 /* destroy DMA queues */
2890 /* reset sequence */
2891
James Ketrenosb095c382005-08-24 22:04:42 -05002892 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002893 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002894 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002895 mdelay(1);
2896
2897 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002898 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002899 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002900
James Ketrenosb095c382005-08-24 22:04:42 -05002901 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002902 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002903
James Ketrenos43f66a62005-03-25 12:31:53 -06002904 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002905 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2906 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 mdelay(1);
2908
2909 /* write ucode */
2910 /**
2911 * @bug
2912 * Do NOT set indirect address register once and then
2913 * store data to indirect data register in the loop.
2914 * It seems very reasonable, but in this case DINO do not
2915 * accept ucode. It is essential to set address each time.
2916 */
2917 /* load new ipw uCode */
2918 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002919 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002920 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002921
James Ketrenos43f66a62005-03-25 12:31:53 -06002922 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002923 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2924 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002925
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002926 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002927
2928 /* wait for alive response */
2929 for (i = 0; i < 100; i++) {
2930 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002931 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 if (cr & DINO_RXFIFO_DATA)
2933 break;
2934 mdelay(1);
2935 }
2936
2937 if (cr & DINO_RXFIFO_DATA) {
2938 /* alive_command_responce size is NOT multiple of 4 */
2939 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002940
2941 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002943 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002944 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 memcpy(&priv->dino_alive, response_buffer,
2946 sizeof(priv->dino_alive));
2947 if (priv->dino_alive.alive_command == 1
2948 && priv->dino_alive.ucode_valid == 1) {
2949 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002950 IPW_DEBUG_INFO
2951 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2952 "of %02d/%02d/%02d %02d:%02d\n",
2953 priv->dino_alive.software_revision,
2954 priv->dino_alive.software_revision,
2955 priv->dino_alive.device_identifier,
2956 priv->dino_alive.device_identifier,
2957 priv->dino_alive.time_stamp[0],
2958 priv->dino_alive.time_stamp[1],
2959 priv->dino_alive.time_stamp[2],
2960 priv->dino_alive.time_stamp[3],
2961 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002962 } else {
2963 IPW_DEBUG_INFO("Microcode is not alive\n");
2964 rc = -EINVAL;
2965 }
2966 } else {
2967 IPW_DEBUG_INFO("No alive response from DINO\n");
2968 rc = -ETIME;
2969 }
2970
2971 /* disable DINO, otherwise for some reason
2972 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002973 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002974
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002975// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002976
2977 return rc;
2978}
2979
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002980static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002981{
2982 int rc = -1;
2983 int offset = 0;
2984 struct fw_chunk *chunk;
2985 dma_addr_t shared_phys;
2986 u8 *shared_virt;
2987
2988 IPW_DEBUG_TRACE("<< : \n");
2989 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2990
2991 if (!shared_virt)
2992 return -ENOMEM;
2993
2994 memmove(shared_virt, data, len);
2995
2996 /* Start the Dma */
2997 rc = ipw_fw_dma_enable(priv);
2998
2999 if (priv->sram_desc.last_cb_index > 0) {
3000 /* the DMA is already ready this would be a bug. */
3001 BUG();
3002 goto out;
3003 }
3004
3005 do {
3006 chunk = (struct fw_chunk *)(data + offset);
3007 offset += sizeof(struct fw_chunk);
3008 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003009 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003010 * offeset*/
3011 /* Dma loading */
3012 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003013 le32_to_cpu(chunk->address),
3014 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003015 if (rc) {
3016 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3017 goto out;
3018 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003019
James Ketrenosa613bff2005-08-24 21:43:11 -05003020 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003021 } while (offset < len);
3022
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003023 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003024 rc = ipw_fw_dma_kick(priv);
3025 if (rc) {
3026 IPW_ERROR("dmaKick Failed\n");
3027 goto out;
3028 }
3029
3030 rc = ipw_fw_dma_wait(priv);
3031 if (rc) {
3032 IPW_ERROR("dmaWaitSync Failed\n");
3033 goto out;
3034 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003035 out:
3036 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003037 return rc;
3038}
3039
3040/* stop nic */
3041static int ipw_stop_nic(struct ipw_priv *priv)
3042{
3043 int rc = 0;
3044
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003045 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003046 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003047
James Ketrenosb095c382005-08-24 22:04:42 -05003048 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3049 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003050 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003051 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003052 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003053 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003054
James Ketrenosb095c382005-08-24 22:04:42 -05003055 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003056
James Ketrenos43f66a62005-03-25 12:31:53 -06003057 return rc;
3058}
3059
3060static void ipw_start_nic(struct ipw_priv *priv)
3061{
3062 IPW_DEBUG_TRACE(">>\n");
3063
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003064 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003065 ipw_clear_bit(priv, IPW_RESET_REG,
3066 IPW_RESET_REG_MASTER_DISABLED |
3067 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003068 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003069
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003071 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3072 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003073
3074 IPW_DEBUG_TRACE("<<\n");
3075}
Jeff Garzikbf794512005-07-31 13:07:26 -04003076
James Ketrenos43f66a62005-03-25 12:31:53 -06003077static int ipw_init_nic(struct ipw_priv *priv)
3078{
3079 int rc;
3080
3081 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003082 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003083 /*prvHwInitNic */
3084 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003085 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003086
3087 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003088 ipw_write32(priv, IPW_READ_INT_REGISTER,
3089 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003090
3091 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003092 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3093 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003094 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003095 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3096
3097 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003098 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003099
3100 udelay(10);
3101
3102 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003103 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003104
3105 IPW_DEBUG_TRACE(">>\n");
3106 return 0;
3107}
3108
Jeff Garzikbf794512005-07-31 13:07:26 -04003109/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003110 * Probe is an ok place to call this from.
3111 */
3112static int ipw_reset_nic(struct ipw_priv *priv)
3113{
3114 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003115 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003116
3117 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003118
James Ketrenos43f66a62005-03-25 12:31:53 -06003119 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003120
James Ketrenosa613bff2005-08-24 21:43:11 -05003121 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003122 /* Clear the 'host command active' bit... */
3123 priv->status &= ~STATUS_HCMD_ACTIVE;
3124 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003125 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3126 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003127 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003128
3129 IPW_DEBUG_TRACE("<<\n");
3130 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003131}
James Ketrenos43f66a62005-03-25 12:31:53 -06003132
Jeff Garzikbf794512005-07-31 13:07:26 -04003133static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003134 const struct firmware **fw, const char *name)
3135{
3136 struct fw_header *header;
3137 int rc;
3138
3139 /* ask firmware_class module to get the boot firmware off disk */
3140 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3141 if (rc < 0) {
3142 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3143 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003144 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003145
3146 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003147 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003148 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3149 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003150 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3151 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003152 return -EINVAL;
3153 }
3154
Jiri Bencaaa4d302005-06-07 14:58:41 +02003155 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003156 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003157 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3158 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003159 (*fw)->size - sizeof(struct fw_header));
3160 return 0;
3161}
3162
James Ketrenosb095c382005-08-24 22:04:42 -05003163#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003164
Arjan van de Ven858119e2006-01-14 13:20:43 -08003165static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003166 struct ipw_rx_queue *rxq)
3167{
3168 unsigned long flags;
3169 int i;
3170
3171 spin_lock_irqsave(&rxq->lock, flags);
3172
3173 INIT_LIST_HEAD(&rxq->rx_free);
3174 INIT_LIST_HEAD(&rxq->rx_used);
3175
3176 /* Fill the rx_used queue with _all_ of the Rx buffers */
3177 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3178 /* In the reset function, these buffers may have been allocated
3179 * to an SKB, so we need to unmap and free potential storage */
3180 if (rxq->pool[i].skb != NULL) {
3181 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003182 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003184 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003185 }
3186 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3187 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003188
James Ketrenos43f66a62005-03-25 12:31:53 -06003189 /* Set us so that we have processed and used all buffers, but have
3190 * not restocked the Rx queue with fresh buffers */
3191 rxq->read = rxq->write = 0;
3192 rxq->processed = RX_QUEUE_SIZE - 1;
3193 rxq->free_count = 0;
3194 spin_unlock_irqrestore(&rxq->lock, flags);
3195}
3196
3197#ifdef CONFIG_PM
3198static int fw_loaded = 0;
3199static const struct firmware *bootfw = NULL;
3200static const struct firmware *firmware = NULL;
3201static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003202
3203static void free_firmware(void)
3204{
3205 if (fw_loaded) {
3206 release_firmware(bootfw);
3207 release_firmware(ucode);
3208 release_firmware(firmware);
3209 bootfw = ucode = firmware = NULL;
3210 fw_loaded = 0;
3211 }
3212}
3213#else
3214#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003215#endif
3216
3217static int ipw_load(struct ipw_priv *priv)
3218{
3219#ifndef CONFIG_PM
3220 const struct firmware *bootfw = NULL;
3221 const struct firmware *firmware = NULL;
3222 const struct firmware *ucode = NULL;
3223#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003224 char *ucode_name;
3225 char *fw_name;
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 int rc = 0, retries = 3;
3227
Zhu Yi397ae122006-01-24 16:37:22 +08003228 switch (priv->ieee->iw_mode) {
3229 case IW_MODE_ADHOC:
3230 ucode_name = IPW_FW_NAME("ibss_ucode");
3231 fw_name = IPW_FW_NAME("ibss");
3232 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003233#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003234 case IW_MODE_MONITOR:
3235 ucode_name = IPW_FW_NAME("sniffer_ucode");
3236 fw_name = IPW_FW_NAME("sniffer");
3237 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003238#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003239 case IW_MODE_INFRA:
3240 ucode_name = IPW_FW_NAME("bss_ucode");
3241 fw_name = IPW_FW_NAME("bss");
3242 break;
3243 default:
3244 rc = -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003245 }
Zhu Yi397ae122006-01-24 16:37:22 +08003246
3247 if (rc < 0)
3248 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003249
3250 if (!priv->rxq)
3251 priv->rxq = ipw_rx_queue_alloc(priv);
3252 else
3253 ipw_rx_queue_reset(priv, priv->rxq);
3254 if (!priv->rxq) {
3255 IPW_ERROR("Unable to initialize Rx queue\n");
3256 goto error;
3257 }
3258
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003259 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003260 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003261 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003262 priv->status &= ~STATUS_INT_ENABLED;
3263
3264 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003265 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003266
James Ketrenos43f66a62005-03-25 12:31:53 -06003267 ipw_stop_nic(priv);
3268
3269 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003270 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003271 IPW_ERROR("Unable to reset NIC\n");
3272 goto error;
3273 }
3274
James Ketrenosb095c382005-08-24 22:04:42 -05003275 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3276 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003277
Zhu Yi397ae122006-01-24 16:37:22 +08003278#ifdef CONFIG_PM
3279 if (!fw_loaded) {
3280#endif
3281 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
3282 if (rc < 0)
3283 goto error;
3284#ifdef CONFIG_PM
3285 }
3286#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003288 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003289 bootfw->size - sizeof(struct fw_header));
3290 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003291 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003292 goto error;
3293 }
3294
3295 /* kick start the device */
3296 ipw_start_nic(priv);
3297
Zhu Yic7b6a672006-01-24 16:37:05 +08003298 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003299 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3300 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003301 if (rc < 0) {
3302 IPW_ERROR("device failed to boot initial fw image\n");
3303 goto error;
3304 }
3305 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3306
Jeff Garzikbf794512005-07-31 13:07:26 -04003307 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003308 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003309
Zhu Yi397ae122006-01-24 16:37:22 +08003310#ifdef CONFIG_PM
3311 if (!fw_loaded) {
3312#endif
3313 rc = ipw_get_fw(priv, &ucode, ucode_name);
3314 if (rc < 0)
3315 goto error;
3316#ifdef CONFIG_PM
3317 }
3318#endif
Zhu Yi2638bc32006-01-24 16:37:52 +08003319
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003321 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003322 ucode->size - sizeof(struct fw_header));
3323 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003324 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003325 goto error;
3326 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003327
James Ketrenos43f66a62005-03-25 12:31:53 -06003328 /* stop nic */
3329 ipw_stop_nic(priv);
3330
Zhu Yi397ae122006-01-24 16:37:22 +08003331#ifdef CONFIG_PM
3332 if (!fw_loaded) {
3333#endif
3334 rc = ipw_get_fw(priv, &firmware, fw_name);
3335 if (rc < 0)
3336 goto error;
3337#ifdef CONFIG_PM
3338 }
3339#endif
3340
James Ketrenos43f66a62005-03-25 12:31:53 -06003341 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003342 rc = ipw_load_firmware(priv, firmware->data +
3343 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003344 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003345 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003346 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003347 goto error;
3348 }
Zhu Yi397ae122006-01-24 16:37:22 +08003349#ifdef CONFIG_PM
3350 fw_loaded = 1;
3351#endif
3352
James Ketrenos43f66a62005-03-25 12:31:53 -06003353 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3354
3355 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003356 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003357 IPW_ERROR("Unable to initialize queues\n");
3358 goto error;
3359 }
3360
3361 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003362 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003363 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003364 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003365
James Ketrenos43f66a62005-03-25 12:31:53 -06003366 /* kick start the device */
3367 ipw_start_nic(priv);
3368
James Ketrenosb095c382005-08-24 22:04:42 -05003369 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003370 if (retries > 0) {
3371 IPW_WARNING("Parity error. Retrying init.\n");
3372 retries--;
3373 goto retry;
3374 }
3375
3376 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3377 rc = -EIO;
3378 goto error;
3379 }
3380
3381 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003382 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3383 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003384 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003385 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003386 goto error;
3387 }
3388 IPW_DEBUG_INFO("device response after %dms\n", rc);
3389
3390 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003391 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003392
3393 /* read eeprom data and initialize the eeprom region of sram */
3394 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003395 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003396
3397 /* enable interrupts */
3398 ipw_enable_interrupts(priv);
3399
3400 /* Ensure our queue has valid packets */
3401 ipw_rx_queue_replenish(priv);
3402
James Ketrenosb095c382005-08-24 22:04:42 -05003403 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003404
3405 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003406 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003407
3408#ifndef CONFIG_PM
3409 release_firmware(bootfw);
3410 release_firmware(ucode);
3411 release_firmware(firmware);
3412#endif
3413 return 0;
3414
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003415 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003416 if (priv->rxq) {
3417 ipw_rx_queue_free(priv, priv->rxq);
3418 priv->rxq = NULL;
3419 }
3420 ipw_tx_queue_free(priv);
3421 if (bootfw)
3422 release_firmware(bootfw);
3423 if (ucode)
3424 release_firmware(ucode);
3425 if (firmware)
3426 release_firmware(firmware);
3427#ifdef CONFIG_PM
3428 fw_loaded = 0;
3429 bootfw = ucode = firmware = NULL;
3430#endif
3431
3432 return rc;
3433}
3434
Jeff Garzikbf794512005-07-31 13:07:26 -04003435/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003436 * DMA services
3437 *
3438 * Theory of operation
3439 *
3440 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3441 * 2 empty entries always kept in the buffer to protect from overflow.
3442 *
3443 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003444 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3445 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003446 * Tx queue resumed.
3447 *
3448 * The IPW operates with six queues, one receive queue in the device's
3449 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003450 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003451 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003452 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003453 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003454 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003455 * we only utilize the first data transmit queue (queue1).
3456 */
3457
3458/**
3459 * Driver allocates buffers of this size for Rx
3460 */
3461
3462static inline int ipw_queue_space(const struct clx2_queue *q)
3463{
3464 int s = q->last_used - q->first_empty;
3465 if (s <= 0)
3466 s += q->n_bd;
3467 s -= 2; /* keep some reserve to not confuse empty and full situations */
3468 if (s < 0)
3469 s = 0;
3470 return s;
3471}
3472
3473static inline int ipw_queue_inc_wrap(int index, int n_bd)
3474{
3475 return (++index == n_bd) ? 0 : index;
3476}
3477
3478/**
3479 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003480 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003481 * @param q queue to init
3482 * @param count Number of BD's to allocate. Should be power of 2
3483 * @param read_register Address for 'read' register
3484 * (not offset within BAR, full address)
3485 * @param write_register Address for 'write' register
3486 * (not offset within BAR, full address)
3487 * @param base_register Address for 'base' register
3488 * (not offset within BAR, full address)
3489 * @param size Address for 'size' register
3490 * (not offset within BAR, full address)
3491 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003492static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003493 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003494{
3495 q->n_bd = count;
3496
3497 q->low_mark = q->n_bd / 4;
3498 if (q->low_mark < 4)
3499 q->low_mark = 4;
3500
3501 q->high_mark = q->n_bd / 8;
3502 if (q->high_mark < 2)
3503 q->high_mark = 2;
3504
3505 q->first_empty = q->last_used = 0;
3506 q->reg_r = read;
3507 q->reg_w = write;
3508
3509 ipw_write32(priv, base, q->dma_addr);
3510 ipw_write32(priv, size, count);
3511 ipw_write32(priv, read, 0);
3512 ipw_write32(priv, write, 0);
3513
3514 _ipw_read32(priv, 0x90);
3515}
3516
Jeff Garzikbf794512005-07-31 13:07:26 -04003517static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003518 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003519 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003520{
3521 struct pci_dev *dev = priv->pci_dev;
3522
3523 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3524 if (!q->txb) {
3525 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3526 return -ENOMEM;
3527 }
3528
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003529 q->bd =
3530 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003531 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003532 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003533 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003534 kfree(q->txb);
3535 q->txb = NULL;
3536 return -ENOMEM;
3537 }
3538
3539 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3540 return 0;
3541}
3542
3543/**
3544 * Free one TFD, those at index [txq->q.last_used].
3545 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003546 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003547 * @param dev
3548 * @param txq
3549 */
3550static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3551 struct clx2_tx_queue *txq)
3552{
3553 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3554 struct pci_dev *dev = priv->pci_dev;
3555 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003556
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 /* classify bd */
3558 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3559 /* nothing to cleanup after for host commands */
3560 return;
3561
3562 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003563 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3564 IPW_ERROR("Too many chunks: %i\n",
3565 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003566 /** @todo issue fatal error, it is quite serious situation */
3567 return;
3568 }
3569
3570 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003571 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3572 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3573 le16_to_cpu(bd->u.data.chunk_len[i]),
3574 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003575 if (txq->txb[txq->q.last_used]) {
3576 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3577 txq->txb[txq->q.last_used] = NULL;
3578 }
3579 }
3580}
3581
3582/**
3583 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003584 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003585 * Empty queue by removing and destroying all BD's.
3586 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003587 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003588 * @param dev
3589 * @param q
3590 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003591static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003592{
3593 struct clx2_queue *q = &txq->q;
3594 struct pci_dev *dev = priv->pci_dev;
3595
Jeff Garzikbf794512005-07-31 13:07:26 -04003596 if (q->n_bd == 0)
3597 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003598
3599 /* first, empty all BD's */
3600 for (; q->first_empty != q->last_used;
3601 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3602 ipw_queue_tx_free_tfd(priv, txq);
3603 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003604
James Ketrenos43f66a62005-03-25 12:31:53 -06003605 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003606 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003607 q->dma_addr);
3608 kfree(txq->txb);
3609
3610 /* 0 fill whole structure */
3611 memset(txq, 0, sizeof(*txq));
3612}
3613
James Ketrenos43f66a62005-03-25 12:31:53 -06003614/**
3615 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003616 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003617 * @param priv
3618 */
3619static void ipw_tx_queue_free(struct ipw_priv *priv)
3620{
3621 /* Tx CMD queue */
3622 ipw_queue_tx_free(priv, &priv->txq_cmd);
3623
3624 /* Tx queues */
3625 ipw_queue_tx_free(priv, &priv->txq[0]);
3626 ipw_queue_tx_free(priv, &priv->txq[1]);
3627 ipw_queue_tx_free(priv, &priv->txq[2]);
3628 ipw_queue_tx_free(priv, &priv->txq[3]);
3629}
3630
Arjan van de Ven858119e2006-01-14 13:20:43 -08003631static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003632{
3633 /* First 3 bytes are manufacturer */
3634 bssid[0] = priv->mac_addr[0];
3635 bssid[1] = priv->mac_addr[1];
3636 bssid[2] = priv->mac_addr[2];
3637
3638 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003639 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003641 bssid[0] &= 0xfe; /* clear multicast bit */
3642 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003643}
3644
Arjan van de Ven858119e2006-01-14 13:20:43 -08003645static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003646{
3647 struct ipw_station_entry entry;
3648 int i;
3649
3650 for (i = 0; i < priv->num_stations; i++) {
3651 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3652 /* Another node is active in network */
3653 priv->missed_adhoc_beacons = 0;
3654 if (!(priv->config & CFG_STATIC_CHANNEL))
3655 /* when other nodes drop out, we drop out */
3656 priv->config &= ~CFG_ADHOC_PERSIST;
3657
3658 return i;
3659 }
3660 }
3661
3662 if (i == MAX_STATIONS)
3663 return IPW_INVALID_STATION;
3664
3665 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3666
3667 entry.reserved = 0;
3668 entry.support_mode = 0;
3669 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3670 memcpy(priv->stations[i], bssid, ETH_ALEN);
3671 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003672 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003673 priv->num_stations++;
3674
3675 return i;
3676}
3677
Arjan van de Ven858119e2006-01-14 13:20:43 -08003678static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003679{
3680 int i;
3681
Jeff Garzikbf794512005-07-31 13:07:26 -04003682 for (i = 0; i < priv->num_stations; i++)
3683 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 return i;
3685
3686 return IPW_INVALID_STATION;
3687}
3688
3689static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3690{
3691 int err;
3692
Hong Liu7b996592005-08-25 17:36:13 +08003693 if (priv->status & STATUS_ASSOCIATING) {
3694 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3695 queue_work(priv->workqueue, &priv->disassociate);
3696 return;
3697 }
3698
3699 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003700 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3701 return;
3702 }
3703
3704 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3705 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003706 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003707 priv->assoc_request.channel);
3708
3709 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3710 priv->status |= STATUS_DISASSOCIATING;
3711
3712 if (quiet)
3713 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3714 else
3715 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003716
James Ketrenos43f66a62005-03-25 12:31:53 -06003717 err = ipw_send_associate(priv, &priv->assoc_request);
3718 if (err) {
3719 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3720 "failed.\n");
3721 return;
3722 }
3723
3724}
3725
James Ketrenosc848d0a2005-08-24 21:56:24 -05003726static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003727{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003728 struct ipw_priv *priv = data;
3729 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3730 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003731 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003732 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003733}
3734
James Ketrenosc848d0a2005-08-24 21:56:24 -05003735static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003736{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003737 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003738 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003739 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003740 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003741}
3742
Zhu Yid8bad6d2005-07-13 12:25:38 -05003743static void ipw_system_config(void *data)
3744{
3745 struct ipw_priv *priv = data;
3746 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003747}
3748
3749struct ipw_status_code {
3750 u16 status;
3751 const char *reason;
3752};
3753
3754static const struct ipw_status_code ipw_status_codes[] = {
3755 {0x00, "Successful"},
3756 {0x01, "Unspecified failure"},
3757 {0x0A, "Cannot support all requested capabilities in the "
3758 "Capability information field"},
3759 {0x0B, "Reassociation denied due to inability to confirm that "
3760 "association exists"},
3761 {0x0C, "Association denied due to reason outside the scope of this "
3762 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003763 {0x0D,
3764 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003765 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003766 {0x0E,
3767 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003768 "transaction sequence number out of expected sequence"},
3769 {0x0F, "Authentication rejected because of challenge failure"},
3770 {0x10, "Authentication rejected due to timeout waiting for next "
3771 "frame in sequence"},
3772 {0x11, "Association denied because AP is unable to handle additional "
3773 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003774 {0x12,
3775 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003777 {0x13,
3778 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003779 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003780 {0x14,
3781 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003783 {0x15,
3784 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003785 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003786 {0x19,
3787 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003788 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003789 {0x1A,
3790 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 "DSSS-OFDM operation"},
3792 {0x28, "Invalid Information Element"},
3793 {0x29, "Group Cipher is not valid"},
3794 {0x2A, "Pairwise Cipher is not valid"},
3795 {0x2B, "AKMP is not valid"},
3796 {0x2C, "Unsupported RSN IE version"},
3797 {0x2D, "Invalid RSN IE Capabilities"},
3798 {0x2E, "Cipher suite is rejected per security policy"},
3799};
3800
Brice Goglin0f52bf92005-12-01 01:41:46 -08003801#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003802static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003803{
3804 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003805 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003806 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003807 return ipw_status_codes[i].reason;
3808 return "Unknown status value.";
3809}
3810#endif
3811
3812static void inline average_init(struct average *avg)
3813{
3814 memset(avg, 0, sizeof(*avg));
3815}
3816
Arjan van de Ven858119e2006-01-14 13:20:43 -08003817static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003818{
3819 avg->sum -= avg->entries[avg->pos];
3820 avg->sum += val;
3821 avg->entries[avg->pos++] = val;
3822 if (unlikely(avg->pos == AVG_ENTRIES)) {
3823 avg->init = 1;
3824 avg->pos = 0;
3825 }
3826}
3827
Arjan van de Ven858119e2006-01-14 13:20:43 -08003828static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003829{
3830 if (!unlikely(avg->init)) {
3831 if (avg->pos)
3832 return avg->sum / avg->pos;
3833 return 0;
3834 }
3835
3836 return avg->sum / AVG_ENTRIES;
3837}
3838
3839static void ipw_reset_stats(struct ipw_priv *priv)
3840{
3841 u32 len = sizeof(u32);
3842
3843 priv->quality = 0;
3844
3845 average_init(&priv->average_missed_beacons);
3846 average_init(&priv->average_rssi);
3847 average_init(&priv->average_noise);
3848
3849 priv->last_rate = 0;
3850 priv->last_missed_beacons = 0;
3851 priv->last_rx_packets = 0;
3852 priv->last_tx_packets = 0;
3853 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003854
James Ketrenos43f66a62005-03-25 12:31:53 -06003855 /* Firmware managed, reset only when NIC is restarted, so we have to
3856 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003857 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003858 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003859 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003860 &priv->last_tx_failures, &len);
3861
3862 /* Driver managed, reset with each association */
3863 priv->missed_adhoc_beacons = 0;
3864 priv->missed_beacons = 0;
3865 priv->tx_packets = 0;
3866 priv->rx_packets = 0;
3867
3868}
3869
Arjan van de Ven858119e2006-01-14 13:20:43 -08003870static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003871{
3872 u32 i = 0x80000000;
3873 u32 mask = priv->rates_mask;
3874 /* If currently associated in B mode, restrict the maximum
3875 * rate match to B rates */
3876 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3877 mask &= IEEE80211_CCK_RATES_MASK;
3878
3879 /* TODO: Verify that the rate is supported by the current rates
3880 * list. */
3881
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003882 while (i && !(mask & i))
3883 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003884 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003885 case IEEE80211_CCK_RATE_1MB_MASK:
3886 return 1000000;
3887 case IEEE80211_CCK_RATE_2MB_MASK:
3888 return 2000000;
3889 case IEEE80211_CCK_RATE_5MB_MASK:
3890 return 5500000;
3891 case IEEE80211_OFDM_RATE_6MB_MASK:
3892 return 6000000;
3893 case IEEE80211_OFDM_RATE_9MB_MASK:
3894 return 9000000;
3895 case IEEE80211_CCK_RATE_11MB_MASK:
3896 return 11000000;
3897 case IEEE80211_OFDM_RATE_12MB_MASK:
3898 return 12000000;
3899 case IEEE80211_OFDM_RATE_18MB_MASK:
3900 return 18000000;
3901 case IEEE80211_OFDM_RATE_24MB_MASK:
3902 return 24000000;
3903 case IEEE80211_OFDM_RATE_36MB_MASK:
3904 return 36000000;
3905 case IEEE80211_OFDM_RATE_48MB_MASK:
3906 return 48000000;
3907 case IEEE80211_OFDM_RATE_54MB_MASK:
3908 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003909 }
3910
Jeff Garzikbf794512005-07-31 13:07:26 -04003911 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003912 return 11000000;
3913 else
3914 return 54000000;
3915}
3916
3917static u32 ipw_get_current_rate(struct ipw_priv *priv)
3918{
3919 u32 rate, len = sizeof(rate);
3920 int err;
3921
Jeff Garzikbf794512005-07-31 13:07:26 -04003922 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003923 return 0;
3924
3925 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003926 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003927 &len);
3928 if (err) {
3929 IPW_DEBUG_INFO("failed querying ordinals.\n");
3930 return 0;
3931 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003932 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003933 return ipw_get_max_rate(priv);
3934
3935 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003936 case IPW_TX_RATE_1MB:
3937 return 1000000;
3938 case IPW_TX_RATE_2MB:
3939 return 2000000;
3940 case IPW_TX_RATE_5MB:
3941 return 5500000;
3942 case IPW_TX_RATE_6MB:
3943 return 6000000;
3944 case IPW_TX_RATE_9MB:
3945 return 9000000;
3946 case IPW_TX_RATE_11MB:
3947 return 11000000;
3948 case IPW_TX_RATE_12MB:
3949 return 12000000;
3950 case IPW_TX_RATE_18MB:
3951 return 18000000;
3952 case IPW_TX_RATE_24MB:
3953 return 24000000;
3954 case IPW_TX_RATE_36MB:
3955 return 36000000;
3956 case IPW_TX_RATE_48MB:
3957 return 48000000;
3958 case IPW_TX_RATE_54MB:
3959 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003960 }
3961
3962 return 0;
3963}
3964
James Ketrenos43f66a62005-03-25 12:31:53 -06003965#define IPW_STATS_INTERVAL (2 * HZ)
3966static void ipw_gather_stats(struct ipw_priv *priv)
3967{
3968 u32 rx_err, rx_err_delta, rx_packets_delta;
3969 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3970 u32 missed_beacons_percent, missed_beacons_delta;
3971 u32 quality = 0;
3972 u32 len = sizeof(u32);
3973 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003974 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003975 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003976 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003977
3978 if (!(priv->status & STATUS_ASSOCIATED)) {
3979 priv->quality = 0;
3980 return;
3981 }
3982
3983 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003984 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003985 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003986 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003987 priv->last_missed_beacons = priv->missed_beacons;
3988 if (priv->assoc_request.beacon_interval) {
3989 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003990 (HZ * priv->assoc_request.beacon_interval) /
3991 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003992 } else {
3993 missed_beacons_percent = 0;
3994 }
3995 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3996
3997 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3998 rx_err_delta = rx_err - priv->last_rx_err;
3999 priv->last_rx_err = rx_err;
4000
4001 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4002 tx_failures_delta = tx_failures - priv->last_tx_failures;
4003 priv->last_tx_failures = tx_failures;
4004
4005 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4006 priv->last_rx_packets = priv->rx_packets;
4007
4008 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4009 priv->last_tx_packets = priv->tx_packets;
4010
4011 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004012 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004013 * Missed beacon: 100% = 0, 0% = 70% missed
4014 * Rate: 60% = 1Mbs, 100% = Max
4015 * Rx and Tx errors represent a straight % of total Rx/Tx
4016 * RSSI: 100% = > -50, 0% = < -80
4017 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004018 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004019 * The lowest computed quality is used.
4020 *
4021 */
4022#define BEACON_THRESHOLD 5
4023 beacon_quality = 100 - missed_beacons_percent;
4024 if (beacon_quality < BEACON_THRESHOLD)
4025 beacon_quality = 0;
4026 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004027 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004028 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004029 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004030 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004031
James Ketrenos43f66a62005-03-25 12:31:53 -06004032 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004033 max_rate = ipw_get_max_rate(priv);
4034 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004035 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4036 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004037
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004038 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004039 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004040 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 else
4042 rx_quality = 100;
4043 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4044 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004045
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004046 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004047 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004048 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004049 else
4050 tx_quality = 100;
4051 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4052 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004053
James Ketrenos43f66a62005-03-25 12:31:53 -06004054 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004055 signal_quality =
4056 (100 *
4057 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4058 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4059 (priv->ieee->perfect_rssi - rssi) *
4060 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4061 62 * (priv->ieee->perfect_rssi - rssi))) /
4062 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4063 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4064 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004065 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004066 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004067 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004068
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4070 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004071
4072 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004073 min(rate_quality,
4074 min(tx_quality, min(rx_quality, signal_quality))));
4075 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004076 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4077 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004078 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004079 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4080 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004081 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004082 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4083 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004084 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004085 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4086 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004087 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004088 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4089 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004090
4091 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004092
4093 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004094 IPW_STATS_INTERVAL);
4095}
4096
James Ketrenosc848d0a2005-08-24 21:56:24 -05004097static void ipw_bg_gather_stats(void *data)
4098{
4099 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004100 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004101 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004102 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004103}
4104
Ben Cahille7582562005-10-06 15:34:41 -05004105/* Missed beacon behavior:
4106 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4107 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4108 * Above disassociate threshold, give up and stop scanning.
4109 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004110static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004111 int missed_count)
4112{
4113 priv->notif_missed_beacons = missed_count;
4114
James Ketrenosafbf30a2005-08-25 00:05:33 -05004115 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004116 priv->status & STATUS_ASSOCIATED) {
4117 /* If associated and we've hit the missed
4118 * beacon threshold, disassociate, turn
4119 * off roaming, and abort any active scans */
4120 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004121 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004122 "Missed beacon: %d - disassociate\n", missed_count);
4123 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004124 if (priv->status & STATUS_SCANNING) {
4125 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4126 IPW_DL_STATE,
4127 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004128 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004129 }
4130
James Ketrenosea2b26e2005-08-24 21:25:16 -05004131 queue_work(priv->workqueue, &priv->disassociate);
4132 return;
4133 }
4134
4135 if (priv->status & STATUS_ROAMING) {
4136 /* If we are currently roaming, then just
4137 * print a debug statement... */
4138 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4139 "Missed beacon: %d - roam in progress\n",
4140 missed_count);
4141 return;
4142 }
4143
Zhu Yi4bfdb912006-01-24 16:37:16 +08004144 if (roaming &&
4145 (missed_count > priv->roaming_threshold &&
4146 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004147 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004148 * bit in the status and kick off a scan.
4149 * This can happen several times before we reach
4150 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004151 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4152 "Missed beacon: %d - initiate "
4153 "roaming\n", missed_count);
4154 if (!(priv->status & STATUS_ROAMING)) {
4155 priv->status |= STATUS_ROAMING;
4156 if (!(priv->status & STATUS_SCANNING))
4157 queue_work(priv->workqueue,
4158 &priv->request_scan);
4159 }
4160 return;
4161 }
4162
4163 if (priv->status & STATUS_SCANNING) {
4164 /* Stop scan to keep fw from getting
4165 * stuck (only if we aren't roaming --
4166 * otherwise we'll never scan more than 2 or 3
4167 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004168 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4169 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004170 queue_work(priv->workqueue, &priv->abort_scan);
4171 }
4172
4173 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004174}
4175
James Ketrenos43f66a62005-03-25 12:31:53 -06004176/**
4177 * Handle host notification packet.
4178 * Called from interrupt routine
4179 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004180static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004181 struct ipw_rx_notification *notif)
4182{
James Ketrenosa613bff2005-08-24 21:43:11 -05004183 notif->size = le16_to_cpu(notif->size);
4184
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004185 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004186
James Ketrenos43f66a62005-03-25 12:31:53 -06004187 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004188 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4189 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004190
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004191 switch (assoc->state) {
4192 case CMAS_ASSOCIATED:{
4193 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4194 IPW_DL_ASSOC,
4195 "associated: '%s' " MAC_FMT
4196 " \n",
4197 escape_essid(priv->essid,
4198 priv->essid_len),
4199 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004200
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004201 switch (priv->ieee->iw_mode) {
4202 case IW_MODE_INFRA:
4203 memcpy(priv->ieee->bssid,
4204 priv->bssid, ETH_ALEN);
4205 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004206
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004207 case IW_MODE_ADHOC:
4208 memcpy(priv->ieee->bssid,
4209 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004210
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004211 /* clear out the station table */
4212 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004213
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004214 IPW_DEBUG_ASSOC
4215 ("queueing adhoc check\n");
4216 queue_delayed_work(priv->
4217 workqueue,
4218 &priv->
4219 adhoc_check,
4220 priv->
4221 assoc_request.
4222 beacon_interval);
4223 break;
4224 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004225
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004226 priv->status &= ~STATUS_ASSOCIATING;
4227 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004228 queue_work(priv->workqueue,
4229 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004230
James Ketrenosb095c382005-08-24 22:04:42 -05004231#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004232#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4233 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4234 if ((priv->status & STATUS_AUTH) &&
4235 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4236 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004237 if ((sizeof
4238 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004239 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004240 <= notif->size)
4241 && (notif->size <= 2314)) {
4242 struct
4243 ieee80211_rx_stats
4244 stats = {
4245 .len =
4246 notif->
4247 size - 1,
4248 };
4249
4250 IPW_DEBUG_QOS
4251 ("QoS Associate "
4252 "size %d\n",
4253 notif->size);
4254 ieee80211_rx_mgt(priv->
4255 ieee,
4256 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004257 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004258 *)
4259 &notif->u.raw, &stats);
4260 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004261 }
James Ketrenosb095c382005-08-24 22:04:42 -05004262#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004263
James Ketrenosa613bff2005-08-24 21:43:11 -05004264 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004265
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004266 break;
4267 }
4268
4269 case CMAS_AUTHENTICATED:{
4270 if (priv->
4271 status & (STATUS_ASSOCIATED |
4272 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004273#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004274 struct notif_authenticate *auth
4275 = &notif->u.auth;
4276 IPW_DEBUG(IPW_DL_NOTIF |
4277 IPW_DL_STATE |
4278 IPW_DL_ASSOC,
4279 "deauthenticated: '%s' "
4280 MAC_FMT
4281 ": (0x%04X) - %s \n",
4282 escape_essid(priv->
4283 essid,
4284 priv->
4285 essid_len),
4286 MAC_ARG(priv->bssid),
4287 ntohs(auth->status),
4288 ipw_get_status_code
4289 (ntohs
4290 (auth->status)));
4291#endif
4292
4293 priv->status &=
4294 ~(STATUS_ASSOCIATING |
4295 STATUS_AUTH |
4296 STATUS_ASSOCIATED);
4297
James Ketrenosa613bff2005-08-24 21:43:11 -05004298 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004299 break;
4300 }
4301
4302 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4303 IPW_DL_ASSOC,
4304 "authenticated: '%s' " MAC_FMT
4305 "\n",
4306 escape_essid(priv->essid,
4307 priv->essid_len),
4308 MAC_ARG(priv->bssid));
4309 break;
4310 }
4311
4312 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004313 if (priv->status & STATUS_AUTH) {
4314 struct
4315 ieee80211_assoc_response
4316 *resp;
4317 resp =
4318 (struct
4319 ieee80211_assoc_response
4320 *)&notif->u.raw;
4321 IPW_DEBUG(IPW_DL_NOTIF |
4322 IPW_DL_STATE |
4323 IPW_DL_ASSOC,
4324 "association failed (0x%04X): %s\n",
4325 ntohs(resp->status),
4326 ipw_get_status_code
4327 (ntohs
4328 (resp->status)));
4329 }
4330
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4332 IPW_DL_ASSOC,
4333 "disassociated: '%s' " MAC_FMT
4334 " \n",
4335 escape_essid(priv->essid,
4336 priv->essid_len),
4337 MAC_ARG(priv->bssid));
4338
4339 priv->status &=
4340 ~(STATUS_DISASSOCIATING |
4341 STATUS_ASSOCIATING |
4342 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004343 if (priv->assoc_network
4344 && (priv->assoc_network->
4345 capability &
4346 WLAN_CAPABILITY_IBSS))
4347 ipw_remove_current_network
4348 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004349
James Ketrenosa613bff2005-08-24 21:43:11 -05004350 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004351
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004352 break;
4353 }
4354
James Ketrenosb095c382005-08-24 22:04:42 -05004355 case CMAS_RX_ASSOC_RESP:
4356 break;
4357
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004358 default:
4359 IPW_ERROR("assoc: unknown (%d)\n",
4360 assoc->state);
4361 break;
4362 }
4363
James Ketrenos43f66a62005-03-25 12:31:53 -06004364 break;
4365 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004366
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004367 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4368 struct notif_authenticate *auth = &notif->u.auth;
4369 switch (auth->state) {
4370 case CMAS_AUTHENTICATED:
4371 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4372 "authenticated: '%s' " MAC_FMT " \n",
4373 escape_essid(priv->essid,
4374 priv->essid_len),
4375 MAC_ARG(priv->bssid));
4376 priv->status |= STATUS_AUTH;
4377 break;
4378
4379 case CMAS_INIT:
4380 if (priv->status & STATUS_AUTH) {
4381 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4382 IPW_DL_ASSOC,
4383 "authentication failed (0x%04X): %s\n",
4384 ntohs(auth->status),
4385 ipw_get_status_code(ntohs
4386 (auth->
4387 status)));
4388 }
4389 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4390 IPW_DL_ASSOC,
4391 "deauthenticated: '%s' " MAC_FMT "\n",
4392 escape_essid(priv->essid,
4393 priv->essid_len),
4394 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004395
4396 priv->status &= ~(STATUS_ASSOCIATING |
4397 STATUS_AUTH |
4398 STATUS_ASSOCIATED);
4399
James Ketrenosa613bff2005-08-24 21:43:11 -05004400 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004401 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004402
4403 case CMAS_TX_AUTH_SEQ_1:
4404 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4405 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4406 break;
4407 case CMAS_RX_AUTH_SEQ_2:
4408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4409 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4410 break;
4411 case CMAS_AUTH_SEQ_1_PASS:
4412 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4413 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4414 break;
4415 case CMAS_AUTH_SEQ_1_FAIL:
4416 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4417 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4418 break;
4419 case CMAS_TX_AUTH_SEQ_3:
4420 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4421 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4422 break;
4423 case CMAS_RX_AUTH_SEQ_4:
4424 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4425 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4426 break;
4427 case CMAS_AUTH_SEQ_2_PASS:
4428 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4429 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4430 break;
4431 case CMAS_AUTH_SEQ_2_FAIL:
4432 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4433 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4434 break;
4435 case CMAS_TX_ASSOC:
4436 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4437 IPW_DL_ASSOC, "TX_ASSOC\n");
4438 break;
4439 case CMAS_RX_ASSOC_RESP:
4440 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4441 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004442
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004443 break;
4444 case CMAS_ASSOCIATED:
4445 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4446 IPW_DL_ASSOC, "ASSOCIATED\n");
4447 break;
4448 default:
4449 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4450 auth->state);
4451 break;
4452 }
4453 break;
4454 }
4455
4456 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4457 struct notif_channel_result *x =
4458 &notif->u.channel_result;
4459
4460 if (notif->size == sizeof(*x)) {
4461 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4462 x->channel_num);
4463 } else {
4464 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4465 "(should be %zd)\n",
4466 notif->size, sizeof(*x));
4467 }
4468 break;
4469 }
4470
4471 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4472 struct notif_scan_complete *x = &notif->u.scan_complete;
4473 if (notif->size == sizeof(*x)) {
4474 IPW_DEBUG_SCAN
4475 ("Scan completed: type %d, %d channels, "
4476 "%d status\n", x->scan_type,
4477 x->num_channels, x->status);
4478 } else {
4479 IPW_ERROR("Scan completed of wrong size %d "
4480 "(should be %zd)\n",
4481 notif->size, sizeof(*x));
4482 }
4483
4484 priv->status &=
4485 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4486
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004487 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004488 cancel_delayed_work(&priv->scan_check);
4489
James Ketrenosb095c382005-08-24 22:04:42 -05004490 if (priv->status & STATUS_EXIT_PENDING)
4491 break;
4492
4493 priv->ieee->scans++;
4494
4495#ifdef CONFIG_IPW2200_MONITOR
4496 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004497 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004498 queue_work(priv->workqueue,
4499 &priv->request_scan);
4500 break;
4501 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004502 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004503#endif /* CONFIG_IPW2200_MONITOR */
4504
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004505 if (!(priv->status & (STATUS_ASSOCIATED |
4506 STATUS_ASSOCIATING |
4507 STATUS_ROAMING |
4508 STATUS_DISASSOCIATING)))
4509 queue_work(priv->workqueue, &priv->associate);
4510 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004511 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4512 /* If a scan completed and we are in roam mode, then
4513 * the scan that completed was the one requested as a
4514 * result of entering roam... so, schedule the
4515 * roam work */
4516 queue_work(priv->workqueue,
4517 &priv->roam);
4518 else
4519 /* Don't schedule if we aborted the scan */
4520 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004521 } else if (priv->status & STATUS_SCAN_PENDING)
4522 queue_work(priv->workqueue,
4523 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004524 else if (priv->config & CFG_BACKGROUND_SCAN
4525 && priv->status & STATUS_ASSOCIATED)
4526 queue_delayed_work(priv->workqueue,
4527 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004528 break;
4529 }
4530
4531 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4532 struct notif_frag_length *x = &notif->u.frag_len;
4533
James Ketrenosa613bff2005-08-24 21:43:11 -05004534 if (notif->size == sizeof(*x))
4535 IPW_ERROR("Frag length: %d\n",
4536 le16_to_cpu(x->frag_length));
4537 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004538 IPW_ERROR("Frag length of wrong size %d "
4539 "(should be %zd)\n",
4540 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004541 break;
4542 }
4543
4544 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4545 struct notif_link_deterioration *x =
4546 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004547
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004548 if (notif->size == sizeof(*x)) {
4549 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4550 "link deterioration: '%s' " MAC_FMT
4551 " \n", escape_essid(priv->essid,
4552 priv->essid_len),
4553 MAC_ARG(priv->bssid));
4554 memcpy(&priv->last_link_deterioration, x,
4555 sizeof(*x));
4556 } else {
4557 IPW_ERROR("Link Deterioration of wrong size %d "
4558 "(should be %zd)\n",
4559 notif->size, sizeof(*x));
4560 }
4561 break;
4562 }
4563
4564 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4565 IPW_ERROR("Dino config\n");
4566 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004567 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004568 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004569
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004570 break;
4571 }
4572
4573 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4574 struct notif_beacon_state *x = &notif->u.beacon_state;
4575 if (notif->size != sizeof(*x)) {
4576 IPW_ERROR
4577 ("Beacon state of wrong size %d (should "
4578 "be %zd)\n", notif->size, sizeof(*x));
4579 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004580 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004581
James Ketrenosa613bff2005-08-24 21:43:11 -05004582 if (le32_to_cpu(x->state) ==
4583 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4584 ipw_handle_missed_beacon(priv,
4585 le32_to_cpu(x->
4586 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004587
James Ketrenos43f66a62005-03-25 12:31:53 -06004588 break;
4589 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004590
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004591 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4592 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4593 if (notif->size == sizeof(*x)) {
4594 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4595 "0x%02x station %d\n",
4596 x->key_state, x->security_type,
4597 x->station_index);
4598 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004599 }
4600
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004601 IPW_ERROR
4602 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4603 notif->size, sizeof(*x));
4604 break;
4605 }
4606
4607 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4608 struct notif_calibration *x = &notif->u.calibration;
4609
4610 if (notif->size == sizeof(*x)) {
4611 memcpy(&priv->calib, x, sizeof(*x));
4612 IPW_DEBUG_INFO("TODO: Calibration\n");
4613 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004614 }
4615
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004616 IPW_ERROR
4617 ("Calibration of wrong size %d (should be %zd)\n",
4618 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004619 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004620 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004621
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004622 case HOST_NOTIFICATION_NOISE_STATS:{
4623 if (notif->size == sizeof(u32)) {
4624 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004625 (u8) (le32_to_cpu(notif->u.noise.value) &
4626 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004627 average_add(&priv->average_noise,
4628 priv->last_noise);
4629 break;
4630 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004631
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004632 IPW_ERROR
4633 ("Noise stat is wrong size %d (should be %zd)\n",
4634 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004635 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004636 }
4637
James Ketrenos43f66a62005-03-25 12:31:53 -06004638 default:
4639 IPW_ERROR("Unknown notification: "
4640 "subtype=%d,flags=0x%2x,size=%d\n",
4641 notif->subtype, notif->flags, notif->size);
4642 }
4643}
4644
4645/**
4646 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004647 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004648 * @param priv
4649 * @return error code
4650 */
4651static int ipw_queue_reset(struct ipw_priv *priv)
4652{
4653 int rc = 0;
4654 /** @todo customize queue sizes */
4655 int nTx = 64, nTxCmd = 8;
4656 ipw_tx_queue_free(priv);
4657 /* Tx CMD queue */
4658 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004659 IPW_TX_CMD_QUEUE_READ_INDEX,
4660 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4661 IPW_TX_CMD_QUEUE_BD_BASE,
4662 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004663 if (rc) {
4664 IPW_ERROR("Tx Cmd queue init failed\n");
4665 goto error;
4666 }
4667 /* Tx queue(s) */
4668 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004669 IPW_TX_QUEUE_0_READ_INDEX,
4670 IPW_TX_QUEUE_0_WRITE_INDEX,
4671 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004672 if (rc) {
4673 IPW_ERROR("Tx 0 queue init failed\n");
4674 goto error;
4675 }
4676 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004677 IPW_TX_QUEUE_1_READ_INDEX,
4678 IPW_TX_QUEUE_1_WRITE_INDEX,
4679 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004680 if (rc) {
4681 IPW_ERROR("Tx 1 queue init failed\n");
4682 goto error;
4683 }
4684 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004685 IPW_TX_QUEUE_2_READ_INDEX,
4686 IPW_TX_QUEUE_2_WRITE_INDEX,
4687 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004688 if (rc) {
4689 IPW_ERROR("Tx 2 queue init failed\n");
4690 goto error;
4691 }
4692 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004693 IPW_TX_QUEUE_3_READ_INDEX,
4694 IPW_TX_QUEUE_3_WRITE_INDEX,
4695 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004696 if (rc) {
4697 IPW_ERROR("Tx 3 queue init failed\n");
4698 goto error;
4699 }
4700 /* statistics */
4701 priv->rx_bufs_min = 0;
4702 priv->rx_pend_max = 0;
4703 return rc;
4704
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004705 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004706 ipw_tx_queue_free(priv);
4707 return rc;
4708}
4709
4710/**
4711 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004712 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004713 * When FW adwances 'R' index, all entries between old and
4714 * new 'R' index need to be reclaimed. As result, some free space
4715 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004716 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 * @note Need to protect against garbage in 'R' index
4718 * @param priv
4719 * @param txq
4720 * @param qindex
4721 * @return Number of used entries remains in the queue
4722 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004723static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004724 struct clx2_tx_queue *txq, int qindex)
4725{
4726 u32 hw_tail;
4727 int used;
4728 struct clx2_queue *q = &txq->q;
4729
4730 hw_tail = ipw_read32(priv, q->reg_r);
4731 if (hw_tail >= q->n_bd) {
4732 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004733 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4734 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004735 goto done;
4736 }
4737 for (; q->last_used != hw_tail;
4738 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4739 ipw_queue_tx_free_tfd(priv, txq);
4740 priv->tx_packets++;
4741 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004742 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004743 if ((ipw_queue_space(q) > q->low_mark) &&
4744 (qindex >= 0) &&
4745 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4746 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004747 used = q->first_empty - q->last_used;
4748 if (used < 0)
4749 used += q->n_bd;
4750
4751 return used;
4752}
4753
4754static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4755 int len, int sync)
4756{
4757 struct clx2_tx_queue *txq = &priv->txq_cmd;
4758 struct clx2_queue *q = &txq->q;
4759 struct tfd_frame *tfd;
4760
4761 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4762 IPW_ERROR("No space for Tx\n");
4763 return -EBUSY;
4764 }
4765
4766 tfd = &txq->bd[q->first_empty];
4767 txq->txb[q->first_empty] = NULL;
4768
4769 memset(tfd, 0, sizeof(*tfd));
4770 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4771 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4772 priv->hcmd_seq++;
4773 tfd->u.cmd.index = hcmd;
4774 tfd->u.cmd.length = len;
4775 memcpy(tfd->u.cmd.payload, buf, len);
4776 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4777 ipw_write32(priv, q->reg_w, q->first_empty);
4778 _ipw_read32(priv, 0x90);
4779
4780 return 0;
4781}
4782
Jeff Garzikbf794512005-07-31 13:07:26 -04004783/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004784 * Rx theory of operation
4785 *
4786 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004787 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004788 * 0 to 31
4789 *
4790 * Rx Queue Indexes
4791 * The host/firmware share two index registers for managing the Rx buffers.
4792 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004793 * The READ index maps to the first position that the firmware may be writing
4794 * to -- the driver can read up to (but not including) this position and get
4795 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004796 * The READ index is managed by the firmware once the card is enabled.
4797 *
4798 * The WRITE index maps to the last position the driver has read from -- the
4799 * position preceding WRITE is the last slot the firmware can place a packet.
4800 *
4801 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004802 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004803 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004804 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004805 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4806 *
4807 * When the firmware places a packet in a buffer it will advance the READ index
4808 * and fire the RX interrupt. The driver can then query the READ index and
4809 * process as many packets as possible, moving the WRITE index forward as it
4810 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004811 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004812 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004813 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004814 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004815 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004816 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4817 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4818 * 'processed' and 'read' driver indexes as well)
4819 * + A received packet is processed and handed to the kernel network stack,
4820 * detached from the ipw->rxq. The driver 'processed' index is updated.
4821 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004822 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4823 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 * were enough free buffers and RX_STALLED is set it is cleared.
4825 *
4826 *
4827 * Driver sequence:
4828 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004829 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004830 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4831 * ipw_rx_queue_restock
4832 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4833 * queue, updates firmware pointers, and updates
4834 * the WRITE index. If insufficient rx_free buffers
4835 * are available, schedules ipw_rx_queue_replenish
4836 *
4837 * -- enable interrupts --
4838 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004839 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004840 * Moves the packet buffer from queue to rx_used.
4841 * Calls ipw_rx_queue_restock to refill any empty
4842 * slots.
4843 * ...
4844 *
4845 */
4846
Jeff Garzikbf794512005-07-31 13:07:26 -04004847/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004848 * If there are slots in the RX queue that need to be restocked,
4849 * and we have free pre-allocated buffers, fill the ranks as much
4850 * as we can pulling from rx_free.
4851 *
4852 * This moves the 'write' index forward to catch up with 'processed', and
4853 * also updates the memory address in the firmware to reference the new
4854 * target buffer.
4855 */
4856static void ipw_rx_queue_restock(struct ipw_priv *priv)
4857{
4858 struct ipw_rx_queue *rxq = priv->rxq;
4859 struct list_head *element;
4860 struct ipw_rx_mem_buffer *rxb;
4861 unsigned long flags;
4862 int write;
4863
4864 spin_lock_irqsave(&rxq->lock, flags);
4865 write = rxq->write;
4866 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4867 element = rxq->rx_free.next;
4868 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4869 list_del(element);
4870
James Ketrenosb095c382005-08-24 22:04:42 -05004871 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004872 rxb->dma_addr);
4873 rxq->queue[rxq->write] = rxb;
4874 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4875 rxq->free_count--;
4876 }
4877 spin_unlock_irqrestore(&rxq->lock, flags);
4878
Jeff Garzikbf794512005-07-31 13:07:26 -04004879 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004880 * refill it */
4881 if (rxq->free_count <= RX_LOW_WATERMARK)
4882 queue_work(priv->workqueue, &priv->rx_replenish);
4883
4884 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004885 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004886 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004887}
4888
4889/*
4890 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004891 * Also restock the Rx queue via ipw_rx_queue_restock.
4892 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004893 * This is called as a scheduled work item (except for during intialization)
4894 */
4895static void ipw_rx_queue_replenish(void *data)
4896{
4897 struct ipw_priv *priv = data;
4898 struct ipw_rx_queue *rxq = priv->rxq;
4899 struct list_head *element;
4900 struct ipw_rx_mem_buffer *rxb;
4901 unsigned long flags;
4902
4903 spin_lock_irqsave(&rxq->lock, flags);
4904 while (!list_empty(&rxq->rx_used)) {
4905 element = rxq->rx_used.next;
4906 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004907 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004908 if (!rxb->skb) {
4909 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4910 priv->net_dev->name);
4911 /* We don't reschedule replenish work here -- we will
4912 * call the restock method and if it still needs
4913 * more buffers it will schedule replenish */
4914 break;
4915 }
4916 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004917
James Ketrenos43f66a62005-03-25 12:31:53 -06004918 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004919 rxb->dma_addr =
4920 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004921 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004922
James Ketrenos43f66a62005-03-25 12:31:53 -06004923 list_add_tail(&rxb->list, &rxq->rx_free);
4924 rxq->free_count++;
4925 }
4926 spin_unlock_irqrestore(&rxq->lock, flags);
4927
4928 ipw_rx_queue_restock(priv);
4929}
4930
James Ketrenosc848d0a2005-08-24 21:56:24 -05004931static void ipw_bg_rx_queue_replenish(void *data)
4932{
4933 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004934 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004935 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08004936 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004937}
4938
James Ketrenos43f66a62005-03-25 12:31:53 -06004939/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08004940 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004941 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004942 * non NULL it is unmapped and freed
4943 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004944static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004945{
4946 int i;
4947
4948 if (!rxq)
4949 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004950
James Ketrenos43f66a62005-03-25 12:31:53 -06004951 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4952 if (rxq->pool[i].skb != NULL) {
4953 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004954 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004955 dev_kfree_skb(rxq->pool[i].skb);
4956 }
4957 }
4958
4959 kfree(rxq);
4960}
4961
4962static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4963{
4964 struct ipw_rx_queue *rxq;
4965 int i;
4966
Takisc75f4742005-12-01 01:41:45 -08004967 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004968 if (unlikely(!rxq)) {
4969 IPW_ERROR("memory allocation failed\n");
4970 return NULL;
4971 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004972 spin_lock_init(&rxq->lock);
4973 INIT_LIST_HEAD(&rxq->rx_free);
4974 INIT_LIST_HEAD(&rxq->rx_used);
4975
4976 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004977 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004978 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4979
4980 /* Set us so that we have processed and used all buffers, but have
4981 * not restocked the Rx queue with fresh buffers */
4982 rxq->read = rxq->write = 0;
4983 rxq->processed = RX_QUEUE_SIZE - 1;
4984 rxq->free_count = 0;
4985
4986 return rxq;
4987}
4988
4989static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4990{
4991 rate &= ~IEEE80211_BASIC_RATE_MASK;
4992 if (ieee_mode == IEEE_A) {
4993 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004994 case IEEE80211_OFDM_RATE_6MB:
4995 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004996 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004997 case IEEE80211_OFDM_RATE_9MB:
4998 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004999 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005000 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005001 return priv->
5002 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005003 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005004 return priv->
5005 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005006 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005007 return priv->
5008 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005009 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005010 return priv->
5011 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005012 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005013 return priv->
5014 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005015 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005016 return priv->
5017 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005018 default:
5019 return 0;
5020 }
5021 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005022
James Ketrenos43f66a62005-03-25 12:31:53 -06005023 /* B and G mixed */
5024 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005025 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005026 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005027 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005029 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005030 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005031 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005032 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5033 }
5034
5035 /* If we are limited to B modulations, bail at this point */
5036 if (ieee_mode == IEEE_B)
5037 return 0;
5038
5039 /* G */
5040 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005041 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005042 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005043 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005044 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005045 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005046 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005047 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005049 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005050 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005051 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005052 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005053 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005054 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005055 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005056 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5057 }
5058
5059 return 0;
5060}
5061
Jeff Garzikbf794512005-07-31 13:07:26 -04005062static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 const struct ieee80211_network *network,
5064 struct ipw_supported_rates *rates)
5065{
5066 int num_rates, i;
5067
5068 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005069 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005070 rates->num_rates = 0;
5071 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005072 if (!ipw_is_rate_in_mask(priv, network->mode,
5073 network->rates[i])) {
5074
James Ketrenosea2b26e2005-08-24 21:25:16 -05005075 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005076 IPW_DEBUG_SCAN("Adding masked mandatory "
5077 "rate %02X\n",
5078 network->rates[i]);
5079 rates->supported_rates[rates->num_rates++] =
5080 network->rates[i];
5081 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005082 }
5083
James Ketrenos43f66a62005-03-25 12:31:53 -06005084 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5085 network->rates[i], priv->rates_mask);
5086 continue;
5087 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005088
James Ketrenos43f66a62005-03-25 12:31:53 -06005089 rates->supported_rates[rates->num_rates++] = network->rates[i];
5090 }
5091
James Ketrenosa613bff2005-08-24 21:43:11 -05005092 num_rates = min(network->rates_ex_len,
5093 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005094 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005095 if (!ipw_is_rate_in_mask(priv, network->mode,
5096 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005097 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005098 IPW_DEBUG_SCAN("Adding masked mandatory "
5099 "rate %02X\n",
5100 network->rates_ex[i]);
5101 rates->supported_rates[rates->num_rates++] =
5102 network->rates[i];
5103 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005104 }
5105
James Ketrenos43f66a62005-03-25 12:31:53 -06005106 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5107 network->rates_ex[i], priv->rates_mask);
5108 continue;
5109 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005110
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005111 rates->supported_rates[rates->num_rates++] =
5112 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005113 }
5114
James Ketrenosea2b26e2005-08-24 21:25:16 -05005115 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005116}
5117
Arjan van de Ven858119e2006-01-14 13:20:43 -08005118static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005119 const struct ipw_supported_rates *src)
5120{
5121 u8 i;
5122 for (i = 0; i < src->num_rates; i++)
5123 dest->supported_rates[i] = src->supported_rates[i];
5124 dest->num_rates = src->num_rates;
5125}
5126
5127/* TODO: Look at sniffed packets in the air to determine if the basic rate
5128 * mask should ever be used -- right now all callers to add the scan rates are
5129 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5130static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005131 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005132{
Jeff Garzikbf794512005-07-31 13:07:26 -04005133 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005134 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005135
James Ketrenos43f66a62005-03-25 12:31:53 -06005136 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005137 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005138 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005139
5140 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005141 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005142 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005143
5144 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005145 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005146 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005147
5148 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005149 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005150 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005151}
5152
5153static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005154 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005155{
Jeff Garzikbf794512005-07-31 13:07:26 -04005156 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005157 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005158
5159 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005160 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005161 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005162
5163 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005164 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005165 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005166
5167 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005168 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005169 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005170
5171 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005172 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005173 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005174
5175 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005176 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005177 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005178
5179 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005180 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005181 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005182
5183 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005184 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005185 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005186
5187 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005188 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005189 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005190}
5191
5192struct ipw_network_match {
5193 struct ieee80211_network *network;
5194 struct ipw_supported_rates rates;
5195};
5196
James Ketrenosc848d0a2005-08-24 21:56:24 -05005197static int ipw_find_adhoc_network(struct ipw_priv *priv,
5198 struct ipw_network_match *match,
5199 struct ieee80211_network *network,
5200 int roaming)
5201{
5202 struct ipw_supported_rates rates;
5203
5204 /* Verify that this network's capability is compatible with the
5205 * current mode (AdHoc or Infrastructure) */
5206 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5207 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5208 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5209 "capability mismatch.\n",
5210 escape_essid(network->ssid, network->ssid_len),
5211 MAC_ARG(network->bssid));
5212 return 0;
5213 }
5214
5215 /* If we do not have an ESSID for this AP, we can not associate with
5216 * it */
5217 if (network->flags & NETWORK_EMPTY_ESSID) {
5218 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5219 "because of hidden ESSID.\n",
5220 escape_essid(network->ssid, network->ssid_len),
5221 MAC_ARG(network->bssid));
5222 return 0;
5223 }
5224
5225 if (unlikely(roaming)) {
5226 /* If we are roaming, then ensure check if this is a valid
5227 * network to try and roam to */
5228 if ((network->ssid_len != match->network->ssid_len) ||
5229 memcmp(network->ssid, match->network->ssid,
5230 network->ssid_len)) {
5231 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5232 "because of non-network ESSID.\n",
5233 escape_essid(network->ssid,
5234 network->ssid_len),
5235 MAC_ARG(network->bssid));
5236 return 0;
5237 }
5238 } else {
5239 /* If an ESSID has been configured then compare the broadcast
5240 * ESSID to ours */
5241 if ((priv->config & CFG_STATIC_ESSID) &&
5242 ((network->ssid_len != priv->essid_len) ||
5243 memcmp(network->ssid, priv->essid,
5244 min(network->ssid_len, priv->essid_len)))) {
5245 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005246
James Ketrenosc848d0a2005-08-24 21:56:24 -05005247 strncpy(escaped,
5248 escape_essid(network->ssid, network->ssid_len),
5249 sizeof(escaped));
5250 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5251 "because of ESSID mismatch: '%s'.\n",
5252 escaped, MAC_ARG(network->bssid),
5253 escape_essid(priv->essid,
5254 priv->essid_len));
5255 return 0;
5256 }
5257 }
5258
5259 /* If the old network rate is better than this one, don't bother
5260 * testing everything else. */
5261
5262 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005263 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5264 "current network.\n",
5265 escape_essid(match->network->ssid,
5266 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005267 return 0;
5268 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005269 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5270 "current network.\n",
5271 escape_essid(match->network->ssid,
5272 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005273 return 0;
5274 }
5275
5276 /* Now go through and see if the requested network is valid... */
5277 if (priv->ieee->scan_age != 0 &&
5278 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5279 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005280 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005281 escape_essid(network->ssid, network->ssid_len),
5282 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005283 jiffies_to_msecs(jiffies -
5284 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005285 return 0;
5286 }
5287
5288 if ((priv->config & CFG_STATIC_CHANNEL) &&
5289 (network->channel != priv->channel)) {
5290 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5291 "because of channel mismatch: %d != %d.\n",
5292 escape_essid(network->ssid, network->ssid_len),
5293 MAC_ARG(network->bssid),
5294 network->channel, priv->channel);
5295 return 0;
5296 }
5297
5298 /* Verify privacy compatability */
5299 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5300 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5301 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5302 "because of privacy mismatch: %s != %s.\n",
5303 escape_essid(network->ssid, network->ssid_len),
5304 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005305 priv->
5306 capability & CAP_PRIVACY_ON ? "on" : "off",
5307 network->
5308 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5309 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005310 return 0;
5311 }
5312
5313 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5314 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5315 "because of the same BSSID match: " MAC_FMT
5316 ".\n", escape_essid(network->ssid,
5317 network->ssid_len),
5318 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5319 return 0;
5320 }
5321
5322 /* Filter out any incompatible freq / mode combinations */
5323 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5324 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5325 "because of invalid frequency/mode "
5326 "combination.\n",
5327 escape_essid(network->ssid, network->ssid_len),
5328 MAC_ARG(network->bssid));
5329 return 0;
5330 }
5331
5332 /* Ensure that the rates supported by the driver are compatible with
5333 * this AP, including verification of basic rates (mandatory) */
5334 if (!ipw_compatible_rates(priv, network, &rates)) {
5335 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5336 "because configured rate mask excludes "
5337 "AP mandatory rate.\n",
5338 escape_essid(network->ssid, network->ssid_len),
5339 MAC_ARG(network->bssid));
5340 return 0;
5341 }
5342
5343 if (rates.num_rates == 0) {
5344 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5345 "because of no compatible rates.\n",
5346 escape_essid(network->ssid, network->ssid_len),
5347 MAC_ARG(network->bssid));
5348 return 0;
5349 }
5350
5351 /* TODO: Perform any further minimal comparititive tests. We do not
5352 * want to put too much policy logic here; intelligent scan selection
5353 * should occur within a generic IEEE 802.11 user space tool. */
5354
5355 /* Set up 'new' AP to this network */
5356 ipw_copy_rates(&match->rates, &rates);
5357 match->network = network;
5358 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5359 escape_essid(network->ssid, network->ssid_len),
5360 MAC_ARG(network->bssid));
5361
5362 return 1;
5363}
5364
5365static void ipw_merge_adhoc_network(void *data)
5366{
5367 struct ipw_priv *priv = data;
5368 struct ieee80211_network *network = NULL;
5369 struct ipw_network_match match = {
5370 .network = priv->assoc_network
5371 };
5372
James Ketrenosafbf30a2005-08-25 00:05:33 -05005373 if ((priv->status & STATUS_ASSOCIATED) &&
5374 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005375 /* First pass through ROAM process -- look for a better
5376 * network */
5377 unsigned long flags;
5378
5379 spin_lock_irqsave(&priv->ieee->lock, flags);
5380 list_for_each_entry(network, &priv->ieee->network_list, list) {
5381 if (network != priv->assoc_network)
5382 ipw_find_adhoc_network(priv, &match, network,
5383 1);
5384 }
5385 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5386
5387 if (match.network == priv->assoc_network) {
5388 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5389 "merge to.\n");
5390 return;
5391 }
5392
Zhu Yi46441512006-01-24 16:37:59 +08005393 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005394 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5395 IPW_DEBUG_MERGE("remove network %s\n",
5396 escape_essid(priv->essid,
5397 priv->essid_len));
5398 ipw_remove_current_network(priv);
5399 }
5400
5401 ipw_disassociate(priv);
5402 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005403 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005404 return;
5405 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005406}
5407
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005408static int ipw_best_network(struct ipw_priv *priv,
5409 struct ipw_network_match *match,
5410 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005411{
5412 struct ipw_supported_rates rates;
5413
5414 /* Verify that this network's capability is compatible with the
5415 * current mode (AdHoc or Infrastructure) */
5416 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005417 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005418 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5419 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5420 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005421 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005422 escape_essid(network->ssid, network->ssid_len),
5423 MAC_ARG(network->bssid));
5424 return 0;
5425 }
5426
5427 /* If we do not have an ESSID for this AP, we can not associate with
5428 * it */
5429 if (network->flags & NETWORK_EMPTY_ESSID) {
5430 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5431 "because of hidden ESSID.\n",
5432 escape_essid(network->ssid, network->ssid_len),
5433 MAC_ARG(network->bssid));
5434 return 0;
5435 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005436
James Ketrenos43f66a62005-03-25 12:31:53 -06005437 if (unlikely(roaming)) {
5438 /* If we are roaming, then ensure check if this is a valid
5439 * network to try and roam to */
5440 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005441 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005442 network->ssid_len)) {
5443 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5444 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005446 network->ssid_len),
5447 MAC_ARG(network->bssid));
5448 return 0;
5449 }
5450 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005451 /* If an ESSID has been configured then compare the broadcast
5452 * ESSID to ours */
5453 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005454 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005455 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005456 min(network->ssid_len, priv->essid_len)))) {
5457 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005458 strncpy(escaped,
5459 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005460 sizeof(escaped));
5461 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005462 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005463 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005464 escape_essid(priv->essid,
5465 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005466 return 0;
5467 }
5468 }
5469
5470 /* If the old network rate is better than this one, don't bother
5471 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005472 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005473 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005474 strncpy(escaped,
5475 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005476 sizeof(escaped));
5477 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5478 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5479 escaped, MAC_ARG(network->bssid),
5480 escape_essid(match->network->ssid,
5481 match->network->ssid_len),
5482 MAC_ARG(match->network->bssid));
5483 return 0;
5484 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005485
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 /* If this network has already had an association attempt within the
5487 * last 3 seconds, do not try and associate again... */
5488 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005489 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005490 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005491 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005492 "assoc attempt).\n",
5493 escape_essid(network->ssid, network->ssid_len),
5494 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005495 jiffies_to_msecs(jiffies -
5496 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005497 return 0;
5498 }
5499
5500 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005501 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005502 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005503 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005504 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005505 escape_essid(network->ssid, network->ssid_len),
5506 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005507 jiffies_to_msecs(jiffies -
5508 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005509 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005510 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005511
Jeff Garzikbf794512005-07-31 13:07:26 -04005512 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005513 (network->channel != priv->channel)) {
5514 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5515 "because of channel mismatch: %d != %d.\n",
5516 escape_essid(network->ssid, network->ssid_len),
5517 MAC_ARG(network->bssid),
5518 network->channel, priv->channel);
5519 return 0;
5520 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005521
James Ketrenos43f66a62005-03-25 12:31:53 -06005522 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005523 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005524 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5525 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5526 "because of privacy mismatch: %s != %s.\n",
5527 escape_essid(network->ssid, network->ssid_len),
5528 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005529 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005531 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005532 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005533 return 0;
5534 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005535
Hong Liucdd1fa12005-08-31 18:14:27 +08005536 if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
5537 network->rsn_ie_len > 0)) {
5538 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5539 "because of WPA capability mismatch.\n",
5540 escape_essid(network->ssid, network->ssid_len),
5541 MAC_ARG(network->bssid));
5542 return 0;
5543 }
5544
Jeff Garzikbf794512005-07-31 13:07:26 -04005545 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005546 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5547 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5548 "because of BSSID mismatch: " MAC_FMT ".\n",
5549 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005550 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005551 return 0;
5552 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005553
James Ketrenos43f66a62005-03-25 12:31:53 -06005554 /* Filter out any incompatible freq / mode combinations */
5555 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5556 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5557 "because of invalid frequency/mode "
5558 "combination.\n",
5559 escape_essid(network->ssid, network->ssid_len),
5560 MAC_ARG(network->bssid));
5561 return 0;
5562 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005563
Liu Hong1fe0adb2005-08-19 09:33:10 -05005564 /* Filter out invalid channel in current GEO */
5565 if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5566 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5567 "because of invalid channel in current GEO\n",
5568 escape_essid(network->ssid, network->ssid_len),
5569 MAC_ARG(network->bssid));
5570 return 0;
5571 }
5572
James Ketrenosea2b26e2005-08-24 21:25:16 -05005573 /* Ensure that the rates supported by the driver are compatible with
5574 * this AP, including verification of basic rates (mandatory) */
5575 if (!ipw_compatible_rates(priv, network, &rates)) {
5576 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5577 "because configured rate mask excludes "
5578 "AP mandatory rate.\n",
5579 escape_essid(network->ssid, network->ssid_len),
5580 MAC_ARG(network->bssid));
5581 return 0;
5582 }
5583
James Ketrenos43f66a62005-03-25 12:31:53 -06005584 if (rates.num_rates == 0) {
5585 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5586 "because of no compatible rates.\n",
5587 escape_essid(network->ssid, network->ssid_len),
5588 MAC_ARG(network->bssid));
5589 return 0;
5590 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005591
James Ketrenos43f66a62005-03-25 12:31:53 -06005592 /* TODO: Perform any further minimal comparititive tests. We do not
5593 * want to put too much policy logic here; intelligent scan selection
5594 * should occur within a generic IEEE 802.11 user space tool. */
5595
5596 /* Set up 'new' AP to this network */
5597 ipw_copy_rates(&match->rates, &rates);
5598 match->network = network;
5599
5600 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5601 escape_essid(network->ssid, network->ssid_len),
5602 MAC_ARG(network->bssid));
5603
5604 return 1;
5605}
5606
Jeff Garzikbf794512005-07-31 13:07:26 -04005607static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005608 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005609{
Liu Hong1fe0adb2005-08-19 09:33:10 -05005610 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005611 int i;
5612
James Ketrenos43f66a62005-03-25 12:31:53 -06005613 /*
5614 * For the purposes of scanning, we can set our wireless mode
5615 * to trigger scans across combinations of bands, but when it
5616 * comes to creating a new ad-hoc network, we have tell the FW
5617 * exactly which band to use.
5618 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005619 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005620 * chossen band. Attempting to create a new ad-hoc network
5621 * with an invalid channel for wireless mode will trigger a
5622 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005623 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005624 */
Liu Hong1fe0adb2005-08-19 09:33:10 -05005625 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005626 case IEEE80211_52GHZ_BAND:
5627 network->mode = IEEE_A;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005628 i = ipw_channel_to_index(priv->ieee, priv->channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005629 if (i == -1)
5630 BUG();
5631 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5632 IPW_WARNING("Overriding invalid channel\n");
5633 priv->channel = geo->a[0].channel;
5634 }
5635 break;
5636
5637 case IEEE80211_24GHZ_BAND:
5638 if (priv->ieee->mode & IEEE_G)
5639 network->mode = IEEE_G;
5640 else
5641 network->mode = IEEE_B;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005642 i = ipw_channel_to_index(priv->ieee, priv->channel);
5643 if (i == -1)
5644 BUG();
5645 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5646 IPW_WARNING("Overriding invalid channel\n");
5647 priv->channel = geo->bg[0].channel;
5648 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005649 break;
5650
5651 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005652 IPW_WARNING("Overriding invalid channel\n");
5653 if (priv->ieee->mode & IEEE_A) {
5654 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005655 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005656 } else if (priv->ieee->mode & IEEE_G) {
5657 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005658 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005659 } else {
5660 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005661 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005662 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005663 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005664 }
5665
5666 network->channel = priv->channel;
5667 priv->config |= CFG_ADHOC_PERSIST;
5668 ipw_create_bssid(priv, network->bssid);
5669 network->ssid_len = priv->essid_len;
5670 memcpy(network->ssid, priv->essid, priv->essid_len);
5671 memset(&network->stats, 0, sizeof(network->stats));
5672 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005673 if (!(priv->config & CFG_PREAMBLE_LONG))
5674 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005675 if (priv->capability & CAP_PRIVACY_ON)
5676 network->capability |= WLAN_CAPABILITY_PRIVACY;
5677 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005678 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005679 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005680 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005681 &priv->rates.supported_rates[network->rates_len],
5682 network->rates_ex_len);
5683 network->last_scanned = 0;
5684 network->flags = 0;
5685 network->last_associate = 0;
5686 network->time_stamp[0] = 0;
5687 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005688 network->beacon_interval = 100; /* Default */
5689 network->listen_interval = 10; /* Default */
5690 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005691 network->wpa_ie_len = 0;
5692 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005693}
5694
James Ketrenosb095c382005-08-24 22:04:42 -05005695static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5696{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005697 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005698
5699 if (!(priv->ieee->sec.flags & (1 << index)))
5700 return;
5701
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005702 key.key_id = index;
5703 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5704 key.security_type = type;
5705 key.station_index = 0; /* always 0 for BSS */
5706 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005707 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005708 key.tx_counter[0] = 0;
5709 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005710
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005711 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005712}
5713
5714static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005715{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005716 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005717 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005718
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005719 key.cmd_id = DINO_CMD_WEP_KEY;
5720 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005721
James Ketrenosb095c382005-08-24 22:04:42 -05005722 /* Note: AES keys cannot be set for multiple times.
5723 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005724 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005725 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005726 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005727 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005728 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005729 }
5730
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005731 key.key_size = priv->ieee->sec.key_sizes[i];
5732 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005733
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005734 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005735 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005736}
5737
Zhu Yi1fbfea52005-08-05 17:22:56 +08005738static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5739{
5740 if (priv->ieee->host_encrypt)
5741 return;
5742
5743 switch (level) {
5744 case SEC_LEVEL_3:
5745 priv->sys_config.disable_unicast_decryption = 0;
5746 priv->ieee->host_decrypt = 0;
5747 break;
5748 case SEC_LEVEL_2:
5749 priv->sys_config.disable_unicast_decryption = 1;
5750 priv->ieee->host_decrypt = 1;
5751 break;
5752 case SEC_LEVEL_1:
5753 priv->sys_config.disable_unicast_decryption = 0;
5754 priv->ieee->host_decrypt = 0;
5755 break;
5756 case SEC_LEVEL_0:
5757 priv->sys_config.disable_unicast_decryption = 1;
5758 break;
5759 default:
5760 break;
5761 }
5762}
5763
5764static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5765{
5766 if (priv->ieee->host_encrypt)
5767 return;
5768
5769 switch (level) {
5770 case SEC_LEVEL_3:
5771 priv->sys_config.disable_multicast_decryption = 0;
5772 break;
5773 case SEC_LEVEL_2:
5774 priv->sys_config.disable_multicast_decryption = 1;
5775 break;
5776 case SEC_LEVEL_1:
5777 priv->sys_config.disable_multicast_decryption = 0;
5778 break;
5779 case SEC_LEVEL_0:
5780 priv->sys_config.disable_multicast_decryption = 1;
5781 break;
5782 default:
5783 break;
5784 }
5785}
5786
James Ketrenosb095c382005-08-24 22:04:42 -05005787static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5788{
5789 switch (priv->ieee->sec.level) {
5790 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005791 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5792 ipw_send_tgi_tx_key(priv,
5793 DCT_FLAG_EXT_SECURITY_CCM,
5794 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005795
Hong Liu567deaf2005-08-31 18:07:22 +08005796 if (!priv->ieee->host_mc_decrypt)
5797 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005798 break;
5799 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005800 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5801 ipw_send_tgi_tx_key(priv,
5802 DCT_FLAG_EXT_SECURITY_TKIP,
5803 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005804 break;
5805 case SEC_LEVEL_1:
5806 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005807 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5808 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005809 break;
5810 case SEC_LEVEL_0:
5811 default:
5812 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005813 }
5814}
5815
5816static void ipw_adhoc_check(void *data)
5817{
5818 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005819
James Ketrenosafbf30a2005-08-25 00:05:33 -05005820 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005822 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5823 IPW_DL_STATE | IPW_DL_ASSOC,
5824 "Missed beacon: %d - disassociate\n",
5825 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005826 ipw_remove_current_network(priv);
5827 ipw_disassociate(priv);
5828 return;
5829 }
5830
Jeff Garzikbf794512005-07-31 13:07:26 -04005831 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 priv->assoc_request.beacon_interval);
5833}
5834
James Ketrenosc848d0a2005-08-24 21:56:24 -05005835static void ipw_bg_adhoc_check(void *data)
5836{
5837 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005838 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005839 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005840 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005841}
5842
Brice Goglin0f52bf92005-12-01 01:41:46 -08005843#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005844static void ipw_debug_config(struct ipw_priv *priv)
5845{
5846 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5847 "[CFG 0x%08X]\n", priv->config);
5848 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005849 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005850 else
5851 IPW_DEBUG_INFO("Channel unlocked.\n");
5852 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005853 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005854 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005855 else
5856 IPW_DEBUG_INFO("ESSID unlocked.\n");
5857 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005858 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5859 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005860 else
5861 IPW_DEBUG_INFO("BSSID unlocked.\n");
5862 if (priv->capability & CAP_PRIVACY_ON)
5863 IPW_DEBUG_INFO("PRIVACY on\n");
5864 else
5865 IPW_DEBUG_INFO("PRIVACY off\n");
5866 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5867}
5868#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005869#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005870#endif
5871
Arjan van de Ven858119e2006-01-14 13:20:43 -08005872static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005873{
5874 /* TODO: Verify that this works... */
5875 struct ipw_fixed_rate fr = {
5876 .tx_rates = priv->rates_mask
5877 };
5878 u32 reg;
5879 u16 mask = 0;
5880
Jeff Garzikbf794512005-07-31 13:07:26 -04005881 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005882 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005883
James Ketrenos43f66a62005-03-25 12:31:53 -06005884 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005885 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005886 /* IEEE_A */
5887 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5888 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005889 IPW_DEBUG_WX
5890 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005891 fr.tx_rates = 0;
5892 break;
5893 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005894
James Ketrenos43f66a62005-03-25 12:31:53 -06005895 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5896 break;
5897
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005898 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005900 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005901 if (fr.tx_rates & ~IEEE80211_CCK_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 }
5907 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005908 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005909
5910 /* IEEE_G */
5911 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5912 IEEE80211_OFDM_RATES_MASK)) {
5913 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005914 IPW_DEBUG_WX
5915 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005916 fr.tx_rates = 0;
5917 break;
5918 }
5919
5920 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5921 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5922 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5923 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005924
James Ketrenos43f66a62005-03-25 12:31:53 -06005925 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5926 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5927 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5928 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005929
James Ketrenos43f66a62005-03-25 12:31:53 -06005930 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5931 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5932 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5933 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005934
James Ketrenos43f66a62005-03-25 12:31:53 -06005935 fr.tx_rates |= mask;
5936 break;
5937 }
5938
5939 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005940 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005941}
5942
James Ketrenosea2b26e2005-08-24 21:25:16 -05005943static void ipw_abort_scan(struct ipw_priv *priv)
5944{
5945 int err;
5946
5947 if (priv->status & STATUS_SCAN_ABORTING) {
5948 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5949 return;
5950 }
5951 priv->status |= STATUS_SCAN_ABORTING;
5952
5953 err = ipw_send_scan_abort(priv);
5954 if (err)
5955 IPW_DEBUG_HC("Request to abort scan failed.\n");
5956}
5957
James Ketrenosafbf30a2005-08-25 00:05:33 -05005958static void ipw_add_scan_channels(struct ipw_priv *priv,
5959 struct ipw_scan_request_ext *scan,
5960 int scan_type)
5961{
5962 int channel_index = 0;
5963 const struct ieee80211_geo *geo;
5964 int i;
5965
Liu Hong1fe0adb2005-08-19 09:33:10 -05005966 geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005967
5968 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5969 int start = channel_index;
5970 for (i = 0; i < geo->a_channels; i++) {
5971 if ((priv->status & STATUS_ASSOCIATED) &&
5972 geo->a[i].channel == priv->channel)
5973 continue;
5974 channel_index++;
5975 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005976 ipw_set_scan_type(scan, channel_index,
5977 geo->a[i].
5978 flags & IEEE80211_CH_PASSIVE_ONLY ?
5979 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5980 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005981 }
5982
5983 if (start != channel_index) {
5984 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5985 (channel_index - start);
5986 channel_index++;
5987 }
5988 }
5989
5990 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5991 int start = channel_index;
5992 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005993 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005994 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5995 /* nop out the list */
5996 [0] = 0
5997 };
5998
5999 u8 channel;
6000 while (channel_index < IPW_SCAN_CHANNELS) {
6001 channel =
6002 priv->speed_scan[priv->speed_scan_pos];
6003 if (channel == 0) {
6004 priv->speed_scan_pos = 0;
6005 channel = priv->speed_scan[0];
6006 }
6007 if ((priv->status & STATUS_ASSOCIATED) &&
6008 channel == priv->channel) {
6009 priv->speed_scan_pos++;
6010 continue;
6011 }
6012
6013 /* If this channel has already been
6014 * added in scan, break from loop
6015 * and this will be the first channel
6016 * in the next scan.
6017 */
6018 if (channels[channel - 1] != 0)
6019 break;
6020
6021 channels[channel - 1] = 1;
6022 priv->speed_scan_pos++;
6023 channel_index++;
6024 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006025 index =
6026 ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006027 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006028 geo->bg[index].
6029 flags &
6030 IEEE80211_CH_PASSIVE_ONLY ?
6031 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6032 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006033 }
6034 } else {
6035 for (i = 0; i < geo->bg_channels; i++) {
6036 if ((priv->status & STATUS_ASSOCIATED) &&
6037 geo->bg[i].channel == priv->channel)
6038 continue;
6039 channel_index++;
6040 scan->channels_list[channel_index] =
6041 geo->bg[i].channel;
6042 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006043 geo->bg[i].
6044 flags &
6045 IEEE80211_CH_PASSIVE_ONLY ?
6046 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6047 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006048 }
6049 }
6050
6051 if (start != channel_index) {
6052 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6053 (channel_index - start);
6054 }
6055 }
6056}
6057
James Ketrenosea2b26e2005-08-24 21:25:16 -05006058static int ipw_request_scan(struct ipw_priv *priv)
6059{
6060 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006061 int err = 0, scan_type;
6062
6063 if (!(priv->status & STATUS_INIT) ||
6064 (priv->status & STATUS_EXIT_PENDING))
6065 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006066
Zhu Yi46441512006-01-24 16:37:59 +08006067 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006068
James Ketrenosea2b26e2005-08-24 21:25:16 -05006069 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006070 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006071 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006072 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006073 }
6074
James Ketrenosafbf30a2005-08-25 00:05:33 -05006075 if (!(priv->status & STATUS_SCAN_FORCED) &&
6076 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006077 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6078 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006079 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006080 }
6081
6082 if (priv->status & STATUS_RF_KILL_MASK) {
6083 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6084 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006085 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006086 }
6087
6088 memset(&scan, 0, sizeof(scan));
6089
James Ketrenosb095c382005-08-24 22:04:42 -05006090 if (priv->config & CFG_SPEED_SCAN)
6091 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6092 cpu_to_le16(30);
6093 else
6094 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6095 cpu_to_le16(20);
6096
James Ketrenosa613bff2005-08-24 21:43:11 -05006097 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6098 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006099 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006100
James Ketrenosa613bff2005-08-24 21:43:11 -05006101 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006102
James Ketrenosb095c382005-08-24 22:04:42 -05006103#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006104 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006105 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006106 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006107
Liu Hong1fe0adb2005-08-19 09:33:10 -05006108 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006109 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006110 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006111 channel = priv->channel;
6112 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006113
James Ketrenosb095c382005-08-24 22:04:42 -05006114 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006115 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006116 channel = priv->channel;
6117 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006118
James Ketrenosb095c382005-08-24 22:04:42 -05006119 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006120 band = (u8) (IPW_B_MODE << 6) | 1;
6121 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006122 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006123 }
6124
James Ketrenosb095c382005-08-24 22:04:42 -05006125 scan.channels_list[0] = band;
6126 scan.channels_list[1] = channel;
6127 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006128
James Ketrenosb095c382005-08-24 22:04:42 -05006129 /* NOTE: The card will sit on this channel for this time
6130 * period. Scan aborts are timing sensitive and frequently
6131 * result in firmware restarts. As such, it is best to
6132 * set a small dwell_time here and just keep re-issuing
6133 * scans. Otherwise fast channel hopping will not actually
6134 * hop channels.
6135 *
6136 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006137 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6138 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006139 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006140#endif /* CONFIG_IPW2200_MONITOR */
6141 /* If we are roaming, then make this a directed scan for the
6142 * current network. Otherwise, ensure that every other scan
6143 * is a fast channel hop scan */
6144 if ((priv->status & STATUS_ROAMING)
6145 || (!(priv->status & STATUS_ASSOCIATED)
6146 && (priv->config & CFG_STATIC_ESSID)
6147 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006148 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6149 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006150 IPW_DEBUG_HC("Attempt to send SSID command "
6151 "failed.\n");
6152 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006153 }
6154
6155 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006156 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006157 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006158
James Ketrenosafbf30a2005-08-25 00:05:33 -05006159 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006160#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006161 }
6162#endif
6163
6164 err = ipw_send_scan_request_ext(priv, &scan);
6165 if (err) {
6166 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006167 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006168 }
6169
6170 priv->status |= STATUS_SCANNING;
6171 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006172 queue_delayed_work(priv->workqueue, &priv->scan_check,
6173 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006174 done:
Zhu Yi46441512006-01-24 16:37:59 +08006175 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006176 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006177}
6178
6179static void ipw_bg_abort_scan(void *data)
6180{
6181 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006182 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006183 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006184 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006185}
6186
James Ketrenosea2b26e2005-08-24 21:25:16 -05006187static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6188{
James Ketrenosb095c382005-08-24 22:04:42 -05006189 /* This is called when wpa_supplicant loads and closes the driver
6190 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006191 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006192 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006193}
6194
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6196{
6197 struct ieee80211_device *ieee = priv->ieee;
6198 struct ieee80211_security sec = {
6199 .flags = SEC_AUTH_MODE,
6200 };
6201 int ret = 0;
6202
James Ketrenosafbf30a2005-08-25 00:05:33 -05006203 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006204 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6205 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006206 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006207 sec.auth_mode = WLAN_AUTH_OPEN;
6208 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006209 } else if (value & IW_AUTH_ALG_LEAP) {
6210 sec.auth_mode = WLAN_AUTH_LEAP;
6211 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006212 } else
6213 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006214
6215 if (ieee->set_security)
6216 ieee->set_security(ieee->dev, &sec);
6217 else
6218 ret = -EOPNOTSUPP;
6219
6220 return ret;
6221}
6222
Adrian Bunka73e22b2006-01-21 01:39:42 +01006223static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6224 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006225{
6226 /* make sure WPA is enabled */
6227 ipw_wpa_enable(priv, 1);
6228
6229 ipw_disassociate(priv);
6230}
6231
6232static int ipw_set_rsn_capa(struct ipw_priv *priv,
6233 char *capabilities, int length)
6234{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006235 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6236
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006237 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006238 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006239}
6240
James Ketrenosafbf30a2005-08-25 00:05:33 -05006241/*
6242 * WE-18 support
6243 */
6244
6245/* SIOCSIWGENIE */
6246static int ipw_wx_set_genie(struct net_device *dev,
6247 struct iw_request_info *info,
6248 union iwreq_data *wrqu, char *extra)
6249{
6250 struct ipw_priv *priv = ieee80211_priv(dev);
6251 struct ieee80211_device *ieee = priv->ieee;
6252 u8 *buf;
6253 int err = 0;
6254
6255 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6256 (wrqu->data.length && extra == NULL))
6257 return -EINVAL;
6258
Zhu Yi46441512006-01-24 16:37:59 +08006259 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006260
6261 //if (!ieee->wpa_enabled) {
6262 // err = -EOPNOTSUPP;
6263 // goto out;
6264 //}
6265
6266 if (wrqu->data.length) {
6267 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6268 if (buf == NULL) {
6269 err = -ENOMEM;
6270 goto out;
6271 }
6272
6273 memcpy(buf, extra, wrqu->data.length);
6274 kfree(ieee->wpa_ie);
6275 ieee->wpa_ie = buf;
6276 ieee->wpa_ie_len = wrqu->data.length;
6277 } else {
6278 kfree(ieee->wpa_ie);
6279 ieee->wpa_ie = NULL;
6280 ieee->wpa_ie_len = 0;
6281 }
6282
6283 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6284 out:
Zhu Yi46441512006-01-24 16:37:59 +08006285 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006286 return err;
6287}
6288
6289/* SIOCGIWGENIE */
6290static int ipw_wx_get_genie(struct net_device *dev,
6291 struct iw_request_info *info,
6292 union iwreq_data *wrqu, char *extra)
6293{
6294 struct ipw_priv *priv = ieee80211_priv(dev);
6295 struct ieee80211_device *ieee = priv->ieee;
6296 int err = 0;
6297
Zhu Yi46441512006-01-24 16:37:59 +08006298 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006299
6300 //if (!ieee->wpa_enabled) {
6301 // err = -EOPNOTSUPP;
6302 // goto out;
6303 //}
6304
6305 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6306 wrqu->data.length = 0;
6307 goto out;
6308 }
6309
6310 if (wrqu->data.length < ieee->wpa_ie_len) {
6311 err = -E2BIG;
6312 goto out;
6313 }
6314
6315 wrqu->data.length = ieee->wpa_ie_len;
6316 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6317
6318 out:
Zhu Yi46441512006-01-24 16:37:59 +08006319 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006320 return err;
6321}
6322
Zhu Yi1fbfea52005-08-05 17:22:56 +08006323static int wext_cipher2level(int cipher)
6324{
6325 switch (cipher) {
6326 case IW_AUTH_CIPHER_NONE:
6327 return SEC_LEVEL_0;
6328 case IW_AUTH_CIPHER_WEP40:
6329 case IW_AUTH_CIPHER_WEP104:
6330 return SEC_LEVEL_1;
6331 case IW_AUTH_CIPHER_TKIP:
6332 return SEC_LEVEL_2;
6333 case IW_AUTH_CIPHER_CCMP:
6334 return SEC_LEVEL_3;
6335 default:
6336 return -1;
6337 }
6338}
6339
James Ketrenosafbf30a2005-08-25 00:05:33 -05006340/* SIOCSIWAUTH */
6341static int ipw_wx_set_auth(struct net_device *dev,
6342 struct iw_request_info *info,
6343 union iwreq_data *wrqu, char *extra)
6344{
6345 struct ipw_priv *priv = ieee80211_priv(dev);
6346 struct ieee80211_device *ieee = priv->ieee;
6347 struct iw_param *param = &wrqu->param;
6348 struct ieee80211_crypt_data *crypt;
6349 unsigned long flags;
6350 int ret = 0;
6351
6352 switch (param->flags & IW_AUTH_INDEX) {
6353 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006354 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006355 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006356 ipw_set_hw_decrypt_unicast(priv,
6357 wext_cipher2level(param->value));
6358 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006359 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006360 ipw_set_hw_decrypt_multicast(priv,
6361 wext_cipher2level(param->value));
6362 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006363 case IW_AUTH_KEY_MGMT:
6364 /*
6365 * ipw2200 does not use these parameters
6366 */
6367 break;
6368
6369 case IW_AUTH_TKIP_COUNTERMEASURES:
6370 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006371 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006372 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006373
6374 flags = crypt->ops->get_flags(crypt->priv);
6375
6376 if (param->value)
6377 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6378 else
6379 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6380
6381 crypt->ops->set_flags(flags, crypt->priv);
6382
6383 break;
6384
6385 case IW_AUTH_DROP_UNENCRYPTED:{
6386 /* HACK:
6387 *
6388 * wpa_supplicant calls set_wpa_enabled when the driver
6389 * is loaded and unloaded, regardless of if WPA is being
6390 * used. No other calls are made which can be used to
6391 * determine if encryption will be used or not prior to
6392 * association being expected. If encryption is not being
6393 * used, drop_unencrypted is set to false, else true -- we
6394 * can use this to determine if the CAP_PRIVACY_ON bit should
6395 * be set.
6396 */
6397 struct ieee80211_security sec = {
6398 .flags = SEC_ENABLED,
6399 .enabled = param->value,
6400 };
6401 priv->ieee->drop_unencrypted = param->value;
6402 /* We only change SEC_LEVEL for open mode. Others
6403 * are set by ipw_wpa_set_encryption.
6404 */
6405 if (!param->value) {
6406 sec.flags |= SEC_LEVEL;
6407 sec.level = SEC_LEVEL_0;
6408 } else {
6409 sec.flags |= SEC_LEVEL;
6410 sec.level = SEC_LEVEL_1;
6411 }
6412 if (priv->ieee->set_security)
6413 priv->ieee->set_security(priv->ieee->dev, &sec);
6414 break;
6415 }
6416
6417 case IW_AUTH_80211_AUTH_ALG:
6418 ret = ipw_wpa_set_auth_algs(priv, param->value);
6419 break;
6420
6421 case IW_AUTH_WPA_ENABLED:
6422 ret = ipw_wpa_enable(priv, param->value);
6423 break;
6424
6425 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6426 ieee->ieee802_1x = param->value;
6427 break;
6428
6429 //case IW_AUTH_ROAMING_CONTROL:
6430 case IW_AUTH_PRIVACY_INVOKED:
6431 ieee->privacy_invoked = param->value;
6432 break;
6433
6434 default:
6435 return -EOPNOTSUPP;
6436 }
6437 return ret;
6438}
6439
6440/* SIOCGIWAUTH */
6441static int ipw_wx_get_auth(struct net_device *dev,
6442 struct iw_request_info *info,
6443 union iwreq_data *wrqu, char *extra)
6444{
6445 struct ipw_priv *priv = ieee80211_priv(dev);
6446 struct ieee80211_device *ieee = priv->ieee;
6447 struct ieee80211_crypt_data *crypt;
6448 struct iw_param *param = &wrqu->param;
6449 int ret = 0;
6450
6451 switch (param->flags & IW_AUTH_INDEX) {
6452 case IW_AUTH_WPA_VERSION:
6453 case IW_AUTH_CIPHER_PAIRWISE:
6454 case IW_AUTH_CIPHER_GROUP:
6455 case IW_AUTH_KEY_MGMT:
6456 /*
6457 * wpa_supplicant will control these internally
6458 */
6459 ret = -EOPNOTSUPP;
6460 break;
6461
6462 case IW_AUTH_TKIP_COUNTERMEASURES:
6463 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006464 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006465 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006466
6467 param->value = (crypt->ops->get_flags(crypt->priv) &
6468 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6469
6470 break;
6471
6472 case IW_AUTH_DROP_UNENCRYPTED:
6473 param->value = ieee->drop_unencrypted;
6474 break;
6475
6476 case IW_AUTH_80211_AUTH_ALG:
6477 param->value = ieee->sec.auth_mode;
6478 break;
6479
6480 case IW_AUTH_WPA_ENABLED:
6481 param->value = ieee->wpa_enabled;
6482 break;
6483
6484 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6485 param->value = ieee->ieee802_1x;
6486 break;
6487
6488 case IW_AUTH_ROAMING_CONTROL:
6489 case IW_AUTH_PRIVACY_INVOKED:
6490 param->value = ieee->privacy_invoked;
6491 break;
6492
6493 default:
6494 return -EOPNOTSUPP;
6495 }
6496 return 0;
6497}
6498
6499/* SIOCSIWENCODEEXT */
6500static int ipw_wx_set_encodeext(struct net_device *dev,
6501 struct iw_request_info *info,
6502 union iwreq_data *wrqu, char *extra)
6503{
6504 struct ipw_priv *priv = ieee80211_priv(dev);
6505 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6506
6507 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006508 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006509 /* IPW HW can't build TKIP MIC,
6510 host decryption still needed */
6511 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6512 priv->ieee->host_mc_decrypt = 1;
6513 else {
6514 priv->ieee->host_encrypt = 0;
6515 priv->ieee->host_encrypt_msdu = 1;
6516 priv->ieee->host_decrypt = 1;
6517 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006518 } else {
6519 priv->ieee->host_encrypt = 0;
6520 priv->ieee->host_encrypt_msdu = 0;
6521 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006522 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006523 }
6524 }
6525
6526 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6527}
6528
6529/* SIOCGIWENCODEEXT */
6530static int ipw_wx_get_encodeext(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 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6536}
6537
6538/* SIOCSIWMLME */
6539static int ipw_wx_set_mlme(struct net_device *dev,
6540 struct iw_request_info *info,
6541 union iwreq_data *wrqu, char *extra)
6542{
6543 struct ipw_priv *priv = ieee80211_priv(dev);
6544 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6545 u16 reason;
6546
6547 reason = cpu_to_le16(mlme->reason_code);
6548
6549 switch (mlme->cmd) {
6550 case IW_MLME_DEAUTH:
6551 // silently ignore
6552 break;
6553
6554 case IW_MLME_DISASSOC:
6555 ipw_disassociate(priv);
6556 break;
6557
6558 default:
6559 return -EOPNOTSUPP;
6560 }
6561 return 0;
6562}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006563
James Ketrenosb095c382005-08-24 22:04:42 -05006564#ifdef CONFIG_IPW_QOS
6565
6566/* QoS */
6567/*
6568* get the modulation type of the current network or
6569* the card current mode
6570*/
6571u8 ipw_qos_current_mode(struct ipw_priv * priv)
6572{
6573 u8 mode = 0;
6574
6575 if (priv->status & STATUS_ASSOCIATED) {
6576 unsigned long flags;
6577
6578 spin_lock_irqsave(&priv->ieee->lock, flags);
6579 mode = priv->assoc_network->mode;
6580 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6581 } else {
6582 mode = priv->ieee->mode;
6583 }
6584 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6585 return mode;
6586}
6587
6588/*
6589* Handle management frame beacon and probe response
6590*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006591static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6592 int active_network,
6593 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006594{
6595 u32 size = sizeof(struct ieee80211_qos_parameters);
6596
James Ketrenosafbf30a2005-08-25 00:05:33 -05006597 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006598 network->qos_data.active = network->qos_data.supported;
6599
6600 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006601 if (active_network &&
6602 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006603 network->qos_data.active = network->qos_data.supported;
6604
6605 if ((network->qos_data.active == 1) && (active_network == 1) &&
6606 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6607 (network->qos_data.old_param_count !=
6608 network->qos_data.param_count)) {
6609 network->qos_data.old_param_count =
6610 network->qos_data.param_count;
6611 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 IPW_DEBUG_QOS("QoS parameters change call "
6613 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006614 }
6615 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006616 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6617 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006618 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 else
6620 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006621 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006622
James Ketrenosb095c382005-08-24 22:04:42 -05006623 if ((network->qos_data.active == 1) && (active_network == 1)) {
6624 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6625 schedule_work(&priv->qos_activate);
6626 }
6627
6628 network->qos_data.active = 0;
6629 network->qos_data.supported = 0;
6630 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006631 if ((priv->status & STATUS_ASSOCIATED) &&
6632 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6633 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6634 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6635 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006636 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006637 priv->assoc_network->ssid_len) &&
6638 !memcmp(network->ssid,
6639 priv->assoc_network->ssid,
6640 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006641 queue_work(priv->workqueue,
6642 &priv->merge_networks);
6643 }
James Ketrenosb095c382005-08-24 22:04:42 -05006644 }
6645
6646 return 0;
6647}
6648
6649/*
6650* This function set up the firmware to support QoS. It sends
6651* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6652*/
6653static int ipw_qos_activate(struct ipw_priv *priv,
6654 struct ieee80211_qos_data *qos_network_data)
6655{
6656 int err;
6657 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6658 struct ieee80211_qos_parameters *active_one = NULL;
6659 u32 size = sizeof(struct ieee80211_qos_parameters);
6660 u32 burst_duration;
6661 int i;
6662 u8 type;
6663
6664 type = ipw_qos_current_mode(priv);
6665
6666 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6667 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6668 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6669 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6670
6671 if (qos_network_data == NULL) {
6672 if (type == IEEE_B) {
6673 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6674 active_one = &def_parameters_CCK;
6675 } else
6676 active_one = &def_parameters_OFDM;
6677
James Ketrenosafbf30a2005-08-25 00:05:33 -05006678 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006679 burst_duration = ipw_qos_get_burst_duration(priv);
6680 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006681 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6682 (u16) burst_duration;
6683 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006684 if (type == IEEE_B) {
6685 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6686 type);
6687 if (priv->qos_data.qos_enable == 0)
6688 active_one = &def_parameters_CCK;
6689 else
6690 active_one = priv->qos_data.def_qos_parm_CCK;
6691 } else {
6692 if (priv->qos_data.qos_enable == 0)
6693 active_one = &def_parameters_OFDM;
6694 else
6695 active_one = priv->qos_data.def_qos_parm_OFDM;
6696 }
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 } else {
6699 unsigned long flags;
6700 int active;
6701
6702 spin_lock_irqsave(&priv->ieee->lock, flags);
6703 active_one = &(qos_network_data->parameters);
6704 qos_network_data->old_param_count =
6705 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006706 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006707 active = qos_network_data->supported;
6708 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6709
6710 if (active == 0) {
6711 burst_duration = ipw_qos_get_burst_duration(priv);
6712 for (i = 0; i < QOS_QUEUE_NUM; i++)
6713 qos_parameters[QOS_PARAM_SET_ACTIVE].
6714 tx_op_limit[i] = (u16) burst_duration;
6715 }
6716 }
6717
6718 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006719 err = ipw_send_qos_params_command(priv,
6720 (struct ieee80211_qos_parameters *)
6721 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006722 if (err)
6723 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6724
6725 return err;
6726}
6727
6728/*
6729* send IPW_CMD_WME_INFO to the firmware
6730*/
6731static int ipw_qos_set_info_element(struct ipw_priv *priv)
6732{
6733 int ret = 0;
6734 struct ieee80211_qos_information_element qos_info;
6735
6736 if (priv == NULL)
6737 return -1;
6738
6739 qos_info.elementID = QOS_ELEMENT_ID;
6740 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6741
6742 qos_info.version = QOS_VERSION_1;
6743 qos_info.ac_info = 0;
6744
6745 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6746 qos_info.qui_type = QOS_OUI_TYPE;
6747 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6748
6749 ret = ipw_send_qos_info_command(priv, &qos_info);
6750 if (ret != 0) {
6751 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6752 }
6753 return ret;
6754}
6755
6756/*
6757* Set the QoS parameter with the association request structure
6758*/
6759static int ipw_qos_association(struct ipw_priv *priv,
6760 struct ieee80211_network *network)
6761{
6762 int err = 0;
6763 struct ieee80211_qos_data *qos_data = NULL;
6764 struct ieee80211_qos_data ibss_data = {
6765 .supported = 1,
6766 .active = 1,
6767 };
6768
6769 switch (priv->ieee->iw_mode) {
6770 case IW_MODE_ADHOC:
6771 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6772 BUG();
6773
6774 qos_data = &ibss_data;
6775 break;
6776
6777 case IW_MODE_INFRA:
6778 qos_data = &network->qos_data;
6779 break;
6780
6781 default:
6782 BUG();
6783 break;
6784 }
6785
6786 err = ipw_qos_activate(priv, qos_data);
6787 if (err) {
6788 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6789 return err;
6790 }
6791
6792 if (priv->qos_data.qos_enable && qos_data->supported) {
6793 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6794 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6795 return ipw_qos_set_info_element(priv);
6796 }
6797
6798 return 0;
6799}
6800
6801/*
6802* handling the beaconing responces. if we get different QoS setting
6803* of the network from the the associated setting adjust the QoS
6804* setting
6805*/
6806static int ipw_qos_association_resp(struct ipw_priv *priv,
6807 struct ieee80211_network *network)
6808{
6809 int ret = 0;
6810 unsigned long flags;
6811 u32 size = sizeof(struct ieee80211_qos_parameters);
6812 int set_qos_param = 0;
6813
James Ketrenosafbf30a2005-08-25 00:05:33 -05006814 if ((priv == NULL) || (network == NULL) ||
6815 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006816 return ret;
6817
6818 if (!(priv->status & STATUS_ASSOCIATED))
6819 return ret;
6820
James Ketrenosafbf30a2005-08-25 00:05:33 -05006821 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006822 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006823
6824 spin_lock_irqsave(&priv->ieee->lock, flags);
6825 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006826 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006827 sizeof(struct ieee80211_qos_data));
6828 priv->assoc_network->qos_data.active = 1;
6829 if ((network->qos_data.old_param_count !=
6830 network->qos_data.param_count)) {
6831 set_qos_param = 1;
6832 network->qos_data.old_param_count =
6833 network->qos_data.param_count;
6834 }
6835
6836 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006837 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6838 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006839 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006840 else
6841 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006842 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006843 priv->assoc_network->qos_data.active = 0;
6844 priv->assoc_network->qos_data.supported = 0;
6845 set_qos_param = 1;
6846 }
6847
6848 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6849
6850 if (set_qos_param == 1)
6851 schedule_work(&priv->qos_activate);
6852
6853 return ret;
6854}
6855
6856static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6857{
6858 u32 ret = 0;
6859
6860 if ((priv == NULL))
6861 return 0;
6862
James Ketrenosafbf30a2005-08-25 00:05:33 -05006863 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006864 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006865 else
James Ketrenosb095c382005-08-24 22:04:42 -05006866 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006867
James Ketrenosb095c382005-08-24 22:04:42 -05006868 return ret;
6869}
6870
6871/*
6872* Initialize the setting of QoS global
6873*/
6874static void ipw_qos_init(struct ipw_priv *priv, int enable,
6875 int burst_enable, u32 burst_duration_CCK,
6876 u32 burst_duration_OFDM)
6877{
6878 priv->qos_data.qos_enable = enable;
6879
6880 if (priv->qos_data.qos_enable) {
6881 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6882 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6883 IPW_DEBUG_QOS("QoS is enabled\n");
6884 } else {
6885 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6886 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6887 IPW_DEBUG_QOS("QoS is not enabled\n");
6888 }
6889
6890 priv->qos_data.burst_enable = burst_enable;
6891
6892 if (burst_enable) {
6893 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6894 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6895 } else {
6896 priv->qos_data.burst_duration_CCK = 0;
6897 priv->qos_data.burst_duration_OFDM = 0;
6898 }
6899}
6900
6901/*
6902* map the packet priority to the right TX Queue
6903*/
6904static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6905{
6906 if (priority > 7 || !priv->qos_data.qos_enable)
6907 priority = 0;
6908
6909 return from_priority_to_tx_queue[priority] - 1;
6910}
6911
6912/*
6913* add QoS parameter to the TX command
6914*/
6915static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6916 u16 priority,
6917 struct tfd_data *tfd, u8 unicast)
6918{
6919 int ret = 0;
6920 int tx_queue_id = 0;
6921 struct ieee80211_qos_data *qos_data = NULL;
6922 int active, supported;
6923 unsigned long flags;
6924
6925 if (!(priv->status & STATUS_ASSOCIATED))
6926 return 0;
6927
6928 qos_data = &priv->assoc_network->qos_data;
6929
6930 spin_lock_irqsave(&priv->ieee->lock, flags);
6931
6932 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6933 if (unicast == 0)
6934 qos_data->active = 0;
6935 else
6936 qos_data->active = qos_data->supported;
6937 }
6938
6939 active = qos_data->active;
6940 supported = qos_data->supported;
6941
6942 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6943
James Ketrenosafbf30a2005-08-25 00:05:33 -05006944 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6945 "unicast %d\n",
6946 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05006947 if (active && priv->qos_data.qos_enable) {
6948 ret = from_priority_to_tx_queue[priority];
6949 tx_queue_id = ret - 1;
6950 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6951 if (priority <= 7) {
6952 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6953 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6954 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6955 IEEE80211_STYPE_QOS_DATA;
6956
6957 if (priv->qos_data.qos_no_ack_mask &
6958 (1UL << tx_queue_id)) {
6959 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6960 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6961 CTRL_QOS_NO_ACK;
6962 }
6963 }
6964 }
6965
6966 return ret;
6967}
6968
6969/*
6970* background support to run QoS activate functionality
6971*/
6972static void ipw_bg_qos_activate(void *data)
6973{
6974 struct ipw_priv *priv = data;
6975
6976 if (priv == NULL)
6977 return;
6978
Zhu Yi46441512006-01-24 16:37:59 +08006979 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006980
6981 if (priv->status & STATUS_ASSOCIATED)
6982 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6983
Zhu Yi46441512006-01-24 16:37:59 +08006984 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006985}
6986
James Ketrenos3b9990c2005-08-19 13:18:55 -05006987static int ipw_handle_probe_response(struct net_device *dev,
6988 struct ieee80211_probe_response *resp,
6989 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006990{
6991 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05006992 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6993 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05006994
James Ketrenos3b9990c2005-08-19 13:18:55 -05006995 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05006996
James Ketrenos3b9990c2005-08-19 13:18:55 -05006997 return 0;
6998}
James Ketrenosb095c382005-08-24 22:04:42 -05006999
James Ketrenos3b9990c2005-08-19 13:18:55 -05007000static int ipw_handle_beacon(struct net_device *dev,
7001 struct ieee80211_beacon *resp,
7002 struct ieee80211_network *network)
7003{
7004 struct ipw_priv *priv = ieee80211_priv(dev);
7005 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7006 (network == priv->assoc_network));
7007
7008 ipw_qos_handle_probe_response(priv, active_network, network);
7009
7010 return 0;
7011}
7012
7013static int ipw_handle_assoc_response(struct net_device *dev,
7014 struct ieee80211_assoc_response *resp,
7015 struct ieee80211_network *network)
7016{
7017 struct ipw_priv *priv = ieee80211_priv(dev);
7018 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007019 return 0;
7020}
7021
7022static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7023 *qos_param)
7024{
Zhu Yi4e226992006-01-24 16:37:36 +08007025 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7026 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007027}
7028
7029static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7030 *qos_param)
7031{
Zhu Yi4e226992006-01-24 16:37:36 +08007032 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7033 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007034}
7035
7036#endif /* CONFIG_IPW_QOS */
7037
James Ketrenos43f66a62005-03-25 12:31:53 -06007038static int ipw_associate_network(struct ipw_priv *priv,
7039 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007040 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007041{
7042 int err;
7043
7044 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007045 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007046
7047 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007048 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007049 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007050 memcpy(priv->essid, network->ssid, priv->essid_len);
7051 }
7052
7053 network->last_associate = jiffies;
7054
7055 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7056 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007057 priv->assoc_request.auth_key = 0;
7058
James Ketrenos43f66a62005-03-25 12:31:53 -06007059 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007060 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007061 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007062 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7063
Zhu Yi3e234b42006-01-24 16:36:52 +08007064 if ((priv->ieee->sec.level == SEC_LEVEL_1) &&
James Ketrenosb095c382005-08-24 22:04:42 -05007065 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7066 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007067
7068 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7069 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7070 priv->assoc_request.auth_type = AUTH_LEAP;
7071 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007072 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007073
James Ketrenosa613bff2005-08-24 21:43:11 -05007074 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007075 priv->assoc_request.policy_support = 0x02; /* RSN active */
7076 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7077 priv->ieee->wpa_ie_len);
7078 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007079
Jeff Garzikbf794512005-07-31 13:07:26 -04007080 /*
7081 * It is valid for our ieee device to support multiple modes, but
7082 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007083 * just one mode.
7084 */
7085 if (network->mode & priv->ieee->mode & IEEE_A)
7086 priv->assoc_request.ieee_mode = IPW_A_MODE;
7087 else if (network->mode & priv->ieee->mode & IEEE_G)
7088 priv->assoc_request.ieee_mode = IPW_G_MODE;
7089 else if (network->mode & priv->ieee->mode & IEEE_B)
7090 priv->assoc_request.ieee_mode = IPW_B_MODE;
7091
James Ketrenosea2b26e2005-08-24 21:25:16 -05007092 priv->assoc_request.capability = network->capability;
7093 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7094 && !(priv->config & CFG_PREAMBLE_LONG)) {
7095 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7096 } else {
7097 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7098
7099 /* Clear the short preamble if we won't be supporting it */
7100 priv->assoc_request.capability &=
7101 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7102 }
7103
James Ketrenosafbf30a2005-08-25 00:05:33 -05007104 /* Clear capability bits that aren't used in Ad Hoc */
7105 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7106 priv->assoc_request.capability &=
7107 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7108
James Ketrenos43f66a62005-03-25 12:31:53 -06007109 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007110 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007111 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007112 escape_essid(priv->essid, priv->essid_len),
7113 network->channel,
7114 ipw_modes[priv->assoc_request.ieee_mode],
7115 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007116 (priv->assoc_request.preamble_length ==
7117 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7118 network->capability &
7119 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007120 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007121 priv->capability & CAP_PRIVACY_ON ?
7122 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007123 "(open)") : "",
7124 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007125 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007126 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007127 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007128
7129 priv->assoc_request.beacon_interval = network->beacon_interval;
7130 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007131 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007132 priv->assoc_request.assoc_type = HC_IBSS_START;
7133 priv->assoc_request.assoc_tsf_msw = 0;
7134 priv->assoc_request.assoc_tsf_lsw = 0;
7135 } else {
7136 if (unlikely(roaming))
7137 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7138 else
7139 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7140 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7141 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7142 }
7143
James Ketrenosafbf30a2005-08-25 00:05:33 -05007144 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007145
7146 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7147 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7148 priv->assoc_request.atim_window = network->atim_window;
7149 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007150 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007151 priv->assoc_request.atim_window = 0;
7152 }
7153
James Ketrenos43f66a62005-03-25 12:31:53 -06007154 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007155
James Ketrenos43f66a62005-03-25 12:31:53 -06007156 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7157 if (err) {
7158 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7159 return err;
7160 }
7161
7162 rates->ieee_mode = priv->assoc_request.ieee_mode;
7163 rates->purpose = IPW_RATE_CONNECT;
7164 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007165
James Ketrenos43f66a62005-03-25 12:31:53 -06007166 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7167 priv->sys_config.dot11g_auto_detection = 1;
7168 else
7169 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007170
7171 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7172 priv->sys_config.answer_broadcast_ssid_probe = 1;
7173 else
7174 priv->sys_config.answer_broadcast_ssid_probe = 0;
7175
James Ketrenos43f66a62005-03-25 12:31:53 -06007176 err = ipw_send_system_config(priv, &priv->sys_config);
7177 if (err) {
7178 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7179 return err;
7180 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007181
James Ketrenos43f66a62005-03-25 12:31:53 -06007182 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007183 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007184 if (err) {
7185 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7186 return err;
7187 }
7188
7189 /*
7190 * If preemption is enabled, it is possible for the association
7191 * to complete before we return from ipw_send_associate. Therefore
7192 * we have to be sure and update our priviate data first.
7193 */
7194 priv->channel = network->channel;
7195 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007196 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007197 priv->status &= ~STATUS_SECURITY_UPDATED;
7198
7199 priv->assoc_network = network;
7200
James Ketrenosb095c382005-08-24 22:04:42 -05007201#ifdef CONFIG_IPW_QOS
7202 ipw_qos_association(priv, network);
7203#endif
7204
James Ketrenos43f66a62005-03-25 12:31:53 -06007205 err = ipw_send_associate(priv, &priv->assoc_request);
7206 if (err) {
7207 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7208 return err;
7209 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007210
7211 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007212 escape_essid(priv->essid, priv->essid_len),
7213 MAC_ARG(priv->bssid));
7214
7215 return 0;
7216}
7217
7218static void ipw_roam(void *data)
7219{
7220 struct ipw_priv *priv = data;
7221 struct ieee80211_network *network = NULL;
7222 struct ipw_network_match match = {
7223 .network = priv->assoc_network
7224 };
7225
7226 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007227 *
7228 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007229 * setting the status ROAM bit and requesting a scan.
7230 * 2. When the scan completes, it schedules the ROAM work
7231 * 3. The ROAM work looks at all of the known networks for one that
7232 * is a better network than the currently associated. If none
7233 * found, the ROAM process is over (ROAM bit cleared)
7234 * 4. If a better network is found, a disassociation request is
7235 * sent.
7236 * 5. When the disassociation completes, the roam work is again
7237 * scheduled. The second time through, the driver is no longer
7238 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007239 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007240 * 6. At this point ,the roaming process is complete and the ROAM
7241 * status bit is cleared.
7242 */
7243
7244 /* If we are no longer associated, and the roaming bit is no longer
7245 * set, then we are not actively roaming, so just return */
7246 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7247 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007248
James Ketrenos43f66a62005-03-25 12:31:53 -06007249 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007250 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007251 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007252 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007253 u8 rssi = priv->assoc_network->stats.rssi;
7254 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007255 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007256 list_for_each_entry(network, &priv->ieee->network_list, list) {
7257 if (network != priv->assoc_network)
7258 ipw_best_network(priv, &match, network, 1);
7259 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007260 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007261 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007262
James Ketrenos43f66a62005-03-25 12:31:53 -06007263 if (match.network == priv->assoc_network) {
7264 IPW_DEBUG_ASSOC("No better APs in this network to "
7265 "roam to.\n");
7266 priv->status &= ~STATUS_ROAMING;
7267 ipw_debug_config(priv);
7268 return;
7269 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007270
James Ketrenos43f66a62005-03-25 12:31:53 -06007271 ipw_send_disassociate(priv, 1);
7272 priv->assoc_network = match.network;
7273
7274 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007275 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007276
7277 /* Second pass through ROAM process -- request association */
7278 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7279 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7280 priv->status &= ~STATUS_ROAMING;
7281}
7282
James Ketrenosc848d0a2005-08-24 21:56:24 -05007283static void ipw_bg_roam(void *data)
7284{
7285 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007286 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007287 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007288 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007289}
7290
7291static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007292{
7293 struct ipw_priv *priv = data;
7294
7295 struct ieee80211_network *network = NULL;
7296 struct ipw_network_match match = {
7297 .network = NULL
7298 };
7299 struct ipw_supported_rates *rates;
7300 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007301 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007302
James Ketrenosb095c382005-08-24 22:04:42 -05007303 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7304 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7305 return 0;
7306 }
7307
James Ketrenosc848d0a2005-08-24 21:56:24 -05007308 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007309 IPW_DEBUG_ASSOC("Not attempting association (already in "
7310 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007311 return 0;
7312 }
7313
Hong Liue6324722005-09-14 21:04:15 -05007314 if (priv->status & STATUS_DISASSOCIATING) {
7315 IPW_DEBUG_ASSOC("Not attempting association (in "
7316 "disassociating)\n ");
7317 queue_work(priv->workqueue, &priv->associate);
7318 return 0;
7319 }
7320
James Ketrenosc848d0a2005-08-24 21:56:24 -05007321 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007322 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7323 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007324 return 0;
7325 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007326
7327 if (!(priv->config & CFG_ASSOCIATE) &&
7328 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007329 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007330 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007331 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007332 }
7333
James Ketrenosa613bff2005-08-24 21:43:11 -05007334 /* Protect our use of the network_list */
7335 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007336 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007337 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007338
7339 network = match.network;
7340 rates = &match.rates;
7341
7342 if (network == NULL &&
7343 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7344 priv->config & CFG_ADHOC_CREATE &&
7345 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007346 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007347 !list_empty(&priv->ieee->network_free_list)) {
7348 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007349 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007350 ipw_adhoc_create(priv, network);
7351 rates = &priv->rates;
7352 list_del(element);
7353 list_add_tail(&network->list, &priv->ieee->network_list);
7354 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007355 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007356
James Ketrenos43f66a62005-03-25 12:31:53 -06007357 /* If we reached the end of the list, then we don't have any valid
7358 * matching APs */
7359 if (!network) {
7360 ipw_debug_config(priv);
7361
James Ketrenosb095c382005-08-24 22:04:42 -05007362 if (!(priv->status & STATUS_SCANNING)) {
7363 if (!(priv->config & CFG_SPEED_SCAN))
7364 queue_delayed_work(priv->workqueue,
7365 &priv->request_scan,
7366 SCAN_INTERVAL);
7367 else
7368 queue_work(priv->workqueue,
7369 &priv->request_scan);
7370 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007371
James Ketrenosc848d0a2005-08-24 21:56:24 -05007372 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007373 }
7374
7375 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007376
7377 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007378}
Jeff Garzikbf794512005-07-31 13:07:26 -04007379
James Ketrenosc848d0a2005-08-24 21:56:24 -05007380static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007381{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007382 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007383 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007384 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007385 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007386}
7387
James Ketrenosb095c382005-08-24 22:04:42 -05007388static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7389 struct sk_buff *skb)
7390{
7391 struct ieee80211_hdr *hdr;
7392 u16 fc;
7393
7394 hdr = (struct ieee80211_hdr *)skb->data;
7395 fc = le16_to_cpu(hdr->frame_ctl);
7396 if (!(fc & IEEE80211_FCTL_PROTECTED))
7397 return;
7398
7399 fc &= ~IEEE80211_FCTL_PROTECTED;
7400 hdr->frame_ctl = cpu_to_le16(fc);
7401 switch (priv->ieee->sec.level) {
7402 case SEC_LEVEL_3:
7403 /* Remove CCMP HDR */
7404 memmove(skb->data + IEEE80211_3ADDR_LEN,
7405 skb->data + IEEE80211_3ADDR_LEN + 8,
7406 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007407 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007408 break;
7409 case SEC_LEVEL_2:
7410 break;
7411 case SEC_LEVEL_1:
7412 /* Remove IV */
7413 memmove(skb->data + IEEE80211_3ADDR_LEN,
7414 skb->data + IEEE80211_3ADDR_LEN + 4,
7415 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007416 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007417 break;
7418 case SEC_LEVEL_0:
7419 break;
7420 default:
7421 printk(KERN_ERR "Unknow security level %d\n",
7422 priv->ieee->sec.level);
7423 break;
7424 }
7425}
7426
7427static void ipw_handle_data_packet(struct ipw_priv *priv,
7428 struct ipw_rx_mem_buffer *rxb,
7429 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007430{
Hong Liu567deaf2005-08-31 18:07:22 +08007431 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007432 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7433
7434 /* We received data from the HW, so stop the watchdog */
7435 priv->net_dev->trans_start = jiffies;
7436
Jeff Garzikbf794512005-07-31 13:07:26 -04007437 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007438 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007439 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007440 skb_tailroom(rxb->skb))) {
7441 priv->ieee->stats.rx_errors++;
7442 priv->wstats.discard.misc++;
7443 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7444 return;
7445 } else if (unlikely(!netif_running(priv->net_dev))) {
7446 priv->ieee->stats.rx_dropped++;
7447 priv->wstats.discard.misc++;
7448 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7449 return;
7450 }
7451
7452 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007453 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007454
7455 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007456 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007457
7458 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7459
James Ketrenosb095c382005-08-24 22:04:42 -05007460 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007461 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7462 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007463 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007464 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007465 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7466
Jeff Garzikbf794512005-07-31 13:07:26 -04007467 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007468 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007469 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007470 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007471 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007472 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007473}
7474
Mike Kershaw24a47db2005-08-26 00:41:54 -05007475#ifdef CONFIG_IEEE80211_RADIOTAP
7476static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7477 struct ipw_rx_mem_buffer *rxb,
7478 struct ieee80211_rx_stats *stats)
7479{
7480 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7481 struct ipw_rx_frame *frame = &pkt->u.frame;
7482
7483 /* initial pull of some data */
7484 u16 received_channel = frame->received_channel;
7485 u8 antennaAndPhy = frame->antennaAndPhy;
7486 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7487 u16 pktrate = frame->rate;
7488
7489 /* Magic struct that slots into the radiotap header -- no reason
7490 * to build this manually element by element, we can write it much
7491 * more efficiently than we can parse it. ORDER MATTERS HERE */
7492 struct ipw_rt_hdr {
7493 struct ieee80211_radiotap_header rt_hdr;
7494 u8 rt_flags; /* radiotap packet flags */
7495 u8 rt_rate; /* rate in 500kb/s */
7496 u16 rt_channel; /* channel in mhz */
7497 u16 rt_chbitmask; /* channel bitfield */
7498 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7499 u8 rt_antenna; /* antenna number */
7500 } *ipw_rt;
7501
7502 short len = le16_to_cpu(pkt->u.frame.length);
7503
7504 /* We received data from the HW, so stop the watchdog */
7505 priv->net_dev->trans_start = jiffies;
7506
7507 /* We only process data packets if the
7508 * interface is open */
7509 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7510 skb_tailroom(rxb->skb))) {
7511 priv->ieee->stats.rx_errors++;
7512 priv->wstats.discard.misc++;
7513 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7514 return;
7515 } else if (unlikely(!netif_running(priv->net_dev))) {
7516 priv->ieee->stats.rx_dropped++;
7517 priv->wstats.discard.misc++;
7518 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7519 return;
7520 }
7521
7522 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7523 * that now */
7524 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7525 /* FIXME: Should alloc bigger skb instead */
7526 priv->ieee->stats.rx_dropped++;
7527 priv->wstats.discard.misc++;
7528 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7529 return;
7530 }
7531
7532 /* copy the frame itself */
7533 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7534 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7535
7536 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7537 * part of our real header, saves a little time.
7538 *
7539 * No longer necessary since we fill in all our data. Purge before merging
7540 * patch officially.
7541 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7542 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7543 */
7544
7545 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7546
7547 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7548 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7549 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7550
7551 /* Big bitfield of all the fields we provide in radiotap */
7552 ipw_rt->rt_hdr.it_present =
7553 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7554 (1 << IEEE80211_RADIOTAP_RATE) |
7555 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7556 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7557 (1 << IEEE80211_RADIOTAP_ANTENNA));
7558
7559 /* Zero the flags, we'll add to them as we go */
7560 ipw_rt->rt_flags = 0;
7561
7562 /* Convert signal to DBM */
7563 ipw_rt->rt_dbmsignal = antsignal;
7564
7565 /* Convert the channel data and set the flags */
7566 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7567 if (received_channel > 14) { /* 802.11a */
7568 ipw_rt->rt_chbitmask =
7569 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7570 } else if (antennaAndPhy & 32) { /* 802.11b */
7571 ipw_rt->rt_chbitmask =
7572 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7573 } else { /* 802.11g */
7574 ipw_rt->rt_chbitmask =
7575 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7576 }
7577
7578 /* set the rate in multiples of 500k/s */
7579 switch (pktrate) {
7580 case IPW_TX_RATE_1MB:
7581 ipw_rt->rt_rate = 2;
7582 break;
7583 case IPW_TX_RATE_2MB:
7584 ipw_rt->rt_rate = 4;
7585 break;
7586 case IPW_TX_RATE_5MB:
7587 ipw_rt->rt_rate = 10;
7588 break;
7589 case IPW_TX_RATE_6MB:
7590 ipw_rt->rt_rate = 12;
7591 break;
7592 case IPW_TX_RATE_9MB:
7593 ipw_rt->rt_rate = 18;
7594 break;
7595 case IPW_TX_RATE_11MB:
7596 ipw_rt->rt_rate = 22;
7597 break;
7598 case IPW_TX_RATE_12MB:
7599 ipw_rt->rt_rate = 24;
7600 break;
7601 case IPW_TX_RATE_18MB:
7602 ipw_rt->rt_rate = 36;
7603 break;
7604 case IPW_TX_RATE_24MB:
7605 ipw_rt->rt_rate = 48;
7606 break;
7607 case IPW_TX_RATE_36MB:
7608 ipw_rt->rt_rate = 72;
7609 break;
7610 case IPW_TX_RATE_48MB:
7611 ipw_rt->rt_rate = 96;
7612 break;
7613 case IPW_TX_RATE_54MB:
7614 ipw_rt->rt_rate = 108;
7615 break;
7616 default:
7617 ipw_rt->rt_rate = 0;
7618 break;
7619 }
7620
7621 /* antenna number */
7622 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7623
7624 /* set the preamble flag if we have it */
7625 if ((antennaAndPhy & 64))
7626 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7627
7628 /* Set the size of the skb to the size of the frame */
7629 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007630
7631 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7632
7633 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7634 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007635 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007636 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007637 /* no LED during capture */
7638 }
7639}
7640#endif
7641
Arjan van de Ven858119e2006-01-14 13:20:43 -08007642static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007643 struct ieee80211_hdr_4addr *header)
7644{
7645 /* Filter incoming packets to determine if they are targetted toward
7646 * this network, discarding packets coming from ourselves */
7647 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007648 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007649 /* packets from our adapter are dropped (echo) */
7650 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7651 return 0;
7652
Peter Jones90700fd2005-08-26 16:51:06 -05007653 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007654 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007655 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007656
7657 /* packets to our adapter go through */
7658 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7659 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007660
Peter Jones90700fd2005-08-26 16:51:06 -05007661 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007662 /* packets from our adapter are dropped (echo) */
7663 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7664 return 0;
7665
Peter Jones90700fd2005-08-26 16:51:06 -05007666 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007667 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007668 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7669
7670 /* packets to our adapter go through */
7671 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7672 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007673 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007674
James Ketrenosea2b26e2005-08-24 21:25:16 -05007675 return 1;
7676}
7677
James Ketrenosafbf30a2005-08-25 00:05:33 -05007678#define IPW_PACKET_RETRY_TIME HZ
7679
Arjan van de Ven858119e2006-01-14 13:20:43 -08007680static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007681 struct ieee80211_hdr_4addr *header)
7682{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007683 u16 sc = le16_to_cpu(header->seq_ctl);
7684 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7685 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7686 u16 *last_seq, *last_frag;
7687 unsigned long *last_time;
7688
7689 switch (priv->ieee->iw_mode) {
7690 case IW_MODE_ADHOC:
7691 {
7692 struct list_head *p;
7693 struct ipw_ibss_seq *entry = NULL;
7694 u8 *mac = header->addr2;
7695 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7696
7697 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7698 entry =
7699 list_entry(p, struct ipw_ibss_seq, list);
7700 if (!memcmp(entry->mac, mac, ETH_ALEN))
7701 break;
7702 }
7703 if (p == &priv->ibss_mac_hash[index]) {
7704 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7705 if (!entry) {
7706 IPW_ERROR
7707 ("Cannot malloc new mac entry\n");
7708 return 0;
7709 }
7710 memcpy(entry->mac, mac, ETH_ALEN);
7711 entry->seq_num = seq;
7712 entry->frag_num = frag;
7713 entry->packet_time = jiffies;
7714 list_add(&entry->list,
7715 &priv->ibss_mac_hash[index]);
7716 return 0;
7717 }
7718 last_seq = &entry->seq_num;
7719 last_frag = &entry->frag_num;
7720 last_time = &entry->packet_time;
7721 break;
7722 }
7723 case IW_MODE_INFRA:
7724 last_seq = &priv->last_seq_num;
7725 last_frag = &priv->last_frag_num;
7726 last_time = &priv->last_packet_time;
7727 break;
7728 default:
7729 return 0;
7730 }
7731 if ((*last_seq == seq) &&
7732 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7733 if (*last_frag == frag)
7734 goto drop;
7735 if (*last_frag + 1 != frag)
7736 /* out-of-order fragment */
7737 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007738 } else
7739 *last_seq = seq;
7740
Zhu Yif57ce7c2005-07-13 12:22:15 -05007741 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007742 *last_time = jiffies;
7743 return 0;
7744
7745 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007746 /* Comment this line now since we observed the card receives
7747 * duplicate packets but the FCTL_RETRY bit is not set in the
7748 * IBSS mode with fragmentation enabled.
7749 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007750 return 1;
7751}
7752
James Ketrenosb095c382005-08-24 22:04:42 -05007753static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7754 struct ipw_rx_mem_buffer *rxb,
7755 struct ieee80211_rx_stats *stats)
7756{
7757 struct sk_buff *skb = rxb->skb;
7758 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7759 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7760 (skb->data + IPW_RX_FRAME_SIZE);
7761
7762 ieee80211_rx_mgt(priv->ieee, header, stats);
7763
7764 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7765 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7766 IEEE80211_STYPE_PROBE_RESP) ||
7767 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7768 IEEE80211_STYPE_BEACON))) {
7769 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7770 ipw_add_station(priv, header->addr2);
7771 }
7772
7773 if (priv->config & CFG_NET_STATS) {
7774 IPW_DEBUG_HC("sending stat packet\n");
7775
7776 /* Set the size of the skb to the size of the full
7777 * ipw header and 802.11 frame */
7778 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7779 IPW_RX_FRAME_SIZE);
7780
7781 /* Advance past the ipw packet header to the 802.11 frame */
7782 skb_pull(skb, IPW_RX_FRAME_SIZE);
7783
7784 /* Push the ieee80211_rx_stats before the 802.11 frame */
7785 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7786
7787 skb->dev = priv->ieee->dev;
7788
7789 /* Point raw at the ieee80211_stats */
7790 skb->mac.raw = skb->data;
7791
7792 skb->pkt_type = PACKET_OTHERHOST;
7793 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7794 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7795 netif_rx(skb);
7796 rxb->skb = NULL;
7797 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007798}
7799
James Ketrenos43f66a62005-03-25 12:31:53 -06007800/*
7801 * Main entry function for recieving a packet with 80211 headers. This
7802 * should be called when ever the FW has notified us that there is a new
7803 * skb in the recieve queue.
7804 */
7805static void ipw_rx(struct ipw_priv *priv)
7806{
7807 struct ipw_rx_mem_buffer *rxb;
7808 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007809 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007810 u32 r, w, i;
7811 u8 network_packet;
7812
James Ketrenosb095c382005-08-24 22:04:42 -05007813 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7814 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007815 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7816
7817 while (i != r) {
7818 rxb = priv->rxq->queue[i];
Brice Goglin0f52bf92005-12-01 01:41:46 -08007819#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06007820 if (unlikely(rxb == NULL)) {
7821 printk(KERN_CRIT "Queue not allocated!\n");
7822 break;
7823 }
7824#endif
7825 priv->rxq->queue[i] = NULL;
7826
7827 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007828 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007829 PCI_DMA_FROMDEVICE);
7830
7831 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7832 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7833 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007834 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007835
7836 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007837 case RX_FRAME_TYPE: /* 802.11 frame */ {
7838 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007839 .rssi =
7840 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007841 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007842 .signal =
7843 le16_to_cpu(pkt->u.frame.signal),
7844 .noise =
7845 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007846 .rate = pkt->u.frame.rate,
7847 .mac_time = jiffies,
7848 .received_channel =
7849 pkt->u.frame.received_channel,
7850 .freq =
7851 (pkt->u.frame.
7852 control & (1 << 0)) ?
7853 IEEE80211_24GHZ_BAND :
7854 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007855 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007856 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007857
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007858 if (stats.rssi != 0)
7859 stats.mask |= IEEE80211_STATMASK_RSSI;
7860 if (stats.signal != 0)
7861 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007862 if (stats.noise != 0)
7863 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007864 if (stats.rate != 0)
7865 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007866
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007867 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007868
James Ketrenosb095c382005-08-24 22:04:42 -05007869#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007870 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007871#ifdef CONFIG_IEEE80211_RADIOTAP
7872 ipw_handle_data_packet_monitor(priv,
7873 rxb,
7874 &stats);
7875#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007876 ipw_handle_data_packet(priv, rxb,
7877 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007878#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007879 break;
7880 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007881#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007882
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007883 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007884 (struct ieee80211_hdr_4addr *)(rxb->skb->
7885 data +
7886 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007887 /* TODO: Check Ad-Hoc dest/source and make sure
7888 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007889 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007890 * frame control of the packet and disregard
7891 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007892
James Ketrenosea2b26e2005-08-24 21:25:16 -05007893 network_packet =
7894 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007895 if (network_packet && priv->assoc_network) {
7896 priv->assoc_network->stats.rssi =
7897 stats.rssi;
7898 average_add(&priv->average_rssi,
7899 stats.rssi);
7900 priv->last_rx_rssi = stats.rssi;
7901 }
7902
7903 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007904 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007905
James Ketrenosa613bff2005-08-24 21:43:11 -05007906 if (le16_to_cpu(pkt->u.frame.length) <
7907 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007908 IPW_DEBUG_DROP
7909 ("Received packet is too small. "
7910 "Dropping.\n");
7911 priv->ieee->stats.rx_errors++;
7912 priv->wstats.discard.misc++;
7913 break;
7914 }
7915
James Ketrenosa613bff2005-08-24 21:43:11 -05007916 switch (WLAN_FC_GET_TYPE
7917 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007918
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007919 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007920 ipw_handle_mgmt_packet(priv, rxb,
7921 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007922 break;
7923
7924 case IEEE80211_FTYPE_CTL:
7925 break;
7926
7927 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007928 if (unlikely(!network_packet ||
7929 is_duplicate_packet(priv,
7930 header)))
7931 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007932 IPW_DEBUG_DROP("Dropping: "
7933 MAC_FMT ", "
7934 MAC_FMT ", "
7935 MAC_FMT "\n",
7936 MAC_ARG(header->
7937 addr1),
7938 MAC_ARG(header->
7939 addr2),
7940 MAC_ARG(header->
7941 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05007942 break;
7943 }
7944
7945 ipw_handle_data_packet(priv, rxb,
7946 &stats);
7947
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007948 break;
7949 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007950 break;
7951 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007952
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007953 case RX_HOST_NOTIFICATION_TYPE:{
7954 IPW_DEBUG_RX
7955 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007956 pkt->u.notification.subtype,
7957 pkt->u.notification.flags,
7958 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007959 ipw_rx_notification(priv, &pkt->u.notification);
7960 break;
7961 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007962
7963 default:
7964 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7965 pkt->header.message_type);
7966 break;
7967 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007968
7969 /* For now we just don't re-use anything. We can tweak this
7970 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06007971 * fail to Rx correctly */
7972 if (rxb->skb != NULL) {
7973 dev_kfree_skb_any(rxb->skb);
7974 rxb->skb = NULL;
7975 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007976
James Ketrenos43f66a62005-03-25 12:31:53 -06007977 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007978 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007979 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04007980
James Ketrenos43f66a62005-03-25 12:31:53 -06007981 i = (i + 1) % RX_QUEUE_SIZE;
7982 }
7983
7984 /* Backtrack one entry */
7985 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7986
7987 ipw_rx_queue_restock(priv);
7988}
7989
James Ketrenosafbf30a2005-08-25 00:05:33 -05007990#define DEFAULT_RTS_THRESHOLD 2304U
7991#define MIN_RTS_THRESHOLD 1U
7992#define MAX_RTS_THRESHOLD 2304U
7993#define DEFAULT_BEACON_INTERVAL 100U
7994#define DEFAULT_SHORT_RETRY_LIMIT 7U
7995#define DEFAULT_LONG_RETRY_LIMIT 4U
7996
7997static int ipw_sw_reset(struct ipw_priv *priv, int init)
James Ketrenos43f66a62005-03-25 12:31:53 -06007998{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007999 int band, modulation;
8000 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008001
James Ketrenosafbf30a2005-08-25 00:05:33 -05008002 /* Initialize module parameter values here */
8003 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008004
James Ketrenosafbf30a2005-08-25 00:05:33 -05008005 /* We default to disabling the LED code as right now it causes
8006 * too many systems to lock up... */
8007 if (!led)
8008 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008009
James Ketrenosafbf30a2005-08-25 00:05:33 -05008010 if (associate)
8011 priv->config |= CFG_ASSOCIATE;
8012 else
8013 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008014
James Ketrenosafbf30a2005-08-25 00:05:33 -05008015 if (auto_create)
8016 priv->config |= CFG_ADHOC_CREATE;
8017 else
8018 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8019
Zhu Yi17ed0812006-01-24 16:36:31 +08008020 priv->config &= ~CFG_STATIC_ESSID;
8021 priv->essid_len = 0;
8022 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8023
James Ketrenosafbf30a2005-08-25 00:05:33 -05008024 if (disable) {
8025 priv->status |= STATUS_RF_KILL_SW;
8026 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008027 }
8028
James Ketrenosafbf30a2005-08-25 00:05:33 -05008029 if (channel != 0) {
8030 priv->config |= CFG_STATIC_CHANNEL;
8031 priv->channel = channel;
8032 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8033 /* TODO: Validate that provided channel is in range */
8034 }
8035#ifdef CONFIG_IPW_QOS
8036 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8037 burst_duration_CCK, burst_duration_OFDM);
8038#endif /* CONFIG_IPW_QOS */
8039
8040 switch (mode) {
8041 case 1:
8042 priv->ieee->iw_mode = IW_MODE_ADHOC;
8043 priv->net_dev->type = ARPHRD_ETHER;
8044
8045 break;
8046#ifdef CONFIG_IPW2200_MONITOR
8047 case 2:
8048 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008049#ifdef CONFIG_IEEE80211_RADIOTAP
8050 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8051#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008052 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008053#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008054 break;
8055#endif
8056 default:
8057 case 0:
8058 priv->net_dev->type = ARPHRD_ETHER;
8059 priv->ieee->iw_mode = IW_MODE_INFRA;
8060 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008061 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008062
James Ketrenosafbf30a2005-08-25 00:05:33 -05008063 if (hwcrypto) {
8064 priv->ieee->host_encrypt = 0;
8065 priv->ieee->host_encrypt_msdu = 0;
8066 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008067 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008068 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008069 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008070
Zhu Yie402c932005-08-05 17:20:40 +08008071 /* IPW2200/2915 is abled to do hardware fragmentation. */
8072 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008073
James Ketrenosafbf30a2005-08-25 00:05:33 -05008074 if ((priv->pci_dev->device == 0x4223) ||
8075 (priv->pci_dev->device == 0x4224)) {
8076 if (init)
8077 printk(KERN_INFO DRV_NAME
8078 ": Detected Intel PRO/Wireless 2915ABG Network "
8079 "Connection\n");
8080 priv->ieee->abg_true = 1;
8081 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8082 modulation = IEEE80211_OFDM_MODULATION |
8083 IEEE80211_CCK_MODULATION;
8084 priv->adapter = IPW_2915ABG;
8085 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008086 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008087 if (init)
8088 printk(KERN_INFO DRV_NAME
8089 ": Detected Intel PRO/Wireless 2200BG Network "
8090 "Connection\n");
8091
8092 priv->ieee->abg_true = 0;
8093 band = IEEE80211_24GHZ_BAND;
8094 modulation = IEEE80211_OFDM_MODULATION |
8095 IEEE80211_CCK_MODULATION;
8096 priv->adapter = IPW_2200BG;
8097 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008098 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008099
James Ketrenosafbf30a2005-08-25 00:05:33 -05008100 priv->ieee->freq_band = band;
8101 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008102
James Ketrenosafbf30a2005-08-25 00:05:33 -05008103 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008104
James Ketrenosafbf30a2005-08-25 00:05:33 -05008105 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8106 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008107
James Ketrenosafbf30a2005-08-25 00:05:33 -05008108 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8109 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8110 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008111
James Ketrenosafbf30a2005-08-25 00:05:33 -05008112 /* If power management is turned on, default to AC mode */
8113 priv->power_mode = IPW_POWER_AC;
8114 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008115
Zhu Yi0ece35b2005-08-05 17:26:51 +08008116 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008117}
8118
8119/*
8120 * This file defines the Wireless Extension handlers. It does not
8121 * define any methods of hardware manipulation and relies on the
8122 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008123 *
8124 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008125 * function used to poll the hardware vs. making unecessary calls.
8126 *
8127 */
8128
Jeff Garzikbf794512005-07-31 13:07:26 -04008129static int ipw_wx_get_name(struct net_device *dev,
8130 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008131 union iwreq_data *wrqu, char *extra)
8132{
8133 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008134 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008135 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008136 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008137 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008138 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008139 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008140 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8141 ipw_modes[priv->assoc_request.ieee_mode]);
8142 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008143 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008144 return 0;
8145}
8146
8147static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8148{
8149 if (channel == 0) {
8150 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8151 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008152 IPW_DEBUG_ASSOC("Attempting to associate with new "
8153 "parameters.\n");
8154 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008155 return 0;
8156 }
8157
8158 priv->config |= CFG_STATIC_CHANNEL;
8159
8160 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008161 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8162 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008163 return 0;
8164 }
8165
8166 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8167 priv->channel = channel;
8168
James Ketrenosb095c382005-08-24 22:04:42 -05008169#ifdef CONFIG_IPW2200_MONITOR
8170 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008171 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008172 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008173 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008174 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008175 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008176 }
8177
8178 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8179 udelay(10);
8180
8181 if (priv->status & STATUS_SCANNING)
8182 IPW_DEBUG_SCAN("Still scanning...\n");
8183 else
8184 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8185 1000 - i);
8186
8187 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008188 }
James Ketrenosb095c382005-08-24 22:04:42 -05008189#endif /* CONFIG_IPW2200_MONITOR */
8190
James Ketrenosc848d0a2005-08-24 21:56:24 -05008191 /* Network configuration changed -- force [re]association */
8192 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8193 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008194 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008195
8196 return 0;
8197}
8198
Jeff Garzikbf794512005-07-31 13:07:26 -04008199static int ipw_wx_set_freq(struct net_device *dev,
8200 struct iw_request_info *info,
8201 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008202{
8203 struct ipw_priv *priv = ieee80211_priv(dev);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008204 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008205 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008206 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008207 u8 channel, flags;
8208 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008209
James Ketrenosb095c382005-08-24 22:04:42 -05008210 if (fwrq->m == 0) {
8211 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008212 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008213 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008214 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008215 return ret;
8216 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008217 /* if setting by freq convert to channel */
8218 if (fwrq->e == 1) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05008219 channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008220 if (channel == 0)
8221 return -EINVAL;
8222 } else
8223 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008224
Liu Hong1fe0adb2005-08-19 09:33:10 -05008225 if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008226 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008227
Liu Hong1fe0adb2005-08-19 09:33:10 -05008228 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8229 i = ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008230 if (i == -1)
8231 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008232
8233 flags = (band == IEEE80211_24GHZ_BAND) ?
8234 geo->bg[i].flags : geo->a[i].flags;
8235 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008236 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8237 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008238 }
8239 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008240
James Ketrenos43f66a62005-03-25 12:31:53 -06008241 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008242 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008243 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008244 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008245 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008246}
8247
Jeff Garzikbf794512005-07-31 13:07:26 -04008248static int ipw_wx_get_freq(struct net_device *dev,
8249 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008250 union iwreq_data *wrqu, char *extra)
8251{
8252 struct ipw_priv *priv = ieee80211_priv(dev);
8253
8254 wrqu->freq.e = 0;
8255
8256 /* If we are associated, trying to associate, or have a statically
8257 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008258 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008259 if (priv->config & CFG_STATIC_CHANNEL ||
8260 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8261 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008262 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008263 wrqu->freq.m = 0;
8264
Zhu Yi46441512006-01-24 16:37:59 +08008265 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008266 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8267 return 0;
8268}
8269
Jeff Garzikbf794512005-07-31 13:07:26 -04008270static int ipw_wx_set_mode(struct net_device *dev,
8271 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008272 union iwreq_data *wrqu, char *extra)
8273{
8274 struct ipw_priv *priv = ieee80211_priv(dev);
8275 int err = 0;
8276
8277 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8278
James Ketrenos43f66a62005-03-25 12:31:53 -06008279 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008280#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008281 case IW_MODE_MONITOR:
8282#endif
8283 case IW_MODE_ADHOC:
8284 case IW_MODE_INFRA:
8285 break;
8286 case IW_MODE_AUTO:
8287 wrqu->mode = IW_MODE_INFRA;
8288 break;
8289 default:
8290 return -EINVAL;
8291 }
James Ketrenosb095c382005-08-24 22:04:42 -05008292 if (wrqu->mode == priv->ieee->iw_mode)
8293 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008294
Zhu Yi46441512006-01-24 16:37:59 +08008295 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008296
8297 ipw_sw_reset(priv, 0);
8298
James Ketrenosb095c382005-08-24 22:04:42 -05008299#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008300 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008301 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008302
8303 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008304#ifdef CONFIG_IEEE80211_RADIOTAP
8305 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8306#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008307 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008308#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008309#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008310
Jeff Garzikbf794512005-07-31 13:07:26 -04008311 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008312 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008313 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008314
8315 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008316
James Ketrenosc848d0a2005-08-24 21:56:24 -05008317 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008318 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008319 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008320}
8321
Jeff Garzikbf794512005-07-31 13:07:26 -04008322static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008323 struct iw_request_info *info,
8324 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008325{
8326 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008327 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008328 wrqu->mode = priv->ieee->iw_mode;
8329 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008330 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008331 return 0;
8332}
8333
James Ketrenos43f66a62005-03-25 12:31:53 -06008334/* Values are in microsecond */
8335static const s32 timeout_duration[] = {
8336 350000,
8337 250000,
8338 75000,
8339 37000,
8340 25000,
8341};
8342
8343static const s32 period_duration[] = {
8344 400000,
8345 700000,
8346 1000000,
8347 1000000,
8348 1000000
8349};
8350
Jeff Garzikbf794512005-07-31 13:07:26 -04008351static int ipw_wx_get_range(struct net_device *dev,
8352 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008353 union iwreq_data *wrqu, char *extra)
8354{
8355 struct ipw_priv *priv = ieee80211_priv(dev);
8356 struct iw_range *range = (struct iw_range *)extra;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008357 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008358 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008359
8360 wrqu->data.length = sizeof(*range);
8361 memset(range, 0, sizeof(*range));
8362
8363 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008364 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008365
8366 range->max_qual.qual = 100;
8367 /* TODO: Find real max RSSI and stick here */
8368 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008369 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008370 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008371
8372 range->avg_qual.qual = 70;
8373 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008374 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008375 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008376 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008377 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008378 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008379
Jeff Garzikbf794512005-07-31 13:07:26 -04008380 for (i = 0; i < range->num_bitrates; i++)
8381 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008382 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008383
James Ketrenos43f66a62005-03-25 12:31:53 -06008384 range->max_rts = DEFAULT_RTS_THRESHOLD;
8385 range->min_frag = MIN_FRAG_THRESHOLD;
8386 range->max_frag = MAX_FRAG_THRESHOLD;
8387
8388 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008389 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008390 range->num_encoding_sizes = 2;
8391 range->max_encoding_tokens = WEP_KEYS;
8392
8393 /* Set the Wireless Extension versions */
8394 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008395 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008396
James Ketrenosb095c382005-08-24 22:04:42 -05008397 i = 0;
8398 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8399 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8400 i++, j++) {
8401 range->freq[i].i = geo->bg[j].channel;
8402 range->freq[i].m = geo->bg[j].freq * 100000;
8403 range->freq[i].e = 1;
8404 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008405 }
James Ketrenosb095c382005-08-24 22:04:42 -05008406
8407 if (priv->ieee->mode & IEEE_A) {
8408 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8409 i++, j++) {
8410 range->freq[i].i = geo->a[j].channel;
8411 range->freq[i].m = geo->a[j].freq * 100000;
8412 range->freq[i].e = 1;
8413 }
8414 }
8415
8416 range->num_channels = i;
8417 range->num_frequency = i;
8418
Zhu Yi46441512006-01-24 16:37:59 +08008419 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008420
8421 /* Event capability (kernel + driver) */
8422 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8423 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8424 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8425 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008426
Dan Williamsf1b50862006-01-30 13:58:56 -05008427 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8428 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8429
James Ketrenos43f66a62005-03-25 12:31:53 -06008430 IPW_DEBUG_WX("GET Range\n");
8431 return 0;
8432}
8433
Jeff Garzikbf794512005-07-31 13:07:26 -04008434static int ipw_wx_set_wap(struct net_device *dev,
8435 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008436 union iwreq_data *wrqu, char *extra)
8437{
8438 struct ipw_priv *priv = ieee80211_priv(dev);
8439
8440 static const unsigned char any[] = {
8441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8442 };
8443 static const unsigned char off[] = {
8444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8445 };
8446
Jeff Garzikbf794512005-07-31 13:07:26 -04008447 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008448 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008449 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008450 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8451 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8452 /* we disable mandatory BSSID association */
8453 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8454 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008455 IPW_DEBUG_ASSOC("Attempting to associate with new "
8456 "parameters.\n");
8457 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008458 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008459 return 0;
8460 }
8461
8462 priv->config |= CFG_STATIC_BSSID;
8463 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8464 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008465 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008466 return 0;
8467 }
8468
8469 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8470 MAC_ARG(wrqu->ap_addr.sa_data));
8471
8472 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8473
James Ketrenosc848d0a2005-08-24 21:56:24 -05008474 /* Network configuration changed -- force [re]association */
8475 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8476 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008477 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008478
Zhu Yi46441512006-01-24 16:37:59 +08008479 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008480 return 0;
8481}
8482
Jeff Garzikbf794512005-07-31 13:07:26 -04008483static int ipw_wx_get_wap(struct net_device *dev,
8484 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008485 union iwreq_data *wrqu, char *extra)
8486{
8487 struct ipw_priv *priv = ieee80211_priv(dev);
8488 /* If we are associated, trying to associate, or have a statically
8489 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008490 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008491 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008492 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8493 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008494 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008495 } else
8496 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8497
8498 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8499 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008500 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008501 return 0;
8502}
8503
Jeff Garzikbf794512005-07-31 13:07:26 -04008504static int ipw_wx_set_essid(struct net_device *dev,
8505 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008506 union iwreq_data *wrqu, char *extra)
8507{
8508 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008509 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008510 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008511 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008512 if (wrqu->essid.flags && wrqu->essid.length) {
8513 length = wrqu->essid.length - 1;
8514 essid = extra;
8515 }
8516 if (length == 0) {
8517 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008518 if ((priv->config & CFG_STATIC_ESSID) &&
8519 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008520 STATUS_ASSOCIATING))) {
8521 IPW_DEBUG_ASSOC("Attempting to associate with new "
8522 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008523 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008524 ipw_associate(priv);
8525 }
Zhu Yi46441512006-01-24 16:37:59 +08008526 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008527 return 0;
8528 }
8529
8530 length = min(length, IW_ESSID_MAX_SIZE);
8531
8532 priv->config |= CFG_STATIC_ESSID;
8533
8534 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8535 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008536 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008537 return 0;
8538 }
8539
8540 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8541 length);
8542
8543 priv->essid_len = length;
8544 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008545
James Ketrenosc848d0a2005-08-24 21:56:24 -05008546 /* Network configuration changed -- force [re]association */
8547 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8548 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008549 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008550
Zhu Yi46441512006-01-24 16:37:59 +08008551 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008552 return 0;
8553}
8554
Jeff Garzikbf794512005-07-31 13:07:26 -04008555static int ipw_wx_get_essid(struct net_device *dev,
8556 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008557 union iwreq_data *wrqu, char *extra)
8558{
8559 struct ipw_priv *priv = ieee80211_priv(dev);
8560
8561 /* If we are associated, trying to associate, or have a statically
8562 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008563 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008564 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008565 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8566 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008567 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008568 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008569 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008570 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 } else {
8572 IPW_DEBUG_WX("Getting essid: ANY\n");
8573 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008574 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008575 }
Zhu Yi46441512006-01-24 16:37:59 +08008576 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 return 0;
8578}
8579
Jeff Garzikbf794512005-07-31 13:07:26 -04008580static int ipw_wx_set_nick(struct net_device *dev,
8581 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008582 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008583{
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 struct ipw_priv *priv = ieee80211_priv(dev);
8585
8586 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8587 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8588 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008589 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008590 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008591 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008592 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008594 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008595 return 0;
8596
8597}
8598
Jeff Garzikbf794512005-07-31 13:07:26 -04008599static int ipw_wx_get_nick(struct net_device *dev,
8600 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008601 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008602{
James Ketrenos43f66a62005-03-25 12:31:53 -06008603 struct ipw_priv *priv = ieee80211_priv(dev);
8604 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008605 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008606 wrqu->data.length = strlen(priv->nick) + 1;
8607 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008608 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008609 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008610 return 0;
8611}
8612
James Ketrenos43f66a62005-03-25 12:31:53 -06008613static int ipw_wx_set_rate(struct net_device *dev,
8614 struct iw_request_info *info,
8615 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008616{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008617 /* TODO: We should use semaphores or locks for access to priv */
8618 struct ipw_priv *priv = ieee80211_priv(dev);
8619 u32 target_rate = wrqu->bitrate.value;
8620 u32 fixed, mask;
8621
8622 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8623 /* value = X, fixed = 1 means only rate X */
8624 /* value = X, fixed = 0 means all rates lower equal X */
8625
8626 if (target_rate == -1) {
8627 fixed = 0;
8628 mask = IEEE80211_DEFAULT_RATES_MASK;
8629 /* Now we should reassociate */
8630 goto apply;
8631 }
8632
8633 mask = 0;
8634 fixed = wrqu->bitrate.fixed;
8635
8636 if (target_rate == 1000000 || !fixed)
8637 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8638 if (target_rate == 1000000)
8639 goto apply;
8640
8641 if (target_rate == 2000000 || !fixed)
8642 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8643 if (target_rate == 2000000)
8644 goto apply;
8645
8646 if (target_rate == 5500000 || !fixed)
8647 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8648 if (target_rate == 5500000)
8649 goto apply;
8650
8651 if (target_rate == 6000000 || !fixed)
8652 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8653 if (target_rate == 6000000)
8654 goto apply;
8655
8656 if (target_rate == 9000000 || !fixed)
8657 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8658 if (target_rate == 9000000)
8659 goto apply;
8660
8661 if (target_rate == 11000000 || !fixed)
8662 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8663 if (target_rate == 11000000)
8664 goto apply;
8665
8666 if (target_rate == 12000000 || !fixed)
8667 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8668 if (target_rate == 12000000)
8669 goto apply;
8670
8671 if (target_rate == 18000000 || !fixed)
8672 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8673 if (target_rate == 18000000)
8674 goto apply;
8675
8676 if (target_rate == 24000000 || !fixed)
8677 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8678 if (target_rate == 24000000)
8679 goto apply;
8680
8681 if (target_rate == 36000000 || !fixed)
8682 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8683 if (target_rate == 36000000)
8684 goto apply;
8685
8686 if (target_rate == 48000000 || !fixed)
8687 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8688 if (target_rate == 48000000)
8689 goto apply;
8690
8691 if (target_rate == 54000000 || !fixed)
8692 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8693 if (target_rate == 54000000)
8694 goto apply;
8695
8696 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8697 return -EINVAL;
8698
8699 apply:
8700 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8701 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08008702 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008703 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008704 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008705 ipw_set_fixed_rate(priv, priv->ieee->mode);
8706 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008707 priv->config |= CFG_FIXED_RATE;
8708
James Ketrenosc848d0a2005-08-24 21:56:24 -05008709 if (priv->rates_mask == mask) {
8710 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008711 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008712 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008713 }
8714
James Ketrenosc848d0a2005-08-24 21:56:24 -05008715 priv->rates_mask = mask;
8716
8717 /* Network configuration changed -- force [re]association */
8718 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8719 if (!ipw_disassociate(priv))
8720 ipw_associate(priv);
8721
Zhu Yi46441512006-01-24 16:37:59 +08008722 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008723 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008724}
8725
Jeff Garzikbf794512005-07-31 13:07:26 -04008726static int ipw_wx_get_rate(struct net_device *dev,
8727 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008728 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008729{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008730 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008731 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008732 wrqu->bitrate.value = priv->last_rate;
Zhu Yi46441512006-01-24 16:37:59 +08008733 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008734 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8735 return 0;
8736}
8737
Jeff Garzikbf794512005-07-31 13:07:26 -04008738static int ipw_wx_set_rts(struct net_device *dev,
8739 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008740 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008741{
James Ketrenos43f66a62005-03-25 12:31:53 -06008742 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008743 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008744 if (wrqu->rts.disabled)
8745 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8746 else {
8747 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008748 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008749 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008750 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008751 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008752 priv->rts_threshold = wrqu->rts.value;
8753 }
8754
8755 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08008756 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008757 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8758 return 0;
8759}
8760
Jeff Garzikbf794512005-07-31 13:07:26 -04008761static int ipw_wx_get_rts(struct net_device *dev,
8762 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008763 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008764{
James Ketrenos43f66a62005-03-25 12:31:53 -06008765 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008766 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008767 wrqu->rts.value = priv->rts_threshold;
8768 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008769 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08008770 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008771 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8772 return 0;
8773}
8774
Jeff Garzikbf794512005-07-31 13:07:26 -04008775static int ipw_wx_set_txpow(struct net_device *dev,
8776 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008777 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008778{
James Ketrenos43f66a62005-03-25 12:31:53 -06008779 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008780 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008781
Zhu Yi46441512006-01-24 16:37:59 +08008782 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008783 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008784 err = -EINPROGRESS;
8785 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008786 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008787
James Ketrenosb095c382005-08-24 22:04:42 -05008788 if (!wrqu->power.fixed)
8789 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008790
James Ketrenosc848d0a2005-08-24 21:56:24 -05008791 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008792 err = -EINVAL;
8793 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008794 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008795
James Ketrenosb095c382005-08-24 22:04:42 -05008796 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008797 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008798 err = -EINVAL;
8799 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008800 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008801
8802 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008803 err = ipw_set_tx_power(priv);
8804 out:
Zhu Yi46441512006-01-24 16:37:59 +08008805 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008806 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008807}
8808
Jeff Garzikbf794512005-07-31 13:07:26 -04008809static int ipw_wx_get_txpow(struct net_device *dev,
8810 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008811 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008812{
James Ketrenos43f66a62005-03-25 12:31:53 -06008813 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008814 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008815 wrqu->power.value = priv->tx_power;
8816 wrqu->power.fixed = 1;
8817 wrqu->power.flags = IW_TXPOW_DBM;
8818 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08008819 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008820
Jeff Garzikbf794512005-07-31 13:07:26 -04008821 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008822 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008823
8824 return 0;
8825}
8826
Jeff Garzikbf794512005-07-31 13:07:26 -04008827static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008828 struct iw_request_info *info,
8829 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008830{
8831 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008832 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008833 if (wrqu->frag.disabled)
8834 priv->ieee->fts = DEFAULT_FTS;
8835 else {
8836 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008837 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008838 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008839 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008840 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008841
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 priv->ieee->fts = wrqu->frag.value & ~0x1;
8843 }
8844
8845 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08008846 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008847 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8848 return 0;
8849}
8850
Jeff Garzikbf794512005-07-31 13:07:26 -04008851static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008852 struct iw_request_info *info,
8853 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008854{
8855 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008856 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008857 wrqu->frag.value = priv->ieee->fts;
8858 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008859 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08008860 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8862
8863 return 0;
8864}
8865
Jeff Garzikbf794512005-07-31 13:07:26 -04008866static int ipw_wx_set_retry(struct net_device *dev,
8867 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008869{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008870 struct ipw_priv *priv = ieee80211_priv(dev);
8871
8872 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8873 return -EINVAL;
8874
8875 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8876 return 0;
8877
8878 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8879 return -EINVAL;
8880
Zhu Yi46441512006-01-24 16:37:59 +08008881 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008882 if (wrqu->retry.flags & IW_RETRY_MIN)
8883 priv->short_retry_limit = (u8) wrqu->retry.value;
8884 else if (wrqu->retry.flags & IW_RETRY_MAX)
8885 priv->long_retry_limit = (u8) wrqu->retry.value;
8886 else {
8887 priv->short_retry_limit = (u8) wrqu->retry.value;
8888 priv->long_retry_limit = (u8) wrqu->retry.value;
8889 }
8890
8891 ipw_send_retry_limit(priv, priv->short_retry_limit,
8892 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08008893 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008894 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8895 priv->short_retry_limit, priv->long_retry_limit);
8896 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008897}
8898
Jeff Garzikbf794512005-07-31 13:07:26 -04008899static int ipw_wx_get_retry(struct net_device *dev,
8900 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008901 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008902{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008903 struct ipw_priv *priv = ieee80211_priv(dev);
8904
Zhu Yi46441512006-01-24 16:37:59 +08008905 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008906 wrqu->retry.disabled = 0;
8907
8908 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08008909 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008910 return -EINVAL;
8911 }
8912
8913 if (wrqu->retry.flags & IW_RETRY_MAX) {
8914 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8915 wrqu->retry.value = priv->long_retry_limit;
8916 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8917 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8918 wrqu->retry.value = priv->short_retry_limit;
8919 } else {
8920 wrqu->retry.flags = IW_RETRY_LIMIT;
8921 wrqu->retry.value = priv->short_retry_limit;
8922 }
Zhu Yi46441512006-01-24 16:37:59 +08008923 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008924
8925 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8926
8927 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008928}
8929
James Ketrenosafbf30a2005-08-25 00:05:33 -05008930static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8931 int essid_len)
8932{
8933 struct ipw_scan_request_ext scan;
8934 int err = 0, scan_type;
8935
Pekka Enbergefb34422005-11-16 21:55:05 +02008936 if (!(priv->status & STATUS_INIT) ||
8937 (priv->status & STATUS_EXIT_PENDING))
8938 return 0;
8939
Zhu Yi46441512006-01-24 16:37:59 +08008940 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008941
8942 if (priv->status & STATUS_RF_KILL_MASK) {
8943 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8944 priv->status |= STATUS_SCAN_PENDING;
8945 goto done;
8946 }
8947
8948 IPW_DEBUG_HC("starting request direct scan!\n");
8949
8950 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01008951 /* We should not sleep here; otherwise we will block most
8952 * of the system (for instance, we hold rtnl_lock when we
8953 * get here).
8954 */
8955 err = -EAGAIN;
8956 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008957 }
8958 memset(&scan, 0, sizeof(scan));
8959
8960 if (priv->config & CFG_SPEED_SCAN)
8961 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8962 cpu_to_le16(30);
8963 else
8964 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8965 cpu_to_le16(20);
8966
8967 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8968 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008969 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008970 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8971
8972 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8973
8974 err = ipw_send_ssid(priv, essid, essid_len);
8975 if (err) {
8976 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8977 goto done;
8978 }
8979 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8980
8981 ipw_add_scan_channels(priv, &scan, scan_type);
8982
8983 err = ipw_send_scan_request_ext(priv, &scan);
8984 if (err) {
8985 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8986 goto done;
8987 }
8988
8989 priv->status |= STATUS_SCANNING;
8990
8991 done:
Zhu Yi46441512006-01-24 16:37:59 +08008992 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008993 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008994}
8995
Jeff Garzikbf794512005-07-31 13:07:26 -04008996static int ipw_wx_set_scan(struct net_device *dev,
8997 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008998 union iwreq_data *wrqu, char *extra)
8999{
9000 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009001 struct iw_scan_req *req = NULL;
9002 if (wrqu->data.length
9003 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9004 req = (struct iw_scan_req *)extra;
9005 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9006 ipw_request_direct_scan(priv, req->essid,
9007 req->essid_len);
9008 return 0;
9009 }
9010 }
James Ketrenos8935f392005-10-05 15:59:08 -05009011
James Ketrenos43f66a62005-03-25 12:31:53 -06009012 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009013
9014 queue_work(priv->workqueue, &priv->request_scan);
9015
James Ketrenos43f66a62005-03-25 12:31:53 -06009016 return 0;
9017}
9018
Jeff Garzikbf794512005-07-31 13:07:26 -04009019static int ipw_wx_get_scan(struct net_device *dev,
9020 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009021 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009022{
James Ketrenos43f66a62005-03-25 12:31:53 -06009023 struct ipw_priv *priv = ieee80211_priv(dev);
9024 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9025}
9026
Jeff Garzikbf794512005-07-31 13:07:26 -04009027static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009028 struct iw_request_info *info,
9029 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009030{
9031 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009032 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009033 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009034
Zhu Yi46441512006-01-24 16:37:59 +08009035 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009036 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009037
Hong Liucaeff812005-08-05 17:25:50 +08009038 /* In IBSS mode, we need to notify the firmware to update
9039 * the beacon info after we changed the capability. */
9040 if (cap != priv->capability &&
9041 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9042 priv->status & STATUS_ASSOCIATED)
9043 ipw_disassociate(priv);
9044
Zhu Yi46441512006-01-24 16:37:59 +08009045 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009046 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009047}
9048
Jeff Garzikbf794512005-07-31 13:07:26 -04009049static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009050 struct iw_request_info *info,
9051 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009052{
9053 struct ipw_priv *priv = ieee80211_priv(dev);
9054 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9055}
9056
Jeff Garzikbf794512005-07-31 13:07:26 -04009057static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009058 struct iw_request_info *info,
9059 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009060{
9061 struct ipw_priv *priv = ieee80211_priv(dev);
9062 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009063 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 if (wrqu->power.disabled) {
9065 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9066 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9067 if (err) {
9068 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009069 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009070 return err;
9071 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009072 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009073 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009074 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009075 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009076
9077 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009078 case IW_POWER_ON: /* If not specified */
9079 case IW_POWER_MODE: /* If set all mask */
9080 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009081 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009082 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009083 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9084 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009085 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009086 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009087 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009088
James Ketrenos43f66a62005-03-25 12:31:53 -06009089 /* If the user hasn't specified a power management mode yet, default
9090 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009091 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009092 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009093 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009094 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9095 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9096 if (err) {
9097 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009098 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009099 return err;
9100 }
9101
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009102 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009103 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009104 return 0;
9105}
9106
Jeff Garzikbf794512005-07-31 13:07:26 -04009107static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009108 struct iw_request_info *info,
9109 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009110{
9111 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009112 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009113 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009114 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009115 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009116 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009117
Zhu Yi46441512006-01-24 16:37:59 +08009118 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009119 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009120
James Ketrenos43f66a62005-03-25 12:31:53 -06009121 return 0;
9122}
9123
Jeff Garzikbf794512005-07-31 13:07:26 -04009124static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009125 struct iw_request_info *info,
9126 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009127{
9128 struct ipw_priv *priv = ieee80211_priv(dev);
9129 int mode = *(int *)extra;
9130 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009131 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009132 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9133 mode = IPW_POWER_AC;
9134 priv->power_mode = mode;
9135 } else {
9136 priv->power_mode = IPW_POWER_ENABLED | mode;
9137 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009138
James Ketrenos43f66a62005-03-25 12:31:53 -06009139 if (priv->power_mode != mode) {
9140 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009141
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 if (err) {
9143 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009144 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009145 return err;
9146 }
9147 }
Zhu Yi46441512006-01-24 16:37:59 +08009148 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009149 return 0;
9150}
9151
9152#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009153static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009154 struct iw_request_info *info,
9155 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009156{
9157 struct ipw_priv *priv = ieee80211_priv(dev);
9158 int level = IPW_POWER_LEVEL(priv->power_mode);
9159 char *p = extra;
9160
9161 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9162
9163 switch (level) {
9164 case IPW_POWER_AC:
9165 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9166 break;
9167 case IPW_POWER_BATTERY:
9168 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9169 break;
9170 default:
9171 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009172 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009173 timeout_duration[level - 1] / 1000,
9174 period_duration[level - 1] / 1000);
9175 }
9176
9177 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009178 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009179
9180 wrqu->data.length = p - extra + 1;
9181
9182 return 0;
9183}
9184
9185static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009186 struct iw_request_info *info,
9187 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009188{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009189 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009190 int mode = *(int *)extra;
9191 u8 band = 0, modulation = 0;
9192
9193 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009194 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009195 return -EINVAL;
9196 }
Zhu Yi46441512006-01-24 16:37:59 +08009197 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009198 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009199 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009200 if (mode & IEEE_A) {
9201 band |= IEEE80211_52GHZ_BAND;
9202 modulation |= IEEE80211_OFDM_MODULATION;
9203 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009204 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009205 } else {
9206 if (mode & IEEE_A) {
9207 IPW_WARNING("Attempt to set 2200BG into "
9208 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009209 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009210 return -EINVAL;
9211 }
9212
James Ketrenosa33a1982005-09-14 14:28:59 -05009213 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009214 }
9215
9216 if (mode & IEEE_B) {
9217 band |= IEEE80211_24GHZ_BAND;
9218 modulation |= IEEE80211_CCK_MODULATION;
9219 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009220 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009221
James Ketrenos43f66a62005-03-25 12:31:53 -06009222 if (mode & IEEE_G) {
9223 band |= IEEE80211_24GHZ_BAND;
9224 modulation |= IEEE80211_OFDM_MODULATION;
9225 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009226 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009227
9228 priv->ieee->mode = mode;
9229 priv->ieee->freq_band = band;
9230 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009231 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009232
James Ketrenosc848d0a2005-08-24 21:56:24 -05009233 /* Network configuration changed -- force [re]association */
9234 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9235 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009236 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009237 ipw_associate(priv);
9238 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009239
James Ketrenosa613bff2005-08-24 21:43:11 -05009240 /* Update the band LEDs */
9241 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009242
Jeff Garzikbf794512005-07-31 13:07:26 -04009243 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009244 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009245 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009246 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009247 return 0;
9248}
9249
9250static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009251 struct iw_request_info *info,
9252 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009253{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009254 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009255 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009256 switch (priv->ieee->mode) {
9257 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009258 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9259 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009260 case IEEE_B:
9261 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9262 break;
9263 case IEEE_A | IEEE_B:
9264 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9265 break;
9266 case IEEE_G:
9267 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9268 break;
9269 case IEEE_A | IEEE_G:
9270 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9271 break;
9272 case IEEE_B | IEEE_G:
9273 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9274 break;
9275 case IEEE_A | IEEE_B | IEEE_G:
9276 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9277 break;
9278 default:
9279 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009280 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009281 }
9282
James Ketrenos43f66a62005-03-25 12:31:53 -06009283 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9284
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009285 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009286 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009287
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009288 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009289}
9290
James Ketrenosea2b26e2005-08-24 21:25:16 -05009291static int ipw_wx_set_preamble(struct net_device *dev,
9292 struct iw_request_info *info,
9293 union iwreq_data *wrqu, char *extra)
9294{
9295 struct ipw_priv *priv = ieee80211_priv(dev);
9296 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009297 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009298 /* Switching from SHORT -> LONG requires a disassociation */
9299 if (mode == 1) {
9300 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9301 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009302
9303 /* Network configuration changed -- force [re]association */
9304 IPW_DEBUG_ASSOC
9305 ("[re]association triggered due to preamble change.\n");
9306 if (!ipw_disassociate(priv))
9307 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009308 }
9309 goto done;
9310 }
9311
9312 if (mode == 0) {
9313 priv->config &= ~CFG_PREAMBLE_LONG;
9314 goto done;
9315 }
Zhu Yi46441512006-01-24 16:37:59 +08009316 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009317 return -EINVAL;
9318
9319 done:
Zhu Yi46441512006-01-24 16:37:59 +08009320 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009321 return 0;
9322}
9323
9324static int ipw_wx_get_preamble(struct net_device *dev,
9325 struct iw_request_info *info,
9326 union iwreq_data *wrqu, char *extra)
9327{
9328 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009329 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009330 if (priv->config & CFG_PREAMBLE_LONG)
9331 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9332 else
9333 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009334 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009335 return 0;
9336}
9337
James Ketrenosb095c382005-08-24 22:04:42 -05009338#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009339static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009340 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009341 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009342{
James Ketrenos43f66a62005-03-25 12:31:53 -06009343 struct ipw_priv *priv = ieee80211_priv(dev);
9344 int *parms = (int *)extra;
9345 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009346 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009347 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009348 if (enable) {
9349 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009350#ifdef CONFIG_IEEE80211_RADIOTAP
9351 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9352#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009353 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009354#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009355 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009356 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009357
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 ipw_set_channel(priv, parms[1]);
9359 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009360 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009361 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009362 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009363 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009364 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009365 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009366 }
Zhu Yi46441512006-01-24 16:37:59 +08009367 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009368 return 0;
9369}
9370
James Ketrenosb095c382005-08-24 22:04:42 -05009371#endif // CONFIG_IPW2200_MONITOR
9372
Jeff Garzikbf794512005-07-31 13:07:26 -04009373static int ipw_wx_reset(struct net_device *dev,
9374 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009376{
James Ketrenos43f66a62005-03-25 12:31:53 -06009377 struct ipw_priv *priv = ieee80211_priv(dev);
9378 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009379 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009380 return 0;
9381}
James Ketrenosb095c382005-08-24 22:04:42 -05009382
James Ketrenosb095c382005-08-24 22:04:42 -05009383static int ipw_wx_sw_reset(struct net_device *dev,
9384 struct iw_request_info *info,
9385 union iwreq_data *wrqu, char *extra)
9386{
9387 struct ipw_priv *priv = ieee80211_priv(dev);
9388 union iwreq_data wrqu_sec = {
9389 .encoding = {
9390 .flags = IW_ENCODE_DISABLED,
9391 },
9392 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009393 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009394
9395 IPW_DEBUG_WX("SW_RESET\n");
9396
Zhu Yi46441512006-01-24 16:37:59 +08009397 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009398
James Ketrenosafbf30a2005-08-25 00:05:33 -05009399 ret = ipw_sw_reset(priv, 0);
9400 if (!ret) {
9401 free_firmware();
9402 ipw_adapter_restart(priv);
9403 }
James Ketrenosb095c382005-08-24 22:04:42 -05009404
9405 /* The SW reset bit might have been toggled on by the 'disable'
9406 * module parameter, so take appropriate action */
9407 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9408
Zhu Yi46441512006-01-24 16:37:59 +08009409 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009410 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009411 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009412
9413 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9414 /* Configuration likely changed -- force [re]association */
9415 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9416 "reset.\n");
9417 if (!ipw_disassociate(priv))
9418 ipw_associate(priv);
9419 }
9420
Zhu Yi46441512006-01-24 16:37:59 +08009421 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009422
9423 return 0;
9424}
James Ketrenos43f66a62005-03-25 12:31:53 -06009425
9426/* Rebase the WE IOCTLs to zero for the handler array */
9427#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009428static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009429 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9430 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9431 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9432 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9433 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9434 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9435 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9436 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9437 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9438 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9439 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9440 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9441 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9442 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9443 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9444 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9445 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9446 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9447 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9448 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9449 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9450 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9451 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9452 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9453 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9454 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9455 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9456 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009457 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9458 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9459 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9460 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009461 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9462 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9463 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9464 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9465 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9466 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9467 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009468};
9469
James Ketrenosb095c382005-08-24 22:04:42 -05009470enum {
9471 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9472 IPW_PRIV_GET_POWER,
9473 IPW_PRIV_SET_MODE,
9474 IPW_PRIV_GET_MODE,
9475 IPW_PRIV_SET_PREAMBLE,
9476 IPW_PRIV_GET_PREAMBLE,
9477 IPW_PRIV_RESET,
9478 IPW_PRIV_SW_RESET,
9479#ifdef CONFIG_IPW2200_MONITOR
9480 IPW_PRIV_SET_MONITOR,
9481#endif
9482};
James Ketrenos43f66a62005-03-25 12:31:53 -06009483
Jeff Garzikbf794512005-07-31 13:07:26 -04009484static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009485 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009486 .cmd = IPW_PRIV_SET_POWER,
9487 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9488 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009489 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009490 .cmd = IPW_PRIV_GET_POWER,
9491 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9492 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009493 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009494 .cmd = IPW_PRIV_SET_MODE,
9495 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9496 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009497 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009498 .cmd = IPW_PRIV_GET_MODE,
9499 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9500 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009501 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009502 .cmd = IPW_PRIV_SET_PREAMBLE,
9503 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9504 .name = "set_preamble"},
9505 {
9506 .cmd = IPW_PRIV_GET_PREAMBLE,
9507 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9508 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009509 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009510 IPW_PRIV_RESET,
9511 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009512 {
9513 IPW_PRIV_SW_RESET,
9514 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9515#ifdef CONFIG_IPW2200_MONITOR
9516 {
9517 IPW_PRIV_SET_MONITOR,
9518 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9519#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009520};
9521
9522static iw_handler ipw_priv_handler[] = {
9523 ipw_wx_set_powermode,
9524 ipw_wx_get_powermode,
9525 ipw_wx_set_wireless_mode,
9526 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009527 ipw_wx_set_preamble,
9528 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009529 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009530 ipw_wx_sw_reset,
9531#ifdef CONFIG_IPW2200_MONITOR
9532 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009533#endif
9534};
9535
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009536static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009537 .standard = ipw_wx_handlers,
9538 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9539 .num_private = ARRAY_SIZE(ipw_priv_handler),
9540 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9541 .private = ipw_priv_handler,
9542 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009543 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009544};
9545
James Ketrenos43f66a62005-03-25 12:31:53 -06009546/*
9547 * Get wireless statistics.
9548 * Called by /proc/net/wireless
9549 * Also called by SIOCGIWSTATS
9550 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009551static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009552{
9553 struct ipw_priv *priv = ieee80211_priv(dev);
9554 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009555
James Ketrenos43f66a62005-03-25 12:31:53 -06009556 wstats = &priv->wstats;
9557
James Ketrenosea2b26e2005-08-24 21:25:16 -05009558 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009559 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009560 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9561 * and associated; if not associcated, the values are all meaningless
9562 * anyway, so set them all to NULL and INVALID */
9563 if (!(priv->status & STATUS_ASSOCIATED)) {
9564 wstats->miss.beacon = 0;
9565 wstats->discard.retries = 0;
9566 wstats->qual.qual = 0;
9567 wstats->qual.level = 0;
9568 wstats->qual.noise = 0;
9569 wstats->qual.updated = 7;
9570 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009571 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009572 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009573 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009574
9575 wstats->qual.qual = priv->quality;
9576 wstats->qual.level = average_value(&priv->average_rssi);
9577 wstats->qual.noise = average_value(&priv->average_noise);
9578 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009579 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009580
9581 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9582 wstats->discard.retries = priv->last_tx_failures;
9583 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009584
James Ketrenos43f66a62005-03-25 12:31:53 -06009585/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9586 goto fail_get_ordinal;
9587 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009588
James Ketrenos43f66a62005-03-25 12:31:53 -06009589 return wstats;
9590}
9591
James Ketrenos43f66a62005-03-25 12:31:53 -06009592/* net device stuff */
9593
Arjan van de Ven858119e2006-01-14 13:20:43 -08009594static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009595{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009596 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009597 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009598 sys_config->answer_broadcast_ssid_probe = 0;
9599 sys_config->accept_all_data_frames = 0;
9600 sys_config->accept_non_directed_frames = 1;
9601 sys_config->exclude_unicast_unencrypted = 0;
9602 sys_config->disable_unicast_decryption = 1;
9603 sys_config->exclude_multicast_unencrypted = 0;
9604 sys_config->disable_multicast_decryption = 1;
9605 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009606 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009607 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009608 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009609 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009610 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009611}
9612
9613static int ipw_net_open(struct net_device *dev)
9614{
9615 struct ipw_priv *priv = ieee80211_priv(dev);
9616 IPW_DEBUG_INFO("dev->open\n");
9617 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +08009618 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009619 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9620 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009621 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009622 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009623 return 0;
9624}
9625
9626static int ipw_net_stop(struct net_device *dev)
9627{
9628 IPW_DEBUG_INFO("dev->close\n");
9629 netif_stop_queue(dev);
9630 return 0;
9631}
9632
9633/*
9634todo:
9635
9636modify to send one tfd per fragment instead of using chunking. otherwise
9637we need to heavily modify the ieee80211_skb_to_txb.
9638*/
9639
Arjan van de Ven858119e2006-01-14 13:20:43 -08009640static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009641 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009642{
James Ketrenos0dacca12005-09-21 12:23:41 -05009643 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009644 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 int i = 0;
9646 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009647#ifdef CONFIG_IPW_QOS
9648 int tx_id = ipw_get_tx_queue_number(priv, pri);
9649 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9650#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009651 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009652#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 struct clx2_queue *q = &txq->q;
9654 u8 id, hdr_len, unicast;
9655 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009656 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009657
James Ketrenos227d2dc2005-07-28 16:25:55 -05009658 /* If there isn't room in the queue, we return busy and let the
9659 * network stack requeue the packet for us */
9660 if (ipw_queue_space(q) < q->high_mark)
9661 return NETDEV_TX_BUSY;
James Ketrenos43f66a62005-03-25 12:31:53 -06009662
9663 switch (priv->ieee->iw_mode) {
9664 case IW_MODE_ADHOC:
9665 hdr_len = IEEE80211_3ADDR_LEN;
Stephen Hemminger3c190652006-01-03 15:27:38 -08009666 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009667 id = ipw_find_station(priv, hdr->addr1);
9668 if (id == IPW_INVALID_STATION) {
9669 id = ipw_add_station(priv, hdr->addr1);
9670 if (id == IPW_INVALID_STATION) {
9671 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009672 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009673 MAC_ARG(hdr->addr1));
9674 goto drop;
9675 }
9676 }
9677 break;
9678
9679 case IW_MODE_INFRA:
9680 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009681 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009682 hdr_len = IEEE80211_3ADDR_LEN;
9683 id = 0;
9684 break;
9685 }
9686
9687 tfd = &txq->bd[q->first_empty];
9688 txq->txb[q->first_empty] = txb;
9689 memset(tfd, 0, sizeof(*tfd));
9690 tfd->u.data.station_number = id;
9691
9692 tfd->control_flags.message_type = TX_FRAME_TYPE;
9693 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9694
9695 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009696 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009697 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009698
James Ketrenos43f66a62005-03-25 12:31:53 -06009699 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009700 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009701 else
James Ketrenosb095c382005-08-24 22:04:42 -05009702 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009703
James Ketrenosea2b26e2005-08-24 21:25:16 -05009704 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9705 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009706
James Ketrenosc848d0a2005-08-24 21:56:24 -05009707 fc = le16_to_cpu(hdr->frame_ctl);
9708 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709
9710 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9711
James Ketrenosb095c382005-08-24 22:04:42 -05009712 if (likely(unicast))
9713 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9714
9715 if (txb->encrypted && !priv->ieee->host_encrypt) {
9716 switch (priv->ieee->sec.level) {
9717 case SEC_LEVEL_3:
9718 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9719 IEEE80211_FCTL_PROTECTED;
9720 /* XXX: ACK flag must be set for CCMP even if it
9721 * is a multicast/broadcast packet, because CCMP
9722 * group communication encrypted by GTK is
9723 * actually done by the AP. */
9724 if (!unicast)
9725 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9726
9727 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9728 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9729 tfd->u.data.key_index = 0;
9730 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9731 break;
9732 case SEC_LEVEL_2:
9733 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9734 IEEE80211_FCTL_PROTECTED;
9735 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9736 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9737 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9738 break;
9739 case SEC_LEVEL_1:
9740 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9741 IEEE80211_FCTL_PROTECTED;
9742 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9743 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9744 40)
9745 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9746 else
9747 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9748 break;
9749 case SEC_LEVEL_0:
9750 break;
9751 default:
9752 printk(KERN_ERR "Unknow security level %d\n",
9753 priv->ieee->sec.level);
9754 break;
9755 }
9756 } else
9757 /* No hardware encryption */
9758 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9759
9760#ifdef CONFIG_IPW_QOS
9761 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9762#endif /* CONFIG_IPW_QOS */
9763
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009765 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9766 txb->nr_frags));
9767 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9768 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9769 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9770 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9771 i, le32_to_cpu(tfd->u.data.num_chunks),
9772 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009773 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009774 i, tfd->u.data.num_chunks,
9775 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009776 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009777 txb->fragments[i]->len - hdr_len);
9778
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009779 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009780 cpu_to_le32(pci_map_single
9781 (priv->pci_dev,
9782 txb->fragments[i]->data + hdr_len,
9783 txb->fragments[i]->len - hdr_len,
9784 PCI_DMA_TODEVICE));
9785 tfd->u.data.chunk_len[i] =
9786 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 }
9788
9789 if (i != txb->nr_frags) {
9790 struct sk_buff *skb;
9791 u16 remaining_bytes = 0;
9792 int j;
9793
9794 for (j = i; j < txb->nr_frags; j++)
9795 remaining_bytes += txb->fragments[j]->len - hdr_len;
9796
9797 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9798 remaining_bytes);
9799 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9800 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009801 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009802 for (j = i; j < txb->nr_frags; j++) {
9803 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009804
James Ketrenos43f66a62005-03-25 12:31:53 -06009805 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009806 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009807 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009808 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009809 }
9810 dev_kfree_skb_any(txb->fragments[i]);
9811 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009812 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009813 cpu_to_le32(pci_map_single
9814 (priv->pci_dev, skb->data,
9815 tfd->u.data.chunk_len[i],
9816 PCI_DMA_TODEVICE));
9817
9818 tfd->u.data.num_chunks =
9819 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9820 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009821 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009822 }
9823
9824 /* kick DMA */
9825 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9826 ipw_write32(priv, q->reg_w, q->first_empty);
9827
James Ketrenos227d2dc2005-07-28 16:25:55 -05009828 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009829
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009830 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009831 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9832 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009833 return NETDEV_TX_OK;
9834}
9835
9836static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9837{
9838 struct ipw_priv *priv = ieee80211_priv(dev);
9839#ifdef CONFIG_IPW_QOS
9840 int tx_id = ipw_get_tx_queue_number(priv, pri);
9841 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9842#else
9843 struct clx2_tx_queue *txq = &priv->txq[0];
9844#endif /* CONFIG_IPW_QOS */
9845
9846 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9847 return 1;
9848
9849 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009850}
9851
9852static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009853 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009854{
9855 struct ipw_priv *priv = ieee80211_priv(dev);
9856 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009857 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009858
9859 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009860 spin_lock_irqsave(&priv->lock, flags);
9861
9862 if (!(priv->status & STATUS_ASSOCIATED)) {
9863 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9864 priv->ieee->stats.tx_carrier_errors++;
9865 netif_stop_queue(dev);
9866 goto fail_unlock;
9867 }
9868
James Ketrenos227d2dc2005-07-28 16:25:55 -05009869 ret = ipw_tx_skb(priv, txb, pri);
9870 if (ret == NETDEV_TX_OK)
9871 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009872 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009873
James Ketrenos227d2dc2005-07-28 16:25:55 -05009874 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009875
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009876 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009877 spin_unlock_irqrestore(&priv->lock, flags);
9878 return 1;
9879}
9880
9881static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9882{
9883 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009884
James Ketrenos43f66a62005-03-25 12:31:53 -06009885 priv->ieee->stats.tx_packets = priv->tx_packets;
9886 priv->ieee->stats.rx_packets = priv->rx_packets;
9887 return &priv->ieee->stats;
9888}
9889
9890static void ipw_net_set_multicast_list(struct net_device *dev)
9891{
9892
9893}
9894
9895static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9896{
9897 struct ipw_priv *priv = ieee80211_priv(dev);
9898 struct sockaddr *addr = p;
9899 if (!is_valid_ether_addr(addr->sa_data))
9900 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +08009901 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009902 priv->config |= CFG_CUSTOM_MAC;
9903 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9904 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9905 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009906 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08009907 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009908 return 0;
9909}
9910
Jeff Garzikbf794512005-07-31 13:07:26 -04009911static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009912 struct ethtool_drvinfo *info)
9913{
9914 struct ipw_priv *p = ieee80211_priv(dev);
9915 char vers[64];
9916 char date[32];
9917 u32 len;
9918
9919 strcpy(info->driver, DRV_NAME);
9920 strcpy(info->version, DRV_VERSION);
9921
9922 len = sizeof(vers);
9923 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9924 len = sizeof(date);
9925 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9926
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009927 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009928 vers, date);
9929 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009930 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009931}
9932
9933static u32 ipw_ethtool_get_link(struct net_device *dev)
9934{
9935 struct ipw_priv *priv = ieee80211_priv(dev);
9936 return (priv->status & STATUS_ASSOCIATED) != 0;
9937}
9938
9939static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9940{
James Ketrenosb095c382005-08-24 22:04:42 -05009941 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009942}
9943
9944static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009945 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009946{
9947 struct ipw_priv *p = ieee80211_priv(dev);
9948
James Ketrenosb095c382005-08-24 22:04:42 -05009949 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009950 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009951 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009952 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +08009953 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009954 return 0;
9955}
9956
9957static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009958 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009959{
9960 struct ipw_priv *p = ieee80211_priv(dev);
9961 int i;
9962
James Ketrenosb095c382005-08-24 22:04:42 -05009963 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009964 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009965 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009966 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009967 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -05009968 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06009969 ipw_write8(p, i, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +08009970 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009971 return 0;
9972}
9973
9974static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009975 .get_link = ipw_ethtool_get_link,
9976 .get_drvinfo = ipw_ethtool_get_drvinfo,
9977 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9978 .get_eeprom = ipw_ethtool_get_eeprom,
9979 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06009980};
9981
9982static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9983{
9984 struct ipw_priv *priv = data;
9985 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04009986
James Ketrenos43f66a62005-03-25 12:31:53 -06009987 if (!priv)
9988 return IRQ_NONE;
9989
9990 spin_lock(&priv->lock);
9991
9992 if (!(priv->status & STATUS_INT_ENABLED)) {
9993 /* Shared IRQ */
9994 goto none;
9995 }
9996
James Ketrenosb095c382005-08-24 22:04:42 -05009997 inta = ipw_read32(priv, IPW_INTA_RW);
9998 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04009999
James Ketrenos43f66a62005-03-25 12:31:53 -060010000 if (inta == 0xFFFFFFFF) {
10001 /* Hardware disappeared */
10002 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10003 goto none;
10004 }
10005
James Ketrenosb095c382005-08-24 22:04:42 -050010006 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010007 /* Shared interrupt */
10008 goto none;
10009 }
10010
10011 /* tell the device to stop sending interrupts */
10012 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010013
James Ketrenos43f66a62005-03-25 12:31:53 -060010014 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010015 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10016 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010017
James Ketrenos43f66a62005-03-25 12:31:53 -060010018 /* Cache INTA value for our tasklet */
10019 priv->isr_inta = inta;
10020
10021 tasklet_schedule(&priv->irq_tasklet);
10022
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010023 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010024
10025 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010026 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010027 spin_unlock(&priv->lock);
10028 return IRQ_NONE;
10029}
10030
10031static void ipw_rf_kill(void *adapter)
10032{
10033 struct ipw_priv *priv = adapter;
10034 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010035
James Ketrenos43f66a62005-03-25 12:31:53 -060010036 spin_lock_irqsave(&priv->lock, flags);
10037
10038 if (rf_kill_active(priv)) {
10039 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10040 if (priv->workqueue)
10041 queue_delayed_work(priv->workqueue,
10042 &priv->rf_kill, 2 * HZ);
10043 goto exit_unlock;
10044 }
10045
10046 /* RF Kill is now disabled, so bring the device back up */
10047
10048 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10049 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10050 "device\n");
10051
10052 /* we can not do an adapter restart while inside an irq lock */
10053 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010054 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10056 "enabled\n");
10057
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010058 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 spin_unlock_irqrestore(&priv->lock, flags);
10060}
10061
James Ketrenosc848d0a2005-08-24 21:56:24 -050010062static void ipw_bg_rf_kill(void *data)
10063{
10064 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010065 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010066 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010067 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010068}
10069
Adrian Bunka73e22b2006-01-21 01:39:42 +010010070static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010071{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010072 priv->last_seq_num = -1;
10073 priv->last_frag_num = -1;
10074 priv->last_packet_time = 0;
10075
James Ketrenosa613bff2005-08-24 21:43:11 -050010076 netif_carrier_on(priv->net_dev);
10077 if (netif_queue_stopped(priv->net_dev)) {
10078 IPW_DEBUG_NOTIF("waking queue\n");
10079 netif_wake_queue(priv->net_dev);
10080 } else {
10081 IPW_DEBUG_NOTIF("starting queue\n");
10082 netif_start_queue(priv->net_dev);
10083 }
10084
James Ketrenosc848d0a2005-08-24 21:56:24 -050010085 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010086 ipw_reset_stats(priv);
10087 /* Ensure the rate is updated immediately */
10088 priv->last_rate = ipw_get_current_rate(priv);
10089 ipw_gather_stats(priv);
10090 ipw_led_link_up(priv);
10091 notify_wx_assoc_event(priv);
10092
10093 if (priv->config & CFG_BACKGROUND_SCAN)
10094 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10095}
10096
James Ketrenosc848d0a2005-08-24 21:56:24 -050010097static void ipw_bg_link_up(void *data)
10098{
10099 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010100 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010101 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010102 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010103}
10104
Adrian Bunka73e22b2006-01-21 01:39:42 +010010105static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010106{
10107 ipw_led_link_down(priv);
10108 netif_carrier_off(priv->net_dev);
10109 netif_stop_queue(priv->net_dev);
10110 notify_wx_assoc_event(priv);
10111
10112 /* Cancel any queued work ... */
10113 cancel_delayed_work(&priv->request_scan);
10114 cancel_delayed_work(&priv->adhoc_check);
10115 cancel_delayed_work(&priv->gather_stats);
10116
10117 ipw_reset_stats(priv);
10118
James Ketrenosafbf30a2005-08-25 00:05:33 -050010119 if (!(priv->status & STATUS_EXIT_PENDING)) {
10120 /* Queue up another scan... */
10121 queue_work(priv->workqueue, &priv->request_scan);
10122 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010123}
10124
James Ketrenosc848d0a2005-08-24 21:56:24 -050010125static void ipw_bg_link_down(void *data)
10126{
10127 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010128 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010129 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010130 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010131}
10132
James Ketrenos43f66a62005-03-25 12:31:53 -060010133static int ipw_setup_deferred_work(struct ipw_priv *priv)
10134{
10135 int ret = 0;
10136
James Ketrenos43f66a62005-03-25 12:31:53 -060010137 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010139 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010140
James Ketrenosc848d0a2005-08-24 21:56:24 -050010141 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10142 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10143 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010144 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010145 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10146 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10147 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10148 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10149 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010150 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010151 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010152 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010153 (void (*)(void *))ipw_bg_gather_stats, priv);
10154 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10155 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10156 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10157 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10158 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10159 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010160 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010161 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010162 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010163 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10164 priv);
10165 INIT_WORK(&priv->merge_networks,
10166 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010167
James Ketrenosb095c382005-08-24 22:04:42 -050010168#ifdef CONFIG_IPW_QOS
10169 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10170 priv);
10171#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010172
10173 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10174 ipw_irq_tasklet, (unsigned long)priv);
10175
10176 return ret;
10177}
10178
James Ketrenos43f66a62005-03-25 12:31:53 -060010179static void shim__set_security(struct net_device *dev,
10180 struct ieee80211_security *sec)
10181{
10182 struct ipw_priv *priv = ieee80211_priv(dev);
10183 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010184 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010185 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010186 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010187 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010188 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010189 priv->ieee->sec.flags &= ~(1 << i);
10190 else {
10191 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010192 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010193 priv->ieee->sec.flags |= (1 << i);
10194 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010196 } else if (sec->level != SEC_LEVEL_1)
10197 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010198 }
10199
James Ketrenosb095c382005-08-24 22:04:42 -050010200 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010201 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010202 priv->ieee->sec.active_key = sec->active_key;
10203 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010204 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010205 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010206 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010207 } else
10208 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010209
10210 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010211 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10212 priv->ieee->sec.auth_mode = sec->auth_mode;
10213 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010214 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10215 priv->capability |= CAP_SHARED_KEY;
10216 else
10217 priv->capability &= ~CAP_SHARED_KEY;
10218 priv->status |= STATUS_SECURITY_UPDATED;
10219 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010220
James Ketrenosb095c382005-08-24 22:04:42 -050010221 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10222 priv->ieee->sec.flags |= SEC_ENABLED;
10223 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010224 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010225 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010226 priv->capability |= CAP_PRIVACY_ON;
10227 else
10228 priv->capability &= ~CAP_PRIVACY_ON;
10229 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010230
James Ketrenosafbf30a2005-08-25 00:05:33 -050010231 if (sec->flags & SEC_ENCRYPT)
10232 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010233
James Ketrenosb095c382005-08-24 22:04:42 -050010234 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10235 priv->ieee->sec.level = sec->level;
10236 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010237 priv->status |= STATUS_SECURITY_UPDATED;
10238 }
10239
Zhu Yi1fbfea52005-08-05 17:22:56 +080010240 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10241 ipw_set_hwcrypto_keys(priv);
10242
Jeff Garzikbf794512005-07-31 13:07:26 -040010243 /* To match current functionality of ipw2100 (which works well w/
10244 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010245 * privacy capability changes ... */
10246#if 0
10247 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010248 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010249 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010250 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010251 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010252 IPW_DEBUG_ASSOC("Disassociating due to capability "
10253 "change.\n");
10254 ipw_disassociate(priv);
10255 }
10256#endif
10257}
10258
Jeff Garzikbf794512005-07-31 13:07:26 -040010259static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010260 struct ipw_supported_rates *rates)
10261{
10262 /* TODO: Mask out rates based on priv->rates_mask */
10263
10264 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010265 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010266 switch (priv->ieee->freq_band) {
10267 case IEEE80211_52GHZ_BAND:
10268 rates->ieee_mode = IPW_A_MODE;
10269 rates->purpose = IPW_RATE_CAPABILITIES;
10270 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10271 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10272 break;
10273
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010274 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010275 rates->ieee_mode = IPW_G_MODE;
10276 rates->purpose = IPW_RATE_CAPABILITIES;
10277 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10278 IEEE80211_CCK_DEFAULT_RATES_MASK);
10279 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10280 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10281 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10282 }
10283 break;
10284 }
10285
10286 return 0;
10287}
10288
Jeff Garzikbf794512005-07-31 13:07:26 -040010289static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010290{
James Ketrenos43f66a62005-03-25 12:31:53 -060010291 /* This is only called from ipw_up, which resets/reloads the firmware
10292 so, we don't need to first disable the card before we configure
10293 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010294 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010295 goto error;
10296
10297 /* initialize adapter address */
10298 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10299 goto error;
10300
10301 /* set basic system config settings */
10302 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010303
10304 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10305 * Does not support BT priority yet (don't abort or defer our Tx) */
10306 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010307 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010308
10309 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10310 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010311 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010312 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10313 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010314 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010315 }
10316
James Ketrenosc848d0a2005-08-24 21:56:24 -050010317 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10318 priv->sys_config.answer_broadcast_ssid_probe = 1;
10319 else
10320 priv->sys_config.answer_broadcast_ssid_probe = 0;
10321
James Ketrenos43f66a62005-03-25 12:31:53 -060010322 if (ipw_send_system_config(priv, &priv->sys_config))
10323 goto error;
10324
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010325 init_supported_rates(priv, &priv->rates);
10326 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010327 goto error;
10328
10329 /* Set request-to-send threshold */
10330 if (priv->rts_threshold) {
10331 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10332 goto error;
10333 }
James Ketrenosb095c382005-08-24 22:04:42 -050010334#ifdef CONFIG_IPW_QOS
10335 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10336 ipw_qos_activate(priv, NULL);
10337#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010338
10339 if (ipw_set_random_seed(priv))
10340 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010341
James Ketrenos43f66a62005-03-25 12:31:53 -060010342 /* final state transition to the RUN state */
10343 if (ipw_send_host_complete(priv))
10344 goto error;
10345
James Ketrenose6666192005-08-12 09:17:04 -050010346 priv->status |= STATUS_INIT;
10347
10348 ipw_led_init(priv);
10349 ipw_led_radio_on(priv);
10350 priv->notif_missed_beacons = 0;
10351
10352 /* Set hardware WEP key if it is configured. */
10353 if ((priv->capability & CAP_PRIVACY_ON) &&
10354 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10355 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10356 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010357
10358 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010359
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010360 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010361 return -EIO;
10362}
10363
James Ketrenos4f36f802005-08-03 20:36:56 -050010364/*
10365 * NOTE:
10366 *
10367 * These tables have been tested in conjunction with the
10368 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10369 *
10370 * Altering this values, using it on other hardware, or in geographies
10371 * not intended for resale of the above mentioned Intel adapters has
10372 * not been tested.
10373 *
10374 */
10375static const struct ieee80211_geo ipw_geos[] = {
10376 { /* Restricted */
10377 "---",
10378 .bg_channels = 11,
10379 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10380 {2427, 4}, {2432, 5}, {2437, 6},
10381 {2442, 7}, {2447, 8}, {2452, 9},
10382 {2457, 10}, {2462, 11}},
10383 },
10384
10385 { /* Custom US/Canada */
10386 "ZZF",
10387 .bg_channels = 11,
10388 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10389 {2427, 4}, {2432, 5}, {2437, 6},
10390 {2442, 7}, {2447, 8}, {2452, 9},
10391 {2457, 10}, {2462, 11}},
10392 .a_channels = 8,
10393 .a = {{5180, 36},
10394 {5200, 40},
10395 {5220, 44},
10396 {5240, 48},
10397 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10398 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10399 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10400 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10401 },
10402
10403 { /* Rest of World */
10404 "ZZD",
10405 .bg_channels = 13,
10406 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10407 {2427, 4}, {2432, 5}, {2437, 6},
10408 {2442, 7}, {2447, 8}, {2452, 9},
10409 {2457, 10}, {2462, 11}, {2467, 12},
10410 {2472, 13}},
10411 },
10412
10413 { /* Custom USA & Europe & High */
10414 "ZZA",
10415 .bg_channels = 11,
10416 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10417 {2427, 4}, {2432, 5}, {2437, 6},
10418 {2442, 7}, {2447, 8}, {2452, 9},
10419 {2457, 10}, {2462, 11}},
10420 .a_channels = 13,
10421 .a = {{5180, 36},
10422 {5200, 40},
10423 {5220, 44},
10424 {5240, 48},
10425 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10426 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10427 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10428 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10429 {5745, 149},
10430 {5765, 153},
10431 {5785, 157},
10432 {5805, 161},
10433 {5825, 165}},
10434 },
10435
10436 { /* Custom NA & Europe */
10437 "ZZB",
10438 .bg_channels = 11,
10439 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10440 {2427, 4}, {2432, 5}, {2437, 6},
10441 {2442, 7}, {2447, 8}, {2452, 9},
10442 {2457, 10}, {2462, 11}},
10443 .a_channels = 13,
10444 .a = {{5180, 36},
10445 {5200, 40},
10446 {5220, 44},
10447 {5240, 48},
10448 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10449 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10450 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10451 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10452 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10453 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10454 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10455 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10456 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10457 },
10458
10459 { /* Custom Japan */
10460 "ZZC",
10461 .bg_channels = 11,
10462 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10463 {2427, 4}, {2432, 5}, {2437, 6},
10464 {2442, 7}, {2447, 8}, {2452, 9},
10465 {2457, 10}, {2462, 11}},
10466 .a_channels = 4,
10467 .a = {{5170, 34}, {5190, 38},
10468 {5210, 42}, {5230, 46}},
10469 },
10470
10471 { /* Custom */
10472 "ZZM",
10473 .bg_channels = 11,
10474 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10475 {2427, 4}, {2432, 5}, {2437, 6},
10476 {2442, 7}, {2447, 8}, {2452, 9},
10477 {2457, 10}, {2462, 11}},
10478 },
10479
10480 { /* Europe */
10481 "ZZE",
10482 .bg_channels = 13,
10483 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10484 {2427, 4}, {2432, 5}, {2437, 6},
10485 {2442, 7}, {2447, 8}, {2452, 9},
10486 {2457, 10}, {2462, 11}, {2467, 12},
10487 {2472, 13}},
10488 .a_channels = 19,
10489 .a = {{5180, 36},
10490 {5200, 40},
10491 {5220, 44},
10492 {5240, 48},
10493 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10494 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10495 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10496 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10497 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10498 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10499 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10500 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10501 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10502 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10503 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10504 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10505 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10506 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10507 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10508 },
10509
10510 { /* Custom Japan */
10511 "ZZJ",
10512 .bg_channels = 14,
10513 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10514 {2427, 4}, {2432, 5}, {2437, 6},
10515 {2442, 7}, {2447, 8}, {2452, 9},
10516 {2457, 10}, {2462, 11}, {2467, 12},
10517 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10518 .a_channels = 4,
10519 .a = {{5170, 34}, {5190, 38},
10520 {5210, 42}, {5230, 46}},
10521 },
10522
James Ketrenos03520572005-10-19 16:12:31 -050010523 { /* Rest of World */
10524 "ZZR",
10525 .bg_channels = 14,
10526 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10527 {2427, 4}, {2432, 5}, {2437, 6},
10528 {2442, 7}, {2447, 8}, {2452, 9},
10529 {2457, 10}, {2462, 11}, {2467, 12},
10530 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10531 IEEE80211_CH_PASSIVE_ONLY}},
10532 },
10533
James Ketrenos4f36f802005-08-03 20:36:56 -050010534 { /* High Band */
10535 "ZZH",
10536 .bg_channels = 13,
10537 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10538 {2427, 4}, {2432, 5}, {2437, 6},
10539 {2442, 7}, {2447, 8}, {2452, 9},
10540 {2457, 10}, {2462, 11},
10541 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10542 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10543 .a_channels = 4,
10544 .a = {{5745, 149}, {5765, 153},
10545 {5785, 157}, {5805, 161}},
10546 },
10547
10548 { /* Custom Europe */
10549 "ZZG",
10550 .bg_channels = 13,
10551 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10552 {2427, 4}, {2432, 5}, {2437, 6},
10553 {2442, 7}, {2447, 8}, {2452, 9},
10554 {2457, 10}, {2462, 11},
10555 {2467, 12}, {2472, 13}},
10556 .a_channels = 4,
10557 .a = {{5180, 36}, {5200, 40},
10558 {5220, 44}, {5240, 48}},
10559 },
10560
10561 { /* Europe */
10562 "ZZK",
10563 .bg_channels = 13,
10564 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10565 {2427, 4}, {2432, 5}, {2437, 6},
10566 {2442, 7}, {2447, 8}, {2452, 9},
10567 {2457, 10}, {2462, 11},
10568 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10569 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10570 .a_channels = 24,
10571 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10572 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10573 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10574 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10575 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10576 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10577 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10578 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10579 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10580 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10581 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10582 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10583 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10584 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10585 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10586 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10587 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10588 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10589 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10590 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10591 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10592 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10593 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10594 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10595 },
10596
10597 { /* Europe */
10598 "ZZL",
10599 .bg_channels = 11,
10600 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10601 {2427, 4}, {2432, 5}, {2437, 6},
10602 {2442, 7}, {2447, 8}, {2452, 9},
10603 {2457, 10}, {2462, 11}},
10604 .a_channels = 13,
10605 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10606 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10607 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10608 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10609 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10610 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10611 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10612 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10613 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10614 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10615 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10616 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10617 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10618 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010619};
10620
Liu Hong1fe0adb2005-08-19 09:33:10 -050010621/* GEO code borrowed from ieee80211_geo.c */
10622static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
10623{
10624 int i;
10625
10626 /* Driver needs to initialize the geography map before using
10627 * these helper functions */
10628 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10629
10630 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10631 for (i = 0; i < ieee->geo.bg_channels; i++)
10632 /* NOTE: If G mode is currently supported but
10633 * this is a B only channel, we don't see it
10634 * as valid. */
10635 if ((ieee->geo.bg[i].channel == channel) &&
10636 (!(ieee->mode & IEEE_G) ||
10637 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
10638 return IEEE80211_24GHZ_BAND;
10639
10640 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10641 for (i = 0; i < ieee->geo.a_channels; i++)
10642 if (ieee->geo.a[i].channel == channel)
10643 return IEEE80211_52GHZ_BAND;
10644
10645 return 0;
10646}
10647
10648static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
10649{
10650 int i;
10651
10652 /* Driver needs to initialize the geography map before using
10653 * these helper functions */
10654 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10655
10656 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10657 for (i = 0; i < ieee->geo.bg_channels; i++)
10658 if (ieee->geo.bg[i].channel == channel)
10659 return i;
10660
10661 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10662 for (i = 0; i < ieee->geo.a_channels; i++)
10663 if (ieee->geo.a[i].channel == channel)
10664 return i;
10665
10666 return -1;
10667}
10668
10669static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
10670{
10671 int i;
10672
10673 /* Driver needs to initialize the geography map before using
10674 * these helper functions */
10675 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10676
10677 freq /= 100000;
10678
10679 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10680 for (i = 0; i < ieee->geo.bg_channels; i++)
10681 if (ieee->geo.bg[i].freq == freq)
10682 return ieee->geo.bg[i].channel;
10683
10684 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10685 for (i = 0; i < ieee->geo.a_channels; i++)
10686 if (ieee->geo.a[i].freq == freq)
10687 return ieee->geo.a[i].channel;
10688
10689 return 0;
10690}
10691
10692static int ipw_set_geo(struct ieee80211_device *ieee,
10693 const struct ieee80211_geo *geo)
10694{
10695 memcpy(ieee->geo.name, geo->name, 3);
10696 ieee->geo.name[3] = '\0';
10697 ieee->geo.bg_channels = geo->bg_channels;
10698 ieee->geo.a_channels = geo->a_channels;
10699 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
10700 sizeof(struct ieee80211_channel));
10701 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
10702 sizeof(struct ieee80211_channel));
10703 return 0;
10704}
10705
10706static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
10707{
10708 return &ieee->geo;
10709}
10710
James Ketrenos43f66a62005-03-25 12:31:53 -060010711#define MAX_HW_RESTARTS 5
10712static int ipw_up(struct ipw_priv *priv)
10713{
James Ketrenos4f36f802005-08-03 20:36:56 -050010714 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010715
10716 if (priv->status & STATUS_EXIT_PENDING)
10717 return -EIO;
10718
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010719 if (cmdlog && !priv->cmdlog) {
10720 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10721 GFP_KERNEL);
10722 if (priv->cmdlog == NULL) {
10723 IPW_ERROR("Error allocating %d command log entries.\n",
10724 cmdlog);
10725 } else {
10726 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10727 priv->cmdlog_len = cmdlog;
10728 }
10729 }
10730
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010731 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010732 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010733 * Also start the clocks. */
10734 rc = ipw_load(priv);
10735 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010736 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010737 return rc;
10738 }
10739
10740 ipw_init_ordinals(priv);
10741 if (!(priv->config & CFG_CUSTOM_MAC))
10742 eeprom_parse_mac(priv, priv->mac_addr);
10743 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10744
James Ketrenos4f36f802005-08-03 20:36:56 -050010745 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10746 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10747 ipw_geos[j].name, 3))
10748 break;
10749 }
James Ketrenos03520572005-10-19 16:12:31 -050010750 if (j == ARRAY_SIZE(ipw_geos)) {
10751 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10752 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10753 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10754 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010755 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010756 }
Liu Hong1fe0adb2005-08-19 09:33:10 -050010757 if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010758 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010759 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010760 }
10761
10762 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10763 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010764
James Ketrenosb095c382005-08-24 22:04:42 -050010765 if (priv->status & STATUS_RF_KILL_SW) {
10766 IPW_WARNING("Radio disabled by module parameter.\n");
10767 return 0;
10768 } else if (rf_kill_active(priv)) {
10769 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10770 "Kill switch must be turned off for "
10771 "wireless networking to work.\n");
10772 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10773 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010774 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010775 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010776
10777 rc = ipw_config(priv);
10778 if (!rc) {
10779 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010780
James Ketrenose6666192005-08-12 09:17:04 -050010781 /* If configure to try and auto-associate, kick
10782 * off a scan. */
10783 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010784
James Ketrenos43f66a62005-03-25 12:31:53 -060010785 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010786 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010787
James Ketrenosc848d0a2005-08-24 21:56:24 -050010788 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010789 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10790 i, MAX_HW_RESTARTS);
10791
10792 /* We had an error bringing up the hardware, so take it
10793 * all the way back down so we can try again */
10794 ipw_down(priv);
10795 }
10796
Jeff Garzikbf794512005-07-31 13:07:26 -040010797 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010798 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010799 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010800
James Ketrenos43f66a62005-03-25 12:31:53 -060010801 return -EIO;
10802}
10803
James Ketrenosc848d0a2005-08-24 21:56:24 -050010804static void ipw_bg_up(void *data)
10805{
10806 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010807 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010808 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010809 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010810}
10811
James Ketrenosb095c382005-08-24 22:04:42 -050010812static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010813{
James Ketrenosb095c382005-08-24 22:04:42 -050010814 int i;
10815
10816 if (priv->status & STATUS_SCANNING) {
10817 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10818 ipw_abort_scan(priv);
10819 }
10820
10821 if (priv->status & STATUS_ASSOCIATED) {
10822 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10823 ipw_disassociate(priv);
10824 }
10825
10826 ipw_led_shutdown(priv);
10827
10828 /* Wait up to 1s for status to change to not scanning and not
10829 * associated (disassociation can take a while for a ful 802.11
10830 * exchange */
10831 for (i = 1000; i && (priv->status &
10832 (STATUS_DISASSOCIATING |
10833 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10834 udelay(10);
10835
10836 if (priv->status & (STATUS_DISASSOCIATING |
10837 STATUS_ASSOCIATED | STATUS_SCANNING))
10838 IPW_DEBUG_INFO("Still associated or scanning...\n");
10839 else
10840 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10841
James Ketrenosc848d0a2005-08-24 21:56:24 -050010842 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010843 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010844
10845 priv->status &= ~STATUS_INIT;
10846}
10847
James Ketrenos43f66a62005-03-25 12:31:53 -060010848static void ipw_down(struct ipw_priv *priv)
10849{
James Ketrenosb095c382005-08-24 22:04:42 -050010850 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10851
10852 priv->status |= STATUS_EXIT_PENDING;
10853
10854 if (ipw_is_init(priv))
10855 ipw_deinit(priv);
10856
10857 /* Wipe out the EXIT_PENDING status bit if we are not actually
10858 * exiting the module */
10859 if (!exit_pending)
10860 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010861
10862 /* tell the device to stop sending interrupts */
10863 ipw_disable_interrupts(priv);
10864
10865 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010866 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010867 netif_carrier_off(priv->net_dev);
10868 netif_stop_queue(priv->net_dev);
10869
10870 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010871
10872 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010873}
10874
James Ketrenosc848d0a2005-08-24 21:56:24 -050010875static void ipw_bg_down(void *data)
10876{
10877 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010878 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010879 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010880 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010881}
10882
10883/* Called by register_netdev() */
10884static int ipw_net_init(struct net_device *dev)
10885{
10886 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010887 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010888
James Ketrenosc848d0a2005-08-24 21:56:24 -050010889 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080010890 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010891 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 }
10893
Zhu Yi46441512006-01-24 16:37:59 +080010894 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010895 return 0;
10896}
10897
10898/* PCI driver stuff */
10899static struct pci_device_id card_ids[] = {
10900 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10901 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10902 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10903 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10904 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10905 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10906 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10907 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10908 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10909 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10910 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10911 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10912 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10913 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10914 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10915 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10916 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10917 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010918 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010919 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010920 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10921 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010922
James Ketrenos43f66a62005-03-25 12:31:53 -060010923 /* required last entry */
10924 {0,}
10925};
10926
10927MODULE_DEVICE_TABLE(pci, card_ids);
10928
10929static struct attribute *ipw_sysfs_entries[] = {
10930 &dev_attr_rf_kill.attr,
10931 &dev_attr_direct_dword.attr,
10932 &dev_attr_indirect_byte.attr,
10933 &dev_attr_indirect_dword.attr,
10934 &dev_attr_mem_gpio_reg.attr,
10935 &dev_attr_command_event_reg.attr,
10936 &dev_attr_nic_type.attr,
10937 &dev_attr_status.attr,
10938 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010939 &dev_attr_error.attr,
10940 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010941 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010942 &dev_attr_eeprom_delay.attr,
10943 &dev_attr_ucode_version.attr,
10944 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010945 &dev_attr_scan_age.attr,
10946 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010947 &dev_attr_speed_scan.attr,
10948 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010949 NULL
10950};
10951
10952static struct attribute_group ipw_attribute_group = {
10953 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010954 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010955};
10956
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010957static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010958{
10959 int err = 0;
10960 struct net_device *net_dev;
10961 void __iomem *base;
10962 u32 length, val;
10963 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010964 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010965
10966 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10967 if (net_dev == NULL) {
10968 err = -ENOMEM;
10969 goto out;
10970 }
10971
10972 priv = ieee80211_priv(net_dev);
10973 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010974
James Ketrenos43f66a62005-03-25 12:31:53 -060010975 priv->net_dev = net_dev;
10976 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080010977#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060010978 ipw_debug_level = debug;
10979#endif
10980 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010981 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10982 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010983
Zhu Yi46441512006-01-24 16:37:59 +080010984 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010985 if (pci_enable_device(pdev)) {
10986 err = -ENODEV;
10987 goto out_free_ieee80211;
10988 }
10989
10990 pci_set_master(pdev);
10991
Tobias Klauser0e08b442005-06-20 14:28:41 -070010992 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010993 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010994 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010995 if (err) {
10996 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10997 goto out_pci_disable_device;
10998 }
10999
11000 pci_set_drvdata(pdev, priv);
11001
11002 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011003 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011004 goto out_pci_disable_device;
11005
Jeff Garzikbf794512005-07-31 13:07:26 -040011006 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011007 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011008 pci_read_config_dword(pdev, 0x40, &val);
11009 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011010 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011011
James Ketrenos43f66a62005-03-25 12:31:53 -060011012 length = pci_resource_len(pdev, 0);
11013 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011014
James Ketrenos43f66a62005-03-25 12:31:53 -060011015 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11016 if (!base) {
11017 err = -ENODEV;
11018 goto out_pci_release_regions;
11019 }
11020
11021 priv->hw_base = base;
11022 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11023 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11024
11025 err = ipw_setup_deferred_work(priv);
11026 if (err) {
11027 IPW_ERROR("Unable to setup deferred work\n");
11028 goto out_iounmap;
11029 }
11030
James Ketrenosb095c382005-08-24 22:04:42 -050011031 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011032
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011033 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011034 if (err) {
11035 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11036 goto out_destroy_workqueue;
11037 }
11038
11039 SET_MODULE_OWNER(net_dev);
11040 SET_NETDEV_DEV(net_dev, &pdev->dev);
11041
Zhu Yi46441512006-01-24 16:37:59 +080011042 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011043
James Ketrenos43f66a62005-03-25 12:31:53 -060011044 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11045 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011046 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011047
James Ketrenosb095c382005-08-24 22:04:42 -050011048#ifdef CONFIG_IPW_QOS
James Ketrenos3b9990c2005-08-19 13:18:55 -050011049 priv->ieee->handle_probe_response = ipw_handle_beacon;
11050 priv->ieee->handle_beacon = ipw_handle_probe_response;
11051 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050011052#endif /* CONFIG_IPW_QOS */
11053
James Ketrenosc848d0a2005-08-24 21:56:24 -050011054 priv->ieee->perfect_rssi = -20;
11055 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011056
11057 net_dev->open = ipw_net_open;
11058 net_dev->stop = ipw_net_stop;
11059 net_dev->init = ipw_net_init;
11060 net_dev->get_stats = ipw_net_get_stats;
11061 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11062 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011063 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011064 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011065 net_dev->wireless_handlers = &ipw_wx_handler_def;
11066 net_dev->ethtool_ops = &ipw_ethtool_ops;
11067 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011068 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011069 net_dev->mem_start = pci_resource_start(pdev, 0);
11070 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11071
11072 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11073 if (err) {
11074 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011075 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011076 goto out_release_irq;
11077 }
11078
Zhu Yi46441512006-01-24 16:37:59 +080011079 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011080 err = register_netdev(net_dev);
11081 if (err) {
11082 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011083 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011084 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011085 return 0;
11086
James Ketrenosa613bff2005-08-24 21:43:11 -050011087 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011088 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011089 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011091 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011092 destroy_workqueue(priv->workqueue);
11093 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011094 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011095 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011096 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011097 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011098 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011099 pci_disable_device(pdev);
11100 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011101 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011102 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011103 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011104 return err;
11105}
11106
11107static void ipw_pci_remove(struct pci_dev *pdev)
11108{
11109 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011110 struct list_head *p, *q;
11111 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011112
James Ketrenos43f66a62005-03-25 12:31:53 -060011113 if (!priv)
11114 return;
11115
Zhu Yi46441512006-01-24 16:37:59 +080011116 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011117
James Ketrenosafbf30a2005-08-25 00:05:33 -050011118 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011119 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011120 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11121
Zhu Yi46441512006-01-24 16:37:59 +080011122 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011123
11124 unregister_netdev(priv->net_dev);
11125
11126 if (priv->rxq) {
11127 ipw_rx_queue_free(priv, priv->rxq);
11128 priv->rxq = NULL;
11129 }
11130 ipw_tx_queue_free(priv);
11131
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011132 if (priv->cmdlog) {
11133 kfree(priv->cmdlog);
11134 priv->cmdlog = NULL;
11135 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011136 /* ipw_down will ensure that there is no more pending work
11137 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011138 cancel_delayed_work(&priv->adhoc_check);
11139 cancel_delayed_work(&priv->gather_stats);
11140 cancel_delayed_work(&priv->request_scan);
11141 cancel_delayed_work(&priv->rf_kill);
11142 cancel_delayed_work(&priv->scan_check);
11143 destroy_workqueue(priv->workqueue);
11144 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011145
James Ketrenosafbf30a2005-08-25 00:05:33 -050011146 /* Free MAC hash list for ADHOC */
11147 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11148 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011149 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011150 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011151 }
11152 }
11153
James Ketrenosb39860c2005-08-12 09:36:32 -050011154 if (priv->error) {
11155 ipw_free_error_log(priv->error);
11156 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011157 }
11158
11159 free_irq(pdev->irq, priv);
11160 iounmap(priv->hw_base);
11161 pci_release_regions(pdev);
11162 pci_disable_device(pdev);
11163 pci_set_drvdata(pdev, NULL);
11164 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011165 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011166}
11167
James Ketrenos43f66a62005-03-25 12:31:53 -060011168#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011169static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011170{
11171 struct ipw_priv *priv = pci_get_drvdata(pdev);
11172 struct net_device *dev = priv->net_dev;
11173
11174 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11175
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011176 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011177 ipw_down(priv);
11178
11179 /* Remove the PRESENT state of the device */
11180 netif_device_detach(dev);
11181
James Ketrenos43f66a62005-03-25 12:31:53 -060011182 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011183 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011184 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011185
James Ketrenos43f66a62005-03-25 12:31:53 -060011186 return 0;
11187}
11188
11189static int ipw_pci_resume(struct pci_dev *pdev)
11190{
11191 struct ipw_priv *priv = pci_get_drvdata(pdev);
11192 struct net_device *dev = priv->net_dev;
11193 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011194
James Ketrenos43f66a62005-03-25 12:31:53 -060011195 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11196
James Ketrenosea2b26e2005-08-24 21:25:16 -050011197 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011198 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011199 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011200
James Ketrenos43f66a62005-03-25 12:31:53 -060011201 /*
11202 * Suspend/Resume resets the PCI configuration space, so we have to
11203 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11204 * from interfering with C3 CPU state. pci_restore_state won't help
11205 * here since it only restores the first 64 bytes pci config header.
11206 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011207 pci_read_config_dword(pdev, 0x40, &val);
11208 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011209 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11210
11211 /* Set the device back into the PRESENT state; this will also wake
11212 * the queue of needed */
11213 netif_device_attach(dev);
11214
11215 /* Bring the device back up */
11216 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011217
James Ketrenos43f66a62005-03-25 12:31:53 -060011218 return 0;
11219}
11220#endif
11221
11222/* driver initialization stuff */
11223static struct pci_driver ipw_driver = {
11224 .name = DRV_NAME,
11225 .id_table = card_ids,
11226 .probe = ipw_pci_probe,
11227 .remove = __devexit_p(ipw_pci_remove),
11228#ifdef CONFIG_PM
11229 .suspend = ipw_pci_suspend,
11230 .resume = ipw_pci_resume,
11231#endif
11232};
11233
11234static int __init ipw_init(void)
11235{
11236 int ret;
11237
11238 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11239 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11240
11241 ret = pci_module_init(&ipw_driver);
11242 if (ret) {
11243 IPW_ERROR("Unable to initialize PCI module\n");
11244 return ret;
11245 }
11246
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011247 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011248 if (ret) {
11249 IPW_ERROR("Unable to create driver sysfs file\n");
11250 pci_unregister_driver(&ipw_driver);
11251 return ret;
11252 }
11253
11254 return ret;
11255}
11256
11257static void __exit ipw_exit(void)
11258{
11259 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11260 pci_unregister_driver(&ipw_driver);
11261}
11262
11263module_param(disable, int, 0444);
11264MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11265
11266module_param(associate, int, 0444);
11267MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11268
11269module_param(auto_create, int, 0444);
11270MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11271
James Ketrenosa613bff2005-08-24 21:43:11 -050011272module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011273MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011274
James Ketrenos43f66a62005-03-25 12:31:53 -060011275module_param(debug, int, 0444);
11276MODULE_PARM_DESC(debug, "debug output mask");
11277
11278module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011279MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011280
James Ketrenosb095c382005-08-24 22:04:42 -050011281#ifdef CONFIG_IPW_QOS
11282module_param(qos_enable, int, 0444);
11283MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011284
James Ketrenosb095c382005-08-24 22:04:42 -050011285module_param(qos_burst_enable, int, 0444);
11286MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11287
11288module_param(qos_no_ack_mask, int, 0444);
11289MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11290
11291module_param(burst_duration_CCK, int, 0444);
11292MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11293
11294module_param(burst_duration_OFDM, int, 0444);
11295MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11296#endif /* CONFIG_IPW_QOS */
11297
11298#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011299module_param(mode, int, 0444);
11300MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11301#else
11302module_param(mode, int, 0444);
11303MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11304#endif
11305
Zhu Yi810dabd2006-01-24 16:36:59 +080011306module_param(bt_coexist, int, 0444);
11307MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11308
James Ketrenosb095c382005-08-24 22:04:42 -050011309module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011310MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011311
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011312module_param(cmdlog, int, 0444);
11313MODULE_PARM_DESC(cmdlog,
11314 "allocate a ring buffer for logging firmware commands");
11315
Zhu Yi4bfdb912006-01-24 16:37:16 +080011316module_param(roaming, int, 0444);
11317MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11318
James Ketrenos43f66a62005-03-25 12:31:53 -060011319module_exit(ipw_exit);
11320module_init(ipw_init);