blob: 2dfe78acda97f11c6a61dc6b71246a946aac8933 [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
33#include "ipw2200.h"
34
Zhu Yiae4af612006-04-13 17:20:34 +080035
36#ifndef KBUILD_EXTMOD
37#define VK "k"
38#else
39#define VK
40#endif
41
42#ifdef CONFIG_IPW2200_DEBUG
43#define VD "d"
44#else
45#define VD
46#endif
47
48#ifdef CONFIG_IPW2200_MONITOR
49#define VM "m"
50#else
51#define VM
52#endif
53
54#ifdef CONFIG_IPW2200_PROMISCUOUS
55#define VP "p"
56#else
57#define VP
58#endif
59
Zhu Yi459d4082006-04-13 17:21:00 +080060#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080061#define VR "r"
62#else
63#define VR
64#endif
65
66#ifdef CONFIG_IPW2200_QOS
67#define VQ "q"
68#else
69#define VQ
70#endif
71
Zhu Yiee2c4ad2007-07-12 16:09:47 +080072#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060073#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080074#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060075#define DRV_VERSION IPW2200_VERSION
76
James Ketrenosb095c382005-08-24 22:04:42 -050077#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
78
James Ketrenos43f66a62005-03-25 12:31:53 -060079MODULE_DESCRIPTION(DRV_DESCRIPTION);
80MODULE_VERSION(DRV_VERSION);
81MODULE_AUTHOR(DRV_COPYRIGHT);
82MODULE_LICENSE("GPL");
Ben Hutchings873395a2009-11-07 21:59:10 +000083MODULE_FIRMWARE("ipw2200-ibss.fw");
84#ifdef CONFIG_IPW2200_MONITOR
85MODULE_FIRMWARE("ipw2200-sniffer.fw");
86#endif
87MODULE_FIRMWARE("ipw2200-bss.fw");
James Ketrenos43f66a62005-03-25 12:31:53 -060088
James Ketrenosf6c5cb72005-08-25 00:39:09 -050089static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060090static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070091static int default_channel = 0;
92static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060093
94static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060095static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060096static int auto_create = 1;
Reinette Chatre21f8a732009-08-18 10:25:05 -070097static int led_support = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060098static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080099static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +0800100static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +0800101static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600102static const char ipw_modes[] = {
103 'a', 'b', 'g', '?'
104};
Zhu Yid2b83e12006-04-13 17:19:36 +0800105static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600106
Zhu Yid685b8c2006-04-13 17:20:27 +0800107#ifdef CONFIG_IPW2200_PROMISCUOUS
108static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
109#endif
110
John W. Linvillea3caa992009-08-25 14:12:25 -0400111static struct ieee80211_rate ipw2200_rates[] = {
112 { .bitrate = 10 },
113 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
114 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
115 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
116 { .bitrate = 60 },
117 { .bitrate = 90 },
118 { .bitrate = 120 },
119 { .bitrate = 180 },
120 { .bitrate = 240 },
121 { .bitrate = 360 },
122 { .bitrate = 480 },
123 { .bitrate = 540 }
124};
125
126#define ipw2200_a_rates (ipw2200_rates + 4)
127#define ipw2200_num_a_rates 8
128#define ipw2200_bg_rates (ipw2200_rates + 0)
129#define ipw2200_num_bg_rates 12
Zhu Yid685b8c2006-04-13 17:20:27 +0800130
Zhu Yie43e3c12006-04-13 17:20:45 +0800131#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500132static int qos_enable = 0;
133static int qos_burst_enable = 0;
134static int qos_no_ack_mask = 0;
135static int burst_duration_CCK = 0;
136static int burst_duration_OFDM = 0;
137
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400138static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500139 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
140 QOS_TX3_CW_MIN_OFDM},
141 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
142 QOS_TX3_CW_MAX_OFDM},
143 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
144 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
145 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
146 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
147};
148
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400149static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500150 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
151 QOS_TX3_CW_MIN_CCK},
152 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
153 QOS_TX3_CW_MAX_CCK},
154 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
155 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
156 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
157 QOS_TX3_TXOP_LIMIT_CCK}
158};
159
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400160static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500161 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
162 DEF_TX3_CW_MIN_OFDM},
163 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
164 DEF_TX3_CW_MAX_OFDM},
165 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
166 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
167 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
168 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
169};
170
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400171static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500172 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
173 DEF_TX3_CW_MIN_CCK},
174 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
175 DEF_TX3_CW_MAX_CCK},
176 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
177 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
178 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
179 DEF_TX3_TXOP_LIMIT_CCK}
180};
181
182static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
183
184static int from_priority_to_tx_queue[] = {
185 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
186 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
187};
188
189static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
190
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400191static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500192 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400193static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500194 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800195#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500196
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000197static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500198static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600199static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400200static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600201 struct clx2_tx_queue *txq, int qindex);
202static int ipw_queue_reset(struct ipw_priv *priv);
203
204static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
205 int len, int sync);
206
207static void ipw_tx_queue_free(struct ipw_priv *);
208
209static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
210static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
211static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600212static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000213static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600214static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000215static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600216static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400217static int init_supported_rates(struct ipw_priv *priv,
218 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500219static void ipw_set_hwcrypto_keys(struct ipw_priv *);
220static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600221
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500222static int snprint_line(char *buf, size_t count,
223 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600224{
225 int out, i, j, l;
226 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400227
James Ketrenos43f66a62005-03-25 12:31:53 -0600228 out = snprintf(buf, count, "%08X", ofs);
229
230 for (l = 0, i = 0; i < 2; i++) {
231 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400232 for (j = 0; j < 8 && l < len; j++, l++)
233 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600234 data[(i * 8 + j)]);
235 for (; j < 8; j++)
236 out += snprintf(buf + out, count - out, " ");
237 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400238
James Ketrenos43f66a62005-03-25 12:31:53 -0600239 out += snprintf(buf + out, count - out, " ");
240 for (l = 0, i = 0; i < 2; i++) {
241 out += snprintf(buf + out, count - out, " ");
242 for (j = 0; j < 8 && l < len; j++, l++) {
243 c = data[(i * 8 + j)];
244 if (!isascii(c) || !isprint(c))
245 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400246
James Ketrenos43f66a62005-03-25 12:31:53 -0600247 out += snprintf(buf + out, count - out, "%c", c);
248 }
249
250 for (; j < 8; j++)
251 out += snprintf(buf + out, count - out, " ");
252 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400253
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500254 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600255}
256
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400257static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600258{
259 char line[81];
260 u32 ofs = 0;
261 if (!(ipw_debug_level & level))
262 return;
263
264 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500265 snprint_line(line, sizeof(line), &data[ofs],
266 min(len, 16U), ofs);
267 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600268 ofs += 16;
269 len -= min(len, 16U);
270 }
271}
272
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500273static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
274{
275 size_t out = size;
276 u32 ofs = 0;
277 int total = 0;
278
279 while (size && len) {
280 out = snprint_line(output, size, &data[ofs],
281 min_t(size_t, len, 16U), ofs);
282
283 ofs += 16;
284 output += out;
285 size -= out;
286 len -= min_t(size_t, len, 16U);
287 total += out;
288 }
289 return total;
290}
291
Zhu Yic8fe6672006-01-24 16:36:36 +0800292/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600293static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
294#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
295
Zhu Yic8fe6672006-01-24 16:36:36 +0800296/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600297static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
298#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
299
Zhu Yic8fe6672006-01-24 16:36:36 +0800300/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600301static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
302static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
303{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400304 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
305 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600306 _ipw_write_reg8(a, b, c);
307}
308
Zhu Yic8fe6672006-01-24 16:36:36 +0800309/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600310static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
311static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
312{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400313 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
314 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600315 _ipw_write_reg16(a, b, c);
316}
317
Zhu Yic8fe6672006-01-24 16:36:36 +0800318/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600319static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
320static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
321{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400322 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
323 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600324 _ipw_write_reg32(a, b, c);
325}
326
Zhu Yic8fe6672006-01-24 16:36:36 +0800327/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100328static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
329 u8 val)
330{
331 writeb(val, ipw->hw_base + ofs);
332}
Zhu Yic8fe6672006-01-24 16:36:36 +0800333
334/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200335#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100336 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
337 __LINE__, (u32)(ofs), (u32)(val)); \
338 _ipw_write8(ipw, ofs, val); \
339} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600340
Zhu Yic8fe6672006-01-24 16:36:36 +0800341/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100342static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
343 u16 val)
344{
345 writew(val, ipw->hw_base + ofs);
346}
Zhu Yic8fe6672006-01-24 16:36:36 +0800347
348/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100349#define ipw_write16(ipw, ofs, val) do { \
350 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
351 __LINE__, (u32)(ofs), (u32)(val)); \
352 _ipw_write16(ipw, ofs, val); \
353} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600354
Zhu Yic8fe6672006-01-24 16:36:36 +0800355/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100356static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
357 u32 val)
358{
359 writel(val, ipw->hw_base + ofs);
360}
Zhu Yic8fe6672006-01-24 16:36:36 +0800361
362/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100363#define ipw_write32(ipw, ofs, val) do { \
364 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
365 __LINE__, (u32)(ofs), (u32)(val)); \
366 _ipw_write32(ipw, ofs, val); \
367} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600368
Zhu Yic8fe6672006-01-24 16:36:36 +0800369/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100370static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400371{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100372 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600373}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400374
Zhu Yic8fe6672006-01-24 16:36:36 +0800375/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100376#define ipw_read8(ipw, ofs) ({ \
377 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
378 (u32)(ofs)); \
379 _ipw_read8(ipw, ofs); \
380})
James Ketrenos43f66a62005-03-25 12:31:53 -0600381
Zhu Yic8fe6672006-01-24 16:36:36 +0800382/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100383static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400384{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100385 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600386}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400387
Zhu Yic8fe6672006-01-24 16:36:36 +0800388/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100389#define ipw_read16(ipw, ofs) ({ \
390 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
391 (u32)(ofs)); \
392 _ipw_read16(ipw, ofs); \
393})
James Ketrenos43f66a62005-03-25 12:31:53 -0600394
Zhu Yic8fe6672006-01-24 16:36:36 +0800395/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100396static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400397{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100398 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600399}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400400
Zhu Yic8fe6672006-01-24 16:36:36 +0800401/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100402#define ipw_read32(ipw, ofs) ({ \
403 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
404 (u32)(ofs)); \
405 _ipw_read32(ipw, ofs); \
406})
James Ketrenos43f66a62005-03-25 12:31:53 -0600407
408static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800409/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100410#define ipw_read_indirect(a, b, c, d) ({ \
411 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
412 __LINE__, (u32)(b), (u32)(d)); \
413 _ipw_read_indirect(a, b, c, d); \
414})
James Ketrenos43f66a62005-03-25 12:31:53 -0600415
Zhu Yic8fe6672006-01-24 16:36:36 +0800416/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400417static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
418 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100419#define ipw_write_indirect(a, b, c, d) do { \
420 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
421 __LINE__, (u32)(b), (u32)(d)); \
422 _ipw_write_indirect(a, b, c, d); \
423} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600424
Zhu Yic8fe6672006-01-24 16:36:36 +0800425/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400426static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600427{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400428 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500429 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
430 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600431}
432
Zhu Yic8fe6672006-01-24 16:36:36 +0800433/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600434static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
435{
Zhu Yi2638bc32006-01-24 16:37:52 +0800436 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800437 u32 dif_len = reg - aligned_addr;
438
James Ketrenos43f66a62005-03-25 12:31:53 -0600439 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800440 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
441 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600442}
443
Zhu Yic8fe6672006-01-24 16:36:36 +0800444/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400445static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600446{
Zhu Yi2638bc32006-01-24 16:37:52 +0800447 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800448 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
449
James Ketrenos43f66a62005-03-25 12:31:53 -0600450 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800451 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
452 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600453}
454
Zhu Yic8fe6672006-01-24 16:36:36 +0800455/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600456static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
457{
458 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500459 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600460 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500461 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400462 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600463}
464
Zhu Yic8fe6672006-01-24 16:36:36 +0800465/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600466static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
467{
468 u32 value;
469
470 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
471
James Ketrenosb095c382005-08-24 22:04:42 -0500472 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
473 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600474 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
475 return value;
476}
477
Zhu Yic8fe6672006-01-24 16:36:36 +0800478/* General purpose, no alignment requirement, iterative (multi-byte) read, */
479/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600480static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
481 int num)
482{
Zhu Yi2638bc32006-01-24 16:37:52 +0800483 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600484 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600485 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400486
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
488
James Ketrenosea2b26e2005-08-24 21:25:16 -0500489 if (num <= 0) {
490 return;
491 }
492
Zhu Yic8fe6672006-01-24 16:36:36 +0800493 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600494 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500495 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600496 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500497 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500498 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600499 aligned_addr += 4;
500 }
501
Zhu Yic8fe6672006-01-24 16:36:36 +0800502 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500503 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500504 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500505 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400506
Zhu Yic8fe6672006-01-24 16:36:36 +0800507 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500508 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500509 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500510 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500511 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500512 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600513}
514
Zhu Yic8fe6672006-01-24 16:36:36 +0800515/* General purpose, no alignment requirement, iterative (multi-byte) write, */
516/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400517static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600518 int num)
519{
Zhu Yi2638bc32006-01-24 16:37:52 +0800520 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600521 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600522 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400523
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400525
James Ketrenosea2b26e2005-08-24 21:25:16 -0500526 if (num <= 0) {
527 return;
528 }
529
Zhu Yic8fe6672006-01-24 16:36:36 +0800530 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600531 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500532 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800533 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500534 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500535 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600536 aligned_addr += 4;
537 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400538
Zhu Yic8fe6672006-01-24 16:36:36 +0800539 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500540 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500541 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500542 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400543
Zhu Yic8fe6672006-01-24 16:36:36 +0800544 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500545 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500546 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500547 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500548 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500549 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600550}
551
Zhu Yic8fe6672006-01-24 16:36:36 +0800552/* General purpose, no alignment requirement, iterative (multi-byte) write, */
553/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400554static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600555 int num)
556{
557 memcpy_toio((priv->hw_base + addr), buf, num);
558}
559
Zhu Yic8fe6672006-01-24 16:36:36 +0800560/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600561static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
562{
563 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
564}
565
Zhu Yic8fe6672006-01-24 16:36:36 +0800566/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600567static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
568{
569 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
570}
571
Zhu Yi89c318e2006-06-08 22:19:49 -0700572static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600573{
574 if (priv->status & STATUS_INT_ENABLED)
575 return;
576 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500577 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600578}
579
Zhu Yi89c318e2006-06-08 22:19:49 -0700580static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600581{
582 if (!(priv->status & STATUS_INT_ENABLED))
583 return;
584 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500585 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600586}
587
Zhu Yi89c318e2006-06-08 22:19:49 -0700588static inline void ipw_enable_interrupts(struct ipw_priv *priv)
589{
590 unsigned long flags;
591
592 spin_lock_irqsave(&priv->irq_lock, flags);
593 __ipw_enable_interrupts(priv);
594 spin_unlock_irqrestore(&priv->irq_lock, flags);
595}
596
597static inline void ipw_disable_interrupts(struct ipw_priv *priv)
598{
599 unsigned long flags;
600
601 spin_lock_irqsave(&priv->irq_lock, flags);
602 __ipw_disable_interrupts(priv);
603 spin_unlock_irqrestore(&priv->irq_lock, flags);
604}
605
James Ketrenos43f66a62005-03-25 12:31:53 -0600606static char *ipw_error_desc(u32 val)
607{
608 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400609 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600610 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400611 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600612 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400613 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600614 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400615 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600616 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400617 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500618 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400619 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500620 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400621 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500622 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400623 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500624 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400625 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500626 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400627 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500628 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400629 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500630 return "DMA_STATUS";
631 case IPW_FW_ERROR_DINO_ERROR:
632 return "DINO_ERROR";
633 case IPW_FW_ERROR_EEPROM_ERROR:
634 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400635 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500636 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400637 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500638 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400639 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500640 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600641 }
642}
643
James Ketrenosb39860c2005-08-12 09:36:32 -0500644static void ipw_dump_error_log(struct ipw_priv *priv,
645 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600646{
James Ketrenosb39860c2005-08-12 09:36:32 -0500647 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600648
James Ketrenosb39860c2005-08-12 09:36:32 -0500649 if (!error) {
650 IPW_ERROR("Error allocating and capturing error log. "
651 "Nothing to dump.\n");
652 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600653 }
654
James Ketrenosb39860c2005-08-12 09:36:32 -0500655 IPW_ERROR("Start IPW Error Log Dump:\n");
656 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
657 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600658
James Ketrenosb39860c2005-08-12 09:36:32 -0500659 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400660 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500661 ipw_error_desc(error->elem[i].desc),
662 error->elem[i].time,
663 error->elem[i].blink1,
664 error->elem[i].blink2,
665 error->elem[i].link1,
666 error->elem[i].link2, error->elem[i].data);
667 for (i = 0; i < error->log_len; i++)
668 IPW_ERROR("%i\t0x%08x\t%i\n",
669 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500670 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600671}
James Ketrenos43f66a62005-03-25 12:31:53 -0600672
James Ketrenosc848d0a2005-08-24 21:56:24 -0500673static inline int ipw_is_init(struct ipw_priv *priv)
674{
675 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600676}
677
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400678static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600679{
680 u32 addr, field_info, field_len, field_count, total_len;
681
682 IPW_DEBUG_ORD("ordinal = %i\n", ord);
683
684 if (!priv || !val || !len) {
685 IPW_DEBUG_ORD("Invalid argument\n");
686 return -EINVAL;
687 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400688
James Ketrenos43f66a62005-03-25 12:31:53 -0600689 /* verify device ordinal tables have been initialized */
690 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
691 IPW_DEBUG_ORD("Access ordinals before initialization\n");
692 return -EINVAL;
693 }
694
695 switch (IPW_ORD_TABLE_ID_MASK & ord) {
696 case IPW_ORD_TABLE_0_MASK:
697 /*
698 * TABLE 0: Direct access to a table of 32 bit values
699 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400700 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600701 * read from the table
702 */
703
704 /* remove the table id from the ordinal */
705 ord &= IPW_ORD_TABLE_VALUE_MASK;
706
707 /* boundary check */
708 if (ord > priv->table0_len) {
709 IPW_DEBUG_ORD("ordinal value (%i) longer then "
710 "max (%i)\n", ord, priv->table0_len);
711 return -EINVAL;
712 }
713
714 /* verify we have enough room to store the value */
715 if (*len < sizeof(u32)) {
716 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200717 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600718 return -EINVAL;
719 }
720
721 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400722 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600723
724 *len = sizeof(u32);
725 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400726 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600727 break;
728
729 case IPW_ORD_TABLE_1_MASK:
730 /*
731 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400732 *
733 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600734 * representing starting addr for the data (which is
735 * also a u32)
736 */
737
738 /* remove the table id from the ordinal */
739 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400740
James Ketrenos43f66a62005-03-25 12:31:53 -0600741 /* boundary check */
742 if (ord > priv->table1_len) {
743 IPW_DEBUG_ORD("ordinal value too long\n");
744 return -EINVAL;
745 }
746
747 /* verify we have enough room to store the value */
748 if (*len < sizeof(u32)) {
749 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200750 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600751 return -EINVAL;
752 }
753
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400754 *((u32 *) val) =
755 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600756 *len = sizeof(u32);
757 break;
758
759 case IPW_ORD_TABLE_2_MASK:
760 /*
761 * TABLE 2: Indirect access to a table of variable sized values
762 *
763 * This table consist of six values, each containing
764 * - dword containing the starting offset of the data
765 * - dword containing the lengh in the first 16bits
766 * and the count in the second 16bits
767 */
768
769 /* remove the table id from the ordinal */
770 ord &= IPW_ORD_TABLE_VALUE_MASK;
771
772 /* boundary check */
773 if (ord > priv->table2_len) {
774 IPW_DEBUG_ORD("ordinal value too long\n");
775 return -EINVAL;
776 }
777
778 /* get the address of statistic */
779 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400780
781 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600782 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400783 field_info =
784 ipw_read_reg32(priv,
785 priv->table2_addr + (ord << 3) +
786 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400787
James Ketrenos43f66a62005-03-25 12:31:53 -0600788 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400789 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400790
James Ketrenos43f66a62005-03-25 12:31:53 -0600791 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400792 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400793
James Ketrenos43f66a62005-03-25 12:31:53 -0600794 /* abort if not enought memory */
795 total_len = field_len * field_count;
796 if (total_len > *len) {
797 *len = total_len;
798 return -EINVAL;
799 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400800
James Ketrenos43f66a62005-03-25 12:31:53 -0600801 *len = total_len;
802 if (!total_len)
803 return 0;
804
805 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400806 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600807 addr, total_len, field_info);
808 ipw_read_indirect(priv, addr, val, total_len);
809 break;
810
811 default:
812 IPW_DEBUG_ORD("Invalid ordinal!\n");
813 return -EINVAL;
814
815 }
816
James Ketrenos43f66a62005-03-25 12:31:53 -0600817 return 0;
818}
819
820static void ipw_init_ordinals(struct ipw_priv *priv)
821{
822 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400823 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600824
825 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
826 priv->table0_addr, priv->table0_len);
827
828 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
829 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
830
831 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
832 priv->table1_addr, priv->table1_len);
833
834 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
835 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400836 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600837
838 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
839 priv->table2_addr, priv->table2_len);
840
841}
842
Adrian Bunka73e22b2006-01-21 01:39:42 +0100843static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500844{
James Ketrenosb095c382005-08-24 22:04:42 -0500845 reg &= ~IPW_START_STANDBY;
846 if (reg & IPW_GATE_ODMA)
847 reg &= ~IPW_GATE_ODMA;
848 if (reg & IPW_GATE_IDMA)
849 reg &= ~IPW_GATE_IDMA;
850 if (reg & IPW_GATE_ADMA)
851 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500852 return reg;
853}
854
855/*
856 * LED behavior:
857 * - On radio ON, turn on any LEDs that require to be on during start
858 * - On initialization, start unassociated blink
859 * - On association, disable unassociated blink
860 * - On disassociation, start unassociated blink
861 * - On radio OFF, turn off any LEDs started during radio on
862 *
863 */
Zhu Yiede61112006-01-24 16:37:10 +0800864#define LD_TIME_LINK_ON msecs_to_jiffies(300)
865#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
866#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500867
Adrian Bunka73e22b2006-01-21 01:39:42 +0100868static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500869{
870 unsigned long flags;
871 u32 led;
872
873 /* If configured to not use LEDs, or nic_type is 1,
874 * then we don't toggle a LINK led */
875 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
876 return;
877
878 spin_lock_irqsave(&priv->lock, flags);
879
880 if (!(priv->status & STATUS_RF_KILL_MASK) &&
881 !(priv->status & STATUS_LED_LINK_ON)) {
882 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500883 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500884 led |= priv->led_association_on;
885
886 led = ipw_register_toggle(led);
887
888 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500889 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500890
891 priv->status |= STATUS_LED_LINK_ON;
892
893 /* If we aren't associated, schedule turning the LED off */
894 if (!(priv->status & STATUS_ASSOCIATED))
895 queue_delayed_work(priv->workqueue,
896 &priv->led_link_off,
897 LD_TIME_LINK_ON);
898 }
899
900 spin_unlock_irqrestore(&priv->lock, flags);
901}
902
David Howellsc4028952006-11-22 14:57:56 +0000903static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500904{
David Howellsc4028952006-11-22 14:57:56 +0000905 struct ipw_priv *priv =
906 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800907 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000908 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800909 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500910}
911
Adrian Bunka73e22b2006-01-21 01:39:42 +0100912static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500913{
914 unsigned long flags;
915 u32 led;
916
917 /* If configured not to use LEDs, or nic type is 1,
918 * then we don't goggle the LINK led. */
919 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
920 return;
921
922 spin_lock_irqsave(&priv->lock, flags);
923
924 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500925 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500926 led &= priv->led_association_off;
927 led = ipw_register_toggle(led);
928
929 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500930 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500931
932 IPW_DEBUG_LED("Link LED Off\n");
933
934 priv->status &= ~STATUS_LED_LINK_ON;
935
936 /* If we aren't associated and the radio is on, schedule
937 * turning the LED on (blink while unassociated) */
938 if (!(priv->status & STATUS_RF_KILL_MASK) &&
939 !(priv->status & STATUS_ASSOCIATED))
940 queue_delayed_work(priv->workqueue, &priv->led_link_on,
941 LD_TIME_LINK_OFF);
942
943 }
944
945 spin_unlock_irqrestore(&priv->lock, flags);
946}
947
David Howellsc4028952006-11-22 14:57:56 +0000948static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500949{
David Howellsc4028952006-11-22 14:57:56 +0000950 struct ipw_priv *priv =
951 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800952 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000953 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800954 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500955}
956
Arjan van de Ven858119e2006-01-14 13:20:43 -0800957static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500958{
James Ketrenosa613bff2005-08-24 21:43:11 -0500959 u32 led;
960
961 if (priv->config & CFG_NO_LED)
962 return;
963
James Ketrenosb095c382005-08-24 22:04:42 -0500964 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500965 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500966
967 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500968 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500969 led |= priv->led_activity_on;
970
971 led = ipw_register_toggle(led);
972
973 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500974 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500975
976 IPW_DEBUG_LED("Activity LED On\n");
977
978 priv->status |= STATUS_LED_ACT_ON;
979
James Ketrenosc848d0a2005-08-24 21:56:24 -0500980 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500981 queue_delayed_work(priv->workqueue, &priv->led_act_off,
982 LD_TIME_ACT_ON);
983 } else {
984 /* Reschedule LED off for full time period */
985 cancel_delayed_work(&priv->led_act_off);
986 queue_delayed_work(priv->workqueue, &priv->led_act_off,
987 LD_TIME_ACT_ON);
988 }
James Ketrenosb095c382005-08-24 22:04:42 -0500989}
James Ketrenosa613bff2005-08-24 21:43:11 -0500990
Adrian Bunka73e22b2006-01-21 01:39:42 +0100991#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500992void ipw_led_activity_on(struct ipw_priv *priv)
993{
994 unsigned long flags;
995 spin_lock_irqsave(&priv->lock, flags);
996 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500997 spin_unlock_irqrestore(&priv->lock, flags);
998}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100999#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -05001000
Adrian Bunka73e22b2006-01-21 01:39:42 +01001001static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001002{
1003 unsigned long flags;
1004 u32 led;
1005
1006 if (priv->config & CFG_NO_LED)
1007 return;
1008
1009 spin_lock_irqsave(&priv->lock, flags);
1010
1011 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001013 led &= priv->led_activity_off;
1014
1015 led = ipw_register_toggle(led);
1016
1017 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001018 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001019
1020 IPW_DEBUG_LED("Activity LED Off\n");
1021
1022 priv->status &= ~STATUS_LED_ACT_ON;
1023 }
1024
1025 spin_unlock_irqrestore(&priv->lock, flags);
1026}
1027
David Howellsc4028952006-11-22 14:57:56 +00001028static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001029{
David Howellsc4028952006-11-22 14:57:56 +00001030 struct ipw_priv *priv =
1031 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001032 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001033 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001034 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001035}
1036
Adrian Bunka73e22b2006-01-21 01:39:42 +01001037static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001038{
1039 unsigned long flags;
1040 u32 led;
1041
1042 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001043 if (priv->config & CFG_NO_LED ||
1044 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001045 return;
1046
1047 spin_lock_irqsave(&priv->lock, flags);
1048
James Ketrenosb095c382005-08-24 22:04:42 -05001049 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001050 if (priv->assoc_network->mode == IEEE_A) {
1051 led |= priv->led_ofdm_on;
1052 led &= priv->led_association_off;
1053 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1054 } else if (priv->assoc_network->mode == IEEE_G) {
1055 led |= priv->led_ofdm_on;
1056 led |= priv->led_association_on;
1057 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1058 } else {
1059 led &= priv->led_ofdm_off;
1060 led |= priv->led_association_on;
1061 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1062 }
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_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001073{
1074 unsigned long flags;
1075 u32 led;
1076
1077 /* Only nic type 1 supports mode LEDs */
1078 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1079 return;
1080
1081 spin_lock_irqsave(&priv->lock, flags);
1082
James Ketrenosb095c382005-08-24 22:04:42 -05001083 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001084 led &= priv->led_ofdm_off;
1085 led &= priv->led_association_off;
1086
1087 led = ipw_register_toggle(led);
1088
1089 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001090 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001091
1092 spin_unlock_irqrestore(&priv->lock, flags);
1093}
1094
Adrian Bunka73e22b2006-01-21 01:39:42 +01001095static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001096{
1097 ipw_led_link_on(priv);
1098}
1099
Adrian Bunka73e22b2006-01-21 01:39:42 +01001100static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001101{
1102 ipw_led_activity_off(priv);
1103 ipw_led_link_off(priv);
1104}
1105
Adrian Bunka73e22b2006-01-21 01:39:42 +01001106static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001107{
1108 /* Set the Link Led on for all nic types */
1109 ipw_led_link_on(priv);
1110}
1111
Adrian Bunka73e22b2006-01-21 01:39:42 +01001112static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001113{
1114 ipw_led_activity_off(priv);
1115 ipw_led_link_off(priv);
1116
1117 if (priv->status & STATUS_RF_KILL_MASK)
1118 ipw_led_radio_off(priv);
1119}
1120
Adrian Bunka73e22b2006-01-21 01:39:42 +01001121static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001122{
1123 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1124
1125 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001126 priv->led_activity_on = IPW_ACTIVITY_LED;
1127 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001128
James Ketrenosb095c382005-08-24 22:04:42 -05001129 priv->led_association_on = IPW_ASSOCIATED_LED;
1130 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001131
1132 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001133 priv->led_ofdm_on = IPW_OFDM_LED;
1134 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001135
1136 switch (priv->nic_type) {
1137 case EEPROM_NIC_TYPE_1:
1138 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001139 priv->led_activity_on = IPW_ASSOCIATED_LED;
1140 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1141 priv->led_association_on = IPW_ACTIVITY_LED;
1142 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001143
1144 if (!(priv->config & CFG_NO_LED))
1145 ipw_led_band_on(priv);
1146
1147 /* And we don't blink link LEDs for this nic, so
1148 * just return here */
1149 return;
1150
1151 case EEPROM_NIC_TYPE_3:
1152 case EEPROM_NIC_TYPE_2:
1153 case EEPROM_NIC_TYPE_4:
1154 case EEPROM_NIC_TYPE_0:
1155 break;
1156
1157 default:
1158 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1159 priv->nic_type);
1160 priv->nic_type = EEPROM_NIC_TYPE_0;
1161 break;
1162 }
1163
1164 if (!(priv->config & CFG_NO_LED)) {
1165 if (priv->status & STATUS_ASSOCIATED)
1166 ipw_led_link_on(priv);
1167 else
1168 ipw_led_link_off(priv);
1169 }
1170}
1171
Adrian Bunka73e22b2006-01-21 01:39:42 +01001172static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001173{
James Ketrenosa613bff2005-08-24 21:43:11 -05001174 ipw_led_activity_off(priv);
1175 ipw_led_link_off(priv);
1176 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001177 cancel_delayed_work(&priv->led_link_on);
1178 cancel_delayed_work(&priv->led_link_off);
1179 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001180}
1181
James Ketrenos43f66a62005-03-25 12:31:53 -06001182/*
1183 * The following adds a new attribute to the sysfs representation
1184 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1185 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001186 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001187 * See the level definitions in ipw for details.
1188 */
1189static ssize_t show_debug_level(struct device_driver *d, char *buf)
1190{
1191 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1192}
James Ketrenosa613bff2005-08-24 21:43:11 -05001193
1194static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1195 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001196{
1197 char *p = (char *)buf;
1198 u32 val;
1199
1200 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1201 p++;
1202 if (p[0] == 'x' || p[0] == 'X')
1203 p++;
1204 val = simple_strtoul(p, &p, 16);
1205 } else
1206 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001207 if (p == buf)
1208 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001209 ": %s is not in hex or decimal form.\n", buf);
1210 else
1211 ipw_debug_level = val;
1212
1213 return strnlen(buf, count);
1214}
1215
Jeff Garzikbf794512005-07-31 13:07:26 -04001216static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001217 show_debug_level, store_debug_level);
1218
James Ketrenosb39860c2005-08-12 09:36:32 -05001219static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1220{
Zhu Yic8fe6672006-01-24 16:36:36 +08001221 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001222 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1223}
1224
1225static void ipw_capture_event_log(struct ipw_priv *priv,
1226 u32 log_len, struct ipw_event *log)
1227{
1228 u32 base;
1229
1230 if (log_len) {
1231 base = ipw_read32(priv, IPW_EVENT_LOG);
1232 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1233 (u8 *) log, sizeof(*log) * log_len);
1234 }
1235}
1236
1237static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1238{
1239 struct ipw_fw_error *error;
1240 u32 log_len = ipw_get_event_log_len(priv);
1241 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1242 u32 elem_len = ipw_read_reg32(priv, base);
1243
1244 error = kmalloc(sizeof(*error) +
1245 sizeof(*error->elem) * elem_len +
1246 sizeof(*error->log) * log_len, GFP_ATOMIC);
1247 if (!error) {
1248 IPW_ERROR("Memory allocation for firmware error log "
1249 "failed.\n");
1250 return NULL;
1251 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001252 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001253 error->status = priv->status;
1254 error->config = priv->config;
1255 error->elem_len = elem_len;
1256 error->log_len = log_len;
1257 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001258 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001259
1260 ipw_capture_event_log(priv, log_len, error->log);
1261
1262 if (elem_len)
1263 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1264 sizeof(*error->elem) * elem_len);
1265
1266 return error;
1267}
1268
James Ketrenosb39860c2005-08-12 09:36:32 -05001269static ssize_t show_event_log(struct device *d,
1270 struct device_attribute *attr, char *buf)
1271{
1272 struct ipw_priv *priv = dev_get_drvdata(d);
1273 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001274 u32 log_size;
1275 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001276 u32 len = 0, i;
1277
Reinette Chatre412e9e72007-12-18 22:01:02 -08001278 /* not using min() because of its strict type checking */
1279 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1280 sizeof(*log) * log_len : PAGE_SIZE;
1281 log = kzalloc(log_size, GFP_KERNEL);
1282 if (!log) {
1283 IPW_ERROR("Unable to allocate memory for log\n");
1284 return 0;
1285 }
1286 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001287 ipw_capture_event_log(priv, log_len, log);
1288
1289 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1290 for (i = 0; i < log_len; i++)
1291 len += snprintf(buf + len, PAGE_SIZE - len,
1292 "\n%08X%08X%08X",
1293 log[i].time, log[i].event, log[i].data);
1294 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001295 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001296 return len;
1297}
1298
1299static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1300
1301static ssize_t show_error(struct device *d,
1302 struct device_attribute *attr, char *buf)
1303{
1304 struct ipw_priv *priv = dev_get_drvdata(d);
1305 u32 len = 0, i;
1306 if (!priv->error)
1307 return 0;
1308 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001309 "%08lX%08X%08X%08X",
1310 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001311 priv->error->status,
1312 priv->error->config, priv->error->elem_len);
1313 for (i = 0; i < priv->error->elem_len; i++)
1314 len += snprintf(buf + len, PAGE_SIZE - len,
1315 "\n%08X%08X%08X%08X%08X%08X%08X",
1316 priv->error->elem[i].time,
1317 priv->error->elem[i].desc,
1318 priv->error->elem[i].blink1,
1319 priv->error->elem[i].blink2,
1320 priv->error->elem[i].link1,
1321 priv->error->elem[i].link2,
1322 priv->error->elem[i].data);
1323
1324 len += snprintf(buf + len, PAGE_SIZE - len,
1325 "\n%08X", priv->error->log_len);
1326 for (i = 0; i < priv->error->log_len; i++)
1327 len += snprintf(buf + len, PAGE_SIZE - len,
1328 "\n%08X%08X%08X",
1329 priv->error->log[i].time,
1330 priv->error->log[i].event,
1331 priv->error->log[i].data);
1332 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1333 return len;
1334}
1335
1336static ssize_t clear_error(struct device *d,
1337 struct device_attribute *attr,
1338 const char *buf, size_t count)
1339{
1340 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001341
1342 kfree(priv->error);
1343 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001344 return count;
1345}
1346
1347static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1348
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001349static ssize_t show_cmd_log(struct device *d,
1350 struct device_attribute *attr, char *buf)
1351{
1352 struct ipw_priv *priv = dev_get_drvdata(d);
1353 u32 len = 0, i;
1354 if (!priv->cmdlog)
1355 return 0;
1356 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1357 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1358 i = (i + 1) % priv->cmdlog_len) {
1359 len +=
1360 snprintf(buf + len, PAGE_SIZE - len,
1361 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1362 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1363 priv->cmdlog[i].cmd.len);
1364 len +=
1365 snprintk_buf(buf + len, PAGE_SIZE - len,
1366 (u8 *) priv->cmdlog[i].cmd.param,
1367 priv->cmdlog[i].cmd.len);
1368 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1369 }
1370 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1371 return len;
1372}
1373
1374static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1375
Zhu Yid685b8c2006-04-13 17:20:27 +08001376#ifdef CONFIG_IPW2200_PROMISCUOUS
1377static void ipw_prom_free(struct ipw_priv *priv);
1378static int ipw_prom_alloc(struct ipw_priv *priv);
1379static ssize_t store_rtap_iface(struct device *d,
1380 struct device_attribute *attr,
1381 const char *buf, size_t count)
1382{
1383 struct ipw_priv *priv = dev_get_drvdata(d);
1384 int rc = 0;
1385
1386 if (count < 1)
1387 return -EINVAL;
1388
1389 switch (buf[0]) {
1390 case '0':
1391 if (!rtap_iface)
1392 return count;
1393
1394 if (netif_running(priv->prom_net_dev)) {
1395 IPW_WARNING("Interface is up. Cannot unregister.\n");
1396 return count;
1397 }
1398
1399 ipw_prom_free(priv);
1400 rtap_iface = 0;
1401 break;
1402
1403 case '1':
1404 if (rtap_iface)
1405 return count;
1406
1407 rc = ipw_prom_alloc(priv);
1408 if (!rc)
1409 rtap_iface = 1;
1410 break;
1411
1412 default:
1413 return -EINVAL;
1414 }
1415
1416 if (rc) {
1417 IPW_ERROR("Failed to register promiscuous network "
1418 "device (error %d).\n", rc);
1419 }
1420
1421 return count;
1422}
1423
1424static ssize_t show_rtap_iface(struct device *d,
1425 struct device_attribute *attr,
1426 char *buf)
1427{
1428 struct ipw_priv *priv = dev_get_drvdata(d);
1429 if (rtap_iface)
1430 return sprintf(buf, "%s", priv->prom_net_dev->name);
1431 else {
1432 buf[0] = '-';
1433 buf[1] = '1';
1434 buf[2] = '\0';
1435 return 3;
1436 }
1437}
1438
1439static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1440 store_rtap_iface);
1441
1442static ssize_t store_rtap_filter(struct device *d,
1443 struct device_attribute *attr,
1444 const char *buf, size_t count)
1445{
1446 struct ipw_priv *priv = dev_get_drvdata(d);
1447
1448 if (!priv->prom_priv) {
1449 IPW_ERROR("Attempting to set filter without "
1450 "rtap_iface enabled.\n");
1451 return -EPERM;
1452 }
1453
1454 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1455
1456 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1457 BIT_ARG16(priv->prom_priv->filter));
1458
1459 return count;
1460}
1461
1462static ssize_t show_rtap_filter(struct device *d,
1463 struct device_attribute *attr,
1464 char *buf)
1465{
1466 struct ipw_priv *priv = dev_get_drvdata(d);
1467 return sprintf(buf, "0x%04X",
1468 priv->prom_priv ? priv->prom_priv->filter : 0);
1469}
1470
1471static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1472 store_rtap_filter);
1473#endif
1474
James Ketrenosa613bff2005-08-24 21:43:11 -05001475static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1476 char *buf)
1477{
1478 struct ipw_priv *priv = dev_get_drvdata(d);
1479 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1480}
1481
1482static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1483 const char *buf, size_t count)
1484{
1485 struct ipw_priv *priv = dev_get_drvdata(d);
1486 struct net_device *dev = priv->net_dev;
1487 char buffer[] = "00000000";
1488 unsigned long len =
1489 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1490 unsigned long val;
1491 char *p = buffer;
1492
1493 IPW_DEBUG_INFO("enter\n");
1494
1495 strncpy(buffer, buf, len);
1496 buffer[len] = 0;
1497
1498 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1499 p++;
1500 if (p[0] == 'x' || p[0] == 'X')
1501 p++;
1502 val = simple_strtoul(p, &p, 16);
1503 } else
1504 val = simple_strtoul(p, &p, 10);
1505 if (p == buffer) {
1506 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1507 } else {
1508 priv->ieee->scan_age = val;
1509 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1510 }
1511
1512 IPW_DEBUG_INFO("exit\n");
1513 return len;
1514}
1515
1516static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1517
1518static ssize_t show_led(struct device *d, struct device_attribute *attr,
1519 char *buf)
1520{
1521 struct ipw_priv *priv = dev_get_drvdata(d);
1522 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1523}
1524
1525static ssize_t store_led(struct device *d, struct device_attribute *attr,
1526 const char *buf, size_t count)
1527{
1528 struct ipw_priv *priv = dev_get_drvdata(d);
1529
1530 IPW_DEBUG_INFO("enter\n");
1531
1532 if (count == 0)
1533 return 0;
1534
1535 if (*buf == 0) {
1536 IPW_DEBUG_LED("Disabling LED control.\n");
1537 priv->config |= CFG_NO_LED;
1538 ipw_led_shutdown(priv);
1539 } else {
1540 IPW_DEBUG_LED("Enabling LED control.\n");
1541 priv->config &= ~CFG_NO_LED;
1542 ipw_led_init(priv);
1543 }
1544
1545 IPW_DEBUG_INFO("exit\n");
1546 return count;
1547}
1548
1549static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1550
Andrew Mortonad3fee52005-06-20 14:30:36 -07001551static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001553{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001554 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001555 return sprintf(buf, "0x%08x\n", (int)p->status);
1556}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557
James Ketrenos43f66a62005-03-25 12:31:53 -06001558static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1559
Andrew Mortonad3fee52005-06-20 14:30:36 -07001560static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1561 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001562{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001563 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001564 return sprintf(buf, "0x%08x\n", (int)p->config);
1565}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001566
James Ketrenos43f66a62005-03-25 12:31:53 -06001567static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1568
Andrew Mortonad3fee52005-06-20 14:30:36 -07001569static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001570 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001571{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001572 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001573 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001574}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575
James Ketrenos43f66a62005-03-25 12:31:53 -06001576static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1577
Andrew Mortonad3fee52005-06-20 14:30:36 -07001578static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001579 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001580{
1581 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001582 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001583
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001584 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001585 return 0;
1586
1587 return sprintf(buf, "0x%08x\n", tmp);
1588}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001589
1590static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001591
Andrew Mortonad3fee52005-06-20 14:30:36 -07001592static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1593 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001594{
1595 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001596 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001597
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001598 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001599 return 0;
1600
1601 return sprintf(buf, "0x%08x\n", tmp);
1602}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001603
1604static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
1606/*
1607 * Add a device attribute to view/control the delay between eeprom
1608 * operations.
1609 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001610static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001611 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001612{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001613 struct ipw_priv *p = dev_get_drvdata(d);
1614 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001615 return sprintf(buf, "%i\n", n);
1616}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001617static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001618 struct device_attribute *attr,
1619 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001620{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001621 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001622 sscanf(buf, "%i", &p->eeprom_delay);
1623 return strnlen(buf, count);
1624}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001625
1626static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1627 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001628
Andrew Mortonad3fee52005-06-20 14:30:36 -07001629static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001630 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001631{
1632 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001633 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001634
James Ketrenosb095c382005-08-24 22:04:42 -05001635 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001636 return sprintf(buf, "0x%08x\n", reg);
1637}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001638static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001639 struct device_attribute *attr,
1640 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001641{
1642 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001643 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001644
1645 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001646 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001647 return strnlen(buf, count);
1648}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001649
1650static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1651 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001652
Andrew Mortonad3fee52005-06-20 14:30:36 -07001653static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001654 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001655{
1656 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001657 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001658
1659 reg = ipw_read_reg32(p, 0x301100);
1660 return sprintf(buf, "0x%08x\n", reg);
1661}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001662static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001663 struct device_attribute *attr,
1664 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001665{
1666 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001667 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001668
1669 sscanf(buf, "%x", &reg);
1670 ipw_write_reg32(p, 0x301100, reg);
1671 return strnlen(buf, count);
1672}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001673
1674static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1675 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001676
Andrew Mortonad3fee52005-06-20 14:30:36 -07001677static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001678 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001679{
1680 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001681 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001682
Jeff Garzikbf794512005-07-31 13:07:26 -04001683 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001684 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001685 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001686 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001687
James Ketrenos43f66a62005-03-25 12:31:53 -06001688 return sprintf(buf, "0x%08x\n", reg);
1689}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001690static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001691 struct device_attribute *attr,
1692 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001693{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001694 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001695
1696 sscanf(buf, "%x", &priv->indirect_dword);
1697 priv->status |= STATUS_INDIRECT_DWORD;
1698 return strnlen(buf, count);
1699}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001700
1701static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1702 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001703
Andrew Mortonad3fee52005-06-20 14:30:36 -07001704static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001705 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001706{
1707 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001708 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001709
Jeff Garzikbf794512005-07-31 13:07:26 -04001710 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001711 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001712 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001713 reg = 0;
1714
1715 return sprintf(buf, "0x%02x\n", reg);
1716}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001717static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001718 struct device_attribute *attr,
1719 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001720{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001721 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001722
1723 sscanf(buf, "%x", &priv->indirect_byte);
1724 priv->status |= STATUS_INDIRECT_BYTE;
1725 return strnlen(buf, count);
1726}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001727
1728static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001729 show_indirect_byte, store_indirect_byte);
1730
Andrew Mortonad3fee52005-06-20 14:30:36 -07001731static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001732 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001733{
1734 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001735 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001736
Jeff Garzikbf794512005-07-31 13:07:26 -04001737 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001738 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001739 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 reg = 0;
1741
1742 return sprintf(buf, "0x%08x\n", reg);
1743}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001744static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001745 struct device_attribute *attr,
1746 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001747{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001748 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001749
1750 sscanf(buf, "%x", &priv->direct_dword);
1751 priv->status |= STATUS_DIRECT_DWORD;
1752 return strnlen(buf, count);
1753}
James Ketrenos43f66a62005-03-25 12:31:53 -06001754
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001755static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1756 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001757
Arjan van de Ven858119e2006-01-14 13:20:43 -08001758static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001759{
1760 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1761 priv->status |= STATUS_RF_KILL_HW;
1762 else
1763 priv->status &= ~STATUS_RF_KILL_HW;
1764
1765 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1766}
1767
Andrew Mortonad3fee52005-06-20 14:30:36 -07001768static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001769 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001770{
1771 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001772 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001773 2 - HW based RF kill active
1774 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001775 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001777 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 return sprintf(buf, "%i\n", val);
1779}
1780
1781static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1782{
Jeff Garzikbf794512005-07-31 13:07:26 -04001783 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001784 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001785 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001786
1787 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1788 disable_radio ? "OFF" : "ON");
1789
1790 if (disable_radio) {
1791 priv->status |= STATUS_RF_KILL_SW;
1792
Dan Williams0b531672007-10-09 13:55:24 -04001793 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001794 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04001795 cancel_delayed_work(&priv->request_direct_scan);
1796 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04001797 cancel_delayed_work(&priv->scan_event);
1798 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001799 queue_work(priv->workqueue, &priv->down);
1800 } else {
1801 priv->status &= ~STATUS_RF_KILL_SW;
1802 if (rf_kill_active(priv)) {
1803 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1804 "disabled by HW switch\n");
1805 /* Make sure the RF_KILL check timer is running */
1806 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001807 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001808 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001809 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001810 queue_work(priv->workqueue, &priv->up);
1811 }
1812
1813 return 1;
1814}
1815
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001816static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1817 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001818{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001819 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001820
James Ketrenos43f66a62005-03-25 12:31:53 -06001821 ipw_radio_kill_sw(priv, buf[0] == '1');
1822
1823 return count;
1824}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001825
1826static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001827
James Ketrenosb095c382005-08-24 22:04:42 -05001828static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1829 char *buf)
1830{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001831 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001832 int pos = 0, len = 0;
1833 if (priv->config & CFG_SPEED_SCAN) {
1834 while (priv->speed_scan[pos] != 0)
1835 len += sprintf(&buf[len], "%d ",
1836 priv->speed_scan[pos++]);
1837 return len + sprintf(&buf[len], "\n");
1838 }
1839
1840 return sprintf(buf, "0\n");
1841}
1842
1843static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1844 const char *buf, size_t count)
1845{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001846 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001847 int channel, pos = 0;
1848 const char *p = buf;
1849
1850 /* list of space separated channels to scan, optionally ending with 0 */
1851 while ((channel = simple_strtol(p, NULL, 0))) {
1852 if (pos == MAX_SPEED_SCAN - 1) {
1853 priv->speed_scan[pos] = 0;
1854 break;
1855 }
1856
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001857 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001858 priv->speed_scan[pos++] = channel;
1859 else
1860 IPW_WARNING("Skipping invalid channel request: %d\n",
1861 channel);
1862 p = strchr(p, ' ');
1863 if (!p)
1864 break;
1865 while (*p == ' ' || *p == '\t')
1866 p++;
1867 }
1868
1869 if (pos == 0)
1870 priv->config &= ~CFG_SPEED_SCAN;
1871 else {
1872 priv->speed_scan_pos = 0;
1873 priv->config |= CFG_SPEED_SCAN;
1874 }
1875
1876 return count;
1877}
1878
1879static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1880 store_speed_scan);
1881
1882static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1883 char *buf)
1884{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001885 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001886 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1887}
1888
1889static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1890 const char *buf, size_t count)
1891{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001892 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001893 if (buf[0] == '1')
1894 priv->config |= CFG_NET_STATS;
1895 else
1896 priv->config &= ~CFG_NET_STATS;
1897
1898 return count;
1899}
1900
James Ketrenosafbf30a2005-08-25 00:05:33 -05001901static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1902 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001903
Zhu Yi375dd242007-02-14 16:04:24 +08001904static ssize_t show_channels(struct device *d,
1905 struct device_attribute *attr,
1906 char *buf)
1907{
1908 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001909 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001910 int len = 0, i;
1911
1912 len = sprintf(&buf[len],
1913 "Displaying %d channels in 2.4Ghz band "
1914 "(802.11bg):\n", geo->bg_channels);
1915
1916 for (i = 0; i < geo->bg_channels; i++) {
1917 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1918 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001919 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001920 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001921 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1922 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001923 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001924 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001925 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001926 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001927 "B" : "B/G");
1928 }
1929
1930 len += sprintf(&buf[len],
1931 "Displaying %d channels in 5.2Ghz band "
1932 "(802.11a):\n", geo->a_channels);
1933 for (i = 0; i < geo->a_channels; i++) {
1934 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1935 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001936 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001937 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001938 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1939 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001940 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001941 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001942 "passive only" : "active/passive");
1943 }
1944
1945 return len;
1946}
1947
1948static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1949
James Ketrenosea2b26e2005-08-24 21:25:16 -05001950static void notify_wx_assoc_event(struct ipw_priv *priv)
1951{
1952 union iwreq_data wrqu;
1953 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1954 if (priv->status & STATUS_ASSOCIATED)
1955 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1956 else
1957 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1958 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1959}
1960
James Ketrenos43f66a62005-03-25 12:31:53 -06001961static void ipw_irq_tasklet(struct ipw_priv *priv)
1962{
1963 u32 inta, inta_mask, handled = 0;
1964 unsigned long flags;
1965 int rc = 0;
1966
Zhu Yi89c318e2006-06-08 22:19:49 -07001967 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001968
James Ketrenosb095c382005-08-24 22:04:42 -05001969 inta = ipw_read32(priv, IPW_INTA_RW);
1970 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1971 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001972
1973 /* Add any cached INTA values that need to be handled */
1974 inta |= priv->isr_inta;
1975
Zhu Yi89c318e2006-06-08 22:19:49 -07001976 spin_unlock_irqrestore(&priv->irq_lock, flags);
1977
1978 spin_lock_irqsave(&priv->lock, flags);
1979
James Ketrenos43f66a62005-03-25 12:31:53 -06001980 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001981 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001982 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001983 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001984 }
1985
James Ketrenosb095c382005-08-24 22:04:42 -05001986 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001987 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001988 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001989 priv->status &= ~STATUS_HCMD_ACTIVE;
1990 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001991 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 }
1993
James Ketrenosb095c382005-08-24 22:04:42 -05001994 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001995 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001996 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001997 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001998 }
1999
James Ketrenosb095c382005-08-24 22:04:42 -05002000 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002002 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002003 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 }
2005
James Ketrenosb095c382005-08-24 22:04:42 -05002006 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002007 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002008 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002009 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002010 }
2011
James Ketrenosb095c382005-08-24 22:04:42 -05002012 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002013 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002014 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002015 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 }
2017
James Ketrenosb095c382005-08-24 22:04:42 -05002018 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002019 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002020 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 }
2022
James Ketrenosb095c382005-08-24 22:04:42 -05002023 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002024 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002025 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 }
2027
James Ketrenosb095c382005-08-24 22:04:42 -05002028 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002029 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002030 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002031 }
2032
James Ketrenosb095c382005-08-24 22:04:42 -05002033 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002034 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002035 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002036 }
2037
James Ketrenosb095c382005-08-24 22:04:42 -05002038 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002039 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002040 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002041 }
2042
James Ketrenosb095c382005-08-24 22:04:42 -05002043 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002044 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2045 priv->status |= STATUS_RF_KILL_HW;
2046 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002047 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002049 cancel_delayed_work(&priv->request_direct_scan);
2050 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002051 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002052 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002053 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002054 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002055 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002056
James Ketrenosb095c382005-08-24 22:04:42 -05002057 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002058 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002059 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002060 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002061 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2062 struct ipw_fw_error *error =
2063 ipw_alloc_error_log(priv);
2064 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002065 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002066 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002067 } else {
2068 priv->error = ipw_alloc_error_log(priv);
2069 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002070 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002071 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002072 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2073 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002074 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2075 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002076 }
2077
James Ketrenosb095c382005-08-24 22:04:42 -05002078 /* XXX: If hardware encryption is for WPA/WPA2,
2079 * we have to notify the supplicant. */
2080 if (priv->ieee->sec.encrypt) {
2081 priv->status &= ~STATUS_ASSOCIATED;
2082 notify_wx_assoc_event(priv);
2083 }
2084
2085 /* Keep the restart process from trying to send host
2086 * commands by clearing the INIT status bit */
2087 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002088
2089 /* Cancel currently queued command. */
2090 priv->status &= ~STATUS_HCMD_ACTIVE;
2091 wake_up_interruptible(&priv->wait_command_queue);
2092
James Ketrenos43f66a62005-03-25 12:31:53 -06002093 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002094 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002095 }
2096
James Ketrenosb095c382005-08-24 22:04:42 -05002097 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002098 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002099 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002100 }
2101
2102 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002103 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002104 }
2105
Zhu Yi89c318e2006-06-08 22:19:49 -07002106 spin_unlock_irqrestore(&priv->lock, flags);
2107
James Ketrenos43f66a62005-03-25 12:31:53 -06002108 /* enable all interrupts */
2109 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002110}
Jeff Garzikbf794512005-07-31 13:07:26 -04002111
James Ketrenos43f66a62005-03-25 12:31:53 -06002112#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2113static char *get_cmd_string(u8 cmd)
2114{
2115 switch (cmd) {
2116 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002117 IPW_CMD(POWER_DOWN);
2118 IPW_CMD(SYSTEM_CONFIG);
2119 IPW_CMD(MULTICAST_ADDRESS);
2120 IPW_CMD(SSID);
2121 IPW_CMD(ADAPTER_ADDRESS);
2122 IPW_CMD(PORT_TYPE);
2123 IPW_CMD(RTS_THRESHOLD);
2124 IPW_CMD(FRAG_THRESHOLD);
2125 IPW_CMD(POWER_MODE);
2126 IPW_CMD(WEP_KEY);
2127 IPW_CMD(TGI_TX_KEY);
2128 IPW_CMD(SCAN_REQUEST);
2129 IPW_CMD(SCAN_REQUEST_EXT);
2130 IPW_CMD(ASSOCIATE);
2131 IPW_CMD(SUPPORTED_RATES);
2132 IPW_CMD(SCAN_ABORT);
2133 IPW_CMD(TX_FLUSH);
2134 IPW_CMD(QOS_PARAMETERS);
2135 IPW_CMD(DINO_CONFIG);
2136 IPW_CMD(RSN_CAPABILITIES);
2137 IPW_CMD(RX_KEY);
2138 IPW_CMD(CARD_DISABLE);
2139 IPW_CMD(SEED_NUMBER);
2140 IPW_CMD(TX_POWER);
2141 IPW_CMD(COUNTRY_INFO);
2142 IPW_CMD(AIRONET_INFO);
2143 IPW_CMD(AP_TX_POWER);
2144 IPW_CMD(CCKM_INFO);
2145 IPW_CMD(CCX_VER_INFO);
2146 IPW_CMD(SET_CALIBRATION);
2147 IPW_CMD(SENSITIVITY_CALIB);
2148 IPW_CMD(RETRY_LIMIT);
2149 IPW_CMD(IPW_PRE_POWER_DOWN);
2150 IPW_CMD(VAP_BEACON_TEMPLATE);
2151 IPW_CMD(VAP_DTIM_PERIOD);
2152 IPW_CMD(EXT_SUPPORTED_RATES);
2153 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2154 IPW_CMD(VAP_QUIET_INTERVALS);
2155 IPW_CMD(VAP_CHANNEL_SWITCH);
2156 IPW_CMD(VAP_MANDATORY_CHANNELS);
2157 IPW_CMD(VAP_CELL_PWR_LIMIT);
2158 IPW_CMD(VAP_CF_PARAM_SET);
2159 IPW_CMD(VAP_SET_BEACONING_STATE);
2160 IPW_CMD(MEASUREMENT);
2161 IPW_CMD(POWER_CAPABILITY);
2162 IPW_CMD(SUPPORTED_CHANNELS);
2163 IPW_CMD(TPC_REPORT);
2164 IPW_CMD(WME_INFO);
2165 IPW_CMD(PRODUCTION_COMMAND);
2166 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002167 return "UNKNOWN";
2168 }
2169}
James Ketrenos43f66a62005-03-25 12:31:53 -06002170
2171#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002172
2173static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002174{
2175 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002176 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002177
James Ketrenosa613bff2005-08-24 21:43:11 -05002178 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002179 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002180 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2181 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002182 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002183 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002184 }
2185
2186 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002187
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002188 if (priv->cmdlog) {
2189 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2190 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2191 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2192 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2193 cmd->len);
2194 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2195 }
2196
James Ketrenosb095c382005-08-24 22:04:42 -05002197 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2198 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2199 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002200
2201#ifndef DEBUG_CMD_WEP_KEY
2202 if (cmd->cmd == IPW_CMD_WEP_KEY)
2203 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2204 else
2205#endif
2206 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2207
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002208 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002209 if (rc) {
2210 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002211 IPW_ERROR("Failed to send %s: Reason %d\n",
2212 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002213 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002214 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002215 }
2216 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002217
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002218 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2219 !(priv->
2220 status & STATUS_HCMD_ACTIVE),
2221 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002222 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002223 spin_lock_irqsave(&priv->lock, flags);
2224 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002225 IPW_ERROR("Failed to send %s: Command timed out.\n",
2226 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002227 priv->status &= ~STATUS_HCMD_ACTIVE;
2228 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002229 rc = -EIO;
2230 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002231 }
2232 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002233 } else
2234 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002235
James Ketrenosb095c382005-08-24 22:04:42 -05002236 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002237 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2238 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002239 rc = -EIO;
2240 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002241 }
2242
Zhu Yi2638bc32006-01-24 16:37:52 +08002243 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002244 if (priv->cmdlog) {
2245 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2246 priv->cmdlog_pos %= priv->cmdlog_len;
2247 }
2248 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002249}
2250
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002251static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002252{
2253 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002254 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002255 };
2256
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002257 return __ipw_send_cmd(priv, &cmd);
2258}
2259
2260static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2261 void *data)
2262{
2263 struct host_cmd cmd = {
2264 .cmd = command,
2265 .len = len,
2266 .param = data,
2267 };
2268
2269 return __ipw_send_cmd(priv, &cmd);
2270}
2271
2272static int ipw_send_host_complete(struct ipw_priv *priv)
2273{
James Ketrenos43f66a62005-03-25 12:31:53 -06002274 if (!priv) {
2275 IPW_ERROR("Invalid args\n");
2276 return -1;
2277 }
2278
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002279 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002280}
2281
Zhu Yid685b8c2006-04-13 17:20:27 +08002282static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002283{
Zhu Yid685b8c2006-04-13 17:20:27 +08002284 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2285 sizeof(priv->sys_config),
2286 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002287}
2288
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002289static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002290{
James Ketrenos43f66a62005-03-25 12:31:53 -06002291 if (!priv || !ssid) {
2292 IPW_ERROR("Invalid args\n");
2293 return -1;
2294 }
2295
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002296 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002297 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002298}
2299
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002300static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002301{
James Ketrenos43f66a62005-03-25 12:31:53 -06002302 if (!priv || !mac) {
2303 IPW_ERROR("Invalid args\n");
2304 return -1;
2305 }
2306
Johannes Berge1749612008-10-27 15:59:26 -07002307 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2308 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002309
Zhu Yi2638bc32006-01-24 16:37:52 +08002310 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002311}
2312
James Ketrenosa613bff2005-08-24 21:43:11 -05002313/*
2314 * NOTE: This must be executed from our workqueue as it results in udelay
2315 * being called which may corrupt the keyboard if executed on default
2316 * workqueue
2317 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002318static void ipw_adapter_restart(void *adapter)
2319{
2320 struct ipw_priv *priv = adapter;
2321
2322 if (priv->status & STATUS_RF_KILL_MASK)
2323 return;
2324
2325 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002326
2327 if (priv->assoc_network &&
2328 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2329 ipw_remove_current_network(priv);
2330
James Ketrenos43f66a62005-03-25 12:31:53 -06002331 if (ipw_up(priv)) {
2332 IPW_ERROR("Failed to up device\n");
2333 return;
2334 }
2335}
2336
David Howellsc4028952006-11-22 14:57:56 +00002337static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002338{
David Howellsc4028952006-11-22 14:57:56 +00002339 struct ipw_priv *priv =
2340 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002341 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002342 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002343 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002344}
2345
James Ketrenos43f66a62005-03-25 12:31:53 -06002346#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2347
2348static void ipw_scan_check(void *data)
2349{
2350 struct ipw_priv *priv = data;
2351 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2352 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002353 "adapter after (%dms).\n",
2354 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002355 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002356 }
2357}
2358
David Howellsc4028952006-11-22 14:57:56 +00002359static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002360{
David Howellsc4028952006-11-22 14:57:56 +00002361 struct ipw_priv *priv =
2362 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002363 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002364 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002365 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002366}
2367
James Ketrenos43f66a62005-03-25 12:31:53 -06002368static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2369 struct ipw_scan_request_ext *request)
2370{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002371 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002372 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002373}
2374
2375static int ipw_send_scan_abort(struct ipw_priv *priv)
2376{
James Ketrenos43f66a62005-03-25 12:31:53 -06002377 if (!priv) {
2378 IPW_ERROR("Invalid args\n");
2379 return -1;
2380 }
2381
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002382 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002383}
2384
2385static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2386{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002387 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002388 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002389 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002390
2391 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002392 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002393}
2394
2395static int ipw_send_associate(struct ipw_priv *priv,
2396 struct ipw_associate *associate)
2397{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002398 if (!priv || !associate) {
2399 IPW_ERROR("Invalid args\n");
2400 return -1;
2401 }
2402
Al Viro5b5e8072007-12-27 01:54:06 -05002403 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2404 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002405}
2406
2407static int ipw_send_supported_rates(struct ipw_priv *priv,
2408 struct ipw_supported_rates *rates)
2409{
James Ketrenos43f66a62005-03-25 12:31:53 -06002410 if (!priv || !rates) {
2411 IPW_ERROR("Invalid args\n");
2412 return -1;
2413 }
2414
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002415 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002416 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002417}
2418
2419static int ipw_set_random_seed(struct ipw_priv *priv)
2420{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002421 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002422
2423 if (!priv) {
2424 IPW_ERROR("Invalid args\n");
2425 return -1;
2426 }
2427
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002428 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002429
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002430 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002431}
2432
James Ketrenos43f66a62005-03-25 12:31:53 -06002433static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2434{
Al Viroe62e1ee2007-12-27 01:36:46 -05002435 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002436 if (!priv) {
2437 IPW_ERROR("Invalid args\n");
2438 return -1;
2439 }
2440
Al Viroe62e1ee2007-12-27 01:36:46 -05002441 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002442}
James Ketrenos43f66a62005-03-25 12:31:53 -06002443
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002444static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002445{
James Ketrenos43f66a62005-03-25 12:31:53 -06002446 if (!priv || !power) {
2447 IPW_ERROR("Invalid args\n");
2448 return -1;
2449 }
2450
Zhu Yi2638bc32006-01-24 16:37:52 +08002451 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002452}
James Ketrenos43f66a62005-03-25 12:31:53 -06002453
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002454static int ipw_set_tx_power(struct ipw_priv *priv)
2455{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002456 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002457 struct ipw_tx_power tx_power;
2458 s8 max_power;
2459 int i;
2460
2461 memset(&tx_power, 0, sizeof(tx_power));
2462
2463 /* configure device for 'G' band */
2464 tx_power.ieee_mode = IPW_G_MODE;
2465 tx_power.num_channels = geo->bg_channels;
2466 for (i = 0; i < geo->bg_channels; i++) {
2467 max_power = geo->bg[i].max_power;
2468 tx_power.channels_tx_power[i].channel_number =
2469 geo->bg[i].channel;
2470 tx_power.channels_tx_power[i].tx_power = max_power ?
2471 min(max_power, priv->tx_power) : priv->tx_power;
2472 }
2473 if (ipw_send_tx_power(priv, &tx_power))
2474 return -EIO;
2475
2476 /* configure device to also handle 'B' band */
2477 tx_power.ieee_mode = IPW_B_MODE;
2478 if (ipw_send_tx_power(priv, &tx_power))
2479 return -EIO;
2480
2481 /* configure device to also handle 'A' band */
2482 if (priv->ieee->abg_true) {
2483 tx_power.ieee_mode = IPW_A_MODE;
2484 tx_power.num_channels = geo->a_channels;
2485 for (i = 0; i < tx_power.num_channels; i++) {
2486 max_power = geo->a[i].max_power;
2487 tx_power.channels_tx_power[i].channel_number =
2488 geo->a[i].channel;
2489 tx_power.channels_tx_power[i].tx_power = max_power ?
2490 min(max_power, priv->tx_power) : priv->tx_power;
2491 }
2492 if (ipw_send_tx_power(priv, &tx_power))
2493 return -EIO;
2494 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002495 return 0;
2496}
2497
2498static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2499{
2500 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002501 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002502 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002503
2504 if (!priv) {
2505 IPW_ERROR("Invalid args\n");
2506 return -1;
2507 }
2508
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002509 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2510 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002511}
2512
2513static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2514{
2515 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002516 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002518
2519 if (!priv) {
2520 IPW_ERROR("Invalid args\n");
2521 return -1;
2522 }
2523
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002524 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2525 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002526}
2527
2528static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2529{
Al Viroe62e1ee2007-12-27 01:36:46 -05002530 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002531
2532 if (!priv) {
2533 IPW_ERROR("Invalid args\n");
2534 return -1;
2535 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002536
James Ketrenos43f66a62005-03-25 12:31:53 -06002537 /* If on battery, set to 3, if AC set to CAM, else user
2538 * level */
2539 switch (mode) {
2540 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002541 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002542 break;
2543 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002544 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002545 break;
2546 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002547 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002548 break;
2549 }
2550
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002551 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002552 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002553}
2554
James Ketrenosafbf30a2005-08-25 00:05:33 -05002555static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2556{
2557 struct ipw_retry_limit retry_limit = {
2558 .short_retry_limit = slimit,
2559 .long_retry_limit = llimit
2560 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002561
2562 if (!priv) {
2563 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 return -1;
2565 }
2566
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002567 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002568 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002569}
2570
2571/*
2572 * The IPW device contains a Microwire compatible EEPROM that stores
2573 * various data like the MAC address. Usually the firmware has exclusive
2574 * access to the eeprom, but during device initialization (before the
2575 * device driver has sent the HostComplete command to the firmware) the
2576 * device driver has read access to the EEPROM by way of indirect addressing
2577 * through a couple of memory mapped registers.
2578 *
2579 * The following is a simplified implementation for pulling data out of the
2580 * the eeprom, along with some helper functions to find information in
2581 * the per device private data's copy of the eeprom.
2582 *
2583 * NOTE: To better understand how these functions work (i.e what is a chip
2584 * select and why do have to keep driving the eeprom clock?), read
2585 * just about any data sheet for a Microwire compatible EEPROM.
2586 */
2587
2588/* write a 32 bit value into the indirect accessor register */
2589static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2590{
2591 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002592
James Ketrenos43f66a62005-03-25 12:31:53 -06002593 /* the eeprom requires some time to complete the operation */
2594 udelay(p->eeprom_delay);
2595
2596 return;
2597}
2598
2599/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002600static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002601{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002602 eeprom_write_reg(priv, 0);
2603 eeprom_write_reg(priv, EEPROM_BIT_CS);
2604 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2605 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002606}
2607
2608/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002609static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002610{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002611 eeprom_write_reg(priv, EEPROM_BIT_CS);
2612 eeprom_write_reg(priv, 0);
2613 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002614}
2615
2616/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002617static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002618{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002619 int d = (bit ? EEPROM_BIT_DI : 0);
2620 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2621 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002622}
2623
2624/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002626{
2627 int i;
2628
2629 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 eeprom_write_bit(priv, 1);
2631 eeprom_write_bit(priv, op & 2);
2632 eeprom_write_bit(priv, op & 1);
2633 for (i = 7; i >= 0; i--) {
2634 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002635 }
2636}
2637
2638/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002639static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002640{
2641 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002642 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002643
James Ketrenos43f66a62005-03-25 12:31:53 -06002644 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002645 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002646
2647 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002648 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002649
2650 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002651 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002652 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002653 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2654 eeprom_write_reg(priv, EEPROM_BIT_CS);
2655 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2656 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002657 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002658
James Ketrenos43f66a62005-03-25 12:31:53 -06002659 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002660 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002661 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002662
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 return r;
2664}
2665
2666/* helper function for pulling the mac address out of the private */
2667/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002669{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002670 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002671}
2672
2673/*
2674 * Either the device driver (i.e. the host) or the firmware can
2675 * load eeprom data into the designated region in SRAM. If neither
2676 * happens then the FW will shutdown with a fatal error.
2677 *
2678 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2679 * bit needs region of shared SRAM needs to be non-zero.
2680 */
2681static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2682{
2683 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002684 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002685
James Ketrenos43f66a62005-03-25 12:31:53 -06002686 IPW_DEBUG_TRACE(">>\n");
2687
2688 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002689 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002690 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002691
Jeff Garzikbf794512005-07-31 13:07:26 -04002692 /*
2693 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002694 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002695 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002696 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002697 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002698 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2699
2700 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002701 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002703
2704 /* Do not load eeprom data on fatal error or suspend */
2705 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2706 } else {
2707 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2708
2709 /* Load eeprom data on fatal error or suspend */
2710 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2711 }
2712
2713 IPW_DEBUG_TRACE("<<\n");
2714}
2715
Arjan van de Ven858119e2006-01-14 13:20:43 -08002716static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002717{
2718 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002719 if (!count)
2720 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002721 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002722 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002723 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002724}
2725
2726static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2727{
James Ketrenosb095c382005-08-24 22:04:42 -05002728 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002729 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002730 sizeof(struct command_block));
2731}
2732
2733static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002734{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002735
2736 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002737
James Ketrenos43f66a62005-03-25 12:31:53 -06002738 /* Start the dma */
2739 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002740
James Ketrenos43f66a62005-03-25 12:31:53 -06002741 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002742 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002743
2744 IPW_DEBUG_FW("<< : \n");
2745 return 0;
2746}
2747
2748static void ipw_fw_dma_abort(struct ipw_priv *priv)
2749{
2750 u32 control = 0;
2751
2752 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002753
Pavel Machek67fd6b42006-07-11 15:34:05 +02002754 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002755 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002756 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002757 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002758
James Ketrenos43f66a62005-03-25 12:31:53 -06002759 IPW_DEBUG_FW("<< \n");
2760}
2761
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002762static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2763 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002764{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002765 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002766 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002767 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002768 IPW_DEBUG_FW(">> :\n");
2769
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002770 ipw_write_indirect(priv, address, (u8 *) cb,
2771 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002772
2773 IPW_DEBUG_FW("<< :\n");
2774 return 0;
2775
2776}
2777
2778static int ipw_fw_dma_kick(struct ipw_priv *priv)
2779{
2780 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002781 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002782
2783 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002784
James Ketrenos43f66a62005-03-25 12:31:53 -06002785 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002786 ipw_fw_dma_write_command_block(priv, index,
2787 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002788
2789 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002790 ipw_clear_bit(priv, IPW_RESET_REG,
2791 IPW_RESET_REG_MASTER_DISABLED |
2792 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002793
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002794 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002796 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002797
2798 IPW_DEBUG_FW("<< :\n");
2799 return 0;
2800}
2801
2802static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2803{
2804 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 u32 register_value = 0;
2806 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002807
2808 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002809 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002810 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002811
2812 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002813 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2814 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002815
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002816 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002817 cb_fields_address = address;
2818 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002819 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002820
2821 cb_fields_address += sizeof(u32);
2822 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002823 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002824
2825 cb_fields_address += sizeof(u32);
2826 register_value = ipw_read_reg32(priv, cb_fields_address);
2827 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2828 register_value);
2829
2830 cb_fields_address += sizeof(u32);
2831 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002832 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002833
2834 IPW_DEBUG_FW(">> :\n");
2835}
2836
2837static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2838{
2839 u32 current_cb_address = 0;
2840 u32 current_cb_index = 0;
2841
2842 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002843 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002844
James Ketrenosb095c382005-08-24 22:04:42 -05002845 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002847
James Ketrenos43f66a62005-03-25 12:31:53 -06002848 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002849 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002850
2851 IPW_DEBUG_FW(">> :\n");
2852 return current_cb_index;
2853
2854}
2855
2856static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2857 u32 src_address,
2858 u32 dest_address,
2859 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002860 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002861{
2862
Jeff Garzikbf794512005-07-31 13:07:26 -04002863 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002864 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2865 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002866 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002867 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002868
2869 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2870 src_address, dest_address, length);
2871
2872 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2873 return -1;
2874
2875 last_cb_element = priv->sram_desc.last_cb_index;
2876 cb = &priv->sram_desc.cb_list[last_cb_element];
2877 priv->sram_desc.last_cb_index++;
2878
2879 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002880 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002881 control |= CB_INT_ENABLED;
2882
2883 if (is_last)
2884 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002885
James Ketrenos43f66a62005-03-25 12:31:53 -06002886 control |= length;
2887
2888 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002889 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002890
2891 /* Copy the Source and Destination addresses */
2892 cb->dest_addr = dest_address;
2893 cb->source_addr = src_address;
2894
2895 /* Copy the Control Word last */
2896 cb->control = control;
2897
2898 return 0;
2899}
2900
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002901static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2902 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002903{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002904 int ret, i;
2905 u32 size;
2906
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 IPW_DEBUG_FW(">> \n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002908 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2909 nr, dest_address, len);
2910
2911 for (i = 0; i < nr; i++) {
2912 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2913 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2914 dest_address +
2915 i * CB_MAX_LENGTH, size,
2916 0, 0);
2917 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002918 IPW_DEBUG_FW_INFO(": Failed\n");
2919 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002920 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002921 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002922 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002923
James Ketrenos43f66a62005-03-25 12:31:53 -06002924 IPW_DEBUG_FW("<< \n");
2925 return 0;
2926}
2927
2928static int ipw_fw_dma_wait(struct ipw_priv *priv)
2929{
Zhu Yi397ae122006-01-24 16:37:22 +08002930 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002931 u32 watchdog = 0;
2932
2933 IPW_DEBUG_FW(">> : \n");
2934
2935 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002936 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002937 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002938
2939 while (current_index < priv->sram_desc.last_cb_index) {
2940 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002941 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 current_index = ipw_fw_dma_command_block_index(priv);
2943
Zhu Yi397ae122006-01-24 16:37:22 +08002944 if (previous_index < current_index) {
2945 watchdog = 0;
2946 continue;
2947 }
2948 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002949 IPW_DEBUG_FW_INFO("Timeout\n");
2950 ipw_fw_dma_dump_command_block(priv);
2951 ipw_fw_dma_abort(priv);
2952 return -1;
2953 }
2954 }
2955
2956 ipw_fw_dma_abort(priv);
2957
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002958 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002959 ipw_set_bit(priv, IPW_RESET_REG,
2960 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002961
2962 IPW_DEBUG_FW("<< dmaWaitSync \n");
2963 return 0;
2964}
2965
Jeff Garzikbf794512005-07-31 13:07:26 -04002966static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002967{
2968 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002969 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002970 unsigned long flags;
2971
2972 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002973 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002974 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002975 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2976 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002977 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002978 &priv->ieee->network_free_list);
2979 }
2980 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002981 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002982}
2983
2984/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002985 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002986 * Reads debug register from domain0.
2987 * If card is present, pre-defined value should
2988 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002989 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002990 * @param priv
2991 * @return 1 if card is present, 0 otherwise
2992 */
2993static inline int ipw_alive(struct ipw_priv *priv)
2994{
2995 return ipw_read32(priv, 0x90) == 0xd55555d5;
2996}
2997
Zhu Yic7b6a672006-01-24 16:37:05 +08002998/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002999static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 int timeout)
3001{
3002 int i = 0;
3003
3004 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003005 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 return i;
3007 mdelay(10);
3008 i += 10;
3009 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003010
James Ketrenos43f66a62005-03-25 12:31:53 -06003011 return -ETIME;
3012}
3013
Jeff Garzikbf794512005-07-31 13:07:26 -04003014/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003015 * the ipw hardware. It assumes the buffer has all the bits for the
3016 * image and the caller is handling the memory allocation and clean up.
3017 */
3018
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003019static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003020{
3021 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003022
James Ketrenos43f66a62005-03-25 12:31:53 -06003023 IPW_DEBUG_TRACE(">> \n");
3024 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003025 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003026
Zhu Yic7b6a672006-01-24 16:37:05 +08003027 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003028 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3029 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003030 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003031 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003032 return -1;
3033 }
3034
3035 IPW_DEBUG_INFO("stop master %dms\n", rc);
3036
3037 return rc;
3038}
3039
3040static void ipw_arc_release(struct ipw_priv *priv)
3041{
3042 IPW_DEBUG_TRACE(">> \n");
3043 mdelay(5);
3044
James Ketrenosb095c382005-08-24 22:04:42 -05003045 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003046
3047 /* no one knows timing, for safety add some delay */
3048 mdelay(5);
3049}
3050
James Ketrenos43f66a62005-03-25 12:31:53 -06003051struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003052 __le32 address;
3053 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003054};
3055
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003056static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003057{
3058 int rc = 0, i, addr;
3059 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003060 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003061
Al Viroe62e1ee2007-12-27 01:36:46 -05003062 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003063
James Ketrenos43f66a62005-03-25 12:31:53 -06003064 IPW_DEBUG_TRACE(">> \n");
3065
3066 rc = ipw_stop_master(priv);
3067
3068 if (rc < 0)
3069 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003070
James Ketrenosb095c382005-08-24 22:04:42 -05003071 for (addr = IPW_SHARED_LOWER_BOUND;
3072 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003073 ipw_write32(priv, addr, 0);
3074 }
3075
3076 /* no ucode (yet) */
3077 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3078 /* destroy DMA queues */
3079 /* reset sequence */
3080
James Ketrenosb095c382005-08-24 22:04:42 -05003081 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003082 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003083 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003084 mdelay(1);
3085
3086 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003087 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003088 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003089
James Ketrenosb095c382005-08-24 22:04:42 -05003090 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003091 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003092
James Ketrenos43f66a62005-03-25 12:31:53 -06003093 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003094 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3095 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003096 mdelay(1);
3097
3098 /* write ucode */
3099 /**
3100 * @bug
3101 * Do NOT set indirect address register once and then
3102 * store data to indirect data register in the loop.
3103 * It seems very reasonable, but in this case DINO do not
3104 * accept ucode. It is essential to set address each time.
3105 */
3106 /* load new ipw uCode */
3107 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003108 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003109 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003110
James Ketrenos43f66a62005-03-25 12:31:53 -06003111 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003112 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3113 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003114
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003115 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003116
3117 /* wait for alive response */
3118 for (i = 0; i < 100; i++) {
3119 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003120 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003121 if (cr & DINO_RXFIFO_DATA)
3122 break;
3123 mdelay(1);
3124 }
3125
3126 if (cr & DINO_RXFIFO_DATA) {
3127 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003128 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003129
3130 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003131 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003132 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003133 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003134 memcpy(&priv->dino_alive, response_buffer,
3135 sizeof(priv->dino_alive));
3136 if (priv->dino_alive.alive_command == 1
3137 && priv->dino_alive.ucode_valid == 1) {
3138 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003139 IPW_DEBUG_INFO
3140 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3141 "of %02d/%02d/%02d %02d:%02d\n",
3142 priv->dino_alive.software_revision,
3143 priv->dino_alive.software_revision,
3144 priv->dino_alive.device_identifier,
3145 priv->dino_alive.device_identifier,
3146 priv->dino_alive.time_stamp[0],
3147 priv->dino_alive.time_stamp[1],
3148 priv->dino_alive.time_stamp[2],
3149 priv->dino_alive.time_stamp[3],
3150 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003151 } else {
3152 IPW_DEBUG_INFO("Microcode is not alive\n");
3153 rc = -EINVAL;
3154 }
3155 } else {
3156 IPW_DEBUG_INFO("No alive response from DINO\n");
3157 rc = -ETIME;
3158 }
3159
3160 /* disable DINO, otherwise for some reason
3161 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003162 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003163
James Ketrenos43f66a62005-03-25 12:31:53 -06003164 return rc;
3165}
3166
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003167static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003168{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003169 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 int offset = 0;
3171 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003172 int total_nr = 0;
3173 int i;
3174 struct pci_pool *pool;
3175 u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL];
3176 dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL];
James Ketrenos43f66a62005-03-25 12:31:53 -06003177
3178 IPW_DEBUG_TRACE("<< : \n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003179
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003180 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3181 if (!pool) {
3182 IPW_ERROR("pci_pool_create failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003184 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003185
3186 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003187 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003188
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003189 /* the DMA is already ready this would be a bug. */
3190 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003191
3192 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003193 u32 chunk_len;
3194 u8 *start;
3195 int size;
3196 int nr = 0;
3197
James Ketrenos43f66a62005-03-25 12:31:53 -06003198 chunk = (struct fw_chunk *)(data + offset);
3199 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003200 chunk_len = le32_to_cpu(chunk->length);
3201 start = data + offset;
3202
3203 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3204 for (i = 0; i < nr; i++) {
3205 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3206 &phys[total_nr]);
3207 if (!virts[total_nr]) {
3208 ret = -ENOMEM;
3209 goto out;
3210 }
3211 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3212 CB_MAX_LENGTH);
3213 memcpy(virts[total_nr], start, size);
3214 start += size;
3215 total_nr++;
3216 /* We don't support fw chunk larger than 64*8K */
3217 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3218 }
3219
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003221 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003222 * offeset*/
3223 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003224 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3225 nr, le32_to_cpu(chunk->address),
3226 chunk_len);
3227 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003228 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3229 goto out;
3230 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003231
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003232 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003233 } while (offset < len);
3234
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003235 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003236 ret = ipw_fw_dma_kick(priv);
3237 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003238 IPW_ERROR("dmaKick Failed\n");
3239 goto out;
3240 }
3241
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003242 ret = ipw_fw_dma_wait(priv);
3243 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 IPW_ERROR("dmaWaitSync Failed\n");
3245 goto out;
3246 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003247 out:
3248 for (i = 0; i < total_nr; i++)
3249 pci_pool_free(pool, virts[i], phys[i]);
3250
3251 pci_pool_destroy(pool);
3252
3253 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003254}
3255
3256/* stop nic */
3257static int ipw_stop_nic(struct ipw_priv *priv)
3258{
3259 int rc = 0;
3260
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003261 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003262 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003263
James Ketrenosb095c382005-08-24 22:04:42 -05003264 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3265 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003266 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003267 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003268 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003269 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003270
James Ketrenosb095c382005-08-24 22:04:42 -05003271 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003272
James Ketrenos43f66a62005-03-25 12:31:53 -06003273 return rc;
3274}
3275
3276static void ipw_start_nic(struct ipw_priv *priv)
3277{
3278 IPW_DEBUG_TRACE(">>\n");
3279
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003280 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003281 ipw_clear_bit(priv, IPW_RESET_REG,
3282 IPW_RESET_REG_MASTER_DISABLED |
3283 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003284 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003285
James Ketrenos43f66a62005-03-25 12:31:53 -06003286 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003287 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3288 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003289
3290 IPW_DEBUG_TRACE("<<\n");
3291}
Jeff Garzikbf794512005-07-31 13:07:26 -04003292
James Ketrenos43f66a62005-03-25 12:31:53 -06003293static int ipw_init_nic(struct ipw_priv *priv)
3294{
3295 int rc;
3296
3297 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003298 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003299 /*prvHwInitNic */
3300 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003301 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003302
3303 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003304 ipw_write32(priv, IPW_READ_INT_REGISTER,
3305 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003306
3307 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003308 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3309 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003310 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003311 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3312
3313 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003314 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003315
3316 udelay(10);
3317
3318 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003319 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003320
3321 IPW_DEBUG_TRACE(">>\n");
3322 return 0;
3323}
3324
Jeff Garzikbf794512005-07-31 13:07:26 -04003325/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003326 * Probe is an ok place to call this from.
3327 */
3328static int ipw_reset_nic(struct ipw_priv *priv)
3329{
3330 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003331 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003332
3333 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003334
James Ketrenos43f66a62005-03-25 12:31:53 -06003335 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003336
James Ketrenosa613bff2005-08-24 21:43:11 -05003337 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003338 /* Clear the 'host command active' bit... */
3339 priv->status &= ~STATUS_HCMD_ACTIVE;
3340 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003341 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3342 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003343 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003344
3345 IPW_DEBUG_TRACE("<<\n");
3346 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003347}
James Ketrenos43f66a62005-03-25 12:31:53 -06003348
James Ketrenos9006ea72006-03-08 03:22:28 +08003349
3350struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003351 __le32 ver;
3352 __le32 boot_size;
3353 __le32 ucode_size;
3354 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003355 u8 data[0];
3356};
3357
Jeff Garzikbf794512005-07-31 13:07:26 -04003358static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003359 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003360{
James Ketrenos9006ea72006-03-08 03:22:28 +08003361 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003362 int rc;
3363
3364 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003365 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003366 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003367 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003368 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003369 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003370
James Ketrenos9006ea72006-03-08 03:22:28 +08003371 if ((*raw)->size < sizeof(*fw)) {
3372 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003373 return -EINVAL;
3374 }
3375
James Ketrenos9006ea72006-03-08 03:22:28 +08003376 fw = (void *)(*raw)->data;
3377
Zhu Yi0070f8c2006-04-13 17:20:12 +08003378 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3379 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003380 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3381 name, (*raw)->size);
3382 return -EINVAL;
3383 }
3384
3385 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003386 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003387 le32_to_cpu(fw->ver) >> 16,
3388 le32_to_cpu(fw->ver) & 0xff,
3389 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003390 return 0;
3391}
3392
James Ketrenosb095c382005-08-24 22:04:42 -05003393#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003394
Arjan van de Ven858119e2006-01-14 13:20:43 -08003395static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 struct ipw_rx_queue *rxq)
3397{
3398 unsigned long flags;
3399 int i;
3400
3401 spin_lock_irqsave(&rxq->lock, flags);
3402
3403 INIT_LIST_HEAD(&rxq->rx_free);
3404 INIT_LIST_HEAD(&rxq->rx_used);
3405
3406 /* Fill the rx_used queue with _all_ of the Rx buffers */
3407 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3408 /* In the reset function, these buffers may have been allocated
3409 * to an SKB, so we need to unmap and free potential storage */
3410 if (rxq->pool[i].skb != NULL) {
3411 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003412 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003413 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003414 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003415 }
3416 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3417 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003418
James Ketrenos43f66a62005-03-25 12:31:53 -06003419 /* Set us so that we have processed and used all buffers, but have
3420 * not restocked the Rx queue with fresh buffers */
3421 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003422 rxq->free_count = 0;
3423 spin_unlock_irqrestore(&rxq->lock, flags);
3424}
3425
3426#ifdef CONFIG_PM
3427static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003428static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003429
3430static void free_firmware(void)
3431{
3432 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003433 release_firmware(raw);
3434 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003435 fw_loaded = 0;
3436 }
3437}
3438#else
3439#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003440#endif
3441
3442static int ipw_load(struct ipw_priv *priv)
3443{
3444#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003445 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003446#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003447 struct ipw_fw *fw;
3448 u8 *boot_img, *ucode_img, *fw_img;
3449 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003450 int rc = 0, retries = 3;
3451
Zhu Yi397ae122006-01-24 16:37:22 +08003452 switch (priv->ieee->iw_mode) {
3453 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003454 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003455 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003456#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003457 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003458 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003459 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003460#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003461 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003462 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003463 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003464 }
Zhu Yi397ae122006-01-24 16:37:22 +08003465
James Ketrenos9006ea72006-03-08 03:22:28 +08003466 if (!name) {
3467 rc = -EINVAL;
3468 goto error;
3469 }
3470
3471#ifdef CONFIG_PM
3472 if (!fw_loaded) {
3473#endif
3474 rc = ipw_get_fw(priv, &raw, name);
3475 if (rc < 0)
3476 goto error;
3477#ifdef CONFIG_PM
3478 }
3479#endif
3480
3481 fw = (void *)raw->data;
3482 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003483 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3484 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3485 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003486
Zhu Yi397ae122006-01-24 16:37:22 +08003487 if (rc < 0)
3488 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003489
3490 if (!priv->rxq)
3491 priv->rxq = ipw_rx_queue_alloc(priv);
3492 else
3493 ipw_rx_queue_reset(priv, priv->rxq);
3494 if (!priv->rxq) {
3495 IPW_ERROR("Unable to initialize Rx queue\n");
3496 goto error;
3497 }
3498
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003499 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003500 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003501 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003502 priv->status &= ~STATUS_INT_ENABLED;
3503
3504 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003505 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003506
James Ketrenos43f66a62005-03-25 12:31:53 -06003507 ipw_stop_nic(priv);
3508
3509 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003510 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003511 IPW_ERROR("Unable to reset NIC\n");
3512 goto error;
3513 }
3514
James Ketrenosb095c382005-08-24 22:04:42 -05003515 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3516 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003517
3518 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003519 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003520 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003521 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003522 goto error;
3523 }
3524
3525 /* kick start the device */
3526 ipw_start_nic(priv);
3527
Zhu Yic7b6a672006-01-24 16:37:05 +08003528 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003529 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3530 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003531 if (rc < 0) {
3532 IPW_ERROR("device failed to boot initial fw image\n");
3533 goto error;
3534 }
3535 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3536
Jeff Garzikbf794512005-07-31 13:07:26 -04003537 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003538 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003539
3540 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003541 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003542 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003543 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003544 goto error;
3545 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003546
James Ketrenos43f66a62005-03-25 12:31:53 -06003547 /* stop nic */
3548 ipw_stop_nic(priv);
3549
3550 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003551 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003552 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003553 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003554 goto error;
3555 }
Zhu Yi397ae122006-01-24 16:37:22 +08003556#ifdef CONFIG_PM
3557 fw_loaded = 1;
3558#endif
3559
James Ketrenos43f66a62005-03-25 12:31:53 -06003560 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3561
3562 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003563 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003564 IPW_ERROR("Unable to initialize queues\n");
3565 goto error;
3566 }
3567
3568 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003569 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003570 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003571 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003572
James Ketrenos43f66a62005-03-25 12:31:53 -06003573 /* kick start the device */
3574 ipw_start_nic(priv);
3575
James Ketrenosb095c382005-08-24 22:04:42 -05003576 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003577 if (retries > 0) {
3578 IPW_WARNING("Parity error. Retrying init.\n");
3579 retries--;
3580 goto retry;
3581 }
3582
3583 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3584 rc = -EIO;
3585 goto error;
3586 }
3587
3588 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003589 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3590 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003591 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003592 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003593 goto error;
3594 }
3595 IPW_DEBUG_INFO("device response after %dms\n", rc);
3596
3597 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003598 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003599
3600 /* read eeprom data and initialize the eeprom region of sram */
3601 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003602 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003603
3604 /* enable interrupts */
3605 ipw_enable_interrupts(priv);
3606
3607 /* Ensure our queue has valid packets */
3608 ipw_rx_queue_replenish(priv);
3609
James Ketrenosb095c382005-08-24 22:04:42 -05003610 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003611
3612 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003613 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003614
3615#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003616 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003617#endif
3618 return 0;
3619
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003620 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003621 if (priv->rxq) {
3622 ipw_rx_queue_free(priv, priv->rxq);
3623 priv->rxq = NULL;
3624 }
3625 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003626 if (raw)
3627 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003628#ifdef CONFIG_PM
3629 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003630 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003631#endif
3632
3633 return rc;
3634}
3635
Jeff Garzikbf794512005-07-31 13:07:26 -04003636/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003637 * DMA services
3638 *
3639 * Theory of operation
3640 *
3641 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3642 * 2 empty entries always kept in the buffer to protect from overflow.
3643 *
3644 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003645 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3646 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003647 * Tx queue resumed.
3648 *
3649 * The IPW operates with six queues, one receive queue in the device's
3650 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003651 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003652 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003653 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003654 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003655 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003656 * we only utilize the first data transmit queue (queue1).
3657 */
3658
3659/**
3660 * Driver allocates buffers of this size for Rx
3661 */
3662
Dan Williams943dbef2008-02-14 17:49:41 -05003663/**
3664 * ipw_rx_queue_space - Return number of free slots available in queue.
3665 */
3666static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3667{
3668 int s = q->read - q->write;
3669 if (s <= 0)
3670 s += RX_QUEUE_SIZE;
3671 /* keep some buffer to not confuse full and empty queue */
3672 s -= 2;
3673 if (s < 0)
3674 s = 0;
3675 return s;
3676}
3677
3678static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003679{
3680 int s = q->last_used - q->first_empty;
3681 if (s <= 0)
3682 s += q->n_bd;
3683 s -= 2; /* keep some reserve to not confuse empty and full situations */
3684 if (s < 0)
3685 s = 0;
3686 return s;
3687}
3688
3689static inline int ipw_queue_inc_wrap(int index, int n_bd)
3690{
3691 return (++index == n_bd) ? 0 : index;
3692}
3693
3694/**
3695 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003696 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003697 * @param q queue to init
3698 * @param count Number of BD's to allocate. Should be power of 2
3699 * @param read_register Address for 'read' register
3700 * (not offset within BAR, full address)
3701 * @param write_register Address for 'write' register
3702 * (not offset within BAR, full address)
3703 * @param base_register Address for 'base' register
3704 * (not offset within BAR, full address)
3705 * @param size Address for 'size' register
3706 * (not offset within BAR, full address)
3707 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003708static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003709 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003710{
3711 q->n_bd = count;
3712
3713 q->low_mark = q->n_bd / 4;
3714 if (q->low_mark < 4)
3715 q->low_mark = 4;
3716
3717 q->high_mark = q->n_bd / 8;
3718 if (q->high_mark < 2)
3719 q->high_mark = 2;
3720
3721 q->first_empty = q->last_used = 0;
3722 q->reg_r = read;
3723 q->reg_w = write;
3724
3725 ipw_write32(priv, base, q->dma_addr);
3726 ipw_write32(priv, size, count);
3727 ipw_write32(priv, read, 0);
3728 ipw_write32(priv, write, 0);
3729
3730 _ipw_read32(priv, 0x90);
3731}
3732
Jeff Garzikbf794512005-07-31 13:07:26 -04003733static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003734 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003735 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003736{
3737 struct pci_dev *dev = priv->pci_dev;
3738
3739 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3740 if (!q->txb) {
3741 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3742 return -ENOMEM;
3743 }
3744
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003745 q->bd =
3746 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003747 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003748 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003749 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003750 kfree(q->txb);
3751 q->txb = NULL;
3752 return -ENOMEM;
3753 }
3754
3755 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3756 return 0;
3757}
3758
3759/**
3760 * Free one TFD, those at index [txq->q.last_used].
3761 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003762 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003763 * @param dev
3764 * @param txq
3765 */
3766static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3767 struct clx2_tx_queue *txq)
3768{
3769 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3770 struct pci_dev *dev = priv->pci_dev;
3771 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003772
James Ketrenos43f66a62005-03-25 12:31:53 -06003773 /* classify bd */
3774 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3775 /* nothing to cleanup after for host commands */
3776 return;
3777
3778 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003779 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3780 IPW_ERROR("Too many chunks: %i\n",
3781 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 /** @todo issue fatal error, it is quite serious situation */
3783 return;
3784 }
3785
3786 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003787 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3788 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3789 le16_to_cpu(bd->u.data.chunk_len[i]),
3790 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003792 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003793 txq->txb[txq->q.last_used] = NULL;
3794 }
3795 }
3796}
3797
3798/**
3799 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003800 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003801 * Empty queue by removing and destroying all BD's.
3802 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003803 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003804 * @param dev
3805 * @param q
3806 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003807static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003808{
3809 struct clx2_queue *q = &txq->q;
3810 struct pci_dev *dev = priv->pci_dev;
3811
Jeff Garzikbf794512005-07-31 13:07:26 -04003812 if (q->n_bd == 0)
3813 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003814
3815 /* first, empty all BD's */
3816 for (; q->first_empty != q->last_used;
3817 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3818 ipw_queue_tx_free_tfd(priv, txq);
3819 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003820
James Ketrenos43f66a62005-03-25 12:31:53 -06003821 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003822 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003823 q->dma_addr);
3824 kfree(txq->txb);
3825
3826 /* 0 fill whole structure */
3827 memset(txq, 0, sizeof(*txq));
3828}
3829
James Ketrenos43f66a62005-03-25 12:31:53 -06003830/**
3831 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003832 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003833 * @param priv
3834 */
3835static void ipw_tx_queue_free(struct ipw_priv *priv)
3836{
3837 /* Tx CMD queue */
3838 ipw_queue_tx_free(priv, &priv->txq_cmd);
3839
3840 /* Tx queues */
3841 ipw_queue_tx_free(priv, &priv->txq[0]);
3842 ipw_queue_tx_free(priv, &priv->txq[1]);
3843 ipw_queue_tx_free(priv, &priv->txq[2]);
3844 ipw_queue_tx_free(priv, &priv->txq[3]);
3845}
3846
Arjan van de Ven858119e2006-01-14 13:20:43 -08003847static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003848{
3849 /* First 3 bytes are manufacturer */
3850 bssid[0] = priv->mac_addr[0];
3851 bssid[1] = priv->mac_addr[1];
3852 bssid[2] = priv->mac_addr[2];
3853
3854 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003855 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003856
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003857 bssid[0] &= 0xfe; /* clear multicast bit */
3858 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003859}
3860
Arjan van de Ven858119e2006-01-14 13:20:43 -08003861static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003862{
3863 struct ipw_station_entry entry;
3864 int i;
3865
3866 for (i = 0; i < priv->num_stations; i++) {
3867 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3868 /* Another node is active in network */
3869 priv->missed_adhoc_beacons = 0;
3870 if (!(priv->config & CFG_STATIC_CHANNEL))
3871 /* when other nodes drop out, we drop out */
3872 priv->config &= ~CFG_ADHOC_PERSIST;
3873
3874 return i;
3875 }
3876 }
3877
3878 if (i == MAX_STATIONS)
3879 return IPW_INVALID_STATION;
3880
Johannes Berge1749612008-10-27 15:59:26 -07003881 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003882
3883 entry.reserved = 0;
3884 entry.support_mode = 0;
3885 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3886 memcpy(priv->stations[i], bssid, ETH_ALEN);
3887 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003888 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003889 priv->num_stations++;
3890
3891 return i;
3892}
3893
Arjan van de Ven858119e2006-01-14 13:20:43 -08003894static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003895{
3896 int i;
3897
Jeff Garzikbf794512005-07-31 13:07:26 -04003898 for (i = 0; i < priv->num_stations; i++)
3899 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003900 return i;
3901
3902 return IPW_INVALID_STATION;
3903}
3904
3905static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3906{
3907 int err;
3908
Hong Liu7b996592005-08-25 17:36:13 +08003909 if (priv->status & STATUS_ASSOCIATING) {
3910 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3911 queue_work(priv->workqueue, &priv->disassociate);
3912 return;
3913 }
3914
3915 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003916 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3917 return;
3918 }
3919
Johannes Berge1749612008-10-27 15:59:26 -07003920 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003921 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003922 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003923 priv->assoc_request.channel);
3924
3925 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3926 priv->status |= STATUS_DISASSOCIATING;
3927
3928 if (quiet)
3929 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3930 else
3931 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003932
James Ketrenos43f66a62005-03-25 12:31:53 -06003933 err = ipw_send_associate(priv, &priv->assoc_request);
3934 if (err) {
3935 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3936 "failed.\n");
3937 return;
3938 }
3939
3940}
3941
James Ketrenosc848d0a2005-08-24 21:56:24 -05003942static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003943{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003944 struct ipw_priv *priv = data;
3945 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3946 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003947 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003948 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003949 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003950}
3951
David Howellsc4028952006-11-22 14:57:56 +00003952static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003953{
David Howellsc4028952006-11-22 14:57:56 +00003954 struct ipw_priv *priv =
3955 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003956 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003957 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003958 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003959}
3960
David Howellsc4028952006-11-22 14:57:56 +00003961static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003962{
David Howellsc4028952006-11-22 14:57:56 +00003963 struct ipw_priv *priv =
3964 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003965
3966#ifdef CONFIG_IPW2200_PROMISCUOUS
3967 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3968 priv->sys_config.accept_all_data_frames = 1;
3969 priv->sys_config.accept_non_directed_frames = 1;
3970 priv->sys_config.accept_all_mgmt_bcpr = 1;
3971 priv->sys_config.accept_all_mgmt_frames = 1;
3972 }
3973#endif
3974
3975 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003976}
3977
3978struct ipw_status_code {
3979 u16 status;
3980 const char *reason;
3981};
3982
3983static const struct ipw_status_code ipw_status_codes[] = {
3984 {0x00, "Successful"},
3985 {0x01, "Unspecified failure"},
3986 {0x0A, "Cannot support all requested capabilities in the "
3987 "Capability information field"},
3988 {0x0B, "Reassociation denied due to inability to confirm that "
3989 "association exists"},
3990 {0x0C, "Association denied due to reason outside the scope of this "
3991 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003992 {0x0D,
3993 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003994 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003995 {0x0E,
3996 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003997 "transaction sequence number out of expected sequence"},
3998 {0x0F, "Authentication rejected because of challenge failure"},
3999 {0x10, "Authentication rejected due to timeout waiting for next "
4000 "frame in sequence"},
4001 {0x11, "Association denied because AP is unable to handle additional "
4002 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004003 {0x12,
4004 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004005 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004006 {0x13,
4007 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004008 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004009 {0x14,
4010 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004011 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004012 {0x15,
4013 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004014 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004015 {0x19,
4016 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004017 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004018 {0x1A,
4019 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004020 "DSSS-OFDM operation"},
4021 {0x28, "Invalid Information Element"},
4022 {0x29, "Group Cipher is not valid"},
4023 {0x2A, "Pairwise Cipher is not valid"},
4024 {0x2B, "AKMP is not valid"},
4025 {0x2C, "Unsupported RSN IE version"},
4026 {0x2D, "Invalid RSN IE Capabilities"},
4027 {0x2E, "Cipher suite is rejected per security policy"},
4028};
4029
Jeff Garzikbf794512005-07-31 13:07:26 -04004030static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004031{
4032 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004033 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004034 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004035 return ipw_status_codes[i].reason;
4036 return "Unknown status value.";
4037}
James Ketrenos43f66a62005-03-25 12:31:53 -06004038
4039static void inline average_init(struct average *avg)
4040{
4041 memset(avg, 0, sizeof(*avg));
4042}
4043
Zhu Yi00d21de2006-04-13 17:19:02 +08004044#define DEPTH_RSSI 8
4045#define DEPTH_NOISE 16
4046static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4047{
4048 return ((depth-1)*prev_avg + val)/depth;
4049}
4050
Arjan van de Ven858119e2006-01-14 13:20:43 -08004051static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004052{
4053 avg->sum -= avg->entries[avg->pos];
4054 avg->sum += val;
4055 avg->entries[avg->pos++] = val;
4056 if (unlikely(avg->pos == AVG_ENTRIES)) {
4057 avg->init = 1;
4058 avg->pos = 0;
4059 }
4060}
4061
Arjan van de Ven858119e2006-01-14 13:20:43 -08004062static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004063{
4064 if (!unlikely(avg->init)) {
4065 if (avg->pos)
4066 return avg->sum / avg->pos;
4067 return 0;
4068 }
4069
4070 return avg->sum / AVG_ENTRIES;
4071}
4072
4073static void ipw_reset_stats(struct ipw_priv *priv)
4074{
4075 u32 len = sizeof(u32);
4076
4077 priv->quality = 0;
4078
4079 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004080 priv->exp_avg_rssi = -60;
4081 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004082
4083 priv->last_rate = 0;
4084 priv->last_missed_beacons = 0;
4085 priv->last_rx_packets = 0;
4086 priv->last_tx_packets = 0;
4087 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004088
James Ketrenos43f66a62005-03-25 12:31:53 -06004089 /* Firmware managed, reset only when NIC is restarted, so we have to
4090 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004091 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004092 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004093 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004094 &priv->last_tx_failures, &len);
4095
4096 /* Driver managed, reset with each association */
4097 priv->missed_adhoc_beacons = 0;
4098 priv->missed_beacons = 0;
4099 priv->tx_packets = 0;
4100 priv->rx_packets = 0;
4101
4102}
4103
Arjan van de Ven858119e2006-01-14 13:20:43 -08004104static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004105{
4106 u32 i = 0x80000000;
4107 u32 mask = priv->rates_mask;
4108 /* If currently associated in B mode, restrict the maximum
4109 * rate match to B rates */
4110 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004111 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004112
4113 /* TODO: Verify that the rate is supported by the current rates
4114 * list. */
4115
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004116 while (i && !(mask & i))
4117 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004118 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004119 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004120 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004121 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004122 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004123 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004124 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004125 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004126 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004127 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004128 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004129 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004130 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004131 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004132 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004133 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004134 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004135 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004136 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004137 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004138 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004139 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004140 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004141 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004142 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004143 }
4144
Jeff Garzikbf794512005-07-31 13:07:26 -04004145 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004146 return 11000000;
4147 else
4148 return 54000000;
4149}
4150
4151static u32 ipw_get_current_rate(struct ipw_priv *priv)
4152{
4153 u32 rate, len = sizeof(rate);
4154 int err;
4155
Jeff Garzikbf794512005-07-31 13:07:26 -04004156 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004157 return 0;
4158
4159 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004160 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004161 &len);
4162 if (err) {
4163 IPW_DEBUG_INFO("failed querying ordinals.\n");
4164 return 0;
4165 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004166 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004167 return ipw_get_max_rate(priv);
4168
4169 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004170 case IPW_TX_RATE_1MB:
4171 return 1000000;
4172 case IPW_TX_RATE_2MB:
4173 return 2000000;
4174 case IPW_TX_RATE_5MB:
4175 return 5500000;
4176 case IPW_TX_RATE_6MB:
4177 return 6000000;
4178 case IPW_TX_RATE_9MB:
4179 return 9000000;
4180 case IPW_TX_RATE_11MB:
4181 return 11000000;
4182 case IPW_TX_RATE_12MB:
4183 return 12000000;
4184 case IPW_TX_RATE_18MB:
4185 return 18000000;
4186 case IPW_TX_RATE_24MB:
4187 return 24000000;
4188 case IPW_TX_RATE_36MB:
4189 return 36000000;
4190 case IPW_TX_RATE_48MB:
4191 return 48000000;
4192 case IPW_TX_RATE_54MB:
4193 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004194 }
4195
4196 return 0;
4197}
4198
James Ketrenos43f66a62005-03-25 12:31:53 -06004199#define IPW_STATS_INTERVAL (2 * HZ)
4200static void ipw_gather_stats(struct ipw_priv *priv)
4201{
4202 u32 rx_err, rx_err_delta, rx_packets_delta;
4203 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4204 u32 missed_beacons_percent, missed_beacons_delta;
4205 u32 quality = 0;
4206 u32 len = sizeof(u32);
4207 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004208 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004209 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004210 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004211
4212 if (!(priv->status & STATUS_ASSOCIATED)) {
4213 priv->quality = 0;
4214 return;
4215 }
4216
4217 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004218 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004219 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004220 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004221 priv->last_missed_beacons = priv->missed_beacons;
4222 if (priv->assoc_request.beacon_interval) {
4223 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004224 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004225 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004226 } else {
4227 missed_beacons_percent = 0;
4228 }
4229 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4230
4231 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4232 rx_err_delta = rx_err - priv->last_rx_err;
4233 priv->last_rx_err = rx_err;
4234
4235 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4236 tx_failures_delta = tx_failures - priv->last_tx_failures;
4237 priv->last_tx_failures = tx_failures;
4238
4239 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4240 priv->last_rx_packets = priv->rx_packets;
4241
4242 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4243 priv->last_tx_packets = priv->tx_packets;
4244
4245 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004246 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004247 * Missed beacon: 100% = 0, 0% = 70% missed
4248 * Rate: 60% = 1Mbs, 100% = Max
4249 * Rx and Tx errors represent a straight % of total Rx/Tx
4250 * RSSI: 100% = > -50, 0% = < -80
4251 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004252 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004253 * The lowest computed quality is used.
4254 *
4255 */
4256#define BEACON_THRESHOLD 5
4257 beacon_quality = 100 - missed_beacons_percent;
4258 if (beacon_quality < BEACON_THRESHOLD)
4259 beacon_quality = 0;
4260 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004261 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004262 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004263 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004264 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004265
James Ketrenos43f66a62005-03-25 12:31:53 -06004266 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004267 max_rate = ipw_get_max_rate(priv);
4268 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004269 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4270 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004271
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004272 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004273 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004274 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004275 else
4276 rx_quality = 100;
4277 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4278 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004279
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004280 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004281 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004282 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004283 else
4284 tx_quality = 100;
4285 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4286 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004287
Zhu Yi00d21de2006-04-13 17:19:02 +08004288 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004289 signal_quality =
4290 (100 *
4291 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4292 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4293 (priv->ieee->perfect_rssi - rssi) *
4294 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4295 62 * (priv->ieee->perfect_rssi - rssi))) /
4296 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4297 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4298 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004299 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004300 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004301 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004302
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004303 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004304 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004305
Reinette Chatre21f8a732009-08-18 10:25:05 -07004306 quality = min(rx_quality, signal_quality);
4307 quality = min(tx_quality, quality);
4308 quality = min(rate_quality, quality);
4309 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004310 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004311 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4312 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004313 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004314 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4315 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004316 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004317 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4318 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004319 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004320 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4321 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004322 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004323 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4324 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004325
4326 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004327
4328 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004329 IPW_STATS_INTERVAL);
4330}
4331
David Howellsc4028952006-11-22 14:57:56 +00004332static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004333{
David Howellsc4028952006-11-22 14:57:56 +00004334 struct ipw_priv *priv =
4335 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004336 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004337 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004338 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004339}
4340
Ben Cahille7582562005-10-06 15:34:41 -05004341/* Missed beacon behavior:
4342 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4343 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4344 * Above disassociate threshold, give up and stop scanning.
4345 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004346static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004347 int missed_count)
4348{
4349 priv->notif_missed_beacons = missed_count;
4350
James Ketrenosafbf30a2005-08-25 00:05:33 -05004351 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004352 priv->status & STATUS_ASSOCIATED) {
4353 /* If associated and we've hit the missed
4354 * beacon threshold, disassociate, turn
4355 * off roaming, and abort any active scans */
4356 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004357 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004358 "Missed beacon: %d - disassociate\n", missed_count);
4359 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004360 if (priv->status & STATUS_SCANNING) {
4361 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4362 IPW_DL_STATE,
4363 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004364 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004365 }
4366
James Ketrenosea2b26e2005-08-24 21:25:16 -05004367 queue_work(priv->workqueue, &priv->disassociate);
4368 return;
4369 }
4370
4371 if (priv->status & STATUS_ROAMING) {
4372 /* If we are currently roaming, then just
4373 * print a debug statement... */
4374 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4375 "Missed beacon: %d - roam in progress\n",
4376 missed_count);
4377 return;
4378 }
4379
Zhu Yi4bfdb912006-01-24 16:37:16 +08004380 if (roaming &&
4381 (missed_count > priv->roaming_threshold &&
4382 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004383 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004384 * bit in the status and kick off a scan.
4385 * This can happen several times before we reach
4386 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004387 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4388 "Missed beacon: %d - initiate "
4389 "roaming\n", missed_count);
4390 if (!(priv->status & STATUS_ROAMING)) {
4391 priv->status |= STATUS_ROAMING;
4392 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004393 queue_delayed_work(priv->workqueue,
4394 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004395 }
4396 return;
4397 }
4398
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004399 if (priv->status & STATUS_SCANNING &&
4400 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004401 /* Stop scan to keep fw from getting
4402 * stuck (only if we aren't roaming --
4403 * otherwise we'll never scan more than 2 or 3
4404 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004405 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4406 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004407 queue_work(priv->workqueue, &priv->abort_scan);
4408 }
4409
4410 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004411}
4412
Dan Williams0b531672007-10-09 13:55:24 -04004413static void ipw_scan_event(struct work_struct *work)
4414{
4415 union iwreq_data wrqu;
4416
4417 struct ipw_priv *priv =
4418 container_of(work, struct ipw_priv, scan_event.work);
4419
4420 wrqu.data.length = 0;
4421 wrqu.data.flags = 0;
4422 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4423}
4424
4425static void handle_scan_event(struct ipw_priv *priv)
4426{
4427 /* Only userspace-requested scan completion events go out immediately */
4428 if (!priv->user_requested_scan) {
4429 if (!delayed_work_pending(&priv->scan_event))
4430 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004431 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004432 } else {
4433 union iwreq_data wrqu;
4434
4435 priv->user_requested_scan = 0;
4436 cancel_delayed_work(&priv->scan_event);
4437
4438 wrqu.data.length = 0;
4439 wrqu.data.flags = 0;
4440 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4441 }
4442}
4443
James Ketrenos43f66a62005-03-25 12:31:53 -06004444/**
4445 * Handle host notification packet.
4446 * Called from interrupt routine
4447 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004448static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004449 struct ipw_rx_notification *notif)
4450{
John W. Linville9387b7c2008-09-30 20:59:05 -04004451 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004452 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004453
Al Viroe62e1ee2007-12-27 01:36:46 -05004454 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004455
James Ketrenos43f66a62005-03-25 12:31:53 -06004456 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004457 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4458 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004459
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004460 switch (assoc->state) {
4461 case CMAS_ASSOCIATED:{
4462 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4463 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004464 "associated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004465 print_ssid(ssid, priv->essid,
4466 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004467 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004468
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004469 switch (priv->ieee->iw_mode) {
4470 case IW_MODE_INFRA:
4471 memcpy(priv->ieee->bssid,
4472 priv->bssid, ETH_ALEN);
4473 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004474
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004475 case IW_MODE_ADHOC:
4476 memcpy(priv->ieee->bssid,
4477 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004479 /* clear out the station table */
4480 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004481
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004482 IPW_DEBUG_ASSOC
4483 ("queueing adhoc check\n");
4484 queue_delayed_work(priv->
4485 workqueue,
4486 &priv->
4487 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004488 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004489 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004490 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004491 break;
4492 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004493
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004494 priv->status &= ~STATUS_ASSOCIATING;
4495 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004496 queue_work(priv->workqueue,
4497 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004498
Zhu Yie43e3c12006-04-13 17:20:45 +08004499#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004500#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004501 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004502 if ((priv->status & STATUS_AUTH) &&
4503 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4504 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004505 if ((sizeof
4506 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004507 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004508 <= size)
4509 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004510 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004511 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004512 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004513 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004514 };
4515
4516 IPW_DEBUG_QOS
4517 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004518 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004519 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004520 ieee,
4521 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004522 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004523 *)
4524 &notif->u.raw, &stats);
4525 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004526 }
James Ketrenosb095c382005-08-24 22:04:42 -05004527#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004528
James Ketrenosa613bff2005-08-24 21:43:11 -05004529 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004530
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004531 break;
4532 }
4533
4534 case CMAS_AUTHENTICATED:{
4535 if (priv->
4536 status & (STATUS_ASSOCIATED |
4537 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004538 struct notif_authenticate *auth
4539 = &notif->u.auth;
4540 IPW_DEBUG(IPW_DL_NOTIF |
4541 IPW_DL_STATE |
4542 IPW_DL_ASSOC,
4543 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004544 "%pM"
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004545 ": (0x%04X) - %s \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004546 print_ssid(ssid,
4547 priv->
4548 essid,
4549 priv->
4550 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004551 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004552 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004553 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004554 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004555 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004556
4557 priv->status &=
4558 ~(STATUS_ASSOCIATING |
4559 STATUS_AUTH |
4560 STATUS_ASSOCIATED);
4561
James Ketrenosa613bff2005-08-24 21:43:11 -05004562 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004563 break;
4564 }
4565
4566 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4567 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004568 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004569 print_ssid(ssid, priv->essid,
4570 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004571 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004572 break;
4573 }
4574
4575 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004576 if (priv->status & STATUS_AUTH) {
4577 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004578 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004579 *resp;
4580 resp =
4581 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004582 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004583 *)&notif->u.raw;
4584 IPW_DEBUG(IPW_DL_NOTIF |
4585 IPW_DL_STATE |
4586 IPW_DL_ASSOC,
4587 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004588 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004589 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004590 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004591 (resp->status)));
4592 }
4593
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004594 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4595 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004596 "disassociated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004597 print_ssid(ssid, priv->essid,
4598 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004599 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004600
4601 priv->status &=
4602 ~(STATUS_DISASSOCIATING |
4603 STATUS_ASSOCIATING |
4604 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004605 if (priv->assoc_network
4606 && (priv->assoc_network->
4607 capability &
4608 WLAN_CAPABILITY_IBSS))
4609 ipw_remove_current_network
4610 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004611
James Ketrenosa613bff2005-08-24 21:43:11 -05004612 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004613
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614 break;
4615 }
4616
James Ketrenosb095c382005-08-24 22:04:42 -05004617 case CMAS_RX_ASSOC_RESP:
4618 break;
4619
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004620 default:
4621 IPW_ERROR("assoc: unknown (%d)\n",
4622 assoc->state);
4623 break;
4624 }
4625
James Ketrenos43f66a62005-03-25 12:31:53 -06004626 break;
4627 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004628
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004629 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4630 struct notif_authenticate *auth = &notif->u.auth;
4631 switch (auth->state) {
4632 case CMAS_AUTHENTICATED:
4633 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Johannes Berge1749612008-10-27 15:59:26 -07004634 "authenticated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004635 print_ssid(ssid, priv->essid,
4636 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004637 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004638 priv->status |= STATUS_AUTH;
4639 break;
4640
4641 case CMAS_INIT:
4642 if (priv->status & STATUS_AUTH) {
4643 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4644 IPW_DL_ASSOC,
4645 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004646 le16_to_cpu(auth->status),
4647 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004648 (auth->
4649 status)));
4650 }
4651 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4652 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004653 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004654 print_ssid(ssid, priv->essid,
4655 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004656 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004657
4658 priv->status &= ~(STATUS_ASSOCIATING |
4659 STATUS_AUTH |
4660 STATUS_ASSOCIATED);
4661
James Ketrenosa613bff2005-08-24 21:43:11 -05004662 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004663 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004664
4665 case CMAS_TX_AUTH_SEQ_1:
4666 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4667 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4668 break;
4669 case CMAS_RX_AUTH_SEQ_2:
4670 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4671 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4672 break;
4673 case CMAS_AUTH_SEQ_1_PASS:
4674 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4675 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4676 break;
4677 case CMAS_AUTH_SEQ_1_FAIL:
4678 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4679 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4680 break;
4681 case CMAS_TX_AUTH_SEQ_3:
4682 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4683 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4684 break;
4685 case CMAS_RX_AUTH_SEQ_4:
4686 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4687 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4688 break;
4689 case CMAS_AUTH_SEQ_2_PASS:
4690 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4691 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4692 break;
4693 case CMAS_AUTH_SEQ_2_FAIL:
4694 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4695 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4696 break;
4697 case CMAS_TX_ASSOC:
4698 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4699 IPW_DL_ASSOC, "TX_ASSOC\n");
4700 break;
4701 case CMAS_RX_ASSOC_RESP:
4702 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4703 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004704
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004705 break;
4706 case CMAS_ASSOCIATED:
4707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4708 IPW_DL_ASSOC, "ASSOCIATED\n");
4709 break;
4710 default:
4711 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4712 auth->state);
4713 break;
4714 }
4715 break;
4716 }
4717
4718 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4719 struct notif_channel_result *x =
4720 &notif->u.channel_result;
4721
Al Viroe62e1ee2007-12-27 01:36:46 -05004722 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004723 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4724 x->channel_num);
4725 } else {
4726 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4727 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004728 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004729 }
4730 break;
4731 }
4732
4733 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4734 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004735 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004736 IPW_DEBUG_SCAN
4737 ("Scan completed: type %d, %d channels, "
4738 "%d status\n", x->scan_type,
4739 x->num_channels, x->status);
4740 } else {
4741 IPW_ERROR("Scan completed of wrong size %d "
4742 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004743 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004744 }
4745
4746 priv->status &=
4747 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4748
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004749 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004750 cancel_delayed_work(&priv->scan_check);
4751
James Ketrenosb095c382005-08-24 22:04:42 -05004752 if (priv->status & STATUS_EXIT_PENDING)
4753 break;
4754
4755 priv->ieee->scans++;
4756
4757#ifdef CONFIG_IPW2200_MONITOR
4758 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004759 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004760 queue_delayed_work(priv->workqueue,
4761 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004762 break;
4763 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004764 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004765#endif /* CONFIG_IPW2200_MONITOR */
4766
Dan Williamsea177302008-06-02 17:51:23 -04004767 /* Do queued direct scans first */
4768 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4769 queue_delayed_work(priv->workqueue,
4770 &priv->request_direct_scan, 0);
4771 }
4772
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004773 if (!(priv->status & (STATUS_ASSOCIATED |
4774 STATUS_ASSOCIATING |
4775 STATUS_ROAMING |
4776 STATUS_DISASSOCIATING)))
4777 queue_work(priv->workqueue, &priv->associate);
4778 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004779 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4780 /* If a scan completed and we are in roam mode, then
4781 * the scan that completed was the one requested as a
4782 * result of entering roam... so, schedule the
4783 * roam work */
4784 queue_work(priv->workqueue,
4785 &priv->roam);
4786 else
4787 /* Don't schedule if we aborted the scan */
4788 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004789 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004790 queue_delayed_work(priv->workqueue,
4791 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004792 else if (priv->config & CFG_BACKGROUND_SCAN
4793 && priv->status & STATUS_ASSOCIATED)
4794 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004795 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004796 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004797
4798 /* Send an empty event to user space.
4799 * We don't send the received data on the event because
4800 * it would require us to do complex transcoding, and
4801 * we want to minimise the work done in the irq handler
4802 * Use a request to extract the data.
4803 * Also, we generate this even for any scan, regardless
4804 * on how the scan was initiated. User space can just
4805 * sync on periodic scan to get fresh data...
4806 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004807 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4808 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004809 break;
4810 }
4811
4812 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4813 struct notif_frag_length *x = &notif->u.frag_len;
4814
Al Viroe62e1ee2007-12-27 01:36:46 -05004815 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004816 IPW_ERROR("Frag length: %d\n",
4817 le16_to_cpu(x->frag_length));
4818 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004819 IPW_ERROR("Frag length of wrong size %d "
4820 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004821 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004822 break;
4823 }
4824
4825 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4826 struct notif_link_deterioration *x =
4827 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004828
Al Viroe62e1ee2007-12-27 01:36:46 -05004829 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004830 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004831 "link deterioration: type %d, cnt %d\n",
4832 x->silence_notification_type,
4833 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004834 memcpy(&priv->last_link_deterioration, x,
4835 sizeof(*x));
4836 } else {
4837 IPW_ERROR("Link Deterioration of wrong size %d "
4838 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004839 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004840 }
4841 break;
4842 }
4843
4844 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4845 IPW_ERROR("Dino config\n");
4846 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004847 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004848 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004849
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004850 break;
4851 }
4852
4853 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4854 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004855 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004856 IPW_ERROR
4857 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004858 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004859 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004860 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004861
James Ketrenosa613bff2005-08-24 21:43:11 -05004862 if (le32_to_cpu(x->state) ==
4863 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4864 ipw_handle_missed_beacon(priv,
4865 le32_to_cpu(x->
4866 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004867
James Ketrenos43f66a62005-03-25 12:31:53 -06004868 break;
4869 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004870
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004871 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4872 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004873 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004874 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4875 "0x%02x station %d\n",
4876 x->key_state, x->security_type,
4877 x->station_index);
4878 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004879 }
4880
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004881 IPW_ERROR
4882 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004883 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004884 break;
4885 }
4886
4887 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4888 struct notif_calibration *x = &notif->u.calibration;
4889
Al Viroe62e1ee2007-12-27 01:36:46 -05004890 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004891 memcpy(&priv->calib, x, sizeof(*x));
4892 IPW_DEBUG_INFO("TODO: Calibration\n");
4893 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004894 }
4895
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004896 IPW_ERROR
4897 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004898 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004899 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004900 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004901
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004902 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004903 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004904 priv->exp_avg_noise =
4905 exponential_average(priv->exp_avg_noise,
4906 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4907 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004908 break;
4909 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004910
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004911 IPW_ERROR
4912 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004913 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004914 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004915 }
4916
James Ketrenos43f66a62005-03-25 12:31:53 -06004917 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004918 IPW_DEBUG_NOTIF("Unknown notification: "
4919 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004920 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004921 }
4922}
4923
4924/**
4925 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004926 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004927 * @param priv
4928 * @return error code
4929 */
4930static int ipw_queue_reset(struct ipw_priv *priv)
4931{
4932 int rc = 0;
4933 /** @todo customize queue sizes */
4934 int nTx = 64, nTxCmd = 8;
4935 ipw_tx_queue_free(priv);
4936 /* Tx CMD queue */
4937 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004938 IPW_TX_CMD_QUEUE_READ_INDEX,
4939 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4940 IPW_TX_CMD_QUEUE_BD_BASE,
4941 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004942 if (rc) {
4943 IPW_ERROR("Tx Cmd queue init failed\n");
4944 goto error;
4945 }
4946 /* Tx queue(s) */
4947 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004948 IPW_TX_QUEUE_0_READ_INDEX,
4949 IPW_TX_QUEUE_0_WRITE_INDEX,
4950 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004951 if (rc) {
4952 IPW_ERROR("Tx 0 queue init failed\n");
4953 goto error;
4954 }
4955 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004956 IPW_TX_QUEUE_1_READ_INDEX,
4957 IPW_TX_QUEUE_1_WRITE_INDEX,
4958 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004959 if (rc) {
4960 IPW_ERROR("Tx 1 queue init failed\n");
4961 goto error;
4962 }
4963 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004964 IPW_TX_QUEUE_2_READ_INDEX,
4965 IPW_TX_QUEUE_2_WRITE_INDEX,
4966 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004967 if (rc) {
4968 IPW_ERROR("Tx 2 queue init failed\n");
4969 goto error;
4970 }
4971 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004972 IPW_TX_QUEUE_3_READ_INDEX,
4973 IPW_TX_QUEUE_3_WRITE_INDEX,
4974 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004975 if (rc) {
4976 IPW_ERROR("Tx 3 queue init failed\n");
4977 goto error;
4978 }
4979 /* statistics */
4980 priv->rx_bufs_min = 0;
4981 priv->rx_pend_max = 0;
4982 return rc;
4983
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004984 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004985 ipw_tx_queue_free(priv);
4986 return rc;
4987}
4988
4989/**
4990 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004991 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01004992 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06004993 * new 'R' index need to be reclaimed. As result, some free space
4994 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004995 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004996 * @note Need to protect against garbage in 'R' index
4997 * @param priv
4998 * @param txq
4999 * @param qindex
5000 * @return Number of used entries remains in the queue
5001 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005002static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005003 struct clx2_tx_queue *txq, int qindex)
5004{
5005 u32 hw_tail;
5006 int used;
5007 struct clx2_queue *q = &txq->q;
5008
5009 hw_tail = ipw_read32(priv, q->reg_r);
5010 if (hw_tail >= q->n_bd) {
5011 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005012 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5013 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005014 goto done;
5015 }
5016 for (; q->last_used != hw_tail;
5017 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5018 ipw_queue_tx_free_tfd(priv, txq);
5019 priv->tx_packets++;
5020 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005021 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005022 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005023 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005024 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005025 used = q->first_empty - q->last_used;
5026 if (used < 0)
5027 used += q->n_bd;
5028
5029 return used;
5030}
5031
5032static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5033 int len, int sync)
5034{
5035 struct clx2_tx_queue *txq = &priv->txq_cmd;
5036 struct clx2_queue *q = &txq->q;
5037 struct tfd_frame *tfd;
5038
Dan Williams943dbef2008-02-14 17:49:41 -05005039 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005040 IPW_ERROR("No space for Tx\n");
5041 return -EBUSY;
5042 }
5043
5044 tfd = &txq->bd[q->first_empty];
5045 txq->txb[q->first_empty] = NULL;
5046
5047 memset(tfd, 0, sizeof(*tfd));
5048 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5049 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5050 priv->hcmd_seq++;
5051 tfd->u.cmd.index = hcmd;
5052 tfd->u.cmd.length = len;
5053 memcpy(tfd->u.cmd.payload, buf, len);
5054 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5055 ipw_write32(priv, q->reg_w, q->first_empty);
5056 _ipw_read32(priv, 0x90);
5057
5058 return 0;
5059}
5060
Jeff Garzikbf794512005-07-31 13:07:26 -04005061/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005062 * Rx theory of operation
5063 *
5064 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005065 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005066 * 0 to 31
5067 *
5068 * Rx Queue Indexes
5069 * The host/firmware share two index registers for managing the Rx buffers.
5070 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005071 * The READ index maps to the first position that the firmware may be writing
5072 * to -- the driver can read up to (but not including) this position and get
5073 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005074 * The READ index is managed by the firmware once the card is enabled.
5075 *
5076 * The WRITE index maps to the last position the driver has read from -- the
5077 * position preceding WRITE is the last slot the firmware can place a packet.
5078 *
5079 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005080 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005081 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005082 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005083 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5084 *
5085 * When the firmware places a packet in a buffer it will advance the READ index
5086 * and fire the RX interrupt. The driver can then query the READ index and
5087 * process as many packets as possible, moving the WRITE index forward as it
5088 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005089 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005090 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005091 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005092 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005093 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005094 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5095 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5096 * 'processed' and 'read' driver indexes as well)
5097 * + A received packet is processed and handed to the kernel network stack,
5098 * detached from the ipw->rxq. The driver 'processed' index is updated.
5099 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005100 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5101 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005102 * were enough free buffers and RX_STALLED is set it is cleared.
5103 *
5104 *
5105 * Driver sequence:
5106 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005107 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005108 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5109 * ipw_rx_queue_restock
5110 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5111 * queue, updates firmware pointers, and updates
5112 * the WRITE index. If insufficient rx_free buffers
5113 * are available, schedules ipw_rx_queue_replenish
5114 *
5115 * -- enable interrupts --
5116 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005117 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005118 * Moves the packet buffer from queue to rx_used.
5119 * Calls ipw_rx_queue_restock to refill any empty
5120 * slots.
5121 * ...
5122 *
5123 */
5124
Jeff Garzikbf794512005-07-31 13:07:26 -04005125/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005126 * If there are slots in the RX queue that need to be restocked,
5127 * and we have free pre-allocated buffers, fill the ranks as much
5128 * as we can pulling from rx_free.
5129 *
5130 * This moves the 'write' index forward to catch up with 'processed', and
5131 * also updates the memory address in the firmware to reference the new
5132 * target buffer.
5133 */
5134static void ipw_rx_queue_restock(struct ipw_priv *priv)
5135{
5136 struct ipw_rx_queue *rxq = priv->rxq;
5137 struct list_head *element;
5138 struct ipw_rx_mem_buffer *rxb;
5139 unsigned long flags;
5140 int write;
5141
5142 spin_lock_irqsave(&rxq->lock, flags);
5143 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005144 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005145 element = rxq->rx_free.next;
5146 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5147 list_del(element);
5148
James Ketrenosb095c382005-08-24 22:04:42 -05005149 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005150 rxb->dma_addr);
5151 rxq->queue[rxq->write] = rxb;
5152 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5153 rxq->free_count--;
5154 }
5155 spin_unlock_irqrestore(&rxq->lock, flags);
5156
Jeff Garzikbf794512005-07-31 13:07:26 -04005157 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005158 * refill it */
5159 if (rxq->free_count <= RX_LOW_WATERMARK)
5160 queue_work(priv->workqueue, &priv->rx_replenish);
5161
5162 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005163 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005164 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005165}
5166
5167/*
5168 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005169 * Also restock the Rx queue via ipw_rx_queue_restock.
5170 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005171 * This is called as a scheduled work item (except for during intialization)
5172 */
5173static void ipw_rx_queue_replenish(void *data)
5174{
5175 struct ipw_priv *priv = data;
5176 struct ipw_rx_queue *rxq = priv->rxq;
5177 struct list_head *element;
5178 struct ipw_rx_mem_buffer *rxb;
5179 unsigned long flags;
5180
5181 spin_lock_irqsave(&rxq->lock, flags);
5182 while (!list_empty(&rxq->rx_used)) {
5183 element = rxq->rx_used.next;
5184 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005185 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005186 if (!rxb->skb) {
5187 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5188 priv->net_dev->name);
5189 /* We don't reschedule replenish work here -- we will
5190 * call the restock method and if it still needs
5191 * more buffers it will schedule replenish */
5192 break;
5193 }
5194 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005195
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005196 rxb->dma_addr =
5197 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005198 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005199
James Ketrenos43f66a62005-03-25 12:31:53 -06005200 list_add_tail(&rxb->list, &rxq->rx_free);
5201 rxq->free_count++;
5202 }
5203 spin_unlock_irqrestore(&rxq->lock, flags);
5204
5205 ipw_rx_queue_restock(priv);
5206}
5207
David Howellsc4028952006-11-22 14:57:56 +00005208static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005209{
David Howellsc4028952006-11-22 14:57:56 +00005210 struct ipw_priv *priv =
5211 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005212 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005213 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005214 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005215}
5216
James Ketrenos43f66a62005-03-25 12:31:53 -06005217/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005218 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005219 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005220 * non NULL it is unmapped and freed
5221 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005222static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005223{
5224 int i;
5225
5226 if (!rxq)
5227 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005228
James Ketrenos43f66a62005-03-25 12:31:53 -06005229 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5230 if (rxq->pool[i].skb != NULL) {
5231 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005232 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005233 dev_kfree_skb(rxq->pool[i].skb);
5234 }
5235 }
5236
5237 kfree(rxq);
5238}
5239
5240static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5241{
5242 struct ipw_rx_queue *rxq;
5243 int i;
5244
Takisc75f4742005-12-01 01:41:45 -08005245 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005246 if (unlikely(!rxq)) {
5247 IPW_ERROR("memory allocation failed\n");
5248 return NULL;
5249 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005250 spin_lock_init(&rxq->lock);
5251 INIT_LIST_HEAD(&rxq->rx_free);
5252 INIT_LIST_HEAD(&rxq->rx_used);
5253
5254 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005255 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005256 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5257
5258 /* Set us so that we have processed and used all buffers, but have
5259 * not restocked the Rx queue with fresh buffers */
5260 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005261 rxq->free_count = 0;
5262
5263 return rxq;
5264}
5265
5266static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5267{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005268 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005269 if (ieee_mode == IEEE_A) {
5270 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005271 case LIBIPW_OFDM_RATE_6MB:
5272 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005273 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005274 case LIBIPW_OFDM_RATE_9MB:
5275 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005276 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005277 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005278 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005279 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5280 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005281 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005282 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5283 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005284 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005285 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5286 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005287 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005288 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5289 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005291 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5292 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005293 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005294 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005295 default:
5296 return 0;
5297 }
5298 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005299
James Ketrenos43f66a62005-03-25 12:31:53 -06005300 /* B and G mixed */
5301 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005302 case LIBIPW_CCK_RATE_1MB:
5303 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5304 case LIBIPW_CCK_RATE_2MB:
5305 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5306 case LIBIPW_CCK_RATE_5MB:
5307 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5308 case LIBIPW_CCK_RATE_11MB:
5309 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005310 }
5311
5312 /* If we are limited to B modulations, bail at this point */
5313 if (ieee_mode == IEEE_B)
5314 return 0;
5315
5316 /* G */
5317 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005318 case LIBIPW_OFDM_RATE_6MB:
5319 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5320 case LIBIPW_OFDM_RATE_9MB:
5321 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5322 case LIBIPW_OFDM_RATE_12MB:
5323 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5324 case LIBIPW_OFDM_RATE_18MB:
5325 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5326 case LIBIPW_OFDM_RATE_24MB:
5327 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5328 case LIBIPW_OFDM_RATE_36MB:
5329 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5330 case LIBIPW_OFDM_RATE_48MB:
5331 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5332 case LIBIPW_OFDM_RATE_54MB:
5333 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005334 }
5335
5336 return 0;
5337}
5338
Jeff Garzikbf794512005-07-31 13:07:26 -04005339static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005340 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005341 struct ipw_supported_rates *rates)
5342{
5343 int num_rates, i;
5344
5345 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005346 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005347 rates->num_rates = 0;
5348 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[i])) {
5351
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005352 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005353 IPW_DEBUG_SCAN("Adding masked mandatory "
5354 "rate %02X\n",
5355 network->rates[i]);
5356 rates->supported_rates[rates->num_rates++] =
5357 network->rates[i];
5358 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005359 }
5360
James Ketrenos43f66a62005-03-25 12:31:53 -06005361 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5362 network->rates[i], priv->rates_mask);
5363 continue;
5364 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005365
James Ketrenos43f66a62005-03-25 12:31:53 -06005366 rates->supported_rates[rates->num_rates++] = network->rates[i];
5367 }
5368
James Ketrenosa613bff2005-08-24 21:43:11 -05005369 num_rates = min(network->rates_ex_len,
5370 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005371 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005372 if (!ipw_is_rate_in_mask(priv, network->mode,
5373 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005374 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005375 IPW_DEBUG_SCAN("Adding masked mandatory "
5376 "rate %02X\n",
5377 network->rates_ex[i]);
5378 rates->supported_rates[rates->num_rates++] =
5379 network->rates[i];
5380 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005381 }
5382
James Ketrenos43f66a62005-03-25 12:31:53 -06005383 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5384 network->rates_ex[i], priv->rates_mask);
5385 continue;
5386 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005387
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005388 rates->supported_rates[rates->num_rates++] =
5389 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005390 }
5391
James Ketrenosea2b26e2005-08-24 21:25:16 -05005392 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005393}
5394
Arjan van de Ven858119e2006-01-14 13:20:43 -08005395static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005396 const struct ipw_supported_rates *src)
5397{
5398 u8 i;
5399 for (i = 0; i < src->num_rates; i++)
5400 dest->supported_rates[i] = src->supported_rates[i];
5401 dest->num_rates = src->num_rates;
5402}
5403
5404/* TODO: Look at sniffed packets in the air to determine if the basic rate
5405 * mask should ever be used -- right now all callers to add the scan rates are
5406 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5407static void ipw_add_cck_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;
Jeff Garzikbf794512005-07-31 13:07:26 -04005412
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005413 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005414 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005415 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005416
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005417 if (rate_mask & LIBIPW_CCK_RATE_2MB_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_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005420
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005421 if (rate_mask & LIBIPW_CCK_RATE_5MB_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_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005424
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005425 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005426 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005427 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005428}
5429
5430static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005431 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005432{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005433 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5434 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005435
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005436 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005437 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005438 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005439
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005440 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005441 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005442 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005443
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005444 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005446 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005447
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005449 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005450 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005451
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005452 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005453 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005454 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005455
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005456 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005457 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005459
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005460 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005461 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005462 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005463
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005464 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005465 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005466 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005467}
5468
5469struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005470 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005471 struct ipw_supported_rates rates;
5472};
5473
James Ketrenosc848d0a2005-08-24 21:56:24 -05005474static int ipw_find_adhoc_network(struct ipw_priv *priv,
5475 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005476 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005477 int roaming)
5478{
5479 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005480 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005481
5482 /* Verify that this network's capability is compatible with the
5483 * current mode (AdHoc or Infrastructure) */
5484 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5485 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005486 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005487 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005488 print_ssid(ssid, network->ssid,
5489 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005490 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005491 return 0;
5492 }
5493
James Ketrenosc848d0a2005-08-24 21:56:24 -05005494 if (unlikely(roaming)) {
5495 /* If we are roaming, then ensure check if this is a valid
5496 * network to try and roam to */
5497 if ((network->ssid_len != match->network->ssid_len) ||
5498 memcmp(network->ssid, match->network->ssid,
5499 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005500 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005501 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005502 print_ssid(ssid, network->ssid,
5503 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005504 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005505 return 0;
5506 }
5507 } else {
5508 /* If an ESSID has been configured then compare the broadcast
5509 * ESSID to ours */
5510 if ((priv->config & CFG_STATIC_ESSID) &&
5511 ((network->ssid_len != priv->essid_len) ||
5512 memcmp(network->ssid, priv->essid,
5513 min(network->ssid_len, priv->essid_len)))) {
5514 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005515
James Ketrenosc848d0a2005-08-24 21:56:24 -05005516 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005517 print_ssid(ssid, network->ssid,
5518 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005519 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005520 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005521 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005522 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005523 print_ssid(ssid, priv->essid,
5524 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005525 return 0;
5526 }
5527 }
5528
5529 /* If the old network rate is better than this one, don't bother
5530 * testing everything else. */
5531
5532 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005533 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5534 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005535 print_ssid(ssid, match->network->ssid,
5536 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005537 return 0;
5538 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005539 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5540 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005541 print_ssid(ssid, match->network->ssid,
5542 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005543 return 0;
5544 }
5545
5546 /* Now go through and see if the requested network is valid... */
5547 if (priv->ieee->scan_age != 0 &&
5548 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005549 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005550 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005551 print_ssid(ssid, network->ssid,
5552 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005553 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005554 jiffies_to_msecs(jiffies -
5555 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005556 return 0;
5557 }
5558
5559 if ((priv->config & CFG_STATIC_CHANNEL) &&
5560 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005561 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005562 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005563 print_ssid(ssid, network->ssid,
5564 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005565 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005566 network->channel, priv->channel);
5567 return 0;
5568 }
5569
5570 /* Verify privacy compatability */
5571 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5572 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005573 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005574 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005575 print_ssid(ssid, network->ssid,
5576 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005577 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005578 priv->
5579 capability & CAP_PRIVACY_ON ? "on" : "off",
5580 network->
5581 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5582 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005583 return 0;
5584 }
5585
5586 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005587 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5588 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005589 ".\n", print_ssid(ssid, network->ssid,
5590 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005591 network->bssid,
5592 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005593 return 0;
5594 }
5595
5596 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005597 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005598 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005599 "because of invalid frequency/mode "
5600 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005601 print_ssid(ssid, network->ssid,
5602 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005603 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005604 return 0;
5605 }
5606
5607 /* Ensure that the rates supported by the driver are compatible with
5608 * this AP, including verification of basic rates (mandatory) */
5609 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005610 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005611 "because configured rate mask excludes "
5612 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005613 print_ssid(ssid, network->ssid,
5614 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005615 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005616 return 0;
5617 }
5618
5619 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005620 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005621 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005622 print_ssid(ssid, network->ssid,
5623 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005624 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625 return 0;
5626 }
5627
5628 /* TODO: Perform any further minimal comparititive tests. We do not
5629 * want to put too much policy logic here; intelligent scan selection
5630 * should occur within a generic IEEE 802.11 user space tool. */
5631
5632 /* Set up 'new' AP to this network */
5633 ipw_copy_rates(&match->rates, &rates);
5634 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005635 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005636 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005637 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005638
5639 return 1;
5640}
5641
David Howellsc4028952006-11-22 14:57:56 +00005642static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005643{
John W. Linville9387b7c2008-09-30 20:59:05 -04005644 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005645 struct ipw_priv *priv =
5646 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005647 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005648 struct ipw_network_match match = {
5649 .network = priv->assoc_network
5650 };
5651
James Ketrenosafbf30a2005-08-25 00:05:33 -05005652 if ((priv->status & STATUS_ASSOCIATED) &&
5653 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005654 /* First pass through ROAM process -- look for a better
5655 * network */
5656 unsigned long flags;
5657
5658 spin_lock_irqsave(&priv->ieee->lock, flags);
5659 list_for_each_entry(network, &priv->ieee->network_list, list) {
5660 if (network != priv->assoc_network)
5661 ipw_find_adhoc_network(priv, &match, network,
5662 1);
5663 }
5664 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5665
5666 if (match.network == priv->assoc_network) {
5667 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5668 "merge to.\n");
5669 return;
5670 }
5671
Zhu Yi46441512006-01-24 16:37:59 +08005672 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005673 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5674 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005675 print_ssid(ssid, priv->essid,
5676 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005677 ipw_remove_current_network(priv);
5678 }
5679
5680 ipw_disassociate(priv);
5681 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005682 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005683 return;
5684 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005685}
5686
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005687static int ipw_best_network(struct ipw_priv *priv,
5688 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005689 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005690{
5691 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005692 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005693
5694 /* Verify that this network's capability is compatible with the
5695 * current mode (AdHoc or Infrastructure) */
5696 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005697 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005698 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5699 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005700 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005701 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005702 print_ssid(ssid, network->ssid,
5703 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005704 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005705 return 0;
5706 }
5707
James Ketrenos43f66a62005-03-25 12:31:53 -06005708 if (unlikely(roaming)) {
5709 /* If we are roaming, then ensure check if this is a valid
5710 * network to try and roam to */
5711 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005712 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005713 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005714 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005715 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005716 print_ssid(ssid, network->ssid,
5717 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005718 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005719 return 0;
5720 }
5721 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005722 /* If an ESSID has been configured then compare the broadcast
5723 * ESSID to ours */
5724 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005725 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005726 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 min(network->ssid_len, priv->essid_len)))) {
5728 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005729 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005730 print_ssid(ssid, network->ssid,
5731 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005732 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005733 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005734 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005735 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005736 print_ssid(ssid, priv->essid,
5737 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005738 return 0;
5739 }
5740 }
5741
5742 /* If the old network rate is better than this one, don't bother
5743 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005744 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005745 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005746 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005747 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005749 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5750 "'%s (%pM)' has a stronger signal.\n",
5751 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005752 print_ssid(ssid, match->network->ssid,
5753 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005754 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005755 return 0;
5756 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005757
James Ketrenos43f66a62005-03-25 12:31:53 -06005758 /* If this network has already had an association attempt within the
5759 * last 3 seconds, do not try and associate again... */
5760 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005761 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005762 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005763 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005764 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005765 print_ssid(ssid, network->ssid,
5766 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005767 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005768 jiffies_to_msecs(jiffies -
5769 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005770 return 0;
5771 }
5772
5773 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005774 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005775 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005776 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005777 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005778 print_ssid(ssid, network->ssid,
5779 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005780 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005781 jiffies_to_msecs(jiffies -
5782 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005783 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005784 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005785
Jeff Garzikbf794512005-07-31 13:07:26 -04005786 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005787 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005788 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005789 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005790 print_ssid(ssid, network->ssid,
5791 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005792 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 network->channel, priv->channel);
5794 return 0;
5795 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005796
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005798 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005799 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005800 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005801 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005802 print_ssid(ssid, network->ssid,
5803 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005804 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005805 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005806 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005807 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005808 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005809 return 0;
5810 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005811
5812 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005813 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005814 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5815 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005816 print_ssid(ssid, network->ssid,
5817 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005818 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005819 return 0;
5820 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005821
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005823 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005824 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005825 "because of invalid frequency/mode "
5826 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005827 print_ssid(ssid, network->ssid,
5828 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005829 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005830 return 0;
5831 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005832
Liu Hong1fe0adb2005-08-19 09:33:10 -05005833 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005834 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005835 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005836 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005837 print_ssid(ssid, network->ssid,
5838 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005839 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005840 return 0;
5841 }
5842
James Ketrenosea2b26e2005-08-24 21:25:16 -05005843 /* Ensure that the rates supported by the driver are compatible with
5844 * this AP, including verification of basic rates (mandatory) */
5845 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005846 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005847 "because configured rate mask excludes "
5848 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005849 print_ssid(ssid, network->ssid,
5850 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005851 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005852 return 0;
5853 }
5854
James Ketrenos43f66a62005-03-25 12:31:53 -06005855 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005856 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005857 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005858 print_ssid(ssid, network->ssid,
5859 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005860 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005861 return 0;
5862 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005863
James Ketrenos43f66a62005-03-25 12:31:53 -06005864 /* TODO: Perform any further minimal comparititive tests. We do not
5865 * want to put too much policy logic here; intelligent scan selection
5866 * should occur within a generic IEEE 802.11 user space tool. */
5867
5868 /* Set up 'new' AP to this network */
5869 ipw_copy_rates(&match->rates, &rates);
5870 match->network = network;
5871
Johannes Berge1749612008-10-27 15:59:26 -07005872 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005873 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005874 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005875
5876 return 1;
5877}
5878
Jeff Garzikbf794512005-07-31 13:07:26 -04005879static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005880 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005881{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005882 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005883 int i;
5884
James Ketrenos43f66a62005-03-25 12:31:53 -06005885 /*
5886 * For the purposes of scanning, we can set our wireless mode
5887 * to trigger scans across combinations of bands, but when it
5888 * comes to creating a new ad-hoc network, we have tell the FW
5889 * exactly which band to use.
5890 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005891 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005892 * chossen band. Attempting to create a new ad-hoc network
5893 * with an invalid channel for wireless mode will trigger a
5894 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005895 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005896 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005897 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5898 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005899 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005900 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005901 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005902 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005903 IPW_WARNING("Overriding invalid channel\n");
5904 priv->channel = geo->a[0].channel;
5905 }
5906 break;
5907
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005908 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005909 if (priv->ieee->mode & IEEE_G)
5910 network->mode = IEEE_G;
5911 else
5912 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005913 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005914 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005915 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005916 IPW_WARNING("Overriding invalid channel\n");
5917 priv->channel = geo->bg[0].channel;
5918 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005919 break;
5920
5921 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005922 IPW_WARNING("Overriding invalid channel\n");
5923 if (priv->ieee->mode & IEEE_A) {
5924 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005925 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005926 } else if (priv->ieee->mode & IEEE_G) {
5927 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005928 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005929 } else {
5930 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005931 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005932 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005933 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005934 }
5935
5936 network->channel = priv->channel;
5937 priv->config |= CFG_ADHOC_PERSIST;
5938 ipw_create_bssid(priv, network->bssid);
5939 network->ssid_len = priv->essid_len;
5940 memcpy(network->ssid, priv->essid, priv->essid_len);
5941 memset(&network->stats, 0, sizeof(network->stats));
5942 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005943 if (!(priv->config & CFG_PREAMBLE_LONG))
5944 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005945 if (priv->capability & CAP_PRIVACY_ON)
5946 network->capability |= WLAN_CAPABILITY_PRIVACY;
5947 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005948 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005949 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005950 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005951 &priv->rates.supported_rates[network->rates_len],
5952 network->rates_ex_len);
5953 network->last_scanned = 0;
5954 network->flags = 0;
5955 network->last_associate = 0;
5956 network->time_stamp[0] = 0;
5957 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005958 network->beacon_interval = 100; /* Default */
5959 network->listen_interval = 10; /* Default */
5960 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005961 network->wpa_ie_len = 0;
5962 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005963}
5964
James Ketrenosb095c382005-08-24 22:04:42 -05005965static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5966{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005967 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005968
5969 if (!(priv->ieee->sec.flags & (1 << index)))
5970 return;
5971
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005972 key.key_id = index;
5973 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5974 key.security_type = type;
5975 key.station_index = 0; /* always 0 for BSS */
5976 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005977 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005978 key.tx_counter[0] = cpu_to_le32(0);
5979 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005980
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005981 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005982}
5983
5984static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005985{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005986 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005987 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005988
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005989 key.cmd_id = DINO_CMD_WEP_KEY;
5990 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005991
James Ketrenosb095c382005-08-24 22:04:42 -05005992 /* Note: AES keys cannot be set for multiple times.
5993 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005994 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005995 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005996 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005997 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005998 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005999 }
6000
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006001 key.key_size = priv->ieee->sec.key_sizes[i];
6002 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006003
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006004 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006005 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006006}
6007
Zhu Yi1fbfea52005-08-05 17:22:56 +08006008static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6009{
6010 if (priv->ieee->host_encrypt)
6011 return;
6012
6013 switch (level) {
6014 case SEC_LEVEL_3:
6015 priv->sys_config.disable_unicast_decryption = 0;
6016 priv->ieee->host_decrypt = 0;
6017 break;
6018 case SEC_LEVEL_2:
6019 priv->sys_config.disable_unicast_decryption = 1;
6020 priv->ieee->host_decrypt = 1;
6021 break;
6022 case SEC_LEVEL_1:
6023 priv->sys_config.disable_unicast_decryption = 0;
6024 priv->ieee->host_decrypt = 0;
6025 break;
6026 case SEC_LEVEL_0:
6027 priv->sys_config.disable_unicast_decryption = 1;
6028 break;
6029 default:
6030 break;
6031 }
6032}
6033
6034static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6035{
6036 if (priv->ieee->host_encrypt)
6037 return;
6038
6039 switch (level) {
6040 case SEC_LEVEL_3:
6041 priv->sys_config.disable_multicast_decryption = 0;
6042 break;
6043 case SEC_LEVEL_2:
6044 priv->sys_config.disable_multicast_decryption = 1;
6045 break;
6046 case SEC_LEVEL_1:
6047 priv->sys_config.disable_multicast_decryption = 0;
6048 break;
6049 case SEC_LEVEL_0:
6050 priv->sys_config.disable_multicast_decryption = 1;
6051 break;
6052 default:
6053 break;
6054 }
6055}
6056
James Ketrenosb095c382005-08-24 22:04:42 -05006057static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6058{
6059 switch (priv->ieee->sec.level) {
6060 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006061 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6062 ipw_send_tgi_tx_key(priv,
6063 DCT_FLAG_EXT_SECURITY_CCM,
6064 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006065
Hong Liu567deaf2005-08-31 18:07:22 +08006066 if (!priv->ieee->host_mc_decrypt)
6067 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006068 break;
6069 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006070 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6071 ipw_send_tgi_tx_key(priv,
6072 DCT_FLAG_EXT_SECURITY_TKIP,
6073 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006074 break;
6075 case SEC_LEVEL_1:
6076 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006077 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6078 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006079 break;
6080 case SEC_LEVEL_0:
6081 default:
6082 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006083 }
6084}
6085
6086static void ipw_adhoc_check(void *data)
6087{
6088 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006089
James Ketrenosafbf30a2005-08-25 00:05:33 -05006090 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006091 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006092 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6093 IPW_DL_STATE | IPW_DL_ASSOC,
6094 "Missed beacon: %d - disassociate\n",
6095 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006096 ipw_remove_current_network(priv);
6097 ipw_disassociate(priv);
6098 return;
6099 }
6100
Jeff Garzikbf794512005-07-31 13:07:26 -04006101 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006102 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006103}
6104
David Howellsc4028952006-11-22 14:57:56 +00006105static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006106{
David Howellsc4028952006-11-22 14:57:56 +00006107 struct ipw_priv *priv =
6108 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006109 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006110 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006111 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006112}
6113
James Ketrenos43f66a62005-03-25 12:31:53 -06006114static void ipw_debug_config(struct ipw_priv *priv)
6115{
John W. Linville9387b7c2008-09-30 20:59:05 -04006116 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006117 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6118 "[CFG 0x%08X]\n", priv->config);
6119 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006120 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006121 else
6122 IPW_DEBUG_INFO("Channel unlocked.\n");
6123 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006124 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006125 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006126 else
6127 IPW_DEBUG_INFO("ESSID unlocked.\n");
6128 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006129 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006130 else
6131 IPW_DEBUG_INFO("BSSID unlocked.\n");
6132 if (priv->capability & CAP_PRIVACY_ON)
6133 IPW_DEBUG_INFO("PRIVACY on\n");
6134 else
6135 IPW_DEBUG_INFO("PRIVACY off\n");
6136 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6137}
James Ketrenos43f66a62005-03-25 12:31:53 -06006138
Arjan van de Ven858119e2006-01-14 13:20:43 -08006139static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006140{
6141 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006142 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006143 u32 reg;
6144 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006145 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006146
Jeff Garzikbf794512005-07-31 13:07:26 -04006147 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006148 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006149
James Ketrenos43f66a62005-03-25 12:31:53 -06006150 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006151 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006152 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006153 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006154 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006155 IPW_DEBUG_WX
6156 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006157 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006158 break;
6159 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006160
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006161 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006162 break;
6163
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006164 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006165 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006166 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006167 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006168 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006169 IPW_DEBUG_WX
6170 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006171 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006172 }
6173 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006174 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006175
6176 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006177 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6178 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006179 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006180 IPW_DEBUG_WX
6181 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006182 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006183 break;
6184 }
6185
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006186 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6187 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6188 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006189 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006190
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006191 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6192 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6193 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006194 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006195
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006196 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6197 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6198 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006199 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006200
Reinette Chatre21f8a732009-08-18 10:25:05 -07006201 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006202 break;
6203 }
6204
Reinette Chatre21f8a732009-08-18 10:25:05 -07006205 fr.tx_rates = cpu_to_le16(new_tx_rates);
6206
James Ketrenos43f66a62005-03-25 12:31:53 -06006207 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006208 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006209}
6210
James Ketrenosea2b26e2005-08-24 21:25:16 -05006211static void ipw_abort_scan(struct ipw_priv *priv)
6212{
6213 int err;
6214
6215 if (priv->status & STATUS_SCAN_ABORTING) {
6216 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6217 return;
6218 }
6219 priv->status |= STATUS_SCAN_ABORTING;
6220
6221 err = ipw_send_scan_abort(priv);
6222 if (err)
6223 IPW_DEBUG_HC("Request to abort scan failed.\n");
6224}
6225
James Ketrenosafbf30a2005-08-25 00:05:33 -05006226static void ipw_add_scan_channels(struct ipw_priv *priv,
6227 struct ipw_scan_request_ext *scan,
6228 int scan_type)
6229{
6230 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006231 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006232 int i;
6233
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006234 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006235
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006236 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006237 int start = channel_index;
6238 for (i = 0; i < geo->a_channels; i++) {
6239 if ((priv->status & STATUS_ASSOCIATED) &&
6240 geo->a[i].channel == priv->channel)
6241 continue;
6242 channel_index++;
6243 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006244 ipw_set_scan_type(scan, channel_index,
6245 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006246 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006247 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6248 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006249 }
6250
6251 if (start != channel_index) {
6252 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6253 (channel_index - start);
6254 channel_index++;
6255 }
6256 }
6257
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006258 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006259 int start = channel_index;
6260 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006261 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006262 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006263 /* nop out the list */
6264 [0] = 0
6265 };
6266
6267 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006268 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006269 channel =
6270 priv->speed_scan[priv->speed_scan_pos];
6271 if (channel == 0) {
6272 priv->speed_scan_pos = 0;
6273 channel = priv->speed_scan[0];
6274 }
6275 if ((priv->status & STATUS_ASSOCIATED) &&
6276 channel == priv->channel) {
6277 priv->speed_scan_pos++;
6278 continue;
6279 }
6280
6281 /* If this channel has already been
6282 * added in scan, break from loop
6283 * and this will be the first channel
6284 * in the next scan.
6285 */
6286 if (channels[channel - 1] != 0)
6287 break;
6288
6289 channels[channel - 1] = 1;
6290 priv->speed_scan_pos++;
6291 channel_index++;
6292 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006293 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006294 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006295 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006296 geo->bg[index].
6297 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006298 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006299 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6300 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006301 }
6302 } else {
6303 for (i = 0; i < geo->bg_channels; i++) {
6304 if ((priv->status & STATUS_ASSOCIATED) &&
6305 geo->bg[i].channel == priv->channel)
6306 continue;
6307 channel_index++;
6308 scan->channels_list[channel_index] =
6309 geo->bg[i].channel;
6310 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006311 geo->bg[i].
6312 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006313 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006314 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6315 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006316 }
6317 }
6318
6319 if (start != channel_index) {
6320 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6321 (channel_index - start);
6322 }
6323 }
6324}
6325
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006326static int ipw_passive_dwell_time(struct ipw_priv *priv)
6327{
6328 /* staying on passive channels longer than the DTIM interval during a
6329 * scan, while associated, causes the firmware to cancel the scan
6330 * without notification. Hence, don't stay on passive channels longer
6331 * than the beacon interval.
6332 */
6333 if (priv->status & STATUS_ASSOCIATED
6334 && priv->assoc_network->beacon_interval > 10)
6335 return priv->assoc_network->beacon_interval - 10;
6336 else
6337 return 120;
6338}
6339
Dan Williamsea177302008-06-02 17:51:23 -04006340static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006341{
6342 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006343 int err = 0, scan_type;
6344
6345 if (!(priv->status & STATUS_INIT) ||
6346 (priv->status & STATUS_EXIT_PENDING))
6347 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006348
Zhu Yi46441512006-01-24 16:37:59 +08006349 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006350
Dan Williamsea177302008-06-02 17:51:23 -04006351 if (direct && (priv->direct_scan_ssid_len == 0)) {
6352 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6353 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6354 goto done;
6355 }
6356
James Ketrenosea2b26e2005-08-24 21:25:16 -05006357 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006358 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6359 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6360 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006361 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006362 }
6363
James Ketrenosafbf30a2005-08-25 00:05:33 -05006364 if (!(priv->status & STATUS_SCAN_FORCED) &&
6365 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006366 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006367 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6368 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006369 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006370 }
6371
6372 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006373 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6374 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6375 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006376 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006377 }
6378
6379 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006380 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006381
Zhu Yi094c4d22006-08-21 11:39:03 +08006382 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006383 IPW_DEBUG_WX("use passive scanning\n");
6384 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006385 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006386 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006387 ipw_add_scan_channels(priv, &scan, scan_type);
6388 goto send_request;
6389 }
6390
6391 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006392 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006393 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006394 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006395 else
6396 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006397 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006398
James Ketrenosa613bff2005-08-24 21:43:11 -05006399 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006400 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006401
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006402 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6403 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006404 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006405
James Ketrenosb095c382005-08-24 22:04:42 -05006406#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006407 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006408 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006409 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006410
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006411 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6412 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006413 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006414 channel = priv->channel;
6415 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006416
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006417 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006418 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006419 channel = priv->channel;
6420 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006421
James Ketrenosb095c382005-08-24 22:04:42 -05006422 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006423 band = (u8) (IPW_B_MODE << 6) | 1;
6424 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006425 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006426 }
6427
James Ketrenosb095c382005-08-24 22:04:42 -05006428 scan.channels_list[0] = band;
6429 scan.channels_list[1] = channel;
6430 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006431
James Ketrenosb095c382005-08-24 22:04:42 -05006432 /* NOTE: The card will sit on this channel for this time
6433 * period. Scan aborts are timing sensitive and frequently
6434 * result in firmware restarts. As such, it is best to
6435 * set a small dwell_time here and just keep re-issuing
6436 * scans. Otherwise fast channel hopping will not actually
6437 * hop channels.
6438 *
6439 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006440 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006441 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006442 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006443#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006444 /* Honor direct scans first, otherwise if we are roaming make
6445 * this a direct scan for the current network. Finally,
6446 * ensure that every other scan is a fast channel hop scan */
6447 if (direct) {
6448 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6449 priv->direct_scan_ssid_len);
6450 if (err) {
6451 IPW_DEBUG_HC("Attempt to send SSID command "
6452 "failed\n");
6453 goto done;
6454 }
6455
6456 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6457 } else if ((priv->status & STATUS_ROAMING)
6458 || (!(priv->status & STATUS_ASSOCIATED)
6459 && (priv->config & CFG_STATIC_ESSID)
6460 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006461 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6462 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006463 IPW_DEBUG_HC("Attempt to send SSID command "
6464 "failed.\n");
6465 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006466 }
6467
6468 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006469 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006470 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006471
James Ketrenosafbf30a2005-08-25 00:05:33 -05006472 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006473#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006474 }
6475#endif
6476
Zhu Yi094c4d22006-08-21 11:39:03 +08006477send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006478 err = ipw_send_scan_request_ext(priv, &scan);
6479 if (err) {
6480 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006481 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006482 }
6483
6484 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006485 if (direct) {
6486 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6487 priv->direct_scan_ssid_len = 0;
6488 } else
6489 priv->status &= ~STATUS_SCAN_PENDING;
6490
James Ketrenosafbf30a2005-08-25 00:05:33 -05006491 queue_delayed_work(priv->workqueue, &priv->scan_check,
6492 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006493done:
Zhu Yi46441512006-01-24 16:37:59 +08006494 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006495 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006496}
6497
David Howellsc4028952006-11-22 14:57:56 +00006498static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006499{
David Howellsc4028952006-11-22 14:57:56 +00006500 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006501 container_of(work, struct ipw_priv, request_passive_scan.work);
6502 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006503}
6504
6505static void ipw_request_scan(struct work_struct *work)
6506{
6507 struct ipw_priv *priv =
6508 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006509 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6510}
6511
6512static void ipw_request_direct_scan(struct work_struct *work)
6513{
6514 struct ipw_priv *priv =
6515 container_of(work, struct ipw_priv, request_direct_scan.work);
6516 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006517}
6518
6519static void ipw_bg_abort_scan(struct work_struct *work)
6520{
6521 struct ipw_priv *priv =
6522 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006523 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006524 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006525 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006526}
6527
James Ketrenosea2b26e2005-08-24 21:25:16 -05006528static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6529{
James Ketrenosb095c382005-08-24 22:04:42 -05006530 /* This is called when wpa_supplicant loads and closes the driver
6531 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006532 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006533 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006534}
6535
James Ketrenosea2b26e2005-08-24 21:25:16 -05006536static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6537{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006538 struct libipw_device *ieee = priv->ieee;
6539 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006540 .flags = SEC_AUTH_MODE,
6541 };
6542 int ret = 0;
6543
James Ketrenosafbf30a2005-08-25 00:05:33 -05006544 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006545 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6546 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006547 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006548 sec.auth_mode = WLAN_AUTH_OPEN;
6549 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006550 } else if (value & IW_AUTH_ALG_LEAP) {
6551 sec.auth_mode = WLAN_AUTH_LEAP;
6552 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006553 } else
6554 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006555
6556 if (ieee->set_security)
6557 ieee->set_security(ieee->dev, &sec);
6558 else
6559 ret = -EOPNOTSUPP;
6560
6561 return ret;
6562}
6563
Adrian Bunka73e22b2006-01-21 01:39:42 +01006564static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6565 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006566{
6567 /* make sure WPA is enabled */
6568 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006569}
6570
6571static int ipw_set_rsn_capa(struct ipw_priv *priv,
6572 char *capabilities, int length)
6573{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006574 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6575
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006576 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006577 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006578}
6579
James Ketrenosafbf30a2005-08-25 00:05:33 -05006580/*
6581 * WE-18 support
6582 */
6583
6584/* SIOCSIWGENIE */
6585static int ipw_wx_set_genie(struct net_device *dev,
6586 struct iw_request_info *info,
6587 union iwreq_data *wrqu, char *extra)
6588{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006589 struct ipw_priv *priv = libipw_priv(dev);
6590 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006591 u8 *buf;
6592 int err = 0;
6593
6594 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6595 (wrqu->data.length && extra == NULL))
6596 return -EINVAL;
6597
James Ketrenosafbf30a2005-08-25 00:05:33 -05006598 if (wrqu->data.length) {
6599 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6600 if (buf == NULL) {
6601 err = -ENOMEM;
6602 goto out;
6603 }
6604
6605 memcpy(buf, extra, wrqu->data.length);
6606 kfree(ieee->wpa_ie);
6607 ieee->wpa_ie = buf;
6608 ieee->wpa_ie_len = wrqu->data.length;
6609 } else {
6610 kfree(ieee->wpa_ie);
6611 ieee->wpa_ie = NULL;
6612 ieee->wpa_ie_len = 0;
6613 }
6614
6615 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6616 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006617 return err;
6618}
6619
6620/* SIOCGIWGENIE */
6621static int ipw_wx_get_genie(struct net_device *dev,
6622 struct iw_request_info *info,
6623 union iwreq_data *wrqu, char *extra)
6624{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006625 struct ipw_priv *priv = libipw_priv(dev);
6626 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006627 int err = 0;
6628
James Ketrenosafbf30a2005-08-25 00:05:33 -05006629 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6630 wrqu->data.length = 0;
6631 goto out;
6632 }
6633
6634 if (wrqu->data.length < ieee->wpa_ie_len) {
6635 err = -E2BIG;
6636 goto out;
6637 }
6638
6639 wrqu->data.length = ieee->wpa_ie_len;
6640 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6641
6642 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006643 return err;
6644}
6645
Zhu Yi1fbfea52005-08-05 17:22:56 +08006646static int wext_cipher2level(int cipher)
6647{
6648 switch (cipher) {
6649 case IW_AUTH_CIPHER_NONE:
6650 return SEC_LEVEL_0;
6651 case IW_AUTH_CIPHER_WEP40:
6652 case IW_AUTH_CIPHER_WEP104:
6653 return SEC_LEVEL_1;
6654 case IW_AUTH_CIPHER_TKIP:
6655 return SEC_LEVEL_2;
6656 case IW_AUTH_CIPHER_CCMP:
6657 return SEC_LEVEL_3;
6658 default:
6659 return -1;
6660 }
6661}
6662
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663/* SIOCSIWAUTH */
6664static int ipw_wx_set_auth(struct net_device *dev,
6665 struct iw_request_info *info,
6666 union iwreq_data *wrqu, char *extra)
6667{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006668 struct ipw_priv *priv = libipw_priv(dev);
6669 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006670 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006671 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006672 unsigned long flags;
6673 int ret = 0;
6674
6675 switch (param->flags & IW_AUTH_INDEX) {
6676 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006677 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006678 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006679 ipw_set_hw_decrypt_unicast(priv,
6680 wext_cipher2level(param->value));
6681 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006682 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006683 ipw_set_hw_decrypt_multicast(priv,
6684 wext_cipher2level(param->value));
6685 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006686 case IW_AUTH_KEY_MGMT:
6687 /*
6688 * ipw2200 does not use these parameters
6689 */
6690 break;
6691
6692 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006693 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006694 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006695 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006696
6697 flags = crypt->ops->get_flags(crypt->priv);
6698
6699 if (param->value)
6700 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6701 else
6702 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6703
6704 crypt->ops->set_flags(flags, crypt->priv);
6705
6706 break;
6707
6708 case IW_AUTH_DROP_UNENCRYPTED:{
6709 /* HACK:
6710 *
6711 * wpa_supplicant calls set_wpa_enabled when the driver
6712 * is loaded and unloaded, regardless of if WPA is being
6713 * used. No other calls are made which can be used to
6714 * determine if encryption will be used or not prior to
6715 * association being expected. If encryption is not being
6716 * used, drop_unencrypted is set to false, else true -- we
6717 * can use this to determine if the CAP_PRIVACY_ON bit should
6718 * be set.
6719 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006720 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006721 .flags = SEC_ENABLED,
6722 .enabled = param->value,
6723 };
6724 priv->ieee->drop_unencrypted = param->value;
6725 /* We only change SEC_LEVEL for open mode. Others
6726 * are set by ipw_wpa_set_encryption.
6727 */
6728 if (!param->value) {
6729 sec.flags |= SEC_LEVEL;
6730 sec.level = SEC_LEVEL_0;
6731 } else {
6732 sec.flags |= SEC_LEVEL;
6733 sec.level = SEC_LEVEL_1;
6734 }
6735 if (priv->ieee->set_security)
6736 priv->ieee->set_security(priv->ieee->dev, &sec);
6737 break;
6738 }
6739
6740 case IW_AUTH_80211_AUTH_ALG:
6741 ret = ipw_wpa_set_auth_algs(priv, param->value);
6742 break;
6743
6744 case IW_AUTH_WPA_ENABLED:
6745 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006746 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006747 break;
6748
6749 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6750 ieee->ieee802_1x = param->value;
6751 break;
6752
James Ketrenosafbf30a2005-08-25 00:05:33 -05006753 case IW_AUTH_PRIVACY_INVOKED:
6754 ieee->privacy_invoked = param->value;
6755 break;
6756
6757 default:
6758 return -EOPNOTSUPP;
6759 }
6760 return ret;
6761}
6762
6763/* SIOCGIWAUTH */
6764static int ipw_wx_get_auth(struct net_device *dev,
6765 struct iw_request_info *info,
6766 union iwreq_data *wrqu, char *extra)
6767{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006768 struct ipw_priv *priv = libipw_priv(dev);
6769 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006770 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006771 struct iw_param *param = &wrqu->param;
6772 int ret = 0;
6773
6774 switch (param->flags & IW_AUTH_INDEX) {
6775 case IW_AUTH_WPA_VERSION:
6776 case IW_AUTH_CIPHER_PAIRWISE:
6777 case IW_AUTH_CIPHER_GROUP:
6778 case IW_AUTH_KEY_MGMT:
6779 /*
6780 * wpa_supplicant will control these internally
6781 */
6782 ret = -EOPNOTSUPP;
6783 break;
6784
6785 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006786 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006787 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006788 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006789
6790 param->value = (crypt->ops->get_flags(crypt->priv) &
6791 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6792
6793 break;
6794
6795 case IW_AUTH_DROP_UNENCRYPTED:
6796 param->value = ieee->drop_unencrypted;
6797 break;
6798
6799 case IW_AUTH_80211_AUTH_ALG:
6800 param->value = ieee->sec.auth_mode;
6801 break;
6802
6803 case IW_AUTH_WPA_ENABLED:
6804 param->value = ieee->wpa_enabled;
6805 break;
6806
6807 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6808 param->value = ieee->ieee802_1x;
6809 break;
6810
6811 case IW_AUTH_ROAMING_CONTROL:
6812 case IW_AUTH_PRIVACY_INVOKED:
6813 param->value = ieee->privacy_invoked;
6814 break;
6815
6816 default:
6817 return -EOPNOTSUPP;
6818 }
6819 return 0;
6820}
6821
6822/* SIOCSIWENCODEEXT */
6823static int ipw_wx_set_encodeext(struct net_device *dev,
6824 struct iw_request_info *info,
6825 union iwreq_data *wrqu, char *extra)
6826{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006827 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006828 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6829
6830 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006831 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006832 /* IPW HW can't build TKIP MIC,
6833 host decryption still needed */
6834 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6835 priv->ieee->host_mc_decrypt = 1;
6836 else {
6837 priv->ieee->host_encrypt = 0;
6838 priv->ieee->host_encrypt_msdu = 1;
6839 priv->ieee->host_decrypt = 1;
6840 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006841 } else {
6842 priv->ieee->host_encrypt = 0;
6843 priv->ieee->host_encrypt_msdu = 0;
6844 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006845 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006846 }
6847 }
6848
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006849 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006850}
6851
6852/* SIOCGIWENCODEEXT */
6853static int ipw_wx_get_encodeext(struct net_device *dev,
6854 struct iw_request_info *info,
6855 union iwreq_data *wrqu, char *extra)
6856{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006857 struct ipw_priv *priv = libipw_priv(dev);
6858 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006859}
6860
6861/* SIOCSIWMLME */
6862static int ipw_wx_set_mlme(struct net_device *dev,
6863 struct iw_request_info *info,
6864 union iwreq_data *wrqu, char *extra)
6865{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006866 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006867 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006868 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006869
6870 reason = cpu_to_le16(mlme->reason_code);
6871
6872 switch (mlme->cmd) {
6873 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006874 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006875 break;
6876
6877 case IW_MLME_DISASSOC:
6878 ipw_disassociate(priv);
6879 break;
6880
6881 default:
6882 return -EOPNOTSUPP;
6883 }
6884 return 0;
6885}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006886
Zhu Yie43e3c12006-04-13 17:20:45 +08006887#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006888
6889/* QoS */
6890/*
6891* get the modulation type of the current network or
6892* the card current mode
6893*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006894static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006895{
6896 u8 mode = 0;
6897
6898 if (priv->status & STATUS_ASSOCIATED) {
6899 unsigned long flags;
6900
6901 spin_lock_irqsave(&priv->ieee->lock, flags);
6902 mode = priv->assoc_network->mode;
6903 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6904 } else {
6905 mode = priv->ieee->mode;
6906 }
6907 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6908 return mode;
6909}
6910
6911/*
6912* Handle management frame beacon and probe response
6913*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006914static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6915 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006916 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006917{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006918 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006919
James Ketrenosafbf30a2005-08-25 00:05:33 -05006920 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006921 network->qos_data.active = network->qos_data.supported;
6922
6923 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006924 if (active_network &&
6925 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006926 network->qos_data.active = network->qos_data.supported;
6927
6928 if ((network->qos_data.active == 1) && (active_network == 1) &&
6929 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6930 (network->qos_data.old_param_count !=
6931 network->qos_data.param_count)) {
6932 network->qos_data.old_param_count =
6933 network->qos_data.param_count;
6934 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006935 IPW_DEBUG_QOS("QoS parameters change call "
6936 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006937 }
6938 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006939 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6940 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006941 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006942 else
6943 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006944 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006945
James Ketrenosb095c382005-08-24 22:04:42 -05006946 if ((network->qos_data.active == 1) && (active_network == 1)) {
6947 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6948 schedule_work(&priv->qos_activate);
6949 }
6950
6951 network->qos_data.active = 0;
6952 network->qos_data.supported = 0;
6953 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006954 if ((priv->status & STATUS_ASSOCIATED) &&
6955 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6956 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006957 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006958 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006959 priv->assoc_network->ssid_len) &&
6960 !memcmp(network->ssid,
6961 priv->assoc_network->ssid,
6962 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006963 queue_work(priv->workqueue,
6964 &priv->merge_networks);
6965 }
James Ketrenosb095c382005-08-24 22:04:42 -05006966 }
6967
6968 return 0;
6969}
6970
6971/*
6972* This function set up the firmware to support QoS. It sends
6973* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6974*/
6975static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006976 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006977{
6978 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006979 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6980 struct libipw_qos_parameters *active_one = NULL;
6981 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006982 u32 burst_duration;
6983 int i;
6984 u8 type;
6985
6986 type = ipw_qos_current_mode(priv);
6987
6988 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6989 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6990 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6991 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6992
6993 if (qos_network_data == NULL) {
6994 if (type == IEEE_B) {
6995 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6996 active_one = &def_parameters_CCK;
6997 } else
6998 active_one = &def_parameters_OFDM;
6999
James Ketrenosafbf30a2005-08-25 00:05:33 -05007000 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007001 burst_duration = ipw_qos_get_burst_duration(priv);
7002 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007003 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007004 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007005 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007006 if (type == IEEE_B) {
7007 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7008 type);
7009 if (priv->qos_data.qos_enable == 0)
7010 active_one = &def_parameters_CCK;
7011 else
7012 active_one = priv->qos_data.def_qos_parm_CCK;
7013 } else {
7014 if (priv->qos_data.qos_enable == 0)
7015 active_one = &def_parameters_OFDM;
7016 else
7017 active_one = priv->qos_data.def_qos_parm_OFDM;
7018 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007019 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007020 } else {
7021 unsigned long flags;
7022 int active;
7023
7024 spin_lock_irqsave(&priv->ieee->lock, flags);
7025 active_one = &(qos_network_data->parameters);
7026 qos_network_data->old_param_count =
7027 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007028 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007029 active = qos_network_data->supported;
7030 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7031
7032 if (active == 0) {
7033 burst_duration = ipw_qos_get_burst_duration(priv);
7034 for (i = 0; i < QOS_QUEUE_NUM; i++)
7035 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007036 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007037 }
7038 }
7039
7040 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007041 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007042 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007043 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007044 if (err)
7045 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7046
7047 return err;
7048}
7049
7050/*
7051* send IPW_CMD_WME_INFO to the firmware
7052*/
7053static int ipw_qos_set_info_element(struct ipw_priv *priv)
7054{
7055 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007056 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007057
7058 if (priv == NULL)
7059 return -1;
7060
7061 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007062 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007063
7064 qos_info.version = QOS_VERSION_1;
7065 qos_info.ac_info = 0;
7066
7067 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7068 qos_info.qui_type = QOS_OUI_TYPE;
7069 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7070
7071 ret = ipw_send_qos_info_command(priv, &qos_info);
7072 if (ret != 0) {
7073 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7074 }
7075 return ret;
7076}
7077
7078/*
7079* Set the QoS parameter with the association request structure
7080*/
7081static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007082 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007083{
7084 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007085 struct libipw_qos_data *qos_data = NULL;
7086 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007087 .supported = 1,
7088 .active = 1,
7089 };
7090
7091 switch (priv->ieee->iw_mode) {
7092 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007093 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007094
7095 qos_data = &ibss_data;
7096 break;
7097
7098 case IW_MODE_INFRA:
7099 qos_data = &network->qos_data;
7100 break;
7101
7102 default:
7103 BUG();
7104 break;
7105 }
7106
7107 err = ipw_qos_activate(priv, qos_data);
7108 if (err) {
7109 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7110 return err;
7111 }
7112
7113 if (priv->qos_data.qos_enable && qos_data->supported) {
7114 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7115 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7116 return ipw_qos_set_info_element(priv);
7117 }
7118
7119 return 0;
7120}
7121
7122/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007123* handling the beaconing responses. if we get different QoS setting
7124* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007125* setting
7126*/
7127static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007128 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007129{
7130 int ret = 0;
7131 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007132 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007133 int set_qos_param = 0;
7134
James Ketrenosafbf30a2005-08-25 00:05:33 -05007135 if ((priv == NULL) || (network == NULL) ||
7136 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007137 return ret;
7138
7139 if (!(priv->status & STATUS_ASSOCIATED))
7140 return ret;
7141
James Ketrenosafbf30a2005-08-25 00:05:33 -05007142 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007143 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007144
7145 spin_lock_irqsave(&priv->ieee->lock, flags);
7146 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007147 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007148 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007149 priv->assoc_network->qos_data.active = 1;
7150 if ((network->qos_data.old_param_count !=
7151 network->qos_data.param_count)) {
7152 set_qos_param = 1;
7153 network->qos_data.old_param_count =
7154 network->qos_data.param_count;
7155 }
7156
7157 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007158 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7159 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007160 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007161 else
7162 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007163 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007164 priv->assoc_network->qos_data.active = 0;
7165 priv->assoc_network->qos_data.supported = 0;
7166 set_qos_param = 1;
7167 }
7168
7169 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7170
7171 if (set_qos_param == 1)
7172 schedule_work(&priv->qos_activate);
7173
7174 return ret;
7175}
7176
7177static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7178{
7179 u32 ret = 0;
7180
7181 if ((priv == NULL))
7182 return 0;
7183
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007184 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007185 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007186 else
James Ketrenosb095c382005-08-24 22:04:42 -05007187 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007188
James Ketrenosb095c382005-08-24 22:04:42 -05007189 return ret;
7190}
7191
7192/*
7193* Initialize the setting of QoS global
7194*/
7195static void ipw_qos_init(struct ipw_priv *priv, int enable,
7196 int burst_enable, u32 burst_duration_CCK,
7197 u32 burst_duration_OFDM)
7198{
7199 priv->qos_data.qos_enable = enable;
7200
7201 if (priv->qos_data.qos_enable) {
7202 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7203 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7204 IPW_DEBUG_QOS("QoS is enabled\n");
7205 } else {
7206 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7207 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7208 IPW_DEBUG_QOS("QoS is not enabled\n");
7209 }
7210
7211 priv->qos_data.burst_enable = burst_enable;
7212
7213 if (burst_enable) {
7214 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7215 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7216 } else {
7217 priv->qos_data.burst_duration_CCK = 0;
7218 priv->qos_data.burst_duration_OFDM = 0;
7219 }
7220}
7221
7222/*
7223* map the packet priority to the right TX Queue
7224*/
7225static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7226{
7227 if (priority > 7 || !priv->qos_data.qos_enable)
7228 priority = 0;
7229
7230 return from_priority_to_tx_queue[priority] - 1;
7231}
7232
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007233static int ipw_is_qos_active(struct net_device *dev,
7234 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007235{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007236 struct ipw_priv *priv = libipw_priv(dev);
7237 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007238 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007239 u8 *daddr = skb->data + ETH_ALEN;
7240 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007241
7242 if (!(priv->status & STATUS_ASSOCIATED))
7243 return 0;
7244
7245 qos_data = &priv->assoc_network->qos_data;
7246
James Ketrenosb095c382005-08-24 22:04:42 -05007247 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7248 if (unicast == 0)
7249 qos_data->active = 0;
7250 else
7251 qos_data->active = qos_data->supported;
7252 }
James Ketrenosb095c382005-08-24 22:04:42 -05007253 active = qos_data->active;
7254 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007255 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7256 "unicast %d\n",
7257 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007258 if (active && priv->qos_data.qos_enable)
7259 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007260
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007261 return 0;
7262
7263}
7264/*
7265* add QoS parameter to the TX command
7266*/
7267static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7268 u16 priority,
7269 struct tfd_data *tfd)
7270{
7271 int tx_queue_id = 0;
7272
7273
7274 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7275 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7276
7277 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7278 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007279 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007280 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007281 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007282}
7283
7284/*
7285* background support to run QoS activate functionality
7286*/
David Howellsc4028952006-11-22 14:57:56 +00007287static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007288{
David Howellsc4028952006-11-22 14:57:56 +00007289 struct ipw_priv *priv =
7290 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007291
Zhu Yi46441512006-01-24 16:37:59 +08007292 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007293
7294 if (priv->status & STATUS_ASSOCIATED)
7295 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7296
Zhu Yi46441512006-01-24 16:37:59 +08007297 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007298}
7299
James Ketrenos3b9990c2005-08-19 13:18:55 -05007300static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007301 struct libipw_probe_response *resp,
7302 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007303{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007304 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007305 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7306 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007307
James Ketrenos3b9990c2005-08-19 13:18:55 -05007308 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007309
James Ketrenos3b9990c2005-08-19 13:18:55 -05007310 return 0;
7311}
James Ketrenosb095c382005-08-24 22:04:42 -05007312
James Ketrenos3b9990c2005-08-19 13:18:55 -05007313static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007314 struct libipw_beacon *resp,
7315 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007316{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007317 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007318 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7319 (network == priv->assoc_network));
7320
7321 ipw_qos_handle_probe_response(priv, active_network, network);
7322
7323 return 0;
7324}
7325
7326static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007327 struct libipw_assoc_response *resp,
7328 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007329{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007330 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007331 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007332 return 0;
7333}
7334
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007335static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007336 *qos_param)
7337{
Zhu Yi4e226992006-01-24 16:37:36 +08007338 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7339 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007340}
7341
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007342static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007343 *qos_param)
7344{
Zhu Yi4e226992006-01-24 16:37:36 +08007345 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7346 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007347}
7348
Zhu Yie43e3c12006-04-13 17:20:45 +08007349#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007350
James Ketrenos43f66a62005-03-25 12:31:53 -06007351static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007352 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007353 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007354{
7355 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007356 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007357
7358 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007359 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007360
7361 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007362 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007363 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007364 memcpy(priv->essid, network->ssid, priv->essid_len);
7365 }
7366
7367 network->last_associate = jiffies;
7368
7369 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7370 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007371 priv->assoc_request.auth_key = 0;
7372
James Ketrenos43f66a62005-03-25 12:31:53 -06007373 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007374 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007375 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007376 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7377
Zhu Yi1ba61e02006-02-15 13:00:55 +08007378 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007379 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007380
7381 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7382 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7383 priv->assoc_request.auth_type = AUTH_LEAP;
7384 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007386
James Ketrenosa613bff2005-08-24 21:43:11 -05007387 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007388 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007389 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7390 priv->ieee->wpa_ie_len);
7391 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007392
Jeff Garzikbf794512005-07-31 13:07:26 -04007393 /*
7394 * It is valid for our ieee device to support multiple modes, but
7395 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007396 * just one mode.
7397 */
7398 if (network->mode & priv->ieee->mode & IEEE_A)
7399 priv->assoc_request.ieee_mode = IPW_A_MODE;
7400 else if (network->mode & priv->ieee->mode & IEEE_G)
7401 priv->assoc_request.ieee_mode = IPW_G_MODE;
7402 else if (network->mode & priv->ieee->mode & IEEE_B)
7403 priv->assoc_request.ieee_mode = IPW_B_MODE;
7404
Al Viro5b5e8072007-12-27 01:54:06 -05007405 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007406 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7407 && !(priv->config & CFG_PREAMBLE_LONG)) {
7408 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7409 } else {
7410 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7411
7412 /* Clear the short preamble if we won't be supporting it */
7413 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007414 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007415 }
7416
James Ketrenosafbf30a2005-08-25 00:05:33 -05007417 /* Clear capability bits that aren't used in Ad Hoc */
7418 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7419 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007420 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007421
James Ketrenos43f66a62005-03-25 12:31:53 -06007422 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007423 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007424 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007425 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007426 network->channel,
7427 ipw_modes[priv->assoc_request.ieee_mode],
7428 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007429 (priv->assoc_request.preamble_length ==
7430 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7431 network->capability &
7432 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007433 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007434 priv->capability & CAP_PRIVACY_ON ?
7435 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 "(open)") : "",
7437 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007438 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007439 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007440 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007441
Al Viro5b5e8072007-12-27 01:54:06 -05007442 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007443 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007444 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007445 priv->assoc_request.assoc_type = HC_IBSS_START;
7446 priv->assoc_request.assoc_tsf_msw = 0;
7447 priv->assoc_request.assoc_tsf_lsw = 0;
7448 } else {
7449 if (unlikely(roaming))
7450 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7451 else
7452 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007453 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7454 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007455 }
7456
James Ketrenosafbf30a2005-08-25 00:05:33 -05007457 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007458
7459 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7460 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007461 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007462 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007463 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 priv->assoc_request.atim_window = 0;
7465 }
7466
Al Viro5b5e8072007-12-27 01:54:06 -05007467 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007468
James Ketrenos43f66a62005-03-25 12:31:53 -06007469 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7470 if (err) {
7471 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7472 return err;
7473 }
7474
7475 rates->ieee_mode = priv->assoc_request.ieee_mode;
7476 rates->purpose = IPW_RATE_CONNECT;
7477 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007478
James Ketrenos43f66a62005-03-25 12:31:53 -06007479 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7480 priv->sys_config.dot11g_auto_detection = 1;
7481 else
7482 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007483
7484 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7485 priv->sys_config.answer_broadcast_ssid_probe = 1;
7486 else
7487 priv->sys_config.answer_broadcast_ssid_probe = 0;
7488
Zhu Yid685b8c2006-04-13 17:20:27 +08007489 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007490 if (err) {
7491 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7492 return err;
7493 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007494
James Ketrenos43f66a62005-03-25 12:31:53 -06007495 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007496 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007497 if (err) {
7498 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7499 return err;
7500 }
7501
7502 /*
7503 * If preemption is enabled, it is possible for the association
7504 * to complete before we return from ipw_send_associate. Therefore
7505 * we have to be sure and update our priviate data first.
7506 */
7507 priv->channel = network->channel;
7508 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007509 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007510 priv->status &= ~STATUS_SECURITY_UPDATED;
7511
7512 priv->assoc_network = network;
7513
Zhu Yie43e3c12006-04-13 17:20:45 +08007514#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007515 ipw_qos_association(priv, network);
7516#endif
7517
James Ketrenos43f66a62005-03-25 12:31:53 -06007518 err = ipw_send_associate(priv, &priv->assoc_request);
7519 if (err) {
7520 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7521 return err;
7522 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007523
Johannes Berge1749612008-10-27 15:59:26 -07007524 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007525 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007526 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007527
7528 return 0;
7529}
7530
7531static void ipw_roam(void *data)
7532{
7533 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007534 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007535 struct ipw_network_match match = {
7536 .network = priv->assoc_network
7537 };
7538
7539 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007540 *
7541 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007542 * setting the status ROAM bit and requesting a scan.
7543 * 2. When the scan completes, it schedules the ROAM work
7544 * 3. The ROAM work looks at all of the known networks for one that
7545 * is a better network than the currently associated. If none
7546 * found, the ROAM process is over (ROAM bit cleared)
7547 * 4. If a better network is found, a disassociation request is
7548 * sent.
7549 * 5. When the disassociation completes, the roam work is again
7550 * scheduled. The second time through, the driver is no longer
7551 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007552 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007553 * 6. At this point ,the roaming process is complete and the ROAM
7554 * status bit is cleared.
7555 */
7556
7557 /* If we are no longer associated, and the roaming bit is no longer
7558 * set, then we are not actively roaming, so just return */
7559 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7560 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007561
James Ketrenos43f66a62005-03-25 12:31:53 -06007562 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007563 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007564 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007565 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007566 u8 rssi = priv->assoc_network->stats.rssi;
7567 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007568 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007569 list_for_each_entry(network, &priv->ieee->network_list, list) {
7570 if (network != priv->assoc_network)
7571 ipw_best_network(priv, &match, network, 1);
7572 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007573 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007574 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007575
James Ketrenos43f66a62005-03-25 12:31:53 -06007576 if (match.network == priv->assoc_network) {
7577 IPW_DEBUG_ASSOC("No better APs in this network to "
7578 "roam to.\n");
7579 priv->status &= ~STATUS_ROAMING;
7580 ipw_debug_config(priv);
7581 return;
7582 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007583
James Ketrenos43f66a62005-03-25 12:31:53 -06007584 ipw_send_disassociate(priv, 1);
7585 priv->assoc_network = match.network;
7586
7587 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007588 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007589
7590 /* Second pass through ROAM process -- request association */
7591 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7592 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7593 priv->status &= ~STATUS_ROAMING;
7594}
7595
David Howellsc4028952006-11-22 14:57:56 +00007596static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007597{
David Howellsc4028952006-11-22 14:57:56 +00007598 struct ipw_priv *priv =
7599 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007600 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007601 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007602 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007603}
7604
7605static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007606{
7607 struct ipw_priv *priv = data;
7608
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007609 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007610 struct ipw_network_match match = {
7611 .network = NULL
7612 };
7613 struct ipw_supported_rates *rates;
7614 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007615 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007616 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007617
James Ketrenosb095c382005-08-24 22:04:42 -05007618 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7619 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7620 return 0;
7621 }
7622
James Ketrenosc848d0a2005-08-24 21:56:24 -05007623 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007624 IPW_DEBUG_ASSOC("Not attempting association (already in "
7625 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007626 return 0;
7627 }
7628
Hong Liue6324722005-09-14 21:04:15 -05007629 if (priv->status & STATUS_DISASSOCIATING) {
7630 IPW_DEBUG_ASSOC("Not attempting association (in "
7631 "disassociating)\n ");
7632 queue_work(priv->workqueue, &priv->associate);
7633 return 0;
7634 }
7635
James Ketrenosc848d0a2005-08-24 21:56:24 -05007636 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007637 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7638 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007639 return 0;
7640 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007641
7642 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007643 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007644 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007645 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007646 }
7647
James Ketrenosa613bff2005-08-24 21:43:11 -05007648 /* Protect our use of the network_list */
7649 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007650 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007651 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007652
7653 network = match.network;
7654 rates = &match.rates;
7655
7656 if (network == NULL &&
7657 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7658 priv->config & CFG_ADHOC_CREATE &&
7659 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007660 priv->config & CFG_STATIC_CHANNEL) {
7661 /* Use oldest network if the free list is empty */
7662 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007663 struct libipw_network *oldest = NULL;
7664 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007665
7666 list_for_each_entry(target, &priv->ieee->network_list, list) {
7667 if ((oldest == NULL) ||
7668 (target->last_scanned < oldest->last_scanned))
7669 oldest = target;
7670 }
7671
7672 /* If there are no more slots, expire the oldest */
7673 list_del(&oldest->list);
7674 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007675 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007676 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007677 print_ssid(ssid, target->ssid,
7678 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007679 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007680 list_add_tail(&target->list,
7681 &priv->ieee->network_free_list);
7682 }
7683
James Ketrenos43f66a62005-03-25 12:31:53 -06007684 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007685 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007686 ipw_adhoc_create(priv, network);
7687 rates = &priv->rates;
7688 list_del(element);
7689 list_add_tail(&network->list, &priv->ieee->network_list);
7690 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007691 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007692
James Ketrenos43f66a62005-03-25 12:31:53 -06007693 /* If we reached the end of the list, then we don't have any valid
7694 * matching APs */
7695 if (!network) {
7696 ipw_debug_config(priv);
7697
James Ketrenosb095c382005-08-24 22:04:42 -05007698 if (!(priv->status & STATUS_SCANNING)) {
7699 if (!(priv->config & CFG_SPEED_SCAN))
7700 queue_delayed_work(priv->workqueue,
7701 &priv->request_scan,
7702 SCAN_INTERVAL);
7703 else
David Howellsc4028952006-11-22 14:57:56 +00007704 queue_delayed_work(priv->workqueue,
7705 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007706 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007707
James Ketrenosc848d0a2005-08-24 21:56:24 -05007708 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007709 }
7710
7711 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007712
7713 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007714}
Jeff Garzikbf794512005-07-31 13:07:26 -04007715
David Howellsc4028952006-11-22 14:57:56 +00007716static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007717{
David Howellsc4028952006-11-22 14:57:56 +00007718 struct ipw_priv *priv =
7719 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007720 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007721 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007722 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007723}
7724
James Ketrenosb095c382005-08-24 22:04:42 -05007725static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7726 struct sk_buff *skb)
7727{
7728 struct ieee80211_hdr *hdr;
7729 u16 fc;
7730
7731 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007732 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007733 if (!(fc & IEEE80211_FCTL_PROTECTED))
7734 return;
7735
7736 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007737 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007738 switch (priv->ieee->sec.level) {
7739 case SEC_LEVEL_3:
7740 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007741 memmove(skb->data + LIBIPW_3ADDR_LEN,
7742 skb->data + LIBIPW_3ADDR_LEN + 8,
7743 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007744 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007745 break;
7746 case SEC_LEVEL_2:
7747 break;
7748 case SEC_LEVEL_1:
7749 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007750 memmove(skb->data + LIBIPW_3ADDR_LEN,
7751 skb->data + LIBIPW_3ADDR_LEN + 4,
7752 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007753 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007754 break;
7755 case SEC_LEVEL_0:
7756 break;
7757 default:
7758 printk(KERN_ERR "Unknow security level %d\n",
7759 priv->ieee->sec.level);
7760 break;
7761 }
7762}
7763
7764static void ipw_handle_data_packet(struct ipw_priv *priv,
7765 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007766 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007767{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007768 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007769 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007770 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7771
7772 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007773 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007774
Jeff Garzikbf794512005-07-31 13:07:26 -04007775 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007776 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007777 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007778 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007779 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007780 priv->wstats.discard.misc++;
7781 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7782 return;
7783 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007784 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007785 priv->wstats.discard.misc++;
7786 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7787 return;
7788 }
7789
7790 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007791 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007792
7793 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007794 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007795
7796 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7797
James Ketrenosb095c382005-08-24 22:04:42 -05007798 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007799 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007800 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007801 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007802 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007803 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7804
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007805 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007806 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007807 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007808 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007809 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007810 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007811}
7812
Zhu Yi459d4082006-04-13 17:21:00 +08007813#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007814static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7815 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007816 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007817{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007818 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007819 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7820 struct ipw_rx_frame *frame = &pkt->u.frame;
7821
7822 /* initial pull of some data */
7823 u16 received_channel = frame->received_channel;
7824 u8 antennaAndPhy = frame->antennaAndPhy;
7825 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7826 u16 pktrate = frame->rate;
7827
7828 /* Magic struct that slots into the radiotap header -- no reason
7829 * to build this manually element by element, we can write it much
7830 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007831 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007832
7833 short len = le16_to_cpu(pkt->u.frame.length);
7834
7835 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007836 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007837
7838 /* We only process data packets if the
7839 * interface is open */
7840 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7841 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007842 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007843 priv->wstats.discard.misc++;
7844 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7845 return;
7846 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007847 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007848 priv->wstats.discard.misc++;
7849 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7850 return;
7851 }
7852
7853 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7854 * that now */
7855 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7856 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007857 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007858 priv->wstats.discard.misc++;
7859 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7860 return;
7861 }
7862
7863 /* copy the frame itself */
7864 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7865 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7866
Mike Kershaw24a47db2005-08-26 00:41:54 -05007867 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7868
7869 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7870 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007871 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007872
7873 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007874 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7875 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007876 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007877 (1 << IEEE80211_RADIOTAP_RATE) |
7878 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7879 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007880 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007881 (1 << IEEE80211_RADIOTAP_ANTENNA));
7882
7883 /* Zero the flags, we'll add to them as we go */
7884 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007885 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7886 frame->parent_tsf[2] << 16 |
7887 frame->parent_tsf[1] << 8 |
7888 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007889
7890 /* Convert signal to DBM */
7891 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007892 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007893
7894 /* Convert the channel data and set the flags */
7895 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7896 if (received_channel > 14) { /* 802.11a */
7897 ipw_rt->rt_chbitmask =
7898 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7899 } else if (antennaAndPhy & 32) { /* 802.11b */
7900 ipw_rt->rt_chbitmask =
7901 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7902 } else { /* 802.11g */
7903 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007904 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007905 }
7906
7907 /* set the rate in multiples of 500k/s */
7908 switch (pktrate) {
7909 case IPW_TX_RATE_1MB:
7910 ipw_rt->rt_rate = 2;
7911 break;
7912 case IPW_TX_RATE_2MB:
7913 ipw_rt->rt_rate = 4;
7914 break;
7915 case IPW_TX_RATE_5MB:
7916 ipw_rt->rt_rate = 10;
7917 break;
7918 case IPW_TX_RATE_6MB:
7919 ipw_rt->rt_rate = 12;
7920 break;
7921 case IPW_TX_RATE_9MB:
7922 ipw_rt->rt_rate = 18;
7923 break;
7924 case IPW_TX_RATE_11MB:
7925 ipw_rt->rt_rate = 22;
7926 break;
7927 case IPW_TX_RATE_12MB:
7928 ipw_rt->rt_rate = 24;
7929 break;
7930 case IPW_TX_RATE_18MB:
7931 ipw_rt->rt_rate = 36;
7932 break;
7933 case IPW_TX_RATE_24MB:
7934 ipw_rt->rt_rate = 48;
7935 break;
7936 case IPW_TX_RATE_36MB:
7937 ipw_rt->rt_rate = 72;
7938 break;
7939 case IPW_TX_RATE_48MB:
7940 ipw_rt->rt_rate = 96;
7941 break;
7942 case IPW_TX_RATE_54MB:
7943 ipw_rt->rt_rate = 108;
7944 break;
7945 default:
7946 ipw_rt->rt_rate = 0;
7947 break;
7948 }
7949
7950 /* antenna number */
7951 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7952
7953 /* set the preamble flag if we have it */
7954 if ((antennaAndPhy & 64))
7955 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7956
7957 /* Set the size of the skb to the size of the frame */
7958 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007959
7960 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7961
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007962 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007963 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007964 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007965 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007966 /* no LED during capture */
7967 }
7968}
7969#endif
7970
Zhu Yid685b8c2006-04-13 17:20:27 +08007971#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007972#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007973 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7974 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7975
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007976#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007977 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7978
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007979#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007980 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7981
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007982#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007983 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7984
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007985#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007986 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7987
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007988#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007989 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7990
7991static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7992 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007993 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08007994{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007995 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08007996 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7997 struct ipw_rx_frame *frame = &pkt->u.frame;
7998 struct ipw_rt_hdr *ipw_rt;
7999
8000 /* First cache any information we need before we overwrite
8001 * the information provided in the skb from the hardware */
8002 struct ieee80211_hdr *hdr;
8003 u16 channel = frame->received_channel;
8004 u8 phy_flags = frame->antennaAndPhy;
8005 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008006 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008007 u8 rate = frame->rate;
8008 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008009 struct sk_buff *skb;
8010 int hdr_only = 0;
8011 u16 filter = priv->prom_priv->filter;
8012
8013 /* If the filter is set to not include Rx frames then return */
8014 if (filter & IPW_PROM_NO_RX)
8015 return;
8016
Zhu Yid685b8c2006-04-13 17:20:27 +08008017 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008018 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008019
8020 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008021 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008022 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8023 return;
8024 }
8025
8026 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008027 if (unlikely(!netif_running(dev))) {
8028 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008029 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8030 return;
8031 }
8032
8033 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8034 * that now */
8035 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8036 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008037 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008038 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8039 return;
8040 }
8041
8042 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008043 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008044 if (filter & IPW_PROM_NO_MGMT)
8045 return;
8046 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8047 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008048 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008049 if (filter & IPW_PROM_NO_CTL)
8050 return;
8051 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8052 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008053 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008054 if (filter & IPW_PROM_NO_DATA)
8055 return;
8056 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8057 hdr_only = 1;
8058 }
8059
8060 /* Copy the SKB since this is for the promiscuous side */
8061 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8062 if (skb == NULL) {
8063 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8064 return;
8065 }
8066
8067 /* copy the frame data to write after where the radiotap header goes */
8068 ipw_rt = (void *)skb->data;
8069
8070 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008071 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008072
8073 memcpy(ipw_rt->payload, hdr, len);
8074
Zhu Yid685b8c2006-04-13 17:20:27 +08008075 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8076 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008077 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008078
8079 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008080 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008081
8082 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008083 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8084 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008085 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008086 (1 << IEEE80211_RADIOTAP_RATE) |
8087 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8088 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8089 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8090 (1 << IEEE80211_RADIOTAP_ANTENNA));
8091
8092 /* Zero the flags, we'll add to them as we go */
8093 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008094 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8095 frame->parent_tsf[2] << 16 |
8096 frame->parent_tsf[1] << 8 |
8097 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008098
8099 /* Convert to DBM */
8100 ipw_rt->rt_dbmsignal = signal;
8101 ipw_rt->rt_dbmnoise = noise;
8102
8103 /* Convert the channel data and set the flags */
8104 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8105 if (channel > 14) { /* 802.11a */
8106 ipw_rt->rt_chbitmask =
8107 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8108 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8109 ipw_rt->rt_chbitmask =
8110 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8111 } else { /* 802.11g */
8112 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008113 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008114 }
8115
8116 /* set the rate in multiples of 500k/s */
8117 switch (rate) {
8118 case IPW_TX_RATE_1MB:
8119 ipw_rt->rt_rate = 2;
8120 break;
8121 case IPW_TX_RATE_2MB:
8122 ipw_rt->rt_rate = 4;
8123 break;
8124 case IPW_TX_RATE_5MB:
8125 ipw_rt->rt_rate = 10;
8126 break;
8127 case IPW_TX_RATE_6MB:
8128 ipw_rt->rt_rate = 12;
8129 break;
8130 case IPW_TX_RATE_9MB:
8131 ipw_rt->rt_rate = 18;
8132 break;
8133 case IPW_TX_RATE_11MB:
8134 ipw_rt->rt_rate = 22;
8135 break;
8136 case IPW_TX_RATE_12MB:
8137 ipw_rt->rt_rate = 24;
8138 break;
8139 case IPW_TX_RATE_18MB:
8140 ipw_rt->rt_rate = 36;
8141 break;
8142 case IPW_TX_RATE_24MB:
8143 ipw_rt->rt_rate = 48;
8144 break;
8145 case IPW_TX_RATE_36MB:
8146 ipw_rt->rt_rate = 72;
8147 break;
8148 case IPW_TX_RATE_48MB:
8149 ipw_rt->rt_rate = 96;
8150 break;
8151 case IPW_TX_RATE_54MB:
8152 ipw_rt->rt_rate = 108;
8153 break;
8154 default:
8155 ipw_rt->rt_rate = 0;
8156 break;
8157 }
8158
8159 /* antenna number */
8160 ipw_rt->rt_antenna = (phy_flags & 3);
8161
8162 /* set the preamble flag if we have it */
8163 if (phy_flags & (1 << 6))
8164 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8165
8166 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8167
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008168 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008169 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008170 dev_kfree_skb_any(skb);
8171 }
8172}
8173#endif
8174
Arjan van de Ven858119e2006-01-14 13:20:43 -08008175static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008176 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008177{
8178 /* Filter incoming packets to determine if they are targetted toward
8179 * this network, discarding packets coming from ourselves */
8180 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008181 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008182 /* packets from our adapter are dropped (echo) */
8183 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8184 return 0;
8185
Peter Jones90700fd2005-08-26 16:51:06 -05008186 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008187 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008188 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008189
8190 /* packets to our adapter go through */
8191 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8192 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008193
Peter Jones90700fd2005-08-26 16:51:06 -05008194 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008195 /* packets from our adapter are dropped (echo) */
8196 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8197 return 0;
8198
Peter Jones90700fd2005-08-26 16:51:06 -05008199 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008200 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008201 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8202
8203 /* packets to our adapter go through */
8204 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8205 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008206 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008207
James Ketrenosea2b26e2005-08-24 21:25:16 -05008208 return 1;
8209}
8210
James Ketrenosafbf30a2005-08-25 00:05:33 -05008211#define IPW_PACKET_RETRY_TIME HZ
8212
Arjan van de Ven858119e2006-01-14 13:20:43 -08008213static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008214 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008215{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008216 u16 sc = le16_to_cpu(header->seq_ctl);
8217 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8218 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8219 u16 *last_seq, *last_frag;
8220 unsigned long *last_time;
8221
8222 switch (priv->ieee->iw_mode) {
8223 case IW_MODE_ADHOC:
8224 {
8225 struct list_head *p;
8226 struct ipw_ibss_seq *entry = NULL;
8227 u8 *mac = header->addr2;
8228 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8229
8230 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8231 entry =
8232 list_entry(p, struct ipw_ibss_seq, list);
8233 if (!memcmp(entry->mac, mac, ETH_ALEN))
8234 break;
8235 }
8236 if (p == &priv->ibss_mac_hash[index]) {
8237 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8238 if (!entry) {
8239 IPW_ERROR
8240 ("Cannot malloc new mac entry\n");
8241 return 0;
8242 }
8243 memcpy(entry->mac, mac, ETH_ALEN);
8244 entry->seq_num = seq;
8245 entry->frag_num = frag;
8246 entry->packet_time = jiffies;
8247 list_add(&entry->list,
8248 &priv->ibss_mac_hash[index]);
8249 return 0;
8250 }
8251 last_seq = &entry->seq_num;
8252 last_frag = &entry->frag_num;
8253 last_time = &entry->packet_time;
8254 break;
8255 }
8256 case IW_MODE_INFRA:
8257 last_seq = &priv->last_seq_num;
8258 last_frag = &priv->last_frag_num;
8259 last_time = &priv->last_packet_time;
8260 break;
8261 default:
8262 return 0;
8263 }
8264 if ((*last_seq == seq) &&
8265 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8266 if (*last_frag == frag)
8267 goto drop;
8268 if (*last_frag + 1 != frag)
8269 /* out-of-order fragment */
8270 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008271 } else
8272 *last_seq = seq;
8273
Zhu Yif57ce7c2005-07-13 12:22:15 -05008274 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008275 *last_time = jiffies;
8276 return 0;
8277
8278 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008279 /* Comment this line now since we observed the card receives
8280 * duplicate packets but the FCTL_RETRY bit is not set in the
8281 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008282 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008283 return 1;
8284}
8285
James Ketrenosb095c382005-08-24 22:04:42 -05008286static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8287 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008288 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008289{
8290 struct sk_buff *skb = rxb->skb;
8291 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008292 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008293 (skb->data + IPW_RX_FRAME_SIZE);
8294
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008295 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008296
8297 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8298 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8299 IEEE80211_STYPE_PROBE_RESP) ||
8300 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8301 IEEE80211_STYPE_BEACON))) {
8302 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8303 ipw_add_station(priv, header->addr2);
8304 }
8305
8306 if (priv->config & CFG_NET_STATS) {
8307 IPW_DEBUG_HC("sending stat packet\n");
8308
8309 /* Set the size of the skb to the size of the full
8310 * ipw header and 802.11 frame */
8311 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8312 IPW_RX_FRAME_SIZE);
8313
8314 /* Advance past the ipw packet header to the 802.11 frame */
8315 skb_pull(skb, IPW_RX_FRAME_SIZE);
8316
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008317 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008318 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8319
8320 skb->dev = priv->ieee->dev;
8321
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008322 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008323 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008324
8325 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008326 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008327 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8328 netif_rx(skb);
8329 rxb->skb = NULL;
8330 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008331}
8332
James Ketrenos43f66a62005-03-25 12:31:53 -06008333/*
8334 * Main entry function for recieving a packet with 80211 headers. This
8335 * should be called when ever the FW has notified us that there is a new
8336 * skb in the recieve queue.
8337 */
8338static void ipw_rx(struct ipw_priv *priv)
8339{
8340 struct ipw_rx_mem_buffer *rxb;
8341 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008342 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008343 u32 r, w, i;
8344 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008345 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008346
James Ketrenosb095c382005-08-24 22:04:42 -05008347 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8348 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008349 i = priv->rxq->read;
8350
8351 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8352 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008353
8354 while (i != r) {
8355 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008356 if (unlikely(rxb == NULL)) {
8357 printk(KERN_CRIT "Queue not allocated!\n");
8358 break;
8359 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008360 priv->rxq->queue[i] = NULL;
8361
8362 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008363 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008364 PCI_DMA_FROMDEVICE);
8365
8366 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8367 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8368 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008369 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008370
8371 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008372 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008373 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008374 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008375 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008376 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008377 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008378 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008379 .noise =
8380 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008381 .rate = pkt->u.frame.rate,
8382 .mac_time = jiffies,
8383 .received_channel =
8384 pkt->u.frame.received_channel,
8385 .freq =
8386 (pkt->u.frame.
8387 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008388 LIBIPW_24GHZ_BAND :
8389 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008390 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008391 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008392
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008393 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008394 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008395 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008396 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008397 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008398 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008399 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008400 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008402 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008403
Zhu Yid685b8c2006-04-13 17:20:27 +08008404#ifdef CONFIG_IPW2200_PROMISCUOUS
8405 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8406 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8407#endif
8408
James Ketrenosb095c382005-08-24 22:04:42 -05008409#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008410 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008411#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008412
8413 ipw_handle_data_packet_monitor(priv,
8414 rxb,
8415 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008416#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008417 ipw_handle_data_packet(priv, rxb,
8418 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008419#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008420 break;
8421 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008422#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008423
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008424 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008425 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008426 data +
8427 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008428 /* TODO: Check Ad-Hoc dest/source and make sure
8429 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008430 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008431 * frame control of the packet and disregard
8432 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008433
James Ketrenosea2b26e2005-08-24 21:25:16 -05008434 network_packet =
8435 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008436 if (network_packet && priv->assoc_network) {
8437 priv->assoc_network->stats.rssi =
8438 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008439 priv->exp_avg_rssi =
8440 exponential_average(priv->exp_avg_rssi,
8441 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008442 }
8443
8444 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008445 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008446
James Ketrenosa613bff2005-08-24 21:43:11 -05008447 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008448 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008449 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008450 IPW_DEBUG_DROP
8451 ("Received packet is too small. "
8452 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008453 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008454 priv->wstats.discard.misc++;
8455 break;
8456 }
8457
James Ketrenosa613bff2005-08-24 21:43:11 -05008458 switch (WLAN_FC_GET_TYPE
8459 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008460
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008461 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008462 ipw_handle_mgmt_packet(priv, rxb,
8463 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008464 break;
8465
8466 case IEEE80211_FTYPE_CTL:
8467 break;
8468
8469 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008470 if (unlikely(!network_packet ||
8471 is_duplicate_packet(priv,
8472 header)))
8473 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008474 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008475 "%pM, "
8476 "%pM, "
8477 "%pM\n",
8478 header->addr1,
8479 header->addr2,
8480 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008481 break;
8482 }
8483
8484 ipw_handle_data_packet(priv, rxb,
8485 &stats);
8486
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008487 break;
8488 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008489 break;
8490 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008491
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008492 case RX_HOST_NOTIFICATION_TYPE:{
8493 IPW_DEBUG_RX
8494 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008495 pkt->u.notification.subtype,
8496 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008497 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008498 ipw_rx_notification(priv, &pkt->u.notification);
8499 break;
8500 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008501
8502 default:
8503 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8504 pkt->header.message_type);
8505 break;
8506 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008507
8508 /* For now we just don't re-use anything. We can tweak this
8509 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008510 * fail to Rx correctly */
8511 if (rxb->skb != NULL) {
8512 dev_kfree_skb_any(rxb->skb);
8513 rxb->skb = NULL;
8514 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008515
James Ketrenos43f66a62005-03-25 12:31:53 -06008516 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008517 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008518 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008519
James Ketrenos43f66a62005-03-25 12:31:53 -06008520 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008521
8522 /* If there are a lot of unsued frames, restock the Rx queue
8523 * so the ucode won't assert */
8524 if (fill_rx) {
8525 priv->rxq->read = i;
8526 ipw_rx_queue_replenish(priv);
8527 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008528 }
8529
8530 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008531 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008532 ipw_rx_queue_restock(priv);
8533}
8534
James Ketrenosafbf30a2005-08-25 00:05:33 -05008535#define DEFAULT_RTS_THRESHOLD 2304U
8536#define MIN_RTS_THRESHOLD 1U
8537#define MAX_RTS_THRESHOLD 2304U
8538#define DEFAULT_BEACON_INTERVAL 100U
8539#define DEFAULT_SHORT_RETRY_LIMIT 7U
8540#define DEFAULT_LONG_RETRY_LIMIT 4U
8541
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008542/**
8543 * ipw_sw_reset
8544 * @option: options to control different reset behaviour
8545 * 0 = reset everything except the 'disable' module_param
8546 * 1 = reset everything and print out driver info (for probe only)
8547 * 2 = reset everything
8548 */
8549static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008550{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008551 int band, modulation;
8552 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008553
James Ketrenosafbf30a2005-08-25 00:05:33 -05008554 /* Initialize module parameter values here */
8555 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008556
James Ketrenosafbf30a2005-08-25 00:05:33 -05008557 /* We default to disabling the LED code as right now it causes
8558 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008559 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008560 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008561
James Ketrenosafbf30a2005-08-25 00:05:33 -05008562 if (associate)
8563 priv->config |= CFG_ASSOCIATE;
8564 else
8565 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008566
James Ketrenosafbf30a2005-08-25 00:05:33 -05008567 if (auto_create)
8568 priv->config |= CFG_ADHOC_CREATE;
8569 else
8570 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8571
Zhu Yi17ed0812006-01-24 16:36:31 +08008572 priv->config &= ~CFG_STATIC_ESSID;
8573 priv->essid_len = 0;
8574 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8575
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008576 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008577 priv->status |= STATUS_RF_KILL_SW;
8578 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008579 }
8580
Reinette Chatre21f8a732009-08-18 10:25:05 -07008581 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008582 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008583 priv->channel = default_channel;
8584 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008585 /* TODO: Validate that provided channel is in range */
8586 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008587#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008588 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8589 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008590#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008591
Reinette Chatre21f8a732009-08-18 10:25:05 -07008592 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008593 case 1:
8594 priv->ieee->iw_mode = IW_MODE_ADHOC;
8595 priv->net_dev->type = ARPHRD_ETHER;
8596
8597 break;
8598#ifdef CONFIG_IPW2200_MONITOR
8599 case 2:
8600 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008601#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008602 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8603#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008604 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008605#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008606 break;
8607#endif
8608 default:
8609 case 0:
8610 priv->net_dev->type = ARPHRD_ETHER;
8611 priv->ieee->iw_mode = IW_MODE_INFRA;
8612 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008613 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008614
James Ketrenosafbf30a2005-08-25 00:05:33 -05008615 if (hwcrypto) {
8616 priv->ieee->host_encrypt = 0;
8617 priv->ieee->host_encrypt_msdu = 0;
8618 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008619 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008620 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008621 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008622
Zhu Yie402c932005-08-05 17:20:40 +08008623 /* IPW2200/2915 is abled to do hardware fragmentation. */
8624 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008625
James Ketrenosafbf30a2005-08-25 00:05:33 -05008626 if ((priv->pci_dev->device == 0x4223) ||
8627 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008628 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008629 printk(KERN_INFO DRV_NAME
8630 ": Detected Intel PRO/Wireless 2915ABG Network "
8631 "Connection\n");
8632 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008633 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8634 modulation = LIBIPW_OFDM_MODULATION |
8635 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008636 priv->adapter = IPW_2915ABG;
8637 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008638 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008639 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008640 printk(KERN_INFO DRV_NAME
8641 ": Detected Intel PRO/Wireless 2200BG Network "
8642 "Connection\n");
8643
8644 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008645 band = LIBIPW_24GHZ_BAND;
8646 modulation = LIBIPW_OFDM_MODULATION |
8647 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008648 priv->adapter = IPW_2200BG;
8649 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008650 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008651
James Ketrenosafbf30a2005-08-25 00:05:33 -05008652 priv->ieee->freq_band = band;
8653 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008654
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008655 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008656
James Ketrenosafbf30a2005-08-25 00:05:33 -05008657 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8658 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008659
James Ketrenosafbf30a2005-08-25 00:05:33 -05008660 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8661 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8662 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008663
James Ketrenosafbf30a2005-08-25 00:05:33 -05008664 /* If power management is turned on, default to AC mode */
8665 priv->power_mode = IPW_POWER_AC;
8666 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008667
Zhu Yi0ece35b2005-08-05 17:26:51 +08008668 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008669}
8670
8671/*
8672 * This file defines the Wireless Extension handlers. It does not
8673 * define any methods of hardware manipulation and relies on the
8674 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008675 *
8676 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008677 * function used to poll the hardware vs. making unecessary calls.
8678 *
8679 */
8680
James Ketrenos43f66a62005-03-25 12:31:53 -06008681static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8682{
8683 if (channel == 0) {
8684 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8685 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008686 IPW_DEBUG_ASSOC("Attempting to associate with new "
8687 "parameters.\n");
8688 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008689 return 0;
8690 }
8691
8692 priv->config |= CFG_STATIC_CHANNEL;
8693
8694 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008695 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8696 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008697 return 0;
8698 }
8699
8700 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8701 priv->channel = channel;
8702
James Ketrenosb095c382005-08-24 22:04:42 -05008703#ifdef CONFIG_IPW2200_MONITOR
8704 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008705 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008706 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008707 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008708 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008709 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008710 }
8711
8712 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8713 udelay(10);
8714
8715 if (priv->status & STATUS_SCANNING)
8716 IPW_DEBUG_SCAN("Still scanning...\n");
8717 else
8718 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8719 1000 - i);
8720
8721 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008722 }
James Ketrenosb095c382005-08-24 22:04:42 -05008723#endif /* CONFIG_IPW2200_MONITOR */
8724
James Ketrenosc848d0a2005-08-24 21:56:24 -05008725 /* Network configuration changed -- force [re]association */
8726 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8727 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008728 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008729
8730 return 0;
8731}
8732
Jeff Garzikbf794512005-07-31 13:07:26 -04008733static int ipw_wx_set_freq(struct net_device *dev,
8734 struct iw_request_info *info,
8735 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008736{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008737 struct ipw_priv *priv = libipw_priv(dev);
8738 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008740 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008741 u8 channel, flags;
8742 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008743
James Ketrenosb095c382005-08-24 22:04:42 -05008744 if (fwrq->m == 0) {
8745 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008746 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008747 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008748 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008749 return ret;
8750 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008751 /* if setting by freq convert to channel */
8752 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008753 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008754 if (channel == 0)
8755 return -EINVAL;
8756 } else
8757 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008758
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008759 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008760 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008761
Liu Hong1fe0adb2005-08-19 09:33:10 -05008762 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008763 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008764 if (i == -1)
8765 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008766
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008767 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008768 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008769 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008770 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8771 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 }
8773 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008774
James Ketrenos43f66a62005-03-25 12:31:53 -06008775 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008776 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008777 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008778 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008779 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008780}
8781
Jeff Garzikbf794512005-07-31 13:07:26 -04008782static int ipw_wx_get_freq(struct net_device *dev,
8783 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008784 union iwreq_data *wrqu, char *extra)
8785{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008786 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008787
8788 wrqu->freq.e = 0;
8789
8790 /* If we are associated, trying to associate, or have a statically
8791 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008792 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008794 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8795 int i;
8796
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008797 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008798 BUG_ON(i == -1);
8799 wrqu->freq.e = 1;
8800
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008801 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8802 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008803 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8804 break;
8805
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008806 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008807 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8808 break;
8809
8810 default:
8811 BUG();
8812 }
8813 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008814 wrqu->freq.m = 0;
8815
Zhu Yi46441512006-01-24 16:37:59 +08008816 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008817 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8818 return 0;
8819}
8820
Jeff Garzikbf794512005-07-31 13:07:26 -04008821static int ipw_wx_set_mode(struct net_device *dev,
8822 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008823 union iwreq_data *wrqu, char *extra)
8824{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008825 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008826 int err = 0;
8827
8828 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8829
James Ketrenos43f66a62005-03-25 12:31:53 -06008830 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008831#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 case IW_MODE_MONITOR:
8833#endif
8834 case IW_MODE_ADHOC:
8835 case IW_MODE_INFRA:
8836 break;
8837 case IW_MODE_AUTO:
8838 wrqu->mode = IW_MODE_INFRA;
8839 break;
8840 default:
8841 return -EINVAL;
8842 }
James Ketrenosb095c382005-08-24 22:04:42 -05008843 if (wrqu->mode == priv->ieee->iw_mode)
8844 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008845
Zhu Yi46441512006-01-24 16:37:59 +08008846 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008847
8848 ipw_sw_reset(priv, 0);
8849
James Ketrenosb095c382005-08-24 22:04:42 -05008850#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008851 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008853
8854 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008855#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008856 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8857#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008858 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008859#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008860#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008861
Jeff Garzikbf794512005-07-31 13:07:26 -04008862 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008863 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008864 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008865
8866 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008867
James Ketrenosc848d0a2005-08-24 21:56:24 -05008868 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008869 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008870 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008871}
8872
Jeff Garzikbf794512005-07-31 13:07:26 -04008873static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008874 struct iw_request_info *info,
8875 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008876{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008877 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008878 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 wrqu->mode = priv->ieee->iw_mode;
8880 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008881 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008882 return 0;
8883}
8884
James Ketrenos43f66a62005-03-25 12:31:53 -06008885/* Values are in microsecond */
8886static const s32 timeout_duration[] = {
8887 350000,
8888 250000,
8889 75000,
8890 37000,
8891 25000,
8892};
8893
8894static const s32 period_duration[] = {
8895 400000,
8896 700000,
8897 1000000,
8898 1000000,
8899 1000000
8900};
8901
Jeff Garzikbf794512005-07-31 13:07:26 -04008902static int ipw_wx_get_range(struct net_device *dev,
8903 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008904 union iwreq_data *wrqu, char *extra)
8905{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008906 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008908 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008909 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008910
8911 wrqu->data.length = sizeof(*range);
8912 memset(range, 0, sizeof(*range));
8913
8914 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008915 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008916
8917 range->max_qual.qual = 100;
8918 /* TODO: Find real max RSSI and stick here */
8919 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008920 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008921 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008922
8923 range->avg_qual.qual = 70;
8924 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008925 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008927 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008928 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008929 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008930
Jeff Garzikbf794512005-07-31 13:07:26 -04008931 for (i = 0; i < range->num_bitrates; i++)
8932 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008933 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008934
James Ketrenos43f66a62005-03-25 12:31:53 -06008935 range->max_rts = DEFAULT_RTS_THRESHOLD;
8936 range->min_frag = MIN_FRAG_THRESHOLD;
8937 range->max_frag = MAX_FRAG_THRESHOLD;
8938
8939 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008940 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008941 range->num_encoding_sizes = 2;
8942 range->max_encoding_tokens = WEP_KEYS;
8943
8944 /* Set the Wireless Extension versions */
8945 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008946 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008947
James Ketrenosb095c382005-08-24 22:04:42 -05008948 i = 0;
8949 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008950 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8951 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008952 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008953 continue;
8954
James Ketrenosb095c382005-08-24 22:04:42 -05008955 range->freq[i].i = geo->bg[j].channel;
8956 range->freq[i].m = geo->bg[j].freq * 100000;
8957 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008958 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008959 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008960 }
James Ketrenosb095c382005-08-24 22:04:42 -05008961
8962 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008963 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8964 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008965 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008966 continue;
8967
James Ketrenosb095c382005-08-24 22:04:42 -05008968 range->freq[i].i = geo->a[j].channel;
8969 range->freq[i].m = geo->a[j].freq * 100000;
8970 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008971 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008972 }
8973 }
8974
8975 range->num_channels = i;
8976 range->num_frequency = i;
8977
Zhu Yi46441512006-01-24 16:37:59 +08008978 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008979
8980 /* Event capability (kernel + driver) */
8981 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8982 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008983 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8984 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008985 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008986
Dan Williamsf1b50862006-01-30 13:58:56 -05008987 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8988 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8989
Dan Williams374fdfb2007-12-12 10:25:07 -05008990 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
8991
James Ketrenos43f66a62005-03-25 12:31:53 -06008992 IPW_DEBUG_WX("GET Range\n");
8993 return 0;
8994}
8995
Jeff Garzikbf794512005-07-31 13:07:26 -04008996static int ipw_wx_set_wap(struct net_device *dev,
8997 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008998 union iwreq_data *wrqu, char *extra)
8999{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009000 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009001
9002 static const unsigned char any[] = {
9003 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9004 };
9005 static const unsigned char off[] = {
9006 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9007 };
9008
Jeff Garzikbf794512005-07-31 13:07:26 -04009009 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009010 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009011 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009012 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9013 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9014 /* we disable mandatory BSSID association */
9015 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9016 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009017 IPW_DEBUG_ASSOC("Attempting to associate with new "
9018 "parameters.\n");
9019 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009020 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009021 return 0;
9022 }
9023
9024 priv->config |= CFG_STATIC_BSSID;
9025 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9026 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009027 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009028 return 0;
9029 }
9030
Johannes Berge1749612008-10-27 15:59:26 -07009031 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9032 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009033
9034 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9035
James Ketrenosc848d0a2005-08-24 21:56:24 -05009036 /* Network configuration changed -- force [re]association */
9037 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9038 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009039 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009040
Zhu Yi46441512006-01-24 16:37:59 +08009041 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 return 0;
9043}
9044
Jeff Garzikbf794512005-07-31 13:07:26 -04009045static int ipw_wx_get_wap(struct net_device *dev,
9046 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009047 union iwreq_data *wrqu, char *extra)
9048{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009049 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009050
James Ketrenos43f66a62005-03-25 12:31:53 -06009051 /* If we are associated, trying to associate, or have a statically
9052 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009053 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009054 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009055 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9056 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009057 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009058 } else
9059 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9060
Johannes Berge1749612008-10-27 15:59:26 -07009061 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9062 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009063 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 return 0;
9065}
9066
Jeff Garzikbf794512005-07-31 13:07:26 -04009067static int ipw_wx_set_essid(struct net_device *dev,
9068 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 union iwreq_data *wrqu, char *extra)
9070{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009071 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009072 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009073 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009074
Zhu Yiab644b02006-08-21 11:37:13 +08009075 mutex_lock(&priv->mutex);
9076
9077 if (!wrqu->essid.flags)
9078 {
9079 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9080 ipw_disassociate(priv);
9081 priv->config &= ~CFG_STATIC_ESSID;
9082 ipw_associate(priv);
9083 mutex_unlock(&priv->mutex);
9084 return 0;
9085 }
9086
Zhu Yia9f0d422006-08-21 11:37:26 +08009087 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009088
9089 priv->config |= CFG_STATIC_ESSID;
9090
Zhu Yia9f0d422006-08-21 11:37:26 +08009091 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9092 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009093 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009094 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009095 return 0;
9096 }
9097
John W. Linville9387b7c2008-09-30 20:59:05 -04009098 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9099 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009100
9101 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009102 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009103
James Ketrenosc848d0a2005-08-24 21:56:24 -05009104 /* Network configuration changed -- force [re]association */
9105 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9106 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009108
Zhu Yi46441512006-01-24 16:37:59 +08009109 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009110 return 0;
9111}
9112
Jeff Garzikbf794512005-07-31 13:07:26 -04009113static int ipw_wx_get_essid(struct net_device *dev,
9114 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009115 union iwreq_data *wrqu, char *extra)
9116{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009117 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009118 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009119
9120 /* If we are associated, trying to associate, or have a statically
9121 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009122 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009123 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009124 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9125 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009126 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009127 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009129 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009130 } else {
9131 IPW_DEBUG_WX("Getting essid: ANY\n");
9132 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009133 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009134 }
Zhu Yi46441512006-01-24 16:37:59 +08009135 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 return 0;
9137}
9138
Jeff Garzikbf794512005-07-31 13:07:26 -04009139static int ipw_wx_set_nick(struct net_device *dev,
9140 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009141 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009142{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009143 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144
9145 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9146 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9147 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009148 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009149 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009151 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009152 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009153 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 return 0;
9155
9156}
9157
Jeff Garzikbf794512005-07-31 13:07:26 -04009158static int ipw_wx_get_nick(struct net_device *dev,
9159 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009160 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009161{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009162 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009163 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009164 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009165 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009166 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009168 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 return 0;
9170}
9171
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009172static int ipw_wx_set_sens(struct net_device *dev,
9173 struct iw_request_info *info,
9174 union iwreq_data *wrqu, char *extra)
9175{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009176 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009177 int err = 0;
9178
9179 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9180 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9181 mutex_lock(&priv->mutex);
9182
9183 if (wrqu->sens.fixed == 0)
9184 {
9185 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9186 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9187 goto out;
9188 }
9189 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9190 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9191 err = -EINVAL;
9192 goto out;
9193 }
9194
9195 priv->roaming_threshold = wrqu->sens.value;
9196 priv->disassociate_threshold = 3*wrqu->sens.value;
9197 out:
9198 mutex_unlock(&priv->mutex);
9199 return err;
9200}
9201
9202static int ipw_wx_get_sens(struct net_device *dev,
9203 struct iw_request_info *info,
9204 union iwreq_data *wrqu, char *extra)
9205{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009206 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009207 mutex_lock(&priv->mutex);
9208 wrqu->sens.fixed = 1;
9209 wrqu->sens.value = priv->roaming_threshold;
9210 mutex_unlock(&priv->mutex);
9211
9212 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9213 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9214
9215 return 0;
9216}
9217
James Ketrenos43f66a62005-03-25 12:31:53 -06009218static int ipw_wx_set_rate(struct net_device *dev,
9219 struct iw_request_info *info,
9220 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009221{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009222 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009223 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009224 u32 target_rate = wrqu->bitrate.value;
9225 u32 fixed, mask;
9226
9227 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9228 /* value = X, fixed = 1 means only rate X */
9229 /* value = X, fixed = 0 means all rates lower equal X */
9230
9231 if (target_rate == -1) {
9232 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009233 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009234 /* Now we should reassociate */
9235 goto apply;
9236 }
9237
9238 mask = 0;
9239 fixed = wrqu->bitrate.fixed;
9240
9241 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009242 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009243 if (target_rate == 1000000)
9244 goto apply;
9245
9246 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009247 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009248 if (target_rate == 2000000)
9249 goto apply;
9250
9251 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009252 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009253 if (target_rate == 5500000)
9254 goto apply;
9255
9256 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009257 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009258 if (target_rate == 6000000)
9259 goto apply;
9260
9261 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009262 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009263 if (target_rate == 9000000)
9264 goto apply;
9265
9266 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009267 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009268 if (target_rate == 11000000)
9269 goto apply;
9270
9271 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009272 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009273 if (target_rate == 12000000)
9274 goto apply;
9275
9276 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009277 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009278 if (target_rate == 18000000)
9279 goto apply;
9280
9281 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009282 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009283 if (target_rate == 24000000)
9284 goto apply;
9285
9286 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009287 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009288 if (target_rate == 36000000)
9289 goto apply;
9290
9291 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009292 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009293 if (target_rate == 48000000)
9294 goto apply;
9295
9296 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009297 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009298 if (target_rate == 54000000)
9299 goto apply;
9300
9301 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9302 return -EINVAL;
9303
9304 apply:
9305 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9306 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009307 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009308 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009309 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009310 ipw_set_fixed_rate(priv, priv->ieee->mode);
9311 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009312 priv->config |= CFG_FIXED_RATE;
9313
James Ketrenosc848d0a2005-08-24 21:56:24 -05009314 if (priv->rates_mask == mask) {
9315 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009316 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009317 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009318 }
9319
James Ketrenosc848d0a2005-08-24 21:56:24 -05009320 priv->rates_mask = mask;
9321
9322 /* Network configuration changed -- force [re]association */
9323 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9324 if (!ipw_disassociate(priv))
9325 ipw_associate(priv);
9326
Zhu Yi46441512006-01-24 16:37:59 +08009327 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009328 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009329}
9330
Jeff Garzikbf794512005-07-31 13:07:26 -04009331static int ipw_wx_get_rate(struct net_device *dev,
9332 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009333 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009334{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009335 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009336 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009337 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009338 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009339 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009340 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9341 return 0;
9342}
9343
Jeff Garzikbf794512005-07-31 13:07:26 -04009344static int ipw_wx_set_rts(struct net_device *dev,
9345 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009347{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009348 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009349 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009350 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9352 else {
9353 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009354 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009355 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009356 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009357 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 priv->rts_threshold = wrqu->rts.value;
9359 }
9360
9361 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009362 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9364 return 0;
9365}
9366
Jeff Garzikbf794512005-07-31 13:07:26 -04009367static int ipw_wx_get_rts(struct net_device *dev,
9368 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009369 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009370{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009371 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009372 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 wrqu->rts.value = priv->rts_threshold;
9374 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009375 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009376 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009377 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9378 return 0;
9379}
9380
Jeff Garzikbf794512005-07-31 13:07:26 -04009381static int ipw_wx_set_txpow(struct net_device *dev,
9382 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009383 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009384{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009385 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009386 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009387
Zhu Yi46441512006-01-24 16:37:59 +08009388 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009389 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009390 err = -EINPROGRESS;
9391 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009392 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009393
James Ketrenosb095c382005-08-24 22:04:42 -05009394 if (!wrqu->power.fixed)
9395 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009396
James Ketrenosc848d0a2005-08-24 21:56:24 -05009397 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009398 err = -EINVAL;
9399 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009400 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009401
James Ketrenosb095c382005-08-24 22:04:42 -05009402 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009403 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009404 err = -EINVAL;
9405 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009406 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009407
9408 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009409 err = ipw_set_tx_power(priv);
9410 out:
Zhu Yi46441512006-01-24 16:37:59 +08009411 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009412 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009413}
9414
Jeff Garzikbf794512005-07-31 13:07:26 -04009415static int ipw_wx_get_txpow(struct net_device *dev,
9416 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009417 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009418{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009419 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009420 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 wrqu->power.value = priv->tx_power;
9422 wrqu->power.fixed = 1;
9423 wrqu->power.flags = IW_TXPOW_DBM;
9424 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009425 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009426
Jeff Garzikbf794512005-07-31 13:07:26 -04009427 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009428 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009429
9430 return 0;
9431}
9432
Jeff Garzikbf794512005-07-31 13:07:26 -04009433static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009434 struct iw_request_info *info,
9435 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009436{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009437 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009438 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009439 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009440 priv->ieee->fts = DEFAULT_FTS;
9441 else {
9442 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009443 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009444 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009446 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009447
James Ketrenos43f66a62005-03-25 12:31:53 -06009448 priv->ieee->fts = wrqu->frag.value & ~0x1;
9449 }
9450
9451 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009452 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009453 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9454 return 0;
9455}
9456
Jeff Garzikbf794512005-07-31 13:07:26 -04009457static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009458 struct iw_request_info *info,
9459 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009460{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009461 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009462 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463 wrqu->frag.value = priv->ieee->fts;
9464 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009465 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009466 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009467 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9468
9469 return 0;
9470}
9471
Jeff Garzikbf794512005-07-31 13:07:26 -04009472static int ipw_wx_set_retry(struct net_device *dev,
9473 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009474 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009475{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009476 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009477
9478 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9479 return -EINVAL;
9480
9481 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9482 return 0;
9483
Zhu Yid5f7ac22006-08-21 11:38:17 +08009484 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009485 return -EINVAL;
9486
Zhu Yi46441512006-01-24 16:37:59 +08009487 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009488 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009489 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009490 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009491 priv->long_retry_limit = (u8) wrqu->retry.value;
9492 else {
9493 priv->short_retry_limit = (u8) wrqu->retry.value;
9494 priv->long_retry_limit = (u8) wrqu->retry.value;
9495 }
9496
9497 ipw_send_retry_limit(priv, priv->short_retry_limit,
9498 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009499 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009500 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9501 priv->short_retry_limit, priv->long_retry_limit);
9502 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009503}
9504
Jeff Garzikbf794512005-07-31 13:07:26 -04009505static int ipw_wx_get_retry(struct net_device *dev,
9506 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009507 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009508{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009509 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009510
Zhu Yi46441512006-01-24 16:37:59 +08009511 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009512 wrqu->retry.disabled = 0;
9513
9514 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009515 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009516 return -EINVAL;
9517 }
9518
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009519 if (wrqu->retry.flags & IW_RETRY_LONG) {
9520 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009521 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009522 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9523 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009524 wrqu->retry.value = priv->short_retry_limit;
9525 } else {
9526 wrqu->retry.flags = IW_RETRY_LIMIT;
9527 wrqu->retry.value = priv->short_retry_limit;
9528 }
Zhu Yi46441512006-01-24 16:37:59 +08009529 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009530
9531 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9532
9533 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009534}
9535
Jeff Garzikbf794512005-07-31 13:07:26 -04009536static int ipw_wx_set_scan(struct net_device *dev,
9537 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009538 union iwreq_data *wrqu, char *extra)
9539{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009540 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009541 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009542 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009543
Dan Williams0b531672007-10-09 13:55:24 -04009544 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009545
Dan Williams0b531672007-10-09 13:55:24 -04009546 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009547
Zhu Yi094c4d22006-08-21 11:39:03 +08009548 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009549 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009550 int len = min((int)req->essid_len,
9551 (int)sizeof(priv->direct_scan_ssid));
9552 memcpy(priv->direct_scan_ssid, req->essid, len);
9553 priv->direct_scan_ssid_len = len;
9554 work = &priv->request_direct_scan;
9555 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9556 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009557 }
Dan Williamsea177302008-06-02 17:51:23 -04009558 } else {
9559 /* Normal active broadcast scan */
9560 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009561 }
James Ketrenos8935f392005-10-05 15:59:08 -05009562
Dan Williamsea177302008-06-02 17:51:23 -04009563 mutex_unlock(&priv->mutex);
9564
James Ketrenos43f66a62005-03-25 12:31:53 -06009565 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009566
Dan Williamsea177302008-06-02 17:51:23 -04009567 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009568
James Ketrenos43f66a62005-03-25 12:31:53 -06009569 return 0;
9570}
9571
Jeff Garzikbf794512005-07-31 13:07:26 -04009572static int ipw_wx_get_scan(struct net_device *dev,
9573 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009574 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009575{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009576 struct ipw_priv *priv = libipw_priv(dev);
9577 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009578}
9579
Jeff Garzikbf794512005-07-31 13:07:26 -04009580static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009581 struct iw_request_info *info,
9582 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009583{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009584 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009585 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009586 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009587
Zhu Yi46441512006-01-24 16:37:59 +08009588 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009589 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009590
Hong Liucaeff812005-08-05 17:25:50 +08009591 /* In IBSS mode, we need to notify the firmware to update
9592 * the beacon info after we changed the capability. */
9593 if (cap != priv->capability &&
9594 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9595 priv->status & STATUS_ASSOCIATED)
9596 ipw_disassociate(priv);
9597
Zhu Yi46441512006-01-24 16:37:59 +08009598 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009599 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009600}
9601
Jeff Garzikbf794512005-07-31 13:07:26 -04009602static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009603 struct iw_request_info *info,
9604 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009605{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009606 struct ipw_priv *priv = libipw_priv(dev);
9607 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009608}
9609
Jeff Garzikbf794512005-07-31 13:07:26 -04009610static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009611 struct iw_request_info *info,
9612 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009613{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009614 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009615 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009616 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009617 if (wrqu->power.disabled) {
9618 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9619 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9620 if (err) {
9621 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009622 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009623 return err;
9624 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009625 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009626 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009627 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009628 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009629
9630 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009631 case IW_POWER_ON: /* If not specified */
9632 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009633 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009635 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009636 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9637 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009638 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009639 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009640 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009641
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 /* If the user hasn't specified a power management mode yet, default
9643 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009644 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009646 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009647 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009648
James Ketrenos43f66a62005-03-25 12:31:53 -06009649 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9650 if (err) {
9651 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009652 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 return err;
9654 }
9655
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009656 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009657 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009658 return 0;
9659}
9660
Jeff Garzikbf794512005-07-31 13:07:26 -04009661static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009662 struct iw_request_info *info,
9663 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009664{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009665 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009666 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009667 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009669 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009671
Zhu Yi46441512006-01-24 16:37:59 +08009672 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009673 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009674
James Ketrenos43f66a62005-03-25 12:31:53 -06009675 return 0;
9676}
9677
Jeff Garzikbf794512005-07-31 13:07:26 -04009678static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009679 struct iw_request_info *info,
9680 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009681{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009682 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 int mode = *(int *)extra;
9684 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009685
Zhu Yi46441512006-01-24 16:37:59 +08009686 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009687 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009688 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009689
Zhu Yi4e157f02007-07-12 16:09:32 +08009690 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009691 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 if (err) {
9693 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009694 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009695 return err;
9696 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009697 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009698 }
Zhu Yi46441512006-01-24 16:37:59 +08009699 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009700 return 0;
9701}
9702
9703#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009704static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009705 struct iw_request_info *info,
9706 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009707{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009708 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 int level = IPW_POWER_LEVEL(priv->power_mode);
9710 char *p = extra;
9711
9712 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9713
9714 switch (level) {
9715 case IPW_POWER_AC:
9716 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9717 break;
9718 case IPW_POWER_BATTERY:
9719 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9720 break;
9721 default:
9722 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009723 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009724 timeout_duration[level - 1] / 1000,
9725 period_duration[level - 1] / 1000);
9726 }
9727
9728 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009729 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009730
9731 wrqu->data.length = p - extra + 1;
9732
9733 return 0;
9734}
9735
9736static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009737 struct iw_request_info *info,
9738 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009739{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009740 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 int mode = *(int *)extra;
9742 u8 band = 0, modulation = 0;
9743
9744 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009745 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009746 return -EINVAL;
9747 }
Zhu Yi46441512006-01-24 16:37:59 +08009748 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009749 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009750 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009751 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009752 band |= LIBIPW_52GHZ_BAND;
9753 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009754 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009755 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 } else {
9757 if (mode & IEEE_A) {
9758 IPW_WARNING("Attempt to set 2200BG into "
9759 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009760 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009761 return -EINVAL;
9762 }
9763
James Ketrenosa33a1982005-09-14 14:28:59 -05009764 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 }
9766
9767 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009768 band |= LIBIPW_24GHZ_BAND;
9769 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009771 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009772
James Ketrenos43f66a62005-03-25 12:31:53 -06009773 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009774 band |= LIBIPW_24GHZ_BAND;
9775 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009776 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009777 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009778
9779 priv->ieee->mode = mode;
9780 priv->ieee->freq_band = band;
9781 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009782 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009783
James Ketrenosc848d0a2005-08-24 21:56:24 -05009784 /* Network configuration changed -- force [re]association */
9785 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9786 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009788 ipw_associate(priv);
9789 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009790
James Ketrenosa613bff2005-08-24 21:43:11 -05009791 /* Update the band LEDs */
9792 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009793
Jeff Garzikbf794512005-07-31 13:07:26 -04009794 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009795 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009796 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009797 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009798 return 0;
9799}
9800
9801static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009802 struct iw_request_info *info,
9803 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009804{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009805 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009806 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009807 switch (priv->ieee->mode) {
9808 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009809 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9810 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009811 case IEEE_B:
9812 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9813 break;
9814 case IEEE_A | IEEE_B:
9815 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9816 break;
9817 case IEEE_G:
9818 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9819 break;
9820 case IEEE_A | IEEE_G:
9821 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9822 break;
9823 case IEEE_B | IEEE_G:
9824 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9825 break;
9826 case IEEE_A | IEEE_B | IEEE_G:
9827 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9828 break;
9829 default:
9830 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009831 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009832 }
9833
James Ketrenos43f66a62005-03-25 12:31:53 -06009834 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9835
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009836 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009837 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009838
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009839 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009840}
9841
James Ketrenosea2b26e2005-08-24 21:25:16 -05009842static int ipw_wx_set_preamble(struct net_device *dev,
9843 struct iw_request_info *info,
9844 union iwreq_data *wrqu, char *extra)
9845{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009846 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009847 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009848 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009849 /* Switching from SHORT -> LONG requires a disassociation */
9850 if (mode == 1) {
9851 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9852 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009853
9854 /* Network configuration changed -- force [re]association */
9855 IPW_DEBUG_ASSOC
9856 ("[re]association triggered due to preamble change.\n");
9857 if (!ipw_disassociate(priv))
9858 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009859 }
9860 goto done;
9861 }
9862
9863 if (mode == 0) {
9864 priv->config &= ~CFG_PREAMBLE_LONG;
9865 goto done;
9866 }
Zhu Yi46441512006-01-24 16:37:59 +08009867 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009868 return -EINVAL;
9869
9870 done:
Zhu Yi46441512006-01-24 16:37:59 +08009871 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009872 return 0;
9873}
9874
9875static int ipw_wx_get_preamble(struct net_device *dev,
9876 struct iw_request_info *info,
9877 union iwreq_data *wrqu, char *extra)
9878{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009879 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009880 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 if (priv->config & CFG_PREAMBLE_LONG)
9882 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9883 else
9884 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009885 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009886 return 0;
9887}
9888
James Ketrenosb095c382005-08-24 22:04:42 -05009889#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009890static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009891 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009892 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009893{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009894 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009895 int *parms = (int *)extra;
9896 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009897 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009898 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009899 if (enable) {
9900 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009901#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009902 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9903#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009904 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009905#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009906 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009907 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009908
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 ipw_set_channel(priv, parms[1]);
9910 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009911 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009912 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009914 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009915 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009916 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 }
Zhu Yi46441512006-01-24 16:37:59 +08009918 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009919 return 0;
9920}
9921
Pavel Machek67fd6b42006-07-11 15:34:05 +02009922#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009923
Jeff Garzikbf794512005-07-31 13:07:26 -04009924static int ipw_wx_reset(struct net_device *dev,
9925 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009926 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009927{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009928 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009929 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009930 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 return 0;
9932}
James Ketrenosb095c382005-08-24 22:04:42 -05009933
James Ketrenosb095c382005-08-24 22:04:42 -05009934static int ipw_wx_sw_reset(struct net_device *dev,
9935 struct iw_request_info *info,
9936 union iwreq_data *wrqu, char *extra)
9937{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009938 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009939 union iwreq_data wrqu_sec = {
9940 .encoding = {
9941 .flags = IW_ENCODE_DISABLED,
9942 },
9943 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009944 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009945
9946 IPW_DEBUG_WX("SW_RESET\n");
9947
Zhu Yi46441512006-01-24 16:37:59 +08009948 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009949
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009950 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009951 if (!ret) {
9952 free_firmware();
9953 ipw_adapter_restart(priv);
9954 }
James Ketrenosb095c382005-08-24 22:04:42 -05009955
9956 /* The SW reset bit might have been toggled on by the 'disable'
9957 * module parameter, so take appropriate action */
9958 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9959
Zhu Yi46441512006-01-24 16:37:59 +08009960 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009961 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009962 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009963
9964 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9965 /* Configuration likely changed -- force [re]association */
9966 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9967 "reset.\n");
9968 if (!ipw_disassociate(priv))
9969 ipw_associate(priv);
9970 }
9971
Zhu Yi46441512006-01-24 16:37:59 +08009972 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009973
9974 return 0;
9975}
James Ketrenos43f66a62005-03-25 12:31:53 -06009976
9977/* Rebase the WE IOCTLs to zero for the handler array */
9978#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009979static iw_handler ipw_wx_handlers[] = {
John W. Linvillea3caa992009-08-25 14:12:25 -04009980 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009981 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9982 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9983 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9984 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009985 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9986 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009987 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9988 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9989 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9990 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9991 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9992 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9993 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9994 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9995 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9996 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9997 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9998 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9999 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
10000 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
10001 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
10002 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
10003 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
10004 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10005 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10006 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10007 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10008 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10009 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -050010010 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10011 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10012 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10013 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -050010014 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10015 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10016 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10017 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10018 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10019 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10020 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -060010021};
10022
James Ketrenosb095c382005-08-24 22:04:42 -050010023enum {
10024 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10025 IPW_PRIV_GET_POWER,
10026 IPW_PRIV_SET_MODE,
10027 IPW_PRIV_GET_MODE,
10028 IPW_PRIV_SET_PREAMBLE,
10029 IPW_PRIV_GET_PREAMBLE,
10030 IPW_PRIV_RESET,
10031 IPW_PRIV_SW_RESET,
10032#ifdef CONFIG_IPW2200_MONITOR
10033 IPW_PRIV_SET_MONITOR,
10034#endif
10035};
James Ketrenos43f66a62005-03-25 12:31:53 -060010036
Jeff Garzikbf794512005-07-31 13:07:26 -040010037static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010038 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010039 .cmd = IPW_PRIV_SET_POWER,
10040 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10041 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010042 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010043 .cmd = IPW_PRIV_GET_POWER,
10044 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10045 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010047 .cmd = IPW_PRIV_SET_MODE,
10048 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10049 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010051 .cmd = IPW_PRIV_GET_MODE,
10052 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10053 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010055 .cmd = IPW_PRIV_SET_PREAMBLE,
10056 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10057 .name = "set_preamble"},
10058 {
10059 .cmd = IPW_PRIV_GET_PREAMBLE,
10060 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10061 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010063 IPW_PRIV_RESET,
10064 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010065 {
10066 IPW_PRIV_SW_RESET,
10067 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10068#ifdef CONFIG_IPW2200_MONITOR
10069 {
10070 IPW_PRIV_SET_MONITOR,
10071 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10072#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010073};
10074
10075static iw_handler ipw_priv_handler[] = {
10076 ipw_wx_set_powermode,
10077 ipw_wx_get_powermode,
10078 ipw_wx_set_wireless_mode,
10079 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010080 ipw_wx_set_preamble,
10081 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010082 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010083 ipw_wx_sw_reset,
10084#ifdef CONFIG_IPW2200_MONITOR
10085 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010086#endif
10087};
10088
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010089static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010090 .standard = ipw_wx_handlers,
10091 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10092 .num_private = ARRAY_SIZE(ipw_priv_handler),
10093 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10094 .private = ipw_priv_handler,
10095 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010096 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010097};
10098
James Ketrenos43f66a62005-03-25 12:31:53 -060010099/*
10100 * Get wireless statistics.
10101 * Called by /proc/net/wireless
10102 * Also called by SIOCGIWSTATS
10103 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010104static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010105{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010106 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010107 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010108
James Ketrenos43f66a62005-03-25 12:31:53 -060010109 wstats = &priv->wstats;
10110
James Ketrenosea2b26e2005-08-24 21:25:16 -050010111 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010112 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010113 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10114 * and associated; if not associcated, the values are all meaningless
10115 * anyway, so set them all to NULL and INVALID */
10116 if (!(priv->status & STATUS_ASSOCIATED)) {
10117 wstats->miss.beacon = 0;
10118 wstats->discard.retries = 0;
10119 wstats->qual.qual = 0;
10120 wstats->qual.level = 0;
10121 wstats->qual.noise = 0;
10122 wstats->qual.updated = 7;
10123 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010124 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010126 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010127
10128 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010129 wstats->qual.level = priv->exp_avg_rssi;
10130 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010131 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010132 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010133
10134 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10135 wstats->discard.retries = priv->last_tx_failures;
10136 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010137
James Ketrenos43f66a62005-03-25 12:31:53 -060010138/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10139 goto fail_get_ordinal;
10140 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010141
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 return wstats;
10143}
10144
James Ketrenos43f66a62005-03-25 12:31:53 -060010145/* net device stuff */
10146
Arjan van de Ven858119e2006-01-14 13:20:43 -080010147static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010148{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010149 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010150 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010151 sys_config->answer_broadcast_ssid_probe = 0;
10152 sys_config->accept_all_data_frames = 0;
10153 sys_config->accept_non_directed_frames = 1;
10154 sys_config->exclude_unicast_unencrypted = 0;
10155 sys_config->disable_unicast_decryption = 1;
10156 sys_config->exclude_multicast_unencrypted = 0;
10157 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010158 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10159 antenna = CFG_SYS_ANTENNA_BOTH;
10160 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010161 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010162 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010163 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010164 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010165 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010166 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010167}
10168
10169static int ipw_net_open(struct net_device *dev)
10170{
James Ketrenos43f66a62005-03-25 12:31:53 -060010171 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010172 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010173 return 0;
10174}
10175
10176static int ipw_net_stop(struct net_device *dev)
10177{
10178 IPW_DEBUG_INFO("dev->close\n");
10179 netif_stop_queue(dev);
10180 return 0;
10181}
10182
10183/*
10184todo:
10185
10186modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010187we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010188*/
10189
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010190static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010191 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010192{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010193 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010194 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 int i = 0;
10196 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010197#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010198 int tx_id = ipw_get_tx_queue_number(priv, pri);
10199 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10200#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010201 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010202#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 struct clx2_queue *q = &txq->q;
10204 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010205 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010206
Zhu Yib8ddafd2008-11-27 13:42:20 +080010207 if (!(priv->status & STATUS_ASSOCIATED))
10208 goto drop;
10209
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010210 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 switch (priv->ieee->iw_mode) {
10212 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010213 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010214 id = ipw_find_station(priv, hdr->addr1);
10215 if (id == IPW_INVALID_STATION) {
10216 id = ipw_add_station(priv, hdr->addr1);
10217 if (id == IPW_INVALID_STATION) {
10218 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010219 "invalid cell: %pM\n",
10220 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010221 goto drop;
10222 }
10223 }
10224 break;
10225
10226 case IW_MODE_INFRA:
10227 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010228 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010229 id = 0;
10230 break;
10231 }
10232
10233 tfd = &txq->bd[q->first_empty];
10234 txq->txb[q->first_empty] = txb;
10235 memset(tfd, 0, sizeof(*tfd));
10236 tfd->u.data.station_number = id;
10237
10238 tfd->control_flags.message_type = TX_FRAME_TYPE;
10239 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10240
10241 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010242 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010243
James Ketrenos43f66a62005-03-25 12:31:53 -060010244 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010245 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010246 else
James Ketrenosb095c382005-08-24 22:04:42 -050010247 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010248
James Ketrenosea2b26e2005-08-24 21:25:16 -050010249 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10250 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010251
James Ketrenosc848d0a2005-08-24 21:56:24 -050010252 fc = le16_to_cpu(hdr->frame_ctl);
10253 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010254
10255 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10256
James Ketrenosb095c382005-08-24 22:04:42 -050010257 if (likely(unicast))
10258 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10259
10260 if (txb->encrypted && !priv->ieee->host_encrypt) {
10261 switch (priv->ieee->sec.level) {
10262 case SEC_LEVEL_3:
10263 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010264 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010265 /* XXX: ACK flag must be set for CCMP even if it
10266 * is a multicast/broadcast packet, because CCMP
10267 * group communication encrypted by GTK is
10268 * actually done by the AP. */
10269 if (!unicast)
10270 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10271
10272 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10273 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10274 tfd->u.data.key_index = 0;
10275 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10276 break;
10277 case SEC_LEVEL_2:
10278 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010279 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010280 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10281 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10282 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10283 break;
10284 case SEC_LEVEL_1:
10285 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010286 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010287 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10288 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010289 40)
10290 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10291 else
10292 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10293 break;
10294 case SEC_LEVEL_0:
10295 break;
10296 default:
10297 printk(KERN_ERR "Unknow security level %d\n",
10298 priv->ieee->sec.level);
10299 break;
10300 }
10301 } else
10302 /* No hardware encryption */
10303 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10304
Zhu Yie43e3c12006-04-13 17:20:45 +080010305#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010306 if (fc & IEEE80211_STYPE_QOS_DATA)
10307 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010308#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010309
James Ketrenos43f66a62005-03-25 12:31:53 -060010310 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010311 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10312 txb->nr_frags));
10313 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10314 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10315 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10316 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10317 i, le32_to_cpu(tfd->u.data.num_chunks),
10318 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010319 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010320 i, tfd->u.data.num_chunks,
10321 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010322 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 txb->fragments[i]->len - hdr_len);
10324
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010325 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010326 cpu_to_le32(pci_map_single
10327 (priv->pci_dev,
10328 txb->fragments[i]->data + hdr_len,
10329 txb->fragments[i]->len - hdr_len,
10330 PCI_DMA_TODEVICE));
10331 tfd->u.data.chunk_len[i] =
10332 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010333 }
10334
10335 if (i != txb->nr_frags) {
10336 struct sk_buff *skb;
10337 u16 remaining_bytes = 0;
10338 int j;
10339
10340 for (j = i; j < txb->nr_frags; j++)
10341 remaining_bytes += txb->fragments[j]->len - hdr_len;
10342
10343 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10344 remaining_bytes);
10345 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10346 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010347 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010348 for (j = i; j < txb->nr_frags; j++) {
10349 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010350
James Ketrenos43f66a62005-03-25 12:31:53 -060010351 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010352 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010353 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010354 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010355 }
10356 dev_kfree_skb_any(txb->fragments[i]);
10357 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010358 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010359 cpu_to_le32(pci_map_single
10360 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010361 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010362 PCI_DMA_TODEVICE));
10363
Marcin Slusarz5c058632008-02-13 00:06:12 +010010364 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010365 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010366 }
10367
10368 /* kick DMA */
10369 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10370 ipw_write32(priv, q->reg_w, q->first_empty);
10371
Dan Williams943dbef2008-02-14 17:49:41 -050010372 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010373 netif_stop_queue(priv->net_dev);
10374
James Ketrenos227d2dc2005-07-28 16:25:55 -050010375 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010376
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010377 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010378 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010379 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010380 return NETDEV_TX_OK;
10381}
10382
10383static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10384{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010385 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010386#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010387 int tx_id = ipw_get_tx_queue_number(priv, pri);
10388 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10389#else
10390 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010391#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010392
Dan Williams943dbef2008-02-14 17:49:41 -050010393 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010394 return 1;
10395
10396 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010397}
10398
Zhu Yid685b8c2006-04-13 17:20:27 +080010399#ifdef CONFIG_IPW2200_PROMISCUOUS
10400static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010401 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010402{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010403 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010404 struct ieee80211_hdr *hdr;
10405 u8 n;
10406 u16 filter = priv->prom_priv->filter;
10407 int hdr_only = 0;
10408
10409 if (filter & IPW_PROM_NO_TX)
10410 return;
10411
10412 memset(&dummystats, 0, sizeof(dummystats));
10413
10414 /* Filtering of fragment chains is done agains the first fragment */
10415 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010416 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010417 if (filter & IPW_PROM_NO_MGMT)
10418 return;
10419 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10420 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010421 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010422 if (filter & IPW_PROM_NO_CTL)
10423 return;
10424 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10425 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010426 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010427 if (filter & IPW_PROM_NO_DATA)
10428 return;
10429 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10430 hdr_only = 1;
10431 }
10432
10433 for(n=0; n<txb->nr_frags; ++n) {
10434 struct sk_buff *src = txb->fragments[n];
10435 struct sk_buff *dst;
10436 struct ieee80211_radiotap_header *rt_hdr;
10437 int len;
10438
10439 if (hdr_only) {
10440 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010441 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010442 } else
10443 len = src->len;
10444
Johannes Berg007e5dd2008-11-27 23:13:38 +010010445 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10446 if (!dst)
10447 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010448
10449 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10450
10451 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10452 rt_hdr->it_pad = 0;
10453 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010454 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010455
Al Viroe62e1ee2007-12-27 01:36:46 -050010456 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010457 ieee80211chan2mhz(priv->channel));
10458 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010459 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010460 cpu_to_le16(IEEE80211_CHAN_OFDM |
10461 IEEE80211_CHAN_5GHZ);
10462 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010463 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010464 cpu_to_le16(IEEE80211_CHAN_CCK |
10465 IEEE80211_CHAN_2GHZ);
10466 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010467 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010468 cpu_to_le16(IEEE80211_CHAN_OFDM |
10469 IEEE80211_CHAN_2GHZ);
10470
Al Viro743b84d2007-12-27 01:43:16 -050010471 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010472
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010473 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010474
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010475 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010476 dev_kfree_skb_any(dst);
10477 }
10478}
10479#endif
10480
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010481static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10482 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010483{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010484 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010485 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010486 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010487
10488 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010489 spin_lock_irqsave(&priv->lock, flags);
10490
Zhu Yid685b8c2006-04-13 17:20:27 +080010491#ifdef CONFIG_IPW2200_PROMISCUOUS
10492 if (rtap_iface && netif_running(priv->prom_net_dev))
10493 ipw_handle_promiscuous_tx(priv, txb);
10494#endif
10495
James Ketrenos227d2dc2005-07-28 16:25:55 -050010496 ret = ipw_tx_skb(priv, txb, pri);
10497 if (ret == NETDEV_TX_OK)
10498 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010499 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010500
James Ketrenos227d2dc2005-07-28 16:25:55 -050010501 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010502}
10503
James Ketrenos43f66a62005-03-25 12:31:53 -060010504static void ipw_net_set_multicast_list(struct net_device *dev)
10505{
10506
10507}
10508
10509static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10510{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010511 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010512 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010513
James Ketrenos43f66a62005-03-25 12:31:53 -060010514 if (!is_valid_ether_addr(addr->sa_data))
10515 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010516 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010517 priv->config |= CFG_CUSTOM_MAC;
10518 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010519 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10520 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010521 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010522 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010523 return 0;
10524}
10525
Jeff Garzikbf794512005-07-31 13:07:26 -040010526static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010527 struct ethtool_drvinfo *info)
10528{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010529 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010530 char vers[64];
10531 char date[32];
10532 u32 len;
10533
10534 strcpy(info->driver, DRV_NAME);
10535 strcpy(info->version, DRV_VERSION);
10536
10537 len = sizeof(vers);
10538 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10539 len = sizeof(date);
10540 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10541
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010542 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010543 vers, date);
10544 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010545 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010546}
10547
10548static u32 ipw_ethtool_get_link(struct net_device *dev)
10549{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010550 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010551 return (priv->status & STATUS_ASSOCIATED) != 0;
10552}
10553
10554static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10555{
James Ketrenosb095c382005-08-24 22:04:42 -050010556 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010557}
10558
10559static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010560 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010561{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010562 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010563
James Ketrenosb095c382005-08-24 22:04:42 -050010564 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010565 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010566 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010567 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010568 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010569 return 0;
10570}
10571
10572static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010573 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010574{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010575 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010576 int i;
10577
James Ketrenosb095c382005-08-24 22:04:42 -050010578 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010579 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010580 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010581 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010582 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10583 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010584 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010585 return 0;
10586}
10587
Jeff Garzik7282d492006-09-13 14:30:00 -040010588static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010589 .get_link = ipw_ethtool_get_link,
10590 .get_drvinfo = ipw_ethtool_get_drvinfo,
10591 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10592 .get_eeprom = ipw_ethtool_get_eeprom,
10593 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010594};
10595
David Howells7d12e782006-10-05 14:55:46 +010010596static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010597{
10598 struct ipw_priv *priv = data;
10599 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010600
James Ketrenos43f66a62005-03-25 12:31:53 -060010601 if (!priv)
10602 return IRQ_NONE;
10603
Zhu Yi89c318e2006-06-08 22:19:49 -070010604 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010605
10606 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010607 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010608 goto none;
10609 }
10610
James Ketrenosb095c382005-08-24 22:04:42 -050010611 inta = ipw_read32(priv, IPW_INTA_RW);
10612 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010613
James Ketrenos43f66a62005-03-25 12:31:53 -060010614 if (inta == 0xFFFFFFFF) {
10615 /* Hardware disappeared */
10616 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10617 goto none;
10618 }
10619
James Ketrenosb095c382005-08-24 22:04:42 -050010620 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010621 /* Shared interrupt */
10622 goto none;
10623 }
10624
10625 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010626 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010627
James Ketrenos43f66a62005-03-25 12:31:53 -060010628 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010629 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10630 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010631
James Ketrenos43f66a62005-03-25 12:31:53 -060010632 /* Cache INTA value for our tasklet */
10633 priv->isr_inta = inta;
10634
10635 tasklet_schedule(&priv->irq_tasklet);
10636
Zhu Yi89c318e2006-06-08 22:19:49 -070010637 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010638
10639 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010640 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010641 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010642 return IRQ_NONE;
10643}
10644
10645static void ipw_rf_kill(void *adapter)
10646{
10647 struct ipw_priv *priv = adapter;
10648 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010649
James Ketrenos43f66a62005-03-25 12:31:53 -060010650 spin_lock_irqsave(&priv->lock, flags);
10651
10652 if (rf_kill_active(priv)) {
10653 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10654 if (priv->workqueue)
10655 queue_delayed_work(priv->workqueue,
10656 &priv->rf_kill, 2 * HZ);
10657 goto exit_unlock;
10658 }
10659
10660 /* RF Kill is now disabled, so bring the device back up */
10661
10662 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10663 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10664 "device\n");
10665
10666 /* we can not do an adapter restart while inside an irq lock */
10667 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010668 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010669 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10670 "enabled\n");
10671
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010672 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010673 spin_unlock_irqrestore(&priv->lock, flags);
10674}
10675
David Howellsc4028952006-11-22 14:57:56 +000010676static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010677{
David Howellsc4028952006-11-22 14:57:56 +000010678 struct ipw_priv *priv =
10679 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010680 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010681 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010682 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010683}
10684
Adrian Bunka73e22b2006-01-21 01:39:42 +010010685static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010686{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010687 priv->last_seq_num = -1;
10688 priv->last_frag_num = -1;
10689 priv->last_packet_time = 0;
10690
James Ketrenosa613bff2005-08-24 21:43:11 -050010691 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010692
James Ketrenosc848d0a2005-08-24 21:56:24 -050010693 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010694 cancel_delayed_work(&priv->request_direct_scan);
10695 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010696 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010697 ipw_reset_stats(priv);
10698 /* Ensure the rate is updated immediately */
10699 priv->last_rate = ipw_get_current_rate(priv);
10700 ipw_gather_stats(priv);
10701 ipw_led_link_up(priv);
10702 notify_wx_assoc_event(priv);
10703
10704 if (priv->config & CFG_BACKGROUND_SCAN)
10705 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10706}
10707
David Howellsc4028952006-11-22 14:57:56 +000010708static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010709{
David Howellsc4028952006-11-22 14:57:56 +000010710 struct ipw_priv *priv =
10711 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010712 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010713 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010714 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010715}
10716
Adrian Bunka73e22b2006-01-21 01:39:42 +010010717static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010718{
10719 ipw_led_link_down(priv);
10720 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010721 notify_wx_assoc_event(priv);
10722
10723 /* Cancel any queued work ... */
10724 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010725 cancel_delayed_work(&priv->request_direct_scan);
10726 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010727 cancel_delayed_work(&priv->adhoc_check);
10728 cancel_delayed_work(&priv->gather_stats);
10729
10730 ipw_reset_stats(priv);
10731
James Ketrenosafbf30a2005-08-25 00:05:33 -050010732 if (!(priv->status & STATUS_EXIT_PENDING)) {
10733 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010734 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010735 } else
10736 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010737}
10738
David Howellsc4028952006-11-22 14:57:56 +000010739static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010740{
David Howellsc4028952006-11-22 14:57:56 +000010741 struct ipw_priv *priv =
10742 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010743 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010744 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010745 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010746}
10747
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010748static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010749{
10750 int ret = 0;
10751
James Ketrenos43f66a62005-03-25 12:31:53 -060010752 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010753 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010754 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010755
David Howellsc4028952006-11-22 14:57:56 +000010756 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10757 INIT_WORK(&priv->associate, ipw_bg_associate);
10758 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10759 INIT_WORK(&priv->system_config, ipw_system_config);
10760 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10761 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10762 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10763 INIT_WORK(&priv->up, ipw_bg_up);
10764 INIT_WORK(&priv->down, ipw_bg_down);
10765 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010766 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10767 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010768 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010769 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10770 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10771 INIT_WORK(&priv->roam, ipw_bg_roam);
10772 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10773 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10774 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10775 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10776 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10777 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10778 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010779
Zhu Yie43e3c12006-04-13 17:20:45 +080010780#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010781 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010782#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010783
10784 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10785 ipw_irq_tasklet, (unsigned long)priv);
10786
10787 return ret;
10788}
10789
James Ketrenos43f66a62005-03-25 12:31:53 -060010790static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010791 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010792{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010793 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010794 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010795 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010796 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010797 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010798 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010799 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010800 priv->ieee->sec.flags &= ~(1 << i);
10801 else {
10802 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010803 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010804 priv->ieee->sec.flags |= (1 << i);
10805 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010806 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010807 } else if (sec->level != SEC_LEVEL_1)
10808 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 }
10810
James Ketrenosb095c382005-08-24 22:04:42 -050010811 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010812 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010813 priv->ieee->sec.active_key = sec->active_key;
10814 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010815 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010816 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010818 } else
10819 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010820
10821 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010822 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10823 priv->ieee->sec.auth_mode = sec->auth_mode;
10824 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010825 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10826 priv->capability |= CAP_SHARED_KEY;
10827 else
10828 priv->capability &= ~CAP_SHARED_KEY;
10829 priv->status |= STATUS_SECURITY_UPDATED;
10830 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010831
James Ketrenosb095c382005-08-24 22:04:42 -050010832 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10833 priv->ieee->sec.flags |= SEC_ENABLED;
10834 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010835 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010836 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010837 priv->capability |= CAP_PRIVACY_ON;
10838 else
10839 priv->capability &= ~CAP_PRIVACY_ON;
10840 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010841
James Ketrenosafbf30a2005-08-25 00:05:33 -050010842 if (sec->flags & SEC_ENCRYPT)
10843 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010844
James Ketrenosb095c382005-08-24 22:04:42 -050010845 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10846 priv->ieee->sec.level = sec->level;
10847 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010848 priv->status |= STATUS_SECURITY_UPDATED;
10849 }
10850
Zhu Yi1fbfea52005-08-05 17:22:56 +080010851 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10852 ipw_set_hwcrypto_keys(priv);
10853
Jeff Garzikbf794512005-07-31 13:07:26 -040010854 /* To match current functionality of ipw2100 (which works well w/
10855 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010856 * privacy capability changes ... */
10857#if 0
10858 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010859 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010860 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010861 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010862 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010863 IPW_DEBUG_ASSOC("Disassociating due to capability "
10864 "change.\n");
10865 ipw_disassociate(priv);
10866 }
10867#endif
10868}
10869
Jeff Garzikbf794512005-07-31 13:07:26 -040010870static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010871 struct ipw_supported_rates *rates)
10872{
10873 /* TODO: Mask out rates based on priv->rates_mask */
10874
10875 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010876 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010877 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010878 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010879 rates->ieee_mode = IPW_A_MODE;
10880 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010881 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10882 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010883 break;
10884
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010885 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010886 rates->ieee_mode = IPW_G_MODE;
10887 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010888 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10889 LIBIPW_CCK_DEFAULT_RATES_MASK);
10890 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10891 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10892 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010893 }
10894 break;
10895 }
10896
10897 return 0;
10898}
10899
Jeff Garzikbf794512005-07-31 13:07:26 -040010900static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010901{
James Ketrenos43f66a62005-03-25 12:31:53 -060010902 /* This is only called from ipw_up, which resets/reloads the firmware
10903 so, we don't need to first disable the card before we configure
10904 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010905 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010906 goto error;
10907
10908 /* initialize adapter address */
10909 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10910 goto error;
10911
10912 /* set basic system config settings */
10913 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010914
10915 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10916 * Does not support BT priority yet (don't abort or defer our Tx) */
10917 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010918 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010919
10920 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10921 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010922 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010923 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10924 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010925 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010926 }
10927
Zhu Yid685b8c2006-04-13 17:20:27 +080010928#ifdef CONFIG_IPW2200_PROMISCUOUS
10929 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10930 priv->sys_config.accept_all_data_frames = 1;
10931 priv->sys_config.accept_non_directed_frames = 1;
10932 priv->sys_config.accept_all_mgmt_bcpr = 1;
10933 priv->sys_config.accept_all_mgmt_frames = 1;
10934 }
10935#endif
10936
James Ketrenosc848d0a2005-08-24 21:56:24 -050010937 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10938 priv->sys_config.answer_broadcast_ssid_probe = 1;
10939 else
10940 priv->sys_config.answer_broadcast_ssid_probe = 0;
10941
Zhu Yid685b8c2006-04-13 17:20:27 +080010942 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010943 goto error;
10944
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010945 init_supported_rates(priv, &priv->rates);
10946 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010947 goto error;
10948
10949 /* Set request-to-send threshold */
10950 if (priv->rts_threshold) {
10951 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10952 goto error;
10953 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010954#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010955 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10956 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010957#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010958
10959 if (ipw_set_random_seed(priv))
10960 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010961
James Ketrenos43f66a62005-03-25 12:31:53 -060010962 /* final state transition to the RUN state */
10963 if (ipw_send_host_complete(priv))
10964 goto error;
10965
James Ketrenose6666192005-08-12 09:17:04 -050010966 priv->status |= STATUS_INIT;
10967
10968 ipw_led_init(priv);
10969 ipw_led_radio_on(priv);
10970 priv->notif_missed_beacons = 0;
10971
10972 /* Set hardware WEP key if it is configured. */
10973 if ((priv->capability & CAP_PRIVACY_ON) &&
10974 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10975 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10976 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010977
10978 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010979
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010980 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010981 return -EIO;
10982}
10983
James Ketrenos4f36f802005-08-03 20:36:56 -050010984/*
10985 * NOTE:
10986 *
10987 * These tables have been tested in conjunction with the
10988 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10989 *
10990 * Altering this values, using it on other hardware, or in geographies
10991 * not intended for resale of the above mentioned Intel adapters has
10992 * not been tested.
10993 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010994 * Remember to update the table in README.ipw2200 when changing this
10995 * table.
10996 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010997 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010998static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050010999 { /* Restricted */
11000 "---",
11001 .bg_channels = 11,
11002 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11003 {2427, 4}, {2432, 5}, {2437, 6},
11004 {2442, 7}, {2447, 8}, {2452, 9},
11005 {2457, 10}, {2462, 11}},
11006 },
11007
11008 { /* Custom US/Canada */
11009 "ZZF",
11010 .bg_channels = 11,
11011 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11012 {2427, 4}, {2432, 5}, {2437, 6},
11013 {2442, 7}, {2447, 8}, {2452, 9},
11014 {2457, 10}, {2462, 11}},
11015 .a_channels = 8,
11016 .a = {{5180, 36},
11017 {5200, 40},
11018 {5220, 44},
11019 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011020 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11021 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11022 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11023 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011024 },
11025
11026 { /* Rest of World */
11027 "ZZD",
11028 .bg_channels = 13,
11029 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11030 {2427, 4}, {2432, 5}, {2437, 6},
11031 {2442, 7}, {2447, 8}, {2452, 9},
11032 {2457, 10}, {2462, 11}, {2467, 12},
11033 {2472, 13}},
11034 },
11035
11036 { /* Custom USA & Europe & High */
11037 "ZZA",
11038 .bg_channels = 11,
11039 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11040 {2427, 4}, {2432, 5}, {2437, 6},
11041 {2442, 7}, {2447, 8}, {2452, 9},
11042 {2457, 10}, {2462, 11}},
11043 .a_channels = 13,
11044 .a = {{5180, 36},
11045 {5200, 40},
11046 {5220, 44},
11047 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011048 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11049 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11050 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11051 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011052 {5745, 149},
11053 {5765, 153},
11054 {5785, 157},
11055 {5805, 161},
11056 {5825, 165}},
11057 },
11058
11059 { /* Custom NA & Europe */
11060 "ZZB",
11061 .bg_channels = 11,
11062 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11063 {2427, 4}, {2432, 5}, {2437, 6},
11064 {2442, 7}, {2447, 8}, {2452, 9},
11065 {2457, 10}, {2462, 11}},
11066 .a_channels = 13,
11067 .a = {{5180, 36},
11068 {5200, 40},
11069 {5220, 44},
11070 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011071 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11072 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11073 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11074 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11075 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11076 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11077 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11078 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11079 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011080 },
11081
11082 { /* Custom Japan */
11083 "ZZC",
11084 .bg_channels = 11,
11085 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11086 {2427, 4}, {2432, 5}, {2437, 6},
11087 {2442, 7}, {2447, 8}, {2452, 9},
11088 {2457, 10}, {2462, 11}},
11089 .a_channels = 4,
11090 .a = {{5170, 34}, {5190, 38},
11091 {5210, 42}, {5230, 46}},
11092 },
11093
11094 { /* Custom */
11095 "ZZM",
11096 .bg_channels = 11,
11097 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11098 {2427, 4}, {2432, 5}, {2437, 6},
11099 {2442, 7}, {2447, 8}, {2452, 9},
11100 {2457, 10}, {2462, 11}},
11101 },
11102
11103 { /* Europe */
11104 "ZZE",
11105 .bg_channels = 13,
11106 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11107 {2427, 4}, {2432, 5}, {2437, 6},
11108 {2442, 7}, {2447, 8}, {2452, 9},
11109 {2457, 10}, {2462, 11}, {2467, 12},
11110 {2472, 13}},
11111 .a_channels = 19,
11112 .a = {{5180, 36},
11113 {5200, 40},
11114 {5220, 44},
11115 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011116 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11117 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11118 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11119 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11120 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11121 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11122 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11123 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11124 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11125 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11126 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11127 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11128 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11129 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11130 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011131 },
11132
11133 { /* Custom Japan */
11134 "ZZJ",
11135 .bg_channels = 14,
11136 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11137 {2427, 4}, {2432, 5}, {2437, 6},
11138 {2442, 7}, {2447, 8}, {2452, 9},
11139 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011140 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011141 .a_channels = 4,
11142 .a = {{5170, 34}, {5190, 38},
11143 {5210, 42}, {5230, 46}},
11144 },
11145
James Ketrenos03520572005-10-19 16:12:31 -050011146 { /* Rest of World */
11147 "ZZR",
11148 .bg_channels = 14,
11149 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11150 {2427, 4}, {2432, 5}, {2437, 6},
11151 {2442, 7}, {2447, 8}, {2452, 9},
11152 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011153 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11154 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011155 },
11156
James Ketrenos4f36f802005-08-03 20:36:56 -050011157 { /* High Band */
11158 "ZZH",
11159 .bg_channels = 13,
11160 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11161 {2427, 4}, {2432, 5}, {2437, 6},
11162 {2442, 7}, {2447, 8}, {2452, 9},
11163 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011164 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11165 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011166 .a_channels = 4,
11167 .a = {{5745, 149}, {5765, 153},
11168 {5785, 157}, {5805, 161}},
11169 },
11170
11171 { /* Custom Europe */
11172 "ZZG",
11173 .bg_channels = 13,
11174 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11175 {2427, 4}, {2432, 5}, {2437, 6},
11176 {2442, 7}, {2447, 8}, {2452, 9},
11177 {2457, 10}, {2462, 11},
11178 {2467, 12}, {2472, 13}},
11179 .a_channels = 4,
11180 .a = {{5180, 36}, {5200, 40},
11181 {5220, 44}, {5240, 48}},
11182 },
11183
11184 { /* Europe */
11185 "ZZK",
11186 .bg_channels = 13,
11187 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11188 {2427, 4}, {2432, 5}, {2437, 6},
11189 {2442, 7}, {2447, 8}, {2452, 9},
11190 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011191 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11192 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011193 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011194 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11195 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11196 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11197 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11198 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11199 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11200 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11201 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11202 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11203 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11204 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11205 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11206 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11207 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11208 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11209 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11210 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11211 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11212 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11213 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11214 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11215 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11216 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11217 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011218 },
11219
11220 { /* Europe */
11221 "ZZL",
11222 .bg_channels = 11,
11223 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11224 {2427, 4}, {2432, 5}, {2437, 6},
11225 {2442, 7}, {2447, 8}, {2452, 9},
11226 {2457, 10}, {2462, 11}},
11227 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011228 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11229 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11230 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11231 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11232 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11233 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11234 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11235 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11236 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11237 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11238 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11239 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11240 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011241 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011242};
11243
James Ketrenos43f66a62005-03-25 12:31:53 -060011244#define MAX_HW_RESTARTS 5
11245static int ipw_up(struct ipw_priv *priv)
11246{
James Ketrenos4f36f802005-08-03 20:36:56 -050011247 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011248
Dan Williamsc3d72b92009-02-11 13:26:06 -050011249 /* Age scan list entries found before suspend */
11250 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011251 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011252 priv->suspend_time = 0;
11253 }
11254
James Ketrenos43f66a62005-03-25 12:31:53 -060011255 if (priv->status & STATUS_EXIT_PENDING)
11256 return -EIO;
11257
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011258 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011259 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011260 GFP_KERNEL);
11261 if (priv->cmdlog == NULL) {
11262 IPW_ERROR("Error allocating %d command log entries.\n",
11263 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011264 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011265 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011266 priv->cmdlog_len = cmdlog;
11267 }
11268 }
11269
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011270 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011271 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011272 * Also start the clocks. */
11273 rc = ipw_load(priv);
11274 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011275 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011276 return rc;
11277 }
11278
11279 ipw_init_ordinals(priv);
11280 if (!(priv->config & CFG_CUSTOM_MAC))
11281 eeprom_parse_mac(priv, priv->mac_addr);
11282 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011283 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011284
James Ketrenos4f36f802005-08-03 20:36:56 -050011285 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11286 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11287 ipw_geos[j].name, 3))
11288 break;
11289 }
James Ketrenos03520572005-10-19 16:12:31 -050011290 if (j == ARRAY_SIZE(ipw_geos)) {
11291 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11292 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11293 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11294 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011295 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011296 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011297 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011298 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011299 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011300 }
11301
James Ketrenosb095c382005-08-24 22:04:42 -050011302 if (priv->status & STATUS_RF_KILL_SW) {
11303 IPW_WARNING("Radio disabled by module parameter.\n");
11304 return 0;
11305 } else if (rf_kill_active(priv)) {
11306 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11307 "Kill switch must be turned off for "
11308 "wireless networking to work.\n");
11309 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11310 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011311 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011312 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011313
11314 rc = ipw_config(priv);
11315 if (!rc) {
11316 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011317
James Ketrenose6666192005-08-12 09:17:04 -050011318 /* If configure to try and auto-associate, kick
11319 * off a scan. */
David Howellsc4028952006-11-22 14:57:56 +000011320 queue_delayed_work(priv->workqueue,
11321 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011322
James Ketrenos43f66a62005-03-25 12:31:53 -060011323 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011324 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011325
James Ketrenosc848d0a2005-08-24 21:56:24 -050011326 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011327 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11328 i, MAX_HW_RESTARTS);
11329
11330 /* We had an error bringing up the hardware, so take it
11331 * all the way back down so we can try again */
11332 ipw_down(priv);
11333 }
11334
Jeff Garzikbf794512005-07-31 13:07:26 -040011335 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011336 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011337 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011338
James Ketrenos43f66a62005-03-25 12:31:53 -060011339 return -EIO;
11340}
11341
David Howellsc4028952006-11-22 14:57:56 +000011342static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011343{
David Howellsc4028952006-11-22 14:57:56 +000011344 struct ipw_priv *priv =
11345 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011346 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011347 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011348 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011349}
11350
James Ketrenosb095c382005-08-24 22:04:42 -050011351static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011352{
James Ketrenosb095c382005-08-24 22:04:42 -050011353 int i;
11354
11355 if (priv->status & STATUS_SCANNING) {
11356 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11357 ipw_abort_scan(priv);
11358 }
11359
11360 if (priv->status & STATUS_ASSOCIATED) {
11361 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11362 ipw_disassociate(priv);
11363 }
11364
11365 ipw_led_shutdown(priv);
11366
11367 /* Wait up to 1s for status to change to not scanning and not
11368 * associated (disassociation can take a while for a ful 802.11
11369 * exchange */
11370 for (i = 1000; i && (priv->status &
11371 (STATUS_DISASSOCIATING |
11372 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11373 udelay(10);
11374
11375 if (priv->status & (STATUS_DISASSOCIATING |
11376 STATUS_ASSOCIATED | STATUS_SCANNING))
11377 IPW_DEBUG_INFO("Still associated or scanning...\n");
11378 else
11379 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11380
James Ketrenosc848d0a2005-08-24 21:56:24 -050011381 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011382 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011383
11384 priv->status &= ~STATUS_INIT;
11385}
11386
James Ketrenos43f66a62005-03-25 12:31:53 -060011387static void ipw_down(struct ipw_priv *priv)
11388{
James Ketrenosb095c382005-08-24 22:04:42 -050011389 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11390
11391 priv->status |= STATUS_EXIT_PENDING;
11392
11393 if (ipw_is_init(priv))
11394 ipw_deinit(priv);
11395
11396 /* Wipe out the EXIT_PENDING status bit if we are not actually
11397 * exiting the module */
11398 if (!exit_pending)
11399 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011400
11401 /* tell the device to stop sending interrupts */
11402 ipw_disable_interrupts(priv);
11403
11404 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011405 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011406 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011407
11408 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011409
11410 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011411}
11412
David Howellsc4028952006-11-22 14:57:56 +000011413static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011414{
David Howellsc4028952006-11-22 14:57:56 +000011415 struct ipw_priv *priv =
11416 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011417 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011418 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011419 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011420}
11421
11422/* Called by register_netdev() */
11423static int ipw_net_init(struct net_device *dev)
11424{
John W. Linvillea3caa992009-08-25 14:12:25 -040011425 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011426 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011427 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11428 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011429 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011430
James Ketrenosc848d0a2005-08-24 21:56:24 -050011431 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011432 rc = -EIO;
11433 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011434 }
11435
John W. Linvillea3caa992009-08-25 14:12:25 -040011436 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11437
11438 /* fill-out priv->ieee->bg_band */
11439 if (geo->bg_channels) {
11440 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11441
11442 bg_band->band = IEEE80211_BAND_2GHZ;
11443 bg_band->n_channels = geo->bg_channels;
11444 bg_band->channels =
11445 kzalloc(geo->bg_channels *
11446 sizeof(struct ieee80211_channel), GFP_KERNEL);
11447 /* translate geo->bg to bg_band.channels */
11448 for (i = 0; i < geo->bg_channels; i++) {
11449 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11450 bg_band->channels[i].center_freq = geo->bg[i].freq;
11451 bg_band->channels[i].hw_value = geo->bg[i].channel;
11452 bg_band->channels[i].max_power = geo->bg[i].max_power;
11453 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11454 bg_band->channels[i].flags |=
11455 IEEE80211_CHAN_PASSIVE_SCAN;
11456 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11457 bg_band->channels[i].flags |=
11458 IEEE80211_CHAN_NO_IBSS;
11459 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11460 bg_band->channels[i].flags |=
11461 IEEE80211_CHAN_RADAR;
11462 /* No equivalent for LIBIPW_CH_80211H_RULES,
11463 LIBIPW_CH_UNIFORM_SPREADING, or
11464 LIBIPW_CH_B_ONLY... */
11465 }
11466 /* point at bitrate info */
11467 bg_band->bitrates = ipw2200_bg_rates;
11468 bg_band->n_bitrates = ipw2200_num_bg_rates;
11469
11470 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11471 }
11472
11473 /* fill-out priv->ieee->a_band */
11474 if (geo->a_channels) {
11475 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11476
11477 a_band->band = IEEE80211_BAND_5GHZ;
11478 a_band->n_channels = geo->a_channels;
11479 a_band->channels =
11480 kzalloc(geo->a_channels *
11481 sizeof(struct ieee80211_channel), GFP_KERNEL);
11482 /* translate geo->bg to a_band.channels */
11483 for (i = 0; i < geo->a_channels; i++) {
11484 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11485 a_band->channels[i].center_freq = geo->a[i].freq;
11486 a_band->channels[i].hw_value = geo->a[i].channel;
11487 a_band->channels[i].max_power = geo->a[i].max_power;
11488 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11489 a_band->channels[i].flags |=
11490 IEEE80211_CHAN_PASSIVE_SCAN;
11491 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11492 a_band->channels[i].flags |=
11493 IEEE80211_CHAN_NO_IBSS;
11494 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11495 a_band->channels[i].flags |=
11496 IEEE80211_CHAN_RADAR;
11497 /* No equivalent for LIBIPW_CH_80211H_RULES,
11498 LIBIPW_CH_UNIFORM_SPREADING, or
11499 LIBIPW_CH_B_ONLY... */
11500 }
11501 /* point at bitrate info */
11502 a_band->bitrates = ipw2200_a_rates;
11503 a_band->n_bitrates = ipw2200_num_a_rates;
11504
11505 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11506 }
11507
11508 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11509
11510 /* With that information in place, we can now register the wiphy... */
11511 if (wiphy_register(wdev->wiphy)) {
11512 rc = -EIO;
11513 goto out;
11514 }
11515
11516out:
Zhu Yi46441512006-01-24 16:37:59 +080011517 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011518 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011519}
11520
11521/* PCI driver stuff */
11522static struct pci_device_id card_ids[] = {
11523 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11524 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11525 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11526 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11527 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11528 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11529 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11530 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11531 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11532 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11533 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11534 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11535 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11536 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11537 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11538 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11539 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011540 {PCI_VDEVICE(INTEL, 0x104f), 0},
11541 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11542 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11543 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11544 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011545
James Ketrenos43f66a62005-03-25 12:31:53 -060011546 /* required last entry */
11547 {0,}
11548};
11549
11550MODULE_DEVICE_TABLE(pci, card_ids);
11551
11552static struct attribute *ipw_sysfs_entries[] = {
11553 &dev_attr_rf_kill.attr,
11554 &dev_attr_direct_dword.attr,
11555 &dev_attr_indirect_byte.attr,
11556 &dev_attr_indirect_dword.attr,
11557 &dev_attr_mem_gpio_reg.attr,
11558 &dev_attr_command_event_reg.attr,
11559 &dev_attr_nic_type.attr,
11560 &dev_attr_status.attr,
11561 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011562 &dev_attr_error.attr,
11563 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011564 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011565 &dev_attr_eeprom_delay.attr,
11566 &dev_attr_ucode_version.attr,
11567 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011568 &dev_attr_scan_age.attr,
11569 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011570 &dev_attr_speed_scan.attr,
11571 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011572 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011573#ifdef CONFIG_IPW2200_PROMISCUOUS
11574 &dev_attr_rtap_iface.attr,
11575 &dev_attr_rtap_filter.attr,
11576#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011577 NULL
11578};
11579
11580static struct attribute_group ipw_attribute_group = {
11581 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011582 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011583};
11584
Zhu Yid685b8c2006-04-13 17:20:27 +080011585#ifdef CONFIG_IPW2200_PROMISCUOUS
11586static int ipw_prom_open(struct net_device *dev)
11587{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011588 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011589 struct ipw_priv *priv = prom_priv->priv;
11590
11591 IPW_DEBUG_INFO("prom dev->open\n");
11592 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011593
11594 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11595 priv->sys_config.accept_all_data_frames = 1;
11596 priv->sys_config.accept_non_directed_frames = 1;
11597 priv->sys_config.accept_all_mgmt_bcpr = 1;
11598 priv->sys_config.accept_all_mgmt_frames = 1;
11599
11600 ipw_send_system_config(priv);
11601 }
11602
11603 return 0;
11604}
11605
11606static int ipw_prom_stop(struct net_device *dev)
11607{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011608 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011609 struct ipw_priv *priv = prom_priv->priv;
11610
11611 IPW_DEBUG_INFO("prom dev->stop\n");
11612
11613 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11614 priv->sys_config.accept_all_data_frames = 0;
11615 priv->sys_config.accept_non_directed_frames = 0;
11616 priv->sys_config.accept_all_mgmt_bcpr = 0;
11617 priv->sys_config.accept_all_mgmt_frames = 0;
11618
11619 ipw_send_system_config(priv);
11620 }
11621
11622 return 0;
11623}
11624
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011625static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11626 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011627{
11628 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011629 dev_kfree_skb(skb);
11630 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011631}
11632
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011633static const struct net_device_ops ipw_prom_netdev_ops = {
11634 .ndo_open = ipw_prom_open,
11635 .ndo_stop = ipw_prom_stop,
11636 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011637 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011638 .ndo_set_mac_address = eth_mac_addr,
11639 .ndo_validate_addr = eth_validate_addr,
11640};
11641
Zhu Yid685b8c2006-04-13 17:20:27 +080011642static int ipw_prom_alloc(struct ipw_priv *priv)
11643{
11644 int rc = 0;
11645
11646 if (priv->prom_net_dev)
11647 return -EPERM;
11648
John W. Linvillea3caa992009-08-25 14:12:25 -040011649 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011650 if (priv->prom_net_dev == NULL)
11651 return -ENOMEM;
11652
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011653 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011654 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11655 priv->prom_priv->priv = priv;
11656
11657 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011658 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011659
11660 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011661 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011662
11663 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011664 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011665
11666 rc = register_netdev(priv->prom_net_dev);
11667 if (rc) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011668 free_ieee80211(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011669 priv->prom_net_dev = NULL;
11670 return rc;
11671 }
11672
11673 return 0;
11674}
11675
11676static void ipw_prom_free(struct ipw_priv *priv)
11677{
11678 if (!priv->prom_net_dev)
11679 return;
11680
11681 unregister_netdev(priv->prom_net_dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011682 free_ieee80211(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011683
11684 priv->prom_net_dev = NULL;
11685}
11686
11687#endif
11688
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011689static const struct net_device_ops ipw_netdev_ops = {
11690 .ndo_init = ipw_net_init,
11691 .ndo_open = ipw_net_open,
11692 .ndo_stop = ipw_net_stop,
11693 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11694 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011695 .ndo_start_xmit = libipw_xmit,
11696 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011697 .ndo_validate_addr = eth_validate_addr,
11698};
Zhu Yid685b8c2006-04-13 17:20:27 +080011699
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011700static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11701 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011702{
11703 int err = 0;
11704 struct net_device *net_dev;
11705 void __iomem *base;
11706 u32 length, val;
11707 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011708 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011709
John W. Linvillea3caa992009-08-25 14:12:25 -040011710 net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011711 if (net_dev == NULL) {
11712 err = -ENOMEM;
11713 goto out;
11714 }
11715
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011716 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011717 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011718
James Ketrenos43f66a62005-03-25 12:31:53 -060011719 priv->net_dev = net_dev;
11720 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011721 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011722 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011723 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011724 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11725 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011726
Zhu Yi46441512006-01-24 16:37:59 +080011727 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011728 if (pci_enable_device(pdev)) {
11729 err = -ENODEV;
11730 goto out_free_ieee80211;
11731 }
11732
11733 pci_set_master(pdev);
11734
Yang Hongyang284901a2009-04-06 19:01:15 -070011735 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011736 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011737 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011738 if (err) {
11739 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11740 goto out_pci_disable_device;
11741 }
11742
11743 pci_set_drvdata(pdev, priv);
11744
11745 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011746 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011747 goto out_pci_disable_device;
11748
Jeff Garzikbf794512005-07-31 13:07:26 -040011749 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011750 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011751 pci_read_config_dword(pdev, 0x40, &val);
11752 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011753 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011754
James Ketrenos43f66a62005-03-25 12:31:53 -060011755 length = pci_resource_len(pdev, 0);
11756 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011757
Arjan van de Ven275f1652008-10-20 21:42:39 -070011758 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011759 if (!base) {
11760 err = -ENODEV;
11761 goto out_pci_release_regions;
11762 }
11763
11764 priv->hw_base = base;
11765 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11766 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11767
11768 err = ipw_setup_deferred_work(priv);
11769 if (err) {
11770 IPW_ERROR("Unable to setup deferred work\n");
11771 goto out_iounmap;
11772 }
11773
James Ketrenosb095c382005-08-24 22:04:42 -050011774 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011775
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011776 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011777 if (err) {
11778 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11779 goto out_destroy_workqueue;
11780 }
11781
James Ketrenos43f66a62005-03-25 12:31:53 -060011782 SET_NETDEV_DEV(net_dev, &pdev->dev);
11783
Zhu Yi46441512006-01-24 16:37:59 +080011784 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011785
James Ketrenos43f66a62005-03-25 12:31:53 -060011786 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11787 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011788 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011789
Zhu Yie43e3c12006-04-13 17:20:45 +080011790#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011791 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011792 priv->ieee->handle_probe_response = ipw_handle_beacon;
11793 priv->ieee->handle_beacon = ipw_handle_probe_response;
11794 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011795#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011796
James Ketrenosc848d0a2005-08-24 21:56:24 -050011797 priv->ieee->perfect_rssi = -20;
11798 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011799
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011800 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011801 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011802 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011803 net_dev->wireless_handlers = &ipw_wx_handler_def;
11804 net_dev->ethtool_ops = &ipw_ethtool_ops;
11805 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011806 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011807 net_dev->mem_start = pci_resource_start(pdev, 0);
11808 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11809
11810 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11811 if (err) {
11812 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011813 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011814 goto out_release_irq;
11815 }
11816
Zhu Yi46441512006-01-24 16:37:59 +080011817 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011818 err = register_netdev(net_dev);
11819 if (err) {
11820 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011821 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011822 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011823
Zhu Yid685b8c2006-04-13 17:20:27 +080011824#ifdef CONFIG_IPW2200_PROMISCUOUS
11825 if (rtap_iface) {
11826 err = ipw_prom_alloc(priv);
11827 if (err) {
11828 IPW_ERROR("Failed to register promiscuous network "
11829 "device (error %d).\n", err);
11830 unregister_netdev(priv->net_dev);
11831 goto out_remove_sysfs;
11832 }
11833 }
11834#endif
11835
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011836 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11837 "channels, %d 802.11a channels)\n",
11838 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11839 priv->ieee->geo.a_channels);
11840
James Ketrenos43f66a62005-03-25 12:31:53 -060011841 return 0;
11842
James Ketrenosa613bff2005-08-24 21:43:11 -050011843 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011844 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011845 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011846 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011847 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011848 destroy_workqueue(priv->workqueue);
11849 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011850 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011851 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011852 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011853 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011854 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011855 pci_disable_device(pdev);
11856 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011857 out_free_ieee80211:
John W. Linvillea3caa992009-08-25 14:12:25 -040011858 free_ieee80211(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011859 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011860 return err;
11861}
11862
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011863static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011864{
11865 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011866 struct list_head *p, *q;
11867 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011868
James Ketrenos43f66a62005-03-25 12:31:53 -060011869 if (!priv)
11870 return;
11871
Zhu Yi46441512006-01-24 16:37:59 +080011872 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011873
James Ketrenosafbf30a2005-08-25 00:05:33 -050011874 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011875 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011876 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11877
Zhu Yi46441512006-01-24 16:37:59 +080011878 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011879
11880 unregister_netdev(priv->net_dev);
11881
11882 if (priv->rxq) {
11883 ipw_rx_queue_free(priv, priv->rxq);
11884 priv->rxq = NULL;
11885 }
11886 ipw_tx_queue_free(priv);
11887
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011888 if (priv->cmdlog) {
11889 kfree(priv->cmdlog);
11890 priv->cmdlog = NULL;
11891 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011892 /* ipw_down will ensure that there is no more pending work
11893 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011894 cancel_delayed_work(&priv->adhoc_check);
11895 cancel_delayed_work(&priv->gather_stats);
11896 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011897 cancel_delayed_work(&priv->request_direct_scan);
11898 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011899 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011900 cancel_delayed_work(&priv->rf_kill);
11901 cancel_delayed_work(&priv->scan_check);
11902 destroy_workqueue(priv->workqueue);
11903 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011904
James Ketrenosafbf30a2005-08-25 00:05:33 -050011905 /* Free MAC hash list for ADHOC */
11906 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11907 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011908 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011909 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011910 }
11911 }
11912
Jesper Juhl8f760782006-06-27 02:55:06 -070011913 kfree(priv->error);
11914 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011915
Zhu Yid685b8c2006-04-13 17:20:27 +080011916#ifdef CONFIG_IPW2200_PROMISCUOUS
11917 ipw_prom_free(priv);
11918#endif
11919
James Ketrenos43f66a62005-03-25 12:31:53 -060011920 free_irq(pdev->irq, priv);
11921 iounmap(priv->hw_base);
11922 pci_release_regions(pdev);
11923 pci_disable_device(pdev);
11924 pci_set_drvdata(pdev, NULL);
John W. Linvillea3caa992009-08-25 14:12:25 -040011925 /* wiphy_unregister needs to be here, before free_ieee80211 */
11926 wiphy_unregister(priv->ieee->wdev.wiphy);
11927 kfree(priv->ieee->a_band.channels);
11928 kfree(priv->ieee->bg_band.channels);
11929 free_ieee80211(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011930 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011931}
11932
James Ketrenos43f66a62005-03-25 12:31:53 -060011933#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011934static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011935{
11936 struct ipw_priv *priv = pci_get_drvdata(pdev);
11937 struct net_device *dev = priv->net_dev;
11938
11939 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11940
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011941 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011942 ipw_down(priv);
11943
11944 /* Remove the PRESENT state of the device */
11945 netif_device_detach(dev);
11946
James Ketrenos43f66a62005-03-25 12:31:53 -060011947 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011948 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011949 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011950
Dan Williamsc3d72b92009-02-11 13:26:06 -050011951 priv->suspend_at = get_seconds();
11952
James Ketrenos43f66a62005-03-25 12:31:53 -060011953 return 0;
11954}
11955
11956static int ipw_pci_resume(struct pci_dev *pdev)
11957{
11958 struct ipw_priv *priv = pci_get_drvdata(pdev);
11959 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011960 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011961 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011962
James Ketrenos43f66a62005-03-25 12:31:53 -060011963 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11964
James Ketrenosea2b26e2005-08-24 21:25:16 -050011965 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011966 err = pci_enable_device(pdev);
11967 if (err) {
11968 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11969 dev->name);
11970 return err;
11971 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011972 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011973
James Ketrenos43f66a62005-03-25 12:31:53 -060011974 /*
11975 * Suspend/Resume resets the PCI configuration space, so we have to
11976 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11977 * from interfering with C3 CPU state. pci_restore_state won't help
11978 * here since it only restores the first 64 bytes pci config header.
11979 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011980 pci_read_config_dword(pdev, 0x40, &val);
11981 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011982 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11983
11984 /* Set the device back into the PRESENT state; this will also wake
11985 * the queue of needed */
11986 netif_device_attach(dev);
11987
Dan Williamsc3d72b92009-02-11 13:26:06 -050011988 priv->suspend_time = get_seconds() - priv->suspend_at;
11989
James Ketrenos43f66a62005-03-25 12:31:53 -060011990 /* Bring the device back up */
11991 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011992
James Ketrenos43f66a62005-03-25 12:31:53 -060011993 return 0;
11994}
11995#endif
11996
Zhu Yic8c22c92006-08-21 11:38:39 +080011997static void ipw_pci_shutdown(struct pci_dev *pdev)
11998{
11999 struct ipw_priv *priv = pci_get_drvdata(pdev);
12000
12001 /* Take down the device; powers it off, etc. */
12002 ipw_down(priv);
12003
12004 pci_disable_device(pdev);
12005}
12006
James Ketrenos43f66a62005-03-25 12:31:53 -060012007/* driver initialization stuff */
12008static struct pci_driver ipw_driver = {
12009 .name = DRV_NAME,
12010 .id_table = card_ids,
12011 .probe = ipw_pci_probe,
12012 .remove = __devexit_p(ipw_pci_remove),
12013#ifdef CONFIG_PM
12014 .suspend = ipw_pci_suspend,
12015 .resume = ipw_pci_resume,
12016#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012017 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012018};
12019
12020static int __init ipw_init(void)
12021{
12022 int ret;
12023
12024 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12025 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12026
Jeff Garzik29917622006-08-19 17:48:59 -040012027 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012028 if (ret) {
12029 IPW_ERROR("Unable to initialize PCI module\n");
12030 return ret;
12031 }
12032
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012033 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012034 if (ret) {
12035 IPW_ERROR("Unable to create driver sysfs file\n");
12036 pci_unregister_driver(&ipw_driver);
12037 return ret;
12038 }
12039
12040 return ret;
12041}
12042
12043static void __exit ipw_exit(void)
12044{
12045 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12046 pci_unregister_driver(&ipw_driver);
12047}
12048
12049module_param(disable, int, 0444);
12050MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12051
12052module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012053MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012054
12055module_param(auto_create, int, 0444);
12056MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12057
Reinette Chatre21f8a732009-08-18 10:25:05 -070012058module_param_named(led, led_support, int, 0444);
Niels de Vos61a2d072008-07-31 00:07:23 -070012059MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012060
James Ketrenos43f66a62005-03-25 12:31:53 -060012061module_param(debug, int, 0444);
12062MODULE_PARM_DESC(debug, "debug output mask");
12063
Reinette Chatre21f8a732009-08-18 10:25:05 -070012064module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012065MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012066
Zhu Yid685b8c2006-04-13 17:20:27 +080012067#ifdef CONFIG_IPW2200_PROMISCUOUS
12068module_param(rtap_iface, int, 0444);
12069MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12070#endif
12071
Zhu Yie43e3c12006-04-13 17:20:45 +080012072#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012073module_param(qos_enable, int, 0444);
12074MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012075
James Ketrenosb095c382005-08-24 22:04:42 -050012076module_param(qos_burst_enable, int, 0444);
12077MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12078
12079module_param(qos_no_ack_mask, int, 0444);
12080MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12081
12082module_param(burst_duration_CCK, int, 0444);
12083MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12084
12085module_param(burst_duration_OFDM, int, 0444);
12086MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012087#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012088
12089#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012090module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012091MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12092#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012093module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012094MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12095#endif
12096
Zhu Yi810dabd2006-01-24 16:36:59 +080012097module_param(bt_coexist, int, 0444);
12098MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12099
James Ketrenosb095c382005-08-24 22:04:42 -050012100module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012101MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012102
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012103module_param(cmdlog, int, 0444);
12104MODULE_PARM_DESC(cmdlog,
12105 "allocate a ring buffer for logging firmware commands");
12106
Zhu Yi4bfdb912006-01-24 16:37:16 +080012107module_param(roaming, int, 0444);
12108MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12109
Zhu Yid2b83e12006-04-13 17:19:36 +080012110module_param(antenna, int, 0444);
12111MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12112
James Ketrenos43f66a62005-03-25 12:31:53 -060012113module_exit(ipw_exit);
12114module_init(ipw_init);