blob: a6ca536e44f81658e15cc361f9e51232a517801a [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
Reinette Chatrec1eb2c82009-08-21 13:34:26 -070028 Intel Linux Wireless <ilw@linux.intel.com>
James Ketrenos43f66a62005-03-25 12:31:53 -060029 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040033#include <linux/sched.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060034#include "ipw2200.h"
35
Zhu Yiae4af612006-04-13 17:20:34 +080036
37#ifndef KBUILD_EXTMOD
38#define VK "k"
39#else
40#define VK
41#endif
42
43#ifdef CONFIG_IPW2200_DEBUG
44#define VD "d"
45#else
46#define VD
47#endif
48
49#ifdef CONFIG_IPW2200_MONITOR
50#define VM "m"
51#else
52#define VM
53#endif
54
55#ifdef CONFIG_IPW2200_PROMISCUOUS
56#define VP "p"
57#else
58#define VP
59#endif
60
Zhu Yi459d4082006-04-13 17:21:00 +080061#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080062#define VR "r"
63#else
64#define VR
65#endif
66
67#ifdef CONFIG_IPW2200_QOS
68#define VQ "q"
69#else
70#define VQ
71#endif
72
Zhu Yiee2c4ad2007-07-12 16:09:47 +080073#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060074#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080075#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060076#define DRV_VERSION IPW2200_VERSION
77
James Ketrenosb095c382005-08-24 22:04:42 -050078#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
79
James Ketrenos43f66a62005-03-25 12:31:53 -060080MODULE_DESCRIPTION(DRV_DESCRIPTION);
81MODULE_VERSION(DRV_VERSION);
82MODULE_AUTHOR(DRV_COPYRIGHT);
83MODULE_LICENSE("GPL");
84
James Ketrenosf6c5cb72005-08-25 00:39:09 -050085static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060086static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070087static int default_channel = 0;
88static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060089
90static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060091static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060092static int auto_create = 1;
Reinette Chatre21f8a732009-08-18 10:25:05 -070093static int led_support = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060094static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080095static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080096static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080097static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060098static const char ipw_modes[] = {
99 'a', 'b', 'g', '?'
100};
Zhu Yid2b83e12006-04-13 17:19:36 +0800101static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600102
Zhu Yid685b8c2006-04-13 17:20:27 +0800103#ifdef CONFIG_IPW2200_PROMISCUOUS
104static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
105#endif
106
107
Zhu Yie43e3c12006-04-13 17:20:45 +0800108#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500109static int qos_enable = 0;
110static int qos_burst_enable = 0;
111static int qos_no_ack_mask = 0;
112static int burst_duration_CCK = 0;
113static int burst_duration_OFDM = 0;
114
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400115static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500116 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
117 QOS_TX3_CW_MIN_OFDM},
118 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
119 QOS_TX3_CW_MAX_OFDM},
120 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
121 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
122 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
123 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
124};
125
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400126static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500127 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
128 QOS_TX3_CW_MIN_CCK},
129 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
130 QOS_TX3_CW_MAX_CCK},
131 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
132 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
133 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
134 QOS_TX3_TXOP_LIMIT_CCK}
135};
136
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400137static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500138 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
139 DEF_TX3_CW_MIN_OFDM},
140 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
141 DEF_TX3_CW_MAX_OFDM},
142 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
143 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
144 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
145 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
146};
147
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400148static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500149 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
150 DEF_TX3_CW_MIN_CCK},
151 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
152 DEF_TX3_CW_MAX_CCK},
153 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
154 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
155 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
156 DEF_TX3_TXOP_LIMIT_CCK}
157};
158
159static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
160
161static int from_priority_to_tx_queue[] = {
162 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
163 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
164};
165
166static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
167
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400168static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500169 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400170static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500171 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800172#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500173
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000174static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500175static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600176static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400177static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600178 struct clx2_tx_queue *txq, int qindex);
179static int ipw_queue_reset(struct ipw_priv *priv);
180
181static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
182 int len, int sync);
183
184static void ipw_tx_queue_free(struct ipw_priv *);
185
186static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
187static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
188static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600189static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000190static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600191static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000192static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600193static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400194static int init_supported_rates(struct ipw_priv *priv,
195 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500196static void ipw_set_hwcrypto_keys(struct ipw_priv *);
197static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600198
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500199static int snprint_line(char *buf, size_t count,
200 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600201{
202 int out, i, j, l;
203 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400204
James Ketrenos43f66a62005-03-25 12:31:53 -0600205 out = snprintf(buf, count, "%08X", ofs);
206
207 for (l = 0, i = 0; i < 2; i++) {
208 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400209 for (j = 0; j < 8 && l < len; j++, l++)
210 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600211 data[(i * 8 + j)]);
212 for (; j < 8; j++)
213 out += snprintf(buf + out, count - out, " ");
214 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400215
James Ketrenos43f66a62005-03-25 12:31:53 -0600216 out += snprintf(buf + out, count - out, " ");
217 for (l = 0, i = 0; i < 2; i++) {
218 out += snprintf(buf + out, count - out, " ");
219 for (j = 0; j < 8 && l < len; j++, l++) {
220 c = data[(i * 8 + j)];
221 if (!isascii(c) || !isprint(c))
222 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400223
James Ketrenos43f66a62005-03-25 12:31:53 -0600224 out += snprintf(buf + out, count - out, "%c", c);
225 }
226
227 for (; j < 8; j++)
228 out += snprintf(buf + out, count - out, " ");
229 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400230
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500231 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600232}
233
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400234static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600235{
236 char line[81];
237 u32 ofs = 0;
238 if (!(ipw_debug_level & level))
239 return;
240
241 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500242 snprint_line(line, sizeof(line), &data[ofs],
243 min(len, 16U), ofs);
244 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600245 ofs += 16;
246 len -= min(len, 16U);
247 }
248}
249
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500250static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
251{
252 size_t out = size;
253 u32 ofs = 0;
254 int total = 0;
255
256 while (size && len) {
257 out = snprint_line(output, size, &data[ofs],
258 min_t(size_t, len, 16U), ofs);
259
260 ofs += 16;
261 output += out;
262 size -= out;
263 len -= min_t(size_t, len, 16U);
264 total += out;
265 }
266 return total;
267}
268
Zhu Yic8fe6672006-01-24 16:36:36 +0800269/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600270static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
271#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
272
Zhu Yic8fe6672006-01-24 16:36:36 +0800273/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600274static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
275#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
276
Zhu Yic8fe6672006-01-24 16:36:36 +0800277/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600278static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
279static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
280{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400281 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
282 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600283 _ipw_write_reg8(a, b, c);
284}
285
Zhu Yic8fe6672006-01-24 16:36:36 +0800286/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600287static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
288static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
289{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400290 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
291 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600292 _ipw_write_reg16(a, b, c);
293}
294
Zhu Yic8fe6672006-01-24 16:36:36 +0800295/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600296static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
297static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
298{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400299 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
300 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600301 _ipw_write_reg32(a, b, c);
302}
303
Zhu Yic8fe6672006-01-24 16:36:36 +0800304/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100305static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
306 u8 val)
307{
308 writeb(val, ipw->hw_base + ofs);
309}
Zhu Yic8fe6672006-01-24 16:36:36 +0800310
311/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200312#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100313 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
314 __LINE__, (u32)(ofs), (u32)(val)); \
315 _ipw_write8(ipw, ofs, val); \
316} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600317
Zhu Yic8fe6672006-01-24 16:36:36 +0800318/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100319static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
320 u16 val)
321{
322 writew(val, ipw->hw_base + ofs);
323}
Zhu Yic8fe6672006-01-24 16:36:36 +0800324
325/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100326#define ipw_write16(ipw, ofs, val) do { \
327 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
328 __LINE__, (u32)(ofs), (u32)(val)); \
329 _ipw_write16(ipw, ofs, val); \
330} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600331
Zhu Yic8fe6672006-01-24 16:36:36 +0800332/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100333static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
334 u32 val)
335{
336 writel(val, ipw->hw_base + ofs);
337}
Zhu Yic8fe6672006-01-24 16:36:36 +0800338
339/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100340#define ipw_write32(ipw, ofs, val) do { \
341 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
342 __LINE__, (u32)(ofs), (u32)(val)); \
343 _ipw_write32(ipw, ofs, val); \
344} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600345
Zhu Yic8fe6672006-01-24 16:36:36 +0800346/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100347static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400348{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100349 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600350}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400351
Zhu Yic8fe6672006-01-24 16:36:36 +0800352/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100353#define ipw_read8(ipw, ofs) ({ \
354 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
355 (u32)(ofs)); \
356 _ipw_read8(ipw, ofs); \
357})
James Ketrenos43f66a62005-03-25 12:31:53 -0600358
Zhu Yic8fe6672006-01-24 16:36:36 +0800359/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100360static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400361{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100362 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600363}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400364
Zhu Yic8fe6672006-01-24 16:36:36 +0800365/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100366#define ipw_read16(ipw, ofs) ({ \
367 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
368 (u32)(ofs)); \
369 _ipw_read16(ipw, ofs); \
370})
James Ketrenos43f66a62005-03-25 12:31:53 -0600371
Zhu Yic8fe6672006-01-24 16:36:36 +0800372/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100373static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400374{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100375 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600376}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400377
Zhu Yic8fe6672006-01-24 16:36:36 +0800378/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100379#define ipw_read32(ipw, ofs) ({ \
380 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
381 (u32)(ofs)); \
382 _ipw_read32(ipw, ofs); \
383})
James Ketrenos43f66a62005-03-25 12:31:53 -0600384
385static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800386/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100387#define ipw_read_indirect(a, b, c, d) ({ \
388 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
389 __LINE__, (u32)(b), (u32)(d)); \
390 _ipw_read_indirect(a, b, c, d); \
391})
James Ketrenos43f66a62005-03-25 12:31:53 -0600392
Zhu Yic8fe6672006-01-24 16:36:36 +0800393/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400394static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
395 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100396#define ipw_write_indirect(a, b, c, d) do { \
397 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
398 __LINE__, (u32)(b), (u32)(d)); \
399 _ipw_write_indirect(a, b, c, d); \
400} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600401
Zhu Yic8fe6672006-01-24 16:36:36 +0800402/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400403static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600404{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400405 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500406 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
407 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600408}
409
Zhu Yic8fe6672006-01-24 16:36:36 +0800410/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600411static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
412{
Zhu Yi2638bc32006-01-24 16:37:52 +0800413 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800414 u32 dif_len = reg - aligned_addr;
415
James Ketrenos43f66a62005-03-25 12:31:53 -0600416 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800417 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
418 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600419}
420
Zhu Yic8fe6672006-01-24 16:36:36 +0800421/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400422static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600423{
Zhu Yi2638bc32006-01-24 16:37:52 +0800424 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800425 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
426
James Ketrenos43f66a62005-03-25 12:31:53 -0600427 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800428 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
429 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600430}
431
Zhu Yic8fe6672006-01-24 16:36:36 +0800432/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600433static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
434{
435 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500436 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600437 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500438 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400439 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600440}
441
Zhu Yic8fe6672006-01-24 16:36:36 +0800442/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600443static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
444{
445 u32 value;
446
447 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
448
James Ketrenosb095c382005-08-24 22:04:42 -0500449 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
450 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
452 return value;
453}
454
Zhu Yic8fe6672006-01-24 16:36:36 +0800455/* General purpose, no alignment requirement, iterative (multi-byte) read, */
456/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600457static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
458 int num)
459{
Zhu Yi2638bc32006-01-24 16:37:52 +0800460 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600461 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600462 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400463
James Ketrenos43f66a62005-03-25 12:31:53 -0600464 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
465
James Ketrenosea2b26e2005-08-24 21:25:16 -0500466 if (num <= 0) {
467 return;
468 }
469
Zhu Yic8fe6672006-01-24 16:36:36 +0800470 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600471 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500472 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600473 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500474 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500475 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 aligned_addr += 4;
477 }
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500480 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500481 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500482 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400483
Zhu Yic8fe6672006-01-24 16:36:36 +0800484 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500485 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500486 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500487 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500488 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500489 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600490}
491
Zhu Yic8fe6672006-01-24 16:36:36 +0800492/* General purpose, no alignment requirement, iterative (multi-byte) write, */
493/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400494static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 int num)
496{
Zhu Yi2638bc32006-01-24 16:37:52 +0800497 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600498 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600499 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400500
James Ketrenos43f66a62005-03-25 12:31:53 -0600501 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400502
James Ketrenosea2b26e2005-08-24 21:25:16 -0500503 if (num <= 0) {
504 return;
505 }
506
Zhu Yic8fe6672006-01-24 16:36:36 +0800507 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600508 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500509 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800510 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500511 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500512 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600513 aligned_addr += 4;
514 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400515
Zhu Yic8fe6672006-01-24 16:36:36 +0800516 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500517 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500518 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500519 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400520
Zhu Yic8fe6672006-01-24 16:36:36 +0800521 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500522 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500523 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500524 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500525 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500526 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600527}
528
Zhu Yic8fe6672006-01-24 16:36:36 +0800529/* General purpose, no alignment requirement, iterative (multi-byte) write, */
530/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400531static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600532 int num)
533{
534 memcpy_toio((priv->hw_base + addr), buf, num);
535}
536
Zhu Yic8fe6672006-01-24 16:36:36 +0800537/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600538static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
539{
540 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
541}
542
Zhu Yic8fe6672006-01-24 16:36:36 +0800543/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600544static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
545{
546 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
547}
548
Zhu Yi89c318e2006-06-08 22:19:49 -0700549static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600550{
551 if (priv->status & STATUS_INT_ENABLED)
552 return;
553 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500554 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600555}
556
Zhu Yi89c318e2006-06-08 22:19:49 -0700557static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600558{
559 if (!(priv->status & STATUS_INT_ENABLED))
560 return;
561 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500562 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600563}
564
Zhu Yi89c318e2006-06-08 22:19:49 -0700565static inline void ipw_enable_interrupts(struct ipw_priv *priv)
566{
567 unsigned long flags;
568
569 spin_lock_irqsave(&priv->irq_lock, flags);
570 __ipw_enable_interrupts(priv);
571 spin_unlock_irqrestore(&priv->irq_lock, flags);
572}
573
574static inline void ipw_disable_interrupts(struct ipw_priv *priv)
575{
576 unsigned long flags;
577
578 spin_lock_irqsave(&priv->irq_lock, flags);
579 __ipw_disable_interrupts(priv);
580 spin_unlock_irqrestore(&priv->irq_lock, flags);
581}
582
James Ketrenos43f66a62005-03-25 12:31:53 -0600583static char *ipw_error_desc(u32 val)
584{
585 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400586 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600587 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400588 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600589 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400590 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600591 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400592 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600593 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400594 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500595 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400596 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500597 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400598 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500599 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400600 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500601 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400602 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500603 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400604 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500605 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400606 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500607 return "DMA_STATUS";
608 case IPW_FW_ERROR_DINO_ERROR:
609 return "DINO_ERROR";
610 case IPW_FW_ERROR_EEPROM_ERROR:
611 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400612 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500613 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400614 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500615 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400616 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500617 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 }
619}
620
James Ketrenosb39860c2005-08-12 09:36:32 -0500621static void ipw_dump_error_log(struct ipw_priv *priv,
622 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600623{
James Ketrenosb39860c2005-08-12 09:36:32 -0500624 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600625
James Ketrenosb39860c2005-08-12 09:36:32 -0500626 if (!error) {
627 IPW_ERROR("Error allocating and capturing error log. "
628 "Nothing to dump.\n");
629 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600630 }
631
James Ketrenosb39860c2005-08-12 09:36:32 -0500632 IPW_ERROR("Start IPW Error Log Dump:\n");
633 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
634 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600635
James Ketrenosb39860c2005-08-12 09:36:32 -0500636 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400637 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500638 ipw_error_desc(error->elem[i].desc),
639 error->elem[i].time,
640 error->elem[i].blink1,
641 error->elem[i].blink2,
642 error->elem[i].link1,
643 error->elem[i].link2, error->elem[i].data);
644 for (i = 0; i < error->log_len; i++)
645 IPW_ERROR("%i\t0x%08x\t%i\n",
646 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500647 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600648}
James Ketrenos43f66a62005-03-25 12:31:53 -0600649
James Ketrenosc848d0a2005-08-24 21:56:24 -0500650static inline int ipw_is_init(struct ipw_priv *priv)
651{
652 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600653}
654
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400655static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600656{
657 u32 addr, field_info, field_len, field_count, total_len;
658
659 IPW_DEBUG_ORD("ordinal = %i\n", ord);
660
661 if (!priv || !val || !len) {
662 IPW_DEBUG_ORD("Invalid argument\n");
663 return -EINVAL;
664 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400665
James Ketrenos43f66a62005-03-25 12:31:53 -0600666 /* verify device ordinal tables have been initialized */
667 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
668 IPW_DEBUG_ORD("Access ordinals before initialization\n");
669 return -EINVAL;
670 }
671
672 switch (IPW_ORD_TABLE_ID_MASK & ord) {
673 case IPW_ORD_TABLE_0_MASK:
674 /*
675 * TABLE 0: Direct access to a table of 32 bit values
676 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400677 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600678 * read from the table
679 */
680
681 /* remove the table id from the ordinal */
682 ord &= IPW_ORD_TABLE_VALUE_MASK;
683
684 /* boundary check */
685 if (ord > priv->table0_len) {
686 IPW_DEBUG_ORD("ordinal value (%i) longer then "
687 "max (%i)\n", ord, priv->table0_len);
688 return -EINVAL;
689 }
690
691 /* verify we have enough room to store the value */
692 if (*len < sizeof(u32)) {
693 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200694 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600695 return -EINVAL;
696 }
697
698 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400699 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600700
701 *len = sizeof(u32);
702 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400703 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600704 break;
705
706 case IPW_ORD_TABLE_1_MASK:
707 /*
708 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400709 *
710 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600711 * representing starting addr for the data (which is
712 * also a u32)
713 */
714
715 /* remove the table id from the ordinal */
716 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400717
James Ketrenos43f66a62005-03-25 12:31:53 -0600718 /* boundary check */
719 if (ord > priv->table1_len) {
720 IPW_DEBUG_ORD("ordinal value too long\n");
721 return -EINVAL;
722 }
723
724 /* verify we have enough room to store the value */
725 if (*len < sizeof(u32)) {
726 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200727 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600728 return -EINVAL;
729 }
730
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400731 *((u32 *) val) =
732 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600733 *len = sizeof(u32);
734 break;
735
736 case IPW_ORD_TABLE_2_MASK:
737 /*
738 * TABLE 2: Indirect access to a table of variable sized values
739 *
740 * This table consist of six values, each containing
741 * - dword containing the starting offset of the data
742 * - dword containing the lengh in the first 16bits
743 * and the count in the second 16bits
744 */
745
746 /* remove the table id from the ordinal */
747 ord &= IPW_ORD_TABLE_VALUE_MASK;
748
749 /* boundary check */
750 if (ord > priv->table2_len) {
751 IPW_DEBUG_ORD("ordinal value too long\n");
752 return -EINVAL;
753 }
754
755 /* get the address of statistic */
756 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400757
758 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600759 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400760 field_info =
761 ipw_read_reg32(priv,
762 priv->table2_addr + (ord << 3) +
763 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400764
James Ketrenos43f66a62005-03-25 12:31:53 -0600765 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400766 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400767
James Ketrenos43f66a62005-03-25 12:31:53 -0600768 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400769 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400770
James Ketrenos43f66a62005-03-25 12:31:53 -0600771 /* abort if not enought memory */
772 total_len = field_len * field_count;
773 if (total_len > *len) {
774 *len = total_len;
775 return -EINVAL;
776 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400777
James Ketrenos43f66a62005-03-25 12:31:53 -0600778 *len = total_len;
779 if (!total_len)
780 return 0;
781
782 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400783 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600784 addr, total_len, field_info);
785 ipw_read_indirect(priv, addr, val, total_len);
786 break;
787
788 default:
789 IPW_DEBUG_ORD("Invalid ordinal!\n");
790 return -EINVAL;
791
792 }
793
James Ketrenos43f66a62005-03-25 12:31:53 -0600794 return 0;
795}
796
797static void ipw_init_ordinals(struct ipw_priv *priv)
798{
799 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400800 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600801
802 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
803 priv->table0_addr, priv->table0_len);
804
805 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
806 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
807
808 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
809 priv->table1_addr, priv->table1_len);
810
811 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
812 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400813 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600814
815 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
816 priv->table2_addr, priv->table2_len);
817
818}
819
Adrian Bunka73e22b2006-01-21 01:39:42 +0100820static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500821{
James Ketrenosb095c382005-08-24 22:04:42 -0500822 reg &= ~IPW_START_STANDBY;
823 if (reg & IPW_GATE_ODMA)
824 reg &= ~IPW_GATE_ODMA;
825 if (reg & IPW_GATE_IDMA)
826 reg &= ~IPW_GATE_IDMA;
827 if (reg & IPW_GATE_ADMA)
828 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500829 return reg;
830}
831
832/*
833 * LED behavior:
834 * - On radio ON, turn on any LEDs that require to be on during start
835 * - On initialization, start unassociated blink
836 * - On association, disable unassociated blink
837 * - On disassociation, start unassociated blink
838 * - On radio OFF, turn off any LEDs started during radio on
839 *
840 */
Zhu Yiede61112006-01-24 16:37:10 +0800841#define LD_TIME_LINK_ON msecs_to_jiffies(300)
842#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
843#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500844
Adrian Bunka73e22b2006-01-21 01:39:42 +0100845static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500846{
847 unsigned long flags;
848 u32 led;
849
850 /* If configured to not use LEDs, or nic_type is 1,
851 * then we don't toggle a LINK led */
852 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
853 return;
854
855 spin_lock_irqsave(&priv->lock, flags);
856
857 if (!(priv->status & STATUS_RF_KILL_MASK) &&
858 !(priv->status & STATUS_LED_LINK_ON)) {
859 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500860 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500861 led |= priv->led_association_on;
862
863 led = ipw_register_toggle(led);
864
865 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500866 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500867
868 priv->status |= STATUS_LED_LINK_ON;
869
870 /* If we aren't associated, schedule turning the LED off */
871 if (!(priv->status & STATUS_ASSOCIATED))
872 queue_delayed_work(priv->workqueue,
873 &priv->led_link_off,
874 LD_TIME_LINK_ON);
875 }
876
877 spin_unlock_irqrestore(&priv->lock, flags);
878}
879
David Howellsc4028952006-11-22 14:57:56 +0000880static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500881{
David Howellsc4028952006-11-22 14:57:56 +0000882 struct ipw_priv *priv =
883 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800884 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000885 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800886 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500887}
888
Adrian Bunka73e22b2006-01-21 01:39:42 +0100889static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500890{
891 unsigned long flags;
892 u32 led;
893
894 /* If configured not to use LEDs, or nic type is 1,
895 * then we don't goggle the LINK led. */
896 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
897 return;
898
899 spin_lock_irqsave(&priv->lock, flags);
900
901 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500902 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500903 led &= priv->led_association_off;
904 led = ipw_register_toggle(led);
905
906 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500907 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500908
909 IPW_DEBUG_LED("Link LED Off\n");
910
911 priv->status &= ~STATUS_LED_LINK_ON;
912
913 /* If we aren't associated and the radio is on, schedule
914 * turning the LED on (blink while unassociated) */
915 if (!(priv->status & STATUS_RF_KILL_MASK) &&
916 !(priv->status & STATUS_ASSOCIATED))
917 queue_delayed_work(priv->workqueue, &priv->led_link_on,
918 LD_TIME_LINK_OFF);
919
920 }
921
922 spin_unlock_irqrestore(&priv->lock, flags);
923}
924
David Howellsc4028952006-11-22 14:57:56 +0000925static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500926{
David Howellsc4028952006-11-22 14:57:56 +0000927 struct ipw_priv *priv =
928 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800929 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000930 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800931 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500932}
933
Arjan van de Ven858119e2006-01-14 13:20:43 -0800934static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500935{
James Ketrenosa613bff2005-08-24 21:43:11 -0500936 u32 led;
937
938 if (priv->config & CFG_NO_LED)
939 return;
940
James Ketrenosb095c382005-08-24 22:04:42 -0500941 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500942 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500943
944 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500945 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500946 led |= priv->led_activity_on;
947
948 led = ipw_register_toggle(led);
949
950 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500951 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500952
953 IPW_DEBUG_LED("Activity LED On\n");
954
955 priv->status |= STATUS_LED_ACT_ON;
956
James Ketrenosc848d0a2005-08-24 21:56:24 -0500957 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500958 queue_delayed_work(priv->workqueue, &priv->led_act_off,
959 LD_TIME_ACT_ON);
960 } else {
961 /* Reschedule LED off for full time period */
962 cancel_delayed_work(&priv->led_act_off);
963 queue_delayed_work(priv->workqueue, &priv->led_act_off,
964 LD_TIME_ACT_ON);
965 }
James Ketrenosb095c382005-08-24 22:04:42 -0500966}
James Ketrenosa613bff2005-08-24 21:43:11 -0500967
Adrian Bunka73e22b2006-01-21 01:39:42 +0100968#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500969void ipw_led_activity_on(struct ipw_priv *priv)
970{
971 unsigned long flags;
972 spin_lock_irqsave(&priv->lock, flags);
973 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500974 spin_unlock_irqrestore(&priv->lock, flags);
975}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100976#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500977
Adrian Bunka73e22b2006-01-21 01:39:42 +0100978static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500979{
980 unsigned long flags;
981 u32 led;
982
983 if (priv->config & CFG_NO_LED)
984 return;
985
986 spin_lock_irqsave(&priv->lock, flags);
987
988 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500989 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500990 led &= priv->led_activity_off;
991
992 led = ipw_register_toggle(led);
993
994 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500995 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500996
997 IPW_DEBUG_LED("Activity LED Off\n");
998
999 priv->status &= ~STATUS_LED_ACT_ON;
1000 }
1001
1002 spin_unlock_irqrestore(&priv->lock, flags);
1003}
1004
David Howellsc4028952006-11-22 14:57:56 +00001005static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001006{
David Howellsc4028952006-11-22 14:57:56 +00001007 struct ipw_priv *priv =
1008 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001009 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001010 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001011 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001012}
1013
Adrian Bunka73e22b2006-01-21 01:39:42 +01001014static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001015{
1016 unsigned long flags;
1017 u32 led;
1018
1019 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001020 if (priv->config & CFG_NO_LED ||
1021 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001022 return;
1023
1024 spin_lock_irqsave(&priv->lock, flags);
1025
James Ketrenosb095c382005-08-24 22:04:42 -05001026 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001027 if (priv->assoc_network->mode == IEEE_A) {
1028 led |= priv->led_ofdm_on;
1029 led &= priv->led_association_off;
1030 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1031 } else if (priv->assoc_network->mode == IEEE_G) {
1032 led |= priv->led_ofdm_on;
1033 led |= priv->led_association_on;
1034 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1035 } else {
1036 led &= priv->led_ofdm_off;
1037 led |= priv->led_association_on;
1038 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1039 }
1040
1041 led = ipw_register_toggle(led);
1042
1043 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001044 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001045
1046 spin_unlock_irqrestore(&priv->lock, flags);
1047}
1048
Adrian Bunka73e22b2006-01-21 01:39:42 +01001049static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001050{
1051 unsigned long flags;
1052 u32 led;
1053
1054 /* Only nic type 1 supports mode LEDs */
1055 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1056 return;
1057
1058 spin_lock_irqsave(&priv->lock, flags);
1059
James Ketrenosb095c382005-08-24 22:04:42 -05001060 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001061 led &= priv->led_ofdm_off;
1062 led &= priv->led_association_off;
1063
1064 led = ipw_register_toggle(led);
1065
1066 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001067 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001068
1069 spin_unlock_irqrestore(&priv->lock, flags);
1070}
1071
Adrian Bunka73e22b2006-01-21 01:39:42 +01001072static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001073{
1074 ipw_led_link_on(priv);
1075}
1076
Adrian Bunka73e22b2006-01-21 01:39:42 +01001077static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001078{
1079 ipw_led_activity_off(priv);
1080 ipw_led_link_off(priv);
1081}
1082
Adrian Bunka73e22b2006-01-21 01:39:42 +01001083static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001084{
1085 /* Set the Link Led on for all nic types */
1086 ipw_led_link_on(priv);
1087}
1088
Adrian Bunka73e22b2006-01-21 01:39:42 +01001089static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001090{
1091 ipw_led_activity_off(priv);
1092 ipw_led_link_off(priv);
1093
1094 if (priv->status & STATUS_RF_KILL_MASK)
1095 ipw_led_radio_off(priv);
1096}
1097
Adrian Bunka73e22b2006-01-21 01:39:42 +01001098static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001099{
1100 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1101
1102 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001103 priv->led_activity_on = IPW_ACTIVITY_LED;
1104 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001105
James Ketrenosb095c382005-08-24 22:04:42 -05001106 priv->led_association_on = IPW_ASSOCIATED_LED;
1107 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001108
1109 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001110 priv->led_ofdm_on = IPW_OFDM_LED;
1111 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001112
1113 switch (priv->nic_type) {
1114 case EEPROM_NIC_TYPE_1:
1115 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001116 priv->led_activity_on = IPW_ASSOCIATED_LED;
1117 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1118 priv->led_association_on = IPW_ACTIVITY_LED;
1119 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001120
1121 if (!(priv->config & CFG_NO_LED))
1122 ipw_led_band_on(priv);
1123
1124 /* And we don't blink link LEDs for this nic, so
1125 * just return here */
1126 return;
1127
1128 case EEPROM_NIC_TYPE_3:
1129 case EEPROM_NIC_TYPE_2:
1130 case EEPROM_NIC_TYPE_4:
1131 case EEPROM_NIC_TYPE_0:
1132 break;
1133
1134 default:
1135 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1136 priv->nic_type);
1137 priv->nic_type = EEPROM_NIC_TYPE_0;
1138 break;
1139 }
1140
1141 if (!(priv->config & CFG_NO_LED)) {
1142 if (priv->status & STATUS_ASSOCIATED)
1143 ipw_led_link_on(priv);
1144 else
1145 ipw_led_link_off(priv);
1146 }
1147}
1148
Adrian Bunka73e22b2006-01-21 01:39:42 +01001149static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001150{
James Ketrenosa613bff2005-08-24 21:43:11 -05001151 ipw_led_activity_off(priv);
1152 ipw_led_link_off(priv);
1153 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001154 cancel_delayed_work(&priv->led_link_on);
1155 cancel_delayed_work(&priv->led_link_off);
1156 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001157}
1158
James Ketrenos43f66a62005-03-25 12:31:53 -06001159/*
1160 * The following adds a new attribute to the sysfs representation
1161 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1162 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001163 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001164 * See the level definitions in ipw for details.
1165 */
1166static ssize_t show_debug_level(struct device_driver *d, char *buf)
1167{
1168 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1169}
James Ketrenosa613bff2005-08-24 21:43:11 -05001170
1171static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1172 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001173{
1174 char *p = (char *)buf;
1175 u32 val;
1176
1177 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1178 p++;
1179 if (p[0] == 'x' || p[0] == 'X')
1180 p++;
1181 val = simple_strtoul(p, &p, 16);
1182 } else
1183 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001184 if (p == buf)
1185 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001186 ": %s is not in hex or decimal form.\n", buf);
1187 else
1188 ipw_debug_level = val;
1189
1190 return strnlen(buf, count);
1191}
1192
Jeff Garzikbf794512005-07-31 13:07:26 -04001193static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001194 show_debug_level, store_debug_level);
1195
James Ketrenosb39860c2005-08-12 09:36:32 -05001196static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1197{
Zhu Yic8fe6672006-01-24 16:36:36 +08001198 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001199 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1200}
1201
1202static void ipw_capture_event_log(struct ipw_priv *priv,
1203 u32 log_len, struct ipw_event *log)
1204{
1205 u32 base;
1206
1207 if (log_len) {
1208 base = ipw_read32(priv, IPW_EVENT_LOG);
1209 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1210 (u8 *) log, sizeof(*log) * log_len);
1211 }
1212}
1213
1214static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1215{
1216 struct ipw_fw_error *error;
1217 u32 log_len = ipw_get_event_log_len(priv);
1218 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1219 u32 elem_len = ipw_read_reg32(priv, base);
1220
1221 error = kmalloc(sizeof(*error) +
1222 sizeof(*error->elem) * elem_len +
1223 sizeof(*error->log) * log_len, GFP_ATOMIC);
1224 if (!error) {
1225 IPW_ERROR("Memory allocation for firmware error log "
1226 "failed.\n");
1227 return NULL;
1228 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001229 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001230 error->status = priv->status;
1231 error->config = priv->config;
1232 error->elem_len = elem_len;
1233 error->log_len = log_len;
1234 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001235 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001236
1237 ipw_capture_event_log(priv, log_len, error->log);
1238
1239 if (elem_len)
1240 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1241 sizeof(*error->elem) * elem_len);
1242
1243 return error;
1244}
1245
James Ketrenosb39860c2005-08-12 09:36:32 -05001246static ssize_t show_event_log(struct device *d,
1247 struct device_attribute *attr, char *buf)
1248{
1249 struct ipw_priv *priv = dev_get_drvdata(d);
1250 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001251 u32 log_size;
1252 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001253 u32 len = 0, i;
1254
Reinette Chatre412e9e72007-12-18 22:01:02 -08001255 /* not using min() because of its strict type checking */
1256 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1257 sizeof(*log) * log_len : PAGE_SIZE;
1258 log = kzalloc(log_size, GFP_KERNEL);
1259 if (!log) {
1260 IPW_ERROR("Unable to allocate memory for log\n");
1261 return 0;
1262 }
1263 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001264 ipw_capture_event_log(priv, log_len, log);
1265
1266 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1267 for (i = 0; i < log_len; i++)
1268 len += snprintf(buf + len, PAGE_SIZE - len,
1269 "\n%08X%08X%08X",
1270 log[i].time, log[i].event, log[i].data);
1271 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001272 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001273 return len;
1274}
1275
1276static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1277
1278static ssize_t show_error(struct device *d,
1279 struct device_attribute *attr, char *buf)
1280{
1281 struct ipw_priv *priv = dev_get_drvdata(d);
1282 u32 len = 0, i;
1283 if (!priv->error)
1284 return 0;
1285 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001286 "%08lX%08X%08X%08X",
1287 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001288 priv->error->status,
1289 priv->error->config, priv->error->elem_len);
1290 for (i = 0; i < priv->error->elem_len; i++)
1291 len += snprintf(buf + len, PAGE_SIZE - len,
1292 "\n%08X%08X%08X%08X%08X%08X%08X",
1293 priv->error->elem[i].time,
1294 priv->error->elem[i].desc,
1295 priv->error->elem[i].blink1,
1296 priv->error->elem[i].blink2,
1297 priv->error->elem[i].link1,
1298 priv->error->elem[i].link2,
1299 priv->error->elem[i].data);
1300
1301 len += snprintf(buf + len, PAGE_SIZE - len,
1302 "\n%08X", priv->error->log_len);
1303 for (i = 0; i < priv->error->log_len; i++)
1304 len += snprintf(buf + len, PAGE_SIZE - len,
1305 "\n%08X%08X%08X",
1306 priv->error->log[i].time,
1307 priv->error->log[i].event,
1308 priv->error->log[i].data);
1309 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1310 return len;
1311}
1312
1313static ssize_t clear_error(struct device *d,
1314 struct device_attribute *attr,
1315 const char *buf, size_t count)
1316{
1317 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001318
1319 kfree(priv->error);
1320 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001321 return count;
1322}
1323
1324static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1325
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001326static ssize_t show_cmd_log(struct device *d,
1327 struct device_attribute *attr, char *buf)
1328{
1329 struct ipw_priv *priv = dev_get_drvdata(d);
1330 u32 len = 0, i;
1331 if (!priv->cmdlog)
1332 return 0;
1333 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1334 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1335 i = (i + 1) % priv->cmdlog_len) {
1336 len +=
1337 snprintf(buf + len, PAGE_SIZE - len,
1338 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1339 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1340 priv->cmdlog[i].cmd.len);
1341 len +=
1342 snprintk_buf(buf + len, PAGE_SIZE - len,
1343 (u8 *) priv->cmdlog[i].cmd.param,
1344 priv->cmdlog[i].cmd.len);
1345 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1346 }
1347 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1348 return len;
1349}
1350
1351static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1352
Zhu Yid685b8c2006-04-13 17:20:27 +08001353#ifdef CONFIG_IPW2200_PROMISCUOUS
1354static void ipw_prom_free(struct ipw_priv *priv);
1355static int ipw_prom_alloc(struct ipw_priv *priv);
1356static ssize_t store_rtap_iface(struct device *d,
1357 struct device_attribute *attr,
1358 const char *buf, size_t count)
1359{
1360 struct ipw_priv *priv = dev_get_drvdata(d);
1361 int rc = 0;
1362
1363 if (count < 1)
1364 return -EINVAL;
1365
1366 switch (buf[0]) {
1367 case '0':
1368 if (!rtap_iface)
1369 return count;
1370
1371 if (netif_running(priv->prom_net_dev)) {
1372 IPW_WARNING("Interface is up. Cannot unregister.\n");
1373 return count;
1374 }
1375
1376 ipw_prom_free(priv);
1377 rtap_iface = 0;
1378 break;
1379
1380 case '1':
1381 if (rtap_iface)
1382 return count;
1383
1384 rc = ipw_prom_alloc(priv);
1385 if (!rc)
1386 rtap_iface = 1;
1387 break;
1388
1389 default:
1390 return -EINVAL;
1391 }
1392
1393 if (rc) {
1394 IPW_ERROR("Failed to register promiscuous network "
1395 "device (error %d).\n", rc);
1396 }
1397
1398 return count;
1399}
1400
1401static ssize_t show_rtap_iface(struct device *d,
1402 struct device_attribute *attr,
1403 char *buf)
1404{
1405 struct ipw_priv *priv = dev_get_drvdata(d);
1406 if (rtap_iface)
1407 return sprintf(buf, "%s", priv->prom_net_dev->name);
1408 else {
1409 buf[0] = '-';
1410 buf[1] = '1';
1411 buf[2] = '\0';
1412 return 3;
1413 }
1414}
1415
1416static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1417 store_rtap_iface);
1418
1419static ssize_t store_rtap_filter(struct device *d,
1420 struct device_attribute *attr,
1421 const char *buf, size_t count)
1422{
1423 struct ipw_priv *priv = dev_get_drvdata(d);
1424
1425 if (!priv->prom_priv) {
1426 IPW_ERROR("Attempting to set filter without "
1427 "rtap_iface enabled.\n");
1428 return -EPERM;
1429 }
1430
1431 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1432
1433 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1434 BIT_ARG16(priv->prom_priv->filter));
1435
1436 return count;
1437}
1438
1439static ssize_t show_rtap_filter(struct device *d,
1440 struct device_attribute *attr,
1441 char *buf)
1442{
1443 struct ipw_priv *priv = dev_get_drvdata(d);
1444 return sprintf(buf, "0x%04X",
1445 priv->prom_priv ? priv->prom_priv->filter : 0);
1446}
1447
1448static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1449 store_rtap_filter);
1450#endif
1451
James Ketrenosa613bff2005-08-24 21:43:11 -05001452static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1453 char *buf)
1454{
1455 struct ipw_priv *priv = dev_get_drvdata(d);
1456 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1457}
1458
1459static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1460 const char *buf, size_t count)
1461{
1462 struct ipw_priv *priv = dev_get_drvdata(d);
1463 struct net_device *dev = priv->net_dev;
1464 char buffer[] = "00000000";
1465 unsigned long len =
1466 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1467 unsigned long val;
1468 char *p = buffer;
1469
1470 IPW_DEBUG_INFO("enter\n");
1471
1472 strncpy(buffer, buf, len);
1473 buffer[len] = 0;
1474
1475 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1476 p++;
1477 if (p[0] == 'x' || p[0] == 'X')
1478 p++;
1479 val = simple_strtoul(p, &p, 16);
1480 } else
1481 val = simple_strtoul(p, &p, 10);
1482 if (p == buffer) {
1483 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1484 } else {
1485 priv->ieee->scan_age = val;
1486 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1487 }
1488
1489 IPW_DEBUG_INFO("exit\n");
1490 return len;
1491}
1492
1493static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1494
1495static ssize_t show_led(struct device *d, struct device_attribute *attr,
1496 char *buf)
1497{
1498 struct ipw_priv *priv = dev_get_drvdata(d);
1499 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1500}
1501
1502static ssize_t store_led(struct device *d, struct device_attribute *attr,
1503 const char *buf, size_t count)
1504{
1505 struct ipw_priv *priv = dev_get_drvdata(d);
1506
1507 IPW_DEBUG_INFO("enter\n");
1508
1509 if (count == 0)
1510 return 0;
1511
1512 if (*buf == 0) {
1513 IPW_DEBUG_LED("Disabling LED control.\n");
1514 priv->config |= CFG_NO_LED;
1515 ipw_led_shutdown(priv);
1516 } else {
1517 IPW_DEBUG_LED("Enabling LED control.\n");
1518 priv->config &= ~CFG_NO_LED;
1519 ipw_led_init(priv);
1520 }
1521
1522 IPW_DEBUG_INFO("exit\n");
1523 return count;
1524}
1525
1526static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1527
Andrew Mortonad3fee52005-06-20 14:30:36 -07001528static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001529 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001530{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001531 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001532 return sprintf(buf, "0x%08x\n", (int)p->status);
1533}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001534
James Ketrenos43f66a62005-03-25 12:31:53 -06001535static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1536
Andrew Mortonad3fee52005-06-20 14:30:36 -07001537static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1538 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001539{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001540 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001541 return sprintf(buf, "0x%08x\n", (int)p->config);
1542}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001543
James Ketrenos43f66a62005-03-25 12:31:53 -06001544static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1545
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001547 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001548{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001549 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001550 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001551}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552
James Ketrenos43f66a62005-03-25 12:31:53 -06001553static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1554
Andrew Mortonad3fee52005-06-20 14:30:36 -07001555static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001556 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001557{
1558 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001559 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001560
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001561 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001562 return 0;
1563
1564 return sprintf(buf, "0x%08x\n", tmp);
1565}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001566
1567static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001568
Andrew Mortonad3fee52005-06-20 14:30:36 -07001569static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1570 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001571{
1572 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001573 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001574
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001576 return 0;
1577
1578 return sprintf(buf, "0x%08x\n", tmp);
1579}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001580
1581static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001582
1583/*
1584 * Add a device attribute to view/control the delay between eeprom
1585 * operations.
1586 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001587static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001588 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001589{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001590 struct ipw_priv *p = dev_get_drvdata(d);
1591 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001592 return sprintf(buf, "%i\n", n);
1593}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001594static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001595 struct device_attribute *attr,
1596 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001597{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001598 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001599 sscanf(buf, "%i", &p->eeprom_delay);
1600 return strnlen(buf, count);
1601}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001602
1603static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1604 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
Andrew Mortonad3fee52005-06-20 14:30:36 -07001606static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001607 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001608{
1609 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001610 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001611
James Ketrenosb095c382005-08-24 22:04:42 -05001612 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001613 return sprintf(buf, "0x%08x\n", reg);
1614}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001615static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001616 struct device_attribute *attr,
1617 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001618{
1619 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001620 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001621
1622 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001623 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001624 return strnlen(buf, count);
1625}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001626
1627static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1628 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001629
Andrew Mortonad3fee52005-06-20 14:30:36 -07001630static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001632{
1633 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001634 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001635
1636 reg = ipw_read_reg32(p, 0x301100);
1637 return sprintf(buf, "0x%08x\n", reg);
1638}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001639static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001640 struct device_attribute *attr,
1641 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001642{
1643 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001644 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001645
1646 sscanf(buf, "%x", &reg);
1647 ipw_write_reg32(p, 0x301100, reg);
1648 return strnlen(buf, count);
1649}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001650
1651static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1652 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001653
Andrew Mortonad3fee52005-06-20 14:30:36 -07001654static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001655 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001656{
1657 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001658 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001659
Jeff Garzikbf794512005-07-31 13:07:26 -04001660 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001661 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001662 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001663 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001664
James Ketrenos43f66a62005-03-25 12:31:53 -06001665 return sprintf(buf, "0x%08x\n", reg);
1666}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001667static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001668 struct device_attribute *attr,
1669 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001670{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001671 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001672
1673 sscanf(buf, "%x", &priv->indirect_dword);
1674 priv->status |= STATUS_INDIRECT_DWORD;
1675 return strnlen(buf, count);
1676}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001677
1678static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1679 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001680
Andrew Mortonad3fee52005-06-20 14:30:36 -07001681static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001682 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001683{
1684 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001685 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001686
Jeff Garzikbf794512005-07-31 13:07:26 -04001687 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001688 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001689 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001690 reg = 0;
1691
1692 return sprintf(buf, "0x%02x\n", reg);
1693}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001694static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001695 struct device_attribute *attr,
1696 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001697{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001698 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001699
1700 sscanf(buf, "%x", &priv->indirect_byte);
1701 priv->status |= STATUS_INDIRECT_BYTE;
1702 return strnlen(buf, count);
1703}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001704
1705static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001706 show_indirect_byte, store_indirect_byte);
1707
Andrew Mortonad3fee52005-06-20 14:30:36 -07001708static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001709 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001710{
1711 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001712 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001713
Jeff Garzikbf794512005-07-31 13:07:26 -04001714 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001715 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001716 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001717 reg = 0;
1718
1719 return sprintf(buf, "0x%08x\n", reg);
1720}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001721static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001722 struct device_attribute *attr,
1723 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001724{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001725 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001726
1727 sscanf(buf, "%x", &priv->direct_dword);
1728 priv->status |= STATUS_DIRECT_DWORD;
1729 return strnlen(buf, count);
1730}
James Ketrenos43f66a62005-03-25 12:31:53 -06001731
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001732static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1733 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001734
Arjan van de Ven858119e2006-01-14 13:20:43 -08001735static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001736{
1737 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1738 priv->status |= STATUS_RF_KILL_HW;
1739 else
1740 priv->status &= ~STATUS_RF_KILL_HW;
1741
1742 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1743}
1744
Andrew Mortonad3fee52005-06-20 14:30:36 -07001745static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001746 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001747{
1748 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001749 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001750 2 - HW based RF kill active
1751 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001752 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001753 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001754 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001755 return sprintf(buf, "%i\n", val);
1756}
1757
1758static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1759{
Jeff Garzikbf794512005-07-31 13:07:26 -04001760 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001761 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001762 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001763
1764 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1765 disable_radio ? "OFF" : "ON");
1766
1767 if (disable_radio) {
1768 priv->status |= STATUS_RF_KILL_SW;
1769
Dan Williams0b531672007-10-09 13:55:24 -04001770 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001771 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04001772 cancel_delayed_work(&priv->request_direct_scan);
1773 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04001774 cancel_delayed_work(&priv->scan_event);
1775 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 queue_work(priv->workqueue, &priv->down);
1777 } else {
1778 priv->status &= ~STATUS_RF_KILL_SW;
1779 if (rf_kill_active(priv)) {
1780 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1781 "disabled by HW switch\n");
1782 /* Make sure the RF_KILL check timer is running */
1783 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001784 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001785 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001786 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001787 queue_work(priv->workqueue, &priv->up);
1788 }
1789
1790 return 1;
1791}
1792
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001793static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1794 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001795{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001796 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001797
James Ketrenos43f66a62005-03-25 12:31:53 -06001798 ipw_radio_kill_sw(priv, buf[0] == '1');
1799
1800 return count;
1801}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001802
1803static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001804
James Ketrenosb095c382005-08-24 22:04:42 -05001805static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1806 char *buf)
1807{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001808 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001809 int pos = 0, len = 0;
1810 if (priv->config & CFG_SPEED_SCAN) {
1811 while (priv->speed_scan[pos] != 0)
1812 len += sprintf(&buf[len], "%d ",
1813 priv->speed_scan[pos++]);
1814 return len + sprintf(&buf[len], "\n");
1815 }
1816
1817 return sprintf(buf, "0\n");
1818}
1819
1820static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1821 const char *buf, size_t count)
1822{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001823 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001824 int channel, pos = 0;
1825 const char *p = buf;
1826
1827 /* list of space separated channels to scan, optionally ending with 0 */
1828 while ((channel = simple_strtol(p, NULL, 0))) {
1829 if (pos == MAX_SPEED_SCAN - 1) {
1830 priv->speed_scan[pos] = 0;
1831 break;
1832 }
1833
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001834 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001835 priv->speed_scan[pos++] = channel;
1836 else
1837 IPW_WARNING("Skipping invalid channel request: %d\n",
1838 channel);
1839 p = strchr(p, ' ');
1840 if (!p)
1841 break;
1842 while (*p == ' ' || *p == '\t')
1843 p++;
1844 }
1845
1846 if (pos == 0)
1847 priv->config &= ~CFG_SPEED_SCAN;
1848 else {
1849 priv->speed_scan_pos = 0;
1850 priv->config |= CFG_SPEED_SCAN;
1851 }
1852
1853 return count;
1854}
1855
1856static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1857 store_speed_scan);
1858
1859static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1860 char *buf)
1861{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001862 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001863 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1864}
1865
1866static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1867 const char *buf, size_t count)
1868{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001869 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001870 if (buf[0] == '1')
1871 priv->config |= CFG_NET_STATS;
1872 else
1873 priv->config &= ~CFG_NET_STATS;
1874
1875 return count;
1876}
1877
James Ketrenosafbf30a2005-08-25 00:05:33 -05001878static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1879 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001880
Zhu Yi375dd242007-02-14 16:04:24 +08001881static ssize_t show_channels(struct device *d,
1882 struct device_attribute *attr,
1883 char *buf)
1884{
1885 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001886 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001887 int len = 0, i;
1888
1889 len = sprintf(&buf[len],
1890 "Displaying %d channels in 2.4Ghz band "
1891 "(802.11bg):\n", geo->bg_channels);
1892
1893 for (i = 0; i < geo->bg_channels; i++) {
1894 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1895 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001896 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001897 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001898 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1899 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001900 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001901 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001902 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001903 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001904 "B" : "B/G");
1905 }
1906
1907 len += sprintf(&buf[len],
1908 "Displaying %d channels in 5.2Ghz band "
1909 "(802.11a):\n", geo->a_channels);
1910 for (i = 0; i < geo->a_channels; i++) {
1911 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1912 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001913 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001914 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001915 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1916 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001917 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001918 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001919 "passive only" : "active/passive");
1920 }
1921
1922 return len;
1923}
1924
1925static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1926
James Ketrenosea2b26e2005-08-24 21:25:16 -05001927static void notify_wx_assoc_event(struct ipw_priv *priv)
1928{
1929 union iwreq_data wrqu;
1930 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1931 if (priv->status & STATUS_ASSOCIATED)
1932 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1933 else
1934 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1935 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1936}
1937
James Ketrenos43f66a62005-03-25 12:31:53 -06001938static void ipw_irq_tasklet(struct ipw_priv *priv)
1939{
1940 u32 inta, inta_mask, handled = 0;
1941 unsigned long flags;
1942 int rc = 0;
1943
Zhu Yi89c318e2006-06-08 22:19:49 -07001944 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001945
James Ketrenosb095c382005-08-24 22:04:42 -05001946 inta = ipw_read32(priv, IPW_INTA_RW);
1947 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1948 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001949
1950 /* Add any cached INTA values that need to be handled */
1951 inta |= priv->isr_inta;
1952
Zhu Yi89c318e2006-06-08 22:19:49 -07001953 spin_unlock_irqrestore(&priv->irq_lock, flags);
1954
1955 spin_lock_irqsave(&priv->lock, flags);
1956
James Ketrenos43f66a62005-03-25 12:31:53 -06001957 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001958 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001959 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001960 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001961 }
1962
James Ketrenosb095c382005-08-24 22:04:42 -05001963 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001964 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001965 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001966 priv->status &= ~STATUS_HCMD_ACTIVE;
1967 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001968 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001969 }
1970
James Ketrenosb095c382005-08-24 22:04:42 -05001971 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001972 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001973 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001974 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001975 }
1976
James Ketrenosb095c382005-08-24 22:04:42 -05001977 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001978 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001979 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001980 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001981 }
1982
James Ketrenosb095c382005-08-24 22:04:42 -05001983 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001984 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001985 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001986 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001987 }
1988
James Ketrenosb095c382005-08-24 22:04:42 -05001989 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001990 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001991 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001992 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001993 }
1994
James Ketrenosb095c382005-08-24 22:04:42 -05001995 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001997 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001998 }
1999
James Ketrenosb095c382005-08-24 22:04:42 -05002000 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002002 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002003 }
2004
James Ketrenosb095c382005-08-24 22:04:42 -05002005 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002006 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002007 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
James Ketrenosb095c382005-08-24 22:04:42 -05002010 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002011 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002012 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002013 }
2014
James Ketrenosb095c382005-08-24 22:04:42 -05002015 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002017 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002018 }
2019
James Ketrenosb095c382005-08-24 22:04:42 -05002020 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2022 priv->status |= STATUS_RF_KILL_HW;
2023 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002024 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002025 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002026 cancel_delayed_work(&priv->request_direct_scan);
2027 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002028 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002029 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002030 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002031 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002033
James Ketrenosb095c382005-08-24 22:04:42 -05002034 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002035 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002036 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002037 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002038 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2039 struct ipw_fw_error *error =
2040 ipw_alloc_error_log(priv);
2041 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002042 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002043 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002044 } else {
2045 priv->error = ipw_alloc_error_log(priv);
2046 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002047 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002048 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002049 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2050 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002051 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2052 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002053 }
2054
James Ketrenosb095c382005-08-24 22:04:42 -05002055 /* XXX: If hardware encryption is for WPA/WPA2,
2056 * we have to notify the supplicant. */
2057 if (priv->ieee->sec.encrypt) {
2058 priv->status &= ~STATUS_ASSOCIATED;
2059 notify_wx_assoc_event(priv);
2060 }
2061
2062 /* Keep the restart process from trying to send host
2063 * commands by clearing the INIT status bit */
2064 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002065
2066 /* Cancel currently queued command. */
2067 priv->status &= ~STATUS_HCMD_ACTIVE;
2068 wake_up_interruptible(&priv->wait_command_queue);
2069
James Ketrenos43f66a62005-03-25 12:31:53 -06002070 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002071 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002072 }
2073
James Ketrenosb095c382005-08-24 22:04:42 -05002074 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002075 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002076 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002077 }
2078
2079 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002080 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002081 }
2082
Zhu Yi89c318e2006-06-08 22:19:49 -07002083 spin_unlock_irqrestore(&priv->lock, flags);
2084
James Ketrenos43f66a62005-03-25 12:31:53 -06002085 /* enable all interrupts */
2086 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002087}
Jeff Garzikbf794512005-07-31 13:07:26 -04002088
James Ketrenos43f66a62005-03-25 12:31:53 -06002089#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2090static char *get_cmd_string(u8 cmd)
2091{
2092 switch (cmd) {
2093 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002094 IPW_CMD(POWER_DOWN);
2095 IPW_CMD(SYSTEM_CONFIG);
2096 IPW_CMD(MULTICAST_ADDRESS);
2097 IPW_CMD(SSID);
2098 IPW_CMD(ADAPTER_ADDRESS);
2099 IPW_CMD(PORT_TYPE);
2100 IPW_CMD(RTS_THRESHOLD);
2101 IPW_CMD(FRAG_THRESHOLD);
2102 IPW_CMD(POWER_MODE);
2103 IPW_CMD(WEP_KEY);
2104 IPW_CMD(TGI_TX_KEY);
2105 IPW_CMD(SCAN_REQUEST);
2106 IPW_CMD(SCAN_REQUEST_EXT);
2107 IPW_CMD(ASSOCIATE);
2108 IPW_CMD(SUPPORTED_RATES);
2109 IPW_CMD(SCAN_ABORT);
2110 IPW_CMD(TX_FLUSH);
2111 IPW_CMD(QOS_PARAMETERS);
2112 IPW_CMD(DINO_CONFIG);
2113 IPW_CMD(RSN_CAPABILITIES);
2114 IPW_CMD(RX_KEY);
2115 IPW_CMD(CARD_DISABLE);
2116 IPW_CMD(SEED_NUMBER);
2117 IPW_CMD(TX_POWER);
2118 IPW_CMD(COUNTRY_INFO);
2119 IPW_CMD(AIRONET_INFO);
2120 IPW_CMD(AP_TX_POWER);
2121 IPW_CMD(CCKM_INFO);
2122 IPW_CMD(CCX_VER_INFO);
2123 IPW_CMD(SET_CALIBRATION);
2124 IPW_CMD(SENSITIVITY_CALIB);
2125 IPW_CMD(RETRY_LIMIT);
2126 IPW_CMD(IPW_PRE_POWER_DOWN);
2127 IPW_CMD(VAP_BEACON_TEMPLATE);
2128 IPW_CMD(VAP_DTIM_PERIOD);
2129 IPW_CMD(EXT_SUPPORTED_RATES);
2130 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2131 IPW_CMD(VAP_QUIET_INTERVALS);
2132 IPW_CMD(VAP_CHANNEL_SWITCH);
2133 IPW_CMD(VAP_MANDATORY_CHANNELS);
2134 IPW_CMD(VAP_CELL_PWR_LIMIT);
2135 IPW_CMD(VAP_CF_PARAM_SET);
2136 IPW_CMD(VAP_SET_BEACONING_STATE);
2137 IPW_CMD(MEASUREMENT);
2138 IPW_CMD(POWER_CAPABILITY);
2139 IPW_CMD(SUPPORTED_CHANNELS);
2140 IPW_CMD(TPC_REPORT);
2141 IPW_CMD(WME_INFO);
2142 IPW_CMD(PRODUCTION_COMMAND);
2143 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002144 return "UNKNOWN";
2145 }
2146}
James Ketrenos43f66a62005-03-25 12:31:53 -06002147
2148#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002149
2150static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002151{
2152 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002153 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002154
James Ketrenosa613bff2005-08-24 21:43:11 -05002155 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002156 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002157 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2158 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002159 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002160 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002161 }
2162
2163 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002164
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002165 if (priv->cmdlog) {
2166 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2167 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2168 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2169 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2170 cmd->len);
2171 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2172 }
2173
James Ketrenosb095c382005-08-24 22:04:42 -05002174 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2175 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2176 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002177
2178#ifndef DEBUG_CMD_WEP_KEY
2179 if (cmd->cmd == IPW_CMD_WEP_KEY)
2180 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2181 else
2182#endif
2183 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2184
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002185 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002186 if (rc) {
2187 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002188 IPW_ERROR("Failed to send %s: Reason %d\n",
2189 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002190 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002191 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002192 }
2193 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002194
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002195 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2196 !(priv->
2197 status & STATUS_HCMD_ACTIVE),
2198 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002199 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002200 spin_lock_irqsave(&priv->lock, flags);
2201 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002202 IPW_ERROR("Failed to send %s: Command timed out.\n",
2203 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002204 priv->status &= ~STATUS_HCMD_ACTIVE;
2205 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002206 rc = -EIO;
2207 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002208 }
2209 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002210 } else
2211 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002212
James Ketrenosb095c382005-08-24 22:04:42 -05002213 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002214 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2215 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002216 rc = -EIO;
2217 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002218 }
2219
Zhu Yi2638bc32006-01-24 16:37:52 +08002220 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002221 if (priv->cmdlog) {
2222 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2223 priv->cmdlog_pos %= priv->cmdlog_len;
2224 }
2225 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002226}
2227
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002228static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002229{
2230 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002231 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002232 };
2233
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002234 return __ipw_send_cmd(priv, &cmd);
2235}
2236
2237static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2238 void *data)
2239{
2240 struct host_cmd cmd = {
2241 .cmd = command,
2242 .len = len,
2243 .param = data,
2244 };
2245
2246 return __ipw_send_cmd(priv, &cmd);
2247}
2248
2249static int ipw_send_host_complete(struct ipw_priv *priv)
2250{
James Ketrenos43f66a62005-03-25 12:31:53 -06002251 if (!priv) {
2252 IPW_ERROR("Invalid args\n");
2253 return -1;
2254 }
2255
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002256 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002257}
2258
Zhu Yid685b8c2006-04-13 17:20:27 +08002259static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002260{
Zhu Yid685b8c2006-04-13 17:20:27 +08002261 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2262 sizeof(priv->sys_config),
2263 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002264}
2265
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002266static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002267{
James Ketrenos43f66a62005-03-25 12:31:53 -06002268 if (!priv || !ssid) {
2269 IPW_ERROR("Invalid args\n");
2270 return -1;
2271 }
2272
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002273 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002274 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002275}
2276
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002277static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002278{
James Ketrenos43f66a62005-03-25 12:31:53 -06002279 if (!priv || !mac) {
2280 IPW_ERROR("Invalid args\n");
2281 return -1;
2282 }
2283
Johannes Berge1749612008-10-27 15:59:26 -07002284 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2285 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002286
Zhu Yi2638bc32006-01-24 16:37:52 +08002287 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002288}
2289
James Ketrenosa613bff2005-08-24 21:43:11 -05002290/*
2291 * NOTE: This must be executed from our workqueue as it results in udelay
2292 * being called which may corrupt the keyboard if executed on default
2293 * workqueue
2294 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002295static void ipw_adapter_restart(void *adapter)
2296{
2297 struct ipw_priv *priv = adapter;
2298
2299 if (priv->status & STATUS_RF_KILL_MASK)
2300 return;
2301
2302 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002303
2304 if (priv->assoc_network &&
2305 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2306 ipw_remove_current_network(priv);
2307
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 if (ipw_up(priv)) {
2309 IPW_ERROR("Failed to up device\n");
2310 return;
2311 }
2312}
2313
David Howellsc4028952006-11-22 14:57:56 +00002314static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002315{
David Howellsc4028952006-11-22 14:57:56 +00002316 struct ipw_priv *priv =
2317 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002318 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002319 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002320 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002321}
2322
James Ketrenos43f66a62005-03-25 12:31:53 -06002323#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2324
2325static void ipw_scan_check(void *data)
2326{
2327 struct ipw_priv *priv = data;
2328 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2329 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002330 "adapter after (%dms).\n",
2331 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002332 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002333 }
2334}
2335
David Howellsc4028952006-11-22 14:57:56 +00002336static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002337{
David Howellsc4028952006-11-22 14:57:56 +00002338 struct ipw_priv *priv =
2339 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002340 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002341 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002342 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002343}
2344
James Ketrenos43f66a62005-03-25 12:31:53 -06002345static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2346 struct ipw_scan_request_ext *request)
2347{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002348 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002349 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002350}
2351
2352static int ipw_send_scan_abort(struct ipw_priv *priv)
2353{
James Ketrenos43f66a62005-03-25 12:31:53 -06002354 if (!priv) {
2355 IPW_ERROR("Invalid args\n");
2356 return -1;
2357 }
2358
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002359 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002360}
2361
2362static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2363{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002364 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002365 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002366 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002367
2368 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002369 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002370}
2371
2372static int ipw_send_associate(struct ipw_priv *priv,
2373 struct ipw_associate *associate)
2374{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002375 if (!priv || !associate) {
2376 IPW_ERROR("Invalid args\n");
2377 return -1;
2378 }
2379
Al Viro5b5e8072007-12-27 01:54:06 -05002380 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2381 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002382}
2383
2384static int ipw_send_supported_rates(struct ipw_priv *priv,
2385 struct ipw_supported_rates *rates)
2386{
James Ketrenos43f66a62005-03-25 12:31:53 -06002387 if (!priv || !rates) {
2388 IPW_ERROR("Invalid args\n");
2389 return -1;
2390 }
2391
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002392 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002393 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002394}
2395
2396static int ipw_set_random_seed(struct ipw_priv *priv)
2397{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002398 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002399
2400 if (!priv) {
2401 IPW_ERROR("Invalid args\n");
2402 return -1;
2403 }
2404
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002405 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002406
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002407 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002408}
2409
James Ketrenos43f66a62005-03-25 12:31:53 -06002410static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2411{
Al Viroe62e1ee2007-12-27 01:36:46 -05002412 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002413 if (!priv) {
2414 IPW_ERROR("Invalid args\n");
2415 return -1;
2416 }
2417
Al Viroe62e1ee2007-12-27 01:36:46 -05002418 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002419}
James Ketrenos43f66a62005-03-25 12:31:53 -06002420
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002421static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002422{
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 if (!priv || !power) {
2424 IPW_ERROR("Invalid args\n");
2425 return -1;
2426 }
2427
Zhu Yi2638bc32006-01-24 16:37:52 +08002428 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002429}
James Ketrenos43f66a62005-03-25 12:31:53 -06002430
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002431static int ipw_set_tx_power(struct ipw_priv *priv)
2432{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002433 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002434 struct ipw_tx_power tx_power;
2435 s8 max_power;
2436 int i;
2437
2438 memset(&tx_power, 0, sizeof(tx_power));
2439
2440 /* configure device for 'G' band */
2441 tx_power.ieee_mode = IPW_G_MODE;
2442 tx_power.num_channels = geo->bg_channels;
2443 for (i = 0; i < geo->bg_channels; i++) {
2444 max_power = geo->bg[i].max_power;
2445 tx_power.channels_tx_power[i].channel_number =
2446 geo->bg[i].channel;
2447 tx_power.channels_tx_power[i].tx_power = max_power ?
2448 min(max_power, priv->tx_power) : priv->tx_power;
2449 }
2450 if (ipw_send_tx_power(priv, &tx_power))
2451 return -EIO;
2452
2453 /* configure device to also handle 'B' band */
2454 tx_power.ieee_mode = IPW_B_MODE;
2455 if (ipw_send_tx_power(priv, &tx_power))
2456 return -EIO;
2457
2458 /* configure device to also handle 'A' band */
2459 if (priv->ieee->abg_true) {
2460 tx_power.ieee_mode = IPW_A_MODE;
2461 tx_power.num_channels = geo->a_channels;
2462 for (i = 0; i < tx_power.num_channels; i++) {
2463 max_power = geo->a[i].max_power;
2464 tx_power.channels_tx_power[i].channel_number =
2465 geo->a[i].channel;
2466 tx_power.channels_tx_power[i].tx_power = max_power ?
2467 min(max_power, priv->tx_power) : priv->tx_power;
2468 }
2469 if (ipw_send_tx_power(priv, &tx_power))
2470 return -EIO;
2471 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002472 return 0;
2473}
2474
2475static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2476{
2477 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002478 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002479 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002480
2481 if (!priv) {
2482 IPW_ERROR("Invalid args\n");
2483 return -1;
2484 }
2485
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002486 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2487 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002488}
2489
2490static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2491{
2492 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002493 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002494 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002495
2496 if (!priv) {
2497 IPW_ERROR("Invalid args\n");
2498 return -1;
2499 }
2500
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002501 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2502 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002503}
2504
2505static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2506{
Al Viroe62e1ee2007-12-27 01:36:46 -05002507 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002508
2509 if (!priv) {
2510 IPW_ERROR("Invalid args\n");
2511 return -1;
2512 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002513
James Ketrenos43f66a62005-03-25 12:31:53 -06002514 /* If on battery, set to 3, if AC set to CAM, else user
2515 * level */
2516 switch (mode) {
2517 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002518 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002519 break;
2520 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002521 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522 break;
2523 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002524 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002525 break;
2526 }
2527
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002528 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002529 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530}
2531
James Ketrenosafbf30a2005-08-25 00:05:33 -05002532static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2533{
2534 struct ipw_retry_limit retry_limit = {
2535 .short_retry_limit = slimit,
2536 .long_retry_limit = llimit
2537 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002538
2539 if (!priv) {
2540 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002541 return -1;
2542 }
2543
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002544 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002545 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002546}
2547
2548/*
2549 * The IPW device contains a Microwire compatible EEPROM that stores
2550 * various data like the MAC address. Usually the firmware has exclusive
2551 * access to the eeprom, but during device initialization (before the
2552 * device driver has sent the HostComplete command to the firmware) the
2553 * device driver has read access to the EEPROM by way of indirect addressing
2554 * through a couple of memory mapped registers.
2555 *
2556 * The following is a simplified implementation for pulling data out of the
2557 * the eeprom, along with some helper functions to find information in
2558 * the per device private data's copy of the eeprom.
2559 *
2560 * NOTE: To better understand how these functions work (i.e what is a chip
2561 * select and why do have to keep driving the eeprom clock?), read
2562 * just about any data sheet for a Microwire compatible EEPROM.
2563 */
2564
2565/* write a 32 bit value into the indirect accessor register */
2566static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2567{
2568 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002569
James Ketrenos43f66a62005-03-25 12:31:53 -06002570 /* the eeprom requires some time to complete the operation */
2571 udelay(p->eeprom_delay);
2572
2573 return;
2574}
2575
2576/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002577static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002578{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002579 eeprom_write_reg(priv, 0);
2580 eeprom_write_reg(priv, EEPROM_BIT_CS);
2581 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2582 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002583}
2584
2585/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002586static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002587{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002588 eeprom_write_reg(priv, EEPROM_BIT_CS);
2589 eeprom_write_reg(priv, 0);
2590 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002591}
2592
2593/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002594static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002595{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002596 int d = (bit ? EEPROM_BIT_DI : 0);
2597 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2598 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002599}
2600
2601/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002602static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002603{
2604 int i;
2605
2606 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002607 eeprom_write_bit(priv, 1);
2608 eeprom_write_bit(priv, op & 2);
2609 eeprom_write_bit(priv, op & 1);
2610 for (i = 7; i >= 0; i--) {
2611 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002612 }
2613}
2614
2615/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002616static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002617{
2618 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002619 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002620
James Ketrenos43f66a62005-03-25 12:31:53 -06002621 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002622 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002623
2624 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002626
2627 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002628 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002629 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2631 eeprom_write_reg(priv, EEPROM_BIT_CS);
2632 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2633 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002634 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002635
James Ketrenos43f66a62005-03-25 12:31:53 -06002636 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002637 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002638 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002639
James Ketrenos43f66a62005-03-25 12:31:53 -06002640 return r;
2641}
2642
2643/* helper function for pulling the mac address out of the private */
2644/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002645static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002646{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002647 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002648}
2649
2650/*
2651 * Either the device driver (i.e. the host) or the firmware can
2652 * load eeprom data into the designated region in SRAM. If neither
2653 * happens then the FW will shutdown with a fatal error.
2654 *
2655 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2656 * bit needs region of shared SRAM needs to be non-zero.
2657 */
2658static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2659{
2660 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002661 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002662
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 IPW_DEBUG_TRACE(">>\n");
2664
2665 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002666 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002667 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002668
Jeff Garzikbf794512005-07-31 13:07:26 -04002669 /*
2670 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002672 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002673 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002674 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002675 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2676
2677 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002678 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002679 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002680
2681 /* Do not load eeprom data on fatal error or suspend */
2682 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2683 } else {
2684 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2685
2686 /* Load eeprom data on fatal error or suspend */
2687 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2688 }
2689
2690 IPW_DEBUG_TRACE("<<\n");
2691}
2692
Arjan van de Ven858119e2006-01-14 13:20:43 -08002693static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002694{
2695 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002696 if (!count)
2697 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002698 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002699 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002700 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002701}
2702
2703static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2704{
James Ketrenosb095c382005-08-24 22:04:42 -05002705 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002706 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002707 sizeof(struct command_block));
2708}
2709
2710static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002711{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002712
2713 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002714
James Ketrenos43f66a62005-03-25 12:31:53 -06002715 /* Start the dma */
2716 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002717
James Ketrenos43f66a62005-03-25 12:31:53 -06002718 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002719 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002720
2721 IPW_DEBUG_FW("<< : \n");
2722 return 0;
2723}
2724
2725static void ipw_fw_dma_abort(struct ipw_priv *priv)
2726{
2727 u32 control = 0;
2728
2729 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002730
Pavel Machek67fd6b42006-07-11 15:34:05 +02002731 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002732 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002733 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002734 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002735
James Ketrenos43f66a62005-03-25 12:31:53 -06002736 IPW_DEBUG_FW("<< \n");
2737}
2738
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2740 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002741{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002742 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002743 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002744 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002745 IPW_DEBUG_FW(">> :\n");
2746
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002747 ipw_write_indirect(priv, address, (u8 *) cb,
2748 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
2750 IPW_DEBUG_FW("<< :\n");
2751 return 0;
2752
2753}
2754
2755static int ipw_fw_dma_kick(struct ipw_priv *priv)
2756{
2757 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002758 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002759
2760 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002761
James Ketrenos43f66a62005-03-25 12:31:53 -06002762 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002763 ipw_fw_dma_write_command_block(priv, index,
2764 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002765
2766 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002767 ipw_clear_bit(priv, IPW_RESET_REG,
2768 IPW_RESET_REG_MASTER_DISABLED |
2769 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002770
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002771 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002772 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002773 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002774
2775 IPW_DEBUG_FW("<< :\n");
2776 return 0;
2777}
2778
2779static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2780{
2781 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002782 u32 register_value = 0;
2783 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002784
2785 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002786 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002787 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002788
2789 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002790 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2791 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002792
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002793 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002794 cb_fields_address = address;
2795 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002796 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002797
2798 cb_fields_address += sizeof(u32);
2799 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002801
2802 cb_fields_address += sizeof(u32);
2803 register_value = ipw_read_reg32(priv, cb_fields_address);
2804 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2805 register_value);
2806
2807 cb_fields_address += sizeof(u32);
2808 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002809 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002810
2811 IPW_DEBUG_FW(">> :\n");
2812}
2813
2814static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2815{
2816 u32 current_cb_address = 0;
2817 u32 current_cb_index = 0;
2818
2819 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002820 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002821
James Ketrenosb095c382005-08-24 22:04:42 -05002822 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002823 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002824
James Ketrenos43f66a62005-03-25 12:31:53 -06002825 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002826 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002827
2828 IPW_DEBUG_FW(">> :\n");
2829 return current_cb_index;
2830
2831}
2832
2833static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2834 u32 src_address,
2835 u32 dest_address,
2836 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002837 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002838{
2839
Jeff Garzikbf794512005-07-31 13:07:26 -04002840 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002841 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2842 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002843 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002844 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002845
2846 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2847 src_address, dest_address, length);
2848
2849 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2850 return -1;
2851
2852 last_cb_element = priv->sram_desc.last_cb_index;
2853 cb = &priv->sram_desc.cb_list[last_cb_element];
2854 priv->sram_desc.last_cb_index++;
2855
2856 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002857 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002858 control |= CB_INT_ENABLED;
2859
2860 if (is_last)
2861 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002862
James Ketrenos43f66a62005-03-25 12:31:53 -06002863 control |= length;
2864
2865 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002866 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002867
2868 /* Copy the Source and Destination addresses */
2869 cb->dest_addr = dest_address;
2870 cb->source_addr = src_address;
2871
2872 /* Copy the Control Word last */
2873 cb->control = control;
2874
2875 return 0;
2876}
2877
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002878static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2879 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002880{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002881 int ret, i;
2882 u32 size;
2883
James Ketrenos43f66a62005-03-25 12:31:53 -06002884 IPW_DEBUG_FW(">> \n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002885 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2886 nr, dest_address, len);
2887
2888 for (i = 0; i < nr; i++) {
2889 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2890 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2891 dest_address +
2892 i * CB_MAX_LENGTH, size,
2893 0, 0);
2894 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002895 IPW_DEBUG_FW_INFO(": Failed\n");
2896 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002897 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002898 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002899 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002900
James Ketrenos43f66a62005-03-25 12:31:53 -06002901 IPW_DEBUG_FW("<< \n");
2902 return 0;
2903}
2904
2905static int ipw_fw_dma_wait(struct ipw_priv *priv)
2906{
Zhu Yi397ae122006-01-24 16:37:22 +08002907 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002908 u32 watchdog = 0;
2909
2910 IPW_DEBUG_FW(">> : \n");
2911
2912 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002913 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002914 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002915
2916 while (current_index < priv->sram_desc.last_cb_index) {
2917 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002918 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002919 current_index = ipw_fw_dma_command_block_index(priv);
2920
Zhu Yi397ae122006-01-24 16:37:22 +08002921 if (previous_index < current_index) {
2922 watchdog = 0;
2923 continue;
2924 }
2925 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002926 IPW_DEBUG_FW_INFO("Timeout\n");
2927 ipw_fw_dma_dump_command_block(priv);
2928 ipw_fw_dma_abort(priv);
2929 return -1;
2930 }
2931 }
2932
2933 ipw_fw_dma_abort(priv);
2934
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002935 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002936 ipw_set_bit(priv, IPW_RESET_REG,
2937 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002938
2939 IPW_DEBUG_FW("<< dmaWaitSync \n");
2940 return 0;
2941}
2942
Jeff Garzikbf794512005-07-31 13:07:26 -04002943static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002944{
2945 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002946 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002947 unsigned long flags;
2948
2949 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002950 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002951 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002952 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2953 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002954 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002955 &priv->ieee->network_free_list);
2956 }
2957 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002958 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002959}
2960
2961/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002962 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002963 * Reads debug register from domain0.
2964 * If card is present, pre-defined value should
2965 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002966 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002967 * @param priv
2968 * @return 1 if card is present, 0 otherwise
2969 */
2970static inline int ipw_alive(struct ipw_priv *priv)
2971{
2972 return ipw_read32(priv, 0x90) == 0xd55555d5;
2973}
2974
Zhu Yic7b6a672006-01-24 16:37:05 +08002975/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002976static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002977 int timeout)
2978{
2979 int i = 0;
2980
2981 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002982 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002983 return i;
2984 mdelay(10);
2985 i += 10;
2986 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002987
James Ketrenos43f66a62005-03-25 12:31:53 -06002988 return -ETIME;
2989}
2990
Jeff Garzikbf794512005-07-31 13:07:26 -04002991/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002992 * the ipw hardware. It assumes the buffer has all the bits for the
2993 * image and the caller is handling the memory allocation and clean up.
2994 */
2995
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002996static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002997{
2998 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002999
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 IPW_DEBUG_TRACE(">> \n");
3001 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003002 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003003
Zhu Yic7b6a672006-01-24 16:37:05 +08003004 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003005 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3006 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003007 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003008 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 return -1;
3010 }
3011
3012 IPW_DEBUG_INFO("stop master %dms\n", rc);
3013
3014 return rc;
3015}
3016
3017static void ipw_arc_release(struct ipw_priv *priv)
3018{
3019 IPW_DEBUG_TRACE(">> \n");
3020 mdelay(5);
3021
James Ketrenosb095c382005-08-24 22:04:42 -05003022 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003023
3024 /* no one knows timing, for safety add some delay */
3025 mdelay(5);
3026}
3027
James Ketrenos43f66a62005-03-25 12:31:53 -06003028struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003029 __le32 address;
3030 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003031};
3032
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003033static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003034{
3035 int rc = 0, i, addr;
3036 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003037 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003038
Al Viroe62e1ee2007-12-27 01:36:46 -05003039 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003040
James Ketrenos43f66a62005-03-25 12:31:53 -06003041 IPW_DEBUG_TRACE(">> \n");
3042
3043 rc = ipw_stop_master(priv);
3044
3045 if (rc < 0)
3046 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003047
James Ketrenosb095c382005-08-24 22:04:42 -05003048 for (addr = IPW_SHARED_LOWER_BOUND;
3049 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003050 ipw_write32(priv, addr, 0);
3051 }
3052
3053 /* no ucode (yet) */
3054 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3055 /* destroy DMA queues */
3056 /* reset sequence */
3057
James Ketrenosb095c382005-08-24 22:04:42 -05003058 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003059 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003060 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003061 mdelay(1);
3062
3063 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003064 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003065 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003066
James Ketrenosb095c382005-08-24 22:04:42 -05003067 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003068 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003069
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003071 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3072 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003073 mdelay(1);
3074
3075 /* write ucode */
3076 /**
3077 * @bug
3078 * Do NOT set indirect address register once and then
3079 * store data to indirect data register in the loop.
3080 * It seems very reasonable, but in this case DINO do not
3081 * accept ucode. It is essential to set address each time.
3082 */
3083 /* load new ipw uCode */
3084 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003085 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003086 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003087
James Ketrenos43f66a62005-03-25 12:31:53 -06003088 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003089 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3090 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003091
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003092 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003093
3094 /* wait for alive response */
3095 for (i = 0; i < 100; i++) {
3096 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003097 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 if (cr & DINO_RXFIFO_DATA)
3099 break;
3100 mdelay(1);
3101 }
3102
3103 if (cr & DINO_RXFIFO_DATA) {
3104 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003105 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003106
3107 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003108 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003109 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003110 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003111 memcpy(&priv->dino_alive, response_buffer,
3112 sizeof(priv->dino_alive));
3113 if (priv->dino_alive.alive_command == 1
3114 && priv->dino_alive.ucode_valid == 1) {
3115 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003116 IPW_DEBUG_INFO
3117 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3118 "of %02d/%02d/%02d %02d:%02d\n",
3119 priv->dino_alive.software_revision,
3120 priv->dino_alive.software_revision,
3121 priv->dino_alive.device_identifier,
3122 priv->dino_alive.device_identifier,
3123 priv->dino_alive.time_stamp[0],
3124 priv->dino_alive.time_stamp[1],
3125 priv->dino_alive.time_stamp[2],
3126 priv->dino_alive.time_stamp[3],
3127 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003128 } else {
3129 IPW_DEBUG_INFO("Microcode is not alive\n");
3130 rc = -EINVAL;
3131 }
3132 } else {
3133 IPW_DEBUG_INFO("No alive response from DINO\n");
3134 rc = -ETIME;
3135 }
3136
3137 /* disable DINO, otherwise for some reason
3138 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003139 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003140
James Ketrenos43f66a62005-03-25 12:31:53 -06003141 return rc;
3142}
3143
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003144static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003145{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003146 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003147 int offset = 0;
3148 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003149 int total_nr = 0;
3150 int i;
3151 struct pci_pool *pool;
3152 u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL];
3153 dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL];
James Ketrenos43f66a62005-03-25 12:31:53 -06003154
3155 IPW_DEBUG_TRACE("<< : \n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003156
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003157 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3158 if (!pool) {
3159 IPW_ERROR("pci_pool_create failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003160 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003161 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003162
3163 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003164 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003165
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003166 /* the DMA is already ready this would be a bug. */
3167 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003168
3169 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003170 u32 chunk_len;
3171 u8 *start;
3172 int size;
3173 int nr = 0;
3174
James Ketrenos43f66a62005-03-25 12:31:53 -06003175 chunk = (struct fw_chunk *)(data + offset);
3176 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003177 chunk_len = le32_to_cpu(chunk->length);
3178 start = data + offset;
3179
3180 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3181 for (i = 0; i < nr; i++) {
3182 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3183 &phys[total_nr]);
3184 if (!virts[total_nr]) {
3185 ret = -ENOMEM;
3186 goto out;
3187 }
3188 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3189 CB_MAX_LENGTH);
3190 memcpy(virts[total_nr], start, size);
3191 start += size;
3192 total_nr++;
3193 /* We don't support fw chunk larger than 64*8K */
3194 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3195 }
3196
James Ketrenos43f66a62005-03-25 12:31:53 -06003197 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003198 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003199 * offeset*/
3200 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003201 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3202 nr, le32_to_cpu(chunk->address),
3203 chunk_len);
3204 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003205 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3206 goto out;
3207 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003208
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003209 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003210 } while (offset < len);
3211
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003212 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003213 ret = ipw_fw_dma_kick(priv);
3214 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003215 IPW_ERROR("dmaKick Failed\n");
3216 goto out;
3217 }
3218
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003219 ret = ipw_fw_dma_wait(priv);
3220 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003221 IPW_ERROR("dmaWaitSync Failed\n");
3222 goto out;
3223 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003224 out:
3225 for (i = 0; i < total_nr; i++)
3226 pci_pool_free(pool, virts[i], phys[i]);
3227
3228 pci_pool_destroy(pool);
3229
3230 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003231}
3232
3233/* stop nic */
3234static int ipw_stop_nic(struct ipw_priv *priv)
3235{
3236 int rc = 0;
3237
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003238 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003239 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003240
James Ketrenosb095c382005-08-24 22:04:42 -05003241 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3242 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003243 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003244 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003245 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003246 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003247
James Ketrenosb095c382005-08-24 22:04:42 -05003248 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003249
James Ketrenos43f66a62005-03-25 12:31:53 -06003250 return rc;
3251}
3252
3253static void ipw_start_nic(struct ipw_priv *priv)
3254{
3255 IPW_DEBUG_TRACE(">>\n");
3256
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003257 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003258 ipw_clear_bit(priv, IPW_RESET_REG,
3259 IPW_RESET_REG_MASTER_DISABLED |
3260 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003261 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003262
James Ketrenos43f66a62005-03-25 12:31:53 -06003263 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003264 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3265 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003266
3267 IPW_DEBUG_TRACE("<<\n");
3268}
Jeff Garzikbf794512005-07-31 13:07:26 -04003269
James Ketrenos43f66a62005-03-25 12:31:53 -06003270static int ipw_init_nic(struct ipw_priv *priv)
3271{
3272 int rc;
3273
3274 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003275 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003276 /*prvHwInitNic */
3277 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003278 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003279
3280 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003281 ipw_write32(priv, IPW_READ_INT_REGISTER,
3282 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003283
3284 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003285 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3286 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003287 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003288 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3289
3290 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003291 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003292
3293 udelay(10);
3294
3295 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003296 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003297
3298 IPW_DEBUG_TRACE(">>\n");
3299 return 0;
3300}
3301
Jeff Garzikbf794512005-07-31 13:07:26 -04003302/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003303 * Probe is an ok place to call this from.
3304 */
3305static int ipw_reset_nic(struct ipw_priv *priv)
3306{
3307 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003308 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003309
3310 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003311
James Ketrenos43f66a62005-03-25 12:31:53 -06003312 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003313
James Ketrenosa613bff2005-08-24 21:43:11 -05003314 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003315 /* Clear the 'host command active' bit... */
3316 priv->status &= ~STATUS_HCMD_ACTIVE;
3317 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003318 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3319 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003320 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003321
3322 IPW_DEBUG_TRACE("<<\n");
3323 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003324}
James Ketrenos43f66a62005-03-25 12:31:53 -06003325
James Ketrenos9006ea72006-03-08 03:22:28 +08003326
3327struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003328 __le32 ver;
3329 __le32 boot_size;
3330 __le32 ucode_size;
3331 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003332 u8 data[0];
3333};
3334
Jeff Garzikbf794512005-07-31 13:07:26 -04003335static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003336 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003337{
James Ketrenos9006ea72006-03-08 03:22:28 +08003338 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003339 int rc;
3340
3341 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003342 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003343 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003344 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003345 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003346 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003347
James Ketrenos9006ea72006-03-08 03:22:28 +08003348 if ((*raw)->size < sizeof(*fw)) {
3349 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003350 return -EINVAL;
3351 }
3352
James Ketrenos9006ea72006-03-08 03:22:28 +08003353 fw = (void *)(*raw)->data;
3354
Zhu Yi0070f8c2006-04-13 17:20:12 +08003355 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3356 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003357 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3358 name, (*raw)->size);
3359 return -EINVAL;
3360 }
3361
3362 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003363 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003364 le32_to_cpu(fw->ver) >> 16,
3365 le32_to_cpu(fw->ver) & 0xff,
3366 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003367 return 0;
3368}
3369
James Ketrenosb095c382005-08-24 22:04:42 -05003370#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003371
Arjan van de Ven858119e2006-01-14 13:20:43 -08003372static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003373 struct ipw_rx_queue *rxq)
3374{
3375 unsigned long flags;
3376 int i;
3377
3378 spin_lock_irqsave(&rxq->lock, flags);
3379
3380 INIT_LIST_HEAD(&rxq->rx_free);
3381 INIT_LIST_HEAD(&rxq->rx_used);
3382
3383 /* Fill the rx_used queue with _all_ of the Rx buffers */
3384 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3385 /* In the reset function, these buffers may have been allocated
3386 * to an SKB, so we need to unmap and free potential storage */
3387 if (rxq->pool[i].skb != NULL) {
3388 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003389 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003390 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003391 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003392 }
3393 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3394 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003395
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 /* Set us so that we have processed and used all buffers, but have
3397 * not restocked the Rx queue with fresh buffers */
3398 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003399 rxq->free_count = 0;
3400 spin_unlock_irqrestore(&rxq->lock, flags);
3401}
3402
3403#ifdef CONFIG_PM
3404static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003405static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003406
3407static void free_firmware(void)
3408{
3409 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003410 release_firmware(raw);
3411 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003412 fw_loaded = 0;
3413 }
3414}
3415#else
3416#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003417#endif
3418
3419static int ipw_load(struct ipw_priv *priv)
3420{
3421#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003422 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003423#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003424 struct ipw_fw *fw;
3425 u8 *boot_img, *ucode_img, *fw_img;
3426 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003427 int rc = 0, retries = 3;
3428
Zhu Yi397ae122006-01-24 16:37:22 +08003429 switch (priv->ieee->iw_mode) {
3430 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003431 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003432 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003433#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003434 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003435 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003436 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003437#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003438 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003439 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003440 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003441 }
Zhu Yi397ae122006-01-24 16:37:22 +08003442
James Ketrenos9006ea72006-03-08 03:22:28 +08003443 if (!name) {
3444 rc = -EINVAL;
3445 goto error;
3446 }
3447
3448#ifdef CONFIG_PM
3449 if (!fw_loaded) {
3450#endif
3451 rc = ipw_get_fw(priv, &raw, name);
3452 if (rc < 0)
3453 goto error;
3454#ifdef CONFIG_PM
3455 }
3456#endif
3457
3458 fw = (void *)raw->data;
3459 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003460 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3461 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3462 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003463
Zhu Yi397ae122006-01-24 16:37:22 +08003464 if (rc < 0)
3465 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003466
3467 if (!priv->rxq)
3468 priv->rxq = ipw_rx_queue_alloc(priv);
3469 else
3470 ipw_rx_queue_reset(priv, priv->rxq);
3471 if (!priv->rxq) {
3472 IPW_ERROR("Unable to initialize Rx queue\n");
3473 goto error;
3474 }
3475
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003476 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003477 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003478 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003479 priv->status &= ~STATUS_INT_ENABLED;
3480
3481 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003482 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003483
James Ketrenos43f66a62005-03-25 12:31:53 -06003484 ipw_stop_nic(priv);
3485
3486 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003487 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003488 IPW_ERROR("Unable to reset NIC\n");
3489 goto error;
3490 }
3491
James Ketrenosb095c382005-08-24 22:04:42 -05003492 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3493 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003494
3495 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003496 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003497 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003498 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003499 goto error;
3500 }
3501
3502 /* kick start the device */
3503 ipw_start_nic(priv);
3504
Zhu Yic7b6a672006-01-24 16:37:05 +08003505 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003506 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3507 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003508 if (rc < 0) {
3509 IPW_ERROR("device failed to boot initial fw image\n");
3510 goto error;
3511 }
3512 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3513
Jeff Garzikbf794512005-07-31 13:07:26 -04003514 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003515 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003516
3517 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003518 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003519 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003520 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003521 goto error;
3522 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003523
James Ketrenos43f66a62005-03-25 12:31:53 -06003524 /* stop nic */
3525 ipw_stop_nic(priv);
3526
3527 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003528 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003529 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003530 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003531 goto error;
3532 }
Zhu Yi397ae122006-01-24 16:37:22 +08003533#ifdef CONFIG_PM
3534 fw_loaded = 1;
3535#endif
3536
James Ketrenos43f66a62005-03-25 12:31:53 -06003537 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3538
3539 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003540 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003541 IPW_ERROR("Unable to initialize queues\n");
3542 goto error;
3543 }
3544
3545 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003546 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003547 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003548 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003549
James Ketrenos43f66a62005-03-25 12:31:53 -06003550 /* kick start the device */
3551 ipw_start_nic(priv);
3552
James Ketrenosb095c382005-08-24 22:04:42 -05003553 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003554 if (retries > 0) {
3555 IPW_WARNING("Parity error. Retrying init.\n");
3556 retries--;
3557 goto retry;
3558 }
3559
3560 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3561 rc = -EIO;
3562 goto error;
3563 }
3564
3565 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003566 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3567 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003569 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003570 goto error;
3571 }
3572 IPW_DEBUG_INFO("device response after %dms\n", rc);
3573
3574 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003575 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003576
3577 /* read eeprom data and initialize the eeprom region of sram */
3578 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003579 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003580
3581 /* enable interrupts */
3582 ipw_enable_interrupts(priv);
3583
3584 /* Ensure our queue has valid packets */
3585 ipw_rx_queue_replenish(priv);
3586
James Ketrenosb095c382005-08-24 22:04:42 -05003587 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003588
3589 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003590 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003591
3592#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003593 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003594#endif
3595 return 0;
3596
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003597 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003598 if (priv->rxq) {
3599 ipw_rx_queue_free(priv, priv->rxq);
3600 priv->rxq = NULL;
3601 }
3602 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003603 if (raw)
3604 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003605#ifdef CONFIG_PM
3606 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003607 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003608#endif
3609
3610 return rc;
3611}
3612
Jeff Garzikbf794512005-07-31 13:07:26 -04003613/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003614 * DMA services
3615 *
3616 * Theory of operation
3617 *
3618 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3619 * 2 empty entries always kept in the buffer to protect from overflow.
3620 *
3621 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003622 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3623 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003624 * Tx queue resumed.
3625 *
3626 * The IPW operates with six queues, one receive queue in the device's
3627 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003628 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003629 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003630 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003631 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003632 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003633 * we only utilize the first data transmit queue (queue1).
3634 */
3635
3636/**
3637 * Driver allocates buffers of this size for Rx
3638 */
3639
Dan Williams943dbef2008-02-14 17:49:41 -05003640/**
3641 * ipw_rx_queue_space - Return number of free slots available in queue.
3642 */
3643static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3644{
3645 int s = q->read - q->write;
3646 if (s <= 0)
3647 s += RX_QUEUE_SIZE;
3648 /* keep some buffer to not confuse full and empty queue */
3649 s -= 2;
3650 if (s < 0)
3651 s = 0;
3652 return s;
3653}
3654
3655static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003656{
3657 int s = q->last_used - q->first_empty;
3658 if (s <= 0)
3659 s += q->n_bd;
3660 s -= 2; /* keep some reserve to not confuse empty and full situations */
3661 if (s < 0)
3662 s = 0;
3663 return s;
3664}
3665
3666static inline int ipw_queue_inc_wrap(int index, int n_bd)
3667{
3668 return (++index == n_bd) ? 0 : index;
3669}
3670
3671/**
3672 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003673 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003674 * @param q queue to init
3675 * @param count Number of BD's to allocate. Should be power of 2
3676 * @param read_register Address for 'read' register
3677 * (not offset within BAR, full address)
3678 * @param write_register Address for 'write' register
3679 * (not offset within BAR, full address)
3680 * @param base_register Address for 'base' register
3681 * (not offset within BAR, full address)
3682 * @param size Address for 'size' register
3683 * (not offset within BAR, full address)
3684 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003685static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003686 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003687{
3688 q->n_bd = count;
3689
3690 q->low_mark = q->n_bd / 4;
3691 if (q->low_mark < 4)
3692 q->low_mark = 4;
3693
3694 q->high_mark = q->n_bd / 8;
3695 if (q->high_mark < 2)
3696 q->high_mark = 2;
3697
3698 q->first_empty = q->last_used = 0;
3699 q->reg_r = read;
3700 q->reg_w = write;
3701
3702 ipw_write32(priv, base, q->dma_addr);
3703 ipw_write32(priv, size, count);
3704 ipw_write32(priv, read, 0);
3705 ipw_write32(priv, write, 0);
3706
3707 _ipw_read32(priv, 0x90);
3708}
3709
Jeff Garzikbf794512005-07-31 13:07:26 -04003710static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003711 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003712 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003713{
3714 struct pci_dev *dev = priv->pci_dev;
3715
3716 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3717 if (!q->txb) {
3718 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3719 return -ENOMEM;
3720 }
3721
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003722 q->bd =
3723 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003724 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003725 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003726 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003727 kfree(q->txb);
3728 q->txb = NULL;
3729 return -ENOMEM;
3730 }
3731
3732 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3733 return 0;
3734}
3735
3736/**
3737 * Free one TFD, those at index [txq->q.last_used].
3738 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003739 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003740 * @param dev
3741 * @param txq
3742 */
3743static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3744 struct clx2_tx_queue *txq)
3745{
3746 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3747 struct pci_dev *dev = priv->pci_dev;
3748 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003749
James Ketrenos43f66a62005-03-25 12:31:53 -06003750 /* classify bd */
3751 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3752 /* nothing to cleanup after for host commands */
3753 return;
3754
3755 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003756 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3757 IPW_ERROR("Too many chunks: %i\n",
3758 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003759 /** @todo issue fatal error, it is quite serious situation */
3760 return;
3761 }
3762
3763 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003764 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3765 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3766 le16_to_cpu(bd->u.data.chunk_len[i]),
3767 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003768 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003769 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003770 txq->txb[txq->q.last_used] = NULL;
3771 }
3772 }
3773}
3774
3775/**
3776 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003777 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003778 * Empty queue by removing and destroying all BD's.
3779 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003780 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003781 * @param dev
3782 * @param q
3783 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003784static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003785{
3786 struct clx2_queue *q = &txq->q;
3787 struct pci_dev *dev = priv->pci_dev;
3788
Jeff Garzikbf794512005-07-31 13:07:26 -04003789 if (q->n_bd == 0)
3790 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003791
3792 /* first, empty all BD's */
3793 for (; q->first_empty != q->last_used;
3794 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3795 ipw_queue_tx_free_tfd(priv, txq);
3796 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003797
James Ketrenos43f66a62005-03-25 12:31:53 -06003798 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003799 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003800 q->dma_addr);
3801 kfree(txq->txb);
3802
3803 /* 0 fill whole structure */
3804 memset(txq, 0, sizeof(*txq));
3805}
3806
James Ketrenos43f66a62005-03-25 12:31:53 -06003807/**
3808 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003809 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003810 * @param priv
3811 */
3812static void ipw_tx_queue_free(struct ipw_priv *priv)
3813{
3814 /* Tx CMD queue */
3815 ipw_queue_tx_free(priv, &priv->txq_cmd);
3816
3817 /* Tx queues */
3818 ipw_queue_tx_free(priv, &priv->txq[0]);
3819 ipw_queue_tx_free(priv, &priv->txq[1]);
3820 ipw_queue_tx_free(priv, &priv->txq[2]);
3821 ipw_queue_tx_free(priv, &priv->txq[3]);
3822}
3823
Arjan van de Ven858119e2006-01-14 13:20:43 -08003824static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003825{
3826 /* First 3 bytes are manufacturer */
3827 bssid[0] = priv->mac_addr[0];
3828 bssid[1] = priv->mac_addr[1];
3829 bssid[2] = priv->mac_addr[2];
3830
3831 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003832 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003833
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003834 bssid[0] &= 0xfe; /* clear multicast bit */
3835 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003836}
3837
Arjan van de Ven858119e2006-01-14 13:20:43 -08003838static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003839{
3840 struct ipw_station_entry entry;
3841 int i;
3842
3843 for (i = 0; i < priv->num_stations; i++) {
3844 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3845 /* Another node is active in network */
3846 priv->missed_adhoc_beacons = 0;
3847 if (!(priv->config & CFG_STATIC_CHANNEL))
3848 /* when other nodes drop out, we drop out */
3849 priv->config &= ~CFG_ADHOC_PERSIST;
3850
3851 return i;
3852 }
3853 }
3854
3855 if (i == MAX_STATIONS)
3856 return IPW_INVALID_STATION;
3857
Johannes Berge1749612008-10-27 15:59:26 -07003858 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003859
3860 entry.reserved = 0;
3861 entry.support_mode = 0;
3862 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3863 memcpy(priv->stations[i], bssid, ETH_ALEN);
3864 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003865 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003866 priv->num_stations++;
3867
3868 return i;
3869}
3870
Arjan van de Ven858119e2006-01-14 13:20:43 -08003871static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003872{
3873 int i;
3874
Jeff Garzikbf794512005-07-31 13:07:26 -04003875 for (i = 0; i < priv->num_stations; i++)
3876 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003877 return i;
3878
3879 return IPW_INVALID_STATION;
3880}
3881
3882static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3883{
3884 int err;
3885
Hong Liu7b996592005-08-25 17:36:13 +08003886 if (priv->status & STATUS_ASSOCIATING) {
3887 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3888 queue_work(priv->workqueue, &priv->disassociate);
3889 return;
3890 }
3891
3892 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003893 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3894 return;
3895 }
3896
Johannes Berge1749612008-10-27 15:59:26 -07003897 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003898 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003899 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003900 priv->assoc_request.channel);
3901
3902 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3903 priv->status |= STATUS_DISASSOCIATING;
3904
3905 if (quiet)
3906 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3907 else
3908 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003909
James Ketrenos43f66a62005-03-25 12:31:53 -06003910 err = ipw_send_associate(priv, &priv->assoc_request);
3911 if (err) {
3912 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3913 "failed.\n");
3914 return;
3915 }
3916
3917}
3918
James Ketrenosc848d0a2005-08-24 21:56:24 -05003919static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003920{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003921 struct ipw_priv *priv = data;
3922 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3923 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003924 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003925 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003926 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003927}
3928
David Howellsc4028952006-11-22 14:57:56 +00003929static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003930{
David Howellsc4028952006-11-22 14:57:56 +00003931 struct ipw_priv *priv =
3932 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003933 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003934 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003935 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003936}
3937
David Howellsc4028952006-11-22 14:57:56 +00003938static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003939{
David Howellsc4028952006-11-22 14:57:56 +00003940 struct ipw_priv *priv =
3941 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003942
3943#ifdef CONFIG_IPW2200_PROMISCUOUS
3944 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3945 priv->sys_config.accept_all_data_frames = 1;
3946 priv->sys_config.accept_non_directed_frames = 1;
3947 priv->sys_config.accept_all_mgmt_bcpr = 1;
3948 priv->sys_config.accept_all_mgmt_frames = 1;
3949 }
3950#endif
3951
3952 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003953}
3954
3955struct ipw_status_code {
3956 u16 status;
3957 const char *reason;
3958};
3959
3960static const struct ipw_status_code ipw_status_codes[] = {
3961 {0x00, "Successful"},
3962 {0x01, "Unspecified failure"},
3963 {0x0A, "Cannot support all requested capabilities in the "
3964 "Capability information field"},
3965 {0x0B, "Reassociation denied due to inability to confirm that "
3966 "association exists"},
3967 {0x0C, "Association denied due to reason outside the scope of this "
3968 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003969 {0x0D,
3970 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003971 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003972 {0x0E,
3973 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 "transaction sequence number out of expected sequence"},
3975 {0x0F, "Authentication rejected because of challenge failure"},
3976 {0x10, "Authentication rejected due to timeout waiting for next "
3977 "frame in sequence"},
3978 {0x11, "Association denied because AP is unable to handle additional "
3979 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003980 {0x12,
3981 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003982 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003983 {0x13,
3984 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003985 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003986 {0x14,
3987 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003988 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003989 {0x15,
3990 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003991 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003992 {0x19,
3993 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003994 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003995 {0x1A,
3996 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003997 "DSSS-OFDM operation"},
3998 {0x28, "Invalid Information Element"},
3999 {0x29, "Group Cipher is not valid"},
4000 {0x2A, "Pairwise Cipher is not valid"},
4001 {0x2B, "AKMP is not valid"},
4002 {0x2C, "Unsupported RSN IE version"},
4003 {0x2D, "Invalid RSN IE Capabilities"},
4004 {0x2E, "Cipher suite is rejected per security policy"},
4005};
4006
Jeff Garzikbf794512005-07-31 13:07:26 -04004007static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004008{
4009 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004010 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004011 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004012 return ipw_status_codes[i].reason;
4013 return "Unknown status value.";
4014}
James Ketrenos43f66a62005-03-25 12:31:53 -06004015
4016static void inline average_init(struct average *avg)
4017{
4018 memset(avg, 0, sizeof(*avg));
4019}
4020
Zhu Yi00d21de2006-04-13 17:19:02 +08004021#define DEPTH_RSSI 8
4022#define DEPTH_NOISE 16
4023static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4024{
4025 return ((depth-1)*prev_avg + val)/depth;
4026}
4027
Arjan van de Ven858119e2006-01-14 13:20:43 -08004028static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004029{
4030 avg->sum -= avg->entries[avg->pos];
4031 avg->sum += val;
4032 avg->entries[avg->pos++] = val;
4033 if (unlikely(avg->pos == AVG_ENTRIES)) {
4034 avg->init = 1;
4035 avg->pos = 0;
4036 }
4037}
4038
Arjan van de Ven858119e2006-01-14 13:20:43 -08004039static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004040{
4041 if (!unlikely(avg->init)) {
4042 if (avg->pos)
4043 return avg->sum / avg->pos;
4044 return 0;
4045 }
4046
4047 return avg->sum / AVG_ENTRIES;
4048}
4049
4050static void ipw_reset_stats(struct ipw_priv *priv)
4051{
4052 u32 len = sizeof(u32);
4053
4054 priv->quality = 0;
4055
4056 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004057 priv->exp_avg_rssi = -60;
4058 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004059
4060 priv->last_rate = 0;
4061 priv->last_missed_beacons = 0;
4062 priv->last_rx_packets = 0;
4063 priv->last_tx_packets = 0;
4064 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004065
James Ketrenos43f66a62005-03-25 12:31:53 -06004066 /* Firmware managed, reset only when NIC is restarted, so we have to
4067 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004068 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004070 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004071 &priv->last_tx_failures, &len);
4072
4073 /* Driver managed, reset with each association */
4074 priv->missed_adhoc_beacons = 0;
4075 priv->missed_beacons = 0;
4076 priv->tx_packets = 0;
4077 priv->rx_packets = 0;
4078
4079}
4080
Arjan van de Ven858119e2006-01-14 13:20:43 -08004081static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004082{
4083 u32 i = 0x80000000;
4084 u32 mask = priv->rates_mask;
4085 /* If currently associated in B mode, restrict the maximum
4086 * rate match to B rates */
4087 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004088 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004089
4090 /* TODO: Verify that the rate is supported by the current rates
4091 * list. */
4092
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004093 while (i && !(mask & i))
4094 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004095 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004096 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004097 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004098 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004099 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004100 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004101 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004102 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004103 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004104 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004105 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004106 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004107 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004108 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004109 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004110 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004111 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004112 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004113 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004114 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004115 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004116 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004117 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004118 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004119 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004120 }
4121
Jeff Garzikbf794512005-07-31 13:07:26 -04004122 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004123 return 11000000;
4124 else
4125 return 54000000;
4126}
4127
4128static u32 ipw_get_current_rate(struct ipw_priv *priv)
4129{
4130 u32 rate, len = sizeof(rate);
4131 int err;
4132
Jeff Garzikbf794512005-07-31 13:07:26 -04004133 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004134 return 0;
4135
4136 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004137 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004138 &len);
4139 if (err) {
4140 IPW_DEBUG_INFO("failed querying ordinals.\n");
4141 return 0;
4142 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004143 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004144 return ipw_get_max_rate(priv);
4145
4146 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004147 case IPW_TX_RATE_1MB:
4148 return 1000000;
4149 case IPW_TX_RATE_2MB:
4150 return 2000000;
4151 case IPW_TX_RATE_5MB:
4152 return 5500000;
4153 case IPW_TX_RATE_6MB:
4154 return 6000000;
4155 case IPW_TX_RATE_9MB:
4156 return 9000000;
4157 case IPW_TX_RATE_11MB:
4158 return 11000000;
4159 case IPW_TX_RATE_12MB:
4160 return 12000000;
4161 case IPW_TX_RATE_18MB:
4162 return 18000000;
4163 case IPW_TX_RATE_24MB:
4164 return 24000000;
4165 case IPW_TX_RATE_36MB:
4166 return 36000000;
4167 case IPW_TX_RATE_48MB:
4168 return 48000000;
4169 case IPW_TX_RATE_54MB:
4170 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 }
4172
4173 return 0;
4174}
4175
James Ketrenos43f66a62005-03-25 12:31:53 -06004176#define IPW_STATS_INTERVAL (2 * HZ)
4177static void ipw_gather_stats(struct ipw_priv *priv)
4178{
4179 u32 rx_err, rx_err_delta, rx_packets_delta;
4180 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4181 u32 missed_beacons_percent, missed_beacons_delta;
4182 u32 quality = 0;
4183 u32 len = sizeof(u32);
4184 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004185 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004186 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004187 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004188
4189 if (!(priv->status & STATUS_ASSOCIATED)) {
4190 priv->quality = 0;
4191 return;
4192 }
4193
4194 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004195 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004196 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004197 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004198 priv->last_missed_beacons = priv->missed_beacons;
4199 if (priv->assoc_request.beacon_interval) {
4200 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004201 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004202 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004203 } else {
4204 missed_beacons_percent = 0;
4205 }
4206 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4207
4208 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4209 rx_err_delta = rx_err - priv->last_rx_err;
4210 priv->last_rx_err = rx_err;
4211
4212 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4213 tx_failures_delta = tx_failures - priv->last_tx_failures;
4214 priv->last_tx_failures = tx_failures;
4215
4216 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4217 priv->last_rx_packets = priv->rx_packets;
4218
4219 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4220 priv->last_tx_packets = priv->tx_packets;
4221
4222 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004223 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004224 * Missed beacon: 100% = 0, 0% = 70% missed
4225 * Rate: 60% = 1Mbs, 100% = Max
4226 * Rx and Tx errors represent a straight % of total Rx/Tx
4227 * RSSI: 100% = > -50, 0% = < -80
4228 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004229 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004230 * The lowest computed quality is used.
4231 *
4232 */
4233#define BEACON_THRESHOLD 5
4234 beacon_quality = 100 - missed_beacons_percent;
4235 if (beacon_quality < BEACON_THRESHOLD)
4236 beacon_quality = 0;
4237 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004238 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004239 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004240 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004241 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004242
James Ketrenos43f66a62005-03-25 12:31:53 -06004243 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004244 max_rate = ipw_get_max_rate(priv);
4245 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004246 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4247 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004248
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004249 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004250 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004251 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004252 else
4253 rx_quality = 100;
4254 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4255 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004256
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004257 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004258 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004259 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004260 else
4261 tx_quality = 100;
4262 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4263 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004264
Zhu Yi00d21de2006-04-13 17:19:02 +08004265 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004266 signal_quality =
4267 (100 *
4268 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4269 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4270 (priv->ieee->perfect_rssi - rssi) *
4271 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4272 62 * (priv->ieee->perfect_rssi - rssi))) /
4273 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4274 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4275 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004276 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004277 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004278 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004279
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004280 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004281 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004282
Reinette Chatre21f8a732009-08-18 10:25:05 -07004283 quality = min(rx_quality, signal_quality);
4284 quality = min(tx_quality, quality);
4285 quality = min(rate_quality, quality);
4286 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004287 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004288 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4289 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004290 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004291 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4292 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004293 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004294 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4295 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004296 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004297 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4298 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004299 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004300 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4301 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004302
4303 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004304
4305 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004306 IPW_STATS_INTERVAL);
4307}
4308
David Howellsc4028952006-11-22 14:57:56 +00004309static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004310{
David Howellsc4028952006-11-22 14:57:56 +00004311 struct ipw_priv *priv =
4312 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004313 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004314 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004315 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004316}
4317
Ben Cahille7582562005-10-06 15:34:41 -05004318/* Missed beacon behavior:
4319 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4320 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4321 * Above disassociate threshold, give up and stop scanning.
4322 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004323static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004324 int missed_count)
4325{
4326 priv->notif_missed_beacons = missed_count;
4327
James Ketrenosafbf30a2005-08-25 00:05:33 -05004328 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004329 priv->status & STATUS_ASSOCIATED) {
4330 /* If associated and we've hit the missed
4331 * beacon threshold, disassociate, turn
4332 * off roaming, and abort any active scans */
4333 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004334 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004335 "Missed beacon: %d - disassociate\n", missed_count);
4336 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004337 if (priv->status & STATUS_SCANNING) {
4338 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4339 IPW_DL_STATE,
4340 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004341 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004342 }
4343
James Ketrenosea2b26e2005-08-24 21:25:16 -05004344 queue_work(priv->workqueue, &priv->disassociate);
4345 return;
4346 }
4347
4348 if (priv->status & STATUS_ROAMING) {
4349 /* If we are currently roaming, then just
4350 * print a debug statement... */
4351 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4352 "Missed beacon: %d - roam in progress\n",
4353 missed_count);
4354 return;
4355 }
4356
Zhu Yi4bfdb912006-01-24 16:37:16 +08004357 if (roaming &&
4358 (missed_count > priv->roaming_threshold &&
4359 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004360 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004361 * bit in the status and kick off a scan.
4362 * This can happen several times before we reach
4363 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004364 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4365 "Missed beacon: %d - initiate "
4366 "roaming\n", missed_count);
4367 if (!(priv->status & STATUS_ROAMING)) {
4368 priv->status |= STATUS_ROAMING;
4369 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004370 queue_delayed_work(priv->workqueue,
4371 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004372 }
4373 return;
4374 }
4375
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004376 if (priv->status & STATUS_SCANNING &&
4377 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004378 /* Stop scan to keep fw from getting
4379 * stuck (only if we aren't roaming --
4380 * otherwise we'll never scan more than 2 or 3
4381 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004382 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4383 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004384 queue_work(priv->workqueue, &priv->abort_scan);
4385 }
4386
4387 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004388}
4389
Dan Williams0b531672007-10-09 13:55:24 -04004390static void ipw_scan_event(struct work_struct *work)
4391{
4392 union iwreq_data wrqu;
4393
4394 struct ipw_priv *priv =
4395 container_of(work, struct ipw_priv, scan_event.work);
4396
4397 wrqu.data.length = 0;
4398 wrqu.data.flags = 0;
4399 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4400}
4401
4402static void handle_scan_event(struct ipw_priv *priv)
4403{
4404 /* Only userspace-requested scan completion events go out immediately */
4405 if (!priv->user_requested_scan) {
4406 if (!delayed_work_pending(&priv->scan_event))
4407 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004408 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004409 } else {
4410 union iwreq_data wrqu;
4411
4412 priv->user_requested_scan = 0;
4413 cancel_delayed_work(&priv->scan_event);
4414
4415 wrqu.data.length = 0;
4416 wrqu.data.flags = 0;
4417 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4418 }
4419}
4420
James Ketrenos43f66a62005-03-25 12:31:53 -06004421/**
4422 * Handle host notification packet.
4423 * Called from interrupt routine
4424 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004425static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004426 struct ipw_rx_notification *notif)
4427{
John W. Linville9387b7c2008-09-30 20:59:05 -04004428 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004429 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004430
Al Viroe62e1ee2007-12-27 01:36:46 -05004431 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004432
James Ketrenos43f66a62005-03-25 12:31:53 -06004433 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004434 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4435 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004436
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004437 switch (assoc->state) {
4438 case CMAS_ASSOCIATED:{
4439 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4440 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004441 "associated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004442 print_ssid(ssid, priv->essid,
4443 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004444 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004445
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004446 switch (priv->ieee->iw_mode) {
4447 case IW_MODE_INFRA:
4448 memcpy(priv->ieee->bssid,
4449 priv->bssid, ETH_ALEN);
4450 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004451
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004452 case IW_MODE_ADHOC:
4453 memcpy(priv->ieee->bssid,
4454 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004455
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004456 /* clear out the station table */
4457 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004458
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004459 IPW_DEBUG_ASSOC
4460 ("queueing adhoc check\n");
4461 queue_delayed_work(priv->
4462 workqueue,
4463 &priv->
4464 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004465 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004466 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004467 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004468 break;
4469 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004470
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004471 priv->status &= ~STATUS_ASSOCIATING;
4472 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004473 queue_work(priv->workqueue,
4474 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004475
Zhu Yie43e3c12006-04-13 17:20:45 +08004476#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004477#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004478 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004479 if ((priv->status & STATUS_AUTH) &&
4480 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4481 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004482 if ((sizeof
4483 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004484 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004485 <= size)
4486 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004487 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004488 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004489 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004490 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004491 };
4492
4493 IPW_DEBUG_QOS
4494 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004495 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004496 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004497 ieee,
4498 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004499 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004500 *)
4501 &notif->u.raw, &stats);
4502 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 }
James Ketrenosb095c382005-08-24 22:04:42 -05004504#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004505
James Ketrenosa613bff2005-08-24 21:43:11 -05004506 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004507
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004508 break;
4509 }
4510
4511 case CMAS_AUTHENTICATED:{
4512 if (priv->
4513 status & (STATUS_ASSOCIATED |
4514 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004515 struct notif_authenticate *auth
4516 = &notif->u.auth;
4517 IPW_DEBUG(IPW_DL_NOTIF |
4518 IPW_DL_STATE |
4519 IPW_DL_ASSOC,
4520 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004521 "%pM"
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004522 ": (0x%04X) - %s \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004523 print_ssid(ssid,
4524 priv->
4525 essid,
4526 priv->
4527 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004528 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004529 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004530 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004531 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004532 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004533
4534 priv->status &=
4535 ~(STATUS_ASSOCIATING |
4536 STATUS_AUTH |
4537 STATUS_ASSOCIATED);
4538
James Ketrenosa613bff2005-08-24 21:43:11 -05004539 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004540 break;
4541 }
4542
4543 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4544 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004545 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004546 print_ssid(ssid, priv->essid,
4547 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004548 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004549 break;
4550 }
4551
4552 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004553 if (priv->status & STATUS_AUTH) {
4554 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004555 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004556 *resp;
4557 resp =
4558 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004559 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004560 *)&notif->u.raw;
4561 IPW_DEBUG(IPW_DL_NOTIF |
4562 IPW_DL_STATE |
4563 IPW_DL_ASSOC,
4564 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004565 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004566 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004567 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004568 (resp->status)));
4569 }
4570
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004571 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4572 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004573 "disassociated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004574 print_ssid(ssid, priv->essid,
4575 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004576 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004577
4578 priv->status &=
4579 ~(STATUS_DISASSOCIATING |
4580 STATUS_ASSOCIATING |
4581 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004582 if (priv->assoc_network
4583 && (priv->assoc_network->
4584 capability &
4585 WLAN_CAPABILITY_IBSS))
4586 ipw_remove_current_network
4587 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004588
James Ketrenosa613bff2005-08-24 21:43:11 -05004589 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004590
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004591 break;
4592 }
4593
James Ketrenosb095c382005-08-24 22:04:42 -05004594 case CMAS_RX_ASSOC_RESP:
4595 break;
4596
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004597 default:
4598 IPW_ERROR("assoc: unknown (%d)\n",
4599 assoc->state);
4600 break;
4601 }
4602
James Ketrenos43f66a62005-03-25 12:31:53 -06004603 break;
4604 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004605
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004606 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4607 struct notif_authenticate *auth = &notif->u.auth;
4608 switch (auth->state) {
4609 case CMAS_AUTHENTICATED:
4610 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Johannes Berge1749612008-10-27 15:59:26 -07004611 "authenticated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004612 print_ssid(ssid, priv->essid,
4613 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004614 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004615 priv->status |= STATUS_AUTH;
4616 break;
4617
4618 case CMAS_INIT:
4619 if (priv->status & STATUS_AUTH) {
4620 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4621 IPW_DL_ASSOC,
4622 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004623 le16_to_cpu(auth->status),
4624 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004625 (auth->
4626 status)));
4627 }
4628 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4629 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004630 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004631 print_ssid(ssid, priv->essid,
4632 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004633 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004634
4635 priv->status &= ~(STATUS_ASSOCIATING |
4636 STATUS_AUTH |
4637 STATUS_ASSOCIATED);
4638
James Ketrenosa613bff2005-08-24 21:43:11 -05004639 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004640 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004641
4642 case CMAS_TX_AUTH_SEQ_1:
4643 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4644 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4645 break;
4646 case CMAS_RX_AUTH_SEQ_2:
4647 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4648 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4649 break;
4650 case CMAS_AUTH_SEQ_1_PASS:
4651 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4652 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4653 break;
4654 case CMAS_AUTH_SEQ_1_FAIL:
4655 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4656 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4657 break;
4658 case CMAS_TX_AUTH_SEQ_3:
4659 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4660 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4661 break;
4662 case CMAS_RX_AUTH_SEQ_4:
4663 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4664 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4665 break;
4666 case CMAS_AUTH_SEQ_2_PASS:
4667 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4668 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4669 break;
4670 case CMAS_AUTH_SEQ_2_FAIL:
4671 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4672 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4673 break;
4674 case CMAS_TX_ASSOC:
4675 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4676 IPW_DL_ASSOC, "TX_ASSOC\n");
4677 break;
4678 case CMAS_RX_ASSOC_RESP:
4679 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4680 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004681
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004682 break;
4683 case CMAS_ASSOCIATED:
4684 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4685 IPW_DL_ASSOC, "ASSOCIATED\n");
4686 break;
4687 default:
4688 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4689 auth->state);
4690 break;
4691 }
4692 break;
4693 }
4694
4695 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4696 struct notif_channel_result *x =
4697 &notif->u.channel_result;
4698
Al Viroe62e1ee2007-12-27 01:36:46 -05004699 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004700 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4701 x->channel_num);
4702 } else {
4703 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4704 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004705 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004706 }
4707 break;
4708 }
4709
4710 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4711 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004712 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004713 IPW_DEBUG_SCAN
4714 ("Scan completed: type %d, %d channels, "
4715 "%d status\n", x->scan_type,
4716 x->num_channels, x->status);
4717 } else {
4718 IPW_ERROR("Scan completed of wrong size %d "
4719 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004720 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004721 }
4722
4723 priv->status &=
4724 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4725
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004726 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004727 cancel_delayed_work(&priv->scan_check);
4728
James Ketrenosb095c382005-08-24 22:04:42 -05004729 if (priv->status & STATUS_EXIT_PENDING)
4730 break;
4731
4732 priv->ieee->scans++;
4733
4734#ifdef CONFIG_IPW2200_MONITOR
4735 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004736 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004737 queue_delayed_work(priv->workqueue,
4738 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004739 break;
4740 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004741 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004742#endif /* CONFIG_IPW2200_MONITOR */
4743
Dan Williamsea177302008-06-02 17:51:23 -04004744 /* Do queued direct scans first */
4745 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4746 queue_delayed_work(priv->workqueue,
4747 &priv->request_direct_scan, 0);
4748 }
4749
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004750 if (!(priv->status & (STATUS_ASSOCIATED |
4751 STATUS_ASSOCIATING |
4752 STATUS_ROAMING |
4753 STATUS_DISASSOCIATING)))
4754 queue_work(priv->workqueue, &priv->associate);
4755 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004756 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4757 /* If a scan completed and we are in roam mode, then
4758 * the scan that completed was the one requested as a
4759 * result of entering roam... so, schedule the
4760 * roam work */
4761 queue_work(priv->workqueue,
4762 &priv->roam);
4763 else
4764 /* Don't schedule if we aborted the scan */
4765 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004766 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004767 queue_delayed_work(priv->workqueue,
4768 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004769 else if (priv->config & CFG_BACKGROUND_SCAN
4770 && priv->status & STATUS_ASSOCIATED)
4771 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004772 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004773 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004774
4775 /* Send an empty event to user space.
4776 * We don't send the received data on the event because
4777 * it would require us to do complex transcoding, and
4778 * we want to minimise the work done in the irq handler
4779 * Use a request to extract the data.
4780 * Also, we generate this even for any scan, regardless
4781 * on how the scan was initiated. User space can just
4782 * sync on periodic scan to get fresh data...
4783 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004784 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4785 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004786 break;
4787 }
4788
4789 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4790 struct notif_frag_length *x = &notif->u.frag_len;
4791
Al Viroe62e1ee2007-12-27 01:36:46 -05004792 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004793 IPW_ERROR("Frag length: %d\n",
4794 le16_to_cpu(x->frag_length));
4795 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004796 IPW_ERROR("Frag length of wrong size %d "
4797 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004798 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004799 break;
4800 }
4801
4802 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4803 struct notif_link_deterioration *x =
4804 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004805
Al Viroe62e1ee2007-12-27 01:36:46 -05004806 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004807 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004808 "link deterioration: type %d, cnt %d\n",
4809 x->silence_notification_type,
4810 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004811 memcpy(&priv->last_link_deterioration, x,
4812 sizeof(*x));
4813 } else {
4814 IPW_ERROR("Link Deterioration of wrong size %d "
4815 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004816 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004817 }
4818 break;
4819 }
4820
4821 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4822 IPW_ERROR("Dino config\n");
4823 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004824 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004825 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004826
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004827 break;
4828 }
4829
4830 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4831 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004832 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004833 IPW_ERROR
4834 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004835 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004836 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004837 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004838
James Ketrenosa613bff2005-08-24 21:43:11 -05004839 if (le32_to_cpu(x->state) ==
4840 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4841 ipw_handle_missed_beacon(priv,
4842 le32_to_cpu(x->
4843 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004844
James Ketrenos43f66a62005-03-25 12:31:53 -06004845 break;
4846 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004847
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004848 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4849 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004850 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004851 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4852 "0x%02x station %d\n",
4853 x->key_state, x->security_type,
4854 x->station_index);
4855 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004856 }
4857
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004858 IPW_ERROR
4859 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004860 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004861 break;
4862 }
4863
4864 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4865 struct notif_calibration *x = &notif->u.calibration;
4866
Al Viroe62e1ee2007-12-27 01:36:46 -05004867 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004868 memcpy(&priv->calib, x, sizeof(*x));
4869 IPW_DEBUG_INFO("TODO: Calibration\n");
4870 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004871 }
4872
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 IPW_ERROR
4874 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004875 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004877 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004878
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004879 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004880 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004881 priv->exp_avg_noise =
4882 exponential_average(priv->exp_avg_noise,
4883 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4884 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 break;
4886 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004887
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004888 IPW_ERROR
4889 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004890 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004891 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004892 }
4893
James Ketrenos43f66a62005-03-25 12:31:53 -06004894 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004895 IPW_DEBUG_NOTIF("Unknown notification: "
4896 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004897 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004898 }
4899}
4900
4901/**
4902 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004903 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004904 * @param priv
4905 * @return error code
4906 */
4907static int ipw_queue_reset(struct ipw_priv *priv)
4908{
4909 int rc = 0;
4910 /** @todo customize queue sizes */
4911 int nTx = 64, nTxCmd = 8;
4912 ipw_tx_queue_free(priv);
4913 /* Tx CMD queue */
4914 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004915 IPW_TX_CMD_QUEUE_READ_INDEX,
4916 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4917 IPW_TX_CMD_QUEUE_BD_BASE,
4918 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004919 if (rc) {
4920 IPW_ERROR("Tx Cmd queue init failed\n");
4921 goto error;
4922 }
4923 /* Tx queue(s) */
4924 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004925 IPW_TX_QUEUE_0_READ_INDEX,
4926 IPW_TX_QUEUE_0_WRITE_INDEX,
4927 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 if (rc) {
4929 IPW_ERROR("Tx 0 queue init failed\n");
4930 goto error;
4931 }
4932 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004933 IPW_TX_QUEUE_1_READ_INDEX,
4934 IPW_TX_QUEUE_1_WRITE_INDEX,
4935 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 if (rc) {
4937 IPW_ERROR("Tx 1 queue init failed\n");
4938 goto error;
4939 }
4940 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004941 IPW_TX_QUEUE_2_READ_INDEX,
4942 IPW_TX_QUEUE_2_WRITE_INDEX,
4943 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004944 if (rc) {
4945 IPW_ERROR("Tx 2 queue init failed\n");
4946 goto error;
4947 }
4948 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004949 IPW_TX_QUEUE_3_READ_INDEX,
4950 IPW_TX_QUEUE_3_WRITE_INDEX,
4951 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004952 if (rc) {
4953 IPW_ERROR("Tx 3 queue init failed\n");
4954 goto error;
4955 }
4956 /* statistics */
4957 priv->rx_bufs_min = 0;
4958 priv->rx_pend_max = 0;
4959 return rc;
4960
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004961 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004962 ipw_tx_queue_free(priv);
4963 return rc;
4964}
4965
4966/**
4967 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004968 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01004969 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06004970 * new 'R' index need to be reclaimed. As result, some free space
4971 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004972 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 * @note Need to protect against garbage in 'R' index
4974 * @param priv
4975 * @param txq
4976 * @param qindex
4977 * @return Number of used entries remains in the queue
4978 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004979static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004980 struct clx2_tx_queue *txq, int qindex)
4981{
4982 u32 hw_tail;
4983 int used;
4984 struct clx2_queue *q = &txq->q;
4985
4986 hw_tail = ipw_read32(priv, q->reg_r);
4987 if (hw_tail >= q->n_bd) {
4988 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004989 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4990 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004991 goto done;
4992 }
4993 for (; q->last_used != hw_tail;
4994 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4995 ipw_queue_tx_free_tfd(priv, txq);
4996 priv->tx_packets++;
4997 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004998 done:
Dan Williams943dbef2008-02-14 17:49:41 -05004999 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005000 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005001 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005002 used = q->first_empty - q->last_used;
5003 if (used < 0)
5004 used += q->n_bd;
5005
5006 return used;
5007}
5008
5009static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5010 int len, int sync)
5011{
5012 struct clx2_tx_queue *txq = &priv->txq_cmd;
5013 struct clx2_queue *q = &txq->q;
5014 struct tfd_frame *tfd;
5015
Dan Williams943dbef2008-02-14 17:49:41 -05005016 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 IPW_ERROR("No space for Tx\n");
5018 return -EBUSY;
5019 }
5020
5021 tfd = &txq->bd[q->first_empty];
5022 txq->txb[q->first_empty] = NULL;
5023
5024 memset(tfd, 0, sizeof(*tfd));
5025 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5026 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5027 priv->hcmd_seq++;
5028 tfd->u.cmd.index = hcmd;
5029 tfd->u.cmd.length = len;
5030 memcpy(tfd->u.cmd.payload, buf, len);
5031 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5032 ipw_write32(priv, q->reg_w, q->first_empty);
5033 _ipw_read32(priv, 0x90);
5034
5035 return 0;
5036}
5037
Jeff Garzikbf794512005-07-31 13:07:26 -04005038/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005039 * Rx theory of operation
5040 *
5041 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005042 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005043 * 0 to 31
5044 *
5045 * Rx Queue Indexes
5046 * The host/firmware share two index registers for managing the Rx buffers.
5047 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005048 * The READ index maps to the first position that the firmware may be writing
5049 * to -- the driver can read up to (but not including) this position and get
5050 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005051 * The READ index is managed by the firmware once the card is enabled.
5052 *
5053 * The WRITE index maps to the last position the driver has read from -- the
5054 * position preceding WRITE is the last slot the firmware can place a packet.
5055 *
5056 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005057 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005058 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005059 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005060 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5061 *
5062 * When the firmware places a packet in a buffer it will advance the READ index
5063 * and fire the RX interrupt. The driver can then query the READ index and
5064 * process as many packets as possible, moving the WRITE index forward as it
5065 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005066 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005067 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005068 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005069 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005070 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005071 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5072 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5073 * 'processed' and 'read' driver indexes as well)
5074 * + A received packet is processed and handed to the kernel network stack,
5075 * detached from the ipw->rxq. The driver 'processed' index is updated.
5076 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005077 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5078 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005079 * were enough free buffers and RX_STALLED is set it is cleared.
5080 *
5081 *
5082 * Driver sequence:
5083 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005084 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005085 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5086 * ipw_rx_queue_restock
5087 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5088 * queue, updates firmware pointers, and updates
5089 * the WRITE index. If insufficient rx_free buffers
5090 * are available, schedules ipw_rx_queue_replenish
5091 *
5092 * -- enable interrupts --
5093 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005094 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 * Moves the packet buffer from queue to rx_used.
5096 * Calls ipw_rx_queue_restock to refill any empty
5097 * slots.
5098 * ...
5099 *
5100 */
5101
Jeff Garzikbf794512005-07-31 13:07:26 -04005102/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005103 * If there are slots in the RX queue that need to be restocked,
5104 * and we have free pre-allocated buffers, fill the ranks as much
5105 * as we can pulling from rx_free.
5106 *
5107 * This moves the 'write' index forward to catch up with 'processed', and
5108 * also updates the memory address in the firmware to reference the new
5109 * target buffer.
5110 */
5111static void ipw_rx_queue_restock(struct ipw_priv *priv)
5112{
5113 struct ipw_rx_queue *rxq = priv->rxq;
5114 struct list_head *element;
5115 struct ipw_rx_mem_buffer *rxb;
5116 unsigned long flags;
5117 int write;
5118
5119 spin_lock_irqsave(&rxq->lock, flags);
5120 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005121 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005122 element = rxq->rx_free.next;
5123 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5124 list_del(element);
5125
James Ketrenosb095c382005-08-24 22:04:42 -05005126 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005127 rxb->dma_addr);
5128 rxq->queue[rxq->write] = rxb;
5129 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5130 rxq->free_count--;
5131 }
5132 spin_unlock_irqrestore(&rxq->lock, flags);
5133
Jeff Garzikbf794512005-07-31 13:07:26 -04005134 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005135 * refill it */
5136 if (rxq->free_count <= RX_LOW_WATERMARK)
5137 queue_work(priv->workqueue, &priv->rx_replenish);
5138
5139 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005140 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005141 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005142}
5143
5144/*
5145 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005146 * Also restock the Rx queue via ipw_rx_queue_restock.
5147 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005148 * This is called as a scheduled work item (except for during intialization)
5149 */
5150static void ipw_rx_queue_replenish(void *data)
5151{
5152 struct ipw_priv *priv = data;
5153 struct ipw_rx_queue *rxq = priv->rxq;
5154 struct list_head *element;
5155 struct ipw_rx_mem_buffer *rxb;
5156 unsigned long flags;
5157
5158 spin_lock_irqsave(&rxq->lock, flags);
5159 while (!list_empty(&rxq->rx_used)) {
5160 element = rxq->rx_used.next;
5161 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005162 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005163 if (!rxb->skb) {
5164 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5165 priv->net_dev->name);
5166 /* We don't reschedule replenish work here -- we will
5167 * call the restock method and if it still needs
5168 * more buffers it will schedule replenish */
5169 break;
5170 }
5171 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005172
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005173 rxb->dma_addr =
5174 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005175 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005176
James Ketrenos43f66a62005-03-25 12:31:53 -06005177 list_add_tail(&rxb->list, &rxq->rx_free);
5178 rxq->free_count++;
5179 }
5180 spin_unlock_irqrestore(&rxq->lock, flags);
5181
5182 ipw_rx_queue_restock(priv);
5183}
5184
David Howellsc4028952006-11-22 14:57:56 +00005185static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005186{
David Howellsc4028952006-11-22 14:57:56 +00005187 struct ipw_priv *priv =
5188 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005189 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005190 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005191 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005192}
5193
James Ketrenos43f66a62005-03-25 12:31:53 -06005194/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005195 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005196 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005197 * non NULL it is unmapped and freed
5198 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005199static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005200{
5201 int i;
5202
5203 if (!rxq)
5204 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005205
James Ketrenos43f66a62005-03-25 12:31:53 -06005206 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5207 if (rxq->pool[i].skb != NULL) {
5208 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005209 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005210 dev_kfree_skb(rxq->pool[i].skb);
5211 }
5212 }
5213
5214 kfree(rxq);
5215}
5216
5217static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5218{
5219 struct ipw_rx_queue *rxq;
5220 int i;
5221
Takisc75f4742005-12-01 01:41:45 -08005222 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005223 if (unlikely(!rxq)) {
5224 IPW_ERROR("memory allocation failed\n");
5225 return NULL;
5226 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005227 spin_lock_init(&rxq->lock);
5228 INIT_LIST_HEAD(&rxq->rx_free);
5229 INIT_LIST_HEAD(&rxq->rx_used);
5230
5231 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005232 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005233 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5234
5235 /* Set us so that we have processed and used all buffers, but have
5236 * not restocked the Rx queue with fresh buffers */
5237 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005238 rxq->free_count = 0;
5239
5240 return rxq;
5241}
5242
5243static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5244{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005245 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005246 if (ieee_mode == IEEE_A) {
5247 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005248 case LIBIPW_OFDM_RATE_6MB:
5249 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005250 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005251 case LIBIPW_OFDM_RATE_9MB:
5252 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005253 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005254 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005255 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005256 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5257 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005258 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005259 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5260 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005261 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005262 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5263 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005264 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005265 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5266 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005267 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005268 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5269 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005270 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005271 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005272 default:
5273 return 0;
5274 }
5275 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005276
James Ketrenos43f66a62005-03-25 12:31:53 -06005277 /* B and G mixed */
5278 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005279 case LIBIPW_CCK_RATE_1MB:
5280 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5281 case LIBIPW_CCK_RATE_2MB:
5282 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5283 case LIBIPW_CCK_RATE_5MB:
5284 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5285 case LIBIPW_CCK_RATE_11MB:
5286 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005287 }
5288
5289 /* If we are limited to B modulations, bail at this point */
5290 if (ieee_mode == IEEE_B)
5291 return 0;
5292
5293 /* G */
5294 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005295 case LIBIPW_OFDM_RATE_6MB:
5296 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5297 case LIBIPW_OFDM_RATE_9MB:
5298 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5299 case LIBIPW_OFDM_RATE_12MB:
5300 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5301 case LIBIPW_OFDM_RATE_18MB:
5302 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5303 case LIBIPW_OFDM_RATE_24MB:
5304 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5305 case LIBIPW_OFDM_RATE_36MB:
5306 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5307 case LIBIPW_OFDM_RATE_48MB:
5308 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5309 case LIBIPW_OFDM_RATE_54MB:
5310 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005311 }
5312
5313 return 0;
5314}
5315
Jeff Garzikbf794512005-07-31 13:07:26 -04005316static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005317 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005318 struct ipw_supported_rates *rates)
5319{
5320 int num_rates, i;
5321
5322 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005323 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005324 rates->num_rates = 0;
5325 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005326 if (!ipw_is_rate_in_mask(priv, network->mode,
5327 network->rates[i])) {
5328
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005329 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005330 IPW_DEBUG_SCAN("Adding masked mandatory "
5331 "rate %02X\n",
5332 network->rates[i]);
5333 rates->supported_rates[rates->num_rates++] =
5334 network->rates[i];
5335 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005336 }
5337
James Ketrenos43f66a62005-03-25 12:31:53 -06005338 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5339 network->rates[i], priv->rates_mask);
5340 continue;
5341 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005342
James Ketrenos43f66a62005-03-25 12:31:53 -06005343 rates->supported_rates[rates->num_rates++] = network->rates[i];
5344 }
5345
James Ketrenosa613bff2005-08-24 21:43:11 -05005346 num_rates = min(network->rates_ex_len,
5347 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005348 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005349 if (!ipw_is_rate_in_mask(priv, network->mode,
5350 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005351 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005352 IPW_DEBUG_SCAN("Adding masked mandatory "
5353 "rate %02X\n",
5354 network->rates_ex[i]);
5355 rates->supported_rates[rates->num_rates++] =
5356 network->rates[i];
5357 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005358 }
5359
James Ketrenos43f66a62005-03-25 12:31:53 -06005360 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5361 network->rates_ex[i], priv->rates_mask);
5362 continue;
5363 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005364
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005365 rates->supported_rates[rates->num_rates++] =
5366 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005367 }
5368
James Ketrenosea2b26e2005-08-24 21:25:16 -05005369 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005370}
5371
Arjan van de Ven858119e2006-01-14 13:20:43 -08005372static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005373 const struct ipw_supported_rates *src)
5374{
5375 u8 i;
5376 for (i = 0; i < src->num_rates; i++)
5377 dest->supported_rates[i] = src->supported_rates[i];
5378 dest->num_rates = src->num_rates;
5379}
5380
5381/* TODO: Look at sniffed packets in the air to determine if the basic rate
5382 * mask should ever be used -- right now all callers to add the scan rates are
5383 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5384static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005385 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005386{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005387 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5388 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005389
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005390 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005391 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005392 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005393
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005394 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005395 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005396 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005397
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005398 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005399 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005400 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005401
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005402 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005403 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005404 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005405}
5406
5407static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005408 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005409{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005410 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5411 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005412
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005413 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005414 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005415 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005416
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005417 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005418 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005419 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005420
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005421 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005422 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005423 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005424
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005425 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005426 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005427 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005428
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005429 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005430 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005431 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005432
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005433 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005434 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005435 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005436
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005437 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005438 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005439 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005440
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005441 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005442 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005443 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005444}
5445
5446struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005447 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005448 struct ipw_supported_rates rates;
5449};
5450
James Ketrenosc848d0a2005-08-24 21:56:24 -05005451static int ipw_find_adhoc_network(struct ipw_priv *priv,
5452 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005453 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005454 int roaming)
5455{
5456 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005457 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005458
5459 /* Verify that this network's capability is compatible with the
5460 * current mode (AdHoc or Infrastructure) */
5461 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5462 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005463 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005464 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005465 print_ssid(ssid, network->ssid,
5466 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005467 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005468 return 0;
5469 }
5470
James Ketrenosc848d0a2005-08-24 21:56:24 -05005471 if (unlikely(roaming)) {
5472 /* If we are roaming, then ensure check if this is a valid
5473 * network to try and roam to */
5474 if ((network->ssid_len != match->network->ssid_len) ||
5475 memcmp(network->ssid, match->network->ssid,
5476 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005477 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005478 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005479 print_ssid(ssid, network->ssid,
5480 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005481 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005482 return 0;
5483 }
5484 } else {
5485 /* If an ESSID has been configured then compare the broadcast
5486 * ESSID to ours */
5487 if ((priv->config & CFG_STATIC_ESSID) &&
5488 ((network->ssid_len != priv->essid_len) ||
5489 memcmp(network->ssid, priv->essid,
5490 min(network->ssid_len, priv->essid_len)))) {
5491 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005492
James Ketrenosc848d0a2005-08-24 21:56:24 -05005493 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005494 print_ssid(ssid, network->ssid,
5495 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005496 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005497 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005498 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005499 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005500 print_ssid(ssid, priv->essid,
5501 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005502 return 0;
5503 }
5504 }
5505
5506 /* If the old network rate is better than this one, don't bother
5507 * testing everything else. */
5508
5509 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005510 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5511 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005512 print_ssid(ssid, match->network->ssid,
5513 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005514 return 0;
5515 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005516 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5517 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005518 print_ssid(ssid, match->network->ssid,
5519 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005520 return 0;
5521 }
5522
5523 /* Now go through and see if the requested network is valid... */
5524 if (priv->ieee->scan_age != 0 &&
5525 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005526 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005527 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005528 print_ssid(ssid, network->ssid,
5529 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005530 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005531 jiffies_to_msecs(jiffies -
5532 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005533 return 0;
5534 }
5535
5536 if ((priv->config & CFG_STATIC_CHANNEL) &&
5537 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005538 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005539 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005540 print_ssid(ssid, network->ssid,
5541 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005542 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005543 network->channel, priv->channel);
5544 return 0;
5545 }
5546
5547 /* Verify privacy compatability */
5548 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5549 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005550 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005551 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005552 print_ssid(ssid, network->ssid,
5553 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005554 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005555 priv->
5556 capability & CAP_PRIVACY_ON ? "on" : "off",
5557 network->
5558 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5559 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005560 return 0;
5561 }
5562
5563 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005564 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5565 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005566 ".\n", print_ssid(ssid, network->ssid,
5567 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005568 network->bssid,
5569 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005570 return 0;
5571 }
5572
5573 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005574 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005575 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005576 "because of invalid frequency/mode "
5577 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005578 print_ssid(ssid, network->ssid,
5579 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005580 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005581 return 0;
5582 }
5583
5584 /* Ensure that the rates supported by the driver are compatible with
5585 * this AP, including verification of basic rates (mandatory) */
5586 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005587 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005588 "because configured rate mask excludes "
5589 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005590 print_ssid(ssid, network->ssid,
5591 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005592 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005593 return 0;
5594 }
5595
5596 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005597 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005598 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005599 print_ssid(ssid, network->ssid,
5600 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005601 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005602 return 0;
5603 }
5604
5605 /* TODO: Perform any further minimal comparititive tests. We do not
5606 * want to put too much policy logic here; intelligent scan selection
5607 * should occur within a generic IEEE 802.11 user space tool. */
5608
5609 /* Set up 'new' AP to this network */
5610 ipw_copy_rates(&match->rates, &rates);
5611 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005612 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005613 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005614 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005615
5616 return 1;
5617}
5618
David Howellsc4028952006-11-22 14:57:56 +00005619static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005620{
John W. Linville9387b7c2008-09-30 20:59:05 -04005621 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005622 struct ipw_priv *priv =
5623 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005624 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625 struct ipw_network_match match = {
5626 .network = priv->assoc_network
5627 };
5628
James Ketrenosafbf30a2005-08-25 00:05:33 -05005629 if ((priv->status & STATUS_ASSOCIATED) &&
5630 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005631 /* First pass through ROAM process -- look for a better
5632 * network */
5633 unsigned long flags;
5634
5635 spin_lock_irqsave(&priv->ieee->lock, flags);
5636 list_for_each_entry(network, &priv->ieee->network_list, list) {
5637 if (network != priv->assoc_network)
5638 ipw_find_adhoc_network(priv, &match, network,
5639 1);
5640 }
5641 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5642
5643 if (match.network == priv->assoc_network) {
5644 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5645 "merge to.\n");
5646 return;
5647 }
5648
Zhu Yi46441512006-01-24 16:37:59 +08005649 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005650 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5651 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005652 print_ssid(ssid, priv->essid,
5653 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005654 ipw_remove_current_network(priv);
5655 }
5656
5657 ipw_disassociate(priv);
5658 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005659 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005660 return;
5661 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005662}
5663
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005664static int ipw_best_network(struct ipw_priv *priv,
5665 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005666 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005667{
5668 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005669 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005670
5671 /* Verify that this network's capability is compatible with the
5672 * current mode (AdHoc or Infrastructure) */
5673 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005674 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005675 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5676 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005677 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005678 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005679 print_ssid(ssid, network->ssid,
5680 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005681 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005682 return 0;
5683 }
5684
James Ketrenos43f66a62005-03-25 12:31:53 -06005685 if (unlikely(roaming)) {
5686 /* If we are roaming, then ensure check if this is a valid
5687 * network to try and roam to */
5688 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005689 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005690 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005691 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005692 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005693 print_ssid(ssid, network->ssid,
5694 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005695 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005696 return 0;
5697 }
5698 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005699 /* If an ESSID has been configured then compare the broadcast
5700 * ESSID to ours */
5701 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005702 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005703 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005704 min(network->ssid_len, priv->essid_len)))) {
5705 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005706 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005707 print_ssid(ssid, network->ssid,
5708 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005709 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005710 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005711 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005712 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005713 print_ssid(ssid, priv->essid,
5714 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005715 return 0;
5716 }
5717 }
5718
5719 /* If the old network rate is better than this one, don't bother
5720 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005721 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005722 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005723 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005724 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005725 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005726 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5727 "'%s (%pM)' has a stronger signal.\n",
5728 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005729 print_ssid(ssid, match->network->ssid,
5730 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005731 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005732 return 0;
5733 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005734
James Ketrenos43f66a62005-03-25 12:31:53 -06005735 /* If this network has already had an association attempt within the
5736 * last 3 seconds, do not try and associate again... */
5737 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005738 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005739 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005740 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005741 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005742 print_ssid(ssid, network->ssid,
5743 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005744 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005745 jiffies_to_msecs(jiffies -
5746 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 return 0;
5748 }
5749
5750 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005751 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005752 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005753 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005754 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005755 print_ssid(ssid, network->ssid,
5756 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005757 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005758 jiffies_to_msecs(jiffies -
5759 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005760 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005761 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005762
Jeff Garzikbf794512005-07-31 13:07:26 -04005763 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005764 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005765 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005766 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005767 print_ssid(ssid, network->ssid,
5768 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005769 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005770 network->channel, priv->channel);
5771 return 0;
5772 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005773
James Ketrenos43f66a62005-03-25 12:31:53 -06005774 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005775 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005776 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005777 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005779 print_ssid(ssid, network->ssid,
5780 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005781 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005782 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005783 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005784 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005785 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005786 return 0;
5787 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005788
5789 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005790 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005791 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5792 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005793 print_ssid(ssid, network->ssid,
5794 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005795 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005796 return 0;
5797 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005798
James Ketrenos43f66a62005-03-25 12:31:53 -06005799 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005800 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005801 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005802 "because of invalid frequency/mode "
5803 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005804 print_ssid(ssid, network->ssid,
5805 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005806 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 return 0;
5808 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005809
Liu Hong1fe0adb2005-08-19 09:33:10 -05005810 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005811 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005812 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005813 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005814 print_ssid(ssid, network->ssid,
5815 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005816 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005817 return 0;
5818 }
5819
James Ketrenosea2b26e2005-08-24 21:25:16 -05005820 /* Ensure that the rates supported by the driver are compatible with
5821 * this AP, including verification of basic rates (mandatory) */
5822 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005823 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005824 "because configured rate mask excludes "
5825 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005826 print_ssid(ssid, network->ssid,
5827 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005828 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005829 return 0;
5830 }
5831
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005833 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005834 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005835 print_ssid(ssid, network->ssid,
5836 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005837 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005838 return 0;
5839 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005840
James Ketrenos43f66a62005-03-25 12:31:53 -06005841 /* TODO: Perform any further minimal comparititive tests. We do not
5842 * want to put too much policy logic here; intelligent scan selection
5843 * should occur within a generic IEEE 802.11 user space tool. */
5844
5845 /* Set up 'new' AP to this network */
5846 ipw_copy_rates(&match->rates, &rates);
5847 match->network = network;
5848
Johannes Berge1749612008-10-27 15:59:26 -07005849 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005850 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005851 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005852
5853 return 1;
5854}
5855
Jeff Garzikbf794512005-07-31 13:07:26 -04005856static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005857 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005858{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005859 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005860 int i;
5861
James Ketrenos43f66a62005-03-25 12:31:53 -06005862 /*
5863 * For the purposes of scanning, we can set our wireless mode
5864 * to trigger scans across combinations of bands, but when it
5865 * comes to creating a new ad-hoc network, we have tell the FW
5866 * exactly which band to use.
5867 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005868 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005869 * chossen band. Attempting to create a new ad-hoc network
5870 * with an invalid channel for wireless mode will trigger a
5871 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005872 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005873 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005874 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5875 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005876 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005877 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005878 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005879 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005880 IPW_WARNING("Overriding invalid channel\n");
5881 priv->channel = geo->a[0].channel;
5882 }
5883 break;
5884
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005885 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005886 if (priv->ieee->mode & IEEE_G)
5887 network->mode = IEEE_G;
5888 else
5889 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005890 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005891 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005892 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005893 IPW_WARNING("Overriding invalid channel\n");
5894 priv->channel = geo->bg[0].channel;
5895 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005896 break;
5897
5898 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 IPW_WARNING("Overriding invalid channel\n");
5900 if (priv->ieee->mode & IEEE_A) {
5901 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005902 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005903 } else if (priv->ieee->mode & IEEE_G) {
5904 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005905 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 } else {
5907 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005908 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005909 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005910 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005911 }
5912
5913 network->channel = priv->channel;
5914 priv->config |= CFG_ADHOC_PERSIST;
5915 ipw_create_bssid(priv, network->bssid);
5916 network->ssid_len = priv->essid_len;
5917 memcpy(network->ssid, priv->essid, priv->essid_len);
5918 memset(&network->stats, 0, sizeof(network->stats));
5919 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005920 if (!(priv->config & CFG_PREAMBLE_LONG))
5921 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005922 if (priv->capability & CAP_PRIVACY_ON)
5923 network->capability |= WLAN_CAPABILITY_PRIVACY;
5924 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005925 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005926 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005927 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005928 &priv->rates.supported_rates[network->rates_len],
5929 network->rates_ex_len);
5930 network->last_scanned = 0;
5931 network->flags = 0;
5932 network->last_associate = 0;
5933 network->time_stamp[0] = 0;
5934 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005935 network->beacon_interval = 100; /* Default */
5936 network->listen_interval = 10; /* Default */
5937 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005938 network->wpa_ie_len = 0;
5939 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005940}
5941
James Ketrenosb095c382005-08-24 22:04:42 -05005942static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5943{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005944 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005945
5946 if (!(priv->ieee->sec.flags & (1 << index)))
5947 return;
5948
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005949 key.key_id = index;
5950 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5951 key.security_type = type;
5952 key.station_index = 0; /* always 0 for BSS */
5953 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005954 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005955 key.tx_counter[0] = cpu_to_le32(0);
5956 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005957
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005958 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005959}
5960
5961static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005962{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005963 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005964 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005965
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005966 key.cmd_id = DINO_CMD_WEP_KEY;
5967 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005968
James Ketrenosb095c382005-08-24 22:04:42 -05005969 /* Note: AES keys cannot be set for multiple times.
5970 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005971 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005972 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005973 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005974 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005975 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005976 }
5977
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005978 key.key_size = priv->ieee->sec.key_sizes[i];
5979 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005980
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005981 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005982 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005983}
5984
Zhu Yi1fbfea52005-08-05 17:22:56 +08005985static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5986{
5987 if (priv->ieee->host_encrypt)
5988 return;
5989
5990 switch (level) {
5991 case SEC_LEVEL_3:
5992 priv->sys_config.disable_unicast_decryption = 0;
5993 priv->ieee->host_decrypt = 0;
5994 break;
5995 case SEC_LEVEL_2:
5996 priv->sys_config.disable_unicast_decryption = 1;
5997 priv->ieee->host_decrypt = 1;
5998 break;
5999 case SEC_LEVEL_1:
6000 priv->sys_config.disable_unicast_decryption = 0;
6001 priv->ieee->host_decrypt = 0;
6002 break;
6003 case SEC_LEVEL_0:
6004 priv->sys_config.disable_unicast_decryption = 1;
6005 break;
6006 default:
6007 break;
6008 }
6009}
6010
6011static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6012{
6013 if (priv->ieee->host_encrypt)
6014 return;
6015
6016 switch (level) {
6017 case SEC_LEVEL_3:
6018 priv->sys_config.disable_multicast_decryption = 0;
6019 break;
6020 case SEC_LEVEL_2:
6021 priv->sys_config.disable_multicast_decryption = 1;
6022 break;
6023 case SEC_LEVEL_1:
6024 priv->sys_config.disable_multicast_decryption = 0;
6025 break;
6026 case SEC_LEVEL_0:
6027 priv->sys_config.disable_multicast_decryption = 1;
6028 break;
6029 default:
6030 break;
6031 }
6032}
6033
James Ketrenosb095c382005-08-24 22:04:42 -05006034static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6035{
6036 switch (priv->ieee->sec.level) {
6037 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006038 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6039 ipw_send_tgi_tx_key(priv,
6040 DCT_FLAG_EXT_SECURITY_CCM,
6041 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006042
Hong Liu567deaf2005-08-31 18:07:22 +08006043 if (!priv->ieee->host_mc_decrypt)
6044 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006045 break;
6046 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006047 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6048 ipw_send_tgi_tx_key(priv,
6049 DCT_FLAG_EXT_SECURITY_TKIP,
6050 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006051 break;
6052 case SEC_LEVEL_1:
6053 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006054 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6055 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006056 break;
6057 case SEC_LEVEL_0:
6058 default:
6059 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006060 }
6061}
6062
6063static void ipw_adhoc_check(void *data)
6064{
6065 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006066
James Ketrenosafbf30a2005-08-25 00:05:33 -05006067 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006068 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006069 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6070 IPW_DL_STATE | IPW_DL_ASSOC,
6071 "Missed beacon: %d - disassociate\n",
6072 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006073 ipw_remove_current_network(priv);
6074 ipw_disassociate(priv);
6075 return;
6076 }
6077
Jeff Garzikbf794512005-07-31 13:07:26 -04006078 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006079 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006080}
6081
David Howellsc4028952006-11-22 14:57:56 +00006082static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006083{
David Howellsc4028952006-11-22 14:57:56 +00006084 struct ipw_priv *priv =
6085 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006086 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006087 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006088 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006089}
6090
James Ketrenos43f66a62005-03-25 12:31:53 -06006091static void ipw_debug_config(struct ipw_priv *priv)
6092{
John W. Linville9387b7c2008-09-30 20:59:05 -04006093 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006094 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6095 "[CFG 0x%08X]\n", priv->config);
6096 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006097 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006098 else
6099 IPW_DEBUG_INFO("Channel unlocked.\n");
6100 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006101 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006102 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006103 else
6104 IPW_DEBUG_INFO("ESSID unlocked.\n");
6105 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006106 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006107 else
6108 IPW_DEBUG_INFO("BSSID unlocked.\n");
6109 if (priv->capability & CAP_PRIVACY_ON)
6110 IPW_DEBUG_INFO("PRIVACY on\n");
6111 else
6112 IPW_DEBUG_INFO("PRIVACY off\n");
6113 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6114}
James Ketrenos43f66a62005-03-25 12:31:53 -06006115
Arjan van de Ven858119e2006-01-14 13:20:43 -08006116static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006117{
6118 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006119 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006120 u32 reg;
6121 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006122 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006123
Jeff Garzikbf794512005-07-31 13:07:26 -04006124 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006125 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006126
James Ketrenos43f66a62005-03-25 12:31:53 -06006127 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006128 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006129 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006130 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006131 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006132 IPW_DEBUG_WX
6133 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006134 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006135 break;
6136 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006137
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006138 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006139 break;
6140
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006141 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006142 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006143 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006144 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006145 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006146 IPW_DEBUG_WX
6147 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006148 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006149 }
6150 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006151 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006152
6153 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006154 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6155 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006156 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006157 IPW_DEBUG_WX
6158 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006159 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006160 break;
6161 }
6162
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006163 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6164 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6165 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006166 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006167
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006168 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6169 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6170 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006171 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006172
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006173 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6174 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6175 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006176 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006177
Reinette Chatre21f8a732009-08-18 10:25:05 -07006178 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006179 break;
6180 }
6181
Reinette Chatre21f8a732009-08-18 10:25:05 -07006182 fr.tx_rates = cpu_to_le16(new_tx_rates);
6183
James Ketrenos43f66a62005-03-25 12:31:53 -06006184 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006185 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006186}
6187
James Ketrenosea2b26e2005-08-24 21:25:16 -05006188static void ipw_abort_scan(struct ipw_priv *priv)
6189{
6190 int err;
6191
6192 if (priv->status & STATUS_SCAN_ABORTING) {
6193 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6194 return;
6195 }
6196 priv->status |= STATUS_SCAN_ABORTING;
6197
6198 err = ipw_send_scan_abort(priv);
6199 if (err)
6200 IPW_DEBUG_HC("Request to abort scan failed.\n");
6201}
6202
James Ketrenosafbf30a2005-08-25 00:05:33 -05006203static void ipw_add_scan_channels(struct ipw_priv *priv,
6204 struct ipw_scan_request_ext *scan,
6205 int scan_type)
6206{
6207 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006208 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006209 int i;
6210
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006211 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006212
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006213 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006214 int start = channel_index;
6215 for (i = 0; i < geo->a_channels; i++) {
6216 if ((priv->status & STATUS_ASSOCIATED) &&
6217 geo->a[i].channel == priv->channel)
6218 continue;
6219 channel_index++;
6220 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006221 ipw_set_scan_type(scan, channel_index,
6222 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006223 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006224 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6225 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006226 }
6227
6228 if (start != channel_index) {
6229 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6230 (channel_index - start);
6231 channel_index++;
6232 }
6233 }
6234
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006235 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006236 int start = channel_index;
6237 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006238 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006239 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006240 /* nop out the list */
6241 [0] = 0
6242 };
6243
6244 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006245 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006246 channel =
6247 priv->speed_scan[priv->speed_scan_pos];
6248 if (channel == 0) {
6249 priv->speed_scan_pos = 0;
6250 channel = priv->speed_scan[0];
6251 }
6252 if ((priv->status & STATUS_ASSOCIATED) &&
6253 channel == priv->channel) {
6254 priv->speed_scan_pos++;
6255 continue;
6256 }
6257
6258 /* If this channel has already been
6259 * added in scan, break from loop
6260 * and this will be the first channel
6261 * in the next scan.
6262 */
6263 if (channels[channel - 1] != 0)
6264 break;
6265
6266 channels[channel - 1] = 1;
6267 priv->speed_scan_pos++;
6268 channel_index++;
6269 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006270 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006271 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006272 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006273 geo->bg[index].
6274 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006275 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006276 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6277 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006278 }
6279 } else {
6280 for (i = 0; i < geo->bg_channels; i++) {
6281 if ((priv->status & STATUS_ASSOCIATED) &&
6282 geo->bg[i].channel == priv->channel)
6283 continue;
6284 channel_index++;
6285 scan->channels_list[channel_index] =
6286 geo->bg[i].channel;
6287 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006288 geo->bg[i].
6289 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006290 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006291 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6292 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006293 }
6294 }
6295
6296 if (start != channel_index) {
6297 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6298 (channel_index - start);
6299 }
6300 }
6301}
6302
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006303static int ipw_passive_dwell_time(struct ipw_priv *priv)
6304{
6305 /* staying on passive channels longer than the DTIM interval during a
6306 * scan, while associated, causes the firmware to cancel the scan
6307 * without notification. Hence, don't stay on passive channels longer
6308 * than the beacon interval.
6309 */
6310 if (priv->status & STATUS_ASSOCIATED
6311 && priv->assoc_network->beacon_interval > 10)
6312 return priv->assoc_network->beacon_interval - 10;
6313 else
6314 return 120;
6315}
6316
Dan Williamsea177302008-06-02 17:51:23 -04006317static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006318{
6319 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006320 int err = 0, scan_type;
6321
6322 if (!(priv->status & STATUS_INIT) ||
6323 (priv->status & STATUS_EXIT_PENDING))
6324 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006325
Zhu Yi46441512006-01-24 16:37:59 +08006326 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006327
Dan Williamsea177302008-06-02 17:51:23 -04006328 if (direct && (priv->direct_scan_ssid_len == 0)) {
6329 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6330 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6331 goto done;
6332 }
6333
James Ketrenosea2b26e2005-08-24 21:25:16 -05006334 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006335 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6336 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6337 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006338 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006339 }
6340
James Ketrenosafbf30a2005-08-25 00:05:33 -05006341 if (!(priv->status & STATUS_SCAN_FORCED) &&
6342 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006343 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006344 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6345 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006346 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006347 }
6348
6349 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006350 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6351 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6352 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006353 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006354 }
6355
6356 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006357 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006358
Zhu Yi094c4d22006-08-21 11:39:03 +08006359 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006360 IPW_DEBUG_WX("use passive scanning\n");
6361 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006362 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006363 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006364 ipw_add_scan_channels(priv, &scan, scan_type);
6365 goto send_request;
6366 }
6367
6368 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006369 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006370 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006371 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006372 else
6373 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006374 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006375
James Ketrenosa613bff2005-08-24 21:43:11 -05006376 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006377 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006378
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006379 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6380 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006381 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006382
James Ketrenosb095c382005-08-24 22:04:42 -05006383#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006384 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006385 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006386 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006387
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006388 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6389 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006390 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006391 channel = priv->channel;
6392 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006393
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006394 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006396 channel = priv->channel;
6397 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006398
James Ketrenosb095c382005-08-24 22:04:42 -05006399 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006400 band = (u8) (IPW_B_MODE << 6) | 1;
6401 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006402 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006403 }
6404
James Ketrenosb095c382005-08-24 22:04:42 -05006405 scan.channels_list[0] = band;
6406 scan.channels_list[1] = channel;
6407 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006408
James Ketrenosb095c382005-08-24 22:04:42 -05006409 /* NOTE: The card will sit on this channel for this time
6410 * period. Scan aborts are timing sensitive and frequently
6411 * result in firmware restarts. As such, it is best to
6412 * set a small dwell_time here and just keep re-issuing
6413 * scans. Otherwise fast channel hopping will not actually
6414 * hop channels.
6415 *
6416 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006417 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006418 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006419 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006420#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006421 /* Honor direct scans first, otherwise if we are roaming make
6422 * this a direct scan for the current network. Finally,
6423 * ensure that every other scan is a fast channel hop scan */
6424 if (direct) {
6425 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6426 priv->direct_scan_ssid_len);
6427 if (err) {
6428 IPW_DEBUG_HC("Attempt to send SSID command "
6429 "failed\n");
6430 goto done;
6431 }
6432
6433 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6434 } else if ((priv->status & STATUS_ROAMING)
6435 || (!(priv->status & STATUS_ASSOCIATED)
6436 && (priv->config & CFG_STATIC_ESSID)
6437 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006438 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6439 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006440 IPW_DEBUG_HC("Attempt to send SSID command "
6441 "failed.\n");
6442 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006443 }
6444
6445 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006446 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006447 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006448
James Ketrenosafbf30a2005-08-25 00:05:33 -05006449 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006450#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006451 }
6452#endif
6453
Zhu Yi094c4d22006-08-21 11:39:03 +08006454send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006455 err = ipw_send_scan_request_ext(priv, &scan);
6456 if (err) {
6457 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006458 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006459 }
6460
6461 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006462 if (direct) {
6463 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6464 priv->direct_scan_ssid_len = 0;
6465 } else
6466 priv->status &= ~STATUS_SCAN_PENDING;
6467
James Ketrenosafbf30a2005-08-25 00:05:33 -05006468 queue_delayed_work(priv->workqueue, &priv->scan_check,
6469 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006470done:
Zhu Yi46441512006-01-24 16:37:59 +08006471 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006472 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006473}
6474
David Howellsc4028952006-11-22 14:57:56 +00006475static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006476{
David Howellsc4028952006-11-22 14:57:56 +00006477 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006478 container_of(work, struct ipw_priv, request_passive_scan.work);
6479 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006480}
6481
6482static void ipw_request_scan(struct work_struct *work)
6483{
6484 struct ipw_priv *priv =
6485 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006486 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6487}
6488
6489static void ipw_request_direct_scan(struct work_struct *work)
6490{
6491 struct ipw_priv *priv =
6492 container_of(work, struct ipw_priv, request_direct_scan.work);
6493 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006494}
6495
6496static void ipw_bg_abort_scan(struct work_struct *work)
6497{
6498 struct ipw_priv *priv =
6499 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006500 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006501 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006502 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006503}
6504
James Ketrenosea2b26e2005-08-24 21:25:16 -05006505static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6506{
James Ketrenosb095c382005-08-24 22:04:42 -05006507 /* This is called when wpa_supplicant loads and closes the driver
6508 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006509 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006510 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006511}
6512
James Ketrenosea2b26e2005-08-24 21:25:16 -05006513static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6514{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006515 struct libipw_device *ieee = priv->ieee;
6516 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006517 .flags = SEC_AUTH_MODE,
6518 };
6519 int ret = 0;
6520
James Ketrenosafbf30a2005-08-25 00:05:33 -05006521 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006522 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6523 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006524 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006525 sec.auth_mode = WLAN_AUTH_OPEN;
6526 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006527 } else if (value & IW_AUTH_ALG_LEAP) {
6528 sec.auth_mode = WLAN_AUTH_LEAP;
6529 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006530 } else
6531 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006532
6533 if (ieee->set_security)
6534 ieee->set_security(ieee->dev, &sec);
6535 else
6536 ret = -EOPNOTSUPP;
6537
6538 return ret;
6539}
6540
Adrian Bunka73e22b2006-01-21 01:39:42 +01006541static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6542 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006543{
6544 /* make sure WPA is enabled */
6545 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006546}
6547
6548static int ipw_set_rsn_capa(struct ipw_priv *priv,
6549 char *capabilities, int length)
6550{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006551 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6552
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006553 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006554 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006555}
6556
James Ketrenosafbf30a2005-08-25 00:05:33 -05006557/*
6558 * WE-18 support
6559 */
6560
6561/* SIOCSIWGENIE */
6562static int ipw_wx_set_genie(struct net_device *dev,
6563 struct iw_request_info *info,
6564 union iwreq_data *wrqu, char *extra)
6565{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006566 struct ipw_priv *priv = libipw_priv(dev);
6567 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006568 u8 *buf;
6569 int err = 0;
6570
6571 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6572 (wrqu->data.length && extra == NULL))
6573 return -EINVAL;
6574
James Ketrenosafbf30a2005-08-25 00:05:33 -05006575 if (wrqu->data.length) {
6576 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6577 if (buf == NULL) {
6578 err = -ENOMEM;
6579 goto out;
6580 }
6581
6582 memcpy(buf, extra, wrqu->data.length);
6583 kfree(ieee->wpa_ie);
6584 ieee->wpa_ie = buf;
6585 ieee->wpa_ie_len = wrqu->data.length;
6586 } else {
6587 kfree(ieee->wpa_ie);
6588 ieee->wpa_ie = NULL;
6589 ieee->wpa_ie_len = 0;
6590 }
6591
6592 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6593 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006594 return err;
6595}
6596
6597/* SIOCGIWGENIE */
6598static int ipw_wx_get_genie(struct net_device *dev,
6599 struct iw_request_info *info,
6600 union iwreq_data *wrqu, char *extra)
6601{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006602 struct ipw_priv *priv = libipw_priv(dev);
6603 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006604 int err = 0;
6605
James Ketrenosafbf30a2005-08-25 00:05:33 -05006606 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6607 wrqu->data.length = 0;
6608 goto out;
6609 }
6610
6611 if (wrqu->data.length < ieee->wpa_ie_len) {
6612 err = -E2BIG;
6613 goto out;
6614 }
6615
6616 wrqu->data.length = ieee->wpa_ie_len;
6617 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6618
6619 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006620 return err;
6621}
6622
Zhu Yi1fbfea52005-08-05 17:22:56 +08006623static int wext_cipher2level(int cipher)
6624{
6625 switch (cipher) {
6626 case IW_AUTH_CIPHER_NONE:
6627 return SEC_LEVEL_0;
6628 case IW_AUTH_CIPHER_WEP40:
6629 case IW_AUTH_CIPHER_WEP104:
6630 return SEC_LEVEL_1;
6631 case IW_AUTH_CIPHER_TKIP:
6632 return SEC_LEVEL_2;
6633 case IW_AUTH_CIPHER_CCMP:
6634 return SEC_LEVEL_3;
6635 default:
6636 return -1;
6637 }
6638}
6639
James Ketrenosafbf30a2005-08-25 00:05:33 -05006640/* SIOCSIWAUTH */
6641static int ipw_wx_set_auth(struct net_device *dev,
6642 struct iw_request_info *info,
6643 union iwreq_data *wrqu, char *extra)
6644{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006645 struct ipw_priv *priv = libipw_priv(dev);
6646 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006647 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006648 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006649 unsigned long flags;
6650 int ret = 0;
6651
6652 switch (param->flags & IW_AUTH_INDEX) {
6653 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006654 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006655 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006656 ipw_set_hw_decrypt_unicast(priv,
6657 wext_cipher2level(param->value));
6658 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006659 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006660 ipw_set_hw_decrypt_multicast(priv,
6661 wext_cipher2level(param->value));
6662 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663 case IW_AUTH_KEY_MGMT:
6664 /*
6665 * ipw2200 does not use these parameters
6666 */
6667 break;
6668
6669 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006670 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006671 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006672 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006673
6674 flags = crypt->ops->get_flags(crypt->priv);
6675
6676 if (param->value)
6677 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6678 else
6679 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6680
6681 crypt->ops->set_flags(flags, crypt->priv);
6682
6683 break;
6684
6685 case IW_AUTH_DROP_UNENCRYPTED:{
6686 /* HACK:
6687 *
6688 * wpa_supplicant calls set_wpa_enabled when the driver
6689 * is loaded and unloaded, regardless of if WPA is being
6690 * used. No other calls are made which can be used to
6691 * determine if encryption will be used or not prior to
6692 * association being expected. If encryption is not being
6693 * used, drop_unencrypted is set to false, else true -- we
6694 * can use this to determine if the CAP_PRIVACY_ON bit should
6695 * be set.
6696 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006697 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006698 .flags = SEC_ENABLED,
6699 .enabled = param->value,
6700 };
6701 priv->ieee->drop_unencrypted = param->value;
6702 /* We only change SEC_LEVEL for open mode. Others
6703 * are set by ipw_wpa_set_encryption.
6704 */
6705 if (!param->value) {
6706 sec.flags |= SEC_LEVEL;
6707 sec.level = SEC_LEVEL_0;
6708 } else {
6709 sec.flags |= SEC_LEVEL;
6710 sec.level = SEC_LEVEL_1;
6711 }
6712 if (priv->ieee->set_security)
6713 priv->ieee->set_security(priv->ieee->dev, &sec);
6714 break;
6715 }
6716
6717 case IW_AUTH_80211_AUTH_ALG:
6718 ret = ipw_wpa_set_auth_algs(priv, param->value);
6719 break;
6720
6721 case IW_AUTH_WPA_ENABLED:
6722 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006723 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006724 break;
6725
6726 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6727 ieee->ieee802_1x = param->value;
6728 break;
6729
James Ketrenosafbf30a2005-08-25 00:05:33 -05006730 case IW_AUTH_PRIVACY_INVOKED:
6731 ieee->privacy_invoked = param->value;
6732 break;
6733
6734 default:
6735 return -EOPNOTSUPP;
6736 }
6737 return ret;
6738}
6739
6740/* SIOCGIWAUTH */
6741static int ipw_wx_get_auth(struct net_device *dev,
6742 struct iw_request_info *info,
6743 union iwreq_data *wrqu, char *extra)
6744{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006745 struct ipw_priv *priv = libipw_priv(dev);
6746 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006747 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006748 struct iw_param *param = &wrqu->param;
6749 int ret = 0;
6750
6751 switch (param->flags & IW_AUTH_INDEX) {
6752 case IW_AUTH_WPA_VERSION:
6753 case IW_AUTH_CIPHER_PAIRWISE:
6754 case IW_AUTH_CIPHER_GROUP:
6755 case IW_AUTH_KEY_MGMT:
6756 /*
6757 * wpa_supplicant will control these internally
6758 */
6759 ret = -EOPNOTSUPP;
6760 break;
6761
6762 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006763 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006764 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006765 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006766
6767 param->value = (crypt->ops->get_flags(crypt->priv) &
6768 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6769
6770 break;
6771
6772 case IW_AUTH_DROP_UNENCRYPTED:
6773 param->value = ieee->drop_unencrypted;
6774 break;
6775
6776 case IW_AUTH_80211_AUTH_ALG:
6777 param->value = ieee->sec.auth_mode;
6778 break;
6779
6780 case IW_AUTH_WPA_ENABLED:
6781 param->value = ieee->wpa_enabled;
6782 break;
6783
6784 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6785 param->value = ieee->ieee802_1x;
6786 break;
6787
6788 case IW_AUTH_ROAMING_CONTROL:
6789 case IW_AUTH_PRIVACY_INVOKED:
6790 param->value = ieee->privacy_invoked;
6791 break;
6792
6793 default:
6794 return -EOPNOTSUPP;
6795 }
6796 return 0;
6797}
6798
6799/* SIOCSIWENCODEEXT */
6800static int ipw_wx_set_encodeext(struct net_device *dev,
6801 struct iw_request_info *info,
6802 union iwreq_data *wrqu, char *extra)
6803{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006804 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006805 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6806
6807 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006808 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006809 /* IPW HW can't build TKIP MIC,
6810 host decryption still needed */
6811 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6812 priv->ieee->host_mc_decrypt = 1;
6813 else {
6814 priv->ieee->host_encrypt = 0;
6815 priv->ieee->host_encrypt_msdu = 1;
6816 priv->ieee->host_decrypt = 1;
6817 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006818 } else {
6819 priv->ieee->host_encrypt = 0;
6820 priv->ieee->host_encrypt_msdu = 0;
6821 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006822 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006823 }
6824 }
6825
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006826 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006827}
6828
6829/* SIOCGIWENCODEEXT */
6830static int ipw_wx_get_encodeext(struct net_device *dev,
6831 struct iw_request_info *info,
6832 union iwreq_data *wrqu, char *extra)
6833{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006834 struct ipw_priv *priv = libipw_priv(dev);
6835 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006836}
6837
6838/* SIOCSIWMLME */
6839static int ipw_wx_set_mlme(struct net_device *dev,
6840 struct iw_request_info *info,
6841 union iwreq_data *wrqu, char *extra)
6842{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006843 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006844 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006845 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006846
6847 reason = cpu_to_le16(mlme->reason_code);
6848
6849 switch (mlme->cmd) {
6850 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006851 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006852 break;
6853
6854 case IW_MLME_DISASSOC:
6855 ipw_disassociate(priv);
6856 break;
6857
6858 default:
6859 return -EOPNOTSUPP;
6860 }
6861 return 0;
6862}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006863
Zhu Yie43e3c12006-04-13 17:20:45 +08006864#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006865
6866/* QoS */
6867/*
6868* get the modulation type of the current network or
6869* the card current mode
6870*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006871static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006872{
6873 u8 mode = 0;
6874
6875 if (priv->status & STATUS_ASSOCIATED) {
6876 unsigned long flags;
6877
6878 spin_lock_irqsave(&priv->ieee->lock, flags);
6879 mode = priv->assoc_network->mode;
6880 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6881 } else {
6882 mode = priv->ieee->mode;
6883 }
6884 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6885 return mode;
6886}
6887
6888/*
6889* Handle management frame beacon and probe response
6890*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006891static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6892 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006893 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006894{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006895 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006896
James Ketrenosafbf30a2005-08-25 00:05:33 -05006897 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006898 network->qos_data.active = network->qos_data.supported;
6899
6900 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006901 if (active_network &&
6902 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006903 network->qos_data.active = network->qos_data.supported;
6904
6905 if ((network->qos_data.active == 1) && (active_network == 1) &&
6906 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6907 (network->qos_data.old_param_count !=
6908 network->qos_data.param_count)) {
6909 network->qos_data.old_param_count =
6910 network->qos_data.param_count;
6911 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006912 IPW_DEBUG_QOS("QoS parameters change call "
6913 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006914 }
6915 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006916 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6917 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006918 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006919 else
6920 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006921 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006922
James Ketrenosb095c382005-08-24 22:04:42 -05006923 if ((network->qos_data.active == 1) && (active_network == 1)) {
6924 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6925 schedule_work(&priv->qos_activate);
6926 }
6927
6928 network->qos_data.active = 0;
6929 network->qos_data.supported = 0;
6930 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006931 if ((priv->status & STATUS_ASSOCIATED) &&
6932 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6933 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006934 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006935 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006936 priv->assoc_network->ssid_len) &&
6937 !memcmp(network->ssid,
6938 priv->assoc_network->ssid,
6939 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006940 queue_work(priv->workqueue,
6941 &priv->merge_networks);
6942 }
James Ketrenosb095c382005-08-24 22:04:42 -05006943 }
6944
6945 return 0;
6946}
6947
6948/*
6949* This function set up the firmware to support QoS. It sends
6950* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6951*/
6952static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006953 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006954{
6955 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006956 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6957 struct libipw_qos_parameters *active_one = NULL;
6958 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006959 u32 burst_duration;
6960 int i;
6961 u8 type;
6962
6963 type = ipw_qos_current_mode(priv);
6964
6965 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6966 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6967 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6968 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6969
6970 if (qos_network_data == NULL) {
6971 if (type == IEEE_B) {
6972 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6973 active_one = &def_parameters_CCK;
6974 } else
6975 active_one = &def_parameters_OFDM;
6976
James Ketrenosafbf30a2005-08-25 00:05:33 -05006977 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006978 burst_duration = ipw_qos_get_burst_duration(priv);
6979 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006980 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05006981 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006982 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006983 if (type == IEEE_B) {
6984 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6985 type);
6986 if (priv->qos_data.qos_enable == 0)
6987 active_one = &def_parameters_CCK;
6988 else
6989 active_one = priv->qos_data.def_qos_parm_CCK;
6990 } else {
6991 if (priv->qos_data.qos_enable == 0)
6992 active_one = &def_parameters_OFDM;
6993 else
6994 active_one = priv->qos_data.def_qos_parm_OFDM;
6995 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006996 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006997 } else {
6998 unsigned long flags;
6999 int active;
7000
7001 spin_lock_irqsave(&priv->ieee->lock, flags);
7002 active_one = &(qos_network_data->parameters);
7003 qos_network_data->old_param_count =
7004 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007005 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007006 active = qos_network_data->supported;
7007 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7008
7009 if (active == 0) {
7010 burst_duration = ipw_qos_get_burst_duration(priv);
7011 for (i = 0; i < QOS_QUEUE_NUM; i++)
7012 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007013 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007014 }
7015 }
7016
7017 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007018 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007019 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007020 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007021 if (err)
7022 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7023
7024 return err;
7025}
7026
7027/*
7028* send IPW_CMD_WME_INFO to the firmware
7029*/
7030static int ipw_qos_set_info_element(struct ipw_priv *priv)
7031{
7032 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007033 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007034
7035 if (priv == NULL)
7036 return -1;
7037
7038 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007039 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007040
7041 qos_info.version = QOS_VERSION_1;
7042 qos_info.ac_info = 0;
7043
7044 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7045 qos_info.qui_type = QOS_OUI_TYPE;
7046 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7047
7048 ret = ipw_send_qos_info_command(priv, &qos_info);
7049 if (ret != 0) {
7050 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7051 }
7052 return ret;
7053}
7054
7055/*
7056* Set the QoS parameter with the association request structure
7057*/
7058static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007059 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007060{
7061 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007062 struct libipw_qos_data *qos_data = NULL;
7063 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007064 .supported = 1,
7065 .active = 1,
7066 };
7067
7068 switch (priv->ieee->iw_mode) {
7069 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007070 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007071
7072 qos_data = &ibss_data;
7073 break;
7074
7075 case IW_MODE_INFRA:
7076 qos_data = &network->qos_data;
7077 break;
7078
7079 default:
7080 BUG();
7081 break;
7082 }
7083
7084 err = ipw_qos_activate(priv, qos_data);
7085 if (err) {
7086 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7087 return err;
7088 }
7089
7090 if (priv->qos_data.qos_enable && qos_data->supported) {
7091 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7092 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7093 return ipw_qos_set_info_element(priv);
7094 }
7095
7096 return 0;
7097}
7098
7099/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007100* handling the beaconing responses. if we get different QoS setting
7101* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007102* setting
7103*/
7104static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007105 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007106{
7107 int ret = 0;
7108 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007109 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007110 int set_qos_param = 0;
7111
James Ketrenosafbf30a2005-08-25 00:05:33 -05007112 if ((priv == NULL) || (network == NULL) ||
7113 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007114 return ret;
7115
7116 if (!(priv->status & STATUS_ASSOCIATED))
7117 return ret;
7118
James Ketrenosafbf30a2005-08-25 00:05:33 -05007119 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007120 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007121
7122 spin_lock_irqsave(&priv->ieee->lock, flags);
7123 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007124 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007125 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007126 priv->assoc_network->qos_data.active = 1;
7127 if ((network->qos_data.old_param_count !=
7128 network->qos_data.param_count)) {
7129 set_qos_param = 1;
7130 network->qos_data.old_param_count =
7131 network->qos_data.param_count;
7132 }
7133
7134 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007135 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7136 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007137 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007138 else
7139 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007140 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007141 priv->assoc_network->qos_data.active = 0;
7142 priv->assoc_network->qos_data.supported = 0;
7143 set_qos_param = 1;
7144 }
7145
7146 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7147
7148 if (set_qos_param == 1)
7149 schedule_work(&priv->qos_activate);
7150
7151 return ret;
7152}
7153
7154static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7155{
7156 u32 ret = 0;
7157
7158 if ((priv == NULL))
7159 return 0;
7160
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007161 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007162 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007163 else
James Ketrenosb095c382005-08-24 22:04:42 -05007164 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007165
James Ketrenosb095c382005-08-24 22:04:42 -05007166 return ret;
7167}
7168
7169/*
7170* Initialize the setting of QoS global
7171*/
7172static void ipw_qos_init(struct ipw_priv *priv, int enable,
7173 int burst_enable, u32 burst_duration_CCK,
7174 u32 burst_duration_OFDM)
7175{
7176 priv->qos_data.qos_enable = enable;
7177
7178 if (priv->qos_data.qos_enable) {
7179 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7180 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7181 IPW_DEBUG_QOS("QoS is enabled\n");
7182 } else {
7183 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7184 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7185 IPW_DEBUG_QOS("QoS is not enabled\n");
7186 }
7187
7188 priv->qos_data.burst_enable = burst_enable;
7189
7190 if (burst_enable) {
7191 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7192 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7193 } else {
7194 priv->qos_data.burst_duration_CCK = 0;
7195 priv->qos_data.burst_duration_OFDM = 0;
7196 }
7197}
7198
7199/*
7200* map the packet priority to the right TX Queue
7201*/
7202static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7203{
7204 if (priority > 7 || !priv->qos_data.qos_enable)
7205 priority = 0;
7206
7207 return from_priority_to_tx_queue[priority] - 1;
7208}
7209
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007210static int ipw_is_qos_active(struct net_device *dev,
7211 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007212{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007213 struct ipw_priv *priv = libipw_priv(dev);
7214 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007215 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007216 u8 *daddr = skb->data + ETH_ALEN;
7217 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007218
7219 if (!(priv->status & STATUS_ASSOCIATED))
7220 return 0;
7221
7222 qos_data = &priv->assoc_network->qos_data;
7223
James Ketrenosb095c382005-08-24 22:04:42 -05007224 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7225 if (unicast == 0)
7226 qos_data->active = 0;
7227 else
7228 qos_data->active = qos_data->supported;
7229 }
James Ketrenosb095c382005-08-24 22:04:42 -05007230 active = qos_data->active;
7231 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007232 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7233 "unicast %d\n",
7234 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007235 if (active && priv->qos_data.qos_enable)
7236 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007237
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007238 return 0;
7239
7240}
7241/*
7242* add QoS parameter to the TX command
7243*/
7244static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7245 u16 priority,
7246 struct tfd_data *tfd)
7247{
7248 int tx_queue_id = 0;
7249
7250
7251 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7252 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7253
7254 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7255 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007256 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007257 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007258 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007259}
7260
7261/*
7262* background support to run QoS activate functionality
7263*/
David Howellsc4028952006-11-22 14:57:56 +00007264static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007265{
David Howellsc4028952006-11-22 14:57:56 +00007266 struct ipw_priv *priv =
7267 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007268
Zhu Yi46441512006-01-24 16:37:59 +08007269 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007270
7271 if (priv->status & STATUS_ASSOCIATED)
7272 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7273
Zhu Yi46441512006-01-24 16:37:59 +08007274 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007275}
7276
James Ketrenos3b9990c2005-08-19 13:18:55 -05007277static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007278 struct libipw_probe_response *resp,
7279 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007280{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007281 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007282 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7283 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007284
James Ketrenos3b9990c2005-08-19 13:18:55 -05007285 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007286
James Ketrenos3b9990c2005-08-19 13:18:55 -05007287 return 0;
7288}
James Ketrenosb095c382005-08-24 22:04:42 -05007289
James Ketrenos3b9990c2005-08-19 13:18:55 -05007290static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007291 struct libipw_beacon *resp,
7292 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007293{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007294 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007295 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7296 (network == priv->assoc_network));
7297
7298 ipw_qos_handle_probe_response(priv, active_network, network);
7299
7300 return 0;
7301}
7302
7303static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007304 struct libipw_assoc_response *resp,
7305 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007306{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007307 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007308 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007309 return 0;
7310}
7311
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007312static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007313 *qos_param)
7314{
Zhu Yi4e226992006-01-24 16:37:36 +08007315 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7316 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007317}
7318
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007319static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007320 *qos_param)
7321{
Zhu Yi4e226992006-01-24 16:37:36 +08007322 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7323 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007324}
7325
Zhu Yie43e3c12006-04-13 17:20:45 +08007326#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007327
James Ketrenos43f66a62005-03-25 12:31:53 -06007328static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007329 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007330 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007331{
7332 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007333 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007334
7335 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007336 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007337
7338 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007339 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007340 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007341 memcpy(priv->essid, network->ssid, priv->essid_len);
7342 }
7343
7344 network->last_associate = jiffies;
7345
7346 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7347 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007348 priv->assoc_request.auth_key = 0;
7349
James Ketrenos43f66a62005-03-25 12:31:53 -06007350 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007351 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007352 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007353 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7354
Zhu Yi1ba61e02006-02-15 13:00:55 +08007355 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007356 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007357
7358 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7359 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7360 priv->assoc_request.auth_type = AUTH_LEAP;
7361 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007362 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007363
James Ketrenosa613bff2005-08-24 21:43:11 -05007364 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007365 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007366 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7367 priv->ieee->wpa_ie_len);
7368 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007369
Jeff Garzikbf794512005-07-31 13:07:26 -04007370 /*
7371 * It is valid for our ieee device to support multiple modes, but
7372 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007373 * just one mode.
7374 */
7375 if (network->mode & priv->ieee->mode & IEEE_A)
7376 priv->assoc_request.ieee_mode = IPW_A_MODE;
7377 else if (network->mode & priv->ieee->mode & IEEE_G)
7378 priv->assoc_request.ieee_mode = IPW_G_MODE;
7379 else if (network->mode & priv->ieee->mode & IEEE_B)
7380 priv->assoc_request.ieee_mode = IPW_B_MODE;
7381
Al Viro5b5e8072007-12-27 01:54:06 -05007382 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007383 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7384 && !(priv->config & CFG_PREAMBLE_LONG)) {
7385 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7386 } else {
7387 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7388
7389 /* Clear the short preamble if we won't be supporting it */
7390 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007391 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007392 }
7393
James Ketrenosafbf30a2005-08-25 00:05:33 -05007394 /* Clear capability bits that aren't used in Ad Hoc */
7395 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7396 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007397 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007398
James Ketrenos43f66a62005-03-25 12:31:53 -06007399 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007400 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007401 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007402 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007403 network->channel,
7404 ipw_modes[priv->assoc_request.ieee_mode],
7405 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007406 (priv->assoc_request.preamble_length ==
7407 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7408 network->capability &
7409 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007410 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007411 priv->capability & CAP_PRIVACY_ON ?
7412 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007413 "(open)") : "",
7414 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007415 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007416 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007417 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007418
Al Viro5b5e8072007-12-27 01:54:06 -05007419 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007420 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007421 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007422 priv->assoc_request.assoc_type = HC_IBSS_START;
7423 priv->assoc_request.assoc_tsf_msw = 0;
7424 priv->assoc_request.assoc_tsf_lsw = 0;
7425 } else {
7426 if (unlikely(roaming))
7427 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7428 else
7429 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007430 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7431 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007432 }
7433
James Ketrenosafbf30a2005-08-25 00:05:33 -05007434 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007435
7436 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7437 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007438 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007439 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007440 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007441 priv->assoc_request.atim_window = 0;
7442 }
7443
Al Viro5b5e8072007-12-27 01:54:06 -05007444 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007445
James Ketrenos43f66a62005-03-25 12:31:53 -06007446 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7447 if (err) {
7448 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7449 return err;
7450 }
7451
7452 rates->ieee_mode = priv->assoc_request.ieee_mode;
7453 rates->purpose = IPW_RATE_CONNECT;
7454 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007455
James Ketrenos43f66a62005-03-25 12:31:53 -06007456 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7457 priv->sys_config.dot11g_auto_detection = 1;
7458 else
7459 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007460
7461 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7462 priv->sys_config.answer_broadcast_ssid_probe = 1;
7463 else
7464 priv->sys_config.answer_broadcast_ssid_probe = 0;
7465
Zhu Yid685b8c2006-04-13 17:20:27 +08007466 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007467 if (err) {
7468 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7469 return err;
7470 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007471
James Ketrenos43f66a62005-03-25 12:31:53 -06007472 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007473 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007474 if (err) {
7475 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7476 return err;
7477 }
7478
7479 /*
7480 * If preemption is enabled, it is possible for the association
7481 * to complete before we return from ipw_send_associate. Therefore
7482 * we have to be sure and update our priviate data first.
7483 */
7484 priv->channel = network->channel;
7485 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007486 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007487 priv->status &= ~STATUS_SECURITY_UPDATED;
7488
7489 priv->assoc_network = network;
7490
Zhu Yie43e3c12006-04-13 17:20:45 +08007491#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007492 ipw_qos_association(priv, network);
7493#endif
7494
James Ketrenos43f66a62005-03-25 12:31:53 -06007495 err = ipw_send_associate(priv, &priv->assoc_request);
7496 if (err) {
7497 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7498 return err;
7499 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007500
Johannes Berge1749612008-10-27 15:59:26 -07007501 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007502 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007503 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007504
7505 return 0;
7506}
7507
7508static void ipw_roam(void *data)
7509{
7510 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007511 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007512 struct ipw_network_match match = {
7513 .network = priv->assoc_network
7514 };
7515
7516 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007517 *
7518 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007519 * setting the status ROAM bit and requesting a scan.
7520 * 2. When the scan completes, it schedules the ROAM work
7521 * 3. The ROAM work looks at all of the known networks for one that
7522 * is a better network than the currently associated. If none
7523 * found, the ROAM process is over (ROAM bit cleared)
7524 * 4. If a better network is found, a disassociation request is
7525 * sent.
7526 * 5. When the disassociation completes, the roam work is again
7527 * scheduled. The second time through, the driver is no longer
7528 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007529 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007530 * 6. At this point ,the roaming process is complete and the ROAM
7531 * status bit is cleared.
7532 */
7533
7534 /* If we are no longer associated, and the roaming bit is no longer
7535 * set, then we are not actively roaming, so just return */
7536 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7537 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007538
James Ketrenos43f66a62005-03-25 12:31:53 -06007539 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007540 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007541 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007542 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007543 u8 rssi = priv->assoc_network->stats.rssi;
7544 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007545 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 list_for_each_entry(network, &priv->ieee->network_list, list) {
7547 if (network != priv->assoc_network)
7548 ipw_best_network(priv, &match, network, 1);
7549 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007550 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007551 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007552
James Ketrenos43f66a62005-03-25 12:31:53 -06007553 if (match.network == priv->assoc_network) {
7554 IPW_DEBUG_ASSOC("No better APs in this network to "
7555 "roam to.\n");
7556 priv->status &= ~STATUS_ROAMING;
7557 ipw_debug_config(priv);
7558 return;
7559 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007560
James Ketrenos43f66a62005-03-25 12:31:53 -06007561 ipw_send_disassociate(priv, 1);
7562 priv->assoc_network = match.network;
7563
7564 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007565 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007566
7567 /* Second pass through ROAM process -- request association */
7568 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7569 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7570 priv->status &= ~STATUS_ROAMING;
7571}
7572
David Howellsc4028952006-11-22 14:57:56 +00007573static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007574{
David Howellsc4028952006-11-22 14:57:56 +00007575 struct ipw_priv *priv =
7576 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007577 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007578 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007579 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007580}
7581
7582static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007583{
7584 struct ipw_priv *priv = data;
7585
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007586 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007587 struct ipw_network_match match = {
7588 .network = NULL
7589 };
7590 struct ipw_supported_rates *rates;
7591 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007592 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007593 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007594
James Ketrenosb095c382005-08-24 22:04:42 -05007595 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7596 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7597 return 0;
7598 }
7599
James Ketrenosc848d0a2005-08-24 21:56:24 -05007600 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007601 IPW_DEBUG_ASSOC("Not attempting association (already in "
7602 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007603 return 0;
7604 }
7605
Hong Liue6324722005-09-14 21:04:15 -05007606 if (priv->status & STATUS_DISASSOCIATING) {
7607 IPW_DEBUG_ASSOC("Not attempting association (in "
7608 "disassociating)\n ");
7609 queue_work(priv->workqueue, &priv->associate);
7610 return 0;
7611 }
7612
James Ketrenosc848d0a2005-08-24 21:56:24 -05007613 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007614 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7615 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007616 return 0;
7617 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007618
7619 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007620 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007621 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007622 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007623 }
7624
James Ketrenosa613bff2005-08-24 21:43:11 -05007625 /* Protect our use of the network_list */
7626 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007627 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007628 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007629
7630 network = match.network;
7631 rates = &match.rates;
7632
7633 if (network == NULL &&
7634 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7635 priv->config & CFG_ADHOC_CREATE &&
7636 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007637 priv->config & CFG_STATIC_CHANNEL) {
7638 /* Use oldest network if the free list is empty */
7639 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007640 struct libipw_network *oldest = NULL;
7641 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007642
7643 list_for_each_entry(target, &priv->ieee->network_list, list) {
7644 if ((oldest == NULL) ||
7645 (target->last_scanned < oldest->last_scanned))
7646 oldest = target;
7647 }
7648
7649 /* If there are no more slots, expire the oldest */
7650 list_del(&oldest->list);
7651 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007652 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007653 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007654 print_ssid(ssid, target->ssid,
7655 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007656 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007657 list_add_tail(&target->list,
7658 &priv->ieee->network_free_list);
7659 }
7660
James Ketrenos43f66a62005-03-25 12:31:53 -06007661 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007662 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007663 ipw_adhoc_create(priv, network);
7664 rates = &priv->rates;
7665 list_del(element);
7666 list_add_tail(&network->list, &priv->ieee->network_list);
7667 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007668 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007669
James Ketrenos43f66a62005-03-25 12:31:53 -06007670 /* If we reached the end of the list, then we don't have any valid
7671 * matching APs */
7672 if (!network) {
7673 ipw_debug_config(priv);
7674
James Ketrenosb095c382005-08-24 22:04:42 -05007675 if (!(priv->status & STATUS_SCANNING)) {
7676 if (!(priv->config & CFG_SPEED_SCAN))
7677 queue_delayed_work(priv->workqueue,
7678 &priv->request_scan,
7679 SCAN_INTERVAL);
7680 else
David Howellsc4028952006-11-22 14:57:56 +00007681 queue_delayed_work(priv->workqueue,
7682 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007683 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007684
James Ketrenosc848d0a2005-08-24 21:56:24 -05007685 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007686 }
7687
7688 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007689
7690 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007691}
Jeff Garzikbf794512005-07-31 13:07:26 -04007692
David Howellsc4028952006-11-22 14:57:56 +00007693static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007694{
David Howellsc4028952006-11-22 14:57:56 +00007695 struct ipw_priv *priv =
7696 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007697 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007698 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007699 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007700}
7701
James Ketrenosb095c382005-08-24 22:04:42 -05007702static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7703 struct sk_buff *skb)
7704{
7705 struct ieee80211_hdr *hdr;
7706 u16 fc;
7707
7708 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007709 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007710 if (!(fc & IEEE80211_FCTL_PROTECTED))
7711 return;
7712
7713 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007714 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007715 switch (priv->ieee->sec.level) {
7716 case SEC_LEVEL_3:
7717 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007718 memmove(skb->data + LIBIPW_3ADDR_LEN,
7719 skb->data + LIBIPW_3ADDR_LEN + 8,
7720 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007721 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007722 break;
7723 case SEC_LEVEL_2:
7724 break;
7725 case SEC_LEVEL_1:
7726 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007727 memmove(skb->data + LIBIPW_3ADDR_LEN,
7728 skb->data + LIBIPW_3ADDR_LEN + 4,
7729 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007730 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007731 break;
7732 case SEC_LEVEL_0:
7733 break;
7734 default:
7735 printk(KERN_ERR "Unknow security level %d\n",
7736 priv->ieee->sec.level);
7737 break;
7738 }
7739}
7740
7741static void ipw_handle_data_packet(struct ipw_priv *priv,
7742 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007743 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007744{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007745 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007746 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007747 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7748
7749 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007750 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007751
Jeff Garzikbf794512005-07-31 13:07:26 -04007752 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007753 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007754 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007755 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007756 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007757 priv->wstats.discard.misc++;
7758 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7759 return;
7760 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007761 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007762 priv->wstats.discard.misc++;
7763 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7764 return;
7765 }
7766
7767 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007768 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007769
7770 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007771 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007772
7773 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7774
James Ketrenosb095c382005-08-24 22:04:42 -05007775 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007776 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007777 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007778 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007779 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007780 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7781
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007782 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007783 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007784 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007785 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007786 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007787 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007788}
7789
Zhu Yi459d4082006-04-13 17:21:00 +08007790#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007791static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7792 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007793 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007794{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007795 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007796 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7797 struct ipw_rx_frame *frame = &pkt->u.frame;
7798
7799 /* initial pull of some data */
7800 u16 received_channel = frame->received_channel;
7801 u8 antennaAndPhy = frame->antennaAndPhy;
7802 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7803 u16 pktrate = frame->rate;
7804
7805 /* Magic struct that slots into the radiotap header -- no reason
7806 * to build this manually element by element, we can write it much
7807 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007808 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007809
7810 short len = le16_to_cpu(pkt->u.frame.length);
7811
7812 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007813 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007814
7815 /* We only process data packets if the
7816 * interface is open */
7817 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7818 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007819 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007820 priv->wstats.discard.misc++;
7821 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7822 return;
7823 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007824 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007825 priv->wstats.discard.misc++;
7826 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7827 return;
7828 }
7829
7830 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7831 * that now */
7832 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7833 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007834 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007835 priv->wstats.discard.misc++;
7836 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7837 return;
7838 }
7839
7840 /* copy the frame itself */
7841 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7842 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7843
Mike Kershaw24a47db2005-08-26 00:41:54 -05007844 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7845
7846 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7847 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007848 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007849
7850 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007851 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7852 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007853 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007854 (1 << IEEE80211_RADIOTAP_RATE) |
7855 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7856 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007857 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007858 (1 << IEEE80211_RADIOTAP_ANTENNA));
7859
7860 /* Zero the flags, we'll add to them as we go */
7861 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007862 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7863 frame->parent_tsf[2] << 16 |
7864 frame->parent_tsf[1] << 8 |
7865 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007866
7867 /* Convert signal to DBM */
7868 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007869 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007870
7871 /* Convert the channel data and set the flags */
7872 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7873 if (received_channel > 14) { /* 802.11a */
7874 ipw_rt->rt_chbitmask =
7875 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7876 } else if (antennaAndPhy & 32) { /* 802.11b */
7877 ipw_rt->rt_chbitmask =
7878 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7879 } else { /* 802.11g */
7880 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007881 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007882 }
7883
7884 /* set the rate in multiples of 500k/s */
7885 switch (pktrate) {
7886 case IPW_TX_RATE_1MB:
7887 ipw_rt->rt_rate = 2;
7888 break;
7889 case IPW_TX_RATE_2MB:
7890 ipw_rt->rt_rate = 4;
7891 break;
7892 case IPW_TX_RATE_5MB:
7893 ipw_rt->rt_rate = 10;
7894 break;
7895 case IPW_TX_RATE_6MB:
7896 ipw_rt->rt_rate = 12;
7897 break;
7898 case IPW_TX_RATE_9MB:
7899 ipw_rt->rt_rate = 18;
7900 break;
7901 case IPW_TX_RATE_11MB:
7902 ipw_rt->rt_rate = 22;
7903 break;
7904 case IPW_TX_RATE_12MB:
7905 ipw_rt->rt_rate = 24;
7906 break;
7907 case IPW_TX_RATE_18MB:
7908 ipw_rt->rt_rate = 36;
7909 break;
7910 case IPW_TX_RATE_24MB:
7911 ipw_rt->rt_rate = 48;
7912 break;
7913 case IPW_TX_RATE_36MB:
7914 ipw_rt->rt_rate = 72;
7915 break;
7916 case IPW_TX_RATE_48MB:
7917 ipw_rt->rt_rate = 96;
7918 break;
7919 case IPW_TX_RATE_54MB:
7920 ipw_rt->rt_rate = 108;
7921 break;
7922 default:
7923 ipw_rt->rt_rate = 0;
7924 break;
7925 }
7926
7927 /* antenna number */
7928 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7929
7930 /* set the preamble flag if we have it */
7931 if ((antennaAndPhy & 64))
7932 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7933
7934 /* Set the size of the skb to the size of the frame */
7935 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007936
7937 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7938
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007939 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007940 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007941 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007942 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007943 /* no LED during capture */
7944 }
7945}
7946#endif
7947
Zhu Yid685b8c2006-04-13 17:20:27 +08007948#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007949#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007950 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7951 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7952
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007953#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007954 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7955
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007956#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007957 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7958
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007959#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007960 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7961
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007962#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007963 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7964
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007965#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007966 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7967
7968static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7969 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007970 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08007971{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007972 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08007973 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7974 struct ipw_rx_frame *frame = &pkt->u.frame;
7975 struct ipw_rt_hdr *ipw_rt;
7976
7977 /* First cache any information we need before we overwrite
7978 * the information provided in the skb from the hardware */
7979 struct ieee80211_hdr *hdr;
7980 u16 channel = frame->received_channel;
7981 u8 phy_flags = frame->antennaAndPhy;
7982 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007983 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08007984 u8 rate = frame->rate;
7985 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08007986 struct sk_buff *skb;
7987 int hdr_only = 0;
7988 u16 filter = priv->prom_priv->filter;
7989
7990 /* If the filter is set to not include Rx frames then return */
7991 if (filter & IPW_PROM_NO_RX)
7992 return;
7993
Zhu Yid685b8c2006-04-13 17:20:27 +08007994 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007995 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08007996
7997 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007998 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08007999 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8000 return;
8001 }
8002
8003 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008004 if (unlikely(!netif_running(dev))) {
8005 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008006 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8007 return;
8008 }
8009
8010 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8011 * that now */
8012 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8013 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008014 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008015 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8016 return;
8017 }
8018
8019 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008020 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008021 if (filter & IPW_PROM_NO_MGMT)
8022 return;
8023 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8024 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008025 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008026 if (filter & IPW_PROM_NO_CTL)
8027 return;
8028 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8029 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008030 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008031 if (filter & IPW_PROM_NO_DATA)
8032 return;
8033 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8034 hdr_only = 1;
8035 }
8036
8037 /* Copy the SKB since this is for the promiscuous side */
8038 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8039 if (skb == NULL) {
8040 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8041 return;
8042 }
8043
8044 /* copy the frame data to write after where the radiotap header goes */
8045 ipw_rt = (void *)skb->data;
8046
8047 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008048 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008049
8050 memcpy(ipw_rt->payload, hdr, len);
8051
Zhu Yid685b8c2006-04-13 17:20:27 +08008052 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8053 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008054 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008055
8056 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008057 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008058
8059 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008060 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8061 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008062 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008063 (1 << IEEE80211_RADIOTAP_RATE) |
8064 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8065 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8066 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8067 (1 << IEEE80211_RADIOTAP_ANTENNA));
8068
8069 /* Zero the flags, we'll add to them as we go */
8070 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008071 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8072 frame->parent_tsf[2] << 16 |
8073 frame->parent_tsf[1] << 8 |
8074 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008075
8076 /* Convert to DBM */
8077 ipw_rt->rt_dbmsignal = signal;
8078 ipw_rt->rt_dbmnoise = noise;
8079
8080 /* Convert the channel data and set the flags */
8081 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8082 if (channel > 14) { /* 802.11a */
8083 ipw_rt->rt_chbitmask =
8084 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8085 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8086 ipw_rt->rt_chbitmask =
8087 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8088 } else { /* 802.11g */
8089 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008090 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008091 }
8092
8093 /* set the rate in multiples of 500k/s */
8094 switch (rate) {
8095 case IPW_TX_RATE_1MB:
8096 ipw_rt->rt_rate = 2;
8097 break;
8098 case IPW_TX_RATE_2MB:
8099 ipw_rt->rt_rate = 4;
8100 break;
8101 case IPW_TX_RATE_5MB:
8102 ipw_rt->rt_rate = 10;
8103 break;
8104 case IPW_TX_RATE_6MB:
8105 ipw_rt->rt_rate = 12;
8106 break;
8107 case IPW_TX_RATE_9MB:
8108 ipw_rt->rt_rate = 18;
8109 break;
8110 case IPW_TX_RATE_11MB:
8111 ipw_rt->rt_rate = 22;
8112 break;
8113 case IPW_TX_RATE_12MB:
8114 ipw_rt->rt_rate = 24;
8115 break;
8116 case IPW_TX_RATE_18MB:
8117 ipw_rt->rt_rate = 36;
8118 break;
8119 case IPW_TX_RATE_24MB:
8120 ipw_rt->rt_rate = 48;
8121 break;
8122 case IPW_TX_RATE_36MB:
8123 ipw_rt->rt_rate = 72;
8124 break;
8125 case IPW_TX_RATE_48MB:
8126 ipw_rt->rt_rate = 96;
8127 break;
8128 case IPW_TX_RATE_54MB:
8129 ipw_rt->rt_rate = 108;
8130 break;
8131 default:
8132 ipw_rt->rt_rate = 0;
8133 break;
8134 }
8135
8136 /* antenna number */
8137 ipw_rt->rt_antenna = (phy_flags & 3);
8138
8139 /* set the preamble flag if we have it */
8140 if (phy_flags & (1 << 6))
8141 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8142
8143 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8144
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008145 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008146 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008147 dev_kfree_skb_any(skb);
8148 }
8149}
8150#endif
8151
Arjan van de Ven858119e2006-01-14 13:20:43 -08008152static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008153 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008154{
8155 /* Filter incoming packets to determine if they are targetted toward
8156 * this network, discarding packets coming from ourselves */
8157 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008158 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008159 /* packets from our adapter are dropped (echo) */
8160 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8161 return 0;
8162
Peter Jones90700fd2005-08-26 16:51:06 -05008163 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008164 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008165 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008166
8167 /* packets to our adapter go through */
8168 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8169 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008170
Peter Jones90700fd2005-08-26 16:51:06 -05008171 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008172 /* packets from our adapter are dropped (echo) */
8173 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8174 return 0;
8175
Peter Jones90700fd2005-08-26 16:51:06 -05008176 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008177 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008178 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8179
8180 /* packets to our adapter go through */
8181 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8182 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008183 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008184
James Ketrenosea2b26e2005-08-24 21:25:16 -05008185 return 1;
8186}
8187
James Ketrenosafbf30a2005-08-25 00:05:33 -05008188#define IPW_PACKET_RETRY_TIME HZ
8189
Arjan van de Ven858119e2006-01-14 13:20:43 -08008190static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008191 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008192{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008193 u16 sc = le16_to_cpu(header->seq_ctl);
8194 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8195 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8196 u16 *last_seq, *last_frag;
8197 unsigned long *last_time;
8198
8199 switch (priv->ieee->iw_mode) {
8200 case IW_MODE_ADHOC:
8201 {
8202 struct list_head *p;
8203 struct ipw_ibss_seq *entry = NULL;
8204 u8 *mac = header->addr2;
8205 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8206
8207 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8208 entry =
8209 list_entry(p, struct ipw_ibss_seq, list);
8210 if (!memcmp(entry->mac, mac, ETH_ALEN))
8211 break;
8212 }
8213 if (p == &priv->ibss_mac_hash[index]) {
8214 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8215 if (!entry) {
8216 IPW_ERROR
8217 ("Cannot malloc new mac entry\n");
8218 return 0;
8219 }
8220 memcpy(entry->mac, mac, ETH_ALEN);
8221 entry->seq_num = seq;
8222 entry->frag_num = frag;
8223 entry->packet_time = jiffies;
8224 list_add(&entry->list,
8225 &priv->ibss_mac_hash[index]);
8226 return 0;
8227 }
8228 last_seq = &entry->seq_num;
8229 last_frag = &entry->frag_num;
8230 last_time = &entry->packet_time;
8231 break;
8232 }
8233 case IW_MODE_INFRA:
8234 last_seq = &priv->last_seq_num;
8235 last_frag = &priv->last_frag_num;
8236 last_time = &priv->last_packet_time;
8237 break;
8238 default:
8239 return 0;
8240 }
8241 if ((*last_seq == seq) &&
8242 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8243 if (*last_frag == frag)
8244 goto drop;
8245 if (*last_frag + 1 != frag)
8246 /* out-of-order fragment */
8247 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008248 } else
8249 *last_seq = seq;
8250
Zhu Yif57ce7c2005-07-13 12:22:15 -05008251 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008252 *last_time = jiffies;
8253 return 0;
8254
8255 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008256 /* Comment this line now since we observed the card receives
8257 * duplicate packets but the FCTL_RETRY bit is not set in the
8258 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008259 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008260 return 1;
8261}
8262
James Ketrenosb095c382005-08-24 22:04:42 -05008263static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8264 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008265 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008266{
8267 struct sk_buff *skb = rxb->skb;
8268 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008269 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008270 (skb->data + IPW_RX_FRAME_SIZE);
8271
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008272 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008273
8274 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8275 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8276 IEEE80211_STYPE_PROBE_RESP) ||
8277 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8278 IEEE80211_STYPE_BEACON))) {
8279 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8280 ipw_add_station(priv, header->addr2);
8281 }
8282
8283 if (priv->config & CFG_NET_STATS) {
8284 IPW_DEBUG_HC("sending stat packet\n");
8285
8286 /* Set the size of the skb to the size of the full
8287 * ipw header and 802.11 frame */
8288 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8289 IPW_RX_FRAME_SIZE);
8290
8291 /* Advance past the ipw packet header to the 802.11 frame */
8292 skb_pull(skb, IPW_RX_FRAME_SIZE);
8293
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008294 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008295 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8296
8297 skb->dev = priv->ieee->dev;
8298
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008299 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008300 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008301
8302 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008303 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008304 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8305 netif_rx(skb);
8306 rxb->skb = NULL;
8307 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008308}
8309
James Ketrenos43f66a62005-03-25 12:31:53 -06008310/*
8311 * Main entry function for recieving a packet with 80211 headers. This
8312 * should be called when ever the FW has notified us that there is a new
8313 * skb in the recieve queue.
8314 */
8315static void ipw_rx(struct ipw_priv *priv)
8316{
8317 struct ipw_rx_mem_buffer *rxb;
8318 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008319 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008320 u32 r, w, i;
8321 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008322 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008323
James Ketrenosb095c382005-08-24 22:04:42 -05008324 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8325 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008326 i = priv->rxq->read;
8327
8328 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8329 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008330
8331 while (i != r) {
8332 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008333 if (unlikely(rxb == NULL)) {
8334 printk(KERN_CRIT "Queue not allocated!\n");
8335 break;
8336 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008337 priv->rxq->queue[i] = NULL;
8338
8339 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008340 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008341 PCI_DMA_FROMDEVICE);
8342
8343 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8344 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8345 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008346 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008347
8348 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008349 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008350 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008351 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008352 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008353 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008354 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008355 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008356 .noise =
8357 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008358 .rate = pkt->u.frame.rate,
8359 .mac_time = jiffies,
8360 .received_channel =
8361 pkt->u.frame.received_channel,
8362 .freq =
8363 (pkt->u.frame.
8364 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008365 LIBIPW_24GHZ_BAND :
8366 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008367 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008368 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008369
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008370 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008371 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008372 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008373 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008374 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008375 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008376 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008377 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008378
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008379 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008380
Zhu Yid685b8c2006-04-13 17:20:27 +08008381#ifdef CONFIG_IPW2200_PROMISCUOUS
8382 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8383 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8384#endif
8385
James Ketrenosb095c382005-08-24 22:04:42 -05008386#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008387 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008388#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008389
8390 ipw_handle_data_packet_monitor(priv,
8391 rxb,
8392 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008393#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008394 ipw_handle_data_packet(priv, rxb,
8395 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008396#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008397 break;
8398 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008399#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008400
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008401 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008402 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008403 data +
8404 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008405 /* TODO: Check Ad-Hoc dest/source and make sure
8406 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008407 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008408 * frame control of the packet and disregard
8409 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008410
James Ketrenosea2b26e2005-08-24 21:25:16 -05008411 network_packet =
8412 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008413 if (network_packet && priv->assoc_network) {
8414 priv->assoc_network->stats.rssi =
8415 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008416 priv->exp_avg_rssi =
8417 exponential_average(priv->exp_avg_rssi,
8418 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008419 }
8420
8421 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008422 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008423
James Ketrenosa613bff2005-08-24 21:43:11 -05008424 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008425 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008426 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008427 IPW_DEBUG_DROP
8428 ("Received packet is too small. "
8429 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008430 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008431 priv->wstats.discard.misc++;
8432 break;
8433 }
8434
James Ketrenosa613bff2005-08-24 21:43:11 -05008435 switch (WLAN_FC_GET_TYPE
8436 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008437
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008438 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008439 ipw_handle_mgmt_packet(priv, rxb,
8440 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008441 break;
8442
8443 case IEEE80211_FTYPE_CTL:
8444 break;
8445
8446 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008447 if (unlikely(!network_packet ||
8448 is_duplicate_packet(priv,
8449 header)))
8450 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008451 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008452 "%pM, "
8453 "%pM, "
8454 "%pM\n",
8455 header->addr1,
8456 header->addr2,
8457 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008458 break;
8459 }
8460
8461 ipw_handle_data_packet(priv, rxb,
8462 &stats);
8463
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008464 break;
8465 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008466 break;
8467 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008468
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008469 case RX_HOST_NOTIFICATION_TYPE:{
8470 IPW_DEBUG_RX
8471 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008472 pkt->u.notification.subtype,
8473 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008474 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008475 ipw_rx_notification(priv, &pkt->u.notification);
8476 break;
8477 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008478
8479 default:
8480 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8481 pkt->header.message_type);
8482 break;
8483 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008484
8485 /* For now we just don't re-use anything. We can tweak this
8486 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008487 * fail to Rx correctly */
8488 if (rxb->skb != NULL) {
8489 dev_kfree_skb_any(rxb->skb);
8490 rxb->skb = NULL;
8491 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008492
James Ketrenos43f66a62005-03-25 12:31:53 -06008493 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008494 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008495 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008496
James Ketrenos43f66a62005-03-25 12:31:53 -06008497 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008498
8499 /* If there are a lot of unsued frames, restock the Rx queue
8500 * so the ucode won't assert */
8501 if (fill_rx) {
8502 priv->rxq->read = i;
8503 ipw_rx_queue_replenish(priv);
8504 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 }
8506
8507 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008508 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008509 ipw_rx_queue_restock(priv);
8510}
8511
James Ketrenosafbf30a2005-08-25 00:05:33 -05008512#define DEFAULT_RTS_THRESHOLD 2304U
8513#define MIN_RTS_THRESHOLD 1U
8514#define MAX_RTS_THRESHOLD 2304U
8515#define DEFAULT_BEACON_INTERVAL 100U
8516#define DEFAULT_SHORT_RETRY_LIMIT 7U
8517#define DEFAULT_LONG_RETRY_LIMIT 4U
8518
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008519/**
8520 * ipw_sw_reset
8521 * @option: options to control different reset behaviour
8522 * 0 = reset everything except the 'disable' module_param
8523 * 1 = reset everything and print out driver info (for probe only)
8524 * 2 = reset everything
8525 */
8526static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008527{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008528 int band, modulation;
8529 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008530
James Ketrenosafbf30a2005-08-25 00:05:33 -05008531 /* Initialize module parameter values here */
8532 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008533
James Ketrenosafbf30a2005-08-25 00:05:33 -05008534 /* We default to disabling the LED code as right now it causes
8535 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008536 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008537 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008538
James Ketrenosafbf30a2005-08-25 00:05:33 -05008539 if (associate)
8540 priv->config |= CFG_ASSOCIATE;
8541 else
8542 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008543
James Ketrenosafbf30a2005-08-25 00:05:33 -05008544 if (auto_create)
8545 priv->config |= CFG_ADHOC_CREATE;
8546 else
8547 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8548
Zhu Yi17ed0812006-01-24 16:36:31 +08008549 priv->config &= ~CFG_STATIC_ESSID;
8550 priv->essid_len = 0;
8551 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8552
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008553 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008554 priv->status |= STATUS_RF_KILL_SW;
8555 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008556 }
8557
Reinette Chatre21f8a732009-08-18 10:25:05 -07008558 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008559 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008560 priv->channel = default_channel;
8561 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008562 /* TODO: Validate that provided channel is in range */
8563 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008564#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008565 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8566 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008567#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008568
Reinette Chatre21f8a732009-08-18 10:25:05 -07008569 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008570 case 1:
8571 priv->ieee->iw_mode = IW_MODE_ADHOC;
8572 priv->net_dev->type = ARPHRD_ETHER;
8573
8574 break;
8575#ifdef CONFIG_IPW2200_MONITOR
8576 case 2:
8577 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008578#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008579 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8580#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008581 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008582#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008583 break;
8584#endif
8585 default:
8586 case 0:
8587 priv->net_dev->type = ARPHRD_ETHER;
8588 priv->ieee->iw_mode = IW_MODE_INFRA;
8589 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008590 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008591
James Ketrenosafbf30a2005-08-25 00:05:33 -05008592 if (hwcrypto) {
8593 priv->ieee->host_encrypt = 0;
8594 priv->ieee->host_encrypt_msdu = 0;
8595 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008596 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008597 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008598 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008599
Zhu Yie402c932005-08-05 17:20:40 +08008600 /* IPW2200/2915 is abled to do hardware fragmentation. */
8601 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008602
James Ketrenosafbf30a2005-08-25 00:05:33 -05008603 if ((priv->pci_dev->device == 0x4223) ||
8604 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008605 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008606 printk(KERN_INFO DRV_NAME
8607 ": Detected Intel PRO/Wireless 2915ABG Network "
8608 "Connection\n");
8609 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008610 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8611 modulation = LIBIPW_OFDM_MODULATION |
8612 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008613 priv->adapter = IPW_2915ABG;
8614 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008615 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008616 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008617 printk(KERN_INFO DRV_NAME
8618 ": Detected Intel PRO/Wireless 2200BG Network "
8619 "Connection\n");
8620
8621 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008622 band = LIBIPW_24GHZ_BAND;
8623 modulation = LIBIPW_OFDM_MODULATION |
8624 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008625 priv->adapter = IPW_2200BG;
8626 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008627 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008628
James Ketrenosafbf30a2005-08-25 00:05:33 -05008629 priv->ieee->freq_band = band;
8630 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008631
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008632 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008633
James Ketrenosafbf30a2005-08-25 00:05:33 -05008634 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8635 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008636
James Ketrenosafbf30a2005-08-25 00:05:33 -05008637 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8638 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8639 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008640
James Ketrenosafbf30a2005-08-25 00:05:33 -05008641 /* If power management is turned on, default to AC mode */
8642 priv->power_mode = IPW_POWER_AC;
8643 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008644
Zhu Yi0ece35b2005-08-05 17:26:51 +08008645 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008646}
8647
8648/*
8649 * This file defines the Wireless Extension handlers. It does not
8650 * define any methods of hardware manipulation and relies on the
8651 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008652 *
8653 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008654 * function used to poll the hardware vs. making unecessary calls.
8655 *
8656 */
8657
John W. Linville8cc31742009-11-13 16:56:13 -05008658static int ipw_wx_get_name(struct net_device *dev,
8659 struct iw_request_info *info,
8660 union iwreq_data *wrqu, char *extra)
8661{
8662 struct ipw_priv *priv = libipw_priv(dev);
8663 mutex_lock(&priv->mutex);
8664 if (priv->status & STATUS_RF_KILL_MASK)
8665 strcpy(wrqu->name, "radio off");
8666 else if (!(priv->status & STATUS_ASSOCIATED))
8667 strcpy(wrqu->name, "unassociated");
8668 else
8669 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8670 ipw_modes[priv->assoc_request.ieee_mode]);
8671 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8672 mutex_unlock(&priv->mutex);
8673 return 0;
8674}
8675
James Ketrenos43f66a62005-03-25 12:31:53 -06008676static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8677{
8678 if (channel == 0) {
8679 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8680 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008681 IPW_DEBUG_ASSOC("Attempting to associate with new "
8682 "parameters.\n");
8683 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008684 return 0;
8685 }
8686
8687 priv->config |= CFG_STATIC_CHANNEL;
8688
8689 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008690 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8691 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008692 return 0;
8693 }
8694
8695 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8696 priv->channel = channel;
8697
James Ketrenosb095c382005-08-24 22:04:42 -05008698#ifdef CONFIG_IPW2200_MONITOR
8699 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008700 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008701 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008702 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008703 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008704 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008705 }
8706
8707 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8708 udelay(10);
8709
8710 if (priv->status & STATUS_SCANNING)
8711 IPW_DEBUG_SCAN("Still scanning...\n");
8712 else
8713 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8714 1000 - i);
8715
8716 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008717 }
James Ketrenosb095c382005-08-24 22:04:42 -05008718#endif /* CONFIG_IPW2200_MONITOR */
8719
James Ketrenosc848d0a2005-08-24 21:56:24 -05008720 /* Network configuration changed -- force [re]association */
8721 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8722 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008723 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008724
8725 return 0;
8726}
8727
Jeff Garzikbf794512005-07-31 13:07:26 -04008728static int ipw_wx_set_freq(struct net_device *dev,
8729 struct iw_request_info *info,
8730 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008731{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008732 struct ipw_priv *priv = libipw_priv(dev);
8733 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008734 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008735 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008736 u8 channel, flags;
8737 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008738
James Ketrenosb095c382005-08-24 22:04:42 -05008739 if (fwrq->m == 0) {
8740 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008741 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008742 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008743 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008744 return ret;
8745 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008746 /* if setting by freq convert to channel */
8747 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008748 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008749 if (channel == 0)
8750 return -EINVAL;
8751 } else
8752 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008753
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008754 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008755 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008756
Liu Hong1fe0adb2005-08-19 09:33:10 -05008757 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008758 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008759 if (i == -1)
8760 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008761
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008762 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008763 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008764 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008765 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8766 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008767 }
8768 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008769
James Ketrenos43f66a62005-03-25 12:31:53 -06008770 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008771 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008772 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008773 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008774 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008775}
8776
Jeff Garzikbf794512005-07-31 13:07:26 -04008777static int ipw_wx_get_freq(struct net_device *dev,
8778 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008779 union iwreq_data *wrqu, char *extra)
8780{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008781 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008782
8783 wrqu->freq.e = 0;
8784
8785 /* If we are associated, trying to associate, or have a statically
8786 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008787 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008788 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008789 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8790 int i;
8791
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008792 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008793 BUG_ON(i == -1);
8794 wrqu->freq.e = 1;
8795
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008796 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8797 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008798 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8799 break;
8800
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008801 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008802 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8803 break;
8804
8805 default:
8806 BUG();
8807 }
8808 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008809 wrqu->freq.m = 0;
8810
Zhu Yi46441512006-01-24 16:37:59 +08008811 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008812 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8813 return 0;
8814}
8815
Jeff Garzikbf794512005-07-31 13:07:26 -04008816static int ipw_wx_set_mode(struct net_device *dev,
8817 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008818 union iwreq_data *wrqu, char *extra)
8819{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008820 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008821 int err = 0;
8822
8823 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8824
James Ketrenos43f66a62005-03-25 12:31:53 -06008825 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008826#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008827 case IW_MODE_MONITOR:
8828#endif
8829 case IW_MODE_ADHOC:
8830 case IW_MODE_INFRA:
8831 break;
8832 case IW_MODE_AUTO:
8833 wrqu->mode = IW_MODE_INFRA;
8834 break;
8835 default:
8836 return -EINVAL;
8837 }
James Ketrenosb095c382005-08-24 22:04:42 -05008838 if (wrqu->mode == priv->ieee->iw_mode)
8839 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008840
Zhu Yi46441512006-01-24 16:37:59 +08008841 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008842
8843 ipw_sw_reset(priv, 0);
8844
James Ketrenosb095c382005-08-24 22:04:42 -05008845#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008846 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008847 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008848
8849 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008850#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008851 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8852#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008853 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008854#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008855#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008856
Jeff Garzikbf794512005-07-31 13:07:26 -04008857 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008858 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008859 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008860
8861 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008862
James Ketrenosc848d0a2005-08-24 21:56:24 -05008863 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008864 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008865 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008866}
8867
Jeff Garzikbf794512005-07-31 13:07:26 -04008868static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008869 struct iw_request_info *info,
8870 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008871{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008872 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008873 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008874 wrqu->mode = priv->ieee->iw_mode;
8875 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008876 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008877 return 0;
8878}
8879
James Ketrenos43f66a62005-03-25 12:31:53 -06008880/* Values are in microsecond */
8881static const s32 timeout_duration[] = {
8882 350000,
8883 250000,
8884 75000,
8885 37000,
8886 25000,
8887};
8888
8889static const s32 period_duration[] = {
8890 400000,
8891 700000,
8892 1000000,
8893 1000000,
8894 1000000
8895};
8896
Jeff Garzikbf794512005-07-31 13:07:26 -04008897static int ipw_wx_get_range(struct net_device *dev,
8898 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008899 union iwreq_data *wrqu, char *extra)
8900{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008901 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008902 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008903 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008904 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008905
8906 wrqu->data.length = sizeof(*range);
8907 memset(range, 0, sizeof(*range));
8908
8909 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008910 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008911
8912 range->max_qual.qual = 100;
8913 /* TODO: Find real max RSSI and stick here */
8914 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008915 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008916 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008917
8918 range->avg_qual.qual = 70;
8919 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008920 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008921 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008922 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008923 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008924 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008925
Jeff Garzikbf794512005-07-31 13:07:26 -04008926 for (i = 0; i < range->num_bitrates; i++)
8927 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008928 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008929
James Ketrenos43f66a62005-03-25 12:31:53 -06008930 range->max_rts = DEFAULT_RTS_THRESHOLD;
8931 range->min_frag = MIN_FRAG_THRESHOLD;
8932 range->max_frag = MAX_FRAG_THRESHOLD;
8933
8934 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008935 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008936 range->num_encoding_sizes = 2;
8937 range->max_encoding_tokens = WEP_KEYS;
8938
8939 /* Set the Wireless Extension versions */
8940 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008941 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008942
James Ketrenosb095c382005-08-24 22:04:42 -05008943 i = 0;
8944 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008945 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8946 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008947 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008948 continue;
8949
James Ketrenosb095c382005-08-24 22:04:42 -05008950 range->freq[i].i = geo->bg[j].channel;
8951 range->freq[i].m = geo->bg[j].freq * 100000;
8952 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008953 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008954 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008955 }
James Ketrenosb095c382005-08-24 22:04:42 -05008956
8957 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008958 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8959 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008960 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008961 continue;
8962
James Ketrenosb095c382005-08-24 22:04:42 -05008963 range->freq[i].i = geo->a[j].channel;
8964 range->freq[i].m = geo->a[j].freq * 100000;
8965 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008966 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008967 }
8968 }
8969
8970 range->num_channels = i;
8971 range->num_frequency = i;
8972
Zhu Yi46441512006-01-24 16:37:59 +08008973 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008974
8975 /* Event capability (kernel + driver) */
8976 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8977 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008978 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8979 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008980 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008981
Dan Williamsf1b50862006-01-30 13:58:56 -05008982 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8983 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8984
Dan Williams374fdfb2007-12-12 10:25:07 -05008985 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
8986
James Ketrenos43f66a62005-03-25 12:31:53 -06008987 IPW_DEBUG_WX("GET Range\n");
8988 return 0;
8989}
8990
Jeff Garzikbf794512005-07-31 13:07:26 -04008991static int ipw_wx_set_wap(struct net_device *dev,
8992 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008993 union iwreq_data *wrqu, char *extra)
8994{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008995 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008996
8997 static const unsigned char any[] = {
8998 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8999 };
9000 static const unsigned char off[] = {
9001 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9002 };
9003
Jeff Garzikbf794512005-07-31 13:07:26 -04009004 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009005 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009006 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009007 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9008 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9009 /* we disable mandatory BSSID association */
9010 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9011 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009012 IPW_DEBUG_ASSOC("Attempting to associate with new "
9013 "parameters.\n");
9014 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009015 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009016 return 0;
9017 }
9018
9019 priv->config |= CFG_STATIC_BSSID;
9020 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9021 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009022 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009023 return 0;
9024 }
9025
Johannes Berge1749612008-10-27 15:59:26 -07009026 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9027 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009028
9029 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9030
James Ketrenosc848d0a2005-08-24 21:56:24 -05009031 /* Network configuration changed -- force [re]association */
9032 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9033 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009034 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009035
Zhu Yi46441512006-01-24 16:37:59 +08009036 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009037 return 0;
9038}
9039
Jeff Garzikbf794512005-07-31 13:07:26 -04009040static int ipw_wx_get_wap(struct net_device *dev,
9041 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 union iwreq_data *wrqu, char *extra)
9043{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009044 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009045
James Ketrenos43f66a62005-03-25 12:31:53 -06009046 /* If we are associated, trying to associate, or have a statically
9047 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009048 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009049 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009050 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9051 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009052 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009053 } else
9054 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9055
Johannes Berge1749612008-10-27 15:59:26 -07009056 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9057 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009058 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009059 return 0;
9060}
9061
Jeff Garzikbf794512005-07-31 13:07:26 -04009062static int ipw_wx_set_essid(struct net_device *dev,
9063 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 union iwreq_data *wrqu, char *extra)
9065{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009066 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009067 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009068 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009069
Zhu Yiab644b02006-08-21 11:37:13 +08009070 mutex_lock(&priv->mutex);
9071
9072 if (!wrqu->essid.flags)
9073 {
9074 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9075 ipw_disassociate(priv);
9076 priv->config &= ~CFG_STATIC_ESSID;
9077 ipw_associate(priv);
9078 mutex_unlock(&priv->mutex);
9079 return 0;
9080 }
9081
Zhu Yia9f0d422006-08-21 11:37:26 +08009082 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009083
9084 priv->config |= CFG_STATIC_ESSID;
9085
Zhu Yia9f0d422006-08-21 11:37:26 +08009086 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9087 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009088 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009089 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009090 return 0;
9091 }
9092
John W. Linville9387b7c2008-09-30 20:59:05 -04009093 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9094 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009095
9096 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009097 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009098
James Ketrenosc848d0a2005-08-24 21:56:24 -05009099 /* Network configuration changed -- force [re]association */
9100 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9101 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009102 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009103
Zhu Yi46441512006-01-24 16:37:59 +08009104 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009105 return 0;
9106}
9107
Jeff Garzikbf794512005-07-31 13:07:26 -04009108static int ipw_wx_get_essid(struct net_device *dev,
9109 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009110 union iwreq_data *wrqu, char *extra)
9111{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009112 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009113 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009114
9115 /* If we are associated, trying to associate, or have a statically
9116 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009117 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009118 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009119 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9120 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009121 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009122 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009123 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009124 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 } else {
9126 IPW_DEBUG_WX("Getting essid: ANY\n");
9127 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009128 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 }
Zhu Yi46441512006-01-24 16:37:59 +08009130 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009131 return 0;
9132}
9133
Jeff Garzikbf794512005-07-31 13:07:26 -04009134static int ipw_wx_set_nick(struct net_device *dev,
9135 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009137{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009138 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009139
9140 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9141 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9142 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009143 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009144 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009145 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009146 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009147 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009148 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009149 return 0;
9150
9151}
9152
Jeff Garzikbf794512005-07-31 13:07:26 -04009153static int ipw_wx_get_nick(struct net_device *dev,
9154 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009155 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009156{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009157 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009158 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009159 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009160 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009161 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009162 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009163 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 return 0;
9165}
9166
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009167static int ipw_wx_set_sens(struct net_device *dev,
9168 struct iw_request_info *info,
9169 union iwreq_data *wrqu, char *extra)
9170{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009171 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009172 int err = 0;
9173
9174 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9175 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9176 mutex_lock(&priv->mutex);
9177
9178 if (wrqu->sens.fixed == 0)
9179 {
9180 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9181 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9182 goto out;
9183 }
9184 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9185 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9186 err = -EINVAL;
9187 goto out;
9188 }
9189
9190 priv->roaming_threshold = wrqu->sens.value;
9191 priv->disassociate_threshold = 3*wrqu->sens.value;
9192 out:
9193 mutex_unlock(&priv->mutex);
9194 return err;
9195}
9196
9197static int ipw_wx_get_sens(struct net_device *dev,
9198 struct iw_request_info *info,
9199 union iwreq_data *wrqu, char *extra)
9200{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009201 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009202 mutex_lock(&priv->mutex);
9203 wrqu->sens.fixed = 1;
9204 wrqu->sens.value = priv->roaming_threshold;
9205 mutex_unlock(&priv->mutex);
9206
9207 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9208 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9209
9210 return 0;
9211}
9212
James Ketrenos43f66a62005-03-25 12:31:53 -06009213static int ipw_wx_set_rate(struct net_device *dev,
9214 struct iw_request_info *info,
9215 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009216{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009217 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009218 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009219 u32 target_rate = wrqu->bitrate.value;
9220 u32 fixed, mask;
9221
9222 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9223 /* value = X, fixed = 1 means only rate X */
9224 /* value = X, fixed = 0 means all rates lower equal X */
9225
9226 if (target_rate == -1) {
9227 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009228 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009229 /* Now we should reassociate */
9230 goto apply;
9231 }
9232
9233 mask = 0;
9234 fixed = wrqu->bitrate.fixed;
9235
9236 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009237 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009238 if (target_rate == 1000000)
9239 goto apply;
9240
9241 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009242 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009243 if (target_rate == 2000000)
9244 goto apply;
9245
9246 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009247 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009248 if (target_rate == 5500000)
9249 goto apply;
9250
9251 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009252 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009253 if (target_rate == 6000000)
9254 goto apply;
9255
9256 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009257 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009258 if (target_rate == 9000000)
9259 goto apply;
9260
9261 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009262 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009263 if (target_rate == 11000000)
9264 goto apply;
9265
9266 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009267 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009268 if (target_rate == 12000000)
9269 goto apply;
9270
9271 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009272 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009273 if (target_rate == 18000000)
9274 goto apply;
9275
9276 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009277 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009278 if (target_rate == 24000000)
9279 goto apply;
9280
9281 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009282 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009283 if (target_rate == 36000000)
9284 goto apply;
9285
9286 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009287 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009288 if (target_rate == 48000000)
9289 goto apply;
9290
9291 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009292 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009293 if (target_rate == 54000000)
9294 goto apply;
9295
9296 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9297 return -EINVAL;
9298
9299 apply:
9300 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9301 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009302 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009303 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009304 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009305 ipw_set_fixed_rate(priv, priv->ieee->mode);
9306 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009307 priv->config |= CFG_FIXED_RATE;
9308
James Ketrenosc848d0a2005-08-24 21:56:24 -05009309 if (priv->rates_mask == mask) {
9310 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009311 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009312 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009313 }
9314
James Ketrenosc848d0a2005-08-24 21:56:24 -05009315 priv->rates_mask = mask;
9316
9317 /* Network configuration changed -- force [re]association */
9318 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9319 if (!ipw_disassociate(priv))
9320 ipw_associate(priv);
9321
Zhu Yi46441512006-01-24 16:37:59 +08009322 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009323 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009324}
9325
Jeff Garzikbf794512005-07-31 13:07:26 -04009326static int ipw_wx_get_rate(struct net_device *dev,
9327 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009328 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009329{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009330 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009331 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009332 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009333 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009334 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009335 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9336 return 0;
9337}
9338
Jeff Garzikbf794512005-07-31 13:07:26 -04009339static int ipw_wx_set_rts(struct net_device *dev,
9340 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009341 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009342{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009343 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009344 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009345 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9347 else {
9348 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009349 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009350 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009352 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009353 priv->rts_threshold = wrqu->rts.value;
9354 }
9355
9356 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009357 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9359 return 0;
9360}
9361
Jeff Garzikbf794512005-07-31 13:07:26 -04009362static int ipw_wx_get_rts(struct net_device *dev,
9363 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009364 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009365{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009366 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009367 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009368 wrqu->rts.value = priv->rts_threshold;
9369 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009370 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009371 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009372 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9373 return 0;
9374}
9375
Jeff Garzikbf794512005-07-31 13:07:26 -04009376static int ipw_wx_set_txpow(struct net_device *dev,
9377 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009378 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009379{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009380 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009381 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009382
Zhu Yi46441512006-01-24 16:37:59 +08009383 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009384 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009385 err = -EINPROGRESS;
9386 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009387 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009388
James Ketrenosb095c382005-08-24 22:04:42 -05009389 if (!wrqu->power.fixed)
9390 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009391
James Ketrenosc848d0a2005-08-24 21:56:24 -05009392 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009393 err = -EINVAL;
9394 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009395 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009396
James Ketrenosb095c382005-08-24 22:04:42 -05009397 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009398 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009399 err = -EINVAL;
9400 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009401 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009402
9403 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009404 err = ipw_set_tx_power(priv);
9405 out:
Zhu Yi46441512006-01-24 16:37:59 +08009406 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009407 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009408}
9409
Jeff Garzikbf794512005-07-31 13:07:26 -04009410static int ipw_wx_get_txpow(struct net_device *dev,
9411 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009412 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009413{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009414 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009415 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009416 wrqu->power.value = priv->tx_power;
9417 wrqu->power.fixed = 1;
9418 wrqu->power.flags = IW_TXPOW_DBM;
9419 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009420 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421
Jeff Garzikbf794512005-07-31 13:07:26 -04009422 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009423 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009424
9425 return 0;
9426}
9427
Jeff Garzikbf794512005-07-31 13:07:26 -04009428static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009429 struct iw_request_info *info,
9430 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009431{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009432 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009433 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009434 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009435 priv->ieee->fts = DEFAULT_FTS;
9436 else {
9437 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009438 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009439 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009440 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009441 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009442
James Ketrenos43f66a62005-03-25 12:31:53 -06009443 priv->ieee->fts = wrqu->frag.value & ~0x1;
9444 }
9445
9446 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009447 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009448 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9449 return 0;
9450}
9451
Jeff Garzikbf794512005-07-31 13:07:26 -04009452static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009453 struct iw_request_info *info,
9454 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009455{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009456 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009457 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009458 wrqu->frag.value = priv->ieee->fts;
9459 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009460 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009461 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009462 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9463
9464 return 0;
9465}
9466
Jeff Garzikbf794512005-07-31 13:07:26 -04009467static int ipw_wx_set_retry(struct net_device *dev,
9468 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009469 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009470{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009471 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009472
9473 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9474 return -EINVAL;
9475
9476 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9477 return 0;
9478
Zhu Yid5f7ac22006-08-21 11:38:17 +08009479 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009480 return -EINVAL;
9481
Zhu Yi46441512006-01-24 16:37:59 +08009482 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009483 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009484 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009485 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009486 priv->long_retry_limit = (u8) wrqu->retry.value;
9487 else {
9488 priv->short_retry_limit = (u8) wrqu->retry.value;
9489 priv->long_retry_limit = (u8) wrqu->retry.value;
9490 }
9491
9492 ipw_send_retry_limit(priv, priv->short_retry_limit,
9493 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009494 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009495 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9496 priv->short_retry_limit, priv->long_retry_limit);
9497 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009498}
9499
Jeff Garzikbf794512005-07-31 13:07:26 -04009500static int ipw_wx_get_retry(struct net_device *dev,
9501 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009502 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009503{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009504 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009505
Zhu Yi46441512006-01-24 16:37:59 +08009506 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009507 wrqu->retry.disabled = 0;
9508
9509 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009510 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009511 return -EINVAL;
9512 }
9513
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009514 if (wrqu->retry.flags & IW_RETRY_LONG) {
9515 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009516 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009517 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9518 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009519 wrqu->retry.value = priv->short_retry_limit;
9520 } else {
9521 wrqu->retry.flags = IW_RETRY_LIMIT;
9522 wrqu->retry.value = priv->short_retry_limit;
9523 }
Zhu Yi46441512006-01-24 16:37:59 +08009524 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009525
9526 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9527
9528 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009529}
9530
Jeff Garzikbf794512005-07-31 13:07:26 -04009531static int ipw_wx_set_scan(struct net_device *dev,
9532 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009533 union iwreq_data *wrqu, char *extra)
9534{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009535 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009536 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009537 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009538
Dan Williams0b531672007-10-09 13:55:24 -04009539 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009540
Dan Williams0b531672007-10-09 13:55:24 -04009541 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009542
Zhu Yi094c4d22006-08-21 11:39:03 +08009543 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009544 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009545 int len = min((int)req->essid_len,
9546 (int)sizeof(priv->direct_scan_ssid));
9547 memcpy(priv->direct_scan_ssid, req->essid, len);
9548 priv->direct_scan_ssid_len = len;
9549 work = &priv->request_direct_scan;
9550 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9551 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009552 }
Dan Williamsea177302008-06-02 17:51:23 -04009553 } else {
9554 /* Normal active broadcast scan */
9555 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009556 }
James Ketrenos8935f392005-10-05 15:59:08 -05009557
Dan Williamsea177302008-06-02 17:51:23 -04009558 mutex_unlock(&priv->mutex);
9559
James Ketrenos43f66a62005-03-25 12:31:53 -06009560 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009561
Dan Williamsea177302008-06-02 17:51:23 -04009562 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009563
James Ketrenos43f66a62005-03-25 12:31:53 -06009564 return 0;
9565}
9566
Jeff Garzikbf794512005-07-31 13:07:26 -04009567static int ipw_wx_get_scan(struct net_device *dev,
9568 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009569 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009570{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009571 struct ipw_priv *priv = libipw_priv(dev);
9572 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009573}
9574
Jeff Garzikbf794512005-07-31 13:07:26 -04009575static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009576 struct iw_request_info *info,
9577 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009578{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009579 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009580 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009581 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009582
Zhu Yi46441512006-01-24 16:37:59 +08009583 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009584 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009585
Hong Liucaeff812005-08-05 17:25:50 +08009586 /* In IBSS mode, we need to notify the firmware to update
9587 * the beacon info after we changed the capability. */
9588 if (cap != priv->capability &&
9589 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9590 priv->status & STATUS_ASSOCIATED)
9591 ipw_disassociate(priv);
9592
Zhu Yi46441512006-01-24 16:37:59 +08009593 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009594 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009595}
9596
Jeff Garzikbf794512005-07-31 13:07:26 -04009597static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009598 struct iw_request_info *info,
9599 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009600{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009601 struct ipw_priv *priv = libipw_priv(dev);
9602 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009603}
9604
Jeff Garzikbf794512005-07-31 13:07:26 -04009605static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009606 struct iw_request_info *info,
9607 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009608{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009609 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009610 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009611 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009612 if (wrqu->power.disabled) {
9613 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9614 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9615 if (err) {
9616 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009617 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009618 return err;
9619 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009620 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009621 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009622 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009623 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009624
9625 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009626 case IW_POWER_ON: /* If not specified */
9627 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009628 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009629 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009630 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009631 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9632 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009633 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009634 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009635 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009636
James Ketrenos43f66a62005-03-25 12:31:53 -06009637 /* If the user hasn't specified a power management mode yet, default
9638 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009639 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009640 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009641 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009643
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9645 if (err) {
9646 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009647 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009648 return err;
9649 }
9650
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009651 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009652 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 return 0;
9654}
9655
Jeff Garzikbf794512005-07-31 13:07:26 -04009656static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009657 struct iw_request_info *info,
9658 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009659{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009660 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009661 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009662 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009664 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009665 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009666
Zhu Yi46441512006-01-24 16:37:59 +08009667 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009669
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 return 0;
9671}
9672
Jeff Garzikbf794512005-07-31 13:07:26 -04009673static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009674 struct iw_request_info *info,
9675 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009676{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009677 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009678 int mode = *(int *)extra;
9679 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009680
Zhu Yi46441512006-01-24 16:37:59 +08009681 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009682 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009684
Zhu Yi4e157f02007-07-12 16:09:32 +08009685 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009686 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 if (err) {
9688 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009689 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009690 return err;
9691 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009692 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009693 }
Zhu Yi46441512006-01-24 16:37:59 +08009694 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009695 return 0;
9696}
9697
9698#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009699static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009700 struct iw_request_info *info,
9701 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009702{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009703 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 int level = IPW_POWER_LEVEL(priv->power_mode);
9705 char *p = extra;
9706
9707 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9708
9709 switch (level) {
9710 case IPW_POWER_AC:
9711 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9712 break;
9713 case IPW_POWER_BATTERY:
9714 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9715 break;
9716 default:
9717 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009718 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009719 timeout_duration[level - 1] / 1000,
9720 period_duration[level - 1] / 1000);
9721 }
9722
9723 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009724 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009725
9726 wrqu->data.length = p - extra + 1;
9727
9728 return 0;
9729}
9730
9731static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009732 struct iw_request_info *info,
9733 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009734{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009735 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009736 int mode = *(int *)extra;
9737 u8 band = 0, modulation = 0;
9738
9739 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009740 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 return -EINVAL;
9742 }
Zhu Yi46441512006-01-24 16:37:59 +08009743 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009744 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009745 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009746 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009747 band |= LIBIPW_52GHZ_BAND;
9748 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009749 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009750 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009751 } else {
9752 if (mode & IEEE_A) {
9753 IPW_WARNING("Attempt to set 2200BG into "
9754 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009755 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 return -EINVAL;
9757 }
9758
James Ketrenosa33a1982005-09-14 14:28:59 -05009759 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009760 }
9761
9762 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009763 band |= LIBIPW_24GHZ_BAND;
9764 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009766 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009767
James Ketrenos43f66a62005-03-25 12:31:53 -06009768 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009769 band |= LIBIPW_24GHZ_BAND;
9770 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009771 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009772 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009773
9774 priv->ieee->mode = mode;
9775 priv->ieee->freq_band = band;
9776 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009777 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009778
James Ketrenosc848d0a2005-08-24 21:56:24 -05009779 /* Network configuration changed -- force [re]association */
9780 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9781 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009783 ipw_associate(priv);
9784 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009785
James Ketrenosa613bff2005-08-24 21:43:11 -05009786 /* Update the band LEDs */
9787 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009788
Jeff Garzikbf794512005-07-31 13:07:26 -04009789 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009791 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009792 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009793 return 0;
9794}
9795
9796static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009797 struct iw_request_info *info,
9798 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009799{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009800 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009801 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009802 switch (priv->ieee->mode) {
9803 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009804 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9805 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009806 case IEEE_B:
9807 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9808 break;
9809 case IEEE_A | IEEE_B:
9810 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9811 break;
9812 case IEEE_G:
9813 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9814 break;
9815 case IEEE_A | IEEE_G:
9816 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9817 break;
9818 case IEEE_B | IEEE_G:
9819 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9820 break;
9821 case IEEE_A | IEEE_B | IEEE_G:
9822 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9823 break;
9824 default:
9825 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009826 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009827 }
9828
James Ketrenos43f66a62005-03-25 12:31:53 -06009829 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9830
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009831 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009832 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009833
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009834 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009835}
9836
James Ketrenosea2b26e2005-08-24 21:25:16 -05009837static int ipw_wx_set_preamble(struct net_device *dev,
9838 struct iw_request_info *info,
9839 union iwreq_data *wrqu, char *extra)
9840{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009841 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009842 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009843 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009844 /* Switching from SHORT -> LONG requires a disassociation */
9845 if (mode == 1) {
9846 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9847 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009848
9849 /* Network configuration changed -- force [re]association */
9850 IPW_DEBUG_ASSOC
9851 ("[re]association triggered due to preamble change.\n");
9852 if (!ipw_disassociate(priv))
9853 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009854 }
9855 goto done;
9856 }
9857
9858 if (mode == 0) {
9859 priv->config &= ~CFG_PREAMBLE_LONG;
9860 goto done;
9861 }
Zhu Yi46441512006-01-24 16:37:59 +08009862 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009863 return -EINVAL;
9864
9865 done:
Zhu Yi46441512006-01-24 16:37:59 +08009866 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009867 return 0;
9868}
9869
9870static int ipw_wx_get_preamble(struct net_device *dev,
9871 struct iw_request_info *info,
9872 union iwreq_data *wrqu, char *extra)
9873{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009874 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009875 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009876 if (priv->config & CFG_PREAMBLE_LONG)
9877 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9878 else
9879 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009880 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 return 0;
9882}
9883
James Ketrenosb095c382005-08-24 22:04:42 -05009884#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009885static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009886 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009887 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009888{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009889 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009890 int *parms = (int *)extra;
9891 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009892 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009893 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009894 if (enable) {
9895 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009896#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009897 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9898#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009899 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009900#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009901 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009902 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009903
James Ketrenos43f66a62005-03-25 12:31:53 -06009904 ipw_set_channel(priv, parms[1]);
9905 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009906 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009907 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009908 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009909 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009910 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009911 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009912 }
Zhu Yi46441512006-01-24 16:37:59 +08009913 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009914 return 0;
9915}
9916
Pavel Machek67fd6b42006-07-11 15:34:05 +02009917#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009918
Jeff Garzikbf794512005-07-31 13:07:26 -04009919static int ipw_wx_reset(struct net_device *dev,
9920 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009921 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009922{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009923 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009924 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009925 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009926 return 0;
9927}
James Ketrenosb095c382005-08-24 22:04:42 -05009928
James Ketrenosb095c382005-08-24 22:04:42 -05009929static int ipw_wx_sw_reset(struct net_device *dev,
9930 struct iw_request_info *info,
9931 union iwreq_data *wrqu, char *extra)
9932{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009933 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009934 union iwreq_data wrqu_sec = {
9935 .encoding = {
9936 .flags = IW_ENCODE_DISABLED,
9937 },
9938 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009939 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009940
9941 IPW_DEBUG_WX("SW_RESET\n");
9942
Zhu Yi46441512006-01-24 16:37:59 +08009943 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009944
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009945 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009946 if (!ret) {
9947 free_firmware();
9948 ipw_adapter_restart(priv);
9949 }
James Ketrenosb095c382005-08-24 22:04:42 -05009950
9951 /* The SW reset bit might have been toggled on by the 'disable'
9952 * module parameter, so take appropriate action */
9953 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9954
Zhu Yi46441512006-01-24 16:37:59 +08009955 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009956 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009957 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009958
9959 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9960 /* Configuration likely changed -- force [re]association */
9961 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9962 "reset.\n");
9963 if (!ipw_disassociate(priv))
9964 ipw_associate(priv);
9965 }
9966
Zhu Yi46441512006-01-24 16:37:59 +08009967 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009968
9969 return 0;
9970}
James Ketrenos43f66a62005-03-25 12:31:53 -06009971
9972/* Rebase the WE IOCTLs to zero for the handler array */
9973#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009974static iw_handler ipw_wx_handlers[] = {
John W. Linville8cc31742009-11-13 16:56:13 -05009975 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009976 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9977 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9978 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9979 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009980 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9981 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009982 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9983 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9984 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9985 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9986 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9987 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9988 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9989 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9990 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9991 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9992 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9993 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9994 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9995 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9996 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9997 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9998 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9999 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10000 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10001 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10002 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10003 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10004 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -050010005 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10006 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10007 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10008 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -050010009 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10010 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10011 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10012 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10013 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10014 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10015 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -060010016};
10017
James Ketrenosb095c382005-08-24 22:04:42 -050010018enum {
10019 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10020 IPW_PRIV_GET_POWER,
10021 IPW_PRIV_SET_MODE,
10022 IPW_PRIV_GET_MODE,
10023 IPW_PRIV_SET_PREAMBLE,
10024 IPW_PRIV_GET_PREAMBLE,
10025 IPW_PRIV_RESET,
10026 IPW_PRIV_SW_RESET,
10027#ifdef CONFIG_IPW2200_MONITOR
10028 IPW_PRIV_SET_MONITOR,
10029#endif
10030};
James Ketrenos43f66a62005-03-25 12:31:53 -060010031
Jeff Garzikbf794512005-07-31 13:07:26 -040010032static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010033 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010034 .cmd = IPW_PRIV_SET_POWER,
10035 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10036 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010037 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010038 .cmd = IPW_PRIV_GET_POWER,
10039 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10040 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010041 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010042 .cmd = IPW_PRIV_SET_MODE,
10043 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10044 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010045 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010046 .cmd = IPW_PRIV_GET_MODE,
10047 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10048 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010049 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010050 .cmd = IPW_PRIV_SET_PREAMBLE,
10051 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10052 .name = "set_preamble"},
10053 {
10054 .cmd = IPW_PRIV_GET_PREAMBLE,
10055 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10056 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010057 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010058 IPW_PRIV_RESET,
10059 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010060 {
10061 IPW_PRIV_SW_RESET,
10062 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10063#ifdef CONFIG_IPW2200_MONITOR
10064 {
10065 IPW_PRIV_SET_MONITOR,
10066 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10067#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010068};
10069
10070static iw_handler ipw_priv_handler[] = {
10071 ipw_wx_set_powermode,
10072 ipw_wx_get_powermode,
10073 ipw_wx_set_wireless_mode,
10074 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010075 ipw_wx_set_preamble,
10076 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010077 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010078 ipw_wx_sw_reset,
10079#ifdef CONFIG_IPW2200_MONITOR
10080 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010081#endif
10082};
10083
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010084static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010085 .standard = ipw_wx_handlers,
10086 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10087 .num_private = ARRAY_SIZE(ipw_priv_handler),
10088 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10089 .private = ipw_priv_handler,
10090 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010091 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010092};
10093
James Ketrenos43f66a62005-03-25 12:31:53 -060010094/*
10095 * Get wireless statistics.
10096 * Called by /proc/net/wireless
10097 * Also called by SIOCGIWSTATS
10098 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010099static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010100{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010101 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010102 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010103
James Ketrenos43f66a62005-03-25 12:31:53 -060010104 wstats = &priv->wstats;
10105
James Ketrenosea2b26e2005-08-24 21:25:16 -050010106 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010107 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010108 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10109 * and associated; if not associcated, the values are all meaningless
10110 * anyway, so set them all to NULL and INVALID */
10111 if (!(priv->status & STATUS_ASSOCIATED)) {
10112 wstats->miss.beacon = 0;
10113 wstats->discard.retries = 0;
10114 wstats->qual.qual = 0;
10115 wstats->qual.level = 0;
10116 wstats->qual.noise = 0;
10117 wstats->qual.updated = 7;
10118 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010119 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010120 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010121 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010122
10123 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010124 wstats->qual.level = priv->exp_avg_rssi;
10125 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010126 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010127 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010128
10129 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10130 wstats->discard.retries = priv->last_tx_failures;
10131 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010132
James Ketrenos43f66a62005-03-25 12:31:53 -060010133/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10134 goto fail_get_ordinal;
10135 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010136
James Ketrenos43f66a62005-03-25 12:31:53 -060010137 return wstats;
10138}
10139
James Ketrenos43f66a62005-03-25 12:31:53 -060010140/* net device stuff */
10141
Arjan van de Ven858119e2006-01-14 13:20:43 -080010142static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010143{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010144 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010145 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010146 sys_config->answer_broadcast_ssid_probe = 0;
10147 sys_config->accept_all_data_frames = 0;
10148 sys_config->accept_non_directed_frames = 1;
10149 sys_config->exclude_unicast_unencrypted = 0;
10150 sys_config->disable_unicast_decryption = 1;
10151 sys_config->exclude_multicast_unencrypted = 0;
10152 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010153 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10154 antenna = CFG_SYS_ANTENNA_BOTH;
10155 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010156 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010157 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010158 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010159 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010160 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010161 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010162}
10163
10164static int ipw_net_open(struct net_device *dev)
10165{
James Ketrenos43f66a62005-03-25 12:31:53 -060010166 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010167 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010168 return 0;
10169}
10170
10171static int ipw_net_stop(struct net_device *dev)
10172{
10173 IPW_DEBUG_INFO("dev->close\n");
10174 netif_stop_queue(dev);
10175 return 0;
10176}
10177
10178/*
10179todo:
10180
10181modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010182we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010183*/
10184
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010185static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010186 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010187{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010188 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010189 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010190 int i = 0;
10191 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010192#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010193 int tx_id = ipw_get_tx_queue_number(priv, pri);
10194 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10195#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010196 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010197#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010198 struct clx2_queue *q = &txq->q;
10199 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010200 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010201
Zhu Yib8ddafd2008-11-27 13:42:20 +080010202 if (!(priv->status & STATUS_ASSOCIATED))
10203 goto drop;
10204
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010205 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010206 switch (priv->ieee->iw_mode) {
10207 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010208 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010209 id = ipw_find_station(priv, hdr->addr1);
10210 if (id == IPW_INVALID_STATION) {
10211 id = ipw_add_station(priv, hdr->addr1);
10212 if (id == IPW_INVALID_STATION) {
10213 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010214 "invalid cell: %pM\n",
10215 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010216 goto drop;
10217 }
10218 }
10219 break;
10220
10221 case IW_MODE_INFRA:
10222 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010223 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010224 id = 0;
10225 break;
10226 }
10227
10228 tfd = &txq->bd[q->first_empty];
10229 txq->txb[q->first_empty] = txb;
10230 memset(tfd, 0, sizeof(*tfd));
10231 tfd->u.data.station_number = id;
10232
10233 tfd->control_flags.message_type = TX_FRAME_TYPE;
10234 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10235
10236 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010237 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010238
James Ketrenos43f66a62005-03-25 12:31:53 -060010239 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010240 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010241 else
James Ketrenosb095c382005-08-24 22:04:42 -050010242 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010243
James Ketrenosea2b26e2005-08-24 21:25:16 -050010244 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10245 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010246
James Ketrenosc848d0a2005-08-24 21:56:24 -050010247 fc = le16_to_cpu(hdr->frame_ctl);
10248 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010249
10250 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10251
James Ketrenosb095c382005-08-24 22:04:42 -050010252 if (likely(unicast))
10253 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10254
10255 if (txb->encrypted && !priv->ieee->host_encrypt) {
10256 switch (priv->ieee->sec.level) {
10257 case SEC_LEVEL_3:
10258 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010259 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010260 /* XXX: ACK flag must be set for CCMP even if it
10261 * is a multicast/broadcast packet, because CCMP
10262 * group communication encrypted by GTK is
10263 * actually done by the AP. */
10264 if (!unicast)
10265 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10266
10267 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10268 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10269 tfd->u.data.key_index = 0;
10270 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10271 break;
10272 case SEC_LEVEL_2:
10273 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010274 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010275 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10276 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10277 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10278 break;
10279 case SEC_LEVEL_1:
10280 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010281 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010282 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10283 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010284 40)
10285 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10286 else
10287 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10288 break;
10289 case SEC_LEVEL_0:
10290 break;
10291 default:
10292 printk(KERN_ERR "Unknow security level %d\n",
10293 priv->ieee->sec.level);
10294 break;
10295 }
10296 } else
10297 /* No hardware encryption */
10298 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10299
Zhu Yie43e3c12006-04-13 17:20:45 +080010300#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010301 if (fc & IEEE80211_STYPE_QOS_DATA)
10302 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010303#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010304
James Ketrenos43f66a62005-03-25 12:31:53 -060010305 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010306 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10307 txb->nr_frags));
10308 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10309 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10310 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10311 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10312 i, le32_to_cpu(tfd->u.data.num_chunks),
10313 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010314 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010315 i, tfd->u.data.num_chunks,
10316 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010317 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010318 txb->fragments[i]->len - hdr_len);
10319
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010320 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010321 cpu_to_le32(pci_map_single
10322 (priv->pci_dev,
10323 txb->fragments[i]->data + hdr_len,
10324 txb->fragments[i]->len - hdr_len,
10325 PCI_DMA_TODEVICE));
10326 tfd->u.data.chunk_len[i] =
10327 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010328 }
10329
10330 if (i != txb->nr_frags) {
10331 struct sk_buff *skb;
10332 u16 remaining_bytes = 0;
10333 int j;
10334
10335 for (j = i; j < txb->nr_frags; j++)
10336 remaining_bytes += txb->fragments[j]->len - hdr_len;
10337
10338 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10339 remaining_bytes);
10340 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10341 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010342 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010343 for (j = i; j < txb->nr_frags; j++) {
10344 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010345
James Ketrenos43f66a62005-03-25 12:31:53 -060010346 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010347 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010348 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010349 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010350 }
10351 dev_kfree_skb_any(txb->fragments[i]);
10352 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010353 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010354 cpu_to_le32(pci_map_single
10355 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010356 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010357 PCI_DMA_TODEVICE));
10358
Marcin Slusarz5c058632008-02-13 00:06:12 +010010359 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010360 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010361 }
10362
10363 /* kick DMA */
10364 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10365 ipw_write32(priv, q->reg_w, q->first_empty);
10366
Dan Williams943dbef2008-02-14 17:49:41 -050010367 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010368 netif_stop_queue(priv->net_dev);
10369
James Ketrenos227d2dc2005-07-28 16:25:55 -050010370 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010371
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010372 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010373 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010374 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010375 return NETDEV_TX_OK;
10376}
10377
10378static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10379{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010380 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010381#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010382 int tx_id = ipw_get_tx_queue_number(priv, pri);
10383 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10384#else
10385 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010386#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010387
Dan Williams943dbef2008-02-14 17:49:41 -050010388 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010389 return 1;
10390
10391 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010392}
10393
Zhu Yid685b8c2006-04-13 17:20:27 +080010394#ifdef CONFIG_IPW2200_PROMISCUOUS
10395static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010396 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010397{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010398 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010399 struct ieee80211_hdr *hdr;
10400 u8 n;
10401 u16 filter = priv->prom_priv->filter;
10402 int hdr_only = 0;
10403
10404 if (filter & IPW_PROM_NO_TX)
10405 return;
10406
10407 memset(&dummystats, 0, sizeof(dummystats));
10408
10409 /* Filtering of fragment chains is done agains the first fragment */
10410 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010411 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010412 if (filter & IPW_PROM_NO_MGMT)
10413 return;
10414 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10415 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010416 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010417 if (filter & IPW_PROM_NO_CTL)
10418 return;
10419 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10420 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010421 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010422 if (filter & IPW_PROM_NO_DATA)
10423 return;
10424 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10425 hdr_only = 1;
10426 }
10427
10428 for(n=0; n<txb->nr_frags; ++n) {
10429 struct sk_buff *src = txb->fragments[n];
10430 struct sk_buff *dst;
10431 struct ieee80211_radiotap_header *rt_hdr;
10432 int len;
10433
10434 if (hdr_only) {
10435 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010436 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010437 } else
10438 len = src->len;
10439
Johannes Berg007e5dd2008-11-27 23:13:38 +010010440 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10441 if (!dst)
10442 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010443
10444 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10445
10446 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10447 rt_hdr->it_pad = 0;
10448 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010449 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010450
Al Viroe62e1ee2007-12-27 01:36:46 -050010451 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010452 ieee80211chan2mhz(priv->channel));
10453 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010454 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010455 cpu_to_le16(IEEE80211_CHAN_OFDM |
10456 IEEE80211_CHAN_5GHZ);
10457 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010458 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010459 cpu_to_le16(IEEE80211_CHAN_CCK |
10460 IEEE80211_CHAN_2GHZ);
10461 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010462 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010463 cpu_to_le16(IEEE80211_CHAN_OFDM |
10464 IEEE80211_CHAN_2GHZ);
10465
Al Viro743b84d2007-12-27 01:43:16 -050010466 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010467
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010468 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010469
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010470 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010471 dev_kfree_skb_any(dst);
10472 }
10473}
10474#endif
10475
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010476static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10477 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010478{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010479 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010480 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010481 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010482
10483 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010484 spin_lock_irqsave(&priv->lock, flags);
10485
Zhu Yid685b8c2006-04-13 17:20:27 +080010486#ifdef CONFIG_IPW2200_PROMISCUOUS
10487 if (rtap_iface && netif_running(priv->prom_net_dev))
10488 ipw_handle_promiscuous_tx(priv, txb);
10489#endif
10490
James Ketrenos227d2dc2005-07-28 16:25:55 -050010491 ret = ipw_tx_skb(priv, txb, pri);
10492 if (ret == NETDEV_TX_OK)
10493 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010494 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010495
James Ketrenos227d2dc2005-07-28 16:25:55 -050010496 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010497}
10498
James Ketrenos43f66a62005-03-25 12:31:53 -060010499static void ipw_net_set_multicast_list(struct net_device *dev)
10500{
10501
10502}
10503
10504static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10505{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010506 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010507 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010508
James Ketrenos43f66a62005-03-25 12:31:53 -060010509 if (!is_valid_ether_addr(addr->sa_data))
10510 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010511 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010512 priv->config |= CFG_CUSTOM_MAC;
10513 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010514 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10515 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010516 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010517 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010518 return 0;
10519}
10520
Jeff Garzikbf794512005-07-31 13:07:26 -040010521static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010522 struct ethtool_drvinfo *info)
10523{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010524 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010525 char vers[64];
10526 char date[32];
10527 u32 len;
10528
10529 strcpy(info->driver, DRV_NAME);
10530 strcpy(info->version, DRV_VERSION);
10531
10532 len = sizeof(vers);
10533 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10534 len = sizeof(date);
10535 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10536
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010537 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010538 vers, date);
10539 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010540 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010541}
10542
10543static u32 ipw_ethtool_get_link(struct net_device *dev)
10544{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010545 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010546 return (priv->status & STATUS_ASSOCIATED) != 0;
10547}
10548
10549static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10550{
James Ketrenosb095c382005-08-24 22:04:42 -050010551 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010552}
10553
10554static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010555 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010556{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010557 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010558
James Ketrenosb095c382005-08-24 22:04:42 -050010559 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010560 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010561 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010562 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010563 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010564 return 0;
10565}
10566
10567static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010568 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010569{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010570 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010571 int i;
10572
James Ketrenosb095c382005-08-24 22:04:42 -050010573 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010574 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010575 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010576 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010577 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10578 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010579 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010580 return 0;
10581}
10582
Jeff Garzik7282d492006-09-13 14:30:00 -040010583static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010584 .get_link = ipw_ethtool_get_link,
10585 .get_drvinfo = ipw_ethtool_get_drvinfo,
10586 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10587 .get_eeprom = ipw_ethtool_get_eeprom,
10588 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010589};
10590
David Howells7d12e782006-10-05 14:55:46 +010010591static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010592{
10593 struct ipw_priv *priv = data;
10594 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010595
James Ketrenos43f66a62005-03-25 12:31:53 -060010596 if (!priv)
10597 return IRQ_NONE;
10598
Zhu Yi89c318e2006-06-08 22:19:49 -070010599 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010600
10601 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010602 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010603 goto none;
10604 }
10605
James Ketrenosb095c382005-08-24 22:04:42 -050010606 inta = ipw_read32(priv, IPW_INTA_RW);
10607 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010608
James Ketrenos43f66a62005-03-25 12:31:53 -060010609 if (inta == 0xFFFFFFFF) {
10610 /* Hardware disappeared */
10611 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10612 goto none;
10613 }
10614
James Ketrenosb095c382005-08-24 22:04:42 -050010615 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010616 /* Shared interrupt */
10617 goto none;
10618 }
10619
10620 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010621 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010622
James Ketrenos43f66a62005-03-25 12:31:53 -060010623 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010624 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10625 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010626
James Ketrenos43f66a62005-03-25 12:31:53 -060010627 /* Cache INTA value for our tasklet */
10628 priv->isr_inta = inta;
10629
10630 tasklet_schedule(&priv->irq_tasklet);
10631
Zhu Yi89c318e2006-06-08 22:19:49 -070010632 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010633
10634 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010635 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010636 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010637 return IRQ_NONE;
10638}
10639
10640static void ipw_rf_kill(void *adapter)
10641{
10642 struct ipw_priv *priv = adapter;
10643 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010644
James Ketrenos43f66a62005-03-25 12:31:53 -060010645 spin_lock_irqsave(&priv->lock, flags);
10646
10647 if (rf_kill_active(priv)) {
10648 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10649 if (priv->workqueue)
10650 queue_delayed_work(priv->workqueue,
10651 &priv->rf_kill, 2 * HZ);
10652 goto exit_unlock;
10653 }
10654
10655 /* RF Kill is now disabled, so bring the device back up */
10656
10657 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10658 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10659 "device\n");
10660
10661 /* we can not do an adapter restart while inside an irq lock */
10662 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010663 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010664 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10665 "enabled\n");
10666
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010667 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010668 spin_unlock_irqrestore(&priv->lock, flags);
10669}
10670
David Howellsc4028952006-11-22 14:57:56 +000010671static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010672{
David Howellsc4028952006-11-22 14:57:56 +000010673 struct ipw_priv *priv =
10674 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010675 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010676 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010677 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010678}
10679
Adrian Bunka73e22b2006-01-21 01:39:42 +010010680static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010681{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010682 priv->last_seq_num = -1;
10683 priv->last_frag_num = -1;
10684 priv->last_packet_time = 0;
10685
James Ketrenosa613bff2005-08-24 21:43:11 -050010686 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010687
James Ketrenosc848d0a2005-08-24 21:56:24 -050010688 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010689 cancel_delayed_work(&priv->request_direct_scan);
10690 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010691 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010692 ipw_reset_stats(priv);
10693 /* Ensure the rate is updated immediately */
10694 priv->last_rate = ipw_get_current_rate(priv);
10695 ipw_gather_stats(priv);
10696 ipw_led_link_up(priv);
10697 notify_wx_assoc_event(priv);
10698
10699 if (priv->config & CFG_BACKGROUND_SCAN)
10700 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10701}
10702
David Howellsc4028952006-11-22 14:57:56 +000010703static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010704{
David Howellsc4028952006-11-22 14:57:56 +000010705 struct ipw_priv *priv =
10706 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010707 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010708 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010709 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010710}
10711
Adrian Bunka73e22b2006-01-21 01:39:42 +010010712static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010713{
10714 ipw_led_link_down(priv);
10715 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010716 notify_wx_assoc_event(priv);
10717
10718 /* Cancel any queued work ... */
10719 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010720 cancel_delayed_work(&priv->request_direct_scan);
10721 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010722 cancel_delayed_work(&priv->adhoc_check);
10723 cancel_delayed_work(&priv->gather_stats);
10724
10725 ipw_reset_stats(priv);
10726
James Ketrenosafbf30a2005-08-25 00:05:33 -050010727 if (!(priv->status & STATUS_EXIT_PENDING)) {
10728 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010729 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010730 } else
10731 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010732}
10733
David Howellsc4028952006-11-22 14:57:56 +000010734static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010735{
David Howellsc4028952006-11-22 14:57:56 +000010736 struct ipw_priv *priv =
10737 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010738 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010739 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010740 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010741}
10742
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010743static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010744{
10745 int ret = 0;
10746
James Ketrenos43f66a62005-03-25 12:31:53 -060010747 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010748 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010749 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010750
David Howellsc4028952006-11-22 14:57:56 +000010751 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10752 INIT_WORK(&priv->associate, ipw_bg_associate);
10753 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10754 INIT_WORK(&priv->system_config, ipw_system_config);
10755 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10756 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10757 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10758 INIT_WORK(&priv->up, ipw_bg_up);
10759 INIT_WORK(&priv->down, ipw_bg_down);
10760 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010761 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10762 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010763 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010764 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10765 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10766 INIT_WORK(&priv->roam, ipw_bg_roam);
10767 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10768 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10769 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10770 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10771 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10772 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10773 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010774
Zhu Yie43e3c12006-04-13 17:20:45 +080010775#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010776 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010777#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010778
10779 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10780 ipw_irq_tasklet, (unsigned long)priv);
10781
10782 return ret;
10783}
10784
James Ketrenos43f66a62005-03-25 12:31:53 -060010785static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010786 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010787{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010788 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010789 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010790 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010791 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010792 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010793 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010794 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010795 priv->ieee->sec.flags &= ~(1 << i);
10796 else {
10797 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010798 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010799 priv->ieee->sec.flags |= (1 << i);
10800 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010801 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010802 } else if (sec->level != SEC_LEVEL_1)
10803 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010804 }
10805
James Ketrenosb095c382005-08-24 22:04:42 -050010806 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010807 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010808 priv->ieee->sec.active_key = sec->active_key;
10809 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010810 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010811 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010812 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010813 } else
10814 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010815
10816 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010817 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10818 priv->ieee->sec.auth_mode = sec->auth_mode;
10819 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010820 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10821 priv->capability |= CAP_SHARED_KEY;
10822 else
10823 priv->capability &= ~CAP_SHARED_KEY;
10824 priv->status |= STATUS_SECURITY_UPDATED;
10825 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010826
James Ketrenosb095c382005-08-24 22:04:42 -050010827 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10828 priv->ieee->sec.flags |= SEC_ENABLED;
10829 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010830 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010831 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010832 priv->capability |= CAP_PRIVACY_ON;
10833 else
10834 priv->capability &= ~CAP_PRIVACY_ON;
10835 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010836
James Ketrenosafbf30a2005-08-25 00:05:33 -050010837 if (sec->flags & SEC_ENCRYPT)
10838 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010839
James Ketrenosb095c382005-08-24 22:04:42 -050010840 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10841 priv->ieee->sec.level = sec->level;
10842 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010843 priv->status |= STATUS_SECURITY_UPDATED;
10844 }
10845
Zhu Yi1fbfea52005-08-05 17:22:56 +080010846 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10847 ipw_set_hwcrypto_keys(priv);
10848
Jeff Garzikbf794512005-07-31 13:07:26 -040010849 /* To match current functionality of ipw2100 (which works well w/
10850 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010851 * privacy capability changes ... */
10852#if 0
10853 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010854 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010855 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010856 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010857 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010858 IPW_DEBUG_ASSOC("Disassociating due to capability "
10859 "change.\n");
10860 ipw_disassociate(priv);
10861 }
10862#endif
10863}
10864
Jeff Garzikbf794512005-07-31 13:07:26 -040010865static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010866 struct ipw_supported_rates *rates)
10867{
10868 /* TODO: Mask out rates based on priv->rates_mask */
10869
10870 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010871 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010872 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010873 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010874 rates->ieee_mode = IPW_A_MODE;
10875 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010876 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10877 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010878 break;
10879
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010880 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010881 rates->ieee_mode = IPW_G_MODE;
10882 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010883 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10884 LIBIPW_CCK_DEFAULT_RATES_MASK);
10885 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10886 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10887 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010888 }
10889 break;
10890 }
10891
10892 return 0;
10893}
10894
Jeff Garzikbf794512005-07-31 13:07:26 -040010895static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010896{
James Ketrenos43f66a62005-03-25 12:31:53 -060010897 /* This is only called from ipw_up, which resets/reloads the firmware
10898 so, we don't need to first disable the card before we configure
10899 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010900 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010901 goto error;
10902
10903 /* initialize adapter address */
10904 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10905 goto error;
10906
10907 /* set basic system config settings */
10908 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010909
10910 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10911 * Does not support BT priority yet (don't abort or defer our Tx) */
10912 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010913 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010914
10915 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10916 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010917 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010918 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10919 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010920 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010921 }
10922
Zhu Yid685b8c2006-04-13 17:20:27 +080010923#ifdef CONFIG_IPW2200_PROMISCUOUS
10924 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10925 priv->sys_config.accept_all_data_frames = 1;
10926 priv->sys_config.accept_non_directed_frames = 1;
10927 priv->sys_config.accept_all_mgmt_bcpr = 1;
10928 priv->sys_config.accept_all_mgmt_frames = 1;
10929 }
10930#endif
10931
James Ketrenosc848d0a2005-08-24 21:56:24 -050010932 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10933 priv->sys_config.answer_broadcast_ssid_probe = 1;
10934 else
10935 priv->sys_config.answer_broadcast_ssid_probe = 0;
10936
Zhu Yid685b8c2006-04-13 17:20:27 +080010937 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010938 goto error;
10939
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010940 init_supported_rates(priv, &priv->rates);
10941 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010942 goto error;
10943
10944 /* Set request-to-send threshold */
10945 if (priv->rts_threshold) {
10946 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10947 goto error;
10948 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010949#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010950 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10951 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010952#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010953
10954 if (ipw_set_random_seed(priv))
10955 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010956
James Ketrenos43f66a62005-03-25 12:31:53 -060010957 /* final state transition to the RUN state */
10958 if (ipw_send_host_complete(priv))
10959 goto error;
10960
James Ketrenose6666192005-08-12 09:17:04 -050010961 priv->status |= STATUS_INIT;
10962
10963 ipw_led_init(priv);
10964 ipw_led_radio_on(priv);
10965 priv->notif_missed_beacons = 0;
10966
10967 /* Set hardware WEP key if it is configured. */
10968 if ((priv->capability & CAP_PRIVACY_ON) &&
10969 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10970 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10971 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010972
10973 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010974
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010975 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010976 return -EIO;
10977}
10978
James Ketrenos4f36f802005-08-03 20:36:56 -050010979/*
10980 * NOTE:
10981 *
10982 * These tables have been tested in conjunction with the
10983 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10984 *
10985 * Altering this values, using it on other hardware, or in geographies
10986 * not intended for resale of the above mentioned Intel adapters has
10987 * not been tested.
10988 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010989 * Remember to update the table in README.ipw2200 when changing this
10990 * table.
10991 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010992 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010993static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050010994 { /* Restricted */
10995 "---",
10996 .bg_channels = 11,
10997 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10998 {2427, 4}, {2432, 5}, {2437, 6},
10999 {2442, 7}, {2447, 8}, {2452, 9},
11000 {2457, 10}, {2462, 11}},
11001 },
11002
11003 { /* Custom US/Canada */
11004 "ZZF",
11005 .bg_channels = 11,
11006 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11007 {2427, 4}, {2432, 5}, {2437, 6},
11008 {2442, 7}, {2447, 8}, {2452, 9},
11009 {2457, 10}, {2462, 11}},
11010 .a_channels = 8,
11011 .a = {{5180, 36},
11012 {5200, 40},
11013 {5220, 44},
11014 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011015 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11016 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11017 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11018 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011019 },
11020
11021 { /* Rest of World */
11022 "ZZD",
11023 .bg_channels = 13,
11024 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11025 {2427, 4}, {2432, 5}, {2437, 6},
11026 {2442, 7}, {2447, 8}, {2452, 9},
11027 {2457, 10}, {2462, 11}, {2467, 12},
11028 {2472, 13}},
11029 },
11030
11031 { /* Custom USA & Europe & High */
11032 "ZZA",
11033 .bg_channels = 11,
11034 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11035 {2427, 4}, {2432, 5}, {2437, 6},
11036 {2442, 7}, {2447, 8}, {2452, 9},
11037 {2457, 10}, {2462, 11}},
11038 .a_channels = 13,
11039 .a = {{5180, 36},
11040 {5200, 40},
11041 {5220, 44},
11042 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011043 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11044 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11045 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11046 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011047 {5745, 149},
11048 {5765, 153},
11049 {5785, 157},
11050 {5805, 161},
11051 {5825, 165}},
11052 },
11053
11054 { /* Custom NA & Europe */
11055 "ZZB",
11056 .bg_channels = 11,
11057 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11058 {2427, 4}, {2432, 5}, {2437, 6},
11059 {2442, 7}, {2447, 8}, {2452, 9},
11060 {2457, 10}, {2462, 11}},
11061 .a_channels = 13,
11062 .a = {{5180, 36},
11063 {5200, 40},
11064 {5220, 44},
11065 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011066 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11067 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11068 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11069 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11070 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11071 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11072 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11073 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11074 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011075 },
11076
11077 { /* Custom Japan */
11078 "ZZC",
11079 .bg_channels = 11,
11080 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11081 {2427, 4}, {2432, 5}, {2437, 6},
11082 {2442, 7}, {2447, 8}, {2452, 9},
11083 {2457, 10}, {2462, 11}},
11084 .a_channels = 4,
11085 .a = {{5170, 34}, {5190, 38},
11086 {5210, 42}, {5230, 46}},
11087 },
11088
11089 { /* Custom */
11090 "ZZM",
11091 .bg_channels = 11,
11092 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11093 {2427, 4}, {2432, 5}, {2437, 6},
11094 {2442, 7}, {2447, 8}, {2452, 9},
11095 {2457, 10}, {2462, 11}},
11096 },
11097
11098 { /* Europe */
11099 "ZZE",
11100 .bg_channels = 13,
11101 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11102 {2427, 4}, {2432, 5}, {2437, 6},
11103 {2442, 7}, {2447, 8}, {2452, 9},
11104 {2457, 10}, {2462, 11}, {2467, 12},
11105 {2472, 13}},
11106 .a_channels = 19,
11107 .a = {{5180, 36},
11108 {5200, 40},
11109 {5220, 44},
11110 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011111 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11112 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11113 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11114 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11115 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11116 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11117 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11118 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11119 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11120 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11121 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11122 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11123 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11124 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11125 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011126 },
11127
11128 { /* Custom Japan */
11129 "ZZJ",
11130 .bg_channels = 14,
11131 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11132 {2427, 4}, {2432, 5}, {2437, 6},
11133 {2442, 7}, {2447, 8}, {2452, 9},
11134 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011135 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011136 .a_channels = 4,
11137 .a = {{5170, 34}, {5190, 38},
11138 {5210, 42}, {5230, 46}},
11139 },
11140
James Ketrenos03520572005-10-19 16:12:31 -050011141 { /* Rest of World */
11142 "ZZR",
11143 .bg_channels = 14,
11144 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11145 {2427, 4}, {2432, 5}, {2437, 6},
11146 {2442, 7}, {2447, 8}, {2452, 9},
11147 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011148 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11149 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011150 },
11151
James Ketrenos4f36f802005-08-03 20:36:56 -050011152 { /* High Band */
11153 "ZZH",
11154 .bg_channels = 13,
11155 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11156 {2427, 4}, {2432, 5}, {2437, 6},
11157 {2442, 7}, {2447, 8}, {2452, 9},
11158 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011159 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11160 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011161 .a_channels = 4,
11162 .a = {{5745, 149}, {5765, 153},
11163 {5785, 157}, {5805, 161}},
11164 },
11165
11166 { /* Custom Europe */
11167 "ZZG",
11168 .bg_channels = 13,
11169 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11170 {2427, 4}, {2432, 5}, {2437, 6},
11171 {2442, 7}, {2447, 8}, {2452, 9},
11172 {2457, 10}, {2462, 11},
11173 {2467, 12}, {2472, 13}},
11174 .a_channels = 4,
11175 .a = {{5180, 36}, {5200, 40},
11176 {5220, 44}, {5240, 48}},
11177 },
11178
11179 { /* Europe */
11180 "ZZK",
11181 .bg_channels = 13,
11182 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11183 {2427, 4}, {2432, 5}, {2437, 6},
11184 {2442, 7}, {2447, 8}, {2452, 9},
11185 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011186 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11187 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011188 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011189 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11190 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11191 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11192 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11193 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11194 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11195 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11196 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11197 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11198 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11199 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11200 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11201 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11202 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11203 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11204 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11205 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11206 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11207 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11208 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11209 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11210 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11211 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11212 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011213 },
11214
11215 { /* Europe */
11216 "ZZL",
11217 .bg_channels = 11,
11218 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11219 {2427, 4}, {2432, 5}, {2437, 6},
11220 {2442, 7}, {2447, 8}, {2452, 9},
11221 {2457, 10}, {2462, 11}},
11222 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011223 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11224 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11225 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11226 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11227 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11228 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11229 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11230 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11231 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11232 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11233 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11234 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11235 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011236 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011237};
11238
James Ketrenos43f66a62005-03-25 12:31:53 -060011239#define MAX_HW_RESTARTS 5
11240static int ipw_up(struct ipw_priv *priv)
11241{
James Ketrenos4f36f802005-08-03 20:36:56 -050011242 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011243
Dan Williamsc3d72b92009-02-11 13:26:06 -050011244 /* Age scan list entries found before suspend */
11245 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011246 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011247 priv->suspend_time = 0;
11248 }
11249
James Ketrenos43f66a62005-03-25 12:31:53 -060011250 if (priv->status & STATUS_EXIT_PENDING)
11251 return -EIO;
11252
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011253 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011254 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011255 GFP_KERNEL);
11256 if (priv->cmdlog == NULL) {
11257 IPW_ERROR("Error allocating %d command log entries.\n",
11258 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011259 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011260 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011261 priv->cmdlog_len = cmdlog;
11262 }
11263 }
11264
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011265 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011266 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011267 * Also start the clocks. */
11268 rc = ipw_load(priv);
11269 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011270 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011271 return rc;
11272 }
11273
11274 ipw_init_ordinals(priv);
11275 if (!(priv->config & CFG_CUSTOM_MAC))
11276 eeprom_parse_mac(priv, priv->mac_addr);
11277 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11278
James Ketrenos4f36f802005-08-03 20:36:56 -050011279 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11280 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11281 ipw_geos[j].name, 3))
11282 break;
11283 }
James Ketrenos03520572005-10-19 16:12:31 -050011284 if (j == ARRAY_SIZE(ipw_geos)) {
11285 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11286 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11287 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11288 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011289 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011290 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011291 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011292 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011293 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011294 }
11295
James Ketrenosb095c382005-08-24 22:04:42 -050011296 if (priv->status & STATUS_RF_KILL_SW) {
11297 IPW_WARNING("Radio disabled by module parameter.\n");
11298 return 0;
11299 } else if (rf_kill_active(priv)) {
11300 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11301 "Kill switch must be turned off for "
11302 "wireless networking to work.\n");
11303 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11304 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011305 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011306 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011307
11308 rc = ipw_config(priv);
11309 if (!rc) {
11310 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011311
James Ketrenose6666192005-08-12 09:17:04 -050011312 /* If configure to try and auto-associate, kick
11313 * off a scan. */
David Howellsc4028952006-11-22 14:57:56 +000011314 queue_delayed_work(priv->workqueue,
11315 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011316
James Ketrenos43f66a62005-03-25 12:31:53 -060011317 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011318 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011319
James Ketrenosc848d0a2005-08-24 21:56:24 -050011320 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011321 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11322 i, MAX_HW_RESTARTS);
11323
11324 /* We had an error bringing up the hardware, so take it
11325 * all the way back down so we can try again */
11326 ipw_down(priv);
11327 }
11328
Jeff Garzikbf794512005-07-31 13:07:26 -040011329 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011330 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011331 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011332
James Ketrenos43f66a62005-03-25 12:31:53 -060011333 return -EIO;
11334}
11335
David Howellsc4028952006-11-22 14:57:56 +000011336static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011337{
David Howellsc4028952006-11-22 14:57:56 +000011338 struct ipw_priv *priv =
11339 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011340 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011341 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011342 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011343}
11344
James Ketrenosb095c382005-08-24 22:04:42 -050011345static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011346{
James Ketrenosb095c382005-08-24 22:04:42 -050011347 int i;
11348
11349 if (priv->status & STATUS_SCANNING) {
11350 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11351 ipw_abort_scan(priv);
11352 }
11353
11354 if (priv->status & STATUS_ASSOCIATED) {
11355 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11356 ipw_disassociate(priv);
11357 }
11358
11359 ipw_led_shutdown(priv);
11360
11361 /* Wait up to 1s for status to change to not scanning and not
11362 * associated (disassociation can take a while for a ful 802.11
11363 * exchange */
11364 for (i = 1000; i && (priv->status &
11365 (STATUS_DISASSOCIATING |
11366 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11367 udelay(10);
11368
11369 if (priv->status & (STATUS_DISASSOCIATING |
11370 STATUS_ASSOCIATED | STATUS_SCANNING))
11371 IPW_DEBUG_INFO("Still associated or scanning...\n");
11372 else
11373 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11374
James Ketrenosc848d0a2005-08-24 21:56:24 -050011375 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011376 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011377
11378 priv->status &= ~STATUS_INIT;
11379}
11380
James Ketrenos43f66a62005-03-25 12:31:53 -060011381static void ipw_down(struct ipw_priv *priv)
11382{
James Ketrenosb095c382005-08-24 22:04:42 -050011383 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11384
11385 priv->status |= STATUS_EXIT_PENDING;
11386
11387 if (ipw_is_init(priv))
11388 ipw_deinit(priv);
11389
11390 /* Wipe out the EXIT_PENDING status bit if we are not actually
11391 * exiting the module */
11392 if (!exit_pending)
11393 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011394
11395 /* tell the device to stop sending interrupts */
11396 ipw_disable_interrupts(priv);
11397
11398 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011399 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011400 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011401
11402 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011403
11404 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011405}
11406
David Howellsc4028952006-11-22 14:57:56 +000011407static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011408{
David Howellsc4028952006-11-22 14:57:56 +000011409 struct ipw_priv *priv =
11410 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011411 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011412 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011413 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011414}
11415
11416/* Called by register_netdev() */
11417static int ipw_net_init(struct net_device *dev)
11418{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011419 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011420 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011421
James Ketrenosc848d0a2005-08-24 21:56:24 -050011422 if (ipw_up(priv)) {
John W. Linville8cc31742009-11-13 16:56:13 -050011423 mutex_unlock(&priv->mutex);
11424 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011425 }
11426
Zhu Yi46441512006-01-24 16:37:59 +080011427 mutex_unlock(&priv->mutex);
John W. Linville8cc31742009-11-13 16:56:13 -050011428 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011429}
11430
11431/* PCI driver stuff */
11432static struct pci_device_id card_ids[] = {
11433 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11434 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11435 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11436 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11437 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11438 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11439 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11440 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11441 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11442 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11443 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11444 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11445 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11446 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11447 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11448 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11449 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011450 {PCI_VDEVICE(INTEL, 0x104f), 0},
11451 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11452 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11453 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11454 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011455
James Ketrenos43f66a62005-03-25 12:31:53 -060011456 /* required last entry */
11457 {0,}
11458};
11459
11460MODULE_DEVICE_TABLE(pci, card_ids);
11461
11462static struct attribute *ipw_sysfs_entries[] = {
11463 &dev_attr_rf_kill.attr,
11464 &dev_attr_direct_dword.attr,
11465 &dev_attr_indirect_byte.attr,
11466 &dev_attr_indirect_dword.attr,
11467 &dev_attr_mem_gpio_reg.attr,
11468 &dev_attr_command_event_reg.attr,
11469 &dev_attr_nic_type.attr,
11470 &dev_attr_status.attr,
11471 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011472 &dev_attr_error.attr,
11473 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011474 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011475 &dev_attr_eeprom_delay.attr,
11476 &dev_attr_ucode_version.attr,
11477 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011478 &dev_attr_scan_age.attr,
11479 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011480 &dev_attr_speed_scan.attr,
11481 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011482 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011483#ifdef CONFIG_IPW2200_PROMISCUOUS
11484 &dev_attr_rtap_iface.attr,
11485 &dev_attr_rtap_filter.attr,
11486#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011487 NULL
11488};
11489
11490static struct attribute_group ipw_attribute_group = {
11491 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011492 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011493};
11494
Zhu Yid685b8c2006-04-13 17:20:27 +080011495#ifdef CONFIG_IPW2200_PROMISCUOUS
11496static int ipw_prom_open(struct net_device *dev)
11497{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011498 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011499 struct ipw_priv *priv = prom_priv->priv;
11500
11501 IPW_DEBUG_INFO("prom dev->open\n");
11502 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011503
11504 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11505 priv->sys_config.accept_all_data_frames = 1;
11506 priv->sys_config.accept_non_directed_frames = 1;
11507 priv->sys_config.accept_all_mgmt_bcpr = 1;
11508 priv->sys_config.accept_all_mgmt_frames = 1;
11509
11510 ipw_send_system_config(priv);
11511 }
11512
11513 return 0;
11514}
11515
11516static int ipw_prom_stop(struct net_device *dev)
11517{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011518 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011519 struct ipw_priv *priv = prom_priv->priv;
11520
11521 IPW_DEBUG_INFO("prom dev->stop\n");
11522
11523 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11524 priv->sys_config.accept_all_data_frames = 0;
11525 priv->sys_config.accept_non_directed_frames = 0;
11526 priv->sys_config.accept_all_mgmt_bcpr = 0;
11527 priv->sys_config.accept_all_mgmt_frames = 0;
11528
11529 ipw_send_system_config(priv);
11530 }
11531
11532 return 0;
11533}
11534
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011535static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11536 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011537{
11538 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011539 dev_kfree_skb(skb);
11540 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011541}
11542
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011543static const struct net_device_ops ipw_prom_netdev_ops = {
11544 .ndo_open = ipw_prom_open,
11545 .ndo_stop = ipw_prom_stop,
11546 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011547 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011548 .ndo_set_mac_address = eth_mac_addr,
11549 .ndo_validate_addr = eth_validate_addr,
11550};
11551
Zhu Yid685b8c2006-04-13 17:20:27 +080011552static int ipw_prom_alloc(struct ipw_priv *priv)
11553{
11554 int rc = 0;
11555
11556 if (priv->prom_net_dev)
11557 return -EPERM;
11558
John W. Linville8cc31742009-11-13 16:56:13 -050011559 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
Zhu Yid685b8c2006-04-13 17:20:27 +080011560 if (priv->prom_net_dev == NULL)
11561 return -ENOMEM;
11562
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011563 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011564 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11565 priv->prom_priv->priv = priv;
11566
11567 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011568 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011569
11570 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011571 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011572
11573 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011574 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011575
11576 rc = register_netdev(priv->prom_net_dev);
11577 if (rc) {
John W. Linville8cc31742009-11-13 16:56:13 -050011578 free_ieee80211(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011579 priv->prom_net_dev = NULL;
11580 return rc;
11581 }
11582
11583 return 0;
11584}
11585
11586static void ipw_prom_free(struct ipw_priv *priv)
11587{
11588 if (!priv->prom_net_dev)
11589 return;
11590
11591 unregister_netdev(priv->prom_net_dev);
John W. Linville8cc31742009-11-13 16:56:13 -050011592 free_ieee80211(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011593
11594 priv->prom_net_dev = NULL;
11595}
11596
11597#endif
11598
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011599static const struct net_device_ops ipw_netdev_ops = {
11600 .ndo_init = ipw_net_init,
11601 .ndo_open = ipw_net_open,
11602 .ndo_stop = ipw_net_stop,
11603 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11604 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011605 .ndo_start_xmit = libipw_xmit,
11606 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011607 .ndo_validate_addr = eth_validate_addr,
11608};
Zhu Yid685b8c2006-04-13 17:20:27 +080011609
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011610static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11611 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011612{
11613 int err = 0;
11614 struct net_device *net_dev;
11615 void __iomem *base;
11616 u32 length, val;
11617 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011618 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011619
John W. Linville8cc31742009-11-13 16:56:13 -050011620 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
James Ketrenos43f66a62005-03-25 12:31:53 -060011621 if (net_dev == NULL) {
11622 err = -ENOMEM;
11623 goto out;
11624 }
11625
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011626 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011627 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011628
James Ketrenos43f66a62005-03-25 12:31:53 -060011629 priv->net_dev = net_dev;
11630 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011631 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011632 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011633 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011634 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11635 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011636
Zhu Yi46441512006-01-24 16:37:59 +080011637 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011638 if (pci_enable_device(pdev)) {
11639 err = -ENODEV;
11640 goto out_free_ieee80211;
11641 }
11642
11643 pci_set_master(pdev);
11644
Yang Hongyang284901a2009-04-06 19:01:15 -070011645 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011646 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011647 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011648 if (err) {
11649 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11650 goto out_pci_disable_device;
11651 }
11652
11653 pci_set_drvdata(pdev, priv);
11654
11655 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011656 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011657 goto out_pci_disable_device;
11658
Jeff Garzikbf794512005-07-31 13:07:26 -040011659 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011660 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011661 pci_read_config_dword(pdev, 0x40, &val);
11662 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011663 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011664
James Ketrenos43f66a62005-03-25 12:31:53 -060011665 length = pci_resource_len(pdev, 0);
11666 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011667
Arjan van de Ven275f1652008-10-20 21:42:39 -070011668 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011669 if (!base) {
11670 err = -ENODEV;
11671 goto out_pci_release_regions;
11672 }
11673
11674 priv->hw_base = base;
11675 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11676 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11677
11678 err = ipw_setup_deferred_work(priv);
11679 if (err) {
11680 IPW_ERROR("Unable to setup deferred work\n");
11681 goto out_iounmap;
11682 }
11683
James Ketrenosb095c382005-08-24 22:04:42 -050011684 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011685
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011686 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011687 if (err) {
11688 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11689 goto out_destroy_workqueue;
11690 }
11691
James Ketrenos43f66a62005-03-25 12:31:53 -060011692 SET_NETDEV_DEV(net_dev, &pdev->dev);
11693
Zhu Yi46441512006-01-24 16:37:59 +080011694 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011695
James Ketrenos43f66a62005-03-25 12:31:53 -060011696 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11697 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011698 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011699
Zhu Yie43e3c12006-04-13 17:20:45 +080011700#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011701 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011702 priv->ieee->handle_probe_response = ipw_handle_beacon;
11703 priv->ieee->handle_beacon = ipw_handle_probe_response;
11704 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011705#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011706
James Ketrenosc848d0a2005-08-24 21:56:24 -050011707 priv->ieee->perfect_rssi = -20;
11708 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011709
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011710 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011711 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011712 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011713 net_dev->wireless_handlers = &ipw_wx_handler_def;
11714 net_dev->ethtool_ops = &ipw_ethtool_ops;
11715 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011716 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011717 net_dev->mem_start = pci_resource_start(pdev, 0);
11718 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11719
11720 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11721 if (err) {
11722 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011723 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011724 goto out_release_irq;
11725 }
11726
Zhu Yi46441512006-01-24 16:37:59 +080011727 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011728 err = register_netdev(net_dev);
11729 if (err) {
11730 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011731 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011732 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011733
Zhu Yid685b8c2006-04-13 17:20:27 +080011734#ifdef CONFIG_IPW2200_PROMISCUOUS
11735 if (rtap_iface) {
11736 err = ipw_prom_alloc(priv);
11737 if (err) {
11738 IPW_ERROR("Failed to register promiscuous network "
11739 "device (error %d).\n", err);
11740 unregister_netdev(priv->net_dev);
11741 goto out_remove_sysfs;
11742 }
11743 }
11744#endif
11745
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011746 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11747 "channels, %d 802.11a channels)\n",
11748 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11749 priv->ieee->geo.a_channels);
11750
James Ketrenos43f66a62005-03-25 12:31:53 -060011751 return 0;
11752
James Ketrenosa613bff2005-08-24 21:43:11 -050011753 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011754 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011755 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011756 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011757 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011758 destroy_workqueue(priv->workqueue);
11759 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011760 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011761 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011762 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011763 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011764 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011765 pci_disable_device(pdev);
11766 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011767 out_free_ieee80211:
John W. Linville8cc31742009-11-13 16:56:13 -050011768 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011769 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011770 return err;
11771}
11772
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011773static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011774{
11775 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011776 struct list_head *p, *q;
11777 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011778
James Ketrenos43f66a62005-03-25 12:31:53 -060011779 if (!priv)
11780 return;
11781
Zhu Yi46441512006-01-24 16:37:59 +080011782 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011783
James Ketrenosafbf30a2005-08-25 00:05:33 -050011784 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011785 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011786 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11787
Zhu Yi46441512006-01-24 16:37:59 +080011788 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011789
11790 unregister_netdev(priv->net_dev);
11791
11792 if (priv->rxq) {
11793 ipw_rx_queue_free(priv, priv->rxq);
11794 priv->rxq = NULL;
11795 }
11796 ipw_tx_queue_free(priv);
11797
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011798 if (priv->cmdlog) {
11799 kfree(priv->cmdlog);
11800 priv->cmdlog = NULL;
11801 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011802 /* ipw_down will ensure that there is no more pending work
11803 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011804 cancel_delayed_work(&priv->adhoc_check);
11805 cancel_delayed_work(&priv->gather_stats);
11806 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011807 cancel_delayed_work(&priv->request_direct_scan);
11808 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011809 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011810 cancel_delayed_work(&priv->rf_kill);
11811 cancel_delayed_work(&priv->scan_check);
11812 destroy_workqueue(priv->workqueue);
11813 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011814
James Ketrenosafbf30a2005-08-25 00:05:33 -050011815 /* Free MAC hash list for ADHOC */
11816 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11817 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011818 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011819 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011820 }
11821 }
11822
Jesper Juhl8f760782006-06-27 02:55:06 -070011823 kfree(priv->error);
11824 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011825
Zhu Yid685b8c2006-04-13 17:20:27 +080011826#ifdef CONFIG_IPW2200_PROMISCUOUS
11827 ipw_prom_free(priv);
11828#endif
11829
James Ketrenos43f66a62005-03-25 12:31:53 -060011830 free_irq(pdev->irq, priv);
11831 iounmap(priv->hw_base);
11832 pci_release_regions(pdev);
11833 pci_disable_device(pdev);
11834 pci_set_drvdata(pdev, NULL);
John W. Linville8cc31742009-11-13 16:56:13 -050011835 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011836 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011837}
11838
James Ketrenos43f66a62005-03-25 12:31:53 -060011839#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011840static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011841{
11842 struct ipw_priv *priv = pci_get_drvdata(pdev);
11843 struct net_device *dev = priv->net_dev;
11844
11845 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11846
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011847 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011848 ipw_down(priv);
11849
11850 /* Remove the PRESENT state of the device */
11851 netif_device_detach(dev);
11852
James Ketrenos43f66a62005-03-25 12:31:53 -060011853 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011854 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011855 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011856
Dan Williamsc3d72b92009-02-11 13:26:06 -050011857 priv->suspend_at = get_seconds();
11858
James Ketrenos43f66a62005-03-25 12:31:53 -060011859 return 0;
11860}
11861
11862static int ipw_pci_resume(struct pci_dev *pdev)
11863{
11864 struct ipw_priv *priv = pci_get_drvdata(pdev);
11865 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011866 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011867 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011868
James Ketrenos43f66a62005-03-25 12:31:53 -060011869 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11870
James Ketrenosea2b26e2005-08-24 21:25:16 -050011871 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011872 err = pci_enable_device(pdev);
11873 if (err) {
11874 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11875 dev->name);
11876 return err;
11877 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011878 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011879
James Ketrenos43f66a62005-03-25 12:31:53 -060011880 /*
11881 * Suspend/Resume resets the PCI configuration space, so we have to
11882 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11883 * from interfering with C3 CPU state. pci_restore_state won't help
11884 * here since it only restores the first 64 bytes pci config header.
11885 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011886 pci_read_config_dword(pdev, 0x40, &val);
11887 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011888 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11889
11890 /* Set the device back into the PRESENT state; this will also wake
11891 * the queue of needed */
11892 netif_device_attach(dev);
11893
Dan Williamsc3d72b92009-02-11 13:26:06 -050011894 priv->suspend_time = get_seconds() - priv->suspend_at;
11895
James Ketrenos43f66a62005-03-25 12:31:53 -060011896 /* Bring the device back up */
11897 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011898
James Ketrenos43f66a62005-03-25 12:31:53 -060011899 return 0;
11900}
11901#endif
11902
Zhu Yic8c22c92006-08-21 11:38:39 +080011903static void ipw_pci_shutdown(struct pci_dev *pdev)
11904{
11905 struct ipw_priv *priv = pci_get_drvdata(pdev);
11906
11907 /* Take down the device; powers it off, etc. */
11908 ipw_down(priv);
11909
11910 pci_disable_device(pdev);
11911}
11912
James Ketrenos43f66a62005-03-25 12:31:53 -060011913/* driver initialization stuff */
11914static struct pci_driver ipw_driver = {
11915 .name = DRV_NAME,
11916 .id_table = card_ids,
11917 .probe = ipw_pci_probe,
11918 .remove = __devexit_p(ipw_pci_remove),
11919#ifdef CONFIG_PM
11920 .suspend = ipw_pci_suspend,
11921 .resume = ipw_pci_resume,
11922#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080011923 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060011924};
11925
11926static int __init ipw_init(void)
11927{
11928 int ret;
11929
11930 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11931 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11932
Jeff Garzik29917622006-08-19 17:48:59 -040011933 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060011934 if (ret) {
11935 IPW_ERROR("Unable to initialize PCI module\n");
11936 return ret;
11937 }
11938
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011939 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011940 if (ret) {
11941 IPW_ERROR("Unable to create driver sysfs file\n");
11942 pci_unregister_driver(&ipw_driver);
11943 return ret;
11944 }
11945
11946 return ret;
11947}
11948
11949static void __exit ipw_exit(void)
11950{
11951 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11952 pci_unregister_driver(&ipw_driver);
11953}
11954
11955module_param(disable, int, 0444);
11956MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11957
11958module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060011959MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060011960
11961module_param(auto_create, int, 0444);
11962MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11963
Reinette Chatre21f8a732009-08-18 10:25:05 -070011964module_param_named(led, led_support, int, 0444);
Niels de Vos61a2d072008-07-31 00:07:23 -070011965MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
James Ketrenosa613bff2005-08-24 21:43:11 -050011966
James Ketrenos43f66a62005-03-25 12:31:53 -060011967module_param(debug, int, 0444);
11968MODULE_PARM_DESC(debug, "debug output mask");
11969
Reinette Chatre21f8a732009-08-18 10:25:05 -070011970module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011971MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011972
Zhu Yid685b8c2006-04-13 17:20:27 +080011973#ifdef CONFIG_IPW2200_PROMISCUOUS
11974module_param(rtap_iface, int, 0444);
11975MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11976#endif
11977
Zhu Yie43e3c12006-04-13 17:20:45 +080011978#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011979module_param(qos_enable, int, 0444);
11980MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011981
James Ketrenosb095c382005-08-24 22:04:42 -050011982module_param(qos_burst_enable, int, 0444);
11983MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11984
11985module_param(qos_no_ack_mask, int, 0444);
11986MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11987
11988module_param(burst_duration_CCK, int, 0444);
11989MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11990
11991module_param(burst_duration_OFDM, int, 0444);
11992MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011993#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011994
11995#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070011996module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060011997MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11998#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070011999module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012000MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12001#endif
12002
Zhu Yi810dabd2006-01-24 16:36:59 +080012003module_param(bt_coexist, int, 0444);
12004MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12005
James Ketrenosb095c382005-08-24 22:04:42 -050012006module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012007MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012008
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012009module_param(cmdlog, int, 0444);
12010MODULE_PARM_DESC(cmdlog,
12011 "allocate a ring buffer for logging firmware commands");
12012
Zhu Yi4bfdb912006-01-24 16:37:16 +080012013module_param(roaming, int, 0444);
12014MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12015
Zhu Yid2b83e12006-04-13 17:19:36 +080012016module_param(antenna, int, 0444);
12017MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12018
James Ketrenos43f66a62005-03-25 12:31:53 -060012019module_exit(ipw_exit);
12020module_init(ipw_init);