blob: 072746c07a9c7931d7415f1a48229824d9282f54 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenosafbf30a2005-08-25 00:05:33 -05003 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
James Ketrenoscf1b4792005-10-20 16:35:24 -050036#define IPW2200_VERSION "git-1.0.8"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
James Ketrenos2b184d52005-08-03 20:33:14 -050038#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060039#define DRV_VERSION IPW2200_VERSION
40
James Ketrenosb095c382005-08-24 22:04:42 -050041#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
James Ketrenos43f66a62005-03-25 12:31:53 -060043MODULE_DESCRIPTION(DRV_DESCRIPTION);
44MODULE_VERSION(DRV_VERSION);
45MODULE_AUTHOR(DRV_COPYRIGHT);
46MODULE_LICENSE("GPL");
47
James Ketrenosf6c5cb72005-08-25 00:39:09 -050048static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060049static int debug = 0;
50static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060051static int mode = 0;
52
53static u32 ipw_debug_level;
54static int associate = 1;
55static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050056static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060057static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080058static int bt_coexist = 0;
James Ketrenosb095c382005-08-24 22:04:42 -050059static int hwcrypto = 1;
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
276/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600277#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800278
279/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600280#define ipw_write16(ipw, ofs, val) \
281 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
282 _ipw_write16(ipw, ofs, val)
283
Zhu Yic8fe6672006-01-24 16:36:36 +0800284
285/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600286#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800287
288/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600289#define ipw_write32(ipw, ofs, val) \
290 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
291 _ipw_write32(ipw, ofs, val)
292
Zhu Yic8fe6672006-01-24 16:36:36 +0800293
294/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600295#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800296
297/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400298static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
299{
300 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600301 return _ipw_read8(ipw, ofs);
302}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400303
Zhu Yic8fe6672006-01-24 16:36:36 +0800304/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600305#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
306
Zhu Yic8fe6672006-01-24 16:36:36 +0800307
308/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600309#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800310
311/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400312static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
313{
314 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600315 return _ipw_read16(ipw, ofs);
316}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400317
Zhu Yic8fe6672006-01-24 16:36:36 +0800318/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600319#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
320
Zhu Yic8fe6672006-01-24 16:36:36 +0800321
322/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600323#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800324
325/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400326static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
327{
328 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600329 return _ipw_read32(ipw, ofs);
330}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400331
Zhu Yic8fe6672006-01-24 16:36:36 +0800332/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600333#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
334
Zhu Yic8fe6672006-01-24 16:36:36 +0800335
336/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600337static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500338static inline void __ipw_read_indirect(const char *f, int l,
339 struct ipw_priv *a, u32 b, u8 * c, int d)
340{
341 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
342 d);
343 _ipw_read_indirect(a, b, c, d);
344}
345
Zhu Yic8fe6672006-01-24 16:36:36 +0800346/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500347#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600348
Zhu Yic8fe6672006-01-24 16:36:36 +0800349/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400350static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
351 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600352#define ipw_write_indirect(a, b, c, d) \
353 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500354 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600355
Zhu Yic8fe6672006-01-24 16:36:36 +0800356/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400357static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600358{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400359 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500360 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
361 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600362}
363
Zhu Yic8fe6672006-01-24 16:36:36 +0800364/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600365static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
366{
Zhu Yic8fe6672006-01-24 16:36:36 +0800367 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
368 u32 dif_len = reg - aligned_addr;
369
James Ketrenos43f66a62005-03-25 12:31:53 -0600370 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800371 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
372 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600373}
374
Zhu Yic8fe6672006-01-24 16:36:36 +0800375/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400376static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600377{
Zhu Yic8fe6672006-01-24 16:36:36 +0800378 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
379 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
380
James Ketrenos43f66a62005-03-25 12:31:53 -0600381 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800382 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
383 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600384}
385
James Ketrenos43f66a62005-03-25 12:31:53 -0600386
Zhu Yic8fe6672006-01-24 16:36:36 +0800387/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600388static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
389{
390 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500391 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600392 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500393 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400394 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600395}
396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600398static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
399{
400 u32 value;
401
402 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
403
James Ketrenosb095c382005-08-24 22:04:42 -0500404 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
405 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600406 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
407 return value;
408}
409
Zhu Yic8fe6672006-01-24 16:36:36 +0800410/* General purpose, no alignment requirement, iterative (multi-byte) read, */
411/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600412static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
413 int num)
414{
Zhu Yic8fe6672006-01-24 16:36:36 +0800415 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600416 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600417 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400418
James Ketrenos43f66a62005-03-25 12:31:53 -0600419 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
420
James Ketrenosea2b26e2005-08-24 21:25:16 -0500421 if (num <= 0) {
422 return;
423 }
424
Zhu Yic8fe6672006-01-24 16:36:36 +0800425 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600426 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500427 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600428 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500429 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500430 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600431 aligned_addr += 4;
432 }
433
Zhu Yic8fe6672006-01-24 16:36:36 +0800434 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500435 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500436 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500437 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400438
Zhu Yic8fe6672006-01-24 16:36:36 +0800439 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500440 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500441 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500442 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500443 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500444 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600445}
446
Zhu Yic8fe6672006-01-24 16:36:36 +0800447/* General purpose, no alignment requirement, iterative (multi-byte) write, */
448/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400449static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600450 int num)
451{
Zhu Yic8fe6672006-01-24 16:36:36 +0800452 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600453 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600454 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400455
James Ketrenos43f66a62005-03-25 12:31:53 -0600456 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400457
James Ketrenosea2b26e2005-08-24 21:25:16 -0500458 if (num <= 0) {
459 return;
460 }
461
Zhu Yic8fe6672006-01-24 16:36:36 +0800462 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600463 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500464 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800465 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500466 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600468 aligned_addr += 4;
469 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400470
Zhu Yic8fe6672006-01-24 16:36:36 +0800471 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500472 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500473 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500474 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400475
Zhu Yic8fe6672006-01-24 16:36:36 +0800476 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500477 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500478 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500479 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500480 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500481 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600482}
483
Zhu Yic8fe6672006-01-24 16:36:36 +0800484/* General purpose, no alignment requirement, iterative (multi-byte) write, */
485/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400486static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 int num)
488{
489 memcpy_toio((priv->hw_base + addr), buf, num);
490}
491
Zhu Yic8fe6672006-01-24 16:36:36 +0800492/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600493static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
494{
495 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
496}
497
Zhu Yic8fe6672006-01-24 16:36:36 +0800498/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600499static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
500{
501 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
502}
503
504static inline void ipw_enable_interrupts(struct ipw_priv *priv)
505{
506 if (priv->status & STATUS_INT_ENABLED)
507 return;
508 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500509 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600510}
511
512static inline void ipw_disable_interrupts(struct ipw_priv *priv)
513{
514 if (!(priv->status & STATUS_INT_ENABLED))
515 return;
516 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500517 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600518}
519
Brice Goglin0f52bf92005-12-01 01:41:46 -0800520#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600521static char *ipw_error_desc(u32 val)
522{
523 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400524 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600525 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400526 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600527 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400528 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600529 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400530 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600531 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400532 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500533 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400534 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500535 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400536 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500537 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400538 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500539 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400540 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500541 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400542 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500543 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400544 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500545 return "DMA_STATUS";
546 case IPW_FW_ERROR_DINO_ERROR:
547 return "DINO_ERROR";
548 case IPW_FW_ERROR_EEPROM_ERROR:
549 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400550 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500551 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400552 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500553 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400554 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500555 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600556 }
557}
558
James Ketrenosb39860c2005-08-12 09:36:32 -0500559static void ipw_dump_error_log(struct ipw_priv *priv,
560 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600561{
James Ketrenosb39860c2005-08-12 09:36:32 -0500562 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600563
James Ketrenosb39860c2005-08-12 09:36:32 -0500564 if (!error) {
565 IPW_ERROR("Error allocating and capturing error log. "
566 "Nothing to dump.\n");
567 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600568 }
569
James Ketrenosb39860c2005-08-12 09:36:32 -0500570 IPW_ERROR("Start IPW Error Log Dump:\n");
571 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
572 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600573
James Ketrenosb39860c2005-08-12 09:36:32 -0500574 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400575 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500576 ipw_error_desc(error->elem[i].desc),
577 error->elem[i].time,
578 error->elem[i].blink1,
579 error->elem[i].blink2,
580 error->elem[i].link1,
581 error->elem[i].link2, error->elem[i].data);
582 for (i = 0; i < error->log_len; i++)
583 IPW_ERROR("%i\t0x%08x\t%i\n",
584 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500585 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600586}
James Ketrenos43f66a62005-03-25 12:31:53 -0600587#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600588
James Ketrenosc848d0a2005-08-24 21:56:24 -0500589static inline int ipw_is_init(struct ipw_priv *priv)
590{
591 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600592}
593
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400594static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600595{
596 u32 addr, field_info, field_len, field_count, total_len;
597
598 IPW_DEBUG_ORD("ordinal = %i\n", ord);
599
600 if (!priv || !val || !len) {
601 IPW_DEBUG_ORD("Invalid argument\n");
602 return -EINVAL;
603 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400604
James Ketrenos43f66a62005-03-25 12:31:53 -0600605 /* verify device ordinal tables have been initialized */
606 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
607 IPW_DEBUG_ORD("Access ordinals before initialization\n");
608 return -EINVAL;
609 }
610
611 switch (IPW_ORD_TABLE_ID_MASK & ord) {
612 case IPW_ORD_TABLE_0_MASK:
613 /*
614 * TABLE 0: Direct access to a table of 32 bit values
615 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400616 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600617 * read from the table
618 */
619
620 /* remove the table id from the ordinal */
621 ord &= IPW_ORD_TABLE_VALUE_MASK;
622
623 /* boundary check */
624 if (ord > priv->table0_len) {
625 IPW_DEBUG_ORD("ordinal value (%i) longer then "
626 "max (%i)\n", ord, priv->table0_len);
627 return -EINVAL;
628 }
629
630 /* verify we have enough room to store the value */
631 if (*len < sizeof(u32)) {
632 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200633 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600634 return -EINVAL;
635 }
636
637 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400638 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600639
640 *len = sizeof(u32);
641 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400642 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600643 break;
644
645 case IPW_ORD_TABLE_1_MASK:
646 /*
647 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400648 *
649 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600650 * representing starting addr for the data (which is
651 * also a u32)
652 */
653
654 /* remove the table id from the ordinal */
655 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400656
James Ketrenos43f66a62005-03-25 12:31:53 -0600657 /* boundary check */
658 if (ord > priv->table1_len) {
659 IPW_DEBUG_ORD("ordinal value too long\n");
660 return -EINVAL;
661 }
662
663 /* verify we have enough room to store the value */
664 if (*len < sizeof(u32)) {
665 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200666 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600667 return -EINVAL;
668 }
669
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400670 *((u32 *) val) =
671 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600672 *len = sizeof(u32);
673 break;
674
675 case IPW_ORD_TABLE_2_MASK:
676 /*
677 * TABLE 2: Indirect access to a table of variable sized values
678 *
679 * This table consist of six values, each containing
680 * - dword containing the starting offset of the data
681 * - dword containing the lengh in the first 16bits
682 * and the count in the second 16bits
683 */
684
685 /* remove the table id from the ordinal */
686 ord &= IPW_ORD_TABLE_VALUE_MASK;
687
688 /* boundary check */
689 if (ord > priv->table2_len) {
690 IPW_DEBUG_ORD("ordinal value too long\n");
691 return -EINVAL;
692 }
693
694 /* get the address of statistic */
695 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400696
697 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600698 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400699 field_info =
700 ipw_read_reg32(priv,
701 priv->table2_addr + (ord << 3) +
702 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400703
James Ketrenos43f66a62005-03-25 12:31:53 -0600704 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400705 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400706
James Ketrenos43f66a62005-03-25 12:31:53 -0600707 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400708 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400709
James Ketrenos43f66a62005-03-25 12:31:53 -0600710 /* abort if not enought memory */
711 total_len = field_len * field_count;
712 if (total_len > *len) {
713 *len = total_len;
714 return -EINVAL;
715 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400716
James Ketrenos43f66a62005-03-25 12:31:53 -0600717 *len = total_len;
718 if (!total_len)
719 return 0;
720
721 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400722 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600723 addr, total_len, field_info);
724 ipw_read_indirect(priv, addr, val, total_len);
725 break;
726
727 default:
728 IPW_DEBUG_ORD("Invalid ordinal!\n");
729 return -EINVAL;
730
731 }
732
James Ketrenos43f66a62005-03-25 12:31:53 -0600733 return 0;
734}
735
736static void ipw_init_ordinals(struct ipw_priv *priv)
737{
738 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400739 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600740
741 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
742 priv->table0_addr, priv->table0_len);
743
744 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
745 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
746
747 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
748 priv->table1_addr, priv->table1_len);
749
750 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
751 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400752 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600753
754 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
755 priv->table2_addr, priv->table2_len);
756
757}
758
Adrian Bunka73e22b2006-01-21 01:39:42 +0100759static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500760{
James Ketrenosb095c382005-08-24 22:04:42 -0500761 reg &= ~IPW_START_STANDBY;
762 if (reg & IPW_GATE_ODMA)
763 reg &= ~IPW_GATE_ODMA;
764 if (reg & IPW_GATE_IDMA)
765 reg &= ~IPW_GATE_IDMA;
766 if (reg & IPW_GATE_ADMA)
767 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500768 return reg;
769}
770
771/*
772 * LED behavior:
773 * - On radio ON, turn on any LEDs that require to be on during start
774 * - On initialization, start unassociated blink
775 * - On association, disable unassociated blink
776 * - On disassociation, start unassociated blink
777 * - On radio OFF, turn off any LEDs started during radio on
778 *
779 */
Zhu Yiede61112006-01-24 16:37:10 +0800780#define LD_TIME_LINK_ON msecs_to_jiffies(300)
781#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
782#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500783
Adrian Bunka73e22b2006-01-21 01:39:42 +0100784static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500785{
786 unsigned long flags;
787 u32 led;
788
789 /* If configured to not use LEDs, or nic_type is 1,
790 * then we don't toggle a LINK led */
791 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
792 return;
793
794 spin_lock_irqsave(&priv->lock, flags);
795
796 if (!(priv->status & STATUS_RF_KILL_MASK) &&
797 !(priv->status & STATUS_LED_LINK_ON)) {
798 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500799 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500800 led |= priv->led_association_on;
801
802 led = ipw_register_toggle(led);
803
804 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500805 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500806
807 priv->status |= STATUS_LED_LINK_ON;
808
809 /* If we aren't associated, schedule turning the LED off */
810 if (!(priv->status & STATUS_ASSOCIATED))
811 queue_delayed_work(priv->workqueue,
812 &priv->led_link_off,
813 LD_TIME_LINK_ON);
814 }
815
816 spin_unlock_irqrestore(&priv->lock, flags);
817}
818
James Ketrenosc848d0a2005-08-24 21:56:24 -0500819static void ipw_bg_led_link_on(void *data)
820{
821 struct ipw_priv *priv = data;
822 down(&priv->sem);
823 ipw_led_link_on(data);
824 up(&priv->sem);
825}
826
Adrian Bunka73e22b2006-01-21 01:39:42 +0100827static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500828{
829 unsigned long flags;
830 u32 led;
831
832 /* If configured not to use LEDs, or nic type is 1,
833 * then we don't goggle the LINK led. */
834 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
835 return;
836
837 spin_lock_irqsave(&priv->lock, flags);
838
839 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500840 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500841 led &= priv->led_association_off;
842 led = ipw_register_toggle(led);
843
844 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500845 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500846
847 IPW_DEBUG_LED("Link LED Off\n");
848
849 priv->status &= ~STATUS_LED_LINK_ON;
850
851 /* If we aren't associated and the radio is on, schedule
852 * turning the LED on (blink while unassociated) */
853 if (!(priv->status & STATUS_RF_KILL_MASK) &&
854 !(priv->status & STATUS_ASSOCIATED))
855 queue_delayed_work(priv->workqueue, &priv->led_link_on,
856 LD_TIME_LINK_OFF);
857
858 }
859
860 spin_unlock_irqrestore(&priv->lock, flags);
861}
862
James Ketrenosc848d0a2005-08-24 21:56:24 -0500863static void ipw_bg_led_link_off(void *data)
864{
865 struct ipw_priv *priv = data;
866 down(&priv->sem);
867 ipw_led_link_off(data);
868 up(&priv->sem);
869}
870
Arjan van de Ven858119e2006-01-14 13:20:43 -0800871static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500872{
James Ketrenosa613bff2005-08-24 21:43:11 -0500873 u32 led;
874
875 if (priv->config & CFG_NO_LED)
876 return;
877
James Ketrenosb095c382005-08-24 22:04:42 -0500878 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500879 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500880
881 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500882 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500883 led |= priv->led_activity_on;
884
885 led = ipw_register_toggle(led);
886
887 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500888 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500889
890 IPW_DEBUG_LED("Activity LED On\n");
891
892 priv->status |= STATUS_LED_ACT_ON;
893
James Ketrenosc848d0a2005-08-24 21:56:24 -0500894 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500895 queue_delayed_work(priv->workqueue, &priv->led_act_off,
896 LD_TIME_ACT_ON);
897 } else {
898 /* Reschedule LED off for full time period */
899 cancel_delayed_work(&priv->led_act_off);
900 queue_delayed_work(priv->workqueue, &priv->led_act_off,
901 LD_TIME_ACT_ON);
902 }
James Ketrenosb095c382005-08-24 22:04:42 -0500903}
James Ketrenosa613bff2005-08-24 21:43:11 -0500904
Adrian Bunka73e22b2006-01-21 01:39:42 +0100905#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500906void ipw_led_activity_on(struct ipw_priv *priv)
907{
908 unsigned long flags;
909 spin_lock_irqsave(&priv->lock, flags);
910 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500911 spin_unlock_irqrestore(&priv->lock, flags);
912}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100913#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500914
Adrian Bunka73e22b2006-01-21 01:39:42 +0100915static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500916{
917 unsigned long flags;
918 u32 led;
919
920 if (priv->config & CFG_NO_LED)
921 return;
922
923 spin_lock_irqsave(&priv->lock, flags);
924
925 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500926 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500927 led &= priv->led_activity_off;
928
929 led = ipw_register_toggle(led);
930
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500932 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933
934 IPW_DEBUG_LED("Activity LED Off\n");
935
936 priv->status &= ~STATUS_LED_ACT_ON;
937 }
938
939 spin_unlock_irqrestore(&priv->lock, flags);
940}
941
James Ketrenosc848d0a2005-08-24 21:56:24 -0500942static void ipw_bg_led_activity_off(void *data)
943{
944 struct ipw_priv *priv = data;
945 down(&priv->sem);
946 ipw_led_activity_off(data);
947 up(&priv->sem);
948}
949
Adrian Bunka73e22b2006-01-21 01:39:42 +0100950static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500951{
952 unsigned long flags;
953 u32 led;
954
955 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500956 if (priv->config & CFG_NO_LED ||
957 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500958 return;
959
960 spin_lock_irqsave(&priv->lock, flags);
961
James Ketrenosb095c382005-08-24 22:04:42 -0500962 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500963 if (priv->assoc_network->mode == IEEE_A) {
964 led |= priv->led_ofdm_on;
965 led &= priv->led_association_off;
966 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
967 } else if (priv->assoc_network->mode == IEEE_G) {
968 led |= priv->led_ofdm_on;
969 led |= priv->led_association_on;
970 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
971 } else {
972 led &= priv->led_ofdm_off;
973 led |= priv->led_association_on;
974 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
975 }
976
977 led = ipw_register_toggle(led);
978
979 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500980 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500981
982 spin_unlock_irqrestore(&priv->lock, flags);
983}
984
Adrian Bunka73e22b2006-01-21 01:39:42 +0100985static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500986{
987 unsigned long flags;
988 u32 led;
989
990 /* Only nic type 1 supports mode LEDs */
991 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
992 return;
993
994 spin_lock_irqsave(&priv->lock, flags);
995
James Ketrenosb095c382005-08-24 22:04:42 -0500996 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500997 led &= priv->led_ofdm_off;
998 led &= priv->led_association_off;
999
1000 led = ipw_register_toggle(led);
1001
1002 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001003 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001004
1005 spin_unlock_irqrestore(&priv->lock, flags);
1006}
1007
Adrian Bunka73e22b2006-01-21 01:39:42 +01001008static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001009{
1010 ipw_led_link_on(priv);
1011}
1012
Adrian Bunka73e22b2006-01-21 01:39:42 +01001013static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001014{
1015 ipw_led_activity_off(priv);
1016 ipw_led_link_off(priv);
1017}
1018
Adrian Bunka73e22b2006-01-21 01:39:42 +01001019static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001020{
1021 /* Set the Link Led on for all nic types */
1022 ipw_led_link_on(priv);
1023}
1024
Adrian Bunka73e22b2006-01-21 01:39:42 +01001025static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001026{
1027 ipw_led_activity_off(priv);
1028 ipw_led_link_off(priv);
1029
1030 if (priv->status & STATUS_RF_KILL_MASK)
1031 ipw_led_radio_off(priv);
1032}
1033
Adrian Bunka73e22b2006-01-21 01:39:42 +01001034static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001035{
1036 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1037
1038 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001039 priv->led_activity_on = IPW_ACTIVITY_LED;
1040 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001041
James Ketrenosb095c382005-08-24 22:04:42 -05001042 priv->led_association_on = IPW_ASSOCIATED_LED;
1043 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001044
1045 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001046 priv->led_ofdm_on = IPW_OFDM_LED;
1047 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001048
1049 switch (priv->nic_type) {
1050 case EEPROM_NIC_TYPE_1:
1051 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001052 priv->led_activity_on = IPW_ASSOCIATED_LED;
1053 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1054 priv->led_association_on = IPW_ACTIVITY_LED;
1055 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001056
1057 if (!(priv->config & CFG_NO_LED))
1058 ipw_led_band_on(priv);
1059
1060 /* And we don't blink link LEDs for this nic, so
1061 * just return here */
1062 return;
1063
1064 case EEPROM_NIC_TYPE_3:
1065 case EEPROM_NIC_TYPE_2:
1066 case EEPROM_NIC_TYPE_4:
1067 case EEPROM_NIC_TYPE_0:
1068 break;
1069
1070 default:
1071 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1072 priv->nic_type);
1073 priv->nic_type = EEPROM_NIC_TYPE_0;
1074 break;
1075 }
1076
1077 if (!(priv->config & CFG_NO_LED)) {
1078 if (priv->status & STATUS_ASSOCIATED)
1079 ipw_led_link_on(priv);
1080 else
1081 ipw_led_link_off(priv);
1082 }
1083}
1084
Adrian Bunka73e22b2006-01-21 01:39:42 +01001085static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001086{
James Ketrenosa613bff2005-08-24 21:43:11 -05001087 ipw_led_activity_off(priv);
1088 ipw_led_link_off(priv);
1089 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001090 cancel_delayed_work(&priv->led_link_on);
1091 cancel_delayed_work(&priv->led_link_off);
1092 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001093}
1094
James Ketrenos43f66a62005-03-25 12:31:53 -06001095/*
1096 * The following adds a new attribute to the sysfs representation
1097 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1098 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001099 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001100 * See the level definitions in ipw for details.
1101 */
1102static ssize_t show_debug_level(struct device_driver *d, char *buf)
1103{
1104 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1105}
James Ketrenosa613bff2005-08-24 21:43:11 -05001106
1107static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1108 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001109{
1110 char *p = (char *)buf;
1111 u32 val;
1112
1113 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1114 p++;
1115 if (p[0] == 'x' || p[0] == 'X')
1116 p++;
1117 val = simple_strtoul(p, &p, 16);
1118 } else
1119 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001120 if (p == buf)
1121 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001122 ": %s is not in hex or decimal form.\n", buf);
1123 else
1124 ipw_debug_level = val;
1125
1126 return strnlen(buf, count);
1127}
1128
Jeff Garzikbf794512005-07-31 13:07:26 -04001129static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001130 show_debug_level, store_debug_level);
1131
James Ketrenosb39860c2005-08-12 09:36:32 -05001132static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1133{
Zhu Yic8fe6672006-01-24 16:36:36 +08001134 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001135 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1136}
1137
1138static void ipw_capture_event_log(struct ipw_priv *priv,
1139 u32 log_len, struct ipw_event *log)
1140{
1141 u32 base;
1142
1143 if (log_len) {
1144 base = ipw_read32(priv, IPW_EVENT_LOG);
1145 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1146 (u8 *) log, sizeof(*log) * log_len);
1147 }
1148}
1149
1150static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1151{
1152 struct ipw_fw_error *error;
1153 u32 log_len = ipw_get_event_log_len(priv);
1154 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1155 u32 elem_len = ipw_read_reg32(priv, base);
1156
1157 error = kmalloc(sizeof(*error) +
1158 sizeof(*error->elem) * elem_len +
1159 sizeof(*error->log) * log_len, GFP_ATOMIC);
1160 if (!error) {
1161 IPW_ERROR("Memory allocation for firmware error log "
1162 "failed.\n");
1163 return NULL;
1164 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001165 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001166 error->status = priv->status;
1167 error->config = priv->config;
1168 error->elem_len = elem_len;
1169 error->log_len = log_len;
1170 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001171 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001172
1173 ipw_capture_event_log(priv, log_len, error->log);
1174
1175 if (elem_len)
1176 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1177 sizeof(*error->elem) * elem_len);
1178
1179 return error;
1180}
1181
1182static void ipw_free_error_log(struct ipw_fw_error *error)
1183{
1184 if (error)
1185 kfree(error);
1186}
1187
1188static ssize_t show_event_log(struct device *d,
1189 struct device_attribute *attr, char *buf)
1190{
1191 struct ipw_priv *priv = dev_get_drvdata(d);
1192 u32 log_len = ipw_get_event_log_len(priv);
1193 struct ipw_event log[log_len];
1194 u32 len = 0, i;
1195
1196 ipw_capture_event_log(priv, log_len, log);
1197
1198 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1199 for (i = 0; i < log_len; i++)
1200 len += snprintf(buf + len, PAGE_SIZE - len,
1201 "\n%08X%08X%08X",
1202 log[i].time, log[i].event, log[i].data);
1203 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1204 return len;
1205}
1206
1207static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1208
1209static ssize_t show_error(struct device *d,
1210 struct device_attribute *attr, char *buf)
1211{
1212 struct ipw_priv *priv = dev_get_drvdata(d);
1213 u32 len = 0, i;
1214 if (!priv->error)
1215 return 0;
1216 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001217 "%08lX%08X%08X%08X",
1218 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001219 priv->error->status,
1220 priv->error->config, priv->error->elem_len);
1221 for (i = 0; i < priv->error->elem_len; i++)
1222 len += snprintf(buf + len, PAGE_SIZE - len,
1223 "\n%08X%08X%08X%08X%08X%08X%08X",
1224 priv->error->elem[i].time,
1225 priv->error->elem[i].desc,
1226 priv->error->elem[i].blink1,
1227 priv->error->elem[i].blink2,
1228 priv->error->elem[i].link1,
1229 priv->error->elem[i].link2,
1230 priv->error->elem[i].data);
1231
1232 len += snprintf(buf + len, PAGE_SIZE - len,
1233 "\n%08X", priv->error->log_len);
1234 for (i = 0; i < priv->error->log_len; i++)
1235 len += snprintf(buf + len, PAGE_SIZE - len,
1236 "\n%08X%08X%08X",
1237 priv->error->log[i].time,
1238 priv->error->log[i].event,
1239 priv->error->log[i].data);
1240 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1241 return len;
1242}
1243
1244static ssize_t clear_error(struct device *d,
1245 struct device_attribute *attr,
1246 const char *buf, size_t count)
1247{
1248 struct ipw_priv *priv = dev_get_drvdata(d);
1249 if (priv->error) {
1250 ipw_free_error_log(priv->error);
1251 priv->error = NULL;
1252 }
1253 return count;
1254}
1255
1256static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1257
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001258static ssize_t show_cmd_log(struct device *d,
1259 struct device_attribute *attr, char *buf)
1260{
1261 struct ipw_priv *priv = dev_get_drvdata(d);
1262 u32 len = 0, i;
1263 if (!priv->cmdlog)
1264 return 0;
1265 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1266 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1267 i = (i + 1) % priv->cmdlog_len) {
1268 len +=
1269 snprintf(buf + len, PAGE_SIZE - len,
1270 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1271 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1272 priv->cmdlog[i].cmd.len);
1273 len +=
1274 snprintk_buf(buf + len, PAGE_SIZE - len,
1275 (u8 *) priv->cmdlog[i].cmd.param,
1276 priv->cmdlog[i].cmd.len);
1277 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1278 }
1279 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1280 return len;
1281}
1282
1283static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1284
James Ketrenosa613bff2005-08-24 21:43:11 -05001285static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1286 char *buf)
1287{
1288 struct ipw_priv *priv = dev_get_drvdata(d);
1289 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1290}
1291
1292static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1293 const char *buf, size_t count)
1294{
1295 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001296#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001297 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001298#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001299 char buffer[] = "00000000";
1300 unsigned long len =
1301 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1302 unsigned long val;
1303 char *p = buffer;
1304
1305 IPW_DEBUG_INFO("enter\n");
1306
1307 strncpy(buffer, buf, len);
1308 buffer[len] = 0;
1309
1310 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1311 p++;
1312 if (p[0] == 'x' || p[0] == 'X')
1313 p++;
1314 val = simple_strtoul(p, &p, 16);
1315 } else
1316 val = simple_strtoul(p, &p, 10);
1317 if (p == buffer) {
1318 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1319 } else {
1320 priv->ieee->scan_age = val;
1321 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1322 }
1323
1324 IPW_DEBUG_INFO("exit\n");
1325 return len;
1326}
1327
1328static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1329
1330static ssize_t show_led(struct device *d, struct device_attribute *attr,
1331 char *buf)
1332{
1333 struct ipw_priv *priv = dev_get_drvdata(d);
1334 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1335}
1336
1337static ssize_t store_led(struct device *d, struct device_attribute *attr,
1338 const char *buf, size_t count)
1339{
1340 struct ipw_priv *priv = dev_get_drvdata(d);
1341
1342 IPW_DEBUG_INFO("enter\n");
1343
1344 if (count == 0)
1345 return 0;
1346
1347 if (*buf == 0) {
1348 IPW_DEBUG_LED("Disabling LED control.\n");
1349 priv->config |= CFG_NO_LED;
1350 ipw_led_shutdown(priv);
1351 } else {
1352 IPW_DEBUG_LED("Enabling LED control.\n");
1353 priv->config &= ~CFG_NO_LED;
1354 ipw_led_init(priv);
1355 }
1356
1357 IPW_DEBUG_INFO("exit\n");
1358 return count;
1359}
1360
1361static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1362
Andrew Mortonad3fee52005-06-20 14:30:36 -07001363static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001364 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001365{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001366 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001367 return sprintf(buf, "0x%08x\n", (int)p->status);
1368}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001369
James Ketrenos43f66a62005-03-25 12:31:53 -06001370static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1371
Andrew Mortonad3fee52005-06-20 14:30:36 -07001372static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1373 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001374{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001375 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001376 return sprintf(buf, "0x%08x\n", (int)p->config);
1377}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001378
James Ketrenos43f66a62005-03-25 12:31:53 -06001379static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1380
Andrew Mortonad3fee52005-06-20 14:30:36 -07001381static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001382 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001383{
James Ketrenosa613bff2005-08-24 21:43:11 -05001384 struct ipw_priv *priv = d->driver_data;
1385 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001386}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001387
James Ketrenos43f66a62005-03-25 12:31:53 -06001388static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1389
Andrew Mortonad3fee52005-06-20 14:30:36 -07001390static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001391 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001392{
1393 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001394 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001395
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001396 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001397 return 0;
1398
1399 return sprintf(buf, "0x%08x\n", tmp);
1400}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001401
1402static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001403
Andrew Mortonad3fee52005-06-20 14:30:36 -07001404static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1405 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001406{
1407 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001408 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001409
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001410 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001411 return 0;
1412
1413 return sprintf(buf, "0x%08x\n", tmp);
1414}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001415
1416static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001417
1418/*
1419 * Add a device attribute to view/control the delay between eeprom
1420 * operations.
1421 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001422static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001423 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001424{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001425 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001426 return sprintf(buf, "%i\n", n);
1427}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001428static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001429 struct device_attribute *attr,
1430 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001431{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001432 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001433 sscanf(buf, "%i", &p->eeprom_delay);
1434 return strnlen(buf, count);
1435}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001436
1437static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1438 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001439
Andrew Mortonad3fee52005-06-20 14:30:36 -07001440static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001441 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001442{
1443 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001444 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001445
James Ketrenosb095c382005-08-24 22:04:42 -05001446 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001447 return sprintf(buf, "0x%08x\n", reg);
1448}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001449static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001450 struct device_attribute *attr,
1451 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001452{
1453 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001454 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001455
1456 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001457 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001458 return strnlen(buf, count);
1459}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001460
1461static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1462 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001463
Andrew Mortonad3fee52005-06-20 14:30:36 -07001464static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001465 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001466{
1467 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001468 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001469
1470 reg = ipw_read_reg32(p, 0x301100);
1471 return sprintf(buf, "0x%08x\n", reg);
1472}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001473static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001474 struct device_attribute *attr,
1475 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001476{
1477 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001478 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001479
1480 sscanf(buf, "%x", &reg);
1481 ipw_write_reg32(p, 0x301100, reg);
1482 return strnlen(buf, count);
1483}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001484
1485static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1486 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001487
Andrew Mortonad3fee52005-06-20 14:30:36 -07001488static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001489 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001490{
1491 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001492 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001493
Jeff Garzikbf794512005-07-31 13:07:26 -04001494 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001495 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001496 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001497 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001498
James Ketrenos43f66a62005-03-25 12:31:53 -06001499 return sprintf(buf, "0x%08x\n", reg);
1500}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001501static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001502 struct device_attribute *attr,
1503 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001504{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001505 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001506
1507 sscanf(buf, "%x", &priv->indirect_dword);
1508 priv->status |= STATUS_INDIRECT_DWORD;
1509 return strnlen(buf, count);
1510}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001511
1512static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1513 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001514
Andrew Mortonad3fee52005-06-20 14:30:36 -07001515static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001516 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001517{
1518 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001519 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001520
Jeff Garzikbf794512005-07-31 13:07:26 -04001521 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001522 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001523 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001524 reg = 0;
1525
1526 return sprintf(buf, "0x%02x\n", reg);
1527}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001528static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001529 struct device_attribute *attr,
1530 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001531{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001532 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001533
1534 sscanf(buf, "%x", &priv->indirect_byte);
1535 priv->status |= STATUS_INDIRECT_BYTE;
1536 return strnlen(buf, count);
1537}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001538
1539static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001540 show_indirect_byte, store_indirect_byte);
1541
Andrew Mortonad3fee52005-06-20 14:30:36 -07001542static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001543 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001544{
1545 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001547
Jeff Garzikbf794512005-07-31 13:07:26 -04001548 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001549 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001550 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001551 reg = 0;
1552
1553 return sprintf(buf, "0x%08x\n", reg);
1554}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001555static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001556 struct device_attribute *attr,
1557 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001558{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001559 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001560
1561 sscanf(buf, "%x", &priv->direct_dword);
1562 priv->status |= STATUS_DIRECT_DWORD;
1563 return strnlen(buf, count);
1564}
James Ketrenos43f66a62005-03-25 12:31:53 -06001565
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001566static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1567 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001568
Arjan van de Ven858119e2006-01-14 13:20:43 -08001569static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001570{
1571 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1572 priv->status |= STATUS_RF_KILL_HW;
1573 else
1574 priv->status &= ~STATUS_RF_KILL_HW;
1575
1576 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1577}
1578
Andrew Mortonad3fee52005-06-20 14:30:36 -07001579static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001580 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001581{
1582 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001583 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001584 2 - HW based RF kill active
1585 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001586 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001587 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001588 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001589 return sprintf(buf, "%i\n", val);
1590}
1591
1592static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1593{
Jeff Garzikbf794512005-07-31 13:07:26 -04001594 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001595 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001596 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001597
1598 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1599 disable_radio ? "OFF" : "ON");
1600
1601 if (disable_radio) {
1602 priv->status |= STATUS_RF_KILL_SW;
1603
James Ketrenosa613bff2005-08-24 21:43:11 -05001604 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001605 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001606 queue_work(priv->workqueue, &priv->down);
1607 } else {
1608 priv->status &= ~STATUS_RF_KILL_SW;
1609 if (rf_kill_active(priv)) {
1610 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1611 "disabled by HW switch\n");
1612 /* Make sure the RF_KILL check timer is running */
1613 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001614 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001615 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001616 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001617 queue_work(priv->workqueue, &priv->up);
1618 }
1619
1620 return 1;
1621}
1622
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001623static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1624 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001625{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001626 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001627
James Ketrenos43f66a62005-03-25 12:31:53 -06001628 ipw_radio_kill_sw(priv, buf[0] == '1');
1629
1630 return count;
1631}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001632
1633static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001634
James Ketrenosb095c382005-08-24 22:04:42 -05001635static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1636 char *buf)
1637{
1638 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1639 int pos = 0, len = 0;
1640 if (priv->config & CFG_SPEED_SCAN) {
1641 while (priv->speed_scan[pos] != 0)
1642 len += sprintf(&buf[len], "%d ",
1643 priv->speed_scan[pos++]);
1644 return len + sprintf(&buf[len], "\n");
1645 }
1646
1647 return sprintf(buf, "0\n");
1648}
1649
1650static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1651 const char *buf, size_t count)
1652{
1653 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1654 int channel, pos = 0;
1655 const char *p = buf;
1656
1657 /* list of space separated channels to scan, optionally ending with 0 */
1658 while ((channel = simple_strtol(p, NULL, 0))) {
1659 if (pos == MAX_SPEED_SCAN - 1) {
1660 priv->speed_scan[pos] = 0;
1661 break;
1662 }
1663
Liu Hong1fe0adb2005-08-19 09:33:10 -05001664 if (ipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001665 priv->speed_scan[pos++] = channel;
1666 else
1667 IPW_WARNING("Skipping invalid channel request: %d\n",
1668 channel);
1669 p = strchr(p, ' ');
1670 if (!p)
1671 break;
1672 while (*p == ' ' || *p == '\t')
1673 p++;
1674 }
1675
1676 if (pos == 0)
1677 priv->config &= ~CFG_SPEED_SCAN;
1678 else {
1679 priv->speed_scan_pos = 0;
1680 priv->config |= CFG_SPEED_SCAN;
1681 }
1682
1683 return count;
1684}
1685
1686static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1687 store_speed_scan);
1688
1689static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1690 char *buf)
1691{
1692 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1693 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1694}
1695
1696static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1697 const char *buf, size_t count)
1698{
1699 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1700 if (buf[0] == '1')
1701 priv->config |= CFG_NET_STATS;
1702 else
1703 priv->config &= ~CFG_NET_STATS;
1704
1705 return count;
1706}
1707
James Ketrenosafbf30a2005-08-25 00:05:33 -05001708static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1709 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001710
James Ketrenosea2b26e2005-08-24 21:25:16 -05001711static void notify_wx_assoc_event(struct ipw_priv *priv)
1712{
1713 union iwreq_data wrqu;
1714 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1715 if (priv->status & STATUS_ASSOCIATED)
1716 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1717 else
1718 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1719 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1720}
1721
James Ketrenos43f66a62005-03-25 12:31:53 -06001722static void ipw_irq_tasklet(struct ipw_priv *priv)
1723{
1724 u32 inta, inta_mask, handled = 0;
1725 unsigned long flags;
1726 int rc = 0;
1727
1728 spin_lock_irqsave(&priv->lock, flags);
1729
James Ketrenosb095c382005-08-24 22:04:42 -05001730 inta = ipw_read32(priv, IPW_INTA_RW);
1731 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1732 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001733
1734 /* Add any cached INTA values that need to be handled */
1735 inta |= priv->isr_inta;
1736
1737 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001738 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001740 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001741 }
1742
James Ketrenosb095c382005-08-24 22:04:42 -05001743 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001744 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001745 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001746 priv->status &= ~STATUS_HCMD_ACTIVE;
1747 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001748 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001749 }
1750
James Ketrenosb095c382005-08-24 22:04:42 -05001751 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001752 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001753 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001754 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001755 }
1756
James Ketrenosb095c382005-08-24 22:04:42 -05001757 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001758 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001759 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001760 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001761 }
1762
James Ketrenosb095c382005-08-24 22:04:42 -05001763 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001764 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001765 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001766 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001767 }
1768
James Ketrenosb095c382005-08-24 22:04:42 -05001769 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001770 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001771 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001772 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001773 }
1774
James Ketrenosb095c382005-08-24 22:04:42 -05001775 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001777 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 }
1779
James Ketrenosb095c382005-08-24 22:04:42 -05001780 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001782 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001783 }
1784
James Ketrenosb095c382005-08-24 22:04:42 -05001785 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001786 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001787 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001788 }
1789
James Ketrenosb095c382005-08-24 22:04:42 -05001790 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001791 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001792 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001793 }
1794
James Ketrenosb095c382005-08-24 22:04:42 -05001795 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001796 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001797 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001798 }
1799
James Ketrenosb095c382005-08-24 22:04:42 -05001800 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001801 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1802 priv->status |= STATUS_RF_KILL_HW;
1803 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001804 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001805 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001806 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001807 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001808 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001809 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001810
James Ketrenosb095c382005-08-24 22:04:42 -05001811 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001812 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001813 if (priv->error) {
1814 IPW_ERROR("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001815#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001816 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1817 struct ipw_fw_error *error =
1818 ipw_alloc_error_log(priv);
1819 ipw_dump_error_log(priv, error);
1820 if (error)
1821 ipw_free_error_log(error);
1822 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001823#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001824 } else {
1825 priv->error = ipw_alloc_error_log(priv);
1826 if (priv->error)
1827 IPW_ERROR("Sysfs 'error' log captured.\n");
1828 else
1829 IPW_ERROR("Error allocating sysfs 'error' "
1830 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001831#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001832 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1833 ipw_dump_error_log(priv, priv->error);
1834#endif
1835 }
1836
James Ketrenosb095c382005-08-24 22:04:42 -05001837 /* XXX: If hardware encryption is for WPA/WPA2,
1838 * we have to notify the supplicant. */
1839 if (priv->ieee->sec.encrypt) {
1840 priv->status &= ~STATUS_ASSOCIATED;
1841 notify_wx_assoc_event(priv);
1842 }
1843
1844 /* Keep the restart process from trying to send host
1845 * commands by clearing the INIT status bit */
1846 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001847
1848 /* Cancel currently queued command. */
1849 priv->status &= ~STATUS_HCMD_ACTIVE;
1850 wake_up_interruptible(&priv->wait_command_queue);
1851
James Ketrenos43f66a62005-03-25 12:31:53 -06001852 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001853 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001854 }
1855
James Ketrenosb095c382005-08-24 22:04:42 -05001856 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001857 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001858 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001859 }
1860
1861 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001862 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001863 }
1864
1865 /* enable all interrupts */
1866 ipw_enable_interrupts(priv);
1867
1868 spin_unlock_irqrestore(&priv->lock, flags);
1869}
Jeff Garzikbf794512005-07-31 13:07:26 -04001870
James Ketrenos43f66a62005-03-25 12:31:53 -06001871#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1872static char *get_cmd_string(u8 cmd)
1873{
1874 switch (cmd) {
1875 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001876 IPW_CMD(POWER_DOWN);
1877 IPW_CMD(SYSTEM_CONFIG);
1878 IPW_CMD(MULTICAST_ADDRESS);
1879 IPW_CMD(SSID);
1880 IPW_CMD(ADAPTER_ADDRESS);
1881 IPW_CMD(PORT_TYPE);
1882 IPW_CMD(RTS_THRESHOLD);
1883 IPW_CMD(FRAG_THRESHOLD);
1884 IPW_CMD(POWER_MODE);
1885 IPW_CMD(WEP_KEY);
1886 IPW_CMD(TGI_TX_KEY);
1887 IPW_CMD(SCAN_REQUEST);
1888 IPW_CMD(SCAN_REQUEST_EXT);
1889 IPW_CMD(ASSOCIATE);
1890 IPW_CMD(SUPPORTED_RATES);
1891 IPW_CMD(SCAN_ABORT);
1892 IPW_CMD(TX_FLUSH);
1893 IPW_CMD(QOS_PARAMETERS);
1894 IPW_CMD(DINO_CONFIG);
1895 IPW_CMD(RSN_CAPABILITIES);
1896 IPW_CMD(RX_KEY);
1897 IPW_CMD(CARD_DISABLE);
1898 IPW_CMD(SEED_NUMBER);
1899 IPW_CMD(TX_POWER);
1900 IPW_CMD(COUNTRY_INFO);
1901 IPW_CMD(AIRONET_INFO);
1902 IPW_CMD(AP_TX_POWER);
1903 IPW_CMD(CCKM_INFO);
1904 IPW_CMD(CCX_VER_INFO);
1905 IPW_CMD(SET_CALIBRATION);
1906 IPW_CMD(SENSITIVITY_CALIB);
1907 IPW_CMD(RETRY_LIMIT);
1908 IPW_CMD(IPW_PRE_POWER_DOWN);
1909 IPW_CMD(VAP_BEACON_TEMPLATE);
1910 IPW_CMD(VAP_DTIM_PERIOD);
1911 IPW_CMD(EXT_SUPPORTED_RATES);
1912 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1913 IPW_CMD(VAP_QUIET_INTERVALS);
1914 IPW_CMD(VAP_CHANNEL_SWITCH);
1915 IPW_CMD(VAP_MANDATORY_CHANNELS);
1916 IPW_CMD(VAP_CELL_PWR_LIMIT);
1917 IPW_CMD(VAP_CF_PARAM_SET);
1918 IPW_CMD(VAP_SET_BEACONING_STATE);
1919 IPW_CMD(MEASUREMENT);
1920 IPW_CMD(POWER_CAPABILITY);
1921 IPW_CMD(SUPPORTED_CHANNELS);
1922 IPW_CMD(TPC_REPORT);
1923 IPW_CMD(WME_INFO);
1924 IPW_CMD(PRODUCTION_COMMAND);
1925 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001926 return "UNKNOWN";
1927 }
1928}
James Ketrenos43f66a62005-03-25 12:31:53 -06001929
1930#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001931
1932static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06001933{
1934 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001935 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001936
James Ketrenosa613bff2005-08-24 21:43:11 -05001937 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001938 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001939 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1940 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001941 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001942 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001943 }
1944
1945 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001946
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001947 if (priv->cmdlog) {
1948 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1949 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1950 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1951 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1952 cmd->len);
1953 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1954 }
1955
James Ketrenosb095c382005-08-24 22:04:42 -05001956 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1957 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1958 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08001959
1960#ifndef DEBUG_CMD_WEP_KEY
1961 if (cmd->cmd == IPW_CMD_WEP_KEY)
1962 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1963 else
1964#endif
1965 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1966
James Ketrenos43f66a62005-03-25 12:31:53 -06001967
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001968 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001969 if (rc) {
1970 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001971 IPW_ERROR("Failed to send %s: Reason %d\n",
1972 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001973 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001974 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001975 }
1976 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001977
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001978 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1979 !(priv->
1980 status & STATUS_HCMD_ACTIVE),
1981 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001982 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001983 spin_lock_irqsave(&priv->lock, flags);
1984 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001985 IPW_ERROR("Failed to send %s: Command timed out.\n",
1986 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001987 priv->status &= ~STATUS_HCMD_ACTIVE;
1988 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001989 rc = -EIO;
1990 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001991 }
1992 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001993 } else
1994 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001995
James Ketrenosb095c382005-08-24 22:04:42 -05001996 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001997 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1998 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001999 rc = -EIO;
2000 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 }
2002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002003exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002004 if (priv->cmdlog) {
2005 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2006 priv->cmdlog_pos %= priv->cmdlog_len;
2007 }
2008 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002009}
2010
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002011static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002012{
2013 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002014 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002015 };
2016
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002017 return __ipw_send_cmd(priv, &cmd);
2018}
2019
2020static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2021 void *data)
2022{
2023 struct host_cmd cmd = {
2024 .cmd = command,
2025 .len = len,
2026 .param = data,
2027 };
2028
2029 return __ipw_send_cmd(priv, &cmd);
2030}
2031
2032static int ipw_send_host_complete(struct ipw_priv *priv)
2033{
James Ketrenos43f66a62005-03-25 12:31:53 -06002034 if (!priv) {
2035 IPW_ERROR("Invalid args\n");
2036 return -1;
2037 }
2038
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002039 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002040}
2041
Jeff Garzikbf794512005-07-31 13:07:26 -04002042static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002043 struct ipw_sys_config *config)
2044{
James Ketrenos43f66a62005-03-25 12:31:53 -06002045 if (!priv || !config) {
2046 IPW_ERROR("Invalid args\n");
2047 return -1;
2048 }
2049
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002050 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
2051 config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002052}
2053
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002054static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002055{
James Ketrenos43f66a62005-03-25 12:31:53 -06002056 if (!priv || !ssid) {
2057 IPW_ERROR("Invalid args\n");
2058 return -1;
2059 }
2060
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002061 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2062 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002063}
2064
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002065static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002066{
James Ketrenos43f66a62005-03-25 12:31:53 -06002067 if (!priv || !mac) {
2068 IPW_ERROR("Invalid args\n");
2069 return -1;
2070 }
2071
2072 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2073 priv->net_dev->name, MAC_ARG(mac));
2074
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002075 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN,
2076 mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002077}
2078
James Ketrenosa613bff2005-08-24 21:43:11 -05002079/*
2080 * NOTE: This must be executed from our workqueue as it results in udelay
2081 * being called which may corrupt the keyboard if executed on default
2082 * workqueue
2083 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002084static void ipw_adapter_restart(void *adapter)
2085{
2086 struct ipw_priv *priv = adapter;
2087
2088 if (priv->status & STATUS_RF_KILL_MASK)
2089 return;
2090
2091 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002092
2093 if (priv->assoc_network &&
2094 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2095 ipw_remove_current_network(priv);
2096
James Ketrenos43f66a62005-03-25 12:31:53 -06002097 if (ipw_up(priv)) {
2098 IPW_ERROR("Failed to up device\n");
2099 return;
2100 }
2101}
2102
James Ketrenosc848d0a2005-08-24 21:56:24 -05002103static void ipw_bg_adapter_restart(void *data)
2104{
2105 struct ipw_priv *priv = data;
2106 down(&priv->sem);
2107 ipw_adapter_restart(data);
2108 up(&priv->sem);
2109}
2110
James Ketrenos43f66a62005-03-25 12:31:53 -06002111#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2112
2113static void ipw_scan_check(void *data)
2114{
2115 struct ipw_priv *priv = data;
2116 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2117 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002118 "adapter after (%dms).\n",
2119 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002120 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121 }
2122}
2123
James Ketrenosc848d0a2005-08-24 21:56:24 -05002124static void ipw_bg_scan_check(void *data)
2125{
2126 struct ipw_priv *priv = data;
2127 down(&priv->sem);
2128 ipw_scan_check(data);
2129 up(&priv->sem);
2130}
2131
James Ketrenos43f66a62005-03-25 12:31:53 -06002132static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2133 struct ipw_scan_request_ext *request)
2134{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002135 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2136 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002137}
2138
2139static int ipw_send_scan_abort(struct ipw_priv *priv)
2140{
James Ketrenos43f66a62005-03-25 12:31:53 -06002141 if (!priv) {
2142 IPW_ERROR("Invalid args\n");
2143 return -1;
2144 }
2145
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002146 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002147}
2148
2149static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2150{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002151 struct ipw_sensitivity_calib calib = {
2152 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002153 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002154
2155 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2156 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002157}
2158
2159static int ipw_send_associate(struct ipw_priv *priv,
2160 struct ipw_associate *associate)
2161{
James Ketrenosa613bff2005-08-24 21:43:11 -05002162 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002163
2164 if (!priv || !associate) {
2165 IPW_ERROR("Invalid args\n");
2166 return -1;
2167 }
2168
James Ketrenosa613bff2005-08-24 21:43:11 -05002169 memcpy(&tmp_associate, associate, sizeof(*associate));
2170 tmp_associate.policy_support =
2171 cpu_to_le16(tmp_associate.policy_support);
2172 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2173 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2174 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2175 tmp_associate.listen_interval =
2176 cpu_to_le16(tmp_associate.listen_interval);
2177 tmp_associate.beacon_interval =
2178 cpu_to_le16(tmp_associate.beacon_interval);
2179 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2180
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002181 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2182 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002183}
2184
2185static int ipw_send_supported_rates(struct ipw_priv *priv,
2186 struct ipw_supported_rates *rates)
2187{
James Ketrenos43f66a62005-03-25 12:31:53 -06002188 if (!priv || !rates) {
2189 IPW_ERROR("Invalid args\n");
2190 return -1;
2191 }
2192
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002193 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2194 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002195}
2196
2197static int ipw_set_random_seed(struct ipw_priv *priv)
2198{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002199 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002200
2201 if (!priv) {
2202 IPW_ERROR("Invalid args\n");
2203 return -1;
2204 }
2205
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002206 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002207
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002208 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002209}
2210
James Ketrenos43f66a62005-03-25 12:31:53 -06002211static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2212{
James Ketrenos43f66a62005-03-25 12:31:53 -06002213 if (!priv) {
2214 IPW_ERROR("Invalid args\n");
2215 return -1;
2216 }
2217
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002218 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2219 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002220}
James Ketrenos43f66a62005-03-25 12:31:53 -06002221
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002222static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002223{
James Ketrenos43f66a62005-03-25 12:31:53 -06002224 if (!priv || !power) {
2225 IPW_ERROR("Invalid args\n");
2226 return -1;
2227 }
2228
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002229 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power),
2230 power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002231}
James Ketrenos43f66a62005-03-25 12:31:53 -06002232
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002233static int ipw_set_tx_power(struct ipw_priv *priv)
2234{
Liu Hong1fe0adb2005-08-19 09:33:10 -05002235 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002236 struct ipw_tx_power tx_power;
2237 s8 max_power;
2238 int i;
2239
2240 memset(&tx_power, 0, sizeof(tx_power));
2241
2242 /* configure device for 'G' band */
2243 tx_power.ieee_mode = IPW_G_MODE;
2244 tx_power.num_channels = geo->bg_channels;
2245 for (i = 0; i < geo->bg_channels; i++) {
2246 max_power = geo->bg[i].max_power;
2247 tx_power.channels_tx_power[i].channel_number =
2248 geo->bg[i].channel;
2249 tx_power.channels_tx_power[i].tx_power = max_power ?
2250 min(max_power, priv->tx_power) : priv->tx_power;
2251 }
2252 if (ipw_send_tx_power(priv, &tx_power))
2253 return -EIO;
2254
2255 /* configure device to also handle 'B' band */
2256 tx_power.ieee_mode = IPW_B_MODE;
2257 if (ipw_send_tx_power(priv, &tx_power))
2258 return -EIO;
2259
2260 /* configure device to also handle 'A' band */
2261 if (priv->ieee->abg_true) {
2262 tx_power.ieee_mode = IPW_A_MODE;
2263 tx_power.num_channels = geo->a_channels;
2264 for (i = 0; i < tx_power.num_channels; i++) {
2265 max_power = geo->a[i].max_power;
2266 tx_power.channels_tx_power[i].channel_number =
2267 geo->a[i].channel;
2268 tx_power.channels_tx_power[i].tx_power = max_power ?
2269 min(max_power, priv->tx_power) : priv->tx_power;
2270 }
2271 if (ipw_send_tx_power(priv, &tx_power))
2272 return -EIO;
2273 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002274 return 0;
2275}
2276
2277static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2278{
2279 struct ipw_rts_threshold rts_threshold = {
2280 .rts_threshold = rts,
2281 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002282
2283 if (!priv) {
2284 IPW_ERROR("Invalid args\n");
2285 return -1;
2286 }
2287
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002288 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2289 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002290}
2291
2292static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2293{
2294 struct ipw_frag_threshold frag_threshold = {
2295 .frag_threshold = frag,
2296 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002297
2298 if (!priv) {
2299 IPW_ERROR("Invalid args\n");
2300 return -1;
2301 }
2302
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002303 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2304 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002305}
2306
2307static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2308{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002309 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002310
2311 if (!priv) {
2312 IPW_ERROR("Invalid args\n");
2313 return -1;
2314 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002315
James Ketrenos43f66a62005-03-25 12:31:53 -06002316 /* If on battery, set to 3, if AC set to CAM, else user
2317 * level */
2318 switch (mode) {
2319 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002320 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002321 break;
2322 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002323 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002324 break;
2325 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002326 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002327 break;
2328 }
2329
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002330 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2331 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002332}
2333
James Ketrenosafbf30a2005-08-25 00:05:33 -05002334static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2335{
2336 struct ipw_retry_limit retry_limit = {
2337 .short_retry_limit = slimit,
2338 .long_retry_limit = llimit
2339 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002340
2341 if (!priv) {
2342 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002343 return -1;
2344 }
2345
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002346 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2347 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002348}
2349
2350/*
2351 * The IPW device contains a Microwire compatible EEPROM that stores
2352 * various data like the MAC address. Usually the firmware has exclusive
2353 * access to the eeprom, but during device initialization (before the
2354 * device driver has sent the HostComplete command to the firmware) the
2355 * device driver has read access to the EEPROM by way of indirect addressing
2356 * through a couple of memory mapped registers.
2357 *
2358 * The following is a simplified implementation for pulling data out of the
2359 * the eeprom, along with some helper functions to find information in
2360 * the per device private data's copy of the eeprom.
2361 *
2362 * NOTE: To better understand how these functions work (i.e what is a chip
2363 * select and why do have to keep driving the eeprom clock?), read
2364 * just about any data sheet for a Microwire compatible EEPROM.
2365 */
2366
2367/* write a 32 bit value into the indirect accessor register */
2368static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2369{
2370 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002371
James Ketrenos43f66a62005-03-25 12:31:53 -06002372 /* the eeprom requires some time to complete the operation */
2373 udelay(p->eeprom_delay);
2374
2375 return;
2376}
2377
2378/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002379static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002380{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002381 eeprom_write_reg(priv, 0);
2382 eeprom_write_reg(priv, EEPROM_BIT_CS);
2383 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2384 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002385}
2386
2387/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002388static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002389{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002390 eeprom_write_reg(priv, EEPROM_BIT_CS);
2391 eeprom_write_reg(priv, 0);
2392 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002393}
2394
2395/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002396static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002397{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002398 int d = (bit ? EEPROM_BIT_DI : 0);
2399 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2400 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002401}
2402
2403/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002404static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002405{
2406 int i;
2407
2408 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002409 eeprom_write_bit(priv, 1);
2410 eeprom_write_bit(priv, op & 2);
2411 eeprom_write_bit(priv, op & 1);
2412 for (i = 7; i >= 0; i--) {
2413 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002414 }
2415}
2416
2417/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002418static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002419{
2420 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002421 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002422
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002424 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002425
2426 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002427 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002428
2429 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002430 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002431 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002432 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2433 eeprom_write_reg(priv, EEPROM_BIT_CS);
2434 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2435 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002436 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002437
James Ketrenos43f66a62005-03-25 12:31:53 -06002438 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002439 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002440 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002441
James Ketrenos43f66a62005-03-25 12:31:53 -06002442 return r;
2443}
2444
2445/* helper function for pulling the mac address out of the private */
2446/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002447static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002448{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002449 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002450}
2451
2452/*
2453 * Either the device driver (i.e. the host) or the firmware can
2454 * load eeprom data into the designated region in SRAM. If neither
2455 * happens then the FW will shutdown with a fatal error.
2456 *
2457 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2458 * bit needs region of shared SRAM needs to be non-zero.
2459 */
2460static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2461{
2462 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002463 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002464
James Ketrenos43f66a62005-03-25 12:31:53 -06002465 IPW_DEBUG_TRACE(">>\n");
2466
2467 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002468 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002469 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002470
Jeff Garzikbf794512005-07-31 13:07:26 -04002471 /*
2472 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002473 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002474 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002475 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002476 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2477 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2478
2479 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002480 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002481 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002482
2483 /* Do not load eeprom data on fatal error or suspend */
2484 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2485 } else {
2486 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2487
2488 /* Load eeprom data on fatal error or suspend */
2489 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2490 }
2491
2492 IPW_DEBUG_TRACE("<<\n");
2493}
2494
Arjan van de Ven858119e2006-01-14 13:20:43 -08002495static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002496{
2497 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002498 if (!count)
2499 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002500 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002501 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002502 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002503}
2504
2505static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2506{
James Ketrenosb095c382005-08-24 22:04:42 -05002507 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002508 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 sizeof(struct command_block));
2510}
2511
2512static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002513{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002514
2515 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002516
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 /* Start the dma */
2518 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002519
James Ketrenos43f66a62005-03-25 12:31:53 -06002520 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002521 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522
2523 IPW_DEBUG_FW("<< : \n");
2524 return 0;
2525}
2526
2527static void ipw_fw_dma_abort(struct ipw_priv *priv)
2528{
2529 u32 control = 0;
2530
2531 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002532
2533 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002534 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002535 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002536 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002537
James Ketrenos43f66a62005-03-25 12:31:53 -06002538 IPW_DEBUG_FW("<< \n");
2539}
2540
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002541static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2542 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002543{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002544 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002545 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002546 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002547 IPW_DEBUG_FW(">> :\n");
2548
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002549 ipw_write_indirect(priv, address, (u8 *) cb,
2550 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002551
2552 IPW_DEBUG_FW("<< :\n");
2553 return 0;
2554
2555}
2556
2557static int ipw_fw_dma_kick(struct ipw_priv *priv)
2558{
2559 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002560 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002561
2562 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002563
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002565 ipw_fw_dma_write_command_block(priv, index,
2566 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002567
2568 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002569 ipw_clear_bit(priv, IPW_RESET_REG,
2570 IPW_RESET_REG_MASTER_DISABLED |
2571 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002572
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002573 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002574 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002575 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002576
2577 IPW_DEBUG_FW("<< :\n");
2578 return 0;
2579}
2580
2581static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2582{
2583 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584 u32 register_value = 0;
2585 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002586
2587 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002588 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002589 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002590
2591 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002592 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2593 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002594
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002595 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002596 cb_fields_address = address;
2597 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002598 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002599
2600 cb_fields_address += sizeof(u32);
2601 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002602 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002603
2604 cb_fields_address += sizeof(u32);
2605 register_value = ipw_read_reg32(priv, cb_fields_address);
2606 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2607 register_value);
2608
2609 cb_fields_address += sizeof(u32);
2610 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002611 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002612
2613 IPW_DEBUG_FW(">> :\n");
2614}
2615
2616static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2617{
2618 u32 current_cb_address = 0;
2619 u32 current_cb_index = 0;
2620
2621 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002622 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002623
James Ketrenosb095c382005-08-24 22:04:42 -05002624 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002626
James Ketrenos43f66a62005-03-25 12:31:53 -06002627 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002628 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002629
2630 IPW_DEBUG_FW(">> :\n");
2631 return current_cb_index;
2632
2633}
2634
2635static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2636 u32 src_address,
2637 u32 dest_address,
2638 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002639 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002640{
2641
Jeff Garzikbf794512005-07-31 13:07:26 -04002642 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002643 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2644 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002645 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002646 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002647
2648 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2649 src_address, dest_address, length);
2650
2651 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2652 return -1;
2653
2654 last_cb_element = priv->sram_desc.last_cb_index;
2655 cb = &priv->sram_desc.cb_list[last_cb_element];
2656 priv->sram_desc.last_cb_index++;
2657
2658 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002660 control |= CB_INT_ENABLED;
2661
2662 if (is_last)
2663 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002664
James Ketrenos43f66a62005-03-25 12:31:53 -06002665 control |= length;
2666
2667 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002669
2670 /* Copy the Source and Destination addresses */
2671 cb->dest_addr = dest_address;
2672 cb->source_addr = src_address;
2673
2674 /* Copy the Control Word last */
2675 cb->control = control;
2676
2677 return 0;
2678}
2679
2680static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002681 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002682{
2683 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002684 u32 src_offset = 0;
2685 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002686 int status = 0;
2687 IPW_DEBUG_FW(">> \n");
2688 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2689 src_phys, dest_address, length);
2690 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002691 status = ipw_fw_dma_add_command_block(priv,
2692 src_phys + src_offset,
2693 dest_address +
2694 dest_offset,
2695 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002696 if (status) {
2697 IPW_DEBUG_FW_INFO(": Failed\n");
2698 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002699 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002700 IPW_DEBUG_FW_INFO(": Added new cb\n");
2701
2702 src_offset += CB_MAX_LENGTH;
2703 dest_offset += CB_MAX_LENGTH;
2704 bytes_left -= CB_MAX_LENGTH;
2705 }
2706
2707 /* add the buffer tail */
2708 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002709 status =
2710 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2711 dest_address + dest_offset,
2712 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002713 if (status) {
2714 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2715 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002716 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002717 IPW_DEBUG_FW_INFO
2718 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002719 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002720
James Ketrenos43f66a62005-03-25 12:31:53 -06002721 IPW_DEBUG_FW("<< \n");
2722 return 0;
2723}
2724
2725static int ipw_fw_dma_wait(struct ipw_priv *priv)
2726{
Zhu Yi397ae122006-01-24 16:37:22 +08002727 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002728 u32 watchdog = 0;
2729
2730 IPW_DEBUG_FW(">> : \n");
2731
2732 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002733 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002734 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002735
2736 while (current_index < priv->sram_desc.last_cb_index) {
2737 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002738 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002739 current_index = ipw_fw_dma_command_block_index(priv);
2740
Zhu Yi397ae122006-01-24 16:37:22 +08002741 if (previous_index < current_index) {
2742 watchdog = 0;
2743 continue;
2744 }
2745 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002746 IPW_DEBUG_FW_INFO("Timeout\n");
2747 ipw_fw_dma_dump_command_block(priv);
2748 ipw_fw_dma_abort(priv);
2749 return -1;
2750 }
2751 }
2752
2753 ipw_fw_dma_abort(priv);
2754
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002755 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002756 ipw_set_bit(priv, IPW_RESET_REG,
2757 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002758
2759 IPW_DEBUG_FW("<< dmaWaitSync \n");
2760 return 0;
2761}
2762
Jeff Garzikbf794512005-07-31 13:07:26 -04002763static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002764{
2765 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002766 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002767 unsigned long flags;
2768
2769 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002770 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2771 network = list_entry(element, struct ieee80211_network, list);
2772 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2773 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002774 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002775 &priv->ieee->network_free_list);
2776 }
2777 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002778 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002779}
2780
2781/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002782 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002783 * Reads debug register from domain0.
2784 * If card is present, pre-defined value should
2785 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002786 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 * @param priv
2788 * @return 1 if card is present, 0 otherwise
2789 */
2790static inline int ipw_alive(struct ipw_priv *priv)
2791{
2792 return ipw_read32(priv, 0x90) == 0xd55555d5;
2793}
2794
Zhu Yic7b6a672006-01-24 16:37:05 +08002795/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002796static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002797 int timeout)
2798{
2799 int i = 0;
2800
2801 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002802 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002803 return i;
2804 mdelay(10);
2805 i += 10;
2806 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002807
James Ketrenos43f66a62005-03-25 12:31:53 -06002808 return -ETIME;
2809}
2810
Jeff Garzikbf794512005-07-31 13:07:26 -04002811/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002812 * the ipw hardware. It assumes the buffer has all the bits for the
2813 * image and the caller is handling the memory allocation and clean up.
2814 */
2815
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002816static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002817{
2818 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002819
James Ketrenos43f66a62005-03-25 12:31:53 -06002820 IPW_DEBUG_TRACE(">> \n");
2821 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002822 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002823
Zhu Yic7b6a672006-01-24 16:37:05 +08002824 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002825 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2826 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002827 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002828 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002829 return -1;
2830 }
2831
2832 IPW_DEBUG_INFO("stop master %dms\n", rc);
2833
2834 return rc;
2835}
2836
2837static void ipw_arc_release(struct ipw_priv *priv)
2838{
2839 IPW_DEBUG_TRACE(">> \n");
2840 mdelay(5);
2841
James Ketrenosb095c382005-08-24 22:04:42 -05002842 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002843
2844 /* no one knows timing, for safety add some delay */
2845 mdelay(5);
2846}
2847
2848struct fw_header {
2849 u32 version;
2850 u32 mode;
2851};
2852
2853struct fw_chunk {
2854 u32 address;
2855 u32 length;
2856};
2857
2858#define IPW_FW_MAJOR_VERSION 2
James Ketrenos817153762005-08-25 01:37:28 -05002859#define IPW_FW_MINOR_VERSION 4
James Ketrenos43f66a62005-03-25 12:31:53 -06002860
2861#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2862#define IPW_FW_MAJOR(x) (x & 0xff)
2863
James Ketrenosafbf30a2005-08-25 00:05:33 -05002864#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002865
2866#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2867"." __stringify(IPW_FW_MINOR_VERSION) "-"
2868
2869#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2870#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2871#else
2872#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2873#endif
2874
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002875static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002876{
2877 int rc = 0, i, addr;
2878 u8 cr = 0;
2879 u16 *image;
2880
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002881 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002882
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 IPW_DEBUG_TRACE(">> \n");
2884
2885 rc = ipw_stop_master(priv);
2886
2887 if (rc < 0)
2888 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002889
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002890// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002891
James Ketrenosb095c382005-08-24 22:04:42 -05002892 for (addr = IPW_SHARED_LOWER_BOUND;
2893 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002894 ipw_write32(priv, addr, 0);
2895 }
2896
2897 /* no ucode (yet) */
2898 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2899 /* destroy DMA queues */
2900 /* reset sequence */
2901
James Ketrenosb095c382005-08-24 22:04:42 -05002902 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002903 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002904 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002905 mdelay(1);
2906
2907 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002908 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002909 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002910
James Ketrenosb095c382005-08-24 22:04:42 -05002911 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002912 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002913
James Ketrenos43f66a62005-03-25 12:31:53 -06002914 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002915 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2916 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002917 mdelay(1);
2918
2919 /* write ucode */
2920 /**
2921 * @bug
2922 * Do NOT set indirect address register once and then
2923 * store data to indirect data register in the loop.
2924 * It seems very reasonable, but in this case DINO do not
2925 * accept ucode. It is essential to set address each time.
2926 */
2927 /* load new ipw uCode */
2928 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002929 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002930 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002931
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002933 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2934 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002935
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002936 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002937
2938 /* wait for alive response */
2939 for (i = 0; i < 100; i++) {
2940 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002941 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 if (cr & DINO_RXFIFO_DATA)
2943 break;
2944 mdelay(1);
2945 }
2946
2947 if (cr & DINO_RXFIFO_DATA) {
2948 /* alive_command_responce size is NOT multiple of 4 */
2949 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002950
2951 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002952 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002953 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002954 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002955 memcpy(&priv->dino_alive, response_buffer,
2956 sizeof(priv->dino_alive));
2957 if (priv->dino_alive.alive_command == 1
2958 && priv->dino_alive.ucode_valid == 1) {
2959 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002960 IPW_DEBUG_INFO
2961 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2962 "of %02d/%02d/%02d %02d:%02d\n",
2963 priv->dino_alive.software_revision,
2964 priv->dino_alive.software_revision,
2965 priv->dino_alive.device_identifier,
2966 priv->dino_alive.device_identifier,
2967 priv->dino_alive.time_stamp[0],
2968 priv->dino_alive.time_stamp[1],
2969 priv->dino_alive.time_stamp[2],
2970 priv->dino_alive.time_stamp[3],
2971 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002972 } else {
2973 IPW_DEBUG_INFO("Microcode is not alive\n");
2974 rc = -EINVAL;
2975 }
2976 } else {
2977 IPW_DEBUG_INFO("No alive response from DINO\n");
2978 rc = -ETIME;
2979 }
2980
2981 /* disable DINO, otherwise for some reason
2982 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002983 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002984
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002985// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002986
2987 return rc;
2988}
2989
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002990static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002991{
2992 int rc = -1;
2993 int offset = 0;
2994 struct fw_chunk *chunk;
2995 dma_addr_t shared_phys;
2996 u8 *shared_virt;
2997
2998 IPW_DEBUG_TRACE("<< : \n");
2999 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3000
3001 if (!shared_virt)
3002 return -ENOMEM;
3003
3004 memmove(shared_virt, data, len);
3005
3006 /* Start the Dma */
3007 rc = ipw_fw_dma_enable(priv);
3008
3009 if (priv->sram_desc.last_cb_index > 0) {
3010 /* the DMA is already ready this would be a bug. */
3011 BUG();
3012 goto out;
3013 }
3014
3015 do {
3016 chunk = (struct fw_chunk *)(data + offset);
3017 offset += sizeof(struct fw_chunk);
3018 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003019 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003020 * offeset*/
3021 /* Dma loading */
3022 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003023 le32_to_cpu(chunk->address),
3024 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 if (rc) {
3026 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3027 goto out;
3028 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003029
James Ketrenosa613bff2005-08-24 21:43:11 -05003030 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003031 } while (offset < len);
3032
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003033 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003034 rc = ipw_fw_dma_kick(priv);
3035 if (rc) {
3036 IPW_ERROR("dmaKick Failed\n");
3037 goto out;
3038 }
3039
3040 rc = ipw_fw_dma_wait(priv);
3041 if (rc) {
3042 IPW_ERROR("dmaWaitSync Failed\n");
3043 goto out;
3044 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003045 out:
3046 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003047 return rc;
3048}
3049
3050/* stop nic */
3051static int ipw_stop_nic(struct ipw_priv *priv)
3052{
3053 int rc = 0;
3054
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003055 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003056 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003057
James Ketrenosb095c382005-08-24 22:04:42 -05003058 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3059 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003060 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003061 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003062 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003063 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003064
James Ketrenosb095c382005-08-24 22:04:42 -05003065 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003066
James Ketrenos43f66a62005-03-25 12:31:53 -06003067 return rc;
3068}
3069
3070static void ipw_start_nic(struct ipw_priv *priv)
3071{
3072 IPW_DEBUG_TRACE(">>\n");
3073
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003074 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003075 ipw_clear_bit(priv, IPW_RESET_REG,
3076 IPW_RESET_REG_MASTER_DISABLED |
3077 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003078 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003079
James Ketrenos43f66a62005-03-25 12:31:53 -06003080 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003081 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3082 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003083
3084 IPW_DEBUG_TRACE("<<\n");
3085}
Jeff Garzikbf794512005-07-31 13:07:26 -04003086
James Ketrenos43f66a62005-03-25 12:31:53 -06003087static int ipw_init_nic(struct ipw_priv *priv)
3088{
3089 int rc;
3090
3091 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003092 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003093 /*prvHwInitNic */
3094 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003095 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003096
3097 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003098 ipw_write32(priv, IPW_READ_INT_REGISTER,
3099 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003100
3101 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003102 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3103 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003104 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003105 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3106
3107 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003108 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003109
3110 udelay(10);
3111
3112 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003113 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003114
3115 IPW_DEBUG_TRACE(">>\n");
3116 return 0;
3117}
3118
Jeff Garzikbf794512005-07-31 13:07:26 -04003119/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003120 * Probe is an ok place to call this from.
3121 */
3122static int ipw_reset_nic(struct ipw_priv *priv)
3123{
3124 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003125 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003126
3127 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003128
James Ketrenos43f66a62005-03-25 12:31:53 -06003129 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003130
James Ketrenosa613bff2005-08-24 21:43:11 -05003131 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003132 /* Clear the 'host command active' bit... */
3133 priv->status &= ~STATUS_HCMD_ACTIVE;
3134 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003135 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3136 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003137 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003138
3139 IPW_DEBUG_TRACE("<<\n");
3140 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003141}
James Ketrenos43f66a62005-03-25 12:31:53 -06003142
Jeff Garzikbf794512005-07-31 13:07:26 -04003143static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003144 const struct firmware **fw, const char *name)
3145{
3146 struct fw_header *header;
3147 int rc;
3148
3149 /* ask firmware_class module to get the boot firmware off disk */
3150 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3151 if (rc < 0) {
3152 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3153 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003154 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003155
3156 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003157 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003158 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3159 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003160 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3161 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003162 return -EINVAL;
3163 }
3164
Jiri Bencaaa4d302005-06-07 14:58:41 +02003165 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003166 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003167 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3168 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003169 (*fw)->size - sizeof(struct fw_header));
3170 return 0;
3171}
3172
James Ketrenosb095c382005-08-24 22:04:42 -05003173#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003174
Arjan van de Ven858119e2006-01-14 13:20:43 -08003175static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003176 struct ipw_rx_queue *rxq)
3177{
3178 unsigned long flags;
3179 int i;
3180
3181 spin_lock_irqsave(&rxq->lock, flags);
3182
3183 INIT_LIST_HEAD(&rxq->rx_free);
3184 INIT_LIST_HEAD(&rxq->rx_used);
3185
3186 /* Fill the rx_used queue with _all_ of the Rx buffers */
3187 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3188 /* In the reset function, these buffers may have been allocated
3189 * to an SKB, so we need to unmap and free potential storage */
3190 if (rxq->pool[i].skb != NULL) {
3191 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003192 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003193 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003194 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003195 }
3196 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3197 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003198
James Ketrenos43f66a62005-03-25 12:31:53 -06003199 /* Set us so that we have processed and used all buffers, but have
3200 * not restocked the Rx queue with fresh buffers */
3201 rxq->read = rxq->write = 0;
3202 rxq->processed = RX_QUEUE_SIZE - 1;
3203 rxq->free_count = 0;
3204 spin_unlock_irqrestore(&rxq->lock, flags);
3205}
3206
3207#ifdef CONFIG_PM
3208static int fw_loaded = 0;
3209static const struct firmware *bootfw = NULL;
3210static const struct firmware *firmware = NULL;
3211static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003212
3213static void free_firmware(void)
3214{
3215 if (fw_loaded) {
3216 release_firmware(bootfw);
3217 release_firmware(ucode);
3218 release_firmware(firmware);
3219 bootfw = ucode = firmware = NULL;
3220 fw_loaded = 0;
3221 }
3222}
3223#else
3224#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003225#endif
3226
3227static int ipw_load(struct ipw_priv *priv)
3228{
3229#ifndef CONFIG_PM
3230 const struct firmware *bootfw = NULL;
3231 const struct firmware *firmware = NULL;
3232 const struct firmware *ucode = NULL;
3233#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003234 char *ucode_name;
3235 char *fw_name;
James Ketrenos43f66a62005-03-25 12:31:53 -06003236 int rc = 0, retries = 3;
3237
Zhu Yi397ae122006-01-24 16:37:22 +08003238 switch (priv->ieee->iw_mode) {
3239 case IW_MODE_ADHOC:
3240 ucode_name = IPW_FW_NAME("ibss_ucode");
3241 fw_name = IPW_FW_NAME("ibss");
3242 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003243#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003244 case IW_MODE_MONITOR:
3245 ucode_name = IPW_FW_NAME("sniffer_ucode");
3246 fw_name = IPW_FW_NAME("sniffer");
3247 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003248#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003249 case IW_MODE_INFRA:
3250 ucode_name = IPW_FW_NAME("bss_ucode");
3251 fw_name = IPW_FW_NAME("bss");
3252 break;
3253 default:
3254 rc = -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003255 }
Zhu Yi397ae122006-01-24 16:37:22 +08003256
3257 if (rc < 0)
3258 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003259
3260 if (!priv->rxq)
3261 priv->rxq = ipw_rx_queue_alloc(priv);
3262 else
3263 ipw_rx_queue_reset(priv, priv->rxq);
3264 if (!priv->rxq) {
3265 IPW_ERROR("Unable to initialize Rx queue\n");
3266 goto error;
3267 }
3268
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003269 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003270 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003271 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003272 priv->status &= ~STATUS_INT_ENABLED;
3273
3274 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003275 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003276
James Ketrenos43f66a62005-03-25 12:31:53 -06003277 ipw_stop_nic(priv);
3278
3279 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003280 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003281 IPW_ERROR("Unable to reset NIC\n");
3282 goto error;
3283 }
3284
James Ketrenosb095c382005-08-24 22:04:42 -05003285 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3286 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003287
Zhu Yi397ae122006-01-24 16:37:22 +08003288#ifdef CONFIG_PM
3289 if (!fw_loaded) {
3290#endif
3291 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
3292 if (rc < 0)
3293 goto error;
3294#ifdef CONFIG_PM
3295 }
3296#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06003297 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003298 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003299 bootfw->size - sizeof(struct fw_header));
3300 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003301 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003302 goto error;
3303 }
3304
3305 /* kick start the device */
3306 ipw_start_nic(priv);
3307
Zhu Yic7b6a672006-01-24 16:37:05 +08003308 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003309 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3310 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003311 if (rc < 0) {
3312 IPW_ERROR("device failed to boot initial fw image\n");
3313 goto error;
3314 }
3315 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3316
Jeff Garzikbf794512005-07-31 13:07:26 -04003317 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003318 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003319
Zhu Yi397ae122006-01-24 16:37:22 +08003320#ifdef CONFIG_PM
3321 if (!fw_loaded) {
3322#endif
3323 rc = ipw_get_fw(priv, &ucode, ucode_name);
3324 if (rc < 0)
3325 goto error;
3326#ifdef CONFIG_PM
3327 }
3328#endif
3329
James Ketrenos43f66a62005-03-25 12:31:53 -06003330 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003331 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 ucode->size - sizeof(struct fw_header));
3333 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003334 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003335 goto error;
3336 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003337
James Ketrenos43f66a62005-03-25 12:31:53 -06003338 /* stop nic */
3339 ipw_stop_nic(priv);
3340
Zhu Yi397ae122006-01-24 16:37:22 +08003341#ifdef CONFIG_PM
3342 if (!fw_loaded) {
3343#endif
3344 rc = ipw_get_fw(priv, &firmware, fw_name);
3345 if (rc < 0)
3346 goto error;
3347#ifdef CONFIG_PM
3348 }
3349#endif
3350
James Ketrenos43f66a62005-03-25 12:31:53 -06003351 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003352 rc = ipw_load_firmware(priv, firmware->data +
3353 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003354 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003355 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003356 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003357 goto error;
3358 }
3359
Zhu Yi397ae122006-01-24 16:37:22 +08003360#ifdef CONFIG_PM
3361 fw_loaded = 1;
3362#endif
3363
James Ketrenos43f66a62005-03-25 12:31:53 -06003364 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3365
3366 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003367 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003368 IPW_ERROR("Unable to initialize queues\n");
3369 goto error;
3370 }
3371
3372 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003373 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003374 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003375 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003376
James Ketrenos43f66a62005-03-25 12:31:53 -06003377 /* kick start the device */
3378 ipw_start_nic(priv);
3379
James Ketrenosb095c382005-08-24 22:04:42 -05003380 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003381 if (retries > 0) {
3382 IPW_WARNING("Parity error. Retrying init.\n");
3383 retries--;
3384 goto retry;
3385 }
3386
3387 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3388 rc = -EIO;
3389 goto error;
3390 }
3391
3392 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003393 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3394 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003395 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003396 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003397 goto error;
3398 }
3399 IPW_DEBUG_INFO("device response after %dms\n", rc);
3400
3401 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003402 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003403
3404 /* read eeprom data and initialize the eeprom region of sram */
3405 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003406 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003407
3408 /* enable interrupts */
3409 ipw_enable_interrupts(priv);
3410
3411 /* Ensure our queue has valid packets */
3412 ipw_rx_queue_replenish(priv);
3413
James Ketrenosb095c382005-08-24 22:04:42 -05003414 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003415
3416 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003417 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003418
3419#ifndef CONFIG_PM
3420 release_firmware(bootfw);
3421 release_firmware(ucode);
3422 release_firmware(firmware);
3423#endif
3424 return 0;
3425
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003426 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003427 if (priv->rxq) {
3428 ipw_rx_queue_free(priv, priv->rxq);
3429 priv->rxq = NULL;
3430 }
3431 ipw_tx_queue_free(priv);
3432 if (bootfw)
3433 release_firmware(bootfw);
3434 if (ucode)
3435 release_firmware(ucode);
3436 if (firmware)
3437 release_firmware(firmware);
3438#ifdef CONFIG_PM
3439 fw_loaded = 0;
3440 bootfw = ucode = firmware = NULL;
3441#endif
3442
3443 return rc;
3444}
3445
Jeff Garzikbf794512005-07-31 13:07:26 -04003446/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003447 * DMA services
3448 *
3449 * Theory of operation
3450 *
3451 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3452 * 2 empty entries always kept in the buffer to protect from overflow.
3453 *
3454 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003455 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3456 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003457 * Tx queue resumed.
3458 *
3459 * The IPW operates with six queues, one receive queue in the device's
3460 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003461 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003462 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003463 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003464 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003465 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003466 * we only utilize the first data transmit queue (queue1).
3467 */
3468
3469/**
3470 * Driver allocates buffers of this size for Rx
3471 */
3472
3473static inline int ipw_queue_space(const struct clx2_queue *q)
3474{
3475 int s = q->last_used - q->first_empty;
3476 if (s <= 0)
3477 s += q->n_bd;
3478 s -= 2; /* keep some reserve to not confuse empty and full situations */
3479 if (s < 0)
3480 s = 0;
3481 return s;
3482}
3483
3484static inline int ipw_queue_inc_wrap(int index, int n_bd)
3485{
3486 return (++index == n_bd) ? 0 : index;
3487}
3488
3489/**
3490 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003491 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003492 * @param q queue to init
3493 * @param count Number of BD's to allocate. Should be power of 2
3494 * @param read_register Address for 'read' register
3495 * (not offset within BAR, full address)
3496 * @param write_register Address for 'write' register
3497 * (not offset within BAR, full address)
3498 * @param base_register Address for 'base' register
3499 * (not offset within BAR, full address)
3500 * @param size Address for 'size' register
3501 * (not offset within BAR, full address)
3502 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003503static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003504 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003505{
3506 q->n_bd = count;
3507
3508 q->low_mark = q->n_bd / 4;
3509 if (q->low_mark < 4)
3510 q->low_mark = 4;
3511
3512 q->high_mark = q->n_bd / 8;
3513 if (q->high_mark < 2)
3514 q->high_mark = 2;
3515
3516 q->first_empty = q->last_used = 0;
3517 q->reg_r = read;
3518 q->reg_w = write;
3519
3520 ipw_write32(priv, base, q->dma_addr);
3521 ipw_write32(priv, size, count);
3522 ipw_write32(priv, read, 0);
3523 ipw_write32(priv, write, 0);
3524
3525 _ipw_read32(priv, 0x90);
3526}
3527
Jeff Garzikbf794512005-07-31 13:07:26 -04003528static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003529 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003530 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003531{
3532 struct pci_dev *dev = priv->pci_dev;
3533
3534 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3535 if (!q->txb) {
3536 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3537 return -ENOMEM;
3538 }
3539
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003540 q->bd =
3541 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003542 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003543 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003544 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 kfree(q->txb);
3546 q->txb = NULL;
3547 return -ENOMEM;
3548 }
3549
3550 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3551 return 0;
3552}
3553
3554/**
3555 * Free one TFD, those at index [txq->q.last_used].
3556 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003557 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003558 * @param dev
3559 * @param txq
3560 */
3561static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3562 struct clx2_tx_queue *txq)
3563{
3564 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3565 struct pci_dev *dev = priv->pci_dev;
3566 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003567
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 /* classify bd */
3569 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3570 /* nothing to cleanup after for host commands */
3571 return;
3572
3573 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003574 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3575 IPW_ERROR("Too many chunks: %i\n",
3576 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003577 /** @todo issue fatal error, it is quite serious situation */
3578 return;
3579 }
3580
3581 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003582 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3583 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3584 le16_to_cpu(bd->u.data.chunk_len[i]),
3585 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003586 if (txq->txb[txq->q.last_used]) {
3587 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3588 txq->txb[txq->q.last_used] = NULL;
3589 }
3590 }
3591}
3592
3593/**
3594 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003595 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003596 * Empty queue by removing and destroying all BD's.
3597 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003598 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003599 * @param dev
3600 * @param q
3601 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003602static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003603{
3604 struct clx2_queue *q = &txq->q;
3605 struct pci_dev *dev = priv->pci_dev;
3606
Jeff Garzikbf794512005-07-31 13:07:26 -04003607 if (q->n_bd == 0)
3608 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003609
3610 /* first, empty all BD's */
3611 for (; q->first_empty != q->last_used;
3612 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3613 ipw_queue_tx_free_tfd(priv, txq);
3614 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003615
James Ketrenos43f66a62005-03-25 12:31:53 -06003616 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003617 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003618 q->dma_addr);
3619 kfree(txq->txb);
3620
3621 /* 0 fill whole structure */
3622 memset(txq, 0, sizeof(*txq));
3623}
3624
James Ketrenos43f66a62005-03-25 12:31:53 -06003625/**
3626 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003627 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003628 * @param priv
3629 */
3630static void ipw_tx_queue_free(struct ipw_priv *priv)
3631{
3632 /* Tx CMD queue */
3633 ipw_queue_tx_free(priv, &priv->txq_cmd);
3634
3635 /* Tx queues */
3636 ipw_queue_tx_free(priv, &priv->txq[0]);
3637 ipw_queue_tx_free(priv, &priv->txq[1]);
3638 ipw_queue_tx_free(priv, &priv->txq[2]);
3639 ipw_queue_tx_free(priv, &priv->txq[3]);
3640}
3641
Arjan van de Ven858119e2006-01-14 13:20:43 -08003642static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003643{
3644 /* First 3 bytes are manufacturer */
3645 bssid[0] = priv->mac_addr[0];
3646 bssid[1] = priv->mac_addr[1];
3647 bssid[2] = priv->mac_addr[2];
3648
3649 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003650 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003651
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003652 bssid[0] &= 0xfe; /* clear multicast bit */
3653 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003654}
3655
Arjan van de Ven858119e2006-01-14 13:20:43 -08003656static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003657{
3658 struct ipw_station_entry entry;
3659 int i;
3660
3661 for (i = 0; i < priv->num_stations; i++) {
3662 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3663 /* Another node is active in network */
3664 priv->missed_adhoc_beacons = 0;
3665 if (!(priv->config & CFG_STATIC_CHANNEL))
3666 /* when other nodes drop out, we drop out */
3667 priv->config &= ~CFG_ADHOC_PERSIST;
3668
3669 return i;
3670 }
3671 }
3672
3673 if (i == MAX_STATIONS)
3674 return IPW_INVALID_STATION;
3675
3676 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3677
3678 entry.reserved = 0;
3679 entry.support_mode = 0;
3680 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3681 memcpy(priv->stations[i], bssid, ETH_ALEN);
3682 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003683 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 priv->num_stations++;
3685
3686 return i;
3687}
3688
Arjan van de Ven858119e2006-01-14 13:20:43 -08003689static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003690{
3691 int i;
3692
Jeff Garzikbf794512005-07-31 13:07:26 -04003693 for (i = 0; i < priv->num_stations; i++)
3694 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003695 return i;
3696
3697 return IPW_INVALID_STATION;
3698}
3699
3700static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3701{
3702 int err;
3703
Hong Liu7b996592005-08-25 17:36:13 +08003704 if (priv->status & STATUS_ASSOCIATING) {
3705 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3706 queue_work(priv->workqueue, &priv->disassociate);
3707 return;
3708 }
3709
3710 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003711 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3712 return;
3713 }
3714
3715 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3716 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003717 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003718 priv->assoc_request.channel);
3719
3720 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3721 priv->status |= STATUS_DISASSOCIATING;
3722
3723 if (quiet)
3724 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3725 else
3726 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003727
James Ketrenos43f66a62005-03-25 12:31:53 -06003728 err = ipw_send_associate(priv, &priv->assoc_request);
3729 if (err) {
3730 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3731 "failed.\n");
3732 return;
3733 }
3734
3735}
3736
James Ketrenosc848d0a2005-08-24 21:56:24 -05003737static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003738{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003739 struct ipw_priv *priv = data;
3740 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3741 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003742 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003743 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003744}
3745
James Ketrenosc848d0a2005-08-24 21:56:24 -05003746static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003747{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003748 struct ipw_priv *priv = data;
3749 down(&priv->sem);
3750 ipw_disassociate(data);
3751 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003752}
3753
Zhu Yid8bad6d2005-07-13 12:25:38 -05003754static void ipw_system_config(void *data)
3755{
3756 struct ipw_priv *priv = data;
3757 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003758}
3759
3760struct ipw_status_code {
3761 u16 status;
3762 const char *reason;
3763};
3764
3765static const struct ipw_status_code ipw_status_codes[] = {
3766 {0x00, "Successful"},
3767 {0x01, "Unspecified failure"},
3768 {0x0A, "Cannot support all requested capabilities in the "
3769 "Capability information field"},
3770 {0x0B, "Reassociation denied due to inability to confirm that "
3771 "association exists"},
3772 {0x0C, "Association denied due to reason outside the scope of this "
3773 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003774 {0x0D,
3775 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003777 {0x0E,
3778 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003779 "transaction sequence number out of expected sequence"},
3780 {0x0F, "Authentication rejected because of challenge failure"},
3781 {0x10, "Authentication rejected due to timeout waiting for next "
3782 "frame in sequence"},
3783 {0x11, "Association denied because AP is unable to handle additional "
3784 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003785 {0x12,
3786 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003787 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003788 {0x13,
3789 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003790 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003791 {0x14,
3792 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003793 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003794 {0x15,
3795 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003796 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003797 {0x19,
3798 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003799 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003800 {0x1A,
3801 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003802 "DSSS-OFDM operation"},
3803 {0x28, "Invalid Information Element"},
3804 {0x29, "Group Cipher is not valid"},
3805 {0x2A, "Pairwise Cipher is not valid"},
3806 {0x2B, "AKMP is not valid"},
3807 {0x2C, "Unsupported RSN IE version"},
3808 {0x2D, "Invalid RSN IE Capabilities"},
3809 {0x2E, "Cipher suite is rejected per security policy"},
3810};
3811
Brice Goglin0f52bf92005-12-01 01:41:46 -08003812#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003813static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003814{
3815 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003816 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003817 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003818 return ipw_status_codes[i].reason;
3819 return "Unknown status value.";
3820}
3821#endif
3822
3823static void inline average_init(struct average *avg)
3824{
3825 memset(avg, 0, sizeof(*avg));
3826}
3827
Arjan van de Ven858119e2006-01-14 13:20:43 -08003828static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003829{
3830 avg->sum -= avg->entries[avg->pos];
3831 avg->sum += val;
3832 avg->entries[avg->pos++] = val;
3833 if (unlikely(avg->pos == AVG_ENTRIES)) {
3834 avg->init = 1;
3835 avg->pos = 0;
3836 }
3837}
3838
Arjan van de Ven858119e2006-01-14 13:20:43 -08003839static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003840{
3841 if (!unlikely(avg->init)) {
3842 if (avg->pos)
3843 return avg->sum / avg->pos;
3844 return 0;
3845 }
3846
3847 return avg->sum / AVG_ENTRIES;
3848}
3849
3850static void ipw_reset_stats(struct ipw_priv *priv)
3851{
3852 u32 len = sizeof(u32);
3853
3854 priv->quality = 0;
3855
3856 average_init(&priv->average_missed_beacons);
3857 average_init(&priv->average_rssi);
3858 average_init(&priv->average_noise);
3859
3860 priv->last_rate = 0;
3861 priv->last_missed_beacons = 0;
3862 priv->last_rx_packets = 0;
3863 priv->last_tx_packets = 0;
3864 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003865
James Ketrenos43f66a62005-03-25 12:31:53 -06003866 /* Firmware managed, reset only when NIC is restarted, so we have to
3867 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003868 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003869 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003870 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003871 &priv->last_tx_failures, &len);
3872
3873 /* Driver managed, reset with each association */
3874 priv->missed_adhoc_beacons = 0;
3875 priv->missed_beacons = 0;
3876 priv->tx_packets = 0;
3877 priv->rx_packets = 0;
3878
3879}
3880
Arjan van de Ven858119e2006-01-14 13:20:43 -08003881static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003882{
3883 u32 i = 0x80000000;
3884 u32 mask = priv->rates_mask;
3885 /* If currently associated in B mode, restrict the maximum
3886 * rate match to B rates */
3887 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3888 mask &= IEEE80211_CCK_RATES_MASK;
3889
3890 /* TODO: Verify that the rate is supported by the current rates
3891 * list. */
3892
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003893 while (i && !(mask & i))
3894 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003895 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003896 case IEEE80211_CCK_RATE_1MB_MASK:
3897 return 1000000;
3898 case IEEE80211_CCK_RATE_2MB_MASK:
3899 return 2000000;
3900 case IEEE80211_CCK_RATE_5MB_MASK:
3901 return 5500000;
3902 case IEEE80211_OFDM_RATE_6MB_MASK:
3903 return 6000000;
3904 case IEEE80211_OFDM_RATE_9MB_MASK:
3905 return 9000000;
3906 case IEEE80211_CCK_RATE_11MB_MASK:
3907 return 11000000;
3908 case IEEE80211_OFDM_RATE_12MB_MASK:
3909 return 12000000;
3910 case IEEE80211_OFDM_RATE_18MB_MASK:
3911 return 18000000;
3912 case IEEE80211_OFDM_RATE_24MB_MASK:
3913 return 24000000;
3914 case IEEE80211_OFDM_RATE_36MB_MASK:
3915 return 36000000;
3916 case IEEE80211_OFDM_RATE_48MB_MASK:
3917 return 48000000;
3918 case IEEE80211_OFDM_RATE_54MB_MASK:
3919 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003920 }
3921
Jeff Garzikbf794512005-07-31 13:07:26 -04003922 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003923 return 11000000;
3924 else
3925 return 54000000;
3926}
3927
3928static u32 ipw_get_current_rate(struct ipw_priv *priv)
3929{
3930 u32 rate, len = sizeof(rate);
3931 int err;
3932
Jeff Garzikbf794512005-07-31 13:07:26 -04003933 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003934 return 0;
3935
3936 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003937 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003938 &len);
3939 if (err) {
3940 IPW_DEBUG_INFO("failed querying ordinals.\n");
3941 return 0;
3942 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003943 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003944 return ipw_get_max_rate(priv);
3945
3946 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003947 case IPW_TX_RATE_1MB:
3948 return 1000000;
3949 case IPW_TX_RATE_2MB:
3950 return 2000000;
3951 case IPW_TX_RATE_5MB:
3952 return 5500000;
3953 case IPW_TX_RATE_6MB:
3954 return 6000000;
3955 case IPW_TX_RATE_9MB:
3956 return 9000000;
3957 case IPW_TX_RATE_11MB:
3958 return 11000000;
3959 case IPW_TX_RATE_12MB:
3960 return 12000000;
3961 case IPW_TX_RATE_18MB:
3962 return 18000000;
3963 case IPW_TX_RATE_24MB:
3964 return 24000000;
3965 case IPW_TX_RATE_36MB:
3966 return 36000000;
3967 case IPW_TX_RATE_48MB:
3968 return 48000000;
3969 case IPW_TX_RATE_54MB:
3970 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003971 }
3972
3973 return 0;
3974}
3975
James Ketrenos43f66a62005-03-25 12:31:53 -06003976#define IPW_STATS_INTERVAL (2 * HZ)
3977static void ipw_gather_stats(struct ipw_priv *priv)
3978{
3979 u32 rx_err, rx_err_delta, rx_packets_delta;
3980 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3981 u32 missed_beacons_percent, missed_beacons_delta;
3982 u32 quality = 0;
3983 u32 len = sizeof(u32);
3984 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003985 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003986 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003987 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003988
3989 if (!(priv->status & STATUS_ASSOCIATED)) {
3990 priv->quality = 0;
3991 return;
3992 }
3993
3994 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003995 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003996 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003997 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003998 priv->last_missed_beacons = priv->missed_beacons;
3999 if (priv->assoc_request.beacon_interval) {
4000 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004001 (HZ * priv->assoc_request.beacon_interval) /
4002 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004003 } else {
4004 missed_beacons_percent = 0;
4005 }
4006 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4007
4008 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4009 rx_err_delta = rx_err - priv->last_rx_err;
4010 priv->last_rx_err = rx_err;
4011
4012 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4013 tx_failures_delta = tx_failures - priv->last_tx_failures;
4014 priv->last_tx_failures = tx_failures;
4015
4016 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4017 priv->last_rx_packets = priv->rx_packets;
4018
4019 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4020 priv->last_tx_packets = priv->tx_packets;
4021
4022 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004023 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004024 * Missed beacon: 100% = 0, 0% = 70% missed
4025 * Rate: 60% = 1Mbs, 100% = Max
4026 * Rx and Tx errors represent a straight % of total Rx/Tx
4027 * RSSI: 100% = > -50, 0% = < -80
4028 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004029 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004030 * The lowest computed quality is used.
4031 *
4032 */
4033#define BEACON_THRESHOLD 5
4034 beacon_quality = 100 - missed_beacons_percent;
4035 if (beacon_quality < BEACON_THRESHOLD)
4036 beacon_quality = 0;
4037 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004038 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004039 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004040 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004042
James Ketrenos43f66a62005-03-25 12:31:53 -06004043 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004044 max_rate = ipw_get_max_rate(priv);
4045 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004046 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4047 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004048
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004049 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004050 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004051 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004052 else
4053 rx_quality = 100;
4054 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4055 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004056
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004057 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004058 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004059 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004060 else
4061 tx_quality = 100;
4062 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4063 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004064
James Ketrenos43f66a62005-03-25 12:31:53 -06004065 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004066 signal_quality =
4067 (100 *
4068 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4069 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4070 (priv->ieee->perfect_rssi - rssi) *
4071 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4072 62 * (priv->ieee->perfect_rssi - rssi))) /
4073 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4074 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4075 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004076 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004077 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004078 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004079
James Ketrenos43f66a62005-03-25 12:31:53 -06004080 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4081 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004082
4083 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004084 min(rate_quality,
4085 min(tx_quality, min(rx_quality, signal_quality))));
4086 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004087 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4088 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004089 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004090 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4091 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004092 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004093 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4094 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004095 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004096 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4097 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004098 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004099 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4100 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004101
4102 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004103
4104 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004105 IPW_STATS_INTERVAL);
4106}
4107
James Ketrenosc848d0a2005-08-24 21:56:24 -05004108static void ipw_bg_gather_stats(void *data)
4109{
4110 struct ipw_priv *priv = data;
4111 down(&priv->sem);
4112 ipw_gather_stats(data);
4113 up(&priv->sem);
4114}
4115
Ben Cahille7582562005-10-06 15:34:41 -05004116/* Missed beacon behavior:
4117 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4118 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4119 * Above disassociate threshold, give up and stop scanning.
4120 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004121static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004122 int missed_count)
4123{
4124 priv->notif_missed_beacons = missed_count;
4125
James Ketrenosafbf30a2005-08-25 00:05:33 -05004126 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004127 priv->status & STATUS_ASSOCIATED) {
4128 /* If associated and we've hit the missed
4129 * beacon threshold, disassociate, turn
4130 * off roaming, and abort any active scans */
4131 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004132 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004133 "Missed beacon: %d - disassociate\n", missed_count);
4134 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004135 if (priv->status & STATUS_SCANNING) {
4136 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4137 IPW_DL_STATE,
4138 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004139 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004140 }
4141
James Ketrenosea2b26e2005-08-24 21:25:16 -05004142 queue_work(priv->workqueue, &priv->disassociate);
4143 return;
4144 }
4145
4146 if (priv->status & STATUS_ROAMING) {
4147 /* If we are currently roaming, then just
4148 * print a debug statement... */
4149 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4150 "Missed beacon: %d - roam in progress\n",
4151 missed_count);
4152 return;
4153 }
4154
Zhu Yi4bfdb912006-01-24 16:37:16 +08004155 if (roaming &&
4156 (missed_count > priv->roaming_threshold &&
4157 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004158 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004159 * bit in the status and kick off a scan.
4160 * This can happen several times before we reach
4161 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004162 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4163 "Missed beacon: %d - initiate "
4164 "roaming\n", missed_count);
4165 if (!(priv->status & STATUS_ROAMING)) {
4166 priv->status |= STATUS_ROAMING;
4167 if (!(priv->status & STATUS_SCANNING))
4168 queue_work(priv->workqueue,
4169 &priv->request_scan);
4170 }
4171 return;
4172 }
4173
4174 if (priv->status & STATUS_SCANNING) {
4175 /* Stop scan to keep fw from getting
4176 * stuck (only if we aren't roaming --
4177 * otherwise we'll never scan more than 2 or 3
4178 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004179 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4180 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004181 queue_work(priv->workqueue, &priv->abort_scan);
4182 }
4183
4184 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004185}
4186
James Ketrenos43f66a62005-03-25 12:31:53 -06004187/**
4188 * Handle host notification packet.
4189 * Called from interrupt routine
4190 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004191static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004192 struct ipw_rx_notification *notif)
4193{
James Ketrenosa613bff2005-08-24 21:43:11 -05004194 notif->size = le16_to_cpu(notif->size);
4195
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004196 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004197
James Ketrenos43f66a62005-03-25 12:31:53 -06004198 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004199 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4200 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004201
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004202 switch (assoc->state) {
4203 case CMAS_ASSOCIATED:{
4204 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4205 IPW_DL_ASSOC,
4206 "associated: '%s' " MAC_FMT
4207 " \n",
4208 escape_essid(priv->essid,
4209 priv->essid_len),
4210 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004211
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004212 switch (priv->ieee->iw_mode) {
4213 case IW_MODE_INFRA:
4214 memcpy(priv->ieee->bssid,
4215 priv->bssid, ETH_ALEN);
4216 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004217
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004218 case IW_MODE_ADHOC:
4219 memcpy(priv->ieee->bssid,
4220 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004221
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004222 /* clear out the station table */
4223 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004224
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004225 IPW_DEBUG_ASSOC
4226 ("queueing adhoc check\n");
4227 queue_delayed_work(priv->
4228 workqueue,
4229 &priv->
4230 adhoc_check,
4231 priv->
4232 assoc_request.
4233 beacon_interval);
4234 break;
4235 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004236
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004237 priv->status &= ~STATUS_ASSOCIATING;
4238 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004239 queue_work(priv->workqueue,
4240 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004241
James Ketrenosb095c382005-08-24 22:04:42 -05004242#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004243#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4244 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4245 if ((priv->status & STATUS_AUTH) &&
4246 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4247 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004248 if ((sizeof
4249 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004250 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004251 <= notif->size)
4252 && (notif->size <= 2314)) {
4253 struct
4254 ieee80211_rx_stats
4255 stats = {
4256 .len =
4257 notif->
4258 size - 1,
4259 };
4260
4261 IPW_DEBUG_QOS
4262 ("QoS Associate "
4263 "size %d\n",
4264 notif->size);
4265 ieee80211_rx_mgt(priv->
4266 ieee,
4267 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004268 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004269 *)
4270 &notif->u.raw, &stats);
4271 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004272 }
James Ketrenosb095c382005-08-24 22:04:42 -05004273#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004274
James Ketrenosa613bff2005-08-24 21:43:11 -05004275 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004276
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004277 break;
4278 }
4279
4280 case CMAS_AUTHENTICATED:{
4281 if (priv->
4282 status & (STATUS_ASSOCIATED |
4283 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004284#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004285 struct notif_authenticate *auth
4286 = &notif->u.auth;
4287 IPW_DEBUG(IPW_DL_NOTIF |
4288 IPW_DL_STATE |
4289 IPW_DL_ASSOC,
4290 "deauthenticated: '%s' "
4291 MAC_FMT
4292 ": (0x%04X) - %s \n",
4293 escape_essid(priv->
4294 essid,
4295 priv->
4296 essid_len),
4297 MAC_ARG(priv->bssid),
4298 ntohs(auth->status),
4299 ipw_get_status_code
4300 (ntohs
4301 (auth->status)));
4302#endif
4303
4304 priv->status &=
4305 ~(STATUS_ASSOCIATING |
4306 STATUS_AUTH |
4307 STATUS_ASSOCIATED);
4308
James Ketrenosa613bff2005-08-24 21:43:11 -05004309 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004310 break;
4311 }
4312
4313 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4314 IPW_DL_ASSOC,
4315 "authenticated: '%s' " MAC_FMT
4316 "\n",
4317 escape_essid(priv->essid,
4318 priv->essid_len),
4319 MAC_ARG(priv->bssid));
4320 break;
4321 }
4322
4323 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004324 if (priv->status & STATUS_AUTH) {
4325 struct
4326 ieee80211_assoc_response
4327 *resp;
4328 resp =
4329 (struct
4330 ieee80211_assoc_response
4331 *)&notif->u.raw;
4332 IPW_DEBUG(IPW_DL_NOTIF |
4333 IPW_DL_STATE |
4334 IPW_DL_ASSOC,
4335 "association failed (0x%04X): %s\n",
4336 ntohs(resp->status),
4337 ipw_get_status_code
4338 (ntohs
4339 (resp->status)));
4340 }
4341
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004342 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4343 IPW_DL_ASSOC,
4344 "disassociated: '%s' " MAC_FMT
4345 " \n",
4346 escape_essid(priv->essid,
4347 priv->essid_len),
4348 MAC_ARG(priv->bssid));
4349
4350 priv->status &=
4351 ~(STATUS_DISASSOCIATING |
4352 STATUS_ASSOCIATING |
4353 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004354 if (priv->assoc_network
4355 && (priv->assoc_network->
4356 capability &
4357 WLAN_CAPABILITY_IBSS))
4358 ipw_remove_current_network
4359 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004360
James Ketrenosa613bff2005-08-24 21:43:11 -05004361 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004362
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004363 break;
4364 }
4365
James Ketrenosb095c382005-08-24 22:04:42 -05004366 case CMAS_RX_ASSOC_RESP:
4367 break;
4368
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004369 default:
4370 IPW_ERROR("assoc: unknown (%d)\n",
4371 assoc->state);
4372 break;
4373 }
4374
James Ketrenos43f66a62005-03-25 12:31:53 -06004375 break;
4376 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004377
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004378 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4379 struct notif_authenticate *auth = &notif->u.auth;
4380 switch (auth->state) {
4381 case CMAS_AUTHENTICATED:
4382 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4383 "authenticated: '%s' " MAC_FMT " \n",
4384 escape_essid(priv->essid,
4385 priv->essid_len),
4386 MAC_ARG(priv->bssid));
4387 priv->status |= STATUS_AUTH;
4388 break;
4389
4390 case CMAS_INIT:
4391 if (priv->status & STATUS_AUTH) {
4392 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4393 IPW_DL_ASSOC,
4394 "authentication failed (0x%04X): %s\n",
4395 ntohs(auth->status),
4396 ipw_get_status_code(ntohs
4397 (auth->
4398 status)));
4399 }
4400 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4401 IPW_DL_ASSOC,
4402 "deauthenticated: '%s' " MAC_FMT "\n",
4403 escape_essid(priv->essid,
4404 priv->essid_len),
4405 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004406
4407 priv->status &= ~(STATUS_ASSOCIATING |
4408 STATUS_AUTH |
4409 STATUS_ASSOCIATED);
4410
James Ketrenosa613bff2005-08-24 21:43:11 -05004411 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004412 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004413
4414 case CMAS_TX_AUTH_SEQ_1:
4415 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4416 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4417 break;
4418 case CMAS_RX_AUTH_SEQ_2:
4419 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4420 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4421 break;
4422 case CMAS_AUTH_SEQ_1_PASS:
4423 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4424 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4425 break;
4426 case CMAS_AUTH_SEQ_1_FAIL:
4427 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4428 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4429 break;
4430 case CMAS_TX_AUTH_SEQ_3:
4431 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4432 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4433 break;
4434 case CMAS_RX_AUTH_SEQ_4:
4435 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4436 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4437 break;
4438 case CMAS_AUTH_SEQ_2_PASS:
4439 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4440 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4441 break;
4442 case CMAS_AUTH_SEQ_2_FAIL:
4443 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4444 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4445 break;
4446 case CMAS_TX_ASSOC:
4447 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4448 IPW_DL_ASSOC, "TX_ASSOC\n");
4449 break;
4450 case CMAS_RX_ASSOC_RESP:
4451 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4452 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004453
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004454 break;
4455 case CMAS_ASSOCIATED:
4456 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4457 IPW_DL_ASSOC, "ASSOCIATED\n");
4458 break;
4459 default:
4460 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4461 auth->state);
4462 break;
4463 }
4464 break;
4465 }
4466
4467 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4468 struct notif_channel_result *x =
4469 &notif->u.channel_result;
4470
4471 if (notif->size == sizeof(*x)) {
4472 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4473 x->channel_num);
4474 } else {
4475 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4476 "(should be %zd)\n",
4477 notif->size, sizeof(*x));
4478 }
4479 break;
4480 }
4481
4482 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4483 struct notif_scan_complete *x = &notif->u.scan_complete;
4484 if (notif->size == sizeof(*x)) {
4485 IPW_DEBUG_SCAN
4486 ("Scan completed: type %d, %d channels, "
4487 "%d status\n", x->scan_type,
4488 x->num_channels, x->status);
4489 } else {
4490 IPW_ERROR("Scan completed of wrong size %d "
4491 "(should be %zd)\n",
4492 notif->size, sizeof(*x));
4493 }
4494
4495 priv->status &=
4496 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4497
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004498 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004499 cancel_delayed_work(&priv->scan_check);
4500
James Ketrenosb095c382005-08-24 22:04:42 -05004501 if (priv->status & STATUS_EXIT_PENDING)
4502 break;
4503
4504 priv->ieee->scans++;
4505
4506#ifdef CONFIG_IPW2200_MONITOR
4507 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004508 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004509 queue_work(priv->workqueue,
4510 &priv->request_scan);
4511 break;
4512 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004513 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004514#endif /* CONFIG_IPW2200_MONITOR */
4515
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004516 if (!(priv->status & (STATUS_ASSOCIATED |
4517 STATUS_ASSOCIATING |
4518 STATUS_ROAMING |
4519 STATUS_DISASSOCIATING)))
4520 queue_work(priv->workqueue, &priv->associate);
4521 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004522 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4523 /* If a scan completed and we are in roam mode, then
4524 * the scan that completed was the one requested as a
4525 * result of entering roam... so, schedule the
4526 * roam work */
4527 queue_work(priv->workqueue,
4528 &priv->roam);
4529 else
4530 /* Don't schedule if we aborted the scan */
4531 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004532 } else if (priv->status & STATUS_SCAN_PENDING)
4533 queue_work(priv->workqueue,
4534 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004535 else if (priv->config & CFG_BACKGROUND_SCAN
4536 && priv->status & STATUS_ASSOCIATED)
4537 queue_delayed_work(priv->workqueue,
4538 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004539 break;
4540 }
4541
4542 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4543 struct notif_frag_length *x = &notif->u.frag_len;
4544
James Ketrenosa613bff2005-08-24 21:43:11 -05004545 if (notif->size == sizeof(*x))
4546 IPW_ERROR("Frag length: %d\n",
4547 le16_to_cpu(x->frag_length));
4548 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004549 IPW_ERROR("Frag length of wrong size %d "
4550 "(should be %zd)\n",
4551 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 break;
4553 }
4554
4555 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4556 struct notif_link_deterioration *x =
4557 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004558
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004559 if (notif->size == sizeof(*x)) {
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4561 "link deterioration: '%s' " MAC_FMT
4562 " \n", escape_essid(priv->essid,
4563 priv->essid_len),
4564 MAC_ARG(priv->bssid));
4565 memcpy(&priv->last_link_deterioration, x,
4566 sizeof(*x));
4567 } else {
4568 IPW_ERROR("Link Deterioration of wrong size %d "
4569 "(should be %zd)\n",
4570 notif->size, sizeof(*x));
4571 }
4572 break;
4573 }
4574
4575 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4576 IPW_ERROR("Dino config\n");
4577 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004578 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004579 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004580
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004581 break;
4582 }
4583
4584 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4585 struct notif_beacon_state *x = &notif->u.beacon_state;
4586 if (notif->size != sizeof(*x)) {
4587 IPW_ERROR
4588 ("Beacon state of wrong size %d (should "
4589 "be %zd)\n", notif->size, sizeof(*x));
4590 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004591 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004592
James Ketrenosa613bff2005-08-24 21:43:11 -05004593 if (le32_to_cpu(x->state) ==
4594 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4595 ipw_handle_missed_beacon(priv,
4596 le32_to_cpu(x->
4597 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004598
James Ketrenos43f66a62005-03-25 12:31:53 -06004599 break;
4600 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004601
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004602 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4603 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4604 if (notif->size == sizeof(*x)) {
4605 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4606 "0x%02x station %d\n",
4607 x->key_state, x->security_type,
4608 x->station_index);
4609 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004610 }
4611
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004612 IPW_ERROR
4613 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4614 notif->size, sizeof(*x));
4615 break;
4616 }
4617
4618 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4619 struct notif_calibration *x = &notif->u.calibration;
4620
4621 if (notif->size == sizeof(*x)) {
4622 memcpy(&priv->calib, x, sizeof(*x));
4623 IPW_DEBUG_INFO("TODO: Calibration\n");
4624 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004625 }
4626
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004627 IPW_ERROR
4628 ("Calibration of wrong size %d (should be %zd)\n",
4629 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004630 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004631 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004632
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004633 case HOST_NOTIFICATION_NOISE_STATS:{
4634 if (notif->size == sizeof(u32)) {
4635 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004636 (u8) (le32_to_cpu(notif->u.noise.value) &
4637 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004638 average_add(&priv->average_noise,
4639 priv->last_noise);
4640 break;
4641 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004642
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004643 IPW_ERROR
4644 ("Noise stat is wrong size %d (should be %zd)\n",
4645 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004646 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004647 }
4648
James Ketrenos43f66a62005-03-25 12:31:53 -06004649 default:
4650 IPW_ERROR("Unknown notification: "
4651 "subtype=%d,flags=0x%2x,size=%d\n",
4652 notif->subtype, notif->flags, notif->size);
4653 }
4654}
4655
4656/**
4657 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004658 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004659 * @param priv
4660 * @return error code
4661 */
4662static int ipw_queue_reset(struct ipw_priv *priv)
4663{
4664 int rc = 0;
4665 /** @todo customize queue sizes */
4666 int nTx = 64, nTxCmd = 8;
4667 ipw_tx_queue_free(priv);
4668 /* Tx CMD queue */
4669 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004670 IPW_TX_CMD_QUEUE_READ_INDEX,
4671 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4672 IPW_TX_CMD_QUEUE_BD_BASE,
4673 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004674 if (rc) {
4675 IPW_ERROR("Tx Cmd queue init failed\n");
4676 goto error;
4677 }
4678 /* Tx queue(s) */
4679 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004680 IPW_TX_QUEUE_0_READ_INDEX,
4681 IPW_TX_QUEUE_0_WRITE_INDEX,
4682 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004683 if (rc) {
4684 IPW_ERROR("Tx 0 queue init failed\n");
4685 goto error;
4686 }
4687 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004688 IPW_TX_QUEUE_1_READ_INDEX,
4689 IPW_TX_QUEUE_1_WRITE_INDEX,
4690 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004691 if (rc) {
4692 IPW_ERROR("Tx 1 queue init failed\n");
4693 goto error;
4694 }
4695 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004696 IPW_TX_QUEUE_2_READ_INDEX,
4697 IPW_TX_QUEUE_2_WRITE_INDEX,
4698 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004699 if (rc) {
4700 IPW_ERROR("Tx 2 queue init failed\n");
4701 goto error;
4702 }
4703 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004704 IPW_TX_QUEUE_3_READ_INDEX,
4705 IPW_TX_QUEUE_3_WRITE_INDEX,
4706 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004707 if (rc) {
4708 IPW_ERROR("Tx 3 queue init failed\n");
4709 goto error;
4710 }
4711 /* statistics */
4712 priv->rx_bufs_min = 0;
4713 priv->rx_pend_max = 0;
4714 return rc;
4715
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004716 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 ipw_tx_queue_free(priv);
4718 return rc;
4719}
4720
4721/**
4722 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004723 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004724 * When FW adwances 'R' index, all entries between old and
4725 * new 'R' index need to be reclaimed. As result, some free space
4726 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004727 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004728 * @note Need to protect against garbage in 'R' index
4729 * @param priv
4730 * @param txq
4731 * @param qindex
4732 * @return Number of used entries remains in the queue
4733 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004734static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004735 struct clx2_tx_queue *txq, int qindex)
4736{
4737 u32 hw_tail;
4738 int used;
4739 struct clx2_queue *q = &txq->q;
4740
4741 hw_tail = ipw_read32(priv, q->reg_r);
4742 if (hw_tail >= q->n_bd) {
4743 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004744 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4745 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004746 goto done;
4747 }
4748 for (; q->last_used != hw_tail;
4749 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4750 ipw_queue_tx_free_tfd(priv, txq);
4751 priv->tx_packets++;
4752 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004753 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004754 if ((ipw_queue_space(q) > q->low_mark) &&
4755 (qindex >= 0) &&
4756 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4757 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004758 used = q->first_empty - q->last_used;
4759 if (used < 0)
4760 used += q->n_bd;
4761
4762 return used;
4763}
4764
4765static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4766 int len, int sync)
4767{
4768 struct clx2_tx_queue *txq = &priv->txq_cmd;
4769 struct clx2_queue *q = &txq->q;
4770 struct tfd_frame *tfd;
4771
4772 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4773 IPW_ERROR("No space for Tx\n");
4774 return -EBUSY;
4775 }
4776
4777 tfd = &txq->bd[q->first_empty];
4778 txq->txb[q->first_empty] = NULL;
4779
4780 memset(tfd, 0, sizeof(*tfd));
4781 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4782 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4783 priv->hcmd_seq++;
4784 tfd->u.cmd.index = hcmd;
4785 tfd->u.cmd.length = len;
4786 memcpy(tfd->u.cmd.payload, buf, len);
4787 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4788 ipw_write32(priv, q->reg_w, q->first_empty);
4789 _ipw_read32(priv, 0x90);
4790
4791 return 0;
4792}
4793
Jeff Garzikbf794512005-07-31 13:07:26 -04004794/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004795 * Rx theory of operation
4796 *
4797 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004798 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004799 * 0 to 31
4800 *
4801 * Rx Queue Indexes
4802 * The host/firmware share two index registers for managing the Rx buffers.
4803 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004804 * The READ index maps to the first position that the firmware may be writing
4805 * to -- the driver can read up to (but not including) this position and get
4806 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004807 * The READ index is managed by the firmware once the card is enabled.
4808 *
4809 * The WRITE index maps to the last position the driver has read from -- the
4810 * position preceding WRITE is the last slot the firmware can place a packet.
4811 *
4812 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004813 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004814 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004815 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004816 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4817 *
4818 * When the firmware places a packet in a buffer it will advance the READ index
4819 * and fire the RX interrupt. The driver can then query the READ index and
4820 * process as many packets as possible, moving the WRITE index forward as it
4821 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004822 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004823 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004824 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004825 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004826 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004827 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4828 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4829 * 'processed' and 'read' driver indexes as well)
4830 * + A received packet is processed and handed to the kernel network stack,
4831 * detached from the ipw->rxq. The driver 'processed' index is updated.
4832 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004833 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4834 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004835 * were enough free buffers and RX_STALLED is set it is cleared.
4836 *
4837 *
4838 * Driver sequence:
4839 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004840 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004841 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4842 * ipw_rx_queue_restock
4843 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4844 * queue, updates firmware pointers, and updates
4845 * the WRITE index. If insufficient rx_free buffers
4846 * are available, schedules ipw_rx_queue_replenish
4847 *
4848 * -- enable interrupts --
4849 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004850 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004851 * Moves the packet buffer from queue to rx_used.
4852 * Calls ipw_rx_queue_restock to refill any empty
4853 * slots.
4854 * ...
4855 *
4856 */
4857
Jeff Garzikbf794512005-07-31 13:07:26 -04004858/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004859 * If there are slots in the RX queue that need to be restocked,
4860 * and we have free pre-allocated buffers, fill the ranks as much
4861 * as we can pulling from rx_free.
4862 *
4863 * This moves the 'write' index forward to catch up with 'processed', and
4864 * also updates the memory address in the firmware to reference the new
4865 * target buffer.
4866 */
4867static void ipw_rx_queue_restock(struct ipw_priv *priv)
4868{
4869 struct ipw_rx_queue *rxq = priv->rxq;
4870 struct list_head *element;
4871 struct ipw_rx_mem_buffer *rxb;
4872 unsigned long flags;
4873 int write;
4874
4875 spin_lock_irqsave(&rxq->lock, flags);
4876 write = rxq->write;
4877 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4878 element = rxq->rx_free.next;
4879 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4880 list_del(element);
4881
James Ketrenosb095c382005-08-24 22:04:42 -05004882 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004883 rxb->dma_addr);
4884 rxq->queue[rxq->write] = rxb;
4885 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4886 rxq->free_count--;
4887 }
4888 spin_unlock_irqrestore(&rxq->lock, flags);
4889
Jeff Garzikbf794512005-07-31 13:07:26 -04004890 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004891 * refill it */
4892 if (rxq->free_count <= RX_LOW_WATERMARK)
4893 queue_work(priv->workqueue, &priv->rx_replenish);
4894
4895 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004896 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004897 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004898}
4899
4900/*
4901 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004902 * Also restock the Rx queue via ipw_rx_queue_restock.
4903 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004904 * This is called as a scheduled work item (except for during intialization)
4905 */
4906static void ipw_rx_queue_replenish(void *data)
4907{
4908 struct ipw_priv *priv = data;
4909 struct ipw_rx_queue *rxq = priv->rxq;
4910 struct list_head *element;
4911 struct ipw_rx_mem_buffer *rxb;
4912 unsigned long flags;
4913
4914 spin_lock_irqsave(&rxq->lock, flags);
4915 while (!list_empty(&rxq->rx_used)) {
4916 element = rxq->rx_used.next;
4917 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004918 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004919 if (!rxb->skb) {
4920 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4921 priv->net_dev->name);
4922 /* We don't reschedule replenish work here -- we will
4923 * call the restock method and if it still needs
4924 * more buffers it will schedule replenish */
4925 break;
4926 }
4927 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004928
James Ketrenos43f66a62005-03-25 12:31:53 -06004929 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004930 rxb->dma_addr =
4931 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004932 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004933
James Ketrenos43f66a62005-03-25 12:31:53 -06004934 list_add_tail(&rxb->list, &rxq->rx_free);
4935 rxq->free_count++;
4936 }
4937 spin_unlock_irqrestore(&rxq->lock, flags);
4938
4939 ipw_rx_queue_restock(priv);
4940}
4941
James Ketrenosc848d0a2005-08-24 21:56:24 -05004942static void ipw_bg_rx_queue_replenish(void *data)
4943{
4944 struct ipw_priv *priv = data;
4945 down(&priv->sem);
4946 ipw_rx_queue_replenish(data);
4947 up(&priv->sem);
4948}
4949
James Ketrenos43f66a62005-03-25 12:31:53 -06004950/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08004951 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004952 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004953 * non NULL it is unmapped and freed
4954 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004955static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004956{
4957 int i;
4958
4959 if (!rxq)
4960 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004961
James Ketrenos43f66a62005-03-25 12:31:53 -06004962 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4963 if (rxq->pool[i].skb != NULL) {
4964 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004965 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004966 dev_kfree_skb(rxq->pool[i].skb);
4967 }
4968 }
4969
4970 kfree(rxq);
4971}
4972
4973static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4974{
4975 struct ipw_rx_queue *rxq;
4976 int i;
4977
Takisc75f4742005-12-01 01:41:45 -08004978 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004979 if (unlikely(!rxq)) {
4980 IPW_ERROR("memory allocation failed\n");
4981 return NULL;
4982 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004983 spin_lock_init(&rxq->lock);
4984 INIT_LIST_HEAD(&rxq->rx_free);
4985 INIT_LIST_HEAD(&rxq->rx_used);
4986
4987 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004988 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004989 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4990
4991 /* Set us so that we have processed and used all buffers, but have
4992 * not restocked the Rx queue with fresh buffers */
4993 rxq->read = rxq->write = 0;
4994 rxq->processed = RX_QUEUE_SIZE - 1;
4995 rxq->free_count = 0;
4996
4997 return rxq;
4998}
4999
5000static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5001{
5002 rate &= ~IEEE80211_BASIC_RATE_MASK;
5003 if (ieee_mode == IEEE_A) {
5004 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005005 case IEEE80211_OFDM_RATE_6MB:
5006 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005007 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005008 case IEEE80211_OFDM_RATE_9MB:
5009 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005010 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005011 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005012 return priv->
5013 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005014 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005015 return priv->
5016 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005017 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005018 return priv->
5019 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005020 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005021 return priv->
5022 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005024 return priv->
5025 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005026 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005027 return priv->
5028 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005029 default:
5030 return 0;
5031 }
5032 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005033
James Ketrenos43f66a62005-03-25 12:31:53 -06005034 /* B and G mixed */
5035 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005036 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005037 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005038 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005039 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005040 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005041 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005042 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005043 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5044 }
5045
5046 /* If we are limited to B modulations, bail at this point */
5047 if (ieee_mode == IEEE_B)
5048 return 0;
5049
5050 /* G */
5051 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005052 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005053 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005054 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005055 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005056 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005057 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005058 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005059 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005060 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005061 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005062 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005064 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005065 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005066 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005067 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5068 }
5069
5070 return 0;
5071}
5072
Jeff Garzikbf794512005-07-31 13:07:26 -04005073static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005074 const struct ieee80211_network *network,
5075 struct ipw_supported_rates *rates)
5076{
5077 int num_rates, i;
5078
5079 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005080 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005081 rates->num_rates = 0;
5082 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005083 if (!ipw_is_rate_in_mask(priv, network->mode,
5084 network->rates[i])) {
5085
James Ketrenosea2b26e2005-08-24 21:25:16 -05005086 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005087 IPW_DEBUG_SCAN("Adding masked mandatory "
5088 "rate %02X\n",
5089 network->rates[i]);
5090 rates->supported_rates[rates->num_rates++] =
5091 network->rates[i];
5092 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005093 }
5094
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5096 network->rates[i], priv->rates_mask);
5097 continue;
5098 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005099
James Ketrenos43f66a62005-03-25 12:31:53 -06005100 rates->supported_rates[rates->num_rates++] = network->rates[i];
5101 }
5102
James Ketrenosa613bff2005-08-24 21:43:11 -05005103 num_rates = min(network->rates_ex_len,
5104 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005105 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005106 if (!ipw_is_rate_in_mask(priv, network->mode,
5107 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005108 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005109 IPW_DEBUG_SCAN("Adding masked mandatory "
5110 "rate %02X\n",
5111 network->rates_ex[i]);
5112 rates->supported_rates[rates->num_rates++] =
5113 network->rates[i];
5114 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005115 }
5116
James Ketrenos43f66a62005-03-25 12:31:53 -06005117 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5118 network->rates_ex[i], priv->rates_mask);
5119 continue;
5120 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005121
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005122 rates->supported_rates[rates->num_rates++] =
5123 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005124 }
5125
James Ketrenosea2b26e2005-08-24 21:25:16 -05005126 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005127}
5128
Arjan van de Ven858119e2006-01-14 13:20:43 -08005129static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005130 const struct ipw_supported_rates *src)
5131{
5132 u8 i;
5133 for (i = 0; i < src->num_rates; i++)
5134 dest->supported_rates[i] = src->supported_rates[i];
5135 dest->num_rates = src->num_rates;
5136}
5137
5138/* TODO: Look at sniffed packets in the air to determine if the basic rate
5139 * mask should ever be used -- right now all callers to add the scan rates are
5140 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5141static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005142 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005143{
Jeff Garzikbf794512005-07-31 13:07:26 -04005144 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005145 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005146
James Ketrenos43f66a62005-03-25 12:31:53 -06005147 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005148 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005149 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005150
5151 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005153 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005154
5155 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005156 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005157 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005158
5159 if (rate_mask & IEEE80211_CCK_RATE_11MB_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_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005162}
5163
5164static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005165 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005166{
Jeff Garzikbf794512005-07-31 13:07:26 -04005167 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005168 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005169
5170 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005172 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005173
5174 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005175 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005176 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005177
5178 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005179 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005180 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005181
5182 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005184 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005185
5186 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005187 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005188 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005189
5190 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005192 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005193
5194 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005195 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005196 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005197
5198 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005199 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005200 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005201}
5202
5203struct ipw_network_match {
5204 struct ieee80211_network *network;
5205 struct ipw_supported_rates rates;
5206};
5207
James Ketrenosc848d0a2005-08-24 21:56:24 -05005208static int ipw_find_adhoc_network(struct ipw_priv *priv,
5209 struct ipw_network_match *match,
5210 struct ieee80211_network *network,
5211 int roaming)
5212{
5213 struct ipw_supported_rates rates;
5214
5215 /* Verify that this network's capability is compatible with the
5216 * current mode (AdHoc or Infrastructure) */
5217 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5218 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5219 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5220 "capability mismatch.\n",
5221 escape_essid(network->ssid, network->ssid_len),
5222 MAC_ARG(network->bssid));
5223 return 0;
5224 }
5225
5226 /* If we do not have an ESSID for this AP, we can not associate with
5227 * it */
5228 if (network->flags & NETWORK_EMPTY_ESSID) {
5229 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5230 "because of hidden ESSID.\n",
5231 escape_essid(network->ssid, network->ssid_len),
5232 MAC_ARG(network->bssid));
5233 return 0;
5234 }
5235
5236 if (unlikely(roaming)) {
5237 /* If we are roaming, then ensure check if this is a valid
5238 * network to try and roam to */
5239 if ((network->ssid_len != match->network->ssid_len) ||
5240 memcmp(network->ssid, match->network->ssid,
5241 network->ssid_len)) {
5242 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5243 "because of non-network ESSID.\n",
5244 escape_essid(network->ssid,
5245 network->ssid_len),
5246 MAC_ARG(network->bssid));
5247 return 0;
5248 }
5249 } else {
5250 /* If an ESSID has been configured then compare the broadcast
5251 * ESSID to ours */
5252 if ((priv->config & CFG_STATIC_ESSID) &&
5253 ((network->ssid_len != priv->essid_len) ||
5254 memcmp(network->ssid, priv->essid,
5255 min(network->ssid_len, priv->essid_len)))) {
5256 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005257
James Ketrenosc848d0a2005-08-24 21:56:24 -05005258 strncpy(escaped,
5259 escape_essid(network->ssid, network->ssid_len),
5260 sizeof(escaped));
5261 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5262 "because of ESSID mismatch: '%s'.\n",
5263 escaped, MAC_ARG(network->bssid),
5264 escape_essid(priv->essid,
5265 priv->essid_len));
5266 return 0;
5267 }
5268 }
5269
5270 /* If the old network rate is better than this one, don't bother
5271 * testing everything else. */
5272
5273 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005274 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5275 "current network.\n",
5276 escape_essid(match->network->ssid,
5277 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005278 return 0;
5279 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005280 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5281 "current network.\n",
5282 escape_essid(match->network->ssid,
5283 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005284 return 0;
5285 }
5286
5287 /* Now go through and see if the requested network is valid... */
5288 if (priv->ieee->scan_age != 0 &&
5289 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5290 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005291 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005292 escape_essid(network->ssid, network->ssid_len),
5293 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005294 jiffies_to_msecs(jiffies - network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005295 return 0;
5296 }
5297
5298 if ((priv->config & CFG_STATIC_CHANNEL) &&
5299 (network->channel != priv->channel)) {
5300 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5301 "because of channel mismatch: %d != %d.\n",
5302 escape_essid(network->ssid, network->ssid_len),
5303 MAC_ARG(network->bssid),
5304 network->channel, priv->channel);
5305 return 0;
5306 }
5307
5308 /* Verify privacy compatability */
5309 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5310 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5311 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5312 "because of privacy mismatch: %s != %s.\n",
5313 escape_essid(network->ssid, network->ssid_len),
5314 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005315 priv->
5316 capability & CAP_PRIVACY_ON ? "on" : "off",
5317 network->
5318 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5319 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005320 return 0;
5321 }
5322
5323 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5324 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5325 "because of the same BSSID match: " MAC_FMT
5326 ".\n", escape_essid(network->ssid,
5327 network->ssid_len),
5328 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5329 return 0;
5330 }
5331
5332 /* Filter out any incompatible freq / mode combinations */
5333 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5334 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5335 "because of invalid frequency/mode "
5336 "combination.\n",
5337 escape_essid(network->ssid, network->ssid_len),
5338 MAC_ARG(network->bssid));
5339 return 0;
5340 }
5341
5342 /* Ensure that the rates supported by the driver are compatible with
5343 * this AP, including verification of basic rates (mandatory) */
5344 if (!ipw_compatible_rates(priv, network, &rates)) {
5345 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5346 "because configured rate mask excludes "
5347 "AP mandatory rate.\n",
5348 escape_essid(network->ssid, network->ssid_len),
5349 MAC_ARG(network->bssid));
5350 return 0;
5351 }
5352
5353 if (rates.num_rates == 0) {
5354 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5355 "because of no compatible rates.\n",
5356 escape_essid(network->ssid, network->ssid_len),
5357 MAC_ARG(network->bssid));
5358 return 0;
5359 }
5360
5361 /* TODO: Perform any further minimal comparititive tests. We do not
5362 * want to put too much policy logic here; intelligent scan selection
5363 * should occur within a generic IEEE 802.11 user space tool. */
5364
5365 /* Set up 'new' AP to this network */
5366 ipw_copy_rates(&match->rates, &rates);
5367 match->network = network;
5368 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5369 escape_essid(network->ssid, network->ssid_len),
5370 MAC_ARG(network->bssid));
5371
5372 return 1;
5373}
5374
5375static void ipw_merge_adhoc_network(void *data)
5376{
5377 struct ipw_priv *priv = data;
5378 struct ieee80211_network *network = NULL;
5379 struct ipw_network_match match = {
5380 .network = priv->assoc_network
5381 };
5382
James Ketrenosafbf30a2005-08-25 00:05:33 -05005383 if ((priv->status & STATUS_ASSOCIATED) &&
5384 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005385 /* First pass through ROAM process -- look for a better
5386 * network */
5387 unsigned long flags;
5388
5389 spin_lock_irqsave(&priv->ieee->lock, flags);
5390 list_for_each_entry(network, &priv->ieee->network_list, list) {
5391 if (network != priv->assoc_network)
5392 ipw_find_adhoc_network(priv, &match, network,
5393 1);
5394 }
5395 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5396
5397 if (match.network == priv->assoc_network) {
5398 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5399 "merge to.\n");
5400 return;
5401 }
5402
5403 down(&priv->sem);
5404 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5405 IPW_DEBUG_MERGE("remove network %s\n",
5406 escape_essid(priv->essid,
5407 priv->essid_len));
5408 ipw_remove_current_network(priv);
5409 }
5410
5411 ipw_disassociate(priv);
5412 priv->assoc_network = match.network;
5413 up(&priv->sem);
5414 return;
5415 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005416}
5417
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005418static int ipw_best_network(struct ipw_priv *priv,
5419 struct ipw_network_match *match,
5420 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005421{
5422 struct ipw_supported_rates rates;
5423
5424 /* Verify that this network's capability is compatible with the
5425 * current mode (AdHoc or Infrastructure) */
5426 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005427 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005428 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5429 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5430 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005431 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005432 escape_essid(network->ssid, network->ssid_len),
5433 MAC_ARG(network->bssid));
5434 return 0;
5435 }
5436
5437 /* If we do not have an ESSID for this AP, we can not associate with
5438 * it */
5439 if (network->flags & NETWORK_EMPTY_ESSID) {
5440 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5441 "because of hidden ESSID.\n",
5442 escape_essid(network->ssid, network->ssid_len),
5443 MAC_ARG(network->bssid));
5444 return 0;
5445 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005446
James Ketrenos43f66a62005-03-25 12:31:53 -06005447 if (unlikely(roaming)) {
5448 /* If we are roaming, then ensure check if this is a valid
5449 * network to try and roam to */
5450 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005451 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005452 network->ssid_len)) {
5453 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5454 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005455 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005456 network->ssid_len),
5457 MAC_ARG(network->bssid));
5458 return 0;
5459 }
5460 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005461 /* If an ESSID has been configured then compare the broadcast
5462 * ESSID to ours */
5463 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005464 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005465 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005466 min(network->ssid_len, priv->essid_len)))) {
5467 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005468 strncpy(escaped,
5469 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005470 sizeof(escaped));
5471 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005472 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005473 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005474 escape_essid(priv->essid,
5475 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005476 return 0;
5477 }
5478 }
5479
5480 /* If the old network rate is better than this one, don't bother
5481 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005482 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005483 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005484 strncpy(escaped,
5485 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 sizeof(escaped));
5487 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5488 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5489 escaped, MAC_ARG(network->bssid),
5490 escape_essid(match->network->ssid,
5491 match->network->ssid_len),
5492 MAC_ARG(match->network->bssid));
5493 return 0;
5494 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005495
James Ketrenos43f66a62005-03-25 12:31:53 -06005496 /* If this network has already had an association attempt within the
5497 * last 3 seconds, do not try and associate again... */
5498 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005499 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005500 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005501 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005502 "assoc attempt).\n",
5503 escape_essid(network->ssid, network->ssid_len),
5504 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005505 jiffies_to_msecs(jiffies - network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005506 return 0;
5507 }
5508
5509 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005510 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005511 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005512 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005513 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005514 escape_essid(network->ssid, network->ssid_len),
5515 MAC_ARG(network->bssid),
Zhu Yic7b6a672006-01-24 16:37:05 +08005516 jiffies_to_msecs(jiffies - network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005517 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005518 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005519
Jeff Garzikbf794512005-07-31 13:07:26 -04005520 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005521 (network->channel != priv->channel)) {
5522 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5523 "because of channel mismatch: %d != %d.\n",
5524 escape_essid(network->ssid, network->ssid_len),
5525 MAC_ARG(network->bssid),
5526 network->channel, priv->channel);
5527 return 0;
5528 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005529
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005531 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005532 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5533 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5534 "because of privacy mismatch: %s != %s.\n",
5535 escape_essid(network->ssid, network->ssid_len),
5536 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005537 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005538 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005539 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005540 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005541 return 0;
5542 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005543
Hong Liucdd1fa12005-08-31 18:14:27 +08005544 if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
5545 network->rsn_ie_len > 0)) {
5546 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5547 "because of WPA capability mismatch.\n",
5548 escape_essid(network->ssid, network->ssid_len),
5549 MAC_ARG(network->bssid));
5550 return 0;
5551 }
5552
Jeff Garzikbf794512005-07-31 13:07:26 -04005553 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005554 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5555 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5556 "because of BSSID mismatch: " MAC_FMT ".\n",
5557 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005558 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005559 return 0;
5560 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005561
James Ketrenos43f66a62005-03-25 12:31:53 -06005562 /* Filter out any incompatible freq / mode combinations */
5563 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5564 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5565 "because of invalid frequency/mode "
5566 "combination.\n",
5567 escape_essid(network->ssid, network->ssid_len),
5568 MAC_ARG(network->bssid));
5569 return 0;
5570 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005571
Liu Hong1fe0adb2005-08-19 09:33:10 -05005572 /* Filter out invalid channel in current GEO */
5573 if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5574 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5575 "because of invalid channel in current GEO\n",
5576 escape_essid(network->ssid, network->ssid_len),
5577 MAC_ARG(network->bssid));
5578 return 0;
5579 }
5580
James Ketrenosea2b26e2005-08-24 21:25:16 -05005581 /* Ensure that the rates supported by the driver are compatible with
5582 * this AP, including verification of basic rates (mandatory) */
5583 if (!ipw_compatible_rates(priv, network, &rates)) {
5584 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5585 "because configured rate mask excludes "
5586 "AP mandatory rate.\n",
5587 escape_essid(network->ssid, network->ssid_len),
5588 MAC_ARG(network->bssid));
5589 return 0;
5590 }
5591
James Ketrenos43f66a62005-03-25 12:31:53 -06005592 if (rates.num_rates == 0) {
5593 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5594 "because of no compatible rates.\n",
5595 escape_essid(network->ssid, network->ssid_len),
5596 MAC_ARG(network->bssid));
5597 return 0;
5598 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005599
James Ketrenos43f66a62005-03-25 12:31:53 -06005600 /* TODO: Perform any further minimal comparititive tests. We do not
5601 * want to put too much policy logic here; intelligent scan selection
5602 * should occur within a generic IEEE 802.11 user space tool. */
5603
5604 /* Set up 'new' AP to this network */
5605 ipw_copy_rates(&match->rates, &rates);
5606 match->network = network;
5607
5608 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5609 escape_essid(network->ssid, network->ssid_len),
5610 MAC_ARG(network->bssid));
5611
5612 return 1;
5613}
5614
Jeff Garzikbf794512005-07-31 13:07:26 -04005615static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005616 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005617{
Liu Hong1fe0adb2005-08-19 09:33:10 -05005618 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005619 int i;
5620
James Ketrenos43f66a62005-03-25 12:31:53 -06005621 /*
5622 * For the purposes of scanning, we can set our wireless mode
5623 * to trigger scans across combinations of bands, but when it
5624 * comes to creating a new ad-hoc network, we have tell the FW
5625 * exactly which band to use.
5626 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005627 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005628 * chossen band. Attempting to create a new ad-hoc network
5629 * with an invalid channel for wireless mode will trigger a
5630 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005631 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005632 */
Liu Hong1fe0adb2005-08-19 09:33:10 -05005633 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005634 case IEEE80211_52GHZ_BAND:
5635 network->mode = IEEE_A;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005636 i = ipw_channel_to_index(priv->ieee, priv->channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005637 if (i == -1)
5638 BUG();
5639 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5640 IPW_WARNING("Overriding invalid channel\n");
5641 priv->channel = geo->a[0].channel;
5642 }
5643 break;
5644
5645 case IEEE80211_24GHZ_BAND:
5646 if (priv->ieee->mode & IEEE_G)
5647 network->mode = IEEE_G;
5648 else
5649 network->mode = IEEE_B;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005650 i = ipw_channel_to_index(priv->ieee, priv->channel);
5651 if (i == -1)
5652 BUG();
5653 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5654 IPW_WARNING("Overriding invalid channel\n");
5655 priv->channel = geo->bg[0].channel;
5656 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005657 break;
5658
5659 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005660 IPW_WARNING("Overriding invalid channel\n");
5661 if (priv->ieee->mode & IEEE_A) {
5662 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005663 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005664 } else if (priv->ieee->mode & IEEE_G) {
5665 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005666 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005667 } else {
5668 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005669 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005670 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005671 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005672 }
5673
5674 network->channel = priv->channel;
5675 priv->config |= CFG_ADHOC_PERSIST;
5676 ipw_create_bssid(priv, network->bssid);
5677 network->ssid_len = priv->essid_len;
5678 memcpy(network->ssid, priv->essid, priv->essid_len);
5679 memset(&network->stats, 0, sizeof(network->stats));
5680 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005681 if (!(priv->config & CFG_PREAMBLE_LONG))
5682 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005683 if (priv->capability & CAP_PRIVACY_ON)
5684 network->capability |= WLAN_CAPABILITY_PRIVACY;
5685 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005686 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005687 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005688 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005689 &priv->rates.supported_rates[network->rates_len],
5690 network->rates_ex_len);
5691 network->last_scanned = 0;
5692 network->flags = 0;
5693 network->last_associate = 0;
5694 network->time_stamp[0] = 0;
5695 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005696 network->beacon_interval = 100; /* Default */
5697 network->listen_interval = 10; /* Default */
5698 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005699 network->wpa_ie_len = 0;
5700 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005701}
5702
James Ketrenosb095c382005-08-24 22:04:42 -05005703static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5704{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005705 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005706
5707 if (!(priv->ieee->sec.flags & (1 << index)))
5708 return;
5709
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005710 key.key_id = index;
5711 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5712 key.security_type = type;
5713 key.station_index = 0; /* always 0 for BSS */
5714 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005715 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005716 key.tx_counter[0] = 0;
5717 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005718
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005719 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005720}
5721
5722static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005723{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005724 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005725 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005726
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005727 key.cmd_id = DINO_CMD_WEP_KEY;
5728 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005729
James Ketrenosb095c382005-08-24 22:04:42 -05005730 /* Note: AES keys cannot be set for multiple times.
5731 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005732 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005733 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005734 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005735 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005736 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005737 }
5738
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005739 key.key_size = priv->ieee->sec.key_sizes[i];
5740 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005741
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005742 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005743 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005744}
5745
Zhu Yi1fbfea52005-08-05 17:22:56 +08005746static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5747{
5748 if (priv->ieee->host_encrypt)
5749 return;
5750
5751 switch (level) {
5752 case SEC_LEVEL_3:
5753 priv->sys_config.disable_unicast_decryption = 0;
5754 priv->ieee->host_decrypt = 0;
5755 break;
5756 case SEC_LEVEL_2:
5757 priv->sys_config.disable_unicast_decryption = 1;
5758 priv->ieee->host_decrypt = 1;
5759 break;
5760 case SEC_LEVEL_1:
5761 priv->sys_config.disable_unicast_decryption = 0;
5762 priv->ieee->host_decrypt = 0;
5763 break;
5764 case SEC_LEVEL_0:
5765 priv->sys_config.disable_unicast_decryption = 1;
5766 break;
5767 default:
5768 break;
5769 }
5770}
5771
5772static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5773{
5774 if (priv->ieee->host_encrypt)
5775 return;
5776
5777 switch (level) {
5778 case SEC_LEVEL_3:
5779 priv->sys_config.disable_multicast_decryption = 0;
5780 break;
5781 case SEC_LEVEL_2:
5782 priv->sys_config.disable_multicast_decryption = 1;
5783 break;
5784 case SEC_LEVEL_1:
5785 priv->sys_config.disable_multicast_decryption = 0;
5786 break;
5787 case SEC_LEVEL_0:
5788 priv->sys_config.disable_multicast_decryption = 1;
5789 break;
5790 default:
5791 break;
5792 }
5793}
5794
James Ketrenosb095c382005-08-24 22:04:42 -05005795static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5796{
5797 switch (priv->ieee->sec.level) {
5798 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005799 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5800 ipw_send_tgi_tx_key(priv,
5801 DCT_FLAG_EXT_SECURITY_CCM,
5802 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005803
Hong Liu567deaf2005-08-31 18:07:22 +08005804 if (!priv->ieee->host_mc_decrypt)
5805 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005806 break;
5807 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005808 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5809 ipw_send_tgi_tx_key(priv,
5810 DCT_FLAG_EXT_SECURITY_TKIP,
5811 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005812 break;
5813 case SEC_LEVEL_1:
5814 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005815 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5816 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005817 break;
5818 case SEC_LEVEL_0:
5819 default:
5820 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 }
5822}
5823
5824static void ipw_adhoc_check(void *data)
5825{
5826 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005827
James Ketrenosafbf30a2005-08-25 00:05:33 -05005828 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005829 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005830 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5831 IPW_DL_STATE | IPW_DL_ASSOC,
5832 "Missed beacon: %d - disassociate\n",
5833 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005834 ipw_remove_current_network(priv);
5835 ipw_disassociate(priv);
5836 return;
5837 }
5838
Jeff Garzikbf794512005-07-31 13:07:26 -04005839 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005840 priv->assoc_request.beacon_interval);
5841}
5842
James Ketrenosc848d0a2005-08-24 21:56:24 -05005843static void ipw_bg_adhoc_check(void *data)
5844{
5845 struct ipw_priv *priv = data;
5846 down(&priv->sem);
5847 ipw_adhoc_check(data);
5848 up(&priv->sem);
5849}
5850
Brice Goglin0f52bf92005-12-01 01:41:46 -08005851#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005852static void ipw_debug_config(struct ipw_priv *priv)
5853{
5854 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5855 "[CFG 0x%08X]\n", priv->config);
5856 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005857 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005858 else
5859 IPW_DEBUG_INFO("Channel unlocked.\n");
5860 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005861 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005862 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005863 else
5864 IPW_DEBUG_INFO("ESSID unlocked.\n");
5865 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005866 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5867 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005868 else
5869 IPW_DEBUG_INFO("BSSID unlocked.\n");
5870 if (priv->capability & CAP_PRIVACY_ON)
5871 IPW_DEBUG_INFO("PRIVACY on\n");
5872 else
5873 IPW_DEBUG_INFO("PRIVACY off\n");
5874 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5875}
5876#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005877#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005878#endif
5879
Arjan van de Ven858119e2006-01-14 13:20:43 -08005880static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005881{
5882 /* TODO: Verify that this works... */
5883 struct ipw_fixed_rate fr = {
5884 .tx_rates = priv->rates_mask
5885 };
5886 u32 reg;
5887 u16 mask = 0;
5888
Jeff Garzikbf794512005-07-31 13:07:26 -04005889 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005890 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005891
James Ketrenos43f66a62005-03-25 12:31:53 -06005892 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005893 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005894 /* IEEE_A */
5895 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5896 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005897 IPW_DEBUG_WX
5898 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 fr.tx_rates = 0;
5900 break;
5901 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005902
James Ketrenos43f66a62005-03-25 12:31:53 -06005903 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5904 break;
5905
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005906 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005907 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005908 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005909 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5910 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005911 IPW_DEBUG_WX
5912 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005913 fr.tx_rates = 0;
5914 }
5915 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005916 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005917
5918 /* IEEE_G */
5919 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5920 IEEE80211_OFDM_RATES_MASK)) {
5921 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005922 IPW_DEBUG_WX
5923 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005924 fr.tx_rates = 0;
5925 break;
5926 }
5927
5928 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5929 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5930 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5931 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005932
James Ketrenos43f66a62005-03-25 12:31:53 -06005933 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5934 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5935 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5936 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005937
James Ketrenos43f66a62005-03-25 12:31:53 -06005938 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5939 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5940 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5941 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005942
James Ketrenos43f66a62005-03-25 12:31:53 -06005943 fr.tx_rates |= mask;
5944 break;
5945 }
5946
5947 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005948 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005949}
5950
James Ketrenosea2b26e2005-08-24 21:25:16 -05005951static void ipw_abort_scan(struct ipw_priv *priv)
5952{
5953 int err;
5954
5955 if (priv->status & STATUS_SCAN_ABORTING) {
5956 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5957 return;
5958 }
5959 priv->status |= STATUS_SCAN_ABORTING;
5960
5961 err = ipw_send_scan_abort(priv);
5962 if (err)
5963 IPW_DEBUG_HC("Request to abort scan failed.\n");
5964}
5965
James Ketrenosafbf30a2005-08-25 00:05:33 -05005966static void ipw_add_scan_channels(struct ipw_priv *priv,
5967 struct ipw_scan_request_ext *scan,
5968 int scan_type)
5969{
5970 int channel_index = 0;
5971 const struct ieee80211_geo *geo;
5972 int i;
5973
Liu Hong1fe0adb2005-08-19 09:33:10 -05005974 geo = ipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005975
5976 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5977 int start = channel_index;
5978 for (i = 0; i < geo->a_channels; i++) {
5979 if ((priv->status & STATUS_ASSOCIATED) &&
5980 geo->a[i].channel == priv->channel)
5981 continue;
5982 channel_index++;
5983 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005984 ipw_set_scan_type(scan, channel_index,
5985 geo->a[i].
5986 flags & IEEE80211_CH_PASSIVE_ONLY ?
5987 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5988 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005989 }
5990
5991 if (start != channel_index) {
5992 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5993 (channel_index - start);
5994 channel_index++;
5995 }
5996 }
5997
5998 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5999 int start = channel_index;
6000 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006001 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006002 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6003 /* nop out the list */
6004 [0] = 0
6005 };
6006
6007 u8 channel;
6008 while (channel_index < IPW_SCAN_CHANNELS) {
6009 channel =
6010 priv->speed_scan[priv->speed_scan_pos];
6011 if (channel == 0) {
6012 priv->speed_scan_pos = 0;
6013 channel = priv->speed_scan[0];
6014 }
6015 if ((priv->status & STATUS_ASSOCIATED) &&
6016 channel == priv->channel) {
6017 priv->speed_scan_pos++;
6018 continue;
6019 }
6020
6021 /* If this channel has already been
6022 * added in scan, break from loop
6023 * and this will be the first channel
6024 * in the next scan.
6025 */
6026 if (channels[channel - 1] != 0)
6027 break;
6028
6029 channels[channel - 1] = 1;
6030 priv->speed_scan_pos++;
6031 channel_index++;
6032 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006033 index =
6034 ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006035 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006036 geo->bg[index].
6037 flags &
6038 IEEE80211_CH_PASSIVE_ONLY ?
6039 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6040 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006041 }
6042 } else {
6043 for (i = 0; i < geo->bg_channels; i++) {
6044 if ((priv->status & STATUS_ASSOCIATED) &&
6045 geo->bg[i].channel == priv->channel)
6046 continue;
6047 channel_index++;
6048 scan->channels_list[channel_index] =
6049 geo->bg[i].channel;
6050 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006051 geo->bg[i].
6052 flags &
6053 IEEE80211_CH_PASSIVE_ONLY ?
6054 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6055 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006056 }
6057 }
6058
6059 if (start != channel_index) {
6060 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6061 (channel_index - start);
6062 }
6063 }
6064}
6065
James Ketrenosea2b26e2005-08-24 21:25:16 -05006066static int ipw_request_scan(struct ipw_priv *priv)
6067{
6068 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006069 int err = 0, scan_type;
6070
6071 if (!(priv->status & STATUS_INIT) ||
6072 (priv->status & STATUS_EXIT_PENDING))
6073 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006074
James Ketrenosb095c382005-08-24 22:04:42 -05006075 down(&priv->sem);
6076
James Ketrenosea2b26e2005-08-24 21:25:16 -05006077 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006078 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006079 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006080 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006081 }
6082
James Ketrenosafbf30a2005-08-25 00:05:33 -05006083 if (!(priv->status & STATUS_SCAN_FORCED) &&
6084 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006085 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6086 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006087 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006088 }
6089
6090 if (priv->status & STATUS_RF_KILL_MASK) {
6091 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6092 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006093 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006094 }
6095
6096 memset(&scan, 0, sizeof(scan));
6097
James Ketrenosb095c382005-08-24 22:04:42 -05006098 if (priv->config & CFG_SPEED_SCAN)
6099 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6100 cpu_to_le16(30);
6101 else
6102 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6103 cpu_to_le16(20);
6104
James Ketrenosa613bff2005-08-24 21:43:11 -05006105 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6106 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006107 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006108
James Ketrenosa613bff2005-08-24 21:43:11 -05006109 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006110
James Ketrenosb095c382005-08-24 22:04:42 -05006111#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006112 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006113 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006114 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006115
Liu Hong1fe0adb2005-08-19 09:33:10 -05006116 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006117 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006118 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006119 channel = priv->channel;
6120 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006121
James Ketrenosb095c382005-08-24 22:04:42 -05006122 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006123 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006124 channel = priv->channel;
6125 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006126
James Ketrenosb095c382005-08-24 22:04:42 -05006127 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006128 band = (u8) (IPW_B_MODE << 6) | 1;
6129 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006130 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006131 }
6132
James Ketrenosb095c382005-08-24 22:04:42 -05006133 scan.channels_list[0] = band;
6134 scan.channels_list[1] = channel;
6135 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006136
James Ketrenosb095c382005-08-24 22:04:42 -05006137 /* NOTE: The card will sit on this channel for this time
6138 * period. Scan aborts are timing sensitive and frequently
6139 * result in firmware restarts. As such, it is best to
6140 * set a small dwell_time here and just keep re-issuing
6141 * scans. Otherwise fast channel hopping will not actually
6142 * hop channels.
6143 *
6144 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006145 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6146 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006147 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006148#endif /* CONFIG_IPW2200_MONITOR */
6149 /* If we are roaming, then make this a directed scan for the
6150 * current network. Otherwise, ensure that every other scan
6151 * is a fast channel hop scan */
6152 if ((priv->status & STATUS_ROAMING)
6153 || (!(priv->status & STATUS_ASSOCIATED)
6154 && (priv->config & CFG_STATIC_ESSID)
6155 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006156 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6157 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006158 IPW_DEBUG_HC("Attempt to send SSID command "
6159 "failed.\n");
6160 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006161 }
6162
6163 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006164 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006165 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006166
James Ketrenosafbf30a2005-08-25 00:05:33 -05006167 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006168#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006169 }
6170#endif
6171
6172 err = ipw_send_scan_request_ext(priv, &scan);
6173 if (err) {
6174 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006175 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006176 }
6177
6178 priv->status |= STATUS_SCANNING;
6179 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006180 queue_delayed_work(priv->workqueue, &priv->scan_check,
6181 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006182 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006183 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006184 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006185}
6186
6187static void ipw_bg_abort_scan(void *data)
6188{
6189 struct ipw_priv *priv = data;
6190 down(&priv->sem);
6191 ipw_abort_scan(data);
6192 up(&priv->sem);
6193}
6194
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6196{
James Ketrenosb095c382005-08-24 22:04:42 -05006197 /* This is called when wpa_supplicant loads and closes the driver
6198 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006199 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006200 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006201}
6202
James Ketrenosea2b26e2005-08-24 21:25:16 -05006203static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6204{
6205 struct ieee80211_device *ieee = priv->ieee;
6206 struct ieee80211_security sec = {
6207 .flags = SEC_AUTH_MODE,
6208 };
6209 int ret = 0;
6210
James Ketrenosafbf30a2005-08-25 00:05:33 -05006211 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006212 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6213 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006214 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006215 sec.auth_mode = WLAN_AUTH_OPEN;
6216 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006217 } else if (value & IW_AUTH_ALG_LEAP) {
6218 sec.auth_mode = WLAN_AUTH_LEAP;
6219 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006220 } else
6221 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006222
6223 if (ieee->set_security)
6224 ieee->set_security(ieee->dev, &sec);
6225 else
6226 ret = -EOPNOTSUPP;
6227
6228 return ret;
6229}
6230
Adrian Bunka73e22b2006-01-21 01:39:42 +01006231static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6232 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006233{
6234 /* make sure WPA is enabled */
6235 ipw_wpa_enable(priv, 1);
6236
6237 ipw_disassociate(priv);
6238}
6239
6240static int ipw_set_rsn_capa(struct ipw_priv *priv,
6241 char *capabilities, int length)
6242{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006243 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6244
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006245 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6246 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006247}
6248
James Ketrenosafbf30a2005-08-25 00:05:33 -05006249/*
6250 * WE-18 support
6251 */
6252
6253/* SIOCSIWGENIE */
6254static int ipw_wx_set_genie(struct net_device *dev,
6255 struct iw_request_info *info,
6256 union iwreq_data *wrqu, char *extra)
6257{
6258 struct ipw_priv *priv = ieee80211_priv(dev);
6259 struct ieee80211_device *ieee = priv->ieee;
6260 u8 *buf;
6261 int err = 0;
6262
6263 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6264 (wrqu->data.length && extra == NULL))
6265 return -EINVAL;
6266
6267 //down(&priv->sem);
6268
6269 //if (!ieee->wpa_enabled) {
6270 // err = -EOPNOTSUPP;
6271 // goto out;
6272 //}
6273
6274 if (wrqu->data.length) {
6275 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6276 if (buf == NULL) {
6277 err = -ENOMEM;
6278 goto out;
6279 }
6280
6281 memcpy(buf, extra, wrqu->data.length);
6282 kfree(ieee->wpa_ie);
6283 ieee->wpa_ie = buf;
6284 ieee->wpa_ie_len = wrqu->data.length;
6285 } else {
6286 kfree(ieee->wpa_ie);
6287 ieee->wpa_ie = NULL;
6288 ieee->wpa_ie_len = 0;
6289 }
6290
6291 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6292 out:
6293 //up(&priv->sem);
6294 return err;
6295}
6296
6297/* SIOCGIWGENIE */
6298static int ipw_wx_get_genie(struct net_device *dev,
6299 struct iw_request_info *info,
6300 union iwreq_data *wrqu, char *extra)
6301{
6302 struct ipw_priv *priv = ieee80211_priv(dev);
6303 struct ieee80211_device *ieee = priv->ieee;
6304 int err = 0;
6305
6306 //down(&priv->sem);
6307
6308 //if (!ieee->wpa_enabled) {
6309 // err = -EOPNOTSUPP;
6310 // goto out;
6311 //}
6312
6313 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6314 wrqu->data.length = 0;
6315 goto out;
6316 }
6317
6318 if (wrqu->data.length < ieee->wpa_ie_len) {
6319 err = -E2BIG;
6320 goto out;
6321 }
6322
6323 wrqu->data.length = ieee->wpa_ie_len;
6324 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6325
6326 out:
6327 //up(&priv->sem);
6328 return err;
6329}
6330
Zhu Yi1fbfea52005-08-05 17:22:56 +08006331static int wext_cipher2level(int cipher)
6332{
6333 switch (cipher) {
6334 case IW_AUTH_CIPHER_NONE:
6335 return SEC_LEVEL_0;
6336 case IW_AUTH_CIPHER_WEP40:
6337 case IW_AUTH_CIPHER_WEP104:
6338 return SEC_LEVEL_1;
6339 case IW_AUTH_CIPHER_TKIP:
6340 return SEC_LEVEL_2;
6341 case IW_AUTH_CIPHER_CCMP:
6342 return SEC_LEVEL_3;
6343 default:
6344 return -1;
6345 }
6346}
6347
James Ketrenosafbf30a2005-08-25 00:05:33 -05006348/* SIOCSIWAUTH */
6349static int ipw_wx_set_auth(struct net_device *dev,
6350 struct iw_request_info *info,
6351 union iwreq_data *wrqu, char *extra)
6352{
6353 struct ipw_priv *priv = ieee80211_priv(dev);
6354 struct ieee80211_device *ieee = priv->ieee;
6355 struct iw_param *param = &wrqu->param;
6356 struct ieee80211_crypt_data *crypt;
6357 unsigned long flags;
6358 int ret = 0;
6359
6360 switch (param->flags & IW_AUTH_INDEX) {
6361 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006362 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006363 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006364 ipw_set_hw_decrypt_unicast(priv,
6365 wext_cipher2level(param->value));
6366 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006367 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006368 ipw_set_hw_decrypt_multicast(priv,
6369 wext_cipher2level(param->value));
6370 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006371 case IW_AUTH_KEY_MGMT:
6372 /*
6373 * ipw2200 does not use these parameters
6374 */
6375 break;
6376
6377 case IW_AUTH_TKIP_COUNTERMEASURES:
6378 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006379 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006380 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006381
6382 flags = crypt->ops->get_flags(crypt->priv);
6383
6384 if (param->value)
6385 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6386 else
6387 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6388
6389 crypt->ops->set_flags(flags, crypt->priv);
6390
6391 break;
6392
6393 case IW_AUTH_DROP_UNENCRYPTED:{
6394 /* HACK:
6395 *
6396 * wpa_supplicant calls set_wpa_enabled when the driver
6397 * is loaded and unloaded, regardless of if WPA is being
6398 * used. No other calls are made which can be used to
6399 * determine if encryption will be used or not prior to
6400 * association being expected. If encryption is not being
6401 * used, drop_unencrypted is set to false, else true -- we
6402 * can use this to determine if the CAP_PRIVACY_ON bit should
6403 * be set.
6404 */
6405 struct ieee80211_security sec = {
6406 .flags = SEC_ENABLED,
6407 .enabled = param->value,
6408 };
6409 priv->ieee->drop_unencrypted = param->value;
6410 /* We only change SEC_LEVEL for open mode. Others
6411 * are set by ipw_wpa_set_encryption.
6412 */
6413 if (!param->value) {
6414 sec.flags |= SEC_LEVEL;
6415 sec.level = SEC_LEVEL_0;
6416 } else {
6417 sec.flags |= SEC_LEVEL;
6418 sec.level = SEC_LEVEL_1;
6419 }
6420 if (priv->ieee->set_security)
6421 priv->ieee->set_security(priv->ieee->dev, &sec);
6422 break;
6423 }
6424
6425 case IW_AUTH_80211_AUTH_ALG:
6426 ret = ipw_wpa_set_auth_algs(priv, param->value);
6427 break;
6428
6429 case IW_AUTH_WPA_ENABLED:
6430 ret = ipw_wpa_enable(priv, param->value);
6431 break;
6432
6433 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6434 ieee->ieee802_1x = param->value;
6435 break;
6436
6437 //case IW_AUTH_ROAMING_CONTROL:
6438 case IW_AUTH_PRIVACY_INVOKED:
6439 ieee->privacy_invoked = param->value;
6440 break;
6441
6442 default:
6443 return -EOPNOTSUPP;
6444 }
6445 return ret;
6446}
6447
6448/* SIOCGIWAUTH */
6449static int ipw_wx_get_auth(struct net_device *dev,
6450 struct iw_request_info *info,
6451 union iwreq_data *wrqu, char *extra)
6452{
6453 struct ipw_priv *priv = ieee80211_priv(dev);
6454 struct ieee80211_device *ieee = priv->ieee;
6455 struct ieee80211_crypt_data *crypt;
6456 struct iw_param *param = &wrqu->param;
6457 int ret = 0;
6458
6459 switch (param->flags & IW_AUTH_INDEX) {
6460 case IW_AUTH_WPA_VERSION:
6461 case IW_AUTH_CIPHER_PAIRWISE:
6462 case IW_AUTH_CIPHER_GROUP:
6463 case IW_AUTH_KEY_MGMT:
6464 /*
6465 * wpa_supplicant will control these internally
6466 */
6467 ret = -EOPNOTSUPP;
6468 break;
6469
6470 case IW_AUTH_TKIP_COUNTERMEASURES:
6471 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006472 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006473 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006474
6475 param->value = (crypt->ops->get_flags(crypt->priv) &
6476 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6477
6478 break;
6479
6480 case IW_AUTH_DROP_UNENCRYPTED:
6481 param->value = ieee->drop_unencrypted;
6482 break;
6483
6484 case IW_AUTH_80211_AUTH_ALG:
6485 param->value = ieee->sec.auth_mode;
6486 break;
6487
6488 case IW_AUTH_WPA_ENABLED:
6489 param->value = ieee->wpa_enabled;
6490 break;
6491
6492 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6493 param->value = ieee->ieee802_1x;
6494 break;
6495
6496 case IW_AUTH_ROAMING_CONTROL:
6497 case IW_AUTH_PRIVACY_INVOKED:
6498 param->value = ieee->privacy_invoked;
6499 break;
6500
6501 default:
6502 return -EOPNOTSUPP;
6503 }
6504 return 0;
6505}
6506
6507/* SIOCSIWENCODEEXT */
6508static int ipw_wx_set_encodeext(struct net_device *dev,
6509 struct iw_request_info *info,
6510 union iwreq_data *wrqu, char *extra)
6511{
6512 struct ipw_priv *priv = ieee80211_priv(dev);
6513 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6514
6515 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006516 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006517 /* IPW HW can't build TKIP MIC,
6518 host decryption still needed */
6519 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6520 priv->ieee->host_mc_decrypt = 1;
6521 else {
6522 priv->ieee->host_encrypt = 0;
6523 priv->ieee->host_encrypt_msdu = 1;
6524 priv->ieee->host_decrypt = 1;
6525 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006526 } else {
6527 priv->ieee->host_encrypt = 0;
6528 priv->ieee->host_encrypt_msdu = 0;
6529 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006530 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006531 }
6532 }
6533
6534 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6535}
6536
6537/* SIOCGIWENCODEEXT */
6538static int ipw_wx_get_encodeext(struct net_device *dev,
6539 struct iw_request_info *info,
6540 union iwreq_data *wrqu, char *extra)
6541{
6542 struct ipw_priv *priv = ieee80211_priv(dev);
6543 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6544}
6545
6546/* SIOCSIWMLME */
6547static int ipw_wx_set_mlme(struct net_device *dev,
6548 struct iw_request_info *info,
6549 union iwreq_data *wrqu, char *extra)
6550{
6551 struct ipw_priv *priv = ieee80211_priv(dev);
6552 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6553 u16 reason;
6554
6555 reason = cpu_to_le16(mlme->reason_code);
6556
6557 switch (mlme->cmd) {
6558 case IW_MLME_DEAUTH:
6559 // silently ignore
6560 break;
6561
6562 case IW_MLME_DISASSOC:
6563 ipw_disassociate(priv);
6564 break;
6565
6566 default:
6567 return -EOPNOTSUPP;
6568 }
6569 return 0;
6570}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006571
James Ketrenosb095c382005-08-24 22:04:42 -05006572#ifdef CONFIG_IPW_QOS
6573
6574/* QoS */
6575/*
6576* get the modulation type of the current network or
6577* the card current mode
6578*/
6579u8 ipw_qos_current_mode(struct ipw_priv * priv)
6580{
6581 u8 mode = 0;
6582
6583 if (priv->status & STATUS_ASSOCIATED) {
6584 unsigned long flags;
6585
6586 spin_lock_irqsave(&priv->ieee->lock, flags);
6587 mode = priv->assoc_network->mode;
6588 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6589 } else {
6590 mode = priv->ieee->mode;
6591 }
6592 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6593 return mode;
6594}
6595
6596/*
6597* Handle management frame beacon and probe response
6598*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006599static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6600 int active_network,
6601 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006602{
6603 u32 size = sizeof(struct ieee80211_qos_parameters);
6604
James Ketrenosafbf30a2005-08-25 00:05:33 -05006605 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006606 network->qos_data.active = network->qos_data.supported;
6607
6608 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006609 if (active_network &&
6610 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006611 network->qos_data.active = network->qos_data.supported;
6612
6613 if ((network->qos_data.active == 1) && (active_network == 1) &&
6614 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6615 (network->qos_data.old_param_count !=
6616 network->qos_data.param_count)) {
6617 network->qos_data.old_param_count =
6618 network->qos_data.param_count;
6619 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006620 IPW_DEBUG_QOS("QoS parameters change call "
6621 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006622 }
6623 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006624 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6625 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006626 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006627 else
6628 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006629 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006630
James Ketrenosb095c382005-08-24 22:04:42 -05006631 if ((network->qos_data.active == 1) && (active_network == 1)) {
6632 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6633 schedule_work(&priv->qos_activate);
6634 }
6635
6636 network->qos_data.active = 0;
6637 network->qos_data.supported = 0;
6638 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006639 if ((priv->status & STATUS_ASSOCIATED) &&
6640 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6641 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6642 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6643 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006644 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006645 priv->assoc_network->ssid_len) &&
6646 !memcmp(network->ssid,
6647 priv->assoc_network->ssid,
6648 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006649 queue_work(priv->workqueue,
6650 &priv->merge_networks);
6651 }
James Ketrenosb095c382005-08-24 22:04:42 -05006652 }
6653
6654 return 0;
6655}
6656
6657/*
6658* This function set up the firmware to support QoS. It sends
6659* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6660*/
6661static int ipw_qos_activate(struct ipw_priv *priv,
6662 struct ieee80211_qos_data *qos_network_data)
6663{
6664 int err;
6665 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6666 struct ieee80211_qos_parameters *active_one = NULL;
6667 u32 size = sizeof(struct ieee80211_qos_parameters);
6668 u32 burst_duration;
6669 int i;
6670 u8 type;
6671
6672 type = ipw_qos_current_mode(priv);
6673
6674 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6675 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6676 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6677 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6678
6679 if (qos_network_data == NULL) {
6680 if (type == IEEE_B) {
6681 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6682 active_one = &def_parameters_CCK;
6683 } else
6684 active_one = &def_parameters_OFDM;
6685
James Ketrenosafbf30a2005-08-25 00:05:33 -05006686 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006687 burst_duration = ipw_qos_get_burst_duration(priv);
6688 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006689 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6690 (u16) burst_duration;
6691 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006692 if (type == IEEE_B) {
6693 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6694 type);
6695 if (priv->qos_data.qos_enable == 0)
6696 active_one = &def_parameters_CCK;
6697 else
6698 active_one = priv->qos_data.def_qos_parm_CCK;
6699 } else {
6700 if (priv->qos_data.qos_enable == 0)
6701 active_one = &def_parameters_OFDM;
6702 else
6703 active_one = priv->qos_data.def_qos_parm_OFDM;
6704 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006705 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006706 } else {
6707 unsigned long flags;
6708 int active;
6709
6710 spin_lock_irqsave(&priv->ieee->lock, flags);
6711 active_one = &(qos_network_data->parameters);
6712 qos_network_data->old_param_count =
6713 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006714 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006715 active = qos_network_data->supported;
6716 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6717
6718 if (active == 0) {
6719 burst_duration = ipw_qos_get_burst_duration(priv);
6720 for (i = 0; i < QOS_QUEUE_NUM; i++)
6721 qos_parameters[QOS_PARAM_SET_ACTIVE].
6722 tx_op_limit[i] = (u16) burst_duration;
6723 }
6724 }
6725
6726 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006727 err = ipw_send_qos_params_command(priv,
6728 (struct ieee80211_qos_parameters *)
6729 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006730 if (err)
6731 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6732
6733 return err;
6734}
6735
6736/*
6737* send IPW_CMD_WME_INFO to the firmware
6738*/
6739static int ipw_qos_set_info_element(struct ipw_priv *priv)
6740{
6741 int ret = 0;
6742 struct ieee80211_qos_information_element qos_info;
6743
6744 if (priv == NULL)
6745 return -1;
6746
6747 qos_info.elementID = QOS_ELEMENT_ID;
6748 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6749
6750 qos_info.version = QOS_VERSION_1;
6751 qos_info.ac_info = 0;
6752
6753 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6754 qos_info.qui_type = QOS_OUI_TYPE;
6755 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6756
6757 ret = ipw_send_qos_info_command(priv, &qos_info);
6758 if (ret != 0) {
6759 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6760 }
6761 return ret;
6762}
6763
6764/*
6765* Set the QoS parameter with the association request structure
6766*/
6767static int ipw_qos_association(struct ipw_priv *priv,
6768 struct ieee80211_network *network)
6769{
6770 int err = 0;
6771 struct ieee80211_qos_data *qos_data = NULL;
6772 struct ieee80211_qos_data ibss_data = {
6773 .supported = 1,
6774 .active = 1,
6775 };
6776
6777 switch (priv->ieee->iw_mode) {
6778 case IW_MODE_ADHOC:
6779 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6780 BUG();
6781
6782 qos_data = &ibss_data;
6783 break;
6784
6785 case IW_MODE_INFRA:
6786 qos_data = &network->qos_data;
6787 break;
6788
6789 default:
6790 BUG();
6791 break;
6792 }
6793
6794 err = ipw_qos_activate(priv, qos_data);
6795 if (err) {
6796 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6797 return err;
6798 }
6799
6800 if (priv->qos_data.qos_enable && qos_data->supported) {
6801 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6802 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6803 return ipw_qos_set_info_element(priv);
6804 }
6805
6806 return 0;
6807}
6808
6809/*
6810* handling the beaconing responces. if we get different QoS setting
6811* of the network from the the associated setting adjust the QoS
6812* setting
6813*/
6814static int ipw_qos_association_resp(struct ipw_priv *priv,
6815 struct ieee80211_network *network)
6816{
6817 int ret = 0;
6818 unsigned long flags;
6819 u32 size = sizeof(struct ieee80211_qos_parameters);
6820 int set_qos_param = 0;
6821
James Ketrenosafbf30a2005-08-25 00:05:33 -05006822 if ((priv == NULL) || (network == NULL) ||
6823 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006824 return ret;
6825
6826 if (!(priv->status & STATUS_ASSOCIATED))
6827 return ret;
6828
James Ketrenosafbf30a2005-08-25 00:05:33 -05006829 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006830 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006831
6832 spin_lock_irqsave(&priv->ieee->lock, flags);
6833 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006834 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006835 sizeof(struct ieee80211_qos_data));
6836 priv->assoc_network->qos_data.active = 1;
6837 if ((network->qos_data.old_param_count !=
6838 network->qos_data.param_count)) {
6839 set_qos_param = 1;
6840 network->qos_data.old_param_count =
6841 network->qos_data.param_count;
6842 }
6843
6844 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006845 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6846 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006847 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006848 else
6849 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006850 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006851 priv->assoc_network->qos_data.active = 0;
6852 priv->assoc_network->qos_data.supported = 0;
6853 set_qos_param = 1;
6854 }
6855
6856 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6857
6858 if (set_qos_param == 1)
6859 schedule_work(&priv->qos_activate);
6860
6861 return ret;
6862}
6863
6864static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6865{
6866 u32 ret = 0;
6867
6868 if ((priv == NULL))
6869 return 0;
6870
James Ketrenosafbf30a2005-08-25 00:05:33 -05006871 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006872 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006873 else
James Ketrenosb095c382005-08-24 22:04:42 -05006874 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006875
James Ketrenosb095c382005-08-24 22:04:42 -05006876 return ret;
6877}
6878
6879/*
6880* Initialize the setting of QoS global
6881*/
6882static void ipw_qos_init(struct ipw_priv *priv, int enable,
6883 int burst_enable, u32 burst_duration_CCK,
6884 u32 burst_duration_OFDM)
6885{
6886 priv->qos_data.qos_enable = enable;
6887
6888 if (priv->qos_data.qos_enable) {
6889 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6890 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6891 IPW_DEBUG_QOS("QoS is enabled\n");
6892 } else {
6893 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6894 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6895 IPW_DEBUG_QOS("QoS is not enabled\n");
6896 }
6897
6898 priv->qos_data.burst_enable = burst_enable;
6899
6900 if (burst_enable) {
6901 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6902 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6903 } else {
6904 priv->qos_data.burst_duration_CCK = 0;
6905 priv->qos_data.burst_duration_OFDM = 0;
6906 }
6907}
6908
6909/*
6910* map the packet priority to the right TX Queue
6911*/
6912static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6913{
6914 if (priority > 7 || !priv->qos_data.qos_enable)
6915 priority = 0;
6916
6917 return from_priority_to_tx_queue[priority] - 1;
6918}
6919
6920/*
6921* add QoS parameter to the TX command
6922*/
6923static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6924 u16 priority,
6925 struct tfd_data *tfd, u8 unicast)
6926{
6927 int ret = 0;
6928 int tx_queue_id = 0;
6929 struct ieee80211_qos_data *qos_data = NULL;
6930 int active, supported;
6931 unsigned long flags;
6932
6933 if (!(priv->status & STATUS_ASSOCIATED))
6934 return 0;
6935
6936 qos_data = &priv->assoc_network->qos_data;
6937
6938 spin_lock_irqsave(&priv->ieee->lock, flags);
6939
6940 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6941 if (unicast == 0)
6942 qos_data->active = 0;
6943 else
6944 qos_data->active = qos_data->supported;
6945 }
6946
6947 active = qos_data->active;
6948 supported = qos_data->supported;
6949
6950 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6951
James Ketrenosafbf30a2005-08-25 00:05:33 -05006952 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6953 "unicast %d\n",
6954 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05006955 if (active && priv->qos_data.qos_enable) {
6956 ret = from_priority_to_tx_queue[priority];
6957 tx_queue_id = ret - 1;
6958 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6959 if (priority <= 7) {
6960 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6961 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6962 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6963 IEEE80211_STYPE_QOS_DATA;
6964
6965 if (priv->qos_data.qos_no_ack_mask &
6966 (1UL << tx_queue_id)) {
6967 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6968 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6969 CTRL_QOS_NO_ACK;
6970 }
6971 }
6972 }
6973
6974 return ret;
6975}
6976
6977/*
6978* background support to run QoS activate functionality
6979*/
6980static void ipw_bg_qos_activate(void *data)
6981{
6982 struct ipw_priv *priv = data;
6983
6984 if (priv == NULL)
6985 return;
6986
6987 down(&priv->sem);
6988
6989 if (priv->status & STATUS_ASSOCIATED)
6990 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6991
6992 up(&priv->sem);
6993}
6994
James Ketrenos3b9990c2005-08-19 13:18:55 -05006995static int ipw_handle_probe_response(struct net_device *dev,
6996 struct ieee80211_probe_response *resp,
6997 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006998{
6999 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007000 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7001 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007002
James Ketrenos3b9990c2005-08-19 13:18:55 -05007003 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007004
James Ketrenos3b9990c2005-08-19 13:18:55 -05007005 return 0;
7006}
James Ketrenosb095c382005-08-24 22:04:42 -05007007
James Ketrenos3b9990c2005-08-19 13:18:55 -05007008static int ipw_handle_beacon(struct net_device *dev,
7009 struct ieee80211_beacon *resp,
7010 struct ieee80211_network *network)
7011{
7012 struct ipw_priv *priv = ieee80211_priv(dev);
7013 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7014 (network == priv->assoc_network));
7015
7016 ipw_qos_handle_probe_response(priv, active_network, network);
7017
7018 return 0;
7019}
7020
7021static int ipw_handle_assoc_response(struct net_device *dev,
7022 struct ieee80211_assoc_response *resp,
7023 struct ieee80211_network *network)
7024{
7025 struct ipw_priv *priv = ieee80211_priv(dev);
7026 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007027 return 0;
7028}
7029
7030static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7031 *qos_param)
7032{
Zhu Yi4e226992006-01-24 16:37:36 +08007033 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7034 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007035}
7036
7037static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7038 *qos_param)
7039{
Zhu Yi4e226992006-01-24 16:37:36 +08007040 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7041 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007042}
7043
7044#endif /* CONFIG_IPW_QOS */
7045
James Ketrenos43f66a62005-03-25 12:31:53 -06007046static int ipw_associate_network(struct ipw_priv *priv,
7047 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007048 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007049{
7050 int err;
7051
7052 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007053 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007054
7055 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007056 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007057 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007058 memcpy(priv->essid, network->ssid, priv->essid_len);
7059 }
7060
7061 network->last_associate = jiffies;
7062
7063 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7064 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007065 priv->assoc_request.auth_key = 0;
7066
James Ketrenos43f66a62005-03-25 12:31:53 -06007067 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007068 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007069 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007070 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7071
Zhu Yi3e234b42006-01-24 16:36:52 +08007072 if ((priv->ieee->sec.level == SEC_LEVEL_1) &&
James Ketrenosb095c382005-08-24 22:04:42 -05007073 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7074 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007075
7076 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7077 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7078 priv->assoc_request.auth_type = AUTH_LEAP;
7079 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007080 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007081
James Ketrenosa613bff2005-08-24 21:43:11 -05007082 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007083 priv->assoc_request.policy_support = 0x02; /* RSN active */
7084 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7085 priv->ieee->wpa_ie_len);
7086 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007087
Jeff Garzikbf794512005-07-31 13:07:26 -04007088 /*
7089 * It is valid for our ieee device to support multiple modes, but
7090 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007091 * just one mode.
7092 */
7093 if (network->mode & priv->ieee->mode & IEEE_A)
7094 priv->assoc_request.ieee_mode = IPW_A_MODE;
7095 else if (network->mode & priv->ieee->mode & IEEE_G)
7096 priv->assoc_request.ieee_mode = IPW_G_MODE;
7097 else if (network->mode & priv->ieee->mode & IEEE_B)
7098 priv->assoc_request.ieee_mode = IPW_B_MODE;
7099
James Ketrenosea2b26e2005-08-24 21:25:16 -05007100 priv->assoc_request.capability = network->capability;
7101 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7102 && !(priv->config & CFG_PREAMBLE_LONG)) {
7103 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7104 } else {
7105 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7106
7107 /* Clear the short preamble if we won't be supporting it */
7108 priv->assoc_request.capability &=
7109 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7110 }
7111
James Ketrenosafbf30a2005-08-25 00:05:33 -05007112 /* Clear capability bits that aren't used in Ad Hoc */
7113 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7114 priv->assoc_request.capability &=
7115 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7116
James Ketrenos43f66a62005-03-25 12:31:53 -06007117 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007118 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007119 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007120 escape_essid(priv->essid, priv->essid_len),
7121 network->channel,
7122 ipw_modes[priv->assoc_request.ieee_mode],
7123 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007124 (priv->assoc_request.preamble_length ==
7125 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7126 network->capability &
7127 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007128 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007129 priv->capability & CAP_PRIVACY_ON ?
7130 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007131 "(open)") : "",
7132 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007133 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007134 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007135 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007136
7137 priv->assoc_request.beacon_interval = network->beacon_interval;
7138 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007139 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007140 priv->assoc_request.assoc_type = HC_IBSS_START;
7141 priv->assoc_request.assoc_tsf_msw = 0;
7142 priv->assoc_request.assoc_tsf_lsw = 0;
7143 } else {
7144 if (unlikely(roaming))
7145 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7146 else
7147 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7148 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7149 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7150 }
7151
James Ketrenosafbf30a2005-08-25 00:05:33 -05007152 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007153
7154 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7155 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7156 priv->assoc_request.atim_window = network->atim_window;
7157 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007158 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007159 priv->assoc_request.atim_window = 0;
7160 }
7161
James Ketrenos43f66a62005-03-25 12:31:53 -06007162 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007163
James Ketrenos43f66a62005-03-25 12:31:53 -06007164 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7165 if (err) {
7166 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7167 return err;
7168 }
7169
7170 rates->ieee_mode = priv->assoc_request.ieee_mode;
7171 rates->purpose = IPW_RATE_CONNECT;
7172 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007173
James Ketrenos43f66a62005-03-25 12:31:53 -06007174 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7175 priv->sys_config.dot11g_auto_detection = 1;
7176 else
7177 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007178
7179 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7180 priv->sys_config.answer_broadcast_ssid_probe = 1;
7181 else
7182 priv->sys_config.answer_broadcast_ssid_probe = 0;
7183
James Ketrenos43f66a62005-03-25 12:31:53 -06007184 err = ipw_send_system_config(priv, &priv->sys_config);
7185 if (err) {
7186 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7187 return err;
7188 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007189
James Ketrenos43f66a62005-03-25 12:31:53 -06007190 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007191 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007192 if (err) {
7193 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7194 return err;
7195 }
7196
7197 /*
7198 * If preemption is enabled, it is possible for the association
7199 * to complete before we return from ipw_send_associate. Therefore
7200 * we have to be sure and update our priviate data first.
7201 */
7202 priv->channel = network->channel;
7203 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007204 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007205 priv->status &= ~STATUS_SECURITY_UPDATED;
7206
7207 priv->assoc_network = network;
7208
James Ketrenosb095c382005-08-24 22:04:42 -05007209#ifdef CONFIG_IPW_QOS
7210 ipw_qos_association(priv, network);
7211#endif
7212
James Ketrenos43f66a62005-03-25 12:31:53 -06007213 err = ipw_send_associate(priv, &priv->assoc_request);
7214 if (err) {
7215 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7216 return err;
7217 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007218
7219 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007220 escape_essid(priv->essid, priv->essid_len),
7221 MAC_ARG(priv->bssid));
7222
7223 return 0;
7224}
7225
7226static void ipw_roam(void *data)
7227{
7228 struct ipw_priv *priv = data;
7229 struct ieee80211_network *network = NULL;
7230 struct ipw_network_match match = {
7231 .network = priv->assoc_network
7232 };
7233
7234 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007235 *
7236 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007237 * setting the status ROAM bit and requesting a scan.
7238 * 2. When the scan completes, it schedules the ROAM work
7239 * 3. The ROAM work looks at all of the known networks for one that
7240 * is a better network than the currently associated. If none
7241 * found, the ROAM process is over (ROAM bit cleared)
7242 * 4. If a better network is found, a disassociation request is
7243 * sent.
7244 * 5. When the disassociation completes, the roam work is again
7245 * scheduled. The second time through, the driver is no longer
7246 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007247 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007248 * 6. At this point ,the roaming process is complete and the ROAM
7249 * status bit is cleared.
7250 */
7251
7252 /* If we are no longer associated, and the roaming bit is no longer
7253 * set, then we are not actively roaming, so just return */
7254 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7255 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007256
James Ketrenos43f66a62005-03-25 12:31:53 -06007257 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007258 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007259 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007260 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007261 u8 rssi = priv->assoc_network->stats.rssi;
7262 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007263 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007264 list_for_each_entry(network, &priv->ieee->network_list, list) {
7265 if (network != priv->assoc_network)
7266 ipw_best_network(priv, &match, network, 1);
7267 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007268 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007269 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007270
James Ketrenos43f66a62005-03-25 12:31:53 -06007271 if (match.network == priv->assoc_network) {
7272 IPW_DEBUG_ASSOC("No better APs in this network to "
7273 "roam to.\n");
7274 priv->status &= ~STATUS_ROAMING;
7275 ipw_debug_config(priv);
7276 return;
7277 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007278
James Ketrenos43f66a62005-03-25 12:31:53 -06007279 ipw_send_disassociate(priv, 1);
7280 priv->assoc_network = match.network;
7281
7282 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007283 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007284
7285 /* Second pass through ROAM process -- request association */
7286 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7287 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7288 priv->status &= ~STATUS_ROAMING;
7289}
7290
James Ketrenosc848d0a2005-08-24 21:56:24 -05007291static void ipw_bg_roam(void *data)
7292{
7293 struct ipw_priv *priv = data;
7294 down(&priv->sem);
7295 ipw_roam(data);
7296 up(&priv->sem);
7297}
7298
7299static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007300{
7301 struct ipw_priv *priv = data;
7302
7303 struct ieee80211_network *network = NULL;
7304 struct ipw_network_match match = {
7305 .network = NULL
7306 };
7307 struct ipw_supported_rates *rates;
7308 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007309 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007310
James Ketrenosb095c382005-08-24 22:04:42 -05007311 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7312 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7313 return 0;
7314 }
7315
James Ketrenosc848d0a2005-08-24 21:56:24 -05007316 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007317 IPW_DEBUG_ASSOC("Not attempting association (already in "
7318 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007319 return 0;
7320 }
7321
Hong Liue6324722005-09-14 21:04:15 -05007322 if (priv->status & STATUS_DISASSOCIATING) {
7323 IPW_DEBUG_ASSOC("Not attempting association (in "
7324 "disassociating)\n ");
7325 queue_work(priv->workqueue, &priv->associate);
7326 return 0;
7327 }
7328
James Ketrenosc848d0a2005-08-24 21:56:24 -05007329 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007330 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7331 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007332 return 0;
7333 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007334
7335 if (!(priv->config & CFG_ASSOCIATE) &&
7336 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007337 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007338 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007339 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007340 }
7341
James Ketrenosa613bff2005-08-24 21:43:11 -05007342 /* Protect our use of the network_list */
7343 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007344 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007345 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007346
7347 network = match.network;
7348 rates = &match.rates;
7349
7350 if (network == NULL &&
7351 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7352 priv->config & CFG_ADHOC_CREATE &&
7353 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007354 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007355 !list_empty(&priv->ieee->network_free_list)) {
7356 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007357 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007358 ipw_adhoc_create(priv, network);
7359 rates = &priv->rates;
7360 list_del(element);
7361 list_add_tail(&network->list, &priv->ieee->network_list);
7362 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007363 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007364
James Ketrenos43f66a62005-03-25 12:31:53 -06007365 /* If we reached the end of the list, then we don't have any valid
7366 * matching APs */
7367 if (!network) {
7368 ipw_debug_config(priv);
7369
James Ketrenosb095c382005-08-24 22:04:42 -05007370 if (!(priv->status & STATUS_SCANNING)) {
7371 if (!(priv->config & CFG_SPEED_SCAN))
7372 queue_delayed_work(priv->workqueue,
7373 &priv->request_scan,
7374 SCAN_INTERVAL);
7375 else
7376 queue_work(priv->workqueue,
7377 &priv->request_scan);
7378 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007379
James Ketrenosc848d0a2005-08-24 21:56:24 -05007380 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007381 }
7382
7383 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007384
7385 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007386}
Jeff Garzikbf794512005-07-31 13:07:26 -04007387
James Ketrenosc848d0a2005-08-24 21:56:24 -05007388static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007389{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007390 struct ipw_priv *priv = data;
7391 down(&priv->sem);
7392 ipw_associate(data);
7393 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007394}
7395
James Ketrenosb095c382005-08-24 22:04:42 -05007396static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7397 struct sk_buff *skb)
7398{
7399 struct ieee80211_hdr *hdr;
7400 u16 fc;
7401
7402 hdr = (struct ieee80211_hdr *)skb->data;
7403 fc = le16_to_cpu(hdr->frame_ctl);
7404 if (!(fc & IEEE80211_FCTL_PROTECTED))
7405 return;
7406
7407 fc &= ~IEEE80211_FCTL_PROTECTED;
7408 hdr->frame_ctl = cpu_to_le16(fc);
7409 switch (priv->ieee->sec.level) {
7410 case SEC_LEVEL_3:
7411 /* Remove CCMP HDR */
7412 memmove(skb->data + IEEE80211_3ADDR_LEN,
7413 skb->data + IEEE80211_3ADDR_LEN + 8,
7414 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007415 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007416 break;
7417 case SEC_LEVEL_2:
7418 break;
7419 case SEC_LEVEL_1:
7420 /* Remove IV */
7421 memmove(skb->data + IEEE80211_3ADDR_LEN,
7422 skb->data + IEEE80211_3ADDR_LEN + 4,
7423 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007424 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007425 break;
7426 case SEC_LEVEL_0:
7427 break;
7428 default:
7429 printk(KERN_ERR "Unknow security level %d\n",
7430 priv->ieee->sec.level);
7431 break;
7432 }
7433}
7434
7435static void ipw_handle_data_packet(struct ipw_priv *priv,
7436 struct ipw_rx_mem_buffer *rxb,
7437 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007438{
Hong Liu567deaf2005-08-31 18:07:22 +08007439 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007440 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7441
7442 /* We received data from the HW, so stop the watchdog */
7443 priv->net_dev->trans_start = jiffies;
7444
Jeff Garzikbf794512005-07-31 13:07:26 -04007445 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007446 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007447 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007448 skb_tailroom(rxb->skb))) {
7449 priv->ieee->stats.rx_errors++;
7450 priv->wstats.discard.misc++;
7451 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7452 return;
7453 } else if (unlikely(!netif_running(priv->net_dev))) {
7454 priv->ieee->stats.rx_dropped++;
7455 priv->wstats.discard.misc++;
7456 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7457 return;
7458 }
7459
7460 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007461 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007462
7463 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007464 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007465
7466 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7467
James Ketrenosb095c382005-08-24 22:04:42 -05007468 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007469 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7470 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007471 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007472 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007473 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7474
Jeff Garzikbf794512005-07-31 13:07:26 -04007475 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007476 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007477 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007478 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007479 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007480 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007481}
7482
Mike Kershaw24a47db2005-08-26 00:41:54 -05007483#ifdef CONFIG_IEEE80211_RADIOTAP
7484static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7485 struct ipw_rx_mem_buffer *rxb,
7486 struct ieee80211_rx_stats *stats)
7487{
7488 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7489 struct ipw_rx_frame *frame = &pkt->u.frame;
7490
7491 /* initial pull of some data */
7492 u16 received_channel = frame->received_channel;
7493 u8 antennaAndPhy = frame->antennaAndPhy;
7494 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7495 u16 pktrate = frame->rate;
7496
7497 /* Magic struct that slots into the radiotap header -- no reason
7498 * to build this manually element by element, we can write it much
7499 * more efficiently than we can parse it. ORDER MATTERS HERE */
7500 struct ipw_rt_hdr {
7501 struct ieee80211_radiotap_header rt_hdr;
7502 u8 rt_flags; /* radiotap packet flags */
7503 u8 rt_rate; /* rate in 500kb/s */
7504 u16 rt_channel; /* channel in mhz */
7505 u16 rt_chbitmask; /* channel bitfield */
7506 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7507 u8 rt_antenna; /* antenna number */
7508 } *ipw_rt;
7509
7510 short len = le16_to_cpu(pkt->u.frame.length);
7511
7512 /* We received data from the HW, so stop the watchdog */
7513 priv->net_dev->trans_start = jiffies;
7514
7515 /* We only process data packets if the
7516 * interface is open */
7517 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7518 skb_tailroom(rxb->skb))) {
7519 priv->ieee->stats.rx_errors++;
7520 priv->wstats.discard.misc++;
7521 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7522 return;
7523 } else if (unlikely(!netif_running(priv->net_dev))) {
7524 priv->ieee->stats.rx_dropped++;
7525 priv->wstats.discard.misc++;
7526 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7527 return;
7528 }
7529
7530 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7531 * that now */
7532 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7533 /* FIXME: Should alloc bigger skb instead */
7534 priv->ieee->stats.rx_dropped++;
7535 priv->wstats.discard.misc++;
7536 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7537 return;
7538 }
7539
7540 /* copy the frame itself */
7541 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7542 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7543
7544 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7545 * part of our real header, saves a little time.
7546 *
7547 * No longer necessary since we fill in all our data. Purge before merging
7548 * patch officially.
7549 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7550 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7551 */
7552
7553 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7554
7555 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7556 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7557 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7558
7559 /* Big bitfield of all the fields we provide in radiotap */
7560 ipw_rt->rt_hdr.it_present =
7561 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7562 (1 << IEEE80211_RADIOTAP_RATE) |
7563 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7564 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7565 (1 << IEEE80211_RADIOTAP_ANTENNA));
7566
7567 /* Zero the flags, we'll add to them as we go */
7568 ipw_rt->rt_flags = 0;
7569
7570 /* Convert signal to DBM */
7571 ipw_rt->rt_dbmsignal = antsignal;
7572
7573 /* Convert the channel data and set the flags */
7574 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7575 if (received_channel > 14) { /* 802.11a */
7576 ipw_rt->rt_chbitmask =
7577 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7578 } else if (antennaAndPhy & 32) { /* 802.11b */
7579 ipw_rt->rt_chbitmask =
7580 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7581 } else { /* 802.11g */
7582 ipw_rt->rt_chbitmask =
7583 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7584 }
7585
7586 /* set the rate in multiples of 500k/s */
7587 switch (pktrate) {
7588 case IPW_TX_RATE_1MB:
7589 ipw_rt->rt_rate = 2;
7590 break;
7591 case IPW_TX_RATE_2MB:
7592 ipw_rt->rt_rate = 4;
7593 break;
7594 case IPW_TX_RATE_5MB:
7595 ipw_rt->rt_rate = 10;
7596 break;
7597 case IPW_TX_RATE_6MB:
7598 ipw_rt->rt_rate = 12;
7599 break;
7600 case IPW_TX_RATE_9MB:
7601 ipw_rt->rt_rate = 18;
7602 break;
7603 case IPW_TX_RATE_11MB:
7604 ipw_rt->rt_rate = 22;
7605 break;
7606 case IPW_TX_RATE_12MB:
7607 ipw_rt->rt_rate = 24;
7608 break;
7609 case IPW_TX_RATE_18MB:
7610 ipw_rt->rt_rate = 36;
7611 break;
7612 case IPW_TX_RATE_24MB:
7613 ipw_rt->rt_rate = 48;
7614 break;
7615 case IPW_TX_RATE_36MB:
7616 ipw_rt->rt_rate = 72;
7617 break;
7618 case IPW_TX_RATE_48MB:
7619 ipw_rt->rt_rate = 96;
7620 break;
7621 case IPW_TX_RATE_54MB:
7622 ipw_rt->rt_rate = 108;
7623 break;
7624 default:
7625 ipw_rt->rt_rate = 0;
7626 break;
7627 }
7628
7629 /* antenna number */
7630 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7631
7632 /* set the preamble flag if we have it */
7633 if ((antennaAndPhy & 64))
7634 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7635
7636 /* Set the size of the skb to the size of the frame */
7637 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007638
7639 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7640
7641 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7642 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007643 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007644 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007645 /* no LED during capture */
7646 }
7647}
7648#endif
7649
Arjan van de Ven858119e2006-01-14 13:20:43 -08007650static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007651 struct ieee80211_hdr_4addr *header)
7652{
7653 /* Filter incoming packets to determine if they are targetted toward
7654 * this network, discarding packets coming from ourselves */
7655 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007656 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007657 /* packets from our adapter are dropped (echo) */
7658 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7659 return 0;
7660
Peter Jones90700fd2005-08-26 16:51:06 -05007661 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007662 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007663 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007664
7665 /* packets to our adapter go through */
7666 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7667 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007668
Peter Jones90700fd2005-08-26 16:51:06 -05007669 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007670 /* packets from our adapter are dropped (echo) */
7671 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7672 return 0;
7673
Peter Jones90700fd2005-08-26 16:51:06 -05007674 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007675 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007676 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7677
7678 /* packets to our adapter go through */
7679 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7680 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007681 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007682
James Ketrenosea2b26e2005-08-24 21:25:16 -05007683 return 1;
7684}
7685
James Ketrenosafbf30a2005-08-25 00:05:33 -05007686#define IPW_PACKET_RETRY_TIME HZ
7687
Arjan van de Ven858119e2006-01-14 13:20:43 -08007688static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007689 struct ieee80211_hdr_4addr *header)
7690{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007691 u16 sc = le16_to_cpu(header->seq_ctl);
7692 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7693 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7694 u16 *last_seq, *last_frag;
7695 unsigned long *last_time;
7696
7697 switch (priv->ieee->iw_mode) {
7698 case IW_MODE_ADHOC:
7699 {
7700 struct list_head *p;
7701 struct ipw_ibss_seq *entry = NULL;
7702 u8 *mac = header->addr2;
7703 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7704
7705 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7706 entry =
7707 list_entry(p, struct ipw_ibss_seq, list);
7708 if (!memcmp(entry->mac, mac, ETH_ALEN))
7709 break;
7710 }
7711 if (p == &priv->ibss_mac_hash[index]) {
7712 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7713 if (!entry) {
7714 IPW_ERROR
7715 ("Cannot malloc new mac entry\n");
7716 return 0;
7717 }
7718 memcpy(entry->mac, mac, ETH_ALEN);
7719 entry->seq_num = seq;
7720 entry->frag_num = frag;
7721 entry->packet_time = jiffies;
7722 list_add(&entry->list,
7723 &priv->ibss_mac_hash[index]);
7724 return 0;
7725 }
7726 last_seq = &entry->seq_num;
7727 last_frag = &entry->frag_num;
7728 last_time = &entry->packet_time;
7729 break;
7730 }
7731 case IW_MODE_INFRA:
7732 last_seq = &priv->last_seq_num;
7733 last_frag = &priv->last_frag_num;
7734 last_time = &priv->last_packet_time;
7735 break;
7736 default:
7737 return 0;
7738 }
7739 if ((*last_seq == seq) &&
7740 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7741 if (*last_frag == frag)
7742 goto drop;
7743 if (*last_frag + 1 != frag)
7744 /* out-of-order fragment */
7745 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007746 } else
7747 *last_seq = seq;
7748
Zhu Yif57ce7c2005-07-13 12:22:15 -05007749 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007750 *last_time = jiffies;
7751 return 0;
7752
7753 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007754 /* Comment this line now since we observed the card receives
7755 * duplicate packets but the FCTL_RETRY bit is not set in the
7756 * IBSS mode with fragmentation enabled.
7757 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007758 return 1;
7759}
7760
James Ketrenosb095c382005-08-24 22:04:42 -05007761static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7762 struct ipw_rx_mem_buffer *rxb,
7763 struct ieee80211_rx_stats *stats)
7764{
7765 struct sk_buff *skb = rxb->skb;
7766 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7767 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7768 (skb->data + IPW_RX_FRAME_SIZE);
7769
7770 ieee80211_rx_mgt(priv->ieee, header, stats);
7771
7772 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7773 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7774 IEEE80211_STYPE_PROBE_RESP) ||
7775 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7776 IEEE80211_STYPE_BEACON))) {
7777 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7778 ipw_add_station(priv, header->addr2);
7779 }
7780
7781 if (priv->config & CFG_NET_STATS) {
7782 IPW_DEBUG_HC("sending stat packet\n");
7783
7784 /* Set the size of the skb to the size of the full
7785 * ipw header and 802.11 frame */
7786 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7787 IPW_RX_FRAME_SIZE);
7788
7789 /* Advance past the ipw packet header to the 802.11 frame */
7790 skb_pull(skb, IPW_RX_FRAME_SIZE);
7791
7792 /* Push the ieee80211_rx_stats before the 802.11 frame */
7793 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7794
7795 skb->dev = priv->ieee->dev;
7796
7797 /* Point raw at the ieee80211_stats */
7798 skb->mac.raw = skb->data;
7799
7800 skb->pkt_type = PACKET_OTHERHOST;
7801 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7802 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7803 netif_rx(skb);
7804 rxb->skb = NULL;
7805 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007806}
7807
James Ketrenos43f66a62005-03-25 12:31:53 -06007808/*
7809 * Main entry function for recieving a packet with 80211 headers. This
7810 * should be called when ever the FW has notified us that there is a new
7811 * skb in the recieve queue.
7812 */
7813static void ipw_rx(struct ipw_priv *priv)
7814{
7815 struct ipw_rx_mem_buffer *rxb;
7816 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007817 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007818 u32 r, w, i;
7819 u8 network_packet;
7820
James Ketrenosb095c382005-08-24 22:04:42 -05007821 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7822 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007823 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7824
7825 while (i != r) {
7826 rxb = priv->rxq->queue[i];
Brice Goglin0f52bf92005-12-01 01:41:46 -08007827#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06007828 if (unlikely(rxb == NULL)) {
7829 printk(KERN_CRIT "Queue not allocated!\n");
7830 break;
7831 }
7832#endif
7833 priv->rxq->queue[i] = NULL;
7834
7835 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007836 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007837 PCI_DMA_FROMDEVICE);
7838
7839 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7840 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7841 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007842 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007843
7844 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007845 case RX_FRAME_TYPE: /* 802.11 frame */ {
7846 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007847 .rssi =
7848 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007849 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007850 .signal =
7851 le16_to_cpu(pkt->u.frame.signal),
7852 .noise =
7853 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007854 .rate = pkt->u.frame.rate,
7855 .mac_time = jiffies,
7856 .received_channel =
7857 pkt->u.frame.received_channel,
7858 .freq =
7859 (pkt->u.frame.
7860 control & (1 << 0)) ?
7861 IEEE80211_24GHZ_BAND :
7862 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007863 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007864 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007865
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007866 if (stats.rssi != 0)
7867 stats.mask |= IEEE80211_STATMASK_RSSI;
7868 if (stats.signal != 0)
7869 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007870 if (stats.noise != 0)
7871 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007872 if (stats.rate != 0)
7873 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007874
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007875 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007876
James Ketrenosb095c382005-08-24 22:04:42 -05007877#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007878 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007879#ifdef CONFIG_IEEE80211_RADIOTAP
7880 ipw_handle_data_packet_monitor(priv,
7881 rxb,
7882 &stats);
7883#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007884 ipw_handle_data_packet(priv, rxb,
7885 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007886#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007887 break;
7888 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007889#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007890
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007891 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007892 (struct ieee80211_hdr_4addr *)(rxb->skb->
7893 data +
7894 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007895 /* TODO: Check Ad-Hoc dest/source and make sure
7896 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007897 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007898 * frame control of the packet and disregard
7899 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007900
James Ketrenosea2b26e2005-08-24 21:25:16 -05007901 network_packet =
7902 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007903 if (network_packet && priv->assoc_network) {
7904 priv->assoc_network->stats.rssi =
7905 stats.rssi;
7906 average_add(&priv->average_rssi,
7907 stats.rssi);
7908 priv->last_rx_rssi = stats.rssi;
7909 }
7910
7911 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007912 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007913
James Ketrenosa613bff2005-08-24 21:43:11 -05007914 if (le16_to_cpu(pkt->u.frame.length) <
7915 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007916 IPW_DEBUG_DROP
7917 ("Received packet is too small. "
7918 "Dropping.\n");
7919 priv->ieee->stats.rx_errors++;
7920 priv->wstats.discard.misc++;
7921 break;
7922 }
7923
James Ketrenosa613bff2005-08-24 21:43:11 -05007924 switch (WLAN_FC_GET_TYPE
7925 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007926
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007927 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007928 ipw_handle_mgmt_packet(priv, rxb,
7929 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007930 break;
7931
7932 case IEEE80211_FTYPE_CTL:
7933 break;
7934
7935 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007936 if (unlikely(!network_packet ||
7937 is_duplicate_packet(priv,
7938 header)))
7939 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007940 IPW_DEBUG_DROP("Dropping: "
7941 MAC_FMT ", "
7942 MAC_FMT ", "
7943 MAC_FMT "\n",
7944 MAC_ARG(header->
7945 addr1),
7946 MAC_ARG(header->
7947 addr2),
7948 MAC_ARG(header->
7949 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05007950 break;
7951 }
7952
7953 ipw_handle_data_packet(priv, rxb,
7954 &stats);
7955
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007956 break;
7957 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007958 break;
7959 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007960
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007961 case RX_HOST_NOTIFICATION_TYPE:{
7962 IPW_DEBUG_RX
7963 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007964 pkt->u.notification.subtype,
7965 pkt->u.notification.flags,
7966 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007967 ipw_rx_notification(priv, &pkt->u.notification);
7968 break;
7969 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007970
7971 default:
7972 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7973 pkt->header.message_type);
7974 break;
7975 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007976
7977 /* For now we just don't re-use anything. We can tweak this
7978 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06007979 * fail to Rx correctly */
7980 if (rxb->skb != NULL) {
7981 dev_kfree_skb_any(rxb->skb);
7982 rxb->skb = NULL;
7983 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007984
James Ketrenos43f66a62005-03-25 12:31:53 -06007985 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007986 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007987 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04007988
James Ketrenos43f66a62005-03-25 12:31:53 -06007989 i = (i + 1) % RX_QUEUE_SIZE;
7990 }
7991
7992 /* Backtrack one entry */
7993 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7994
7995 ipw_rx_queue_restock(priv);
7996}
7997
James Ketrenosafbf30a2005-08-25 00:05:33 -05007998#define DEFAULT_RTS_THRESHOLD 2304U
7999#define MIN_RTS_THRESHOLD 1U
8000#define MAX_RTS_THRESHOLD 2304U
8001#define DEFAULT_BEACON_INTERVAL 100U
8002#define DEFAULT_SHORT_RETRY_LIMIT 7U
8003#define DEFAULT_LONG_RETRY_LIMIT 4U
8004
8005static int ipw_sw_reset(struct ipw_priv *priv, int init)
James Ketrenos43f66a62005-03-25 12:31:53 -06008006{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008007 int band, modulation;
8008 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008009
James Ketrenosafbf30a2005-08-25 00:05:33 -05008010 /* Initialize module parameter values here */
8011 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008012
James Ketrenosafbf30a2005-08-25 00:05:33 -05008013 /* We default to disabling the LED code as right now it causes
8014 * too many systems to lock up... */
8015 if (!led)
8016 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008017
James Ketrenosafbf30a2005-08-25 00:05:33 -05008018 if (associate)
8019 priv->config |= CFG_ASSOCIATE;
8020 else
8021 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008022
James Ketrenosafbf30a2005-08-25 00:05:33 -05008023 if (auto_create)
8024 priv->config |= CFG_ADHOC_CREATE;
8025 else
8026 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8027
Zhu Yi17ed0812006-01-24 16:36:31 +08008028 priv->config &= ~CFG_STATIC_ESSID;
8029 priv->essid_len = 0;
8030 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8031
James Ketrenosafbf30a2005-08-25 00:05:33 -05008032 if (disable) {
8033 priv->status |= STATUS_RF_KILL_SW;
8034 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008035 }
8036
James Ketrenosafbf30a2005-08-25 00:05:33 -05008037 if (channel != 0) {
8038 priv->config |= CFG_STATIC_CHANNEL;
8039 priv->channel = channel;
8040 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8041 /* TODO: Validate that provided channel is in range */
8042 }
8043#ifdef CONFIG_IPW_QOS
8044 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8045 burst_duration_CCK, burst_duration_OFDM);
8046#endif /* CONFIG_IPW_QOS */
8047
8048 switch (mode) {
8049 case 1:
8050 priv->ieee->iw_mode = IW_MODE_ADHOC;
8051 priv->net_dev->type = ARPHRD_ETHER;
8052
8053 break;
8054#ifdef CONFIG_IPW2200_MONITOR
8055 case 2:
8056 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008057#ifdef CONFIG_IEEE80211_RADIOTAP
8058 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8059#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008060 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008061#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008062 break;
8063#endif
8064 default:
8065 case 0:
8066 priv->net_dev->type = ARPHRD_ETHER;
8067 priv->ieee->iw_mode = IW_MODE_INFRA;
8068 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008069 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008070
James Ketrenosafbf30a2005-08-25 00:05:33 -05008071 if (hwcrypto) {
8072 priv->ieee->host_encrypt = 0;
8073 priv->ieee->host_encrypt_msdu = 0;
8074 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008075 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008076 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008077 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008078
Zhu Yie402c932005-08-05 17:20:40 +08008079 /* IPW2200/2915 is abled to do hardware fragmentation. */
8080 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008081
James Ketrenosafbf30a2005-08-25 00:05:33 -05008082 if ((priv->pci_dev->device == 0x4223) ||
8083 (priv->pci_dev->device == 0x4224)) {
8084 if (init)
8085 printk(KERN_INFO DRV_NAME
8086 ": Detected Intel PRO/Wireless 2915ABG Network "
8087 "Connection\n");
8088 priv->ieee->abg_true = 1;
8089 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8090 modulation = IEEE80211_OFDM_MODULATION |
8091 IEEE80211_CCK_MODULATION;
8092 priv->adapter = IPW_2915ABG;
8093 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008094 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008095 if (init)
8096 printk(KERN_INFO DRV_NAME
8097 ": Detected Intel PRO/Wireless 2200BG Network "
8098 "Connection\n");
8099
8100 priv->ieee->abg_true = 0;
8101 band = IEEE80211_24GHZ_BAND;
8102 modulation = IEEE80211_OFDM_MODULATION |
8103 IEEE80211_CCK_MODULATION;
8104 priv->adapter = IPW_2200BG;
8105 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008106 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008107
James Ketrenosafbf30a2005-08-25 00:05:33 -05008108 priv->ieee->freq_band = band;
8109 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008110
James Ketrenosafbf30a2005-08-25 00:05:33 -05008111 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008112
James Ketrenosafbf30a2005-08-25 00:05:33 -05008113 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8114 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008115
James Ketrenosafbf30a2005-08-25 00:05:33 -05008116 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8117 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8118 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008119
James Ketrenosafbf30a2005-08-25 00:05:33 -05008120 /* If power management is turned on, default to AC mode */
8121 priv->power_mode = IPW_POWER_AC;
8122 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008123
Zhu Yi0ece35b2005-08-05 17:26:51 +08008124 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008125}
8126
8127/*
8128 * This file defines the Wireless Extension handlers. It does not
8129 * define any methods of hardware manipulation and relies on the
8130 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008131 *
8132 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008133 * function used to poll the hardware vs. making unecessary calls.
8134 *
8135 */
8136
Jeff Garzikbf794512005-07-31 13:07:26 -04008137static int ipw_wx_get_name(struct net_device *dev,
8138 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008139 union iwreq_data *wrqu, char *extra)
8140{
8141 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008142 down(&priv->sem);
8143 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008144 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008145 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008146 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008147 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008148 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8149 ipw_modes[priv->assoc_request.ieee_mode]);
8150 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008151 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008152 return 0;
8153}
8154
8155static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8156{
8157 if (channel == 0) {
8158 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8159 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008160 IPW_DEBUG_ASSOC("Attempting to associate with new "
8161 "parameters.\n");
8162 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008163 return 0;
8164 }
8165
8166 priv->config |= CFG_STATIC_CHANNEL;
8167
8168 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008169 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8170 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008171 return 0;
8172 }
8173
8174 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8175 priv->channel = channel;
8176
James Ketrenosb095c382005-08-24 22:04:42 -05008177#ifdef CONFIG_IPW2200_MONITOR
8178 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008179 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008180 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008181 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008182 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008183 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008184 }
8185
8186 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8187 udelay(10);
8188
8189 if (priv->status & STATUS_SCANNING)
8190 IPW_DEBUG_SCAN("Still scanning...\n");
8191 else
8192 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8193 1000 - i);
8194
8195 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008196 }
James Ketrenosb095c382005-08-24 22:04:42 -05008197#endif /* CONFIG_IPW2200_MONITOR */
8198
James Ketrenosc848d0a2005-08-24 21:56:24 -05008199 /* Network configuration changed -- force [re]association */
8200 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8201 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008202 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008203
8204 return 0;
8205}
8206
Jeff Garzikbf794512005-07-31 13:07:26 -04008207static int ipw_wx_set_freq(struct net_device *dev,
8208 struct iw_request_info *info,
8209 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008210{
8211 struct ipw_priv *priv = ieee80211_priv(dev);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008212 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008213 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008214 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008215 u8 channel, flags;
8216 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008217
James Ketrenosb095c382005-08-24 22:04:42 -05008218 if (fwrq->m == 0) {
8219 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8220 down(&priv->sem);
8221 ret = ipw_set_channel(priv, 0);
8222 up(&priv->sem);
8223 return ret;
8224 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008225 /* if setting by freq convert to channel */
8226 if (fwrq->e == 1) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05008227 channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008228 if (channel == 0)
8229 return -EINVAL;
8230 } else
8231 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008232
Liu Hong1fe0adb2005-08-19 09:33:10 -05008233 if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008234 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008235
Liu Hong1fe0adb2005-08-19 09:33:10 -05008236 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8237 i = ipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008238 if (i == -1)
8239 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008240
8241 flags = (band == IEEE80211_24GHZ_BAND) ?
8242 geo->bg[i].flags : geo->a[i].flags;
8243 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008244 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8245 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008246 }
8247 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008248
James Ketrenos43f66a62005-03-25 12:31:53 -06008249 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008250 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008251 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008252 up(&priv->sem);
8253 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008254}
8255
Jeff Garzikbf794512005-07-31 13:07:26 -04008256static int ipw_wx_get_freq(struct net_device *dev,
8257 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008258 union iwreq_data *wrqu, char *extra)
8259{
8260 struct ipw_priv *priv = ieee80211_priv(dev);
8261
8262 wrqu->freq.e = 0;
8263
8264 /* If we are associated, trying to associate, or have a statically
8265 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008266 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008267 if (priv->config & CFG_STATIC_CHANNEL ||
8268 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8269 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008270 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008271 wrqu->freq.m = 0;
8272
James Ketrenosc848d0a2005-08-24 21:56:24 -05008273 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008274 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8275 return 0;
8276}
8277
Jeff Garzikbf794512005-07-31 13:07:26 -04008278static int ipw_wx_set_mode(struct net_device *dev,
8279 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008280 union iwreq_data *wrqu, char *extra)
8281{
8282 struct ipw_priv *priv = ieee80211_priv(dev);
8283 int err = 0;
8284
8285 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8286
James Ketrenos43f66a62005-03-25 12:31:53 -06008287 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008288#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008289 case IW_MODE_MONITOR:
8290#endif
8291 case IW_MODE_ADHOC:
8292 case IW_MODE_INFRA:
8293 break;
8294 case IW_MODE_AUTO:
8295 wrqu->mode = IW_MODE_INFRA;
8296 break;
8297 default:
8298 return -EINVAL;
8299 }
James Ketrenosb095c382005-08-24 22:04:42 -05008300 if (wrqu->mode == priv->ieee->iw_mode)
8301 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008302
James Ketrenosb095c382005-08-24 22:04:42 -05008303 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008304
8305 ipw_sw_reset(priv, 0);
8306
James Ketrenosb095c382005-08-24 22:04:42 -05008307#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008308 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008309 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008310
8311 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008312#ifdef CONFIG_IEEE80211_RADIOTAP
8313 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8314#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008315 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008316#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008317#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008318
Jeff Garzikbf794512005-07-31 13:07:26 -04008319 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008320 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008321 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008322
8323 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008324
James Ketrenosc848d0a2005-08-24 21:56:24 -05008325 queue_work(priv->workqueue, &priv->adapter_restart);
8326 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008327 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008328}
8329
Jeff Garzikbf794512005-07-31 13:07:26 -04008330static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008331 struct iw_request_info *info,
8332 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008333{
8334 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008335 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008336 wrqu->mode = priv->ieee->iw_mode;
8337 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008338 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008339 return 0;
8340}
8341
James Ketrenos43f66a62005-03-25 12:31:53 -06008342/* Values are in microsecond */
8343static const s32 timeout_duration[] = {
8344 350000,
8345 250000,
8346 75000,
8347 37000,
8348 25000,
8349};
8350
8351static const s32 period_duration[] = {
8352 400000,
8353 700000,
8354 1000000,
8355 1000000,
8356 1000000
8357};
8358
Jeff Garzikbf794512005-07-31 13:07:26 -04008359static int ipw_wx_get_range(struct net_device *dev,
8360 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008361 union iwreq_data *wrqu, char *extra)
8362{
8363 struct ipw_priv *priv = ieee80211_priv(dev);
8364 struct iw_range *range = (struct iw_range *)extra;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008365 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008366 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008367
8368 wrqu->data.length = sizeof(*range);
8369 memset(range, 0, sizeof(*range));
8370
8371 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008372 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008373
8374 range->max_qual.qual = 100;
8375 /* TODO: Find real max RSSI and stick here */
8376 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008377 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008378 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008379
8380 range->avg_qual.qual = 70;
8381 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008382 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008383 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008384 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008385 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008386 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008387
Jeff Garzikbf794512005-07-31 13:07:26 -04008388 for (i = 0; i < range->num_bitrates; i++)
8389 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008390 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008391
James Ketrenos43f66a62005-03-25 12:31:53 -06008392 range->max_rts = DEFAULT_RTS_THRESHOLD;
8393 range->min_frag = MIN_FRAG_THRESHOLD;
8394 range->max_frag = MAX_FRAG_THRESHOLD;
8395
8396 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008397 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008398 range->num_encoding_sizes = 2;
8399 range->max_encoding_tokens = WEP_KEYS;
8400
8401 /* Set the Wireless Extension versions */
8402 range->we_version_compiled = WIRELESS_EXT;
8403 range->we_version_source = 16;
8404
James Ketrenosb095c382005-08-24 22:04:42 -05008405 i = 0;
8406 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8407 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8408 i++, j++) {
8409 range->freq[i].i = geo->bg[j].channel;
8410 range->freq[i].m = geo->bg[j].freq * 100000;
8411 range->freq[i].e = 1;
8412 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008413 }
James Ketrenosb095c382005-08-24 22:04:42 -05008414
8415 if (priv->ieee->mode & IEEE_A) {
8416 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8417 i++, j++) {
8418 range->freq[i].i = geo->a[j].channel;
8419 range->freq[i].m = geo->a[j].freq * 100000;
8420 range->freq[i].e = 1;
8421 }
8422 }
8423
8424 range->num_channels = i;
8425 range->num_frequency = i;
8426
James Ketrenosc848d0a2005-08-24 21:56:24 -05008427 up(&priv->sem);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008428
8429 /* Event capability (kernel + driver) */
8430 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8431 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8432 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8433 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008434
8435 IPW_DEBUG_WX("GET Range\n");
8436 return 0;
8437}
8438
Jeff Garzikbf794512005-07-31 13:07:26 -04008439static int ipw_wx_set_wap(struct net_device *dev,
8440 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008441 union iwreq_data *wrqu, char *extra)
8442{
8443 struct ipw_priv *priv = ieee80211_priv(dev);
8444
8445 static const unsigned char any[] = {
8446 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8447 };
8448 static const unsigned char off[] = {
8449 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8450 };
8451
Jeff Garzikbf794512005-07-31 13:07:26 -04008452 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008453 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008454 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008455 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8456 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8457 /* we disable mandatory BSSID association */
8458 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8459 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008460 IPW_DEBUG_ASSOC("Attempting to associate with new "
8461 "parameters.\n");
8462 ipw_associate(priv);
8463 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008464 return 0;
8465 }
8466
8467 priv->config |= CFG_STATIC_BSSID;
8468 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8469 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008470 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008471 return 0;
8472 }
8473
8474 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8475 MAC_ARG(wrqu->ap_addr.sa_data));
8476
8477 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8478
James Ketrenosc848d0a2005-08-24 21:56:24 -05008479 /* Network configuration changed -- force [re]association */
8480 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8481 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008482 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008483
James Ketrenosc848d0a2005-08-24 21:56:24 -05008484 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008485 return 0;
8486}
8487
Jeff Garzikbf794512005-07-31 13:07:26 -04008488static int ipw_wx_get_wap(struct net_device *dev,
8489 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008490 union iwreq_data *wrqu, char *extra)
8491{
8492 struct ipw_priv *priv = ieee80211_priv(dev);
8493 /* If we are associated, trying to associate, or have a statically
8494 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008495 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008496 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008497 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8498 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008499 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008500 } else
8501 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8502
8503 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8504 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008505 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008506 return 0;
8507}
8508
Jeff Garzikbf794512005-07-31 13:07:26 -04008509static int ipw_wx_set_essid(struct net_device *dev,
8510 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008511 union iwreq_data *wrqu, char *extra)
8512{
8513 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008514 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008515 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008516 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008517 if (wrqu->essid.flags && wrqu->essid.length) {
8518 length = wrqu->essid.length - 1;
8519 essid = extra;
8520 }
8521 if (length == 0) {
8522 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008523 if ((priv->config & CFG_STATIC_ESSID) &&
8524 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008525 STATUS_ASSOCIATING))) {
8526 IPW_DEBUG_ASSOC("Attempting to associate with new "
8527 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008528 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008529 ipw_associate(priv);
8530 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008531 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008532 return 0;
8533 }
8534
8535 length = min(length, IW_ESSID_MAX_SIZE);
8536
8537 priv->config |= CFG_STATIC_ESSID;
8538
8539 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8540 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008541 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 return 0;
8543 }
8544
8545 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8546 length);
8547
8548 priv->essid_len = length;
8549 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008550
James Ketrenosc848d0a2005-08-24 21:56:24 -05008551 /* Network configuration changed -- force [re]association */
8552 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8553 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008554 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008555
James Ketrenosc848d0a2005-08-24 21:56:24 -05008556 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008557 return 0;
8558}
8559
Jeff Garzikbf794512005-07-31 13:07:26 -04008560static int ipw_wx_get_essid(struct net_device *dev,
8561 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 union iwreq_data *wrqu, char *extra)
8563{
8564 struct ipw_priv *priv = ieee80211_priv(dev);
8565
8566 /* If we are associated, trying to associate, or have a statically
8567 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008568 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008569 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008570 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8571 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008572 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008573 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008574 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008575 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008576 } else {
8577 IPW_DEBUG_WX("Getting essid: ANY\n");
8578 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008579 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008580 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008581 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008582 return 0;
8583}
8584
Jeff Garzikbf794512005-07-31 13:07:26 -04008585static int ipw_wx_set_nick(struct net_device *dev,
8586 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008587 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008588{
James Ketrenos43f66a62005-03-25 12:31:53 -06008589 struct ipw_priv *priv = ieee80211_priv(dev);
8590
8591 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8592 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8593 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008594 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008595 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008597 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008598 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008599 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008600 return 0;
8601
8602}
8603
Jeff Garzikbf794512005-07-31 13:07:26 -04008604static int ipw_wx_get_nick(struct net_device *dev,
8605 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008606 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008607{
James Ketrenos43f66a62005-03-25 12:31:53 -06008608 struct ipw_priv *priv = ieee80211_priv(dev);
8609 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008610 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008611 wrqu->data.length = strlen(priv->nick) + 1;
8612 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008613 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008614 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008615 return 0;
8616}
8617
James Ketrenos43f66a62005-03-25 12:31:53 -06008618static int ipw_wx_set_rate(struct net_device *dev,
8619 struct iw_request_info *info,
8620 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008621{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008622 /* TODO: We should use semaphores or locks for access to priv */
8623 struct ipw_priv *priv = ieee80211_priv(dev);
8624 u32 target_rate = wrqu->bitrate.value;
8625 u32 fixed, mask;
8626
8627 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8628 /* value = X, fixed = 1 means only rate X */
8629 /* value = X, fixed = 0 means all rates lower equal X */
8630
8631 if (target_rate == -1) {
8632 fixed = 0;
8633 mask = IEEE80211_DEFAULT_RATES_MASK;
8634 /* Now we should reassociate */
8635 goto apply;
8636 }
8637
8638 mask = 0;
8639 fixed = wrqu->bitrate.fixed;
8640
8641 if (target_rate == 1000000 || !fixed)
8642 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8643 if (target_rate == 1000000)
8644 goto apply;
8645
8646 if (target_rate == 2000000 || !fixed)
8647 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8648 if (target_rate == 2000000)
8649 goto apply;
8650
8651 if (target_rate == 5500000 || !fixed)
8652 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8653 if (target_rate == 5500000)
8654 goto apply;
8655
8656 if (target_rate == 6000000 || !fixed)
8657 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8658 if (target_rate == 6000000)
8659 goto apply;
8660
8661 if (target_rate == 9000000 || !fixed)
8662 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8663 if (target_rate == 9000000)
8664 goto apply;
8665
8666 if (target_rate == 11000000 || !fixed)
8667 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8668 if (target_rate == 11000000)
8669 goto apply;
8670
8671 if (target_rate == 12000000 || !fixed)
8672 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8673 if (target_rate == 12000000)
8674 goto apply;
8675
8676 if (target_rate == 18000000 || !fixed)
8677 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8678 if (target_rate == 18000000)
8679 goto apply;
8680
8681 if (target_rate == 24000000 || !fixed)
8682 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8683 if (target_rate == 24000000)
8684 goto apply;
8685
8686 if (target_rate == 36000000 || !fixed)
8687 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8688 if (target_rate == 36000000)
8689 goto apply;
8690
8691 if (target_rate == 48000000 || !fixed)
8692 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8693 if (target_rate == 48000000)
8694 goto apply;
8695
8696 if (target_rate == 54000000 || !fixed)
8697 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8698 if (target_rate == 54000000)
8699 goto apply;
8700
8701 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8702 return -EINVAL;
8703
8704 apply:
8705 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8706 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008707 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008708 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008709 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008710 ipw_set_fixed_rate(priv, priv->ieee->mode);
8711 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008712 priv->config |= CFG_FIXED_RATE;
8713
James Ketrenosc848d0a2005-08-24 21:56:24 -05008714 if (priv->rates_mask == mask) {
8715 IPW_DEBUG_WX("Mask set to current mask.\n");
8716 up(&priv->sem);
8717 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008718 }
8719
James Ketrenosc848d0a2005-08-24 21:56:24 -05008720 priv->rates_mask = mask;
8721
8722 /* Network configuration changed -- force [re]association */
8723 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8724 if (!ipw_disassociate(priv))
8725 ipw_associate(priv);
8726
8727 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008728 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008729}
8730
Jeff Garzikbf794512005-07-31 13:07:26 -04008731static int ipw_wx_get_rate(struct net_device *dev,
8732 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008733 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008734{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008735 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008736 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008737 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008738 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8740 return 0;
8741}
8742
Jeff Garzikbf794512005-07-31 13:07:26 -04008743static int ipw_wx_set_rts(struct net_device *dev,
8744 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008745 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008746{
James Ketrenos43f66a62005-03-25 12:31:53 -06008747 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008748 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008749 if (wrqu->rts.disabled)
8750 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8751 else {
8752 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008753 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8754 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008755 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008756 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008757 priv->rts_threshold = wrqu->rts.value;
8758 }
8759
8760 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008761 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008762 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8763 return 0;
8764}
8765
Jeff Garzikbf794512005-07-31 13:07:26 -04008766static int ipw_wx_get_rts(struct net_device *dev,
8767 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008768 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008769{
James Ketrenos43f66a62005-03-25 12:31:53 -06008770 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008771 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 wrqu->rts.value = priv->rts_threshold;
8773 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008774 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008775 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008776 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8777 return 0;
8778}
8779
Jeff Garzikbf794512005-07-31 13:07:26 -04008780static int ipw_wx_set_txpow(struct net_device *dev,
8781 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008782 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008783{
James Ketrenos43f66a62005-03-25 12:31:53 -06008784 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008785 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008786
James Ketrenosc848d0a2005-08-24 21:56:24 -05008787 down(&priv->sem);
8788 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008789 err = -EINPROGRESS;
8790 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008791 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008792
James Ketrenosb095c382005-08-24 22:04:42 -05008793 if (!wrqu->power.fixed)
8794 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008795
James Ketrenosc848d0a2005-08-24 21:56:24 -05008796 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008797 err = -EINVAL;
8798 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008799 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008800
James Ketrenosb095c382005-08-24 22:04:42 -05008801 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008802 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008803 err = -EINVAL;
8804 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008805 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008806
8807 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008808 err = ipw_set_tx_power(priv);
8809 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008810 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008811 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008812}
8813
Jeff Garzikbf794512005-07-31 13:07:26 -04008814static int ipw_wx_get_txpow(struct net_device *dev,
8815 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008816 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008817{
James Ketrenos43f66a62005-03-25 12:31:53 -06008818 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008819 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008820 wrqu->power.value = priv->tx_power;
8821 wrqu->power.fixed = 1;
8822 wrqu->power.flags = IW_TXPOW_DBM;
8823 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008824 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008825
Jeff Garzikbf794512005-07-31 13:07:26 -04008826 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008827 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008828
8829 return 0;
8830}
8831
Jeff Garzikbf794512005-07-31 13:07:26 -04008832static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008833 struct iw_request_info *info,
8834 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008835{
8836 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008837 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008838 if (wrqu->frag.disabled)
8839 priv->ieee->fts = DEFAULT_FTS;
8840 else {
8841 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008842 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8843 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008845 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008846
James Ketrenos43f66a62005-03-25 12:31:53 -06008847 priv->ieee->fts = wrqu->frag.value & ~0x1;
8848 }
8849
8850 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008851 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8853 return 0;
8854}
8855
Jeff Garzikbf794512005-07-31 13:07:26 -04008856static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008857 struct iw_request_info *info,
8858 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008859{
8860 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008861 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008862 wrqu->frag.value = priv->ieee->fts;
8863 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008864 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008865 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008866 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8867
8868 return 0;
8869}
8870
Jeff Garzikbf794512005-07-31 13:07:26 -04008871static int ipw_wx_set_retry(struct net_device *dev,
8872 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008873 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008874{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008875 struct ipw_priv *priv = ieee80211_priv(dev);
8876
8877 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8878 return -EINVAL;
8879
8880 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8881 return 0;
8882
8883 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8884 return -EINVAL;
8885
8886 down(&priv->sem);
8887 if (wrqu->retry.flags & IW_RETRY_MIN)
8888 priv->short_retry_limit = (u8) wrqu->retry.value;
8889 else if (wrqu->retry.flags & IW_RETRY_MAX)
8890 priv->long_retry_limit = (u8) wrqu->retry.value;
8891 else {
8892 priv->short_retry_limit = (u8) wrqu->retry.value;
8893 priv->long_retry_limit = (u8) wrqu->retry.value;
8894 }
8895
8896 ipw_send_retry_limit(priv, priv->short_retry_limit,
8897 priv->long_retry_limit);
8898 up(&priv->sem);
8899 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8900 priv->short_retry_limit, priv->long_retry_limit);
8901 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008902}
8903
Jeff Garzikbf794512005-07-31 13:07:26 -04008904static int ipw_wx_get_retry(struct net_device *dev,
8905 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008906 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008907{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008908 struct ipw_priv *priv = ieee80211_priv(dev);
8909
8910 down(&priv->sem);
8911 wrqu->retry.disabled = 0;
8912
8913 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8914 up(&priv->sem);
8915 return -EINVAL;
8916 }
8917
8918 if (wrqu->retry.flags & IW_RETRY_MAX) {
8919 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8920 wrqu->retry.value = priv->long_retry_limit;
8921 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8922 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8923 wrqu->retry.value = priv->short_retry_limit;
8924 } else {
8925 wrqu->retry.flags = IW_RETRY_LIMIT;
8926 wrqu->retry.value = priv->short_retry_limit;
8927 }
8928 up(&priv->sem);
8929
8930 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8931
8932 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008933}
8934
James Ketrenosafbf30a2005-08-25 00:05:33 -05008935static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8936 int essid_len)
8937{
8938 struct ipw_scan_request_ext scan;
8939 int err = 0, scan_type;
8940
Pekka Enbergefb34422005-11-16 21:55:05 +02008941 if (!(priv->status & STATUS_INIT) ||
8942 (priv->status & STATUS_EXIT_PENDING))
8943 return 0;
8944
James Ketrenosafbf30a2005-08-25 00:05:33 -05008945 down(&priv->sem);
8946
8947 if (priv->status & STATUS_RF_KILL_MASK) {
8948 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8949 priv->status |= STATUS_SCAN_PENDING;
8950 goto done;
8951 }
8952
8953 IPW_DEBUG_HC("starting request direct scan!\n");
8954
8955 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01008956 /* We should not sleep here; otherwise we will block most
8957 * of the system (for instance, we hold rtnl_lock when we
8958 * get here).
8959 */
8960 err = -EAGAIN;
8961 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008962 }
8963 memset(&scan, 0, sizeof(scan));
8964
8965 if (priv->config & CFG_SPEED_SCAN)
8966 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8967 cpu_to_le16(30);
8968 else
8969 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8970 cpu_to_le16(20);
8971
8972 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8973 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008974 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008975 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8976
8977 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8978
8979 err = ipw_send_ssid(priv, essid, essid_len);
8980 if (err) {
8981 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8982 goto done;
8983 }
8984 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8985
8986 ipw_add_scan_channels(priv, &scan, scan_type);
8987
8988 err = ipw_send_scan_request_ext(priv, &scan);
8989 if (err) {
8990 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8991 goto done;
8992 }
8993
8994 priv->status |= STATUS_SCANNING;
8995
8996 done:
8997 up(&priv->sem);
8998 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008999}
9000
Jeff Garzikbf794512005-07-31 13:07:26 -04009001static int ipw_wx_set_scan(struct net_device *dev,
9002 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009003 union iwreq_data *wrqu, char *extra)
9004{
9005 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009006 struct iw_scan_req *req = NULL;
9007 if (wrqu->data.length
9008 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9009 req = (struct iw_scan_req *)extra;
9010 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9011 ipw_request_direct_scan(priv, req->essid,
9012 req->essid_len);
9013 return 0;
9014 }
9015 }
James Ketrenos8935f392005-10-05 15:59:08 -05009016
James Ketrenos43f66a62005-03-25 12:31:53 -06009017 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009018
9019 queue_work(priv->workqueue, &priv->request_scan);
9020
James Ketrenos43f66a62005-03-25 12:31:53 -06009021 return 0;
9022}
9023
Jeff Garzikbf794512005-07-31 13:07:26 -04009024static int ipw_wx_get_scan(struct net_device *dev,
9025 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009026 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009027{
James Ketrenos43f66a62005-03-25 12:31:53 -06009028 struct ipw_priv *priv = ieee80211_priv(dev);
9029 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9030}
9031
Jeff Garzikbf794512005-07-31 13:07:26 -04009032static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009033 struct iw_request_info *info,
9034 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009035{
9036 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009037 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009038 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009039
9040 down(&priv->sem);
9041 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009042
Hong Liucaeff812005-08-05 17:25:50 +08009043 /* In IBSS mode, we need to notify the firmware to update
9044 * the beacon info after we changed the capability. */
9045 if (cap != priv->capability &&
9046 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9047 priv->status & STATUS_ASSOCIATED)
9048 ipw_disassociate(priv);
9049
9050 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009051 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009052}
9053
Jeff Garzikbf794512005-07-31 13:07:26 -04009054static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009055 struct iw_request_info *info,
9056 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009057{
9058 struct ipw_priv *priv = ieee80211_priv(dev);
9059 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9060}
9061
Jeff Garzikbf794512005-07-31 13:07:26 -04009062static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009063 struct iw_request_info *info,
9064 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009065{
9066 struct ipw_priv *priv = ieee80211_priv(dev);
9067 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009068 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 if (wrqu->power.disabled) {
9070 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9071 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9072 if (err) {
9073 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009074 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009075 return err;
9076 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009077 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009078 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009079 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009080 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009081
9082 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009083 case IW_POWER_ON: /* If not specified */
9084 case IW_POWER_MODE: /* If set all mask */
9085 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009086 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009087 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009088 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9089 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009090 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009091 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009092 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009093
James Ketrenos43f66a62005-03-25 12:31:53 -06009094 /* If the user hasn't specified a power management mode yet, default
9095 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009096 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009097 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009098 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009099 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9100 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9101 if (err) {
9102 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009103 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009104 return err;
9105 }
9106
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009107 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009108 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 return 0;
9110}
9111
Jeff Garzikbf794512005-07-31 13:07:26 -04009112static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009113 struct iw_request_info *info,
9114 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009115{
9116 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009117 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009118 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009119 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009120 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009121 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009122
James Ketrenosc848d0a2005-08-24 21:56:24 -05009123 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009124 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009125
James Ketrenos43f66a62005-03-25 12:31:53 -06009126 return 0;
9127}
9128
Jeff Garzikbf794512005-07-31 13:07:26 -04009129static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009130 struct iw_request_info *info,
9131 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009132{
9133 struct ipw_priv *priv = ieee80211_priv(dev);
9134 int mode = *(int *)extra;
9135 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009136 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9138 mode = IPW_POWER_AC;
9139 priv->power_mode = mode;
9140 } else {
9141 priv->power_mode = IPW_POWER_ENABLED | mode;
9142 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009143
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 if (priv->power_mode != mode) {
9145 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009146
James Ketrenos43f66a62005-03-25 12:31:53 -06009147 if (err) {
9148 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009149 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 return err;
9151 }
9152 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009153 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 return 0;
9155}
9156
9157#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009158static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009159 struct iw_request_info *info,
9160 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009161{
9162 struct ipw_priv *priv = ieee80211_priv(dev);
9163 int level = IPW_POWER_LEVEL(priv->power_mode);
9164 char *p = extra;
9165
9166 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9167
9168 switch (level) {
9169 case IPW_POWER_AC:
9170 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9171 break;
9172 case IPW_POWER_BATTERY:
9173 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9174 break;
9175 default:
9176 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009177 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009178 timeout_duration[level - 1] / 1000,
9179 period_duration[level - 1] / 1000);
9180 }
9181
9182 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009183 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009184
9185 wrqu->data.length = p - extra + 1;
9186
9187 return 0;
9188}
9189
9190static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009191 struct iw_request_info *info,
9192 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009193{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009194 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009195 int mode = *(int *)extra;
9196 u8 band = 0, modulation = 0;
9197
9198 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009199 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009200 return -EINVAL;
9201 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009202 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009203 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009204 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009205 if (mode & IEEE_A) {
9206 band |= IEEE80211_52GHZ_BAND;
9207 modulation |= IEEE80211_OFDM_MODULATION;
9208 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009209 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009210 } else {
9211 if (mode & IEEE_A) {
9212 IPW_WARNING("Attempt to set 2200BG into "
9213 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009214 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009215 return -EINVAL;
9216 }
9217
James Ketrenosa33a1982005-09-14 14:28:59 -05009218 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009219 }
9220
9221 if (mode & IEEE_B) {
9222 band |= IEEE80211_24GHZ_BAND;
9223 modulation |= IEEE80211_CCK_MODULATION;
9224 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009225 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009226
James Ketrenos43f66a62005-03-25 12:31:53 -06009227 if (mode & IEEE_G) {
9228 band |= IEEE80211_24GHZ_BAND;
9229 modulation |= IEEE80211_OFDM_MODULATION;
9230 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009231 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009232
9233 priv->ieee->mode = mode;
9234 priv->ieee->freq_band = band;
9235 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009236 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009237
James Ketrenosc848d0a2005-08-24 21:56:24 -05009238 /* Network configuration changed -- force [re]association */
9239 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9240 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009241 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009242 ipw_associate(priv);
9243 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009244
James Ketrenosa613bff2005-08-24 21:43:11 -05009245 /* Update the band LEDs */
9246 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009247
Jeff Garzikbf794512005-07-31 13:07:26 -04009248 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009249 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009250 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009251 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009252 return 0;
9253}
9254
9255static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009256 struct iw_request_info *info,
9257 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009258{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009259 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009260 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009261 switch (priv->ieee->mode) {
9262 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009263 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9264 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009265 case IEEE_B:
9266 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9267 break;
9268 case IEEE_A | IEEE_B:
9269 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9270 break;
9271 case IEEE_G:
9272 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9273 break;
9274 case IEEE_A | IEEE_G:
9275 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9276 break;
9277 case IEEE_B | IEEE_G:
9278 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9279 break;
9280 case IEEE_A | IEEE_B | IEEE_G:
9281 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9282 break;
9283 default:
9284 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009285 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009286 }
9287
James Ketrenos43f66a62005-03-25 12:31:53 -06009288 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9289
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009290 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009291 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009292
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009293 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009294}
9295
James Ketrenosea2b26e2005-08-24 21:25:16 -05009296static int ipw_wx_set_preamble(struct net_device *dev,
9297 struct iw_request_info *info,
9298 union iwreq_data *wrqu, char *extra)
9299{
9300 struct ipw_priv *priv = ieee80211_priv(dev);
9301 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009302 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009303 /* Switching from SHORT -> LONG requires a disassociation */
9304 if (mode == 1) {
9305 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9306 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009307
9308 /* Network configuration changed -- force [re]association */
9309 IPW_DEBUG_ASSOC
9310 ("[re]association triggered due to preamble change.\n");
9311 if (!ipw_disassociate(priv))
9312 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009313 }
9314 goto done;
9315 }
9316
9317 if (mode == 0) {
9318 priv->config &= ~CFG_PREAMBLE_LONG;
9319 goto done;
9320 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009321 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009322 return -EINVAL;
9323
9324 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009325 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009326 return 0;
9327}
9328
9329static int ipw_wx_get_preamble(struct net_device *dev,
9330 struct iw_request_info *info,
9331 union iwreq_data *wrqu, char *extra)
9332{
9333 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009334 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009335 if (priv->config & CFG_PREAMBLE_LONG)
9336 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9337 else
9338 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009339 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009340 return 0;
9341}
9342
James Ketrenosb095c382005-08-24 22:04:42 -05009343#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009344static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009345 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009347{
James Ketrenos43f66a62005-03-25 12:31:53 -06009348 struct ipw_priv *priv = ieee80211_priv(dev);
9349 int *parms = (int *)extra;
9350 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009351 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009352 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009353 if (enable) {
9354 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009355#ifdef CONFIG_IEEE80211_RADIOTAP
9356 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9357#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009359#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009360 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009362
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 ipw_set_channel(priv, parms[1]);
9364 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009365 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9366 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009367 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009368 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009369 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009370 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009371 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009372 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 return 0;
9374}
9375
James Ketrenosb095c382005-08-24 22:04:42 -05009376#endif // CONFIG_IPW2200_MONITOR
9377
Jeff Garzikbf794512005-07-31 13:07:26 -04009378static int ipw_wx_reset(struct net_device *dev,
9379 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009380 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009381{
James Ketrenos43f66a62005-03-25 12:31:53 -06009382 struct ipw_priv *priv = ieee80211_priv(dev);
9383 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009384 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009385 return 0;
9386}
James Ketrenosb095c382005-08-24 22:04:42 -05009387
James Ketrenosb095c382005-08-24 22:04:42 -05009388static int ipw_wx_sw_reset(struct net_device *dev,
9389 struct iw_request_info *info,
9390 union iwreq_data *wrqu, char *extra)
9391{
9392 struct ipw_priv *priv = ieee80211_priv(dev);
9393 union iwreq_data wrqu_sec = {
9394 .encoding = {
9395 .flags = IW_ENCODE_DISABLED,
9396 },
9397 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009398 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009399
9400 IPW_DEBUG_WX("SW_RESET\n");
9401
9402 down(&priv->sem);
9403
James Ketrenosafbf30a2005-08-25 00:05:33 -05009404 ret = ipw_sw_reset(priv, 0);
9405 if (!ret) {
9406 free_firmware();
9407 ipw_adapter_restart(priv);
9408 }
James Ketrenosb095c382005-08-24 22:04:42 -05009409
9410 /* The SW reset bit might have been toggled on by the 'disable'
9411 * module parameter, so take appropriate action */
9412 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9413
9414 up(&priv->sem);
9415 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9416 down(&priv->sem);
9417
9418 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9419 /* Configuration likely changed -- force [re]association */
9420 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9421 "reset.\n");
9422 if (!ipw_disassociate(priv))
9423 ipw_associate(priv);
9424 }
9425
9426 up(&priv->sem);
9427
9428 return 0;
9429}
James Ketrenos43f66a62005-03-25 12:31:53 -06009430
9431/* Rebase the WE IOCTLs to zero for the handler array */
9432#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009433static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009434 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9435 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9436 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9437 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9438 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9439 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9440 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9441 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9442 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9443 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9444 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9445 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9446 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9447 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9448 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9449 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9450 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9451 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9452 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9453 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9454 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9455 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9456 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9457 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9458 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9459 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9460 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9461 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009462 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9463 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9464 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9465 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009466 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9467 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9468 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9469 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9470 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9471 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9472 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009473};
9474
James Ketrenosb095c382005-08-24 22:04:42 -05009475enum {
9476 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9477 IPW_PRIV_GET_POWER,
9478 IPW_PRIV_SET_MODE,
9479 IPW_PRIV_GET_MODE,
9480 IPW_PRIV_SET_PREAMBLE,
9481 IPW_PRIV_GET_PREAMBLE,
9482 IPW_PRIV_RESET,
9483 IPW_PRIV_SW_RESET,
9484#ifdef CONFIG_IPW2200_MONITOR
9485 IPW_PRIV_SET_MONITOR,
9486#endif
9487};
James Ketrenos43f66a62005-03-25 12:31:53 -06009488
Jeff Garzikbf794512005-07-31 13:07:26 -04009489static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009490 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009491 .cmd = IPW_PRIV_SET_POWER,
9492 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9493 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009494 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009495 .cmd = IPW_PRIV_GET_POWER,
9496 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9497 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009498 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009499 .cmd = IPW_PRIV_SET_MODE,
9500 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9501 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009502 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009503 .cmd = IPW_PRIV_GET_MODE,
9504 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9505 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009506 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009507 .cmd = IPW_PRIV_SET_PREAMBLE,
9508 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9509 .name = "set_preamble"},
9510 {
9511 .cmd = IPW_PRIV_GET_PREAMBLE,
9512 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9513 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009514 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009515 IPW_PRIV_RESET,
9516 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009517 {
9518 IPW_PRIV_SW_RESET,
9519 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9520#ifdef CONFIG_IPW2200_MONITOR
9521 {
9522 IPW_PRIV_SET_MONITOR,
9523 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9524#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009525};
9526
9527static iw_handler ipw_priv_handler[] = {
9528 ipw_wx_set_powermode,
9529 ipw_wx_get_powermode,
9530 ipw_wx_set_wireless_mode,
9531 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009532 ipw_wx_set_preamble,
9533 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009534 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009535 ipw_wx_sw_reset,
9536#ifdef CONFIG_IPW2200_MONITOR
9537 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009538#endif
9539};
9540
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009541static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009542 .standard = ipw_wx_handlers,
9543 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9544 .num_private = ARRAY_SIZE(ipw_priv_handler),
9545 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9546 .private = ipw_priv_handler,
9547 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009548 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009549};
9550
James Ketrenos43f66a62005-03-25 12:31:53 -06009551/*
9552 * Get wireless statistics.
9553 * Called by /proc/net/wireless
9554 * Also called by SIOCGIWSTATS
9555 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009556static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009557{
9558 struct ipw_priv *priv = ieee80211_priv(dev);
9559 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009560
James Ketrenos43f66a62005-03-25 12:31:53 -06009561 wstats = &priv->wstats;
9562
James Ketrenosea2b26e2005-08-24 21:25:16 -05009563 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009564 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009565 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9566 * and associated; if not associcated, the values are all meaningless
9567 * anyway, so set them all to NULL and INVALID */
9568 if (!(priv->status & STATUS_ASSOCIATED)) {
9569 wstats->miss.beacon = 0;
9570 wstats->discard.retries = 0;
9571 wstats->qual.qual = 0;
9572 wstats->qual.level = 0;
9573 wstats->qual.noise = 0;
9574 wstats->qual.updated = 7;
9575 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009576 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009577 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009578 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009579
9580 wstats->qual.qual = priv->quality;
9581 wstats->qual.level = average_value(&priv->average_rssi);
9582 wstats->qual.noise = average_value(&priv->average_noise);
9583 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009584 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009585
9586 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9587 wstats->discard.retries = priv->last_tx_failures;
9588 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009589
James Ketrenos43f66a62005-03-25 12:31:53 -06009590/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9591 goto fail_get_ordinal;
9592 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009593
James Ketrenos43f66a62005-03-25 12:31:53 -06009594 return wstats;
9595}
9596
James Ketrenos43f66a62005-03-25 12:31:53 -06009597/* net device stuff */
9598
Arjan van de Ven858119e2006-01-14 13:20:43 -08009599static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009600{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009601 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009602 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009603 sys_config->answer_broadcast_ssid_probe = 0;
9604 sys_config->accept_all_data_frames = 0;
9605 sys_config->accept_non_directed_frames = 1;
9606 sys_config->exclude_unicast_unencrypted = 0;
9607 sys_config->disable_unicast_decryption = 1;
9608 sys_config->exclude_multicast_unencrypted = 0;
9609 sys_config->disable_multicast_decryption = 1;
9610 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009611 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009612 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009613 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009614 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009615 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009616}
9617
9618static int ipw_net_open(struct net_device *dev)
9619{
9620 struct ipw_priv *priv = ieee80211_priv(dev);
9621 IPW_DEBUG_INFO("dev->open\n");
9622 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009623 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009624 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9625 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009626 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009627 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009628 return 0;
9629}
9630
9631static int ipw_net_stop(struct net_device *dev)
9632{
9633 IPW_DEBUG_INFO("dev->close\n");
9634 netif_stop_queue(dev);
9635 return 0;
9636}
9637
9638/*
9639todo:
9640
9641modify to send one tfd per fragment instead of using chunking. otherwise
9642we need to heavily modify the ieee80211_skb_to_txb.
9643*/
9644
Arjan van de Ven858119e2006-01-14 13:20:43 -08009645static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009646 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009647{
James Ketrenos0dacca12005-09-21 12:23:41 -05009648 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009649 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009650 int i = 0;
9651 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009652#ifdef CONFIG_IPW_QOS
9653 int tx_id = ipw_get_tx_queue_number(priv, pri);
9654 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9655#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009656 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009657#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009658 struct clx2_queue *q = &txq->q;
9659 u8 id, hdr_len, unicast;
9660 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009661 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009662
James Ketrenos227d2dc2005-07-28 16:25:55 -05009663 /* If there isn't room in the queue, we return busy and let the
9664 * network stack requeue the packet for us */
9665 if (ipw_queue_space(q) < q->high_mark)
9666 return NETDEV_TX_BUSY;
James Ketrenos43f66a62005-03-25 12:31:53 -06009667
9668 switch (priv->ieee->iw_mode) {
9669 case IW_MODE_ADHOC:
9670 hdr_len = IEEE80211_3ADDR_LEN;
Stephen Hemminger3c190652006-01-03 15:27:38 -08009671 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009672 id = ipw_find_station(priv, hdr->addr1);
9673 if (id == IPW_INVALID_STATION) {
9674 id = ipw_add_station(priv, hdr->addr1);
9675 if (id == IPW_INVALID_STATION) {
9676 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009677 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009678 MAC_ARG(hdr->addr1));
9679 goto drop;
9680 }
9681 }
9682 break;
9683
9684 case IW_MODE_INFRA:
9685 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009686 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 hdr_len = IEEE80211_3ADDR_LEN;
9688 id = 0;
9689 break;
9690 }
9691
9692 tfd = &txq->bd[q->first_empty];
9693 txq->txb[q->first_empty] = txb;
9694 memset(tfd, 0, sizeof(*tfd));
9695 tfd->u.data.station_number = id;
9696
9697 tfd->control_flags.message_type = TX_FRAME_TYPE;
9698 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9699
9700 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009701 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009702 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009703
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009705 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009706 else
James Ketrenosb095c382005-08-24 22:04:42 -05009707 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009708
James Ketrenosea2b26e2005-08-24 21:25:16 -05009709 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9710 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009711
James Ketrenosc848d0a2005-08-24 21:56:24 -05009712 fc = le16_to_cpu(hdr->frame_ctl);
9713 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009714
9715 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9716
James Ketrenosb095c382005-08-24 22:04:42 -05009717 if (likely(unicast))
9718 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9719
9720 if (txb->encrypted && !priv->ieee->host_encrypt) {
9721 switch (priv->ieee->sec.level) {
9722 case SEC_LEVEL_3:
9723 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9724 IEEE80211_FCTL_PROTECTED;
9725 /* XXX: ACK flag must be set for CCMP even if it
9726 * is a multicast/broadcast packet, because CCMP
9727 * group communication encrypted by GTK is
9728 * actually done by the AP. */
9729 if (!unicast)
9730 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9731
9732 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9733 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9734 tfd->u.data.key_index = 0;
9735 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9736 break;
9737 case SEC_LEVEL_2:
9738 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9739 IEEE80211_FCTL_PROTECTED;
9740 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9741 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9742 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9743 break;
9744 case SEC_LEVEL_1:
9745 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9746 IEEE80211_FCTL_PROTECTED;
9747 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9748 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9749 40)
9750 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9751 else
9752 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9753 break;
9754 case SEC_LEVEL_0:
9755 break;
9756 default:
9757 printk(KERN_ERR "Unknow security level %d\n",
9758 priv->ieee->sec.level);
9759 break;
9760 }
9761 } else
9762 /* No hardware encryption */
9763 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9764
9765#ifdef CONFIG_IPW_QOS
9766 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9767#endif /* CONFIG_IPW_QOS */
9768
James Ketrenos43f66a62005-03-25 12:31:53 -06009769 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009770 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9771 txb->nr_frags));
9772 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9773 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9774 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9775 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9776 i, le32_to_cpu(tfd->u.data.num_chunks),
9777 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009778 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009779 i, tfd->u.data.num_chunks,
9780 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009781 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 txb->fragments[i]->len - hdr_len);
9783
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009784 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009785 cpu_to_le32(pci_map_single
9786 (priv->pci_dev,
9787 txb->fragments[i]->data + hdr_len,
9788 txb->fragments[i]->len - hdr_len,
9789 PCI_DMA_TODEVICE));
9790 tfd->u.data.chunk_len[i] =
9791 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009792 }
9793
9794 if (i != txb->nr_frags) {
9795 struct sk_buff *skb;
9796 u16 remaining_bytes = 0;
9797 int j;
9798
9799 for (j = i; j < txb->nr_frags; j++)
9800 remaining_bytes += txb->fragments[j]->len - hdr_len;
9801
9802 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9803 remaining_bytes);
9804 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9805 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009806 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009807 for (j = i; j < txb->nr_frags; j++) {
9808 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009809
James Ketrenos43f66a62005-03-25 12:31:53 -06009810 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009811 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009812 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009813 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009814 }
9815 dev_kfree_skb_any(txb->fragments[i]);
9816 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009817 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009818 cpu_to_le32(pci_map_single
9819 (priv->pci_dev, skb->data,
9820 tfd->u.data.chunk_len[i],
9821 PCI_DMA_TODEVICE));
9822
9823 tfd->u.data.num_chunks =
9824 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9825 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009826 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009827 }
9828
9829 /* kick DMA */
9830 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9831 ipw_write32(priv, q->reg_w, q->first_empty);
9832
James Ketrenos227d2dc2005-07-28 16:25:55 -05009833 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009834
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009835 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009836 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9837 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009838 return NETDEV_TX_OK;
9839}
9840
9841static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9842{
9843 struct ipw_priv *priv = ieee80211_priv(dev);
9844#ifdef CONFIG_IPW_QOS
9845 int tx_id = ipw_get_tx_queue_number(priv, pri);
9846 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9847#else
9848 struct clx2_tx_queue *txq = &priv->txq[0];
9849#endif /* CONFIG_IPW_QOS */
9850
9851 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9852 return 1;
9853
9854 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009855}
9856
9857static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009858 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009859{
9860 struct ipw_priv *priv = ieee80211_priv(dev);
9861 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009862 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009863
9864 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009865 spin_lock_irqsave(&priv->lock, flags);
9866
9867 if (!(priv->status & STATUS_ASSOCIATED)) {
9868 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9869 priv->ieee->stats.tx_carrier_errors++;
9870 netif_stop_queue(dev);
9871 goto fail_unlock;
9872 }
9873
James Ketrenos227d2dc2005-07-28 16:25:55 -05009874 ret = ipw_tx_skb(priv, txb, pri);
9875 if (ret == NETDEV_TX_OK)
9876 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009877 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009878
James Ketrenos227d2dc2005-07-28 16:25:55 -05009879 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009880
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009881 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009882 spin_unlock_irqrestore(&priv->lock, flags);
9883 return 1;
9884}
9885
9886static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9887{
9888 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009889
James Ketrenos43f66a62005-03-25 12:31:53 -06009890 priv->ieee->stats.tx_packets = priv->tx_packets;
9891 priv->ieee->stats.rx_packets = priv->rx_packets;
9892 return &priv->ieee->stats;
9893}
9894
9895static void ipw_net_set_multicast_list(struct net_device *dev)
9896{
9897
9898}
9899
9900static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9901{
9902 struct ipw_priv *priv = ieee80211_priv(dev);
9903 struct sockaddr *addr = p;
9904 if (!is_valid_ether_addr(addr->sa_data))
9905 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009906 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009907 priv->config |= CFG_CUSTOM_MAC;
9908 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9909 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9910 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009911 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009912 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 return 0;
9914}
9915
Jeff Garzikbf794512005-07-31 13:07:26 -04009916static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 struct ethtool_drvinfo *info)
9918{
9919 struct ipw_priv *p = ieee80211_priv(dev);
9920 char vers[64];
9921 char date[32];
9922 u32 len;
9923
9924 strcpy(info->driver, DRV_NAME);
9925 strcpy(info->version, DRV_VERSION);
9926
9927 len = sizeof(vers);
9928 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9929 len = sizeof(date);
9930 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9931
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009932 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009933 vers, date);
9934 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009935 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009936}
9937
9938static u32 ipw_ethtool_get_link(struct net_device *dev)
9939{
9940 struct ipw_priv *priv = ieee80211_priv(dev);
9941 return (priv->status & STATUS_ASSOCIATED) != 0;
9942}
9943
9944static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9945{
James Ketrenosb095c382005-08-24 22:04:42 -05009946 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009947}
9948
9949static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009950 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009951{
9952 struct ipw_priv *p = ieee80211_priv(dev);
9953
James Ketrenosb095c382005-08-24 22:04:42 -05009954 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009955 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009956 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009957 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009958 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009959 return 0;
9960}
9961
9962static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009963 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009964{
9965 struct ipw_priv *p = ieee80211_priv(dev);
9966 int i;
9967
James Ketrenosb095c382005-08-24 22:04:42 -05009968 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009969 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009970 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009971 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009972 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -05009973 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06009974 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009975 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009976 return 0;
9977}
9978
9979static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009980 .get_link = ipw_ethtool_get_link,
9981 .get_drvinfo = ipw_ethtool_get_drvinfo,
9982 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9983 .get_eeprom = ipw_ethtool_get_eeprom,
9984 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06009985};
9986
9987static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9988{
9989 struct ipw_priv *priv = data;
9990 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04009991
James Ketrenos43f66a62005-03-25 12:31:53 -06009992 if (!priv)
9993 return IRQ_NONE;
9994
9995 spin_lock(&priv->lock);
9996
9997 if (!(priv->status & STATUS_INT_ENABLED)) {
9998 /* Shared IRQ */
9999 goto none;
10000 }
10001
James Ketrenosb095c382005-08-24 22:04:42 -050010002 inta = ipw_read32(priv, IPW_INTA_RW);
10003 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010004
James Ketrenos43f66a62005-03-25 12:31:53 -060010005 if (inta == 0xFFFFFFFF) {
10006 /* Hardware disappeared */
10007 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10008 goto none;
10009 }
10010
James Ketrenosb095c382005-08-24 22:04:42 -050010011 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010012 /* Shared interrupt */
10013 goto none;
10014 }
10015
10016 /* tell the device to stop sending interrupts */
10017 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010018
James Ketrenos43f66a62005-03-25 12:31:53 -060010019 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010020 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10021 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010022
James Ketrenos43f66a62005-03-25 12:31:53 -060010023 /* Cache INTA value for our tasklet */
10024 priv->isr_inta = inta;
10025
10026 tasklet_schedule(&priv->irq_tasklet);
10027
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010028 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010029
10030 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010031 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010032 spin_unlock(&priv->lock);
10033 return IRQ_NONE;
10034}
10035
10036static void ipw_rf_kill(void *adapter)
10037{
10038 struct ipw_priv *priv = adapter;
10039 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010040
James Ketrenos43f66a62005-03-25 12:31:53 -060010041 spin_lock_irqsave(&priv->lock, flags);
10042
10043 if (rf_kill_active(priv)) {
10044 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10045 if (priv->workqueue)
10046 queue_delayed_work(priv->workqueue,
10047 &priv->rf_kill, 2 * HZ);
10048 goto exit_unlock;
10049 }
10050
10051 /* RF Kill is now disabled, so bring the device back up */
10052
10053 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10054 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10055 "device\n");
10056
10057 /* we can not do an adapter restart while inside an irq lock */
10058 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010059 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010060 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10061 "enabled\n");
10062
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010063 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010064 spin_unlock_irqrestore(&priv->lock, flags);
10065}
10066
James Ketrenosc848d0a2005-08-24 21:56:24 -050010067static void ipw_bg_rf_kill(void *data)
10068{
10069 struct ipw_priv *priv = data;
10070 down(&priv->sem);
10071 ipw_rf_kill(data);
10072 up(&priv->sem);
10073}
10074
Adrian Bunka73e22b2006-01-21 01:39:42 +010010075static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010076{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010077 priv->last_seq_num = -1;
10078 priv->last_frag_num = -1;
10079 priv->last_packet_time = 0;
10080
James Ketrenosa613bff2005-08-24 21:43:11 -050010081 netif_carrier_on(priv->net_dev);
10082 if (netif_queue_stopped(priv->net_dev)) {
10083 IPW_DEBUG_NOTIF("waking queue\n");
10084 netif_wake_queue(priv->net_dev);
10085 } else {
10086 IPW_DEBUG_NOTIF("starting queue\n");
10087 netif_start_queue(priv->net_dev);
10088 }
10089
James Ketrenosc848d0a2005-08-24 21:56:24 -050010090 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010091 ipw_reset_stats(priv);
10092 /* Ensure the rate is updated immediately */
10093 priv->last_rate = ipw_get_current_rate(priv);
10094 ipw_gather_stats(priv);
10095 ipw_led_link_up(priv);
10096 notify_wx_assoc_event(priv);
10097
10098 if (priv->config & CFG_BACKGROUND_SCAN)
10099 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10100}
10101
James Ketrenosc848d0a2005-08-24 21:56:24 -050010102static void ipw_bg_link_up(void *data)
10103{
10104 struct ipw_priv *priv = data;
10105 down(&priv->sem);
10106 ipw_link_up(data);
10107 up(&priv->sem);
10108}
10109
Adrian Bunka73e22b2006-01-21 01:39:42 +010010110static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010111{
10112 ipw_led_link_down(priv);
10113 netif_carrier_off(priv->net_dev);
10114 netif_stop_queue(priv->net_dev);
10115 notify_wx_assoc_event(priv);
10116
10117 /* Cancel any queued work ... */
10118 cancel_delayed_work(&priv->request_scan);
10119 cancel_delayed_work(&priv->adhoc_check);
10120 cancel_delayed_work(&priv->gather_stats);
10121
10122 ipw_reset_stats(priv);
10123
James Ketrenosafbf30a2005-08-25 00:05:33 -050010124 if (!(priv->status & STATUS_EXIT_PENDING)) {
10125 /* Queue up another scan... */
10126 queue_work(priv->workqueue, &priv->request_scan);
10127 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010128}
10129
James Ketrenosc848d0a2005-08-24 21:56:24 -050010130static void ipw_bg_link_down(void *data)
10131{
10132 struct ipw_priv *priv = data;
10133 down(&priv->sem);
10134 ipw_link_down(data);
10135 up(&priv->sem);
10136}
10137
James Ketrenos43f66a62005-03-25 12:31:53 -060010138static int ipw_setup_deferred_work(struct ipw_priv *priv)
10139{
10140 int ret = 0;
10141
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010143 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010144 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010145
James Ketrenosc848d0a2005-08-24 21:56:24 -050010146 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10147 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10148 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010149 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010150 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10151 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10152 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10153 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10154 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010155 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010156 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010157 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010158 (void (*)(void *))ipw_bg_gather_stats, priv);
10159 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10160 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10161 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10162 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10163 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10164 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010165 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010166 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010167 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010168 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10169 priv);
10170 INIT_WORK(&priv->merge_networks,
10171 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010172
James Ketrenosb095c382005-08-24 22:04:42 -050010173#ifdef CONFIG_IPW_QOS
10174 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10175 priv);
10176#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010177
10178 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10179 ipw_irq_tasklet, (unsigned long)priv);
10180
10181 return ret;
10182}
10183
James Ketrenos43f66a62005-03-25 12:31:53 -060010184static void shim__set_security(struct net_device *dev,
10185 struct ieee80211_security *sec)
10186{
10187 struct ipw_priv *priv = ieee80211_priv(dev);
10188 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010189 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010190 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010191 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010192 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010193 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010194 priv->ieee->sec.flags &= ~(1 << i);
10195 else {
10196 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010197 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010198 priv->ieee->sec.flags |= (1 << i);
10199 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010200 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010201 } else if (sec->level != SEC_LEVEL_1)
10202 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 }
10204
James Ketrenosb095c382005-08-24 22:04:42 -050010205 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010206 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010207 priv->ieee->sec.active_key = sec->active_key;
10208 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010209 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010210 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010212 } else
10213 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010214
10215 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010216 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10217 priv->ieee->sec.auth_mode = sec->auth_mode;
10218 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010219 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10220 priv->capability |= CAP_SHARED_KEY;
10221 else
10222 priv->capability &= ~CAP_SHARED_KEY;
10223 priv->status |= STATUS_SECURITY_UPDATED;
10224 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010225
James Ketrenosb095c382005-08-24 22:04:42 -050010226 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10227 priv->ieee->sec.flags |= SEC_ENABLED;
10228 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010229 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010230 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010231 priv->capability |= CAP_PRIVACY_ON;
10232 else
10233 priv->capability &= ~CAP_PRIVACY_ON;
10234 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010235
James Ketrenosafbf30a2005-08-25 00:05:33 -050010236 if (sec->flags & SEC_ENCRYPT)
10237 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010238
James Ketrenosb095c382005-08-24 22:04:42 -050010239 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10240 priv->ieee->sec.level = sec->level;
10241 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010242 priv->status |= STATUS_SECURITY_UPDATED;
10243 }
10244
Zhu Yi1fbfea52005-08-05 17:22:56 +080010245 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10246 ipw_set_hwcrypto_keys(priv);
10247
Jeff Garzikbf794512005-07-31 13:07:26 -040010248 /* To match current functionality of ipw2100 (which works well w/
10249 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010250 * privacy capability changes ... */
10251#if 0
10252 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010253 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010254 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010255 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010256 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010257 IPW_DEBUG_ASSOC("Disassociating due to capability "
10258 "change.\n");
10259 ipw_disassociate(priv);
10260 }
10261#endif
10262}
10263
Jeff Garzikbf794512005-07-31 13:07:26 -040010264static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010265 struct ipw_supported_rates *rates)
10266{
10267 /* TODO: Mask out rates based on priv->rates_mask */
10268
10269 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010270 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010271 switch (priv->ieee->freq_band) {
10272 case IEEE80211_52GHZ_BAND:
10273 rates->ieee_mode = IPW_A_MODE;
10274 rates->purpose = IPW_RATE_CAPABILITIES;
10275 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10276 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10277 break;
10278
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010279 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010280 rates->ieee_mode = IPW_G_MODE;
10281 rates->purpose = IPW_RATE_CAPABILITIES;
10282 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10283 IEEE80211_CCK_DEFAULT_RATES_MASK);
10284 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10285 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10286 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10287 }
10288 break;
10289 }
10290
10291 return 0;
10292}
10293
Jeff Garzikbf794512005-07-31 13:07:26 -040010294static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010295{
James Ketrenos43f66a62005-03-25 12:31:53 -060010296 /* This is only called from ipw_up, which resets/reloads the firmware
10297 so, we don't need to first disable the card before we configure
10298 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010299 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010300 goto error;
10301
10302 /* initialize adapter address */
10303 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10304 goto error;
10305
10306 /* set basic system config settings */
10307 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010308
10309 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10310 * Does not support BT priority yet (don't abort or defer our Tx) */
10311 if (bt_coexist) {
10312 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10313
10314 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10315 priv->sys_config.bt_coexistence
10316 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10317 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10318 priv->sys_config.bt_coexistence
10319 |= CFG_BT_COEXISTENCE_OOB;
10320 }
10321
James Ketrenosc848d0a2005-08-24 21:56:24 -050010322 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10323 priv->sys_config.answer_broadcast_ssid_probe = 1;
10324 else
10325 priv->sys_config.answer_broadcast_ssid_probe = 0;
10326
James Ketrenos43f66a62005-03-25 12:31:53 -060010327 if (ipw_send_system_config(priv, &priv->sys_config))
10328 goto error;
10329
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010330 init_supported_rates(priv, &priv->rates);
10331 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010332 goto error;
10333
10334 /* Set request-to-send threshold */
10335 if (priv->rts_threshold) {
10336 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10337 goto error;
10338 }
James Ketrenosb095c382005-08-24 22:04:42 -050010339#ifdef CONFIG_IPW_QOS
10340 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10341 ipw_qos_activate(priv, NULL);
10342#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010343
10344 if (ipw_set_random_seed(priv))
10345 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010346
James Ketrenos43f66a62005-03-25 12:31:53 -060010347 /* final state transition to the RUN state */
10348 if (ipw_send_host_complete(priv))
10349 goto error;
10350
James Ketrenose6666192005-08-12 09:17:04 -050010351 priv->status |= STATUS_INIT;
10352
10353 ipw_led_init(priv);
10354 ipw_led_radio_on(priv);
10355 priv->notif_missed_beacons = 0;
10356
10357 /* Set hardware WEP key if it is configured. */
10358 if ((priv->capability & CAP_PRIVACY_ON) &&
10359 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10360 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10361 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010362
10363 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010364
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010365 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010366 return -EIO;
10367}
10368
James Ketrenos4f36f802005-08-03 20:36:56 -050010369/*
10370 * NOTE:
10371 *
10372 * These tables have been tested in conjunction with the
10373 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10374 *
10375 * Altering this values, using it on other hardware, or in geographies
10376 * not intended for resale of the above mentioned Intel adapters has
10377 * not been tested.
10378 *
10379 */
10380static const struct ieee80211_geo ipw_geos[] = {
10381 { /* Restricted */
10382 "---",
10383 .bg_channels = 11,
10384 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10385 {2427, 4}, {2432, 5}, {2437, 6},
10386 {2442, 7}, {2447, 8}, {2452, 9},
10387 {2457, 10}, {2462, 11}},
10388 },
10389
10390 { /* Custom US/Canada */
10391 "ZZF",
10392 .bg_channels = 11,
10393 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10394 {2427, 4}, {2432, 5}, {2437, 6},
10395 {2442, 7}, {2447, 8}, {2452, 9},
10396 {2457, 10}, {2462, 11}},
10397 .a_channels = 8,
10398 .a = {{5180, 36},
10399 {5200, 40},
10400 {5220, 44},
10401 {5240, 48},
10402 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10403 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10404 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10405 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10406 },
10407
10408 { /* Rest of World */
10409 "ZZD",
10410 .bg_channels = 13,
10411 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10412 {2427, 4}, {2432, 5}, {2437, 6},
10413 {2442, 7}, {2447, 8}, {2452, 9},
10414 {2457, 10}, {2462, 11}, {2467, 12},
10415 {2472, 13}},
10416 },
10417
10418 { /* Custom USA & Europe & High */
10419 "ZZA",
10420 .bg_channels = 11,
10421 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10422 {2427, 4}, {2432, 5}, {2437, 6},
10423 {2442, 7}, {2447, 8}, {2452, 9},
10424 {2457, 10}, {2462, 11}},
10425 .a_channels = 13,
10426 .a = {{5180, 36},
10427 {5200, 40},
10428 {5220, 44},
10429 {5240, 48},
10430 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10431 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10432 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10433 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10434 {5745, 149},
10435 {5765, 153},
10436 {5785, 157},
10437 {5805, 161},
10438 {5825, 165}},
10439 },
10440
10441 { /* Custom NA & Europe */
10442 "ZZB",
10443 .bg_channels = 11,
10444 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10445 {2427, 4}, {2432, 5}, {2437, 6},
10446 {2442, 7}, {2447, 8}, {2452, 9},
10447 {2457, 10}, {2462, 11}},
10448 .a_channels = 13,
10449 .a = {{5180, 36},
10450 {5200, 40},
10451 {5220, 44},
10452 {5240, 48},
10453 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10454 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10455 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10456 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10457 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10458 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10459 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10460 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10461 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10462 },
10463
10464 { /* Custom Japan */
10465 "ZZC",
10466 .bg_channels = 11,
10467 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10468 {2427, 4}, {2432, 5}, {2437, 6},
10469 {2442, 7}, {2447, 8}, {2452, 9},
10470 {2457, 10}, {2462, 11}},
10471 .a_channels = 4,
10472 .a = {{5170, 34}, {5190, 38},
10473 {5210, 42}, {5230, 46}},
10474 },
10475
10476 { /* Custom */
10477 "ZZM",
10478 .bg_channels = 11,
10479 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10480 {2427, 4}, {2432, 5}, {2437, 6},
10481 {2442, 7}, {2447, 8}, {2452, 9},
10482 {2457, 10}, {2462, 11}},
10483 },
10484
10485 { /* Europe */
10486 "ZZE",
10487 .bg_channels = 13,
10488 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10489 {2427, 4}, {2432, 5}, {2437, 6},
10490 {2442, 7}, {2447, 8}, {2452, 9},
10491 {2457, 10}, {2462, 11}, {2467, 12},
10492 {2472, 13}},
10493 .a_channels = 19,
10494 .a = {{5180, 36},
10495 {5200, 40},
10496 {5220, 44},
10497 {5240, 48},
10498 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10499 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10500 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10501 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10502 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10503 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10504 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10505 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10506 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10507 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10508 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10509 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10510 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10511 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10512 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10513 },
10514
10515 { /* Custom Japan */
10516 "ZZJ",
10517 .bg_channels = 14,
10518 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10519 {2427, 4}, {2432, 5}, {2437, 6},
10520 {2442, 7}, {2447, 8}, {2452, 9},
10521 {2457, 10}, {2462, 11}, {2467, 12},
10522 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10523 .a_channels = 4,
10524 .a = {{5170, 34}, {5190, 38},
10525 {5210, 42}, {5230, 46}},
10526 },
10527
James Ketrenos03520572005-10-19 16:12:31 -050010528 { /* Rest of World */
10529 "ZZR",
10530 .bg_channels = 14,
10531 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10532 {2427, 4}, {2432, 5}, {2437, 6},
10533 {2442, 7}, {2447, 8}, {2452, 9},
10534 {2457, 10}, {2462, 11}, {2467, 12},
10535 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10536 IEEE80211_CH_PASSIVE_ONLY}},
10537 },
10538
James Ketrenos4f36f802005-08-03 20:36:56 -050010539 { /* High Band */
10540 "ZZH",
10541 .bg_channels = 13,
10542 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10543 {2427, 4}, {2432, 5}, {2437, 6},
10544 {2442, 7}, {2447, 8}, {2452, 9},
10545 {2457, 10}, {2462, 11},
10546 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10547 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10548 .a_channels = 4,
10549 .a = {{5745, 149}, {5765, 153},
10550 {5785, 157}, {5805, 161}},
10551 },
10552
10553 { /* Custom Europe */
10554 "ZZG",
10555 .bg_channels = 13,
10556 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10557 {2427, 4}, {2432, 5}, {2437, 6},
10558 {2442, 7}, {2447, 8}, {2452, 9},
10559 {2457, 10}, {2462, 11},
10560 {2467, 12}, {2472, 13}},
10561 .a_channels = 4,
10562 .a = {{5180, 36}, {5200, 40},
10563 {5220, 44}, {5240, 48}},
10564 },
10565
10566 { /* Europe */
10567 "ZZK",
10568 .bg_channels = 13,
10569 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10570 {2427, 4}, {2432, 5}, {2437, 6},
10571 {2442, 7}, {2447, 8}, {2452, 9},
10572 {2457, 10}, {2462, 11},
10573 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10574 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10575 .a_channels = 24,
10576 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10577 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10578 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10579 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10580 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10581 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10582 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10583 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10584 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10585 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10586 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10587 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10588 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10589 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10590 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10591 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10592 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10593 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10594 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10595 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10596 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10597 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10598 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10599 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10600 },
10601
10602 { /* Europe */
10603 "ZZL",
10604 .bg_channels = 11,
10605 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10606 {2427, 4}, {2432, 5}, {2437, 6},
10607 {2442, 7}, {2447, 8}, {2452, 9},
10608 {2457, 10}, {2462, 11}},
10609 .a_channels = 13,
10610 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10611 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10612 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10613 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10614 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10615 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10616 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10617 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10618 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10619 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10620 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10621 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10622 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10623 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010624};
10625
Liu Hong1fe0adb2005-08-19 09:33:10 -050010626/* GEO code borrowed from ieee80211_geo.c */
10627static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
10628{
10629 int i;
10630
10631 /* Driver needs to initialize the geography map before using
10632 * these helper functions */
10633 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10634
10635 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10636 for (i = 0; i < ieee->geo.bg_channels; i++)
10637 /* NOTE: If G mode is currently supported but
10638 * this is a B only channel, we don't see it
10639 * as valid. */
10640 if ((ieee->geo.bg[i].channel == channel) &&
10641 (!(ieee->mode & IEEE_G) ||
10642 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
10643 return IEEE80211_24GHZ_BAND;
10644
10645 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10646 for (i = 0; i < ieee->geo.a_channels; i++)
10647 if (ieee->geo.a[i].channel == channel)
10648 return IEEE80211_52GHZ_BAND;
10649
10650 return 0;
10651}
10652
10653static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
10654{
10655 int i;
10656
10657 /* Driver needs to initialize the geography map before using
10658 * these helper functions */
10659 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10660
10661 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10662 for (i = 0; i < ieee->geo.bg_channels; i++)
10663 if (ieee->geo.bg[i].channel == channel)
10664 return i;
10665
10666 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10667 for (i = 0; i < ieee->geo.a_channels; i++)
10668 if (ieee->geo.a[i].channel == channel)
10669 return i;
10670
10671 return -1;
10672}
10673
10674static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
10675{
10676 int i;
10677
10678 /* Driver needs to initialize the geography map before using
10679 * these helper functions */
10680 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10681
10682 freq /= 100000;
10683
10684 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10685 for (i = 0; i < ieee->geo.bg_channels; i++)
10686 if (ieee->geo.bg[i].freq == freq)
10687 return ieee->geo.bg[i].channel;
10688
10689 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10690 for (i = 0; i < ieee->geo.a_channels; i++)
10691 if (ieee->geo.a[i].freq == freq)
10692 return ieee->geo.a[i].channel;
10693
10694 return 0;
10695}
10696
10697static int ipw_set_geo(struct ieee80211_device *ieee,
10698 const struct ieee80211_geo *geo)
10699{
10700 memcpy(ieee->geo.name, geo->name, 3);
10701 ieee->geo.name[3] = '\0';
10702 ieee->geo.bg_channels = geo->bg_channels;
10703 ieee->geo.a_channels = geo->a_channels;
10704 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
10705 sizeof(struct ieee80211_channel));
10706 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
10707 sizeof(struct ieee80211_channel));
10708 return 0;
10709}
10710
10711static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
10712{
10713 return &ieee->geo;
10714}
10715
James Ketrenos43f66a62005-03-25 12:31:53 -060010716#define MAX_HW_RESTARTS 5
10717static int ipw_up(struct ipw_priv *priv)
10718{
James Ketrenos4f36f802005-08-03 20:36:56 -050010719 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010720
10721 if (priv->status & STATUS_EXIT_PENDING)
10722 return -EIO;
10723
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010724 if (cmdlog && !priv->cmdlog) {
10725 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10726 GFP_KERNEL);
10727 if (priv->cmdlog == NULL) {
10728 IPW_ERROR("Error allocating %d command log entries.\n",
10729 cmdlog);
10730 } else {
10731 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10732 priv->cmdlog_len = cmdlog;
10733 }
10734 }
10735
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010736 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010737 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010738 * Also start the clocks. */
10739 rc = ipw_load(priv);
10740 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010741 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010742 return rc;
10743 }
10744
10745 ipw_init_ordinals(priv);
10746 if (!(priv->config & CFG_CUSTOM_MAC))
10747 eeprom_parse_mac(priv, priv->mac_addr);
10748 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10749
James Ketrenos4f36f802005-08-03 20:36:56 -050010750 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10751 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10752 ipw_geos[j].name, 3))
10753 break;
10754 }
James Ketrenos03520572005-10-19 16:12:31 -050010755 if (j == ARRAY_SIZE(ipw_geos)) {
10756 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10757 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10758 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10759 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010760 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010761 }
Liu Hong1fe0adb2005-08-19 09:33:10 -050010762 if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010763 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010764 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010765 }
10766
10767 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10768 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010769
James Ketrenosb095c382005-08-24 22:04:42 -050010770 if (priv->status & STATUS_RF_KILL_SW) {
10771 IPW_WARNING("Radio disabled by module parameter.\n");
10772 return 0;
10773 } else if (rf_kill_active(priv)) {
10774 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10775 "Kill switch must be turned off for "
10776 "wireless networking to work.\n");
10777 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10778 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010779 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010780 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010781
10782 rc = ipw_config(priv);
10783 if (!rc) {
10784 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010785
James Ketrenose6666192005-08-12 09:17:04 -050010786 /* If configure to try and auto-associate, kick
10787 * off a scan. */
10788 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010789
James Ketrenos43f66a62005-03-25 12:31:53 -060010790 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010791 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010792
James Ketrenosc848d0a2005-08-24 21:56:24 -050010793 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010794 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10795 i, MAX_HW_RESTARTS);
10796
10797 /* We had an error bringing up the hardware, so take it
10798 * all the way back down so we can try again */
10799 ipw_down(priv);
10800 }
10801
Jeff Garzikbf794512005-07-31 13:07:26 -040010802 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010803 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010804 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010805
James Ketrenos43f66a62005-03-25 12:31:53 -060010806 return -EIO;
10807}
10808
James Ketrenosc848d0a2005-08-24 21:56:24 -050010809static void ipw_bg_up(void *data)
10810{
10811 struct ipw_priv *priv = data;
10812 down(&priv->sem);
10813 ipw_up(data);
10814 up(&priv->sem);
10815}
10816
James Ketrenosb095c382005-08-24 22:04:42 -050010817static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010818{
James Ketrenosb095c382005-08-24 22:04:42 -050010819 int i;
10820
10821 if (priv->status & STATUS_SCANNING) {
10822 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10823 ipw_abort_scan(priv);
10824 }
10825
10826 if (priv->status & STATUS_ASSOCIATED) {
10827 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10828 ipw_disassociate(priv);
10829 }
10830
10831 ipw_led_shutdown(priv);
10832
10833 /* Wait up to 1s for status to change to not scanning and not
10834 * associated (disassociation can take a while for a ful 802.11
10835 * exchange */
10836 for (i = 1000; i && (priv->status &
10837 (STATUS_DISASSOCIATING |
10838 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10839 udelay(10);
10840
10841 if (priv->status & (STATUS_DISASSOCIATING |
10842 STATUS_ASSOCIATED | STATUS_SCANNING))
10843 IPW_DEBUG_INFO("Still associated or scanning...\n");
10844 else
10845 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10846
James Ketrenosc848d0a2005-08-24 21:56:24 -050010847 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010848 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010849
10850 priv->status &= ~STATUS_INIT;
10851}
10852
James Ketrenos43f66a62005-03-25 12:31:53 -060010853static void ipw_down(struct ipw_priv *priv)
10854{
James Ketrenosb095c382005-08-24 22:04:42 -050010855 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10856
10857 priv->status |= STATUS_EXIT_PENDING;
10858
10859 if (ipw_is_init(priv))
10860 ipw_deinit(priv);
10861
10862 /* Wipe out the EXIT_PENDING status bit if we are not actually
10863 * exiting the module */
10864 if (!exit_pending)
10865 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010866
10867 /* tell the device to stop sending interrupts */
10868 ipw_disable_interrupts(priv);
10869
10870 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010871 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010872 netif_carrier_off(priv->net_dev);
10873 netif_stop_queue(priv->net_dev);
10874
10875 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010876
10877 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010878}
10879
James Ketrenosc848d0a2005-08-24 21:56:24 -050010880static void ipw_bg_down(void *data)
10881{
10882 struct ipw_priv *priv = data;
10883 down(&priv->sem);
10884 ipw_down(data);
10885 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010886}
10887
10888/* Called by register_netdev() */
10889static int ipw_net_init(struct net_device *dev)
10890{
10891 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010892 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010893
James Ketrenosc848d0a2005-08-24 21:56:24 -050010894 if (ipw_up(priv)) {
10895 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010896 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010897 }
10898
James Ketrenosc848d0a2005-08-24 21:56:24 -050010899 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010900 return 0;
10901}
10902
10903/* PCI driver stuff */
10904static struct pci_device_id card_ids[] = {
10905 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10906 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10907 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10908 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10909 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10910 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10911 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10912 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10913 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10914 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10915 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10916 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10917 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10918 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10919 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10920 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10921 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10922 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010923 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010924 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010925 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10926 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010927
James Ketrenos43f66a62005-03-25 12:31:53 -060010928 /* required last entry */
10929 {0,}
10930};
10931
10932MODULE_DEVICE_TABLE(pci, card_ids);
10933
10934static struct attribute *ipw_sysfs_entries[] = {
10935 &dev_attr_rf_kill.attr,
10936 &dev_attr_direct_dword.attr,
10937 &dev_attr_indirect_byte.attr,
10938 &dev_attr_indirect_dword.attr,
10939 &dev_attr_mem_gpio_reg.attr,
10940 &dev_attr_command_event_reg.attr,
10941 &dev_attr_nic_type.attr,
10942 &dev_attr_status.attr,
10943 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010944 &dev_attr_error.attr,
10945 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010946 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010947 &dev_attr_eeprom_delay.attr,
10948 &dev_attr_ucode_version.attr,
10949 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010950 &dev_attr_scan_age.attr,
10951 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010952 &dev_attr_speed_scan.attr,
10953 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010954 NULL
10955};
10956
10957static struct attribute_group ipw_attribute_group = {
10958 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010959 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010960};
10961
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010962static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010963{
10964 int err = 0;
10965 struct net_device *net_dev;
10966 void __iomem *base;
10967 u32 length, val;
10968 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010969 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010970
10971 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10972 if (net_dev == NULL) {
10973 err = -ENOMEM;
10974 goto out;
10975 }
10976
10977 priv = ieee80211_priv(net_dev);
10978 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010979
James Ketrenos43f66a62005-03-25 12:31:53 -060010980 priv->net_dev = net_dev;
10981 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080010982#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060010983 ipw_debug_level = debug;
10984#endif
10985 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010986 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10987 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010988
James Ketrenosc848d0a2005-08-24 21:56:24 -050010989 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010990 if (pci_enable_device(pdev)) {
10991 err = -ENODEV;
10992 goto out_free_ieee80211;
10993 }
10994
10995 pci_set_master(pdev);
10996
Tobias Klauser0e08b442005-06-20 14:28:41 -070010997 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010998 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010999 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011000 if (err) {
11001 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11002 goto out_pci_disable_device;
11003 }
11004
11005 pci_set_drvdata(pdev, priv);
11006
11007 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011008 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011009 goto out_pci_disable_device;
11010
Jeff Garzikbf794512005-07-31 13:07:26 -040011011 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011012 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011013 pci_read_config_dword(pdev, 0x40, &val);
11014 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011015 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011016
James Ketrenos43f66a62005-03-25 12:31:53 -060011017 length = pci_resource_len(pdev, 0);
11018 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011019
James Ketrenos43f66a62005-03-25 12:31:53 -060011020 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11021 if (!base) {
11022 err = -ENODEV;
11023 goto out_pci_release_regions;
11024 }
11025
11026 priv->hw_base = base;
11027 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11028 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11029
11030 err = ipw_setup_deferred_work(priv);
11031 if (err) {
11032 IPW_ERROR("Unable to setup deferred work\n");
11033 goto out_iounmap;
11034 }
11035
James Ketrenosb095c382005-08-24 22:04:42 -050011036 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011037
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011038 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011039 if (err) {
11040 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11041 goto out_destroy_workqueue;
11042 }
11043
11044 SET_MODULE_OWNER(net_dev);
11045 SET_NETDEV_DEV(net_dev, &pdev->dev);
11046
James Ketrenosc848d0a2005-08-24 21:56:24 -050011047 down(&priv->sem);
11048
James Ketrenos43f66a62005-03-25 12:31:53 -060011049 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11050 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011051 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011052
James Ketrenosb095c382005-08-24 22:04:42 -050011053#ifdef CONFIG_IPW_QOS
James Ketrenos3b9990c2005-08-19 13:18:55 -050011054 priv->ieee->handle_probe_response = ipw_handle_beacon;
11055 priv->ieee->handle_beacon = ipw_handle_probe_response;
11056 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050011057#endif /* CONFIG_IPW_QOS */
11058
James Ketrenosc848d0a2005-08-24 21:56:24 -050011059 priv->ieee->perfect_rssi = -20;
11060 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011061
11062 net_dev->open = ipw_net_open;
11063 net_dev->stop = ipw_net_stop;
11064 net_dev->init = ipw_net_init;
11065 net_dev->get_stats = ipw_net_get_stats;
11066 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11067 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011068 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011069 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011070 net_dev->wireless_handlers = &ipw_wx_handler_def;
11071 net_dev->ethtool_ops = &ipw_ethtool_ops;
11072 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011073 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011074 net_dev->mem_start = pci_resource_start(pdev, 0);
11075 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11076
11077 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11078 if (err) {
11079 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011080 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011081 goto out_release_irq;
11082 }
11083
James Ketrenosc848d0a2005-08-24 21:56:24 -050011084 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011085 err = register_netdev(net_dev);
11086 if (err) {
11087 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011088 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011089 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 return 0;
11091
James Ketrenosa613bff2005-08-24 21:43:11 -050011092 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011093 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011094 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011095 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011096 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011097 destroy_workqueue(priv->workqueue);
11098 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011099 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011100 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011101 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011102 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011103 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011104 pci_disable_device(pdev);
11105 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011106 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011107 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011108 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011109 return err;
11110}
11111
11112static void ipw_pci_remove(struct pci_dev *pdev)
11113{
11114 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011115 struct list_head *p, *q;
11116 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011117
James Ketrenos43f66a62005-03-25 12:31:53 -060011118 if (!priv)
11119 return;
11120
James Ketrenosb095c382005-08-24 22:04:42 -050011121 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011122
James Ketrenosafbf30a2005-08-25 00:05:33 -050011123 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011124 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011125 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11126
James Ketrenosb095c382005-08-24 22:04:42 -050011127 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011128
11129 unregister_netdev(priv->net_dev);
11130
11131 if (priv->rxq) {
11132 ipw_rx_queue_free(priv, priv->rxq);
11133 priv->rxq = NULL;
11134 }
11135 ipw_tx_queue_free(priv);
11136
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011137 if (priv->cmdlog) {
11138 kfree(priv->cmdlog);
11139 priv->cmdlog = NULL;
11140 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011141 /* ipw_down will ensure that there is no more pending work
11142 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011143 cancel_delayed_work(&priv->adhoc_check);
11144 cancel_delayed_work(&priv->gather_stats);
11145 cancel_delayed_work(&priv->request_scan);
11146 cancel_delayed_work(&priv->rf_kill);
11147 cancel_delayed_work(&priv->scan_check);
11148 destroy_workqueue(priv->workqueue);
11149 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011150
James Ketrenosafbf30a2005-08-25 00:05:33 -050011151 /* Free MAC hash list for ADHOC */
11152 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11153 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011154 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011155 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011156 }
11157 }
11158
James Ketrenosb39860c2005-08-12 09:36:32 -050011159 if (priv->error) {
11160 ipw_free_error_log(priv->error);
11161 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011162 }
11163
11164 free_irq(pdev->irq, priv);
11165 iounmap(priv->hw_base);
11166 pci_release_regions(pdev);
11167 pci_disable_device(pdev);
11168 pci_set_drvdata(pdev, NULL);
11169 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011170 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011171}
11172
James Ketrenos43f66a62005-03-25 12:31:53 -060011173#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011174static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011175{
11176 struct ipw_priv *priv = pci_get_drvdata(pdev);
11177 struct net_device *dev = priv->net_dev;
11178
11179 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11180
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011181 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011182 ipw_down(priv);
11183
11184 /* Remove the PRESENT state of the device */
11185 netif_device_detach(dev);
11186
James Ketrenos43f66a62005-03-25 12:31:53 -060011187 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011188 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011189 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011190
James Ketrenos43f66a62005-03-25 12:31:53 -060011191 return 0;
11192}
11193
11194static int ipw_pci_resume(struct pci_dev *pdev)
11195{
11196 struct ipw_priv *priv = pci_get_drvdata(pdev);
11197 struct net_device *dev = priv->net_dev;
11198 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011199
James Ketrenos43f66a62005-03-25 12:31:53 -060011200 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11201
James Ketrenosea2b26e2005-08-24 21:25:16 -050011202 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011203 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011204 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011205
James Ketrenos43f66a62005-03-25 12:31:53 -060011206 /*
11207 * Suspend/Resume resets the PCI configuration space, so we have to
11208 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11209 * from interfering with C3 CPU state. pci_restore_state won't help
11210 * here since it only restores the first 64 bytes pci config header.
11211 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011212 pci_read_config_dword(pdev, 0x40, &val);
11213 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011214 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11215
11216 /* Set the device back into the PRESENT state; this will also wake
11217 * the queue of needed */
11218 netif_device_attach(dev);
11219
11220 /* Bring the device back up */
11221 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011222
James Ketrenos43f66a62005-03-25 12:31:53 -060011223 return 0;
11224}
11225#endif
11226
11227/* driver initialization stuff */
11228static struct pci_driver ipw_driver = {
11229 .name = DRV_NAME,
11230 .id_table = card_ids,
11231 .probe = ipw_pci_probe,
11232 .remove = __devexit_p(ipw_pci_remove),
11233#ifdef CONFIG_PM
11234 .suspend = ipw_pci_suspend,
11235 .resume = ipw_pci_resume,
11236#endif
11237};
11238
11239static int __init ipw_init(void)
11240{
11241 int ret;
11242
11243 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11244 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11245
11246 ret = pci_module_init(&ipw_driver);
11247 if (ret) {
11248 IPW_ERROR("Unable to initialize PCI module\n");
11249 return ret;
11250 }
11251
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011252 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011253 if (ret) {
11254 IPW_ERROR("Unable to create driver sysfs file\n");
11255 pci_unregister_driver(&ipw_driver);
11256 return ret;
11257 }
11258
11259 return ret;
11260}
11261
11262static void __exit ipw_exit(void)
11263{
11264 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11265 pci_unregister_driver(&ipw_driver);
11266}
11267
11268module_param(disable, int, 0444);
11269MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11270
11271module_param(associate, int, 0444);
11272MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11273
11274module_param(auto_create, int, 0444);
11275MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11276
James Ketrenosa613bff2005-08-24 21:43:11 -050011277module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011278MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011279
James Ketrenos43f66a62005-03-25 12:31:53 -060011280module_param(debug, int, 0444);
11281MODULE_PARM_DESC(debug, "debug output mask");
11282
11283module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011284MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011285
James Ketrenosb095c382005-08-24 22:04:42 -050011286#ifdef CONFIG_IPW_QOS
11287module_param(qos_enable, int, 0444);
11288MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011289
James Ketrenosb095c382005-08-24 22:04:42 -050011290module_param(qos_burst_enable, int, 0444);
11291MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11292
11293module_param(qos_no_ack_mask, int, 0444);
11294MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11295
11296module_param(burst_duration_CCK, int, 0444);
11297MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11298
11299module_param(burst_duration_OFDM, int, 0444);
11300MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11301#endif /* CONFIG_IPW_QOS */
11302
11303#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011304module_param(mode, int, 0444);
11305MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11306#else
11307module_param(mode, int, 0444);
11308MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11309#endif
11310
Zhu Yi810dabd2006-01-24 16:36:59 +080011311module_param(bt_coexist, int, 0444);
11312MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11313
James Ketrenosb095c382005-08-24 22:04:42 -050011314module_param(hwcrypto, int, 0444);
11315MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11316
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011317module_param(cmdlog, int, 0444);
11318MODULE_PARM_DESC(cmdlog,
11319 "allocate a ring buffer for logging firmware commands");
11320
Zhu Yi4bfdb912006-01-24 16:37:16 +080011321module_param(roaming, int, 0444);
11322MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11323
James Ketrenos43f66a62005-03-25 12:31:53 -060011324module_exit(ipw_exit);
11325module_init(ipw_init);