blob: ae438ed80c2fa73dcafc17577c54194f6cc054fb [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
Reinette Chatrec1eb2c82009-08-21 13:34:26 -070028 Intel Linux Wireless <ilw@linux.intel.com>
James Ketrenos43f66a62005-03-25 12:31:53 -060029 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040033#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035#include "ipw2200.h"
36
Zhu Yiae4af612006-04-13 17:20:34 +080037
38#ifndef KBUILD_EXTMOD
39#define VK "k"
40#else
41#define VK
42#endif
43
44#ifdef CONFIG_IPW2200_DEBUG
45#define VD "d"
46#else
47#define VD
48#endif
49
50#ifdef CONFIG_IPW2200_MONITOR
51#define VM "m"
52#else
53#define VM
54#endif
55
56#ifdef CONFIG_IPW2200_PROMISCUOUS
57#define VP "p"
58#else
59#define VP
60#endif
61
Zhu Yi459d4082006-04-13 17:21:00 +080062#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080063#define VR "r"
64#else
65#define VR
66#endif
67
68#ifdef CONFIG_IPW2200_QOS
69#define VQ "q"
70#else
71#define VQ
72#endif
73
Zhu Yiee2c4ad2007-07-12 16:09:47 +080074#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060075#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080076#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060077#define DRV_VERSION IPW2200_VERSION
78
James Ketrenosb095c382005-08-24 22:04:42 -050079#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
80
James Ketrenos43f66a62005-03-25 12:31:53 -060081MODULE_DESCRIPTION(DRV_DESCRIPTION);
82MODULE_VERSION(DRV_VERSION);
83MODULE_AUTHOR(DRV_COPYRIGHT);
84MODULE_LICENSE("GPL");
Ben Hutchings873395a2009-11-07 21:59:10 +000085MODULE_FIRMWARE("ipw2200-ibss.fw");
86#ifdef CONFIG_IPW2200_MONITOR
87MODULE_FIRMWARE("ipw2200-sniffer.fw");
88#endif
89MODULE_FIRMWARE("ipw2200-bss.fw");
James Ketrenos43f66a62005-03-25 12:31:53 -060090
James Ketrenosf6c5cb72005-08-25 00:39:09 -050091static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060092static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070093static int default_channel = 0;
94static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060095
96static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060097static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060098static int auto_create = 1;
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000099static int led_support = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600100static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +0800101static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +0800102static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +0800103static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600104static const char ipw_modes[] = {
105 'a', 'b', 'g', '?'
106};
Zhu Yid2b83e12006-04-13 17:19:36 +0800107static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600108
Zhu Yid685b8c2006-04-13 17:20:27 +0800109#ifdef CONFIG_IPW2200_PROMISCUOUS
110static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
111#endif
112
John W. Linvillea3caa992009-08-25 14:12:25 -0400113static struct ieee80211_rate ipw2200_rates[] = {
114 { .bitrate = 10 },
115 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
116 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
117 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
118 { .bitrate = 60 },
119 { .bitrate = 90 },
120 { .bitrate = 120 },
121 { .bitrate = 180 },
122 { .bitrate = 240 },
123 { .bitrate = 360 },
124 { .bitrate = 480 },
125 { .bitrate = 540 }
126};
127
128#define ipw2200_a_rates (ipw2200_rates + 4)
129#define ipw2200_num_a_rates 8
130#define ipw2200_bg_rates (ipw2200_rates + 0)
131#define ipw2200_num_bg_rates 12
Zhu Yid685b8c2006-04-13 17:20:27 +0800132
Zhu Yie43e3c12006-04-13 17:20:45 +0800133#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500134static int qos_enable = 0;
135static int qos_burst_enable = 0;
136static int qos_no_ack_mask = 0;
137static int burst_duration_CCK = 0;
138static int burst_duration_OFDM = 0;
139
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400140static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500141 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
142 QOS_TX3_CW_MIN_OFDM},
143 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
144 QOS_TX3_CW_MAX_OFDM},
145 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
146 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
147 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
148 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
149};
150
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400151static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500152 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
153 QOS_TX3_CW_MIN_CCK},
154 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
155 QOS_TX3_CW_MAX_CCK},
156 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
157 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
158 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
159 QOS_TX3_TXOP_LIMIT_CCK}
160};
161
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400162static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500163 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
164 DEF_TX3_CW_MIN_OFDM},
165 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
166 DEF_TX3_CW_MAX_OFDM},
167 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
168 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
169 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
170 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
171};
172
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400173static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500174 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
175 DEF_TX3_CW_MIN_CCK},
176 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
177 DEF_TX3_CW_MAX_CCK},
178 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
179 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
180 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
181 DEF_TX3_TXOP_LIMIT_CCK}
182};
183
184static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
185
186static int from_priority_to_tx_queue[] = {
187 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
188 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
189};
190
191static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
192
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400193static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500194 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400195static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500196 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800197#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500198
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000199static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500200static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600201static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400202static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600203 struct clx2_tx_queue *txq, int qindex);
204static int ipw_queue_reset(struct ipw_priv *priv);
205
206static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
207 int len, int sync);
208
209static void ipw_tx_queue_free(struct ipw_priv *);
210
211static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
212static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
213static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600214static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000215static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600216static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000217static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600218static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400219static int init_supported_rates(struct ipw_priv *priv,
220 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500221static void ipw_set_hwcrypto_keys(struct ipw_priv *);
222static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600223
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500224static int snprint_line(char *buf, size_t count,
225 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600226{
227 int out, i, j, l;
228 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400229
James Ketrenos43f66a62005-03-25 12:31:53 -0600230 out = snprintf(buf, count, "%08X", ofs);
231
232 for (l = 0, i = 0; i < 2; i++) {
233 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400234 for (j = 0; j < 8 && l < len; j++, l++)
235 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600236 data[(i * 8 + j)]);
237 for (; j < 8; j++)
238 out += snprintf(buf + out, count - out, " ");
239 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400240
James Ketrenos43f66a62005-03-25 12:31:53 -0600241 out += snprintf(buf + out, count - out, " ");
242 for (l = 0, i = 0; i < 2; i++) {
243 out += snprintf(buf + out, count - out, " ");
244 for (j = 0; j < 8 && l < len; j++, l++) {
245 c = data[(i * 8 + j)];
246 if (!isascii(c) || !isprint(c))
247 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400248
James Ketrenos43f66a62005-03-25 12:31:53 -0600249 out += snprintf(buf + out, count - out, "%c", c);
250 }
251
252 for (; j < 8; j++)
253 out += snprintf(buf + out, count - out, " ");
254 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400255
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500256 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600257}
258
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400259static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600260{
261 char line[81];
262 u32 ofs = 0;
263 if (!(ipw_debug_level & level))
264 return;
265
266 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500267 snprint_line(line, sizeof(line), &data[ofs],
268 min(len, 16U), ofs);
269 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600270 ofs += 16;
271 len -= min(len, 16U);
272 }
273}
274
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500275static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
276{
277 size_t out = size;
278 u32 ofs = 0;
279 int total = 0;
280
281 while (size && len) {
282 out = snprint_line(output, size, &data[ofs],
283 min_t(size_t, len, 16U), ofs);
284
285 ofs += 16;
286 output += out;
287 size -= out;
288 len -= min_t(size_t, len, 16U);
289 total += out;
290 }
291 return total;
292}
293
Zhu Yic8fe6672006-01-24 16:36:36 +0800294/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600295static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
296#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
297
Zhu Yic8fe6672006-01-24 16:36:36 +0800298/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600299static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
300#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
301
Zhu Yic8fe6672006-01-24 16:36:36 +0800302/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600303static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
304static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
305{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400306 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
307 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600308 _ipw_write_reg8(a, b, c);
309}
310
Zhu Yic8fe6672006-01-24 16:36:36 +0800311/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600312static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
313static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
314{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
316 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600317 _ipw_write_reg16(a, b, c);
318}
319
Zhu Yic8fe6672006-01-24 16:36:36 +0800320/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600321static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
322static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
323{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400324 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
325 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 _ipw_write_reg32(a, b, c);
327}
328
Zhu Yic8fe6672006-01-24 16:36:36 +0800329/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100330static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
331 u8 val)
332{
333 writeb(val, ipw->hw_base + ofs);
334}
Zhu Yic8fe6672006-01-24 16:36:36 +0800335
336/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200337#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100338 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
339 __LINE__, (u32)(ofs), (u32)(val)); \
340 _ipw_write8(ipw, ofs, val); \
341} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600342
Zhu Yic8fe6672006-01-24 16:36:36 +0800343/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100344static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
345 u16 val)
346{
347 writew(val, ipw->hw_base + ofs);
348}
Zhu Yic8fe6672006-01-24 16:36:36 +0800349
350/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100351#define ipw_write16(ipw, ofs, val) do { \
352 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
353 __LINE__, (u32)(ofs), (u32)(val)); \
354 _ipw_write16(ipw, ofs, val); \
355} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600356
Zhu Yic8fe6672006-01-24 16:36:36 +0800357/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100358static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
359 u32 val)
360{
361 writel(val, ipw->hw_base + ofs);
362}
Zhu Yic8fe6672006-01-24 16:36:36 +0800363
364/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100365#define ipw_write32(ipw, ofs, val) do { \
366 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
367 __LINE__, (u32)(ofs), (u32)(val)); \
368 _ipw_write32(ipw, ofs, val); \
369} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600370
Zhu Yic8fe6672006-01-24 16:36:36 +0800371/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100372static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400373{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100374 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600375}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400376
Zhu Yic8fe6672006-01-24 16:36:36 +0800377/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100378#define ipw_read8(ipw, ofs) ({ \
379 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
380 (u32)(ofs)); \
381 _ipw_read8(ipw, ofs); \
382})
James Ketrenos43f66a62005-03-25 12:31:53 -0600383
Zhu Yic8fe6672006-01-24 16:36:36 +0800384/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100385static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400386{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100387 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600388}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400389
Zhu Yic8fe6672006-01-24 16:36:36 +0800390/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100391#define ipw_read16(ipw, ofs) ({ \
392 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
393 (u32)(ofs)); \
394 _ipw_read16(ipw, ofs); \
395})
James Ketrenos43f66a62005-03-25 12:31:53 -0600396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100398static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400399{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100400 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600401}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400402
Zhu Yic8fe6672006-01-24 16:36:36 +0800403/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100404#define ipw_read32(ipw, ofs) ({ \
405 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
406 (u32)(ofs)); \
407 _ipw_read32(ipw, ofs); \
408})
James Ketrenos43f66a62005-03-25 12:31:53 -0600409
410static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800411/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100412#define ipw_read_indirect(a, b, c, d) ({ \
413 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
414 __LINE__, (u32)(b), (u32)(d)); \
415 _ipw_read_indirect(a, b, c, d); \
416})
James Ketrenos43f66a62005-03-25 12:31:53 -0600417
Zhu Yic8fe6672006-01-24 16:36:36 +0800418/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400419static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
420 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100421#define ipw_write_indirect(a, b, c, d) do { \
422 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
423 __LINE__, (u32)(b), (u32)(d)); \
424 _ipw_write_indirect(a, b, c, d); \
425} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600426
Zhu Yic8fe6672006-01-24 16:36:36 +0800427/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400428static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600429{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400430 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500431 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
432 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600433}
434
Zhu Yic8fe6672006-01-24 16:36:36 +0800435/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600436static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
437{
Zhu Yi2638bc32006-01-24 16:37:52 +0800438 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800439 u32 dif_len = reg - aligned_addr;
440
James Ketrenos43f66a62005-03-25 12:31:53 -0600441 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800442 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
443 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600444}
445
Zhu Yic8fe6672006-01-24 16:36:36 +0800446/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400447static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600448{
Zhu Yi2638bc32006-01-24 16:37:52 +0800449 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800450 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
451
James Ketrenos43f66a62005-03-25 12:31:53 -0600452 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800453 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
454 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600455}
456
Zhu Yic8fe6672006-01-24 16:36:36 +0800457/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600458static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
459{
460 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500461 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100462 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500463 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400464 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600465}
466
Zhu Yic8fe6672006-01-24 16:36:36 +0800467/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600468static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
469{
470 u32 value;
471
472 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
473
James Ketrenosb095c382005-08-24 22:04:42 -0500474 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
475 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100476 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600477 return value;
478}
479
Zhu Yic8fe6672006-01-24 16:36:36 +0800480/* General purpose, no alignment requirement, iterative (multi-byte) read, */
481/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600482static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
483 int num)
484{
Zhu Yi2638bc32006-01-24 16:37:52 +0800485 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400488
James Ketrenos43f66a62005-03-25 12:31:53 -0600489 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
490
James Ketrenosea2b26e2005-08-24 21:25:16 -0500491 if (num <= 0) {
492 return;
493 }
494
Zhu Yic8fe6672006-01-24 16:36:36 +0800495 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600496 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500497 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600498 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500499 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500500 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600501 aligned_addr += 4;
502 }
503
Zhu Yic8fe6672006-01-24 16:36:36 +0800504 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500505 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500506 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500507 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400508
Zhu Yic8fe6672006-01-24 16:36:36 +0800509 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500510 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500511 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500512 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500513 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500514 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600515}
516
Zhu Yic8fe6672006-01-24 16:36:36 +0800517/* General purpose, no alignment requirement, iterative (multi-byte) write, */
518/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400519static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600520 int num)
521{
Zhu Yi2638bc32006-01-24 16:37:52 +0800522 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600523 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400525
James Ketrenos43f66a62005-03-25 12:31:53 -0600526 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400527
James Ketrenosea2b26e2005-08-24 21:25:16 -0500528 if (num <= 0) {
529 return;
530 }
531
Zhu Yic8fe6672006-01-24 16:36:36 +0800532 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600533 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500534 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800535 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500536 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500537 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600538 aligned_addr += 4;
539 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400540
Zhu Yic8fe6672006-01-24 16:36:36 +0800541 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500542 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500543 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500544 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400545
Zhu Yic8fe6672006-01-24 16:36:36 +0800546 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500547 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500548 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500549 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500550 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500551 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600552}
553
Zhu Yic8fe6672006-01-24 16:36:36 +0800554/* General purpose, no alignment requirement, iterative (multi-byte) write, */
555/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400556static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600557 int num)
558{
559 memcpy_toio((priv->hw_base + addr), buf, num);
560}
561
Zhu Yic8fe6672006-01-24 16:36:36 +0800562/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600563static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
564{
565 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
566}
567
Zhu Yic8fe6672006-01-24 16:36:36 +0800568/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600569static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
570{
571 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
572}
573
Zhu Yi89c318e2006-06-08 22:19:49 -0700574static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600575{
576 if (priv->status & STATUS_INT_ENABLED)
577 return;
578 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500579 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600580}
581
Zhu Yi89c318e2006-06-08 22:19:49 -0700582static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600583{
584 if (!(priv->status & STATUS_INT_ENABLED))
585 return;
586 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500587 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600588}
589
Zhu Yi89c318e2006-06-08 22:19:49 -0700590static inline void ipw_enable_interrupts(struct ipw_priv *priv)
591{
592 unsigned long flags;
593
594 spin_lock_irqsave(&priv->irq_lock, flags);
595 __ipw_enable_interrupts(priv);
596 spin_unlock_irqrestore(&priv->irq_lock, flags);
597}
598
599static inline void ipw_disable_interrupts(struct ipw_priv *priv)
600{
601 unsigned long flags;
602
603 spin_lock_irqsave(&priv->irq_lock, flags);
604 __ipw_disable_interrupts(priv);
605 spin_unlock_irqrestore(&priv->irq_lock, flags);
606}
607
James Ketrenos43f66a62005-03-25 12:31:53 -0600608static char *ipw_error_desc(u32 val)
609{
610 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400611 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600612 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400613 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600614 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400615 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600616 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400617 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400619 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500620 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400621 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500622 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400623 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500624 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400625 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500626 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400627 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500628 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400629 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500630 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400631 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500632 return "DMA_STATUS";
633 case IPW_FW_ERROR_DINO_ERROR:
634 return "DINO_ERROR";
635 case IPW_FW_ERROR_EEPROM_ERROR:
636 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400637 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500638 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400639 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500640 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400641 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500642 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600643 }
644}
645
James Ketrenosb39860c2005-08-12 09:36:32 -0500646static void ipw_dump_error_log(struct ipw_priv *priv,
647 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600648{
James Ketrenosb39860c2005-08-12 09:36:32 -0500649 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600650
James Ketrenosb39860c2005-08-12 09:36:32 -0500651 if (!error) {
652 IPW_ERROR("Error allocating and capturing error log. "
653 "Nothing to dump.\n");
654 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600655 }
656
James Ketrenosb39860c2005-08-12 09:36:32 -0500657 IPW_ERROR("Start IPW Error Log Dump:\n");
658 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
659 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600660
James Ketrenosb39860c2005-08-12 09:36:32 -0500661 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400662 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500663 ipw_error_desc(error->elem[i].desc),
664 error->elem[i].time,
665 error->elem[i].blink1,
666 error->elem[i].blink2,
667 error->elem[i].link1,
668 error->elem[i].link2, error->elem[i].data);
669 for (i = 0; i < error->log_len; i++)
670 IPW_ERROR("%i\t0x%08x\t%i\n",
671 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500672 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600673}
James Ketrenos43f66a62005-03-25 12:31:53 -0600674
James Ketrenosc848d0a2005-08-24 21:56:24 -0500675static inline int ipw_is_init(struct ipw_priv *priv)
676{
677 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600678}
679
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400680static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600681{
682 u32 addr, field_info, field_len, field_count, total_len;
683
684 IPW_DEBUG_ORD("ordinal = %i\n", ord);
685
686 if (!priv || !val || !len) {
687 IPW_DEBUG_ORD("Invalid argument\n");
688 return -EINVAL;
689 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400690
James Ketrenos43f66a62005-03-25 12:31:53 -0600691 /* verify device ordinal tables have been initialized */
692 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
693 IPW_DEBUG_ORD("Access ordinals before initialization\n");
694 return -EINVAL;
695 }
696
697 switch (IPW_ORD_TABLE_ID_MASK & ord) {
698 case IPW_ORD_TABLE_0_MASK:
699 /*
700 * TABLE 0: Direct access to a table of 32 bit values
701 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400702 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600703 * read from the table
704 */
705
706 /* remove the table id from the ordinal */
707 ord &= IPW_ORD_TABLE_VALUE_MASK;
708
709 /* boundary check */
710 if (ord > priv->table0_len) {
711 IPW_DEBUG_ORD("ordinal value (%i) longer then "
712 "max (%i)\n", ord, priv->table0_len);
713 return -EINVAL;
714 }
715
716 /* verify we have enough room to store the value */
717 if (*len < sizeof(u32)) {
718 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200719 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600720 return -EINVAL;
721 }
722
723 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400724 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600725
726 *len = sizeof(u32);
727 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400728 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600729 break;
730
731 case IPW_ORD_TABLE_1_MASK:
732 /*
733 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400734 *
735 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600736 * representing starting addr for the data (which is
737 * also a u32)
738 */
739
740 /* remove the table id from the ordinal */
741 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400742
James Ketrenos43f66a62005-03-25 12:31:53 -0600743 /* boundary check */
744 if (ord > priv->table1_len) {
745 IPW_DEBUG_ORD("ordinal value too long\n");
746 return -EINVAL;
747 }
748
749 /* verify we have enough room to store the value */
750 if (*len < sizeof(u32)) {
751 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200752 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600753 return -EINVAL;
754 }
755
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400756 *((u32 *) val) =
757 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600758 *len = sizeof(u32);
759 break;
760
761 case IPW_ORD_TABLE_2_MASK:
762 /*
763 * TABLE 2: Indirect access to a table of variable sized values
764 *
765 * This table consist of six values, each containing
766 * - dword containing the starting offset of the data
767 * - dword containing the lengh in the first 16bits
768 * and the count in the second 16bits
769 */
770
771 /* remove the table id from the ordinal */
772 ord &= IPW_ORD_TABLE_VALUE_MASK;
773
774 /* boundary check */
775 if (ord > priv->table2_len) {
776 IPW_DEBUG_ORD("ordinal value too long\n");
777 return -EINVAL;
778 }
779
780 /* get the address of statistic */
781 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400782
783 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600784 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400785 field_info =
786 ipw_read_reg32(priv,
787 priv->table2_addr + (ord << 3) +
788 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400789
James Ketrenos43f66a62005-03-25 12:31:53 -0600790 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400791 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400792
James Ketrenos43f66a62005-03-25 12:31:53 -0600793 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400794 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400795
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200796 /* abort if not enough memory */
James Ketrenos43f66a62005-03-25 12:31:53 -0600797 total_len = field_len * field_count;
798 if (total_len > *len) {
799 *len = total_len;
800 return -EINVAL;
801 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400802
James Ketrenos43f66a62005-03-25 12:31:53 -0600803 *len = total_len;
804 if (!total_len)
805 return 0;
806
807 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400808 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600809 addr, total_len, field_info);
810 ipw_read_indirect(priv, addr, val, total_len);
811 break;
812
813 default:
814 IPW_DEBUG_ORD("Invalid ordinal!\n");
815 return -EINVAL;
816
817 }
818
James Ketrenos43f66a62005-03-25 12:31:53 -0600819 return 0;
820}
821
822static void ipw_init_ordinals(struct ipw_priv *priv)
823{
824 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400825 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600826
827 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
828 priv->table0_addr, priv->table0_len);
829
830 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
831 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
832
833 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
834 priv->table1_addr, priv->table1_len);
835
836 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
837 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400838 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600839
840 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
841 priv->table2_addr, priv->table2_len);
842
843}
844
Adrian Bunka73e22b2006-01-21 01:39:42 +0100845static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500846{
James Ketrenosb095c382005-08-24 22:04:42 -0500847 reg &= ~IPW_START_STANDBY;
848 if (reg & IPW_GATE_ODMA)
849 reg &= ~IPW_GATE_ODMA;
850 if (reg & IPW_GATE_IDMA)
851 reg &= ~IPW_GATE_IDMA;
852 if (reg & IPW_GATE_ADMA)
853 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500854 return reg;
855}
856
857/*
858 * LED behavior:
859 * - On radio ON, turn on any LEDs that require to be on during start
860 * - On initialization, start unassociated blink
861 * - On association, disable unassociated blink
862 * - On disassociation, start unassociated blink
863 * - On radio OFF, turn off any LEDs started during radio on
864 *
865 */
Zhu Yiede61112006-01-24 16:37:10 +0800866#define LD_TIME_LINK_ON msecs_to_jiffies(300)
867#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
868#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500869
Adrian Bunka73e22b2006-01-21 01:39:42 +0100870static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500871{
872 unsigned long flags;
873 u32 led;
874
875 /* If configured to not use LEDs, or nic_type is 1,
876 * then we don't toggle a LINK led */
877 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
878 return;
879
880 spin_lock_irqsave(&priv->lock, flags);
881
882 if (!(priv->status & STATUS_RF_KILL_MASK) &&
883 !(priv->status & STATUS_LED_LINK_ON)) {
884 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500885 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500886 led |= priv->led_association_on;
887
888 led = ipw_register_toggle(led);
889
890 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500891 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500892
893 priv->status |= STATUS_LED_LINK_ON;
894
895 /* If we aren't associated, schedule turning the LED off */
896 if (!(priv->status & STATUS_ASSOCIATED))
897 queue_delayed_work(priv->workqueue,
898 &priv->led_link_off,
899 LD_TIME_LINK_ON);
900 }
901
902 spin_unlock_irqrestore(&priv->lock, flags);
903}
904
David Howellsc4028952006-11-22 14:57:56 +0000905static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500906{
David Howellsc4028952006-11-22 14:57:56 +0000907 struct ipw_priv *priv =
908 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800909 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000910 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800911 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500912}
913
Adrian Bunka73e22b2006-01-21 01:39:42 +0100914static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500915{
916 unsigned long flags;
917 u32 led;
918
919 /* If configured not to use LEDs, or nic type is 1,
920 * then we don't goggle the LINK led. */
921 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
922 return;
923
924 spin_lock_irqsave(&priv->lock, flags);
925
926 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500927 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500928 led &= priv->led_association_off;
929 led = ipw_register_toggle(led);
930
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500932 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933
934 IPW_DEBUG_LED("Link LED Off\n");
935
936 priv->status &= ~STATUS_LED_LINK_ON;
937
938 /* If we aren't associated and the radio is on, schedule
939 * turning the LED on (blink while unassociated) */
940 if (!(priv->status & STATUS_RF_KILL_MASK) &&
941 !(priv->status & STATUS_ASSOCIATED))
942 queue_delayed_work(priv->workqueue, &priv->led_link_on,
943 LD_TIME_LINK_OFF);
944
945 }
946
947 spin_unlock_irqrestore(&priv->lock, flags);
948}
949
David Howellsc4028952006-11-22 14:57:56 +0000950static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500951{
David Howellsc4028952006-11-22 14:57:56 +0000952 struct ipw_priv *priv =
953 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800954 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000955 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800956 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500957}
958
Arjan van de Ven858119e2006-01-14 13:20:43 -0800959static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500960{
James Ketrenosa613bff2005-08-24 21:43:11 -0500961 u32 led;
962
963 if (priv->config & CFG_NO_LED)
964 return;
965
James Ketrenosb095c382005-08-24 22:04:42 -0500966 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500967 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500968
969 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500970 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500971 led |= priv->led_activity_on;
972
973 led = ipw_register_toggle(led);
974
975 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500976 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500977
978 IPW_DEBUG_LED("Activity LED On\n");
979
980 priv->status |= STATUS_LED_ACT_ON;
981
James Ketrenosc848d0a2005-08-24 21:56:24 -0500982 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500983 queue_delayed_work(priv->workqueue, &priv->led_act_off,
984 LD_TIME_ACT_ON);
985 } else {
986 /* Reschedule LED off for full time period */
987 cancel_delayed_work(&priv->led_act_off);
988 queue_delayed_work(priv->workqueue, &priv->led_act_off,
989 LD_TIME_ACT_ON);
990 }
James Ketrenosb095c382005-08-24 22:04:42 -0500991}
James Ketrenosa613bff2005-08-24 21:43:11 -0500992
Adrian Bunka73e22b2006-01-21 01:39:42 +0100993#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500994void ipw_led_activity_on(struct ipw_priv *priv)
995{
996 unsigned long flags;
997 spin_lock_irqsave(&priv->lock, flags);
998 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500999 spin_unlock_irqrestore(&priv->lock, flags);
1000}
Adrian Bunka73e22b2006-01-21 01:39:42 +01001001#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -05001002
Adrian Bunka73e22b2006-01-21 01:39:42 +01001003static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001004{
1005 unsigned long flags;
1006 u32 led;
1007
1008 if (priv->config & CFG_NO_LED)
1009 return;
1010
1011 spin_lock_irqsave(&priv->lock, flags);
1012
1013 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001014 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001015 led &= priv->led_activity_off;
1016
1017 led = ipw_register_toggle(led);
1018
1019 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001020 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001021
1022 IPW_DEBUG_LED("Activity LED Off\n");
1023
1024 priv->status &= ~STATUS_LED_ACT_ON;
1025 }
1026
1027 spin_unlock_irqrestore(&priv->lock, flags);
1028}
1029
David Howellsc4028952006-11-22 14:57:56 +00001030static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001031{
David Howellsc4028952006-11-22 14:57:56 +00001032 struct ipw_priv *priv =
1033 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001034 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001035 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001036 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001037}
1038
Adrian Bunka73e22b2006-01-21 01:39:42 +01001039static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001040{
1041 unsigned long flags;
1042 u32 led;
1043
1044 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001045 if (priv->config & CFG_NO_LED ||
1046 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001047 return;
1048
1049 spin_lock_irqsave(&priv->lock, flags);
1050
James Ketrenosb095c382005-08-24 22:04:42 -05001051 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001052 if (priv->assoc_network->mode == IEEE_A) {
1053 led |= priv->led_ofdm_on;
1054 led &= priv->led_association_off;
1055 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1056 } else if (priv->assoc_network->mode == IEEE_G) {
1057 led |= priv->led_ofdm_on;
1058 led |= priv->led_association_on;
1059 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1060 } else {
1061 led &= priv->led_ofdm_off;
1062 led |= priv->led_association_on;
1063 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1064 }
1065
1066 led = ipw_register_toggle(led);
1067
1068 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001069 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001070
1071 spin_unlock_irqrestore(&priv->lock, flags);
1072}
1073
Adrian Bunka73e22b2006-01-21 01:39:42 +01001074static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001075{
1076 unsigned long flags;
1077 u32 led;
1078
1079 /* Only nic type 1 supports mode LEDs */
1080 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1081 return;
1082
1083 spin_lock_irqsave(&priv->lock, flags);
1084
James Ketrenosb095c382005-08-24 22:04:42 -05001085 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001086 led &= priv->led_ofdm_off;
1087 led &= priv->led_association_off;
1088
1089 led = ipw_register_toggle(led);
1090
1091 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001092 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001093
1094 spin_unlock_irqrestore(&priv->lock, flags);
1095}
1096
Adrian Bunka73e22b2006-01-21 01:39:42 +01001097static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001098{
1099 ipw_led_link_on(priv);
1100}
1101
Adrian Bunka73e22b2006-01-21 01:39:42 +01001102static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001103{
1104 ipw_led_activity_off(priv);
1105 ipw_led_link_off(priv);
1106}
1107
Adrian Bunka73e22b2006-01-21 01:39:42 +01001108static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001109{
1110 /* Set the Link Led on for all nic types */
1111 ipw_led_link_on(priv);
1112}
1113
Adrian Bunka73e22b2006-01-21 01:39:42 +01001114static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001115{
1116 ipw_led_activity_off(priv);
1117 ipw_led_link_off(priv);
1118
1119 if (priv->status & STATUS_RF_KILL_MASK)
1120 ipw_led_radio_off(priv);
1121}
1122
Adrian Bunka73e22b2006-01-21 01:39:42 +01001123static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001124{
1125 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1126
1127 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001128 priv->led_activity_on = IPW_ACTIVITY_LED;
1129 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001130
James Ketrenosb095c382005-08-24 22:04:42 -05001131 priv->led_association_on = IPW_ASSOCIATED_LED;
1132 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001133
1134 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001135 priv->led_ofdm_on = IPW_OFDM_LED;
1136 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001137
1138 switch (priv->nic_type) {
1139 case EEPROM_NIC_TYPE_1:
1140 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001141 priv->led_activity_on = IPW_ASSOCIATED_LED;
1142 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1143 priv->led_association_on = IPW_ACTIVITY_LED;
1144 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001145
1146 if (!(priv->config & CFG_NO_LED))
1147 ipw_led_band_on(priv);
1148
1149 /* And we don't blink link LEDs for this nic, so
1150 * just return here */
1151 return;
1152
1153 case EEPROM_NIC_TYPE_3:
1154 case EEPROM_NIC_TYPE_2:
1155 case EEPROM_NIC_TYPE_4:
1156 case EEPROM_NIC_TYPE_0:
1157 break;
1158
1159 default:
1160 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1161 priv->nic_type);
1162 priv->nic_type = EEPROM_NIC_TYPE_0;
1163 break;
1164 }
1165
1166 if (!(priv->config & CFG_NO_LED)) {
1167 if (priv->status & STATUS_ASSOCIATED)
1168 ipw_led_link_on(priv);
1169 else
1170 ipw_led_link_off(priv);
1171 }
1172}
1173
Adrian Bunka73e22b2006-01-21 01:39:42 +01001174static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001175{
James Ketrenosa613bff2005-08-24 21:43:11 -05001176 ipw_led_activity_off(priv);
1177 ipw_led_link_off(priv);
1178 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001179 cancel_delayed_work(&priv->led_link_on);
1180 cancel_delayed_work(&priv->led_link_off);
1181 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001182}
1183
James Ketrenos43f66a62005-03-25 12:31:53 -06001184/*
1185 * The following adds a new attribute to the sysfs representation
1186 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1187 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001188 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001189 * See the level definitions in ipw for details.
1190 */
1191static ssize_t show_debug_level(struct device_driver *d, char *buf)
1192{
1193 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1194}
James Ketrenosa613bff2005-08-24 21:43:11 -05001195
1196static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1197 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001198{
1199 char *p = (char *)buf;
1200 u32 val;
1201
1202 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1203 p++;
1204 if (p[0] == 'x' || p[0] == 'X')
1205 p++;
1206 val = simple_strtoul(p, &p, 16);
1207 } else
1208 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001209 if (p == buf)
1210 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001211 ": %s is not in hex or decimal form.\n", buf);
1212 else
1213 ipw_debug_level = val;
1214
1215 return strnlen(buf, count);
1216}
1217
Jeff Garzikbf794512005-07-31 13:07:26 -04001218static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001219 show_debug_level, store_debug_level);
1220
James Ketrenosb39860c2005-08-12 09:36:32 -05001221static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1222{
Zhu Yic8fe6672006-01-24 16:36:36 +08001223 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001224 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1225}
1226
1227static void ipw_capture_event_log(struct ipw_priv *priv,
1228 u32 log_len, struct ipw_event *log)
1229{
1230 u32 base;
1231
1232 if (log_len) {
1233 base = ipw_read32(priv, IPW_EVENT_LOG);
1234 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1235 (u8 *) log, sizeof(*log) * log_len);
1236 }
1237}
1238
1239static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1240{
1241 struct ipw_fw_error *error;
1242 u32 log_len = ipw_get_event_log_len(priv);
1243 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1244 u32 elem_len = ipw_read_reg32(priv, base);
1245
1246 error = kmalloc(sizeof(*error) +
1247 sizeof(*error->elem) * elem_len +
1248 sizeof(*error->log) * log_len, GFP_ATOMIC);
1249 if (!error) {
1250 IPW_ERROR("Memory allocation for firmware error log "
1251 "failed.\n");
1252 return NULL;
1253 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001254 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001255 error->status = priv->status;
1256 error->config = priv->config;
1257 error->elem_len = elem_len;
1258 error->log_len = log_len;
1259 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001260 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001261
1262 ipw_capture_event_log(priv, log_len, error->log);
1263
1264 if (elem_len)
1265 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1266 sizeof(*error->elem) * elem_len);
1267
1268 return error;
1269}
1270
James Ketrenosb39860c2005-08-12 09:36:32 -05001271static ssize_t show_event_log(struct device *d,
1272 struct device_attribute *attr, char *buf)
1273{
1274 struct ipw_priv *priv = dev_get_drvdata(d);
1275 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001276 u32 log_size;
1277 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001278 u32 len = 0, i;
1279
Reinette Chatre412e9e72007-12-18 22:01:02 -08001280 /* not using min() because of its strict type checking */
1281 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1282 sizeof(*log) * log_len : PAGE_SIZE;
1283 log = kzalloc(log_size, GFP_KERNEL);
1284 if (!log) {
1285 IPW_ERROR("Unable to allocate memory for log\n");
1286 return 0;
1287 }
1288 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001289 ipw_capture_event_log(priv, log_len, log);
1290
1291 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1292 for (i = 0; i < log_len; i++)
1293 len += snprintf(buf + len, PAGE_SIZE - len,
1294 "\n%08X%08X%08X",
1295 log[i].time, log[i].event, log[i].data);
1296 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001297 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001298 return len;
1299}
1300
1301static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1302
1303static ssize_t show_error(struct device *d,
1304 struct device_attribute *attr, char *buf)
1305{
1306 struct ipw_priv *priv = dev_get_drvdata(d);
1307 u32 len = 0, i;
1308 if (!priv->error)
1309 return 0;
1310 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001311 "%08lX%08X%08X%08X",
1312 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001313 priv->error->status,
1314 priv->error->config, priv->error->elem_len);
1315 for (i = 0; i < priv->error->elem_len; i++)
1316 len += snprintf(buf + len, PAGE_SIZE - len,
1317 "\n%08X%08X%08X%08X%08X%08X%08X",
1318 priv->error->elem[i].time,
1319 priv->error->elem[i].desc,
1320 priv->error->elem[i].blink1,
1321 priv->error->elem[i].blink2,
1322 priv->error->elem[i].link1,
1323 priv->error->elem[i].link2,
1324 priv->error->elem[i].data);
1325
1326 len += snprintf(buf + len, PAGE_SIZE - len,
1327 "\n%08X", priv->error->log_len);
1328 for (i = 0; i < priv->error->log_len; i++)
1329 len += snprintf(buf + len, PAGE_SIZE - len,
1330 "\n%08X%08X%08X",
1331 priv->error->log[i].time,
1332 priv->error->log[i].event,
1333 priv->error->log[i].data);
1334 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1335 return len;
1336}
1337
1338static ssize_t clear_error(struct device *d,
1339 struct device_attribute *attr,
1340 const char *buf, size_t count)
1341{
1342 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001343
1344 kfree(priv->error);
1345 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001346 return count;
1347}
1348
1349static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1350
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001351static ssize_t show_cmd_log(struct device *d,
1352 struct device_attribute *attr, char *buf)
1353{
1354 struct ipw_priv *priv = dev_get_drvdata(d);
1355 u32 len = 0, i;
1356 if (!priv->cmdlog)
1357 return 0;
1358 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1359 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1360 i = (i + 1) % priv->cmdlog_len) {
1361 len +=
1362 snprintf(buf + len, PAGE_SIZE - len,
1363 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1364 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1365 priv->cmdlog[i].cmd.len);
1366 len +=
1367 snprintk_buf(buf + len, PAGE_SIZE - len,
1368 (u8 *) priv->cmdlog[i].cmd.param,
1369 priv->cmdlog[i].cmd.len);
1370 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1371 }
1372 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1373 return len;
1374}
1375
1376static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1377
Zhu Yid685b8c2006-04-13 17:20:27 +08001378#ifdef CONFIG_IPW2200_PROMISCUOUS
1379static void ipw_prom_free(struct ipw_priv *priv);
1380static int ipw_prom_alloc(struct ipw_priv *priv);
1381static ssize_t store_rtap_iface(struct device *d,
1382 struct device_attribute *attr,
1383 const char *buf, size_t count)
1384{
1385 struct ipw_priv *priv = dev_get_drvdata(d);
1386 int rc = 0;
1387
1388 if (count < 1)
1389 return -EINVAL;
1390
1391 switch (buf[0]) {
1392 case '0':
1393 if (!rtap_iface)
1394 return count;
1395
1396 if (netif_running(priv->prom_net_dev)) {
1397 IPW_WARNING("Interface is up. Cannot unregister.\n");
1398 return count;
1399 }
1400
1401 ipw_prom_free(priv);
1402 rtap_iface = 0;
1403 break;
1404
1405 case '1':
1406 if (rtap_iface)
1407 return count;
1408
1409 rc = ipw_prom_alloc(priv);
1410 if (!rc)
1411 rtap_iface = 1;
1412 break;
1413
1414 default:
1415 return -EINVAL;
1416 }
1417
1418 if (rc) {
1419 IPW_ERROR("Failed to register promiscuous network "
1420 "device (error %d).\n", rc);
1421 }
1422
1423 return count;
1424}
1425
1426static ssize_t show_rtap_iface(struct device *d,
1427 struct device_attribute *attr,
1428 char *buf)
1429{
1430 struct ipw_priv *priv = dev_get_drvdata(d);
1431 if (rtap_iface)
1432 return sprintf(buf, "%s", priv->prom_net_dev->name);
1433 else {
1434 buf[0] = '-';
1435 buf[1] = '1';
1436 buf[2] = '\0';
1437 return 3;
1438 }
1439}
1440
1441static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1442 store_rtap_iface);
1443
1444static ssize_t store_rtap_filter(struct device *d,
1445 struct device_attribute *attr,
1446 const char *buf, size_t count)
1447{
1448 struct ipw_priv *priv = dev_get_drvdata(d);
1449
1450 if (!priv->prom_priv) {
1451 IPW_ERROR("Attempting to set filter without "
1452 "rtap_iface enabled.\n");
1453 return -EPERM;
1454 }
1455
1456 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1457
1458 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1459 BIT_ARG16(priv->prom_priv->filter));
1460
1461 return count;
1462}
1463
1464static ssize_t show_rtap_filter(struct device *d,
1465 struct device_attribute *attr,
1466 char *buf)
1467{
1468 struct ipw_priv *priv = dev_get_drvdata(d);
1469 return sprintf(buf, "0x%04X",
1470 priv->prom_priv ? priv->prom_priv->filter : 0);
1471}
1472
1473static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1474 store_rtap_filter);
1475#endif
1476
James Ketrenosa613bff2005-08-24 21:43:11 -05001477static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1478 char *buf)
1479{
1480 struct ipw_priv *priv = dev_get_drvdata(d);
1481 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1482}
1483
1484static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1485 const char *buf, size_t count)
1486{
1487 struct ipw_priv *priv = dev_get_drvdata(d);
1488 struct net_device *dev = priv->net_dev;
1489 char buffer[] = "00000000";
1490 unsigned long len =
1491 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1492 unsigned long val;
1493 char *p = buffer;
1494
1495 IPW_DEBUG_INFO("enter\n");
1496
1497 strncpy(buffer, buf, len);
1498 buffer[len] = 0;
1499
1500 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1501 p++;
1502 if (p[0] == 'x' || p[0] == 'X')
1503 p++;
1504 val = simple_strtoul(p, &p, 16);
1505 } else
1506 val = simple_strtoul(p, &p, 10);
1507 if (p == buffer) {
1508 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1509 } else {
1510 priv->ieee->scan_age = val;
1511 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1512 }
1513
1514 IPW_DEBUG_INFO("exit\n");
1515 return len;
1516}
1517
1518static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1519
1520static ssize_t show_led(struct device *d, struct device_attribute *attr,
1521 char *buf)
1522{
1523 struct ipw_priv *priv = dev_get_drvdata(d);
1524 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1525}
1526
1527static ssize_t store_led(struct device *d, struct device_attribute *attr,
1528 const char *buf, size_t count)
1529{
1530 struct ipw_priv *priv = dev_get_drvdata(d);
1531
1532 IPW_DEBUG_INFO("enter\n");
1533
1534 if (count == 0)
1535 return 0;
1536
1537 if (*buf == 0) {
1538 IPW_DEBUG_LED("Disabling LED control.\n");
1539 priv->config |= CFG_NO_LED;
1540 ipw_led_shutdown(priv);
1541 } else {
1542 IPW_DEBUG_LED("Enabling LED control.\n");
1543 priv->config &= ~CFG_NO_LED;
1544 ipw_led_init(priv);
1545 }
1546
1547 IPW_DEBUG_INFO("exit\n");
1548 return count;
1549}
1550
1551static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1552
Andrew Mortonad3fee52005-06-20 14:30:36 -07001553static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001554 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001555{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001556 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001557 return sprintf(buf, "0x%08x\n", (int)p->status);
1558}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001559
James Ketrenos43f66a62005-03-25 12:31:53 -06001560static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1561
Andrew Mortonad3fee52005-06-20 14:30:36 -07001562static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1563 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001564{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001565 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001566 return sprintf(buf, "0x%08x\n", (int)p->config);
1567}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001568
James Ketrenos43f66a62005-03-25 12:31:53 -06001569static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1570
Andrew Mortonad3fee52005-06-20 14:30:36 -07001571static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001572 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001573{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001574 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001575 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001576}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001577
James Ketrenos43f66a62005-03-25 12:31:53 -06001578static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1579
Andrew Mortonad3fee52005-06-20 14:30:36 -07001580static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001581 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001582{
1583 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001584 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001585
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001586 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001587 return 0;
1588
1589 return sprintf(buf, "0x%08x\n", tmp);
1590}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001591
1592static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001593
Andrew Mortonad3fee52005-06-20 14:30:36 -07001594static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1595 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001596{
1597 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001598 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001599
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001600 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001601 return 0;
1602
1603 return sprintf(buf, "0x%08x\n", tmp);
1604}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001605
1606static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001607
1608/*
1609 * Add a device attribute to view/control the delay between eeprom
1610 * operations.
1611 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001612static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001613 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001614{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001615 struct ipw_priv *p = dev_get_drvdata(d);
1616 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001617 return sprintf(buf, "%i\n", n);
1618}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001619static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001620 struct device_attribute *attr,
1621 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001622{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001623 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001624 sscanf(buf, "%i", &p->eeprom_delay);
1625 return strnlen(buf, count);
1626}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001627
1628static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1629 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001630
Andrew Mortonad3fee52005-06-20 14:30:36 -07001631static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001632 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001633{
1634 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001635 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001636
James Ketrenosb095c382005-08-24 22:04:42 -05001637 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001638 return sprintf(buf, "0x%08x\n", reg);
1639}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001640static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001641 struct device_attribute *attr,
1642 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001643{
1644 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001645 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001646
1647 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001648 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001649 return strnlen(buf, count);
1650}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001651
1652static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1653 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001654
Andrew Mortonad3fee52005-06-20 14:30:36 -07001655static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001656 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001657{
1658 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001659 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001660
1661 reg = ipw_read_reg32(p, 0x301100);
1662 return sprintf(buf, "0x%08x\n", reg);
1663}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001664static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001665 struct device_attribute *attr,
1666 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001667{
1668 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001669 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001670
1671 sscanf(buf, "%x", &reg);
1672 ipw_write_reg32(p, 0x301100, reg);
1673 return strnlen(buf, count);
1674}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001675
1676static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1677 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001678
Andrew Mortonad3fee52005-06-20 14:30:36 -07001679static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001680 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001681{
1682 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001683 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001684
Jeff Garzikbf794512005-07-31 13:07:26 -04001685 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001686 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001687 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001688 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001689
James Ketrenos43f66a62005-03-25 12:31:53 -06001690 return sprintf(buf, "0x%08x\n", reg);
1691}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001692static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001693 struct device_attribute *attr,
1694 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001695{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001696 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001697
1698 sscanf(buf, "%x", &priv->indirect_dword);
1699 priv->status |= STATUS_INDIRECT_DWORD;
1700 return strnlen(buf, count);
1701}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001702
1703static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1704 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001705
Andrew Mortonad3fee52005-06-20 14:30:36 -07001706static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001707 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001708{
1709 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001710 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001711
Jeff Garzikbf794512005-07-31 13:07:26 -04001712 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001713 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001714 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001715 reg = 0;
1716
1717 return sprintf(buf, "0x%02x\n", reg);
1718}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001719static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001720 struct device_attribute *attr,
1721 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001722{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001723 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001724
1725 sscanf(buf, "%x", &priv->indirect_byte);
1726 priv->status |= STATUS_INDIRECT_BYTE;
1727 return strnlen(buf, count);
1728}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001729
1730static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001731 show_indirect_byte, store_indirect_byte);
1732
Andrew Mortonad3fee52005-06-20 14:30:36 -07001733static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001734 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001735{
1736 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001737 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001738
Jeff Garzikbf794512005-07-31 13:07:26 -04001739 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001741 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 reg = 0;
1743
1744 return sprintf(buf, "0x%08x\n", reg);
1745}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001746static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001747 struct device_attribute *attr,
1748 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001749{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001750 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001751
1752 sscanf(buf, "%x", &priv->direct_dword);
1753 priv->status |= STATUS_DIRECT_DWORD;
1754 return strnlen(buf, count);
1755}
James Ketrenos43f66a62005-03-25 12:31:53 -06001756
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001757static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1758 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001759
Arjan van de Ven858119e2006-01-14 13:20:43 -08001760static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001761{
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001762 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001763 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001764 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1765 } else {
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001767 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1768 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001769
1770 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1771}
1772
Andrew Mortonad3fee52005-06-20 14:30:36 -07001773static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001774 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001775{
1776 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001777 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 2 - HW based RF kill active
1779 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001780 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001782 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001783 return sprintf(buf, "%i\n", val);
1784}
1785
1786static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1787{
Jeff Garzikbf794512005-07-31 13:07:26 -04001788 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001789 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001790 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001791
1792 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1793 disable_radio ? "OFF" : "ON");
1794
1795 if (disable_radio) {
1796 priv->status |= STATUS_RF_KILL_SW;
1797
Dan Williams0b531672007-10-09 13:55:24 -04001798 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001799 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04001800 cancel_delayed_work(&priv->request_direct_scan);
1801 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04001802 cancel_delayed_work(&priv->scan_event);
1803 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001804 queue_work(priv->workqueue, &priv->down);
1805 } else {
1806 priv->status &= ~STATUS_RF_KILL_SW;
1807 if (rf_kill_active(priv)) {
1808 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1809 "disabled by HW switch\n");
1810 /* Make sure the RF_KILL check timer is running */
1811 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001812 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001813 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001814 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001815 queue_work(priv->workqueue, &priv->up);
1816 }
1817
1818 return 1;
1819}
1820
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001821static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1822 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001823{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001824 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001825
James Ketrenos43f66a62005-03-25 12:31:53 -06001826 ipw_radio_kill_sw(priv, buf[0] == '1');
1827
1828 return count;
1829}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001830
1831static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001832
James Ketrenosb095c382005-08-24 22:04:42 -05001833static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1834 char *buf)
1835{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001836 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001837 int pos = 0, len = 0;
1838 if (priv->config & CFG_SPEED_SCAN) {
1839 while (priv->speed_scan[pos] != 0)
1840 len += sprintf(&buf[len], "%d ",
1841 priv->speed_scan[pos++]);
1842 return len + sprintf(&buf[len], "\n");
1843 }
1844
1845 return sprintf(buf, "0\n");
1846}
1847
1848static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1849 const char *buf, size_t count)
1850{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001851 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001852 int channel, pos = 0;
1853 const char *p = buf;
1854
1855 /* list of space separated channels to scan, optionally ending with 0 */
1856 while ((channel = simple_strtol(p, NULL, 0))) {
1857 if (pos == MAX_SPEED_SCAN - 1) {
1858 priv->speed_scan[pos] = 0;
1859 break;
1860 }
1861
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001862 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001863 priv->speed_scan[pos++] = channel;
1864 else
1865 IPW_WARNING("Skipping invalid channel request: %d\n",
1866 channel);
1867 p = strchr(p, ' ');
1868 if (!p)
1869 break;
1870 while (*p == ' ' || *p == '\t')
1871 p++;
1872 }
1873
1874 if (pos == 0)
1875 priv->config &= ~CFG_SPEED_SCAN;
1876 else {
1877 priv->speed_scan_pos = 0;
1878 priv->config |= CFG_SPEED_SCAN;
1879 }
1880
1881 return count;
1882}
1883
1884static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1885 store_speed_scan);
1886
1887static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1888 char *buf)
1889{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001890 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001891 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1892}
1893
1894static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1895 const char *buf, size_t count)
1896{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001897 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001898 if (buf[0] == '1')
1899 priv->config |= CFG_NET_STATS;
1900 else
1901 priv->config &= ~CFG_NET_STATS;
1902
1903 return count;
1904}
1905
James Ketrenosafbf30a2005-08-25 00:05:33 -05001906static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1907 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001908
Zhu Yi375dd242007-02-14 16:04:24 +08001909static ssize_t show_channels(struct device *d,
1910 struct device_attribute *attr,
1911 char *buf)
1912{
1913 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001914 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001915 int len = 0, i;
1916
1917 len = sprintf(&buf[len],
1918 "Displaying %d channels in 2.4Ghz band "
1919 "(802.11bg):\n", geo->bg_channels);
1920
1921 for (i = 0; i < geo->bg_channels; i++) {
1922 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1923 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001924 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001925 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001926 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1927 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001928 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001929 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001930 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001931 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001932 "B" : "B/G");
1933 }
1934
1935 len += sprintf(&buf[len],
1936 "Displaying %d channels in 5.2Ghz band "
1937 "(802.11a):\n", geo->a_channels);
1938 for (i = 0; i < geo->a_channels; i++) {
1939 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1940 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001941 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001942 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001943 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1944 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001945 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001946 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001947 "passive only" : "active/passive");
1948 }
1949
1950 return len;
1951}
1952
1953static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1954
James Ketrenosea2b26e2005-08-24 21:25:16 -05001955static void notify_wx_assoc_event(struct ipw_priv *priv)
1956{
1957 union iwreq_data wrqu;
1958 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1959 if (priv->status & STATUS_ASSOCIATED)
1960 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1961 else
1962 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1963 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1964}
1965
James Ketrenos43f66a62005-03-25 12:31:53 -06001966static void ipw_irq_tasklet(struct ipw_priv *priv)
1967{
1968 u32 inta, inta_mask, handled = 0;
1969 unsigned long flags;
1970 int rc = 0;
1971
Zhu Yi89c318e2006-06-08 22:19:49 -07001972 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001973
James Ketrenosb095c382005-08-24 22:04:42 -05001974 inta = ipw_read32(priv, IPW_INTA_RW);
1975 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Indan Zupancic3c4a8cc2011-01-08 12:17:27 +01001976
1977 if (inta == 0xFFFFFFFF) {
1978 /* Hardware disappeared */
1979 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1980 /* Only handle the cached INTA values */
1981 inta = 0;
1982 }
James Ketrenosb095c382005-08-24 22:04:42 -05001983 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001984
1985 /* Add any cached INTA values that need to be handled */
1986 inta |= priv->isr_inta;
1987
Zhu Yi89c318e2006-06-08 22:19:49 -07001988 spin_unlock_irqrestore(&priv->irq_lock, flags);
1989
1990 spin_lock_irqsave(&priv->lock, flags);
1991
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001993 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001995 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 }
1997
James Ketrenosb095c382005-08-24 22:04:42 -05001998 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002000 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 priv->status &= ~STATUS_HCMD_ACTIVE;
2002 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05002003 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 }
2005
James Ketrenosb095c382005-08-24 22:04:42 -05002006 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002007 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002008 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002009 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002010 }
2011
James Ketrenosb095c382005-08-24 22:04:42 -05002012 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002013 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002014 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002015 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 }
2017
James Ketrenosb095c382005-08-24 22:04:42 -05002018 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002019 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002020 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002021 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002022 }
2023
James Ketrenosb095c382005-08-24 22:04:42 -05002024 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002025 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002026 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002027 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002028 }
2029
James Ketrenosb095c382005-08-24 22:04:42 -05002030 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002031 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002032 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002033 }
2034
James Ketrenosb095c382005-08-24 22:04:42 -05002035 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002036 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002037 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002038 }
2039
James Ketrenosb095c382005-08-24 22:04:42 -05002040 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002041 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002042 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002043 }
2044
James Ketrenosb095c382005-08-24 22:04:42 -05002045 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002046 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002047 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 }
2049
James Ketrenosb095c382005-08-24 22:04:42 -05002050 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002051 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002052 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002053 }
2054
James Ketrenosb095c382005-08-24 22:04:42 -05002055 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002056 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2057 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002058 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002059 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002060 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002061 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002062 cancel_delayed_work(&priv->request_direct_scan);
2063 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002064 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002065 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002066 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002067 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002068 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002069
James Ketrenosb095c382005-08-24 22:04:42 -05002070 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002071 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002072 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002073 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002074 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2075 struct ipw_fw_error *error =
2076 ipw_alloc_error_log(priv);
2077 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002078 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002079 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002080 } else {
2081 priv->error = ipw_alloc_error_log(priv);
2082 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002083 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002084 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002085 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2086 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002087 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2088 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002089 }
2090
James Ketrenosb095c382005-08-24 22:04:42 -05002091 /* XXX: If hardware encryption is for WPA/WPA2,
2092 * we have to notify the supplicant. */
2093 if (priv->ieee->sec.encrypt) {
2094 priv->status &= ~STATUS_ASSOCIATED;
2095 notify_wx_assoc_event(priv);
2096 }
2097
2098 /* Keep the restart process from trying to send host
2099 * commands by clearing the INIT status bit */
2100 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002101
2102 /* Cancel currently queued command. */
2103 priv->status &= ~STATUS_HCMD_ACTIVE;
2104 wake_up_interruptible(&priv->wait_command_queue);
2105
James Ketrenos43f66a62005-03-25 12:31:53 -06002106 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002107 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002108 }
2109
James Ketrenosb095c382005-08-24 22:04:42 -05002110 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002111 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002112 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002113 }
2114
2115 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002116 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002117 }
2118
Zhu Yi89c318e2006-06-08 22:19:49 -07002119 spin_unlock_irqrestore(&priv->lock, flags);
2120
James Ketrenos43f66a62005-03-25 12:31:53 -06002121 /* enable all interrupts */
2122 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002123}
Jeff Garzikbf794512005-07-31 13:07:26 -04002124
James Ketrenos43f66a62005-03-25 12:31:53 -06002125#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2126static char *get_cmd_string(u8 cmd)
2127{
2128 switch (cmd) {
2129 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002130 IPW_CMD(POWER_DOWN);
2131 IPW_CMD(SYSTEM_CONFIG);
2132 IPW_CMD(MULTICAST_ADDRESS);
2133 IPW_CMD(SSID);
2134 IPW_CMD(ADAPTER_ADDRESS);
2135 IPW_CMD(PORT_TYPE);
2136 IPW_CMD(RTS_THRESHOLD);
2137 IPW_CMD(FRAG_THRESHOLD);
2138 IPW_CMD(POWER_MODE);
2139 IPW_CMD(WEP_KEY);
2140 IPW_CMD(TGI_TX_KEY);
2141 IPW_CMD(SCAN_REQUEST);
2142 IPW_CMD(SCAN_REQUEST_EXT);
2143 IPW_CMD(ASSOCIATE);
2144 IPW_CMD(SUPPORTED_RATES);
2145 IPW_CMD(SCAN_ABORT);
2146 IPW_CMD(TX_FLUSH);
2147 IPW_CMD(QOS_PARAMETERS);
2148 IPW_CMD(DINO_CONFIG);
2149 IPW_CMD(RSN_CAPABILITIES);
2150 IPW_CMD(RX_KEY);
2151 IPW_CMD(CARD_DISABLE);
2152 IPW_CMD(SEED_NUMBER);
2153 IPW_CMD(TX_POWER);
2154 IPW_CMD(COUNTRY_INFO);
2155 IPW_CMD(AIRONET_INFO);
2156 IPW_CMD(AP_TX_POWER);
2157 IPW_CMD(CCKM_INFO);
2158 IPW_CMD(CCX_VER_INFO);
2159 IPW_CMD(SET_CALIBRATION);
2160 IPW_CMD(SENSITIVITY_CALIB);
2161 IPW_CMD(RETRY_LIMIT);
2162 IPW_CMD(IPW_PRE_POWER_DOWN);
2163 IPW_CMD(VAP_BEACON_TEMPLATE);
2164 IPW_CMD(VAP_DTIM_PERIOD);
2165 IPW_CMD(EXT_SUPPORTED_RATES);
2166 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2167 IPW_CMD(VAP_QUIET_INTERVALS);
2168 IPW_CMD(VAP_CHANNEL_SWITCH);
2169 IPW_CMD(VAP_MANDATORY_CHANNELS);
2170 IPW_CMD(VAP_CELL_PWR_LIMIT);
2171 IPW_CMD(VAP_CF_PARAM_SET);
2172 IPW_CMD(VAP_SET_BEACONING_STATE);
2173 IPW_CMD(MEASUREMENT);
2174 IPW_CMD(POWER_CAPABILITY);
2175 IPW_CMD(SUPPORTED_CHANNELS);
2176 IPW_CMD(TPC_REPORT);
2177 IPW_CMD(WME_INFO);
2178 IPW_CMD(PRODUCTION_COMMAND);
2179 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002180 return "UNKNOWN";
2181 }
2182}
James Ketrenos43f66a62005-03-25 12:31:53 -06002183
2184#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002185
2186static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002187{
2188 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002189 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002190
James Ketrenosa613bff2005-08-24 21:43:11 -05002191 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002192 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002193 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2194 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002195 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002196 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002197 }
2198
2199 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002200
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002201 if (priv->cmdlog) {
2202 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2203 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2204 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2205 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2206 cmd->len);
2207 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2208 }
2209
James Ketrenosb095c382005-08-24 22:04:42 -05002210 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2211 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2212 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002213
2214#ifndef DEBUG_CMD_WEP_KEY
2215 if (cmd->cmd == IPW_CMD_WEP_KEY)
2216 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2217 else
2218#endif
2219 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2220
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002221 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002222 if (rc) {
2223 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002224 IPW_ERROR("Failed to send %s: Reason %d\n",
2225 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002226 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002227 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002228 }
2229 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002230
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002231 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2232 !(priv->
2233 status & STATUS_HCMD_ACTIVE),
2234 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002235 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002236 spin_lock_irqsave(&priv->lock, flags);
2237 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002238 IPW_ERROR("Failed to send %s: Command timed out.\n",
2239 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002240 priv->status &= ~STATUS_HCMD_ACTIVE;
2241 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002242 rc = -EIO;
2243 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002244 }
2245 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002246 } else
2247 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002248
James Ketrenosb095c382005-08-24 22:04:42 -05002249 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002250 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2251 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002252 rc = -EIO;
2253 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002254 }
2255
Zhu Yi2638bc32006-01-24 16:37:52 +08002256 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002257 if (priv->cmdlog) {
2258 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2259 priv->cmdlog_pos %= priv->cmdlog_len;
2260 }
2261 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002262}
2263
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002264static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002265{
2266 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002267 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002268 };
2269
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002270 return __ipw_send_cmd(priv, &cmd);
2271}
2272
2273static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2274 void *data)
2275{
2276 struct host_cmd cmd = {
2277 .cmd = command,
2278 .len = len,
2279 .param = data,
2280 };
2281
2282 return __ipw_send_cmd(priv, &cmd);
2283}
2284
2285static int ipw_send_host_complete(struct ipw_priv *priv)
2286{
James Ketrenos43f66a62005-03-25 12:31:53 -06002287 if (!priv) {
2288 IPW_ERROR("Invalid args\n");
2289 return -1;
2290 }
2291
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002292 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002293}
2294
Zhu Yid685b8c2006-04-13 17:20:27 +08002295static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002296{
Zhu Yid685b8c2006-04-13 17:20:27 +08002297 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2298 sizeof(priv->sys_config),
2299 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002300}
2301
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002302static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002303{
James Ketrenos43f66a62005-03-25 12:31:53 -06002304 if (!priv || !ssid) {
2305 IPW_ERROR("Invalid args\n");
2306 return -1;
2307 }
2308
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002309 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002310 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002311}
2312
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002313static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002314{
James Ketrenos43f66a62005-03-25 12:31:53 -06002315 if (!priv || !mac) {
2316 IPW_ERROR("Invalid args\n");
2317 return -1;
2318 }
2319
Johannes Berge1749612008-10-27 15:59:26 -07002320 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2321 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002322
Zhu Yi2638bc32006-01-24 16:37:52 +08002323 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002324}
2325
James Ketrenosa613bff2005-08-24 21:43:11 -05002326/*
2327 * NOTE: This must be executed from our workqueue as it results in udelay
2328 * being called which may corrupt the keyboard if executed on default
2329 * workqueue
2330 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002331static void ipw_adapter_restart(void *adapter)
2332{
2333 struct ipw_priv *priv = adapter;
2334
2335 if (priv->status & STATUS_RF_KILL_MASK)
2336 return;
2337
2338 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002339
2340 if (priv->assoc_network &&
2341 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2342 ipw_remove_current_network(priv);
2343
James Ketrenos43f66a62005-03-25 12:31:53 -06002344 if (ipw_up(priv)) {
2345 IPW_ERROR("Failed to up device\n");
2346 return;
2347 }
2348}
2349
David Howellsc4028952006-11-22 14:57:56 +00002350static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002351{
David Howellsc4028952006-11-22 14:57:56 +00002352 struct ipw_priv *priv =
2353 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002354 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002355 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002356 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002357}
2358
Zhu Yie65054b2010-03-30 09:36:16 +08002359static void ipw_abort_scan(struct ipw_priv *priv);
2360
2361#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
James Ketrenos43f66a62005-03-25 12:31:53 -06002362
2363static void ipw_scan_check(void *data)
2364{
2365 struct ipw_priv *priv = data;
Zhu Yie65054b2010-03-30 09:36:16 +08002366
2367 if (priv->status & STATUS_SCAN_ABORTING) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002368 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002369 "adapter after (%dms).\n",
2370 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002371 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yie65054b2010-03-30 09:36:16 +08002372 } else if (priv->status & STATUS_SCANNING) {
2373 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2374 "after (%dms).\n",
2375 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2376 ipw_abort_scan(priv);
2377 queue_delayed_work(priv->workqueue, &priv->scan_check, HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002378 }
2379}
2380
David Howellsc4028952006-11-22 14:57:56 +00002381static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002382{
David Howellsc4028952006-11-22 14:57:56 +00002383 struct ipw_priv *priv =
2384 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002385 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002386 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002387 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002388}
2389
James Ketrenos43f66a62005-03-25 12:31:53 -06002390static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2391 struct ipw_scan_request_ext *request)
2392{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002393 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002394 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002395}
2396
2397static int ipw_send_scan_abort(struct ipw_priv *priv)
2398{
James Ketrenos43f66a62005-03-25 12:31:53 -06002399 if (!priv) {
2400 IPW_ERROR("Invalid args\n");
2401 return -1;
2402 }
2403
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002404 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002405}
2406
2407static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2408{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002409 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002410 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002411 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002412
2413 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002414 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002415}
2416
2417static int ipw_send_associate(struct ipw_priv *priv,
2418 struct ipw_associate *associate)
2419{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002420 if (!priv || !associate) {
2421 IPW_ERROR("Invalid args\n");
2422 return -1;
2423 }
2424
Al Viro5b5e8072007-12-27 01:54:06 -05002425 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2426 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002427}
2428
2429static int ipw_send_supported_rates(struct ipw_priv *priv,
2430 struct ipw_supported_rates *rates)
2431{
James Ketrenos43f66a62005-03-25 12:31:53 -06002432 if (!priv || !rates) {
2433 IPW_ERROR("Invalid args\n");
2434 return -1;
2435 }
2436
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002437 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002438 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002439}
2440
2441static int ipw_set_random_seed(struct ipw_priv *priv)
2442{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002443 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002444
2445 if (!priv) {
2446 IPW_ERROR("Invalid args\n");
2447 return -1;
2448 }
2449
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002450 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002451
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002452 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002453}
2454
James Ketrenos43f66a62005-03-25 12:31:53 -06002455static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2456{
Al Viroe62e1ee2007-12-27 01:36:46 -05002457 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 if (!priv) {
2459 IPW_ERROR("Invalid args\n");
2460 return -1;
2461 }
2462
Al Viroe62e1ee2007-12-27 01:36:46 -05002463 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002464}
James Ketrenos43f66a62005-03-25 12:31:53 -06002465
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002466static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002467{
James Ketrenos43f66a62005-03-25 12:31:53 -06002468 if (!priv || !power) {
2469 IPW_ERROR("Invalid args\n");
2470 return -1;
2471 }
2472
Zhu Yi2638bc32006-01-24 16:37:52 +08002473 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002474}
James Ketrenos43f66a62005-03-25 12:31:53 -06002475
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002476static int ipw_set_tx_power(struct ipw_priv *priv)
2477{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002478 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002479 struct ipw_tx_power tx_power;
2480 s8 max_power;
2481 int i;
2482
2483 memset(&tx_power, 0, sizeof(tx_power));
2484
2485 /* configure device for 'G' band */
2486 tx_power.ieee_mode = IPW_G_MODE;
2487 tx_power.num_channels = geo->bg_channels;
2488 for (i = 0; i < geo->bg_channels; i++) {
2489 max_power = geo->bg[i].max_power;
2490 tx_power.channels_tx_power[i].channel_number =
2491 geo->bg[i].channel;
2492 tx_power.channels_tx_power[i].tx_power = max_power ?
2493 min(max_power, priv->tx_power) : priv->tx_power;
2494 }
2495 if (ipw_send_tx_power(priv, &tx_power))
2496 return -EIO;
2497
2498 /* configure device to also handle 'B' band */
2499 tx_power.ieee_mode = IPW_B_MODE;
2500 if (ipw_send_tx_power(priv, &tx_power))
2501 return -EIO;
2502
2503 /* configure device to also handle 'A' band */
2504 if (priv->ieee->abg_true) {
2505 tx_power.ieee_mode = IPW_A_MODE;
2506 tx_power.num_channels = geo->a_channels;
2507 for (i = 0; i < tx_power.num_channels; i++) {
2508 max_power = geo->a[i].max_power;
2509 tx_power.channels_tx_power[i].channel_number =
2510 geo->a[i].channel;
2511 tx_power.channels_tx_power[i].tx_power = max_power ?
2512 min(max_power, priv->tx_power) : priv->tx_power;
2513 }
2514 if (ipw_send_tx_power(priv, &tx_power))
2515 return -EIO;
2516 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 return 0;
2518}
2519
2520static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2521{
2522 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002523 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002524 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002525
2526 if (!priv) {
2527 IPW_ERROR("Invalid args\n");
2528 return -1;
2529 }
2530
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002531 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2532 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002533}
2534
2535static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2536{
2537 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002538 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002539 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002540
2541 if (!priv) {
2542 IPW_ERROR("Invalid args\n");
2543 return -1;
2544 }
2545
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002546 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2547 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002548}
2549
2550static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2551{
Al Viroe62e1ee2007-12-27 01:36:46 -05002552 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002553
2554 if (!priv) {
2555 IPW_ERROR("Invalid args\n");
2556 return -1;
2557 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002558
James Ketrenos43f66a62005-03-25 12:31:53 -06002559 /* If on battery, set to 3, if AC set to CAM, else user
2560 * level */
2561 switch (mode) {
2562 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002563 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 break;
2565 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002566 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002567 break;
2568 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002569 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002570 break;
2571 }
2572
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002573 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002574 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002575}
2576
James Ketrenosafbf30a2005-08-25 00:05:33 -05002577static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2578{
2579 struct ipw_retry_limit retry_limit = {
2580 .short_retry_limit = slimit,
2581 .long_retry_limit = llimit
2582 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002583
2584 if (!priv) {
2585 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002586 return -1;
2587 }
2588
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002589 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002590 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002591}
2592
2593/*
2594 * The IPW device contains a Microwire compatible EEPROM that stores
2595 * various data like the MAC address. Usually the firmware has exclusive
2596 * access to the eeprom, but during device initialization (before the
2597 * device driver has sent the HostComplete command to the firmware) the
2598 * device driver has read access to the EEPROM by way of indirect addressing
2599 * through a couple of memory mapped registers.
2600 *
2601 * The following is a simplified implementation for pulling data out of the
2602 * the eeprom, along with some helper functions to find information in
2603 * the per device private data's copy of the eeprom.
2604 *
2605 * NOTE: To better understand how these functions work (i.e what is a chip
2606 * select and why do have to keep driving the eeprom clock?), read
2607 * just about any data sheet for a Microwire compatible EEPROM.
2608 */
2609
2610/* write a 32 bit value into the indirect accessor register */
2611static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2612{
2613 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002614
James Ketrenos43f66a62005-03-25 12:31:53 -06002615 /* the eeprom requires some time to complete the operation */
2616 udelay(p->eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06002617}
2618
2619/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002620static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002621{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002622 eeprom_write_reg(priv, 0);
2623 eeprom_write_reg(priv, EEPROM_BIT_CS);
2624 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2625 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002626}
2627
2628/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002629static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002630{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002631 eeprom_write_reg(priv, EEPROM_BIT_CS);
2632 eeprom_write_reg(priv, 0);
2633 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002634}
2635
2636/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002637static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002638{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002639 int d = (bit ? EEPROM_BIT_DI : 0);
2640 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2641 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002642}
2643
2644/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002645static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002646{
2647 int i;
2648
2649 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002650 eeprom_write_bit(priv, 1);
2651 eeprom_write_bit(priv, op & 2);
2652 eeprom_write_bit(priv, op & 1);
2653 for (i = 7; i >= 0; i--) {
2654 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002655 }
2656}
2657
2658/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002660{
2661 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002662 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002663
James Ketrenos43f66a62005-03-25 12:31:53 -06002664 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002665 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002666
2667 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002669
2670 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002671 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002672 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002673 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2674 eeprom_write_reg(priv, EEPROM_BIT_CS);
2675 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2676 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002677 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002678
James Ketrenos43f66a62005-03-25 12:31:53 -06002679 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002680 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002681 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002682
James Ketrenos43f66a62005-03-25 12:31:53 -06002683 return r;
2684}
2685
2686/* helper function for pulling the mac address out of the private */
2687/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002688static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002689{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002690 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002691}
2692
2693/*
2694 * Either the device driver (i.e. the host) or the firmware can
2695 * load eeprom data into the designated region in SRAM. If neither
2696 * happens then the FW will shutdown with a fatal error.
2697 *
2698 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2699 * bit needs region of shared SRAM needs to be non-zero.
2700 */
2701static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2702{
2703 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002704 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002705
James Ketrenos43f66a62005-03-25 12:31:53 -06002706 IPW_DEBUG_TRACE(">>\n");
2707
2708 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002709 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002710 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002711
Jeff Garzikbf794512005-07-31 13:07:26 -04002712 /*
2713 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002714 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002715 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002716 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002717 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002718 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2719
2720 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002721 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002722 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002723
2724 /* Do not load eeprom data on fatal error or suspend */
2725 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2726 } else {
2727 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2728
2729 /* Load eeprom data on fatal error or suspend */
2730 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2731 }
2732
2733 IPW_DEBUG_TRACE("<<\n");
2734}
2735
Arjan van de Ven858119e2006-01-14 13:20:43 -08002736static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002737{
2738 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739 if (!count)
2740 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002741 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002742 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002743 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002744}
2745
2746static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2747{
James Ketrenosb095c382005-08-24 22:04:42 -05002748 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002749 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002750 sizeof(struct command_block));
2751}
2752
2753static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002754{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002755
Frans Pop9fd1ea42010-03-24 19:46:31 +01002756 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002757
James Ketrenos43f66a62005-03-25 12:31:53 -06002758 /* Start the dma */
2759 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002760
James Ketrenos43f66a62005-03-25 12:31:53 -06002761 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002762 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002763
Frans Pop9fd1ea42010-03-24 19:46:31 +01002764 IPW_DEBUG_FW("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002765 return 0;
2766}
2767
2768static void ipw_fw_dma_abort(struct ipw_priv *priv)
2769{
2770 u32 control = 0;
2771
2772 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002773
Pavel Machek67fd6b42006-07-11 15:34:05 +02002774 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002775 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002776 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002777 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002778
Frans Pop9fd1ea42010-03-24 19:46:31 +01002779 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002780}
2781
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002782static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2783 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002784{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002785 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002786 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002787 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002788 IPW_DEBUG_FW(">> :\n");
2789
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002790 ipw_write_indirect(priv, address, (u8 *) cb,
2791 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002792
2793 IPW_DEBUG_FW("<< :\n");
2794 return 0;
2795
2796}
2797
2798static int ipw_fw_dma_kick(struct ipw_priv *priv)
2799{
2800 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002801 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002802
2803 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002804
James Ketrenos43f66a62005-03-25 12:31:53 -06002805 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002806 ipw_fw_dma_write_command_block(priv, index,
2807 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002808
2809 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002810 ipw_clear_bit(priv, IPW_RESET_REG,
2811 IPW_RESET_REG_MASTER_DISABLED |
2812 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002813
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002814 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002815 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002816 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002817
2818 IPW_DEBUG_FW("<< :\n");
2819 return 0;
2820}
2821
2822static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2823{
2824 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002825 u32 register_value = 0;
2826 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002827
2828 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002829 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002830 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002831
2832 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002833 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002834 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002835
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002836 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002837 cb_fields_address = address;
2838 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002839 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002840
2841 cb_fields_address += sizeof(u32);
2842 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002843 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002844
2845 cb_fields_address += sizeof(u32);
2846 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002847 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002848 register_value);
2849
2850 cb_fields_address += sizeof(u32);
2851 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002852 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002853
2854 IPW_DEBUG_FW(">> :\n");
2855}
2856
2857static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2858{
2859 u32 current_cb_address = 0;
2860 u32 current_cb_index = 0;
2861
2862 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002863 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002864
James Ketrenosb095c382005-08-24 22:04:42 -05002865 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002866 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002867
Frans Pop9fd1ea42010-03-24 19:46:31 +01002868 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002869 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002870
2871 IPW_DEBUG_FW(">> :\n");
2872 return current_cb_index;
2873
2874}
2875
2876static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2877 u32 src_address,
2878 u32 dest_address,
2879 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002880 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002881{
2882
Jeff Garzikbf794512005-07-31 13:07:26 -04002883 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002884 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2885 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002886 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002887 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002888
2889 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2890 src_address, dest_address, length);
2891
2892 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2893 return -1;
2894
2895 last_cb_element = priv->sram_desc.last_cb_index;
2896 cb = &priv->sram_desc.cb_list[last_cb_element];
2897 priv->sram_desc.last_cb_index++;
2898
2899 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002900 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002901 control |= CB_INT_ENABLED;
2902
2903 if (is_last)
2904 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002905
James Ketrenos43f66a62005-03-25 12:31:53 -06002906 control |= length;
2907
2908 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002909 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002910
2911 /* Copy the Source and Destination addresses */
2912 cb->dest_addr = dest_address;
2913 cb->source_addr = src_address;
2914
2915 /* Copy the Control Word last */
2916 cb->control = control;
2917
2918 return 0;
2919}
2920
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002921static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2922 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002923{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002924 int ret, i;
2925 u32 size;
2926
Frans Pop9fd1ea42010-03-24 19:46:31 +01002927 IPW_DEBUG_FW(">>\n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002928 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2929 nr, dest_address, len);
2930
2931 for (i = 0; i < nr; i++) {
2932 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2933 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2934 dest_address +
2935 i * CB_MAX_LENGTH, size,
2936 0, 0);
2937 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002938 IPW_DEBUG_FW_INFO(": Failed\n");
2939 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002940 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002941 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002943
Frans Pop9fd1ea42010-03-24 19:46:31 +01002944 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 return 0;
2946}
2947
2948static int ipw_fw_dma_wait(struct ipw_priv *priv)
2949{
Zhu Yi397ae122006-01-24 16:37:22 +08002950 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002951 u32 watchdog = 0;
2952
Frans Pop9fd1ea42010-03-24 19:46:31 +01002953 IPW_DEBUG_FW(">> :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002954
2955 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002956 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002957 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002958
2959 while (current_index < priv->sram_desc.last_cb_index) {
2960 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002961 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002962 current_index = ipw_fw_dma_command_block_index(priv);
2963
Zhu Yi397ae122006-01-24 16:37:22 +08002964 if (previous_index < current_index) {
2965 watchdog = 0;
2966 continue;
2967 }
2968 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002969 IPW_DEBUG_FW_INFO("Timeout\n");
2970 ipw_fw_dma_dump_command_block(priv);
2971 ipw_fw_dma_abort(priv);
2972 return -1;
2973 }
2974 }
2975
2976 ipw_fw_dma_abort(priv);
2977
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002978 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002979 ipw_set_bit(priv, IPW_RESET_REG,
2980 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002981
Frans Pop9fd1ea42010-03-24 19:46:31 +01002982 IPW_DEBUG_FW("<< dmaWaitSync\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002983 return 0;
2984}
2985
Jeff Garzikbf794512005-07-31 13:07:26 -04002986static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002987{
2988 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002989 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002990 unsigned long flags;
2991
2992 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002993 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002994 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002995 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2996 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002997 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002998 &priv->ieee->network_free_list);
2999 }
3000 }
James Ketrenosa613bff2005-08-24 21:43:11 -05003001 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003002}
3003
3004/**
Jeff Garzikbf794512005-07-31 13:07:26 -04003005 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 * Reads debug register from domain0.
3007 * If card is present, pre-defined value should
3008 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04003009 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003010 * @param priv
3011 * @return 1 if card is present, 0 otherwise
3012 */
3013static inline int ipw_alive(struct ipw_priv *priv)
3014{
3015 return ipw_read32(priv, 0x90) == 0xd55555d5;
3016}
3017
Zhu Yic7b6a672006-01-24 16:37:05 +08003018/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003019static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003020 int timeout)
3021{
3022 int i = 0;
3023
3024 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003025 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003026 return i;
3027 mdelay(10);
3028 i += 10;
3029 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003030
James Ketrenos43f66a62005-03-25 12:31:53 -06003031 return -ETIME;
3032}
3033
Jeff Garzikbf794512005-07-31 13:07:26 -04003034/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003035 * the ipw hardware. It assumes the buffer has all the bits for the
3036 * image and the caller is handling the memory allocation and clean up.
3037 */
3038
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003039static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003040{
3041 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003042
Frans Pop9fd1ea42010-03-24 19:46:31 +01003043 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003044 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003045 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003046
Zhu Yic7b6a672006-01-24 16:37:05 +08003047 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003048 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3049 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003050 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003051 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003052 return -1;
3053 }
3054
3055 IPW_DEBUG_INFO("stop master %dms\n", rc);
3056
3057 return rc;
3058}
3059
3060static void ipw_arc_release(struct ipw_priv *priv)
3061{
Frans Pop9fd1ea42010-03-24 19:46:31 +01003062 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003063 mdelay(5);
3064
James Ketrenosb095c382005-08-24 22:04:42 -05003065 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003066
3067 /* no one knows timing, for safety add some delay */
3068 mdelay(5);
3069}
3070
James Ketrenos43f66a62005-03-25 12:31:53 -06003071struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003072 __le32 address;
3073 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003074};
3075
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003076static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003077{
3078 int rc = 0, i, addr;
3079 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003080 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003081
Al Viroe62e1ee2007-12-27 01:36:46 -05003082 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003083
Frans Pop9fd1ea42010-03-24 19:46:31 +01003084 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003085
3086 rc = ipw_stop_master(priv);
3087
3088 if (rc < 0)
3089 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003090
James Ketrenosb095c382005-08-24 22:04:42 -05003091 for (addr = IPW_SHARED_LOWER_BOUND;
3092 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003093 ipw_write32(priv, addr, 0);
3094 }
3095
3096 /* no ucode (yet) */
3097 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3098 /* destroy DMA queues */
3099 /* reset sequence */
3100
James Ketrenosb095c382005-08-24 22:04:42 -05003101 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003102 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003103 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003104 mdelay(1);
3105
3106 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003107 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003108 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003109
James Ketrenosb095c382005-08-24 22:04:42 -05003110 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003111 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003112
James Ketrenos43f66a62005-03-25 12:31:53 -06003113 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003114 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3115 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003116 mdelay(1);
3117
3118 /* write ucode */
3119 /**
3120 * @bug
3121 * Do NOT set indirect address register once and then
3122 * store data to indirect data register in the loop.
3123 * It seems very reasonable, but in this case DINO do not
3124 * accept ucode. It is essential to set address each time.
3125 */
3126 /* load new ipw uCode */
3127 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003128 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003129 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003130
James Ketrenos43f66a62005-03-25 12:31:53 -06003131 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003132 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3133 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003134
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003135 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003136
3137 /* wait for alive response */
3138 for (i = 0; i < 100; i++) {
3139 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003140 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003141 if (cr & DINO_RXFIFO_DATA)
3142 break;
3143 mdelay(1);
3144 }
3145
3146 if (cr & DINO_RXFIFO_DATA) {
3147 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003148 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003149
3150 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003151 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003152 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003153 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003154 memcpy(&priv->dino_alive, response_buffer,
3155 sizeof(priv->dino_alive));
3156 if (priv->dino_alive.alive_command == 1
3157 && priv->dino_alive.ucode_valid == 1) {
3158 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003159 IPW_DEBUG_INFO
3160 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3161 "of %02d/%02d/%02d %02d:%02d\n",
3162 priv->dino_alive.software_revision,
3163 priv->dino_alive.software_revision,
3164 priv->dino_alive.device_identifier,
3165 priv->dino_alive.device_identifier,
3166 priv->dino_alive.time_stamp[0],
3167 priv->dino_alive.time_stamp[1],
3168 priv->dino_alive.time_stamp[2],
3169 priv->dino_alive.time_stamp[3],
3170 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003171 } else {
3172 IPW_DEBUG_INFO("Microcode is not alive\n");
3173 rc = -EINVAL;
3174 }
3175 } else {
3176 IPW_DEBUG_INFO("No alive response from DINO\n");
3177 rc = -ETIME;
3178 }
3179
3180 /* disable DINO, otherwise for some reason
3181 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003182 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003183
James Ketrenos43f66a62005-03-25 12:31:53 -06003184 return rc;
3185}
3186
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003187static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003188{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003189 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003190 int offset = 0;
3191 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003192 int total_nr = 0;
3193 int i;
3194 struct pci_pool *pool;
Zhu Yi41093162010-03-09 16:05:31 +08003195 void **virts;
3196 dma_addr_t *phys;
James Ketrenos43f66a62005-03-25 12:31:53 -06003197
Frans Pop9fd1ea42010-03-24 19:46:31 +01003198 IPW_DEBUG_TRACE("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003199
Zhu Yi41093162010-03-09 16:05:31 +08003200 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3201 GFP_KERNEL);
3202 if (!virts)
3203 return -ENOMEM;
3204
3205 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3206 GFP_KERNEL);
3207 if (!phys) {
3208 kfree(virts);
3209 return -ENOMEM;
3210 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003211 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3212 if (!pool) {
3213 IPW_ERROR("pci_pool_create failed\n");
Zhu Yi41093162010-03-09 16:05:31 +08003214 kfree(phys);
3215 kfree(virts);
James Ketrenos43f66a62005-03-25 12:31:53 -06003216 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003217 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003218
3219 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003220 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003221
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003222 /* the DMA is already ready this would be a bug. */
3223 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003224
3225 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003226 u32 chunk_len;
3227 u8 *start;
3228 int size;
3229 int nr = 0;
3230
James Ketrenos43f66a62005-03-25 12:31:53 -06003231 chunk = (struct fw_chunk *)(data + offset);
3232 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003233 chunk_len = le32_to_cpu(chunk->length);
3234 start = data + offset;
3235
3236 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3237 for (i = 0; i < nr; i++) {
3238 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3239 &phys[total_nr]);
3240 if (!virts[total_nr]) {
3241 ret = -ENOMEM;
3242 goto out;
3243 }
3244 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3245 CB_MAX_LENGTH);
3246 memcpy(virts[total_nr], start, size);
3247 start += size;
3248 total_nr++;
3249 /* We don't support fw chunk larger than 64*8K */
3250 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3251 }
3252
James Ketrenos43f66a62005-03-25 12:31:53 -06003253 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003254 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003255 * offeset*/
3256 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003257 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3258 nr, le32_to_cpu(chunk->address),
3259 chunk_len);
3260 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003261 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3262 goto out;
3263 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003264
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003265 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003266 } while (offset < len);
3267
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003268 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003269 ret = ipw_fw_dma_kick(priv);
3270 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003271 IPW_ERROR("dmaKick Failed\n");
3272 goto out;
3273 }
3274
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003275 ret = ipw_fw_dma_wait(priv);
3276 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003277 IPW_ERROR("dmaWaitSync Failed\n");
3278 goto out;
3279 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003280 out:
3281 for (i = 0; i < total_nr; i++)
3282 pci_pool_free(pool, virts[i], phys[i]);
3283
3284 pci_pool_destroy(pool);
Zhu Yi41093162010-03-09 16:05:31 +08003285 kfree(phys);
3286 kfree(virts);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003287
3288 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003289}
3290
3291/* stop nic */
3292static int ipw_stop_nic(struct ipw_priv *priv)
3293{
3294 int rc = 0;
3295
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003296 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003297 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003298
James Ketrenosb095c382005-08-24 22:04:42 -05003299 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3300 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003301 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003302 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003303 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003304 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003305
James Ketrenosb095c382005-08-24 22:04:42 -05003306 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003307
James Ketrenos43f66a62005-03-25 12:31:53 -06003308 return rc;
3309}
3310
3311static void ipw_start_nic(struct ipw_priv *priv)
3312{
3313 IPW_DEBUG_TRACE(">>\n");
3314
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003315 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003316 ipw_clear_bit(priv, IPW_RESET_REG,
3317 IPW_RESET_REG_MASTER_DISABLED |
3318 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003319 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003320
James Ketrenos43f66a62005-03-25 12:31:53 -06003321 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003322 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3323 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003324
3325 IPW_DEBUG_TRACE("<<\n");
3326}
Jeff Garzikbf794512005-07-31 13:07:26 -04003327
James Ketrenos43f66a62005-03-25 12:31:53 -06003328static int ipw_init_nic(struct ipw_priv *priv)
3329{
3330 int rc;
3331
3332 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003333 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003334 /*prvHwInitNic */
3335 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003336 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003337
3338 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003339 ipw_write32(priv, IPW_READ_INT_REGISTER,
3340 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003341
3342 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003343 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3344 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003345 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003346 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3347
3348 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003349 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003350
3351 udelay(10);
3352
3353 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003354 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003355
3356 IPW_DEBUG_TRACE(">>\n");
3357 return 0;
3358}
3359
Jeff Garzikbf794512005-07-31 13:07:26 -04003360/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003361 * Probe is an ok place to call this from.
3362 */
3363static int ipw_reset_nic(struct ipw_priv *priv)
3364{
3365 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003366 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003367
3368 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003369
James Ketrenos43f66a62005-03-25 12:31:53 -06003370 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003371
James Ketrenosa613bff2005-08-24 21:43:11 -05003372 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003373 /* Clear the 'host command active' bit... */
3374 priv->status &= ~STATUS_HCMD_ACTIVE;
3375 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003376 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3377 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003378 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003379
3380 IPW_DEBUG_TRACE("<<\n");
3381 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003382}
James Ketrenos43f66a62005-03-25 12:31:53 -06003383
James Ketrenos9006ea72006-03-08 03:22:28 +08003384
3385struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003386 __le32 ver;
3387 __le32 boot_size;
3388 __le32 ucode_size;
3389 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003390 u8 data[0];
3391};
3392
Jeff Garzikbf794512005-07-31 13:07:26 -04003393static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003394 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003395{
James Ketrenos9006ea72006-03-08 03:22:28 +08003396 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003397 int rc;
3398
3399 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003400 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003401 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003402 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003403 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003404 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003405
James Ketrenos9006ea72006-03-08 03:22:28 +08003406 if ((*raw)->size < sizeof(*fw)) {
3407 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003408 return -EINVAL;
3409 }
3410
James Ketrenos9006ea72006-03-08 03:22:28 +08003411 fw = (void *)(*raw)->data;
3412
Zhu Yi0070f8c2006-04-13 17:20:12 +08003413 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3414 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003415 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3416 name, (*raw)->size);
3417 return -EINVAL;
3418 }
3419
3420 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003421 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003422 le32_to_cpu(fw->ver) >> 16,
3423 le32_to_cpu(fw->ver) & 0xff,
3424 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003425 return 0;
3426}
3427
James Ketrenosb095c382005-08-24 22:04:42 -05003428#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003429
Arjan van de Ven858119e2006-01-14 13:20:43 -08003430static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003431 struct ipw_rx_queue *rxq)
3432{
3433 unsigned long flags;
3434 int i;
3435
3436 spin_lock_irqsave(&rxq->lock, flags);
3437
3438 INIT_LIST_HEAD(&rxq->rx_free);
3439 INIT_LIST_HEAD(&rxq->rx_used);
3440
3441 /* Fill the rx_used queue with _all_ of the Rx buffers */
3442 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3443 /* In the reset function, these buffers may have been allocated
3444 * to an SKB, so we need to unmap and free potential storage */
3445 if (rxq->pool[i].skb != NULL) {
3446 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003447 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003448 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003449 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003450 }
3451 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3452 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003453
James Ketrenos43f66a62005-03-25 12:31:53 -06003454 /* Set us so that we have processed and used all buffers, but have
3455 * not restocked the Rx queue with fresh buffers */
3456 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003457 rxq->free_count = 0;
3458 spin_unlock_irqrestore(&rxq->lock, flags);
3459}
3460
3461#ifdef CONFIG_PM
3462static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003463static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003464
3465static void free_firmware(void)
3466{
3467 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003468 release_firmware(raw);
3469 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003470 fw_loaded = 0;
3471 }
3472}
3473#else
3474#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003475#endif
3476
3477static int ipw_load(struct ipw_priv *priv)
3478{
3479#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003480 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003481#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003482 struct ipw_fw *fw;
3483 u8 *boot_img, *ucode_img, *fw_img;
3484 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003485 int rc = 0, retries = 3;
3486
Zhu Yi397ae122006-01-24 16:37:22 +08003487 switch (priv->ieee->iw_mode) {
3488 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003489 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003490 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003491#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003492 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003493 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003494 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003495#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003496 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003497 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003498 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003499 }
Zhu Yi397ae122006-01-24 16:37:22 +08003500
James Ketrenos9006ea72006-03-08 03:22:28 +08003501 if (!name) {
3502 rc = -EINVAL;
3503 goto error;
3504 }
3505
3506#ifdef CONFIG_PM
3507 if (!fw_loaded) {
3508#endif
3509 rc = ipw_get_fw(priv, &raw, name);
3510 if (rc < 0)
3511 goto error;
3512#ifdef CONFIG_PM
3513 }
3514#endif
3515
3516 fw = (void *)raw->data;
3517 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003518 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3519 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3520 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003521
Zhu Yi397ae122006-01-24 16:37:22 +08003522 if (rc < 0)
3523 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003524
3525 if (!priv->rxq)
3526 priv->rxq = ipw_rx_queue_alloc(priv);
3527 else
3528 ipw_rx_queue_reset(priv, priv->rxq);
3529 if (!priv->rxq) {
3530 IPW_ERROR("Unable to initialize Rx queue\n");
3531 goto error;
3532 }
3533
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003534 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003535 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003536 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003537 priv->status &= ~STATUS_INT_ENABLED;
3538
3539 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003540 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003541
James Ketrenos43f66a62005-03-25 12:31:53 -06003542 ipw_stop_nic(priv);
3543
3544 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003545 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003546 IPW_ERROR("Unable to reset NIC\n");
3547 goto error;
3548 }
3549
James Ketrenosb095c382005-08-24 22:04:42 -05003550 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3551 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003552
3553 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003554 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003555 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003556 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 goto error;
3558 }
3559
3560 /* kick start the device */
3561 ipw_start_nic(priv);
3562
Zhu Yic7b6a672006-01-24 16:37:05 +08003563 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003564 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3565 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003566 if (rc < 0) {
3567 IPW_ERROR("device failed to boot initial fw image\n");
3568 goto error;
3569 }
3570 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3571
Jeff Garzikbf794512005-07-31 13:07:26 -04003572 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003573 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003574
3575 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003576 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003577 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003578 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003579 goto error;
3580 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003581
James Ketrenos43f66a62005-03-25 12:31:53 -06003582 /* stop nic */
3583 ipw_stop_nic(priv);
3584
3585 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003586 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003587 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003588 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003589 goto error;
3590 }
Zhu Yi397ae122006-01-24 16:37:22 +08003591#ifdef CONFIG_PM
3592 fw_loaded = 1;
3593#endif
3594
James Ketrenos43f66a62005-03-25 12:31:53 -06003595 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3596
3597 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003598 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003599 IPW_ERROR("Unable to initialize queues\n");
3600 goto error;
3601 }
3602
3603 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003604 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003605 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003606 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003607
James Ketrenos43f66a62005-03-25 12:31:53 -06003608 /* kick start the device */
3609 ipw_start_nic(priv);
3610
James Ketrenosb095c382005-08-24 22:04:42 -05003611 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003612 if (retries > 0) {
3613 IPW_WARNING("Parity error. Retrying init.\n");
3614 retries--;
3615 goto retry;
3616 }
3617
3618 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3619 rc = -EIO;
3620 goto error;
3621 }
3622
3623 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003624 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3625 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003626 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003627 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003628 goto error;
3629 }
3630 IPW_DEBUG_INFO("device response after %dms\n", rc);
3631
3632 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003633 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003634
3635 /* read eeprom data and initialize the eeprom region of sram */
3636 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003637 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003638
3639 /* enable interrupts */
3640 ipw_enable_interrupts(priv);
3641
3642 /* Ensure our queue has valid packets */
3643 ipw_rx_queue_replenish(priv);
3644
James Ketrenosb095c382005-08-24 22:04:42 -05003645 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003646
3647 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003648 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003649
3650#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003651 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003652#endif
3653 return 0;
3654
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003655 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003656 if (priv->rxq) {
3657 ipw_rx_queue_free(priv, priv->rxq);
3658 priv->rxq = NULL;
3659 }
3660 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003661 if (raw)
3662 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003663#ifdef CONFIG_PM
3664 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003665 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003666#endif
3667
3668 return rc;
3669}
3670
Jeff Garzikbf794512005-07-31 13:07:26 -04003671/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003672 * DMA services
3673 *
3674 * Theory of operation
3675 *
3676 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3677 * 2 empty entries always kept in the buffer to protect from overflow.
3678 *
3679 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003680 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3681 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003682 * Tx queue resumed.
3683 *
3684 * The IPW operates with six queues, one receive queue in the device's
3685 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003686 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003687 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003688 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003689 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003690 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003691 * we only utilize the first data transmit queue (queue1).
3692 */
3693
3694/**
3695 * Driver allocates buffers of this size for Rx
3696 */
3697
Dan Williams943dbef2008-02-14 17:49:41 -05003698/**
3699 * ipw_rx_queue_space - Return number of free slots available in queue.
3700 */
3701static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3702{
3703 int s = q->read - q->write;
3704 if (s <= 0)
3705 s += RX_QUEUE_SIZE;
3706 /* keep some buffer to not confuse full and empty queue */
3707 s -= 2;
3708 if (s < 0)
3709 s = 0;
3710 return s;
3711}
3712
3713static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003714{
3715 int s = q->last_used - q->first_empty;
3716 if (s <= 0)
3717 s += q->n_bd;
3718 s -= 2; /* keep some reserve to not confuse empty and full situations */
3719 if (s < 0)
3720 s = 0;
3721 return s;
3722}
3723
3724static inline int ipw_queue_inc_wrap(int index, int n_bd)
3725{
3726 return (++index == n_bd) ? 0 : index;
3727}
3728
3729/**
3730 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003731 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003732 * @param q queue to init
3733 * @param count Number of BD's to allocate. Should be power of 2
3734 * @param read_register Address for 'read' register
3735 * (not offset within BAR, full address)
3736 * @param write_register Address for 'write' register
3737 * (not offset within BAR, full address)
3738 * @param base_register Address for 'base' register
3739 * (not offset within BAR, full address)
3740 * @param size Address for 'size' register
3741 * (not offset within BAR, full address)
3742 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003743static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003744 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003745{
3746 q->n_bd = count;
3747
3748 q->low_mark = q->n_bd / 4;
3749 if (q->low_mark < 4)
3750 q->low_mark = 4;
3751
3752 q->high_mark = q->n_bd / 8;
3753 if (q->high_mark < 2)
3754 q->high_mark = 2;
3755
3756 q->first_empty = q->last_used = 0;
3757 q->reg_r = read;
3758 q->reg_w = write;
3759
3760 ipw_write32(priv, base, q->dma_addr);
3761 ipw_write32(priv, size, count);
3762 ipw_write32(priv, read, 0);
3763 ipw_write32(priv, write, 0);
3764
3765 _ipw_read32(priv, 0x90);
3766}
3767
Jeff Garzikbf794512005-07-31 13:07:26 -04003768static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003769 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003770 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003771{
3772 struct pci_dev *dev = priv->pci_dev;
3773
3774 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3775 if (!q->txb) {
3776 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3777 return -ENOMEM;
3778 }
3779
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003780 q->bd =
3781 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003783 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003784 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003785 kfree(q->txb);
3786 q->txb = NULL;
3787 return -ENOMEM;
3788 }
3789
3790 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3791 return 0;
3792}
3793
3794/**
3795 * Free one TFD, those at index [txq->q.last_used].
3796 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003797 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003798 * @param dev
3799 * @param txq
3800 */
3801static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3802 struct clx2_tx_queue *txq)
3803{
3804 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3805 struct pci_dev *dev = priv->pci_dev;
3806 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003807
James Ketrenos43f66a62005-03-25 12:31:53 -06003808 /* classify bd */
3809 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3810 /* nothing to cleanup after for host commands */
3811 return;
3812
3813 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003814 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3815 IPW_ERROR("Too many chunks: %i\n",
3816 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003817 /** @todo issue fatal error, it is quite serious situation */
3818 return;
3819 }
3820
3821 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003822 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3823 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3824 le16_to_cpu(bd->u.data.chunk_len[i]),
3825 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003826 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003827 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003828 txq->txb[txq->q.last_used] = NULL;
3829 }
3830 }
3831}
3832
3833/**
3834 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003835 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003836 * Empty queue by removing and destroying all BD's.
3837 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003838 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003839 * @param dev
3840 * @param q
3841 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003842static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003843{
3844 struct clx2_queue *q = &txq->q;
3845 struct pci_dev *dev = priv->pci_dev;
3846
Jeff Garzikbf794512005-07-31 13:07:26 -04003847 if (q->n_bd == 0)
3848 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003849
3850 /* first, empty all BD's */
3851 for (; q->first_empty != q->last_used;
3852 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3853 ipw_queue_tx_free_tfd(priv, txq);
3854 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003855
James Ketrenos43f66a62005-03-25 12:31:53 -06003856 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003857 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003858 q->dma_addr);
3859 kfree(txq->txb);
3860
3861 /* 0 fill whole structure */
3862 memset(txq, 0, sizeof(*txq));
3863}
3864
James Ketrenos43f66a62005-03-25 12:31:53 -06003865/**
3866 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003867 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003868 * @param priv
3869 */
3870static void ipw_tx_queue_free(struct ipw_priv *priv)
3871{
3872 /* Tx CMD queue */
3873 ipw_queue_tx_free(priv, &priv->txq_cmd);
3874
3875 /* Tx queues */
3876 ipw_queue_tx_free(priv, &priv->txq[0]);
3877 ipw_queue_tx_free(priv, &priv->txq[1]);
3878 ipw_queue_tx_free(priv, &priv->txq[2]);
3879 ipw_queue_tx_free(priv, &priv->txq[3]);
3880}
3881
Arjan van de Ven858119e2006-01-14 13:20:43 -08003882static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003883{
3884 /* First 3 bytes are manufacturer */
3885 bssid[0] = priv->mac_addr[0];
3886 bssid[1] = priv->mac_addr[1];
3887 bssid[2] = priv->mac_addr[2];
3888
3889 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003890 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003891
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003892 bssid[0] &= 0xfe; /* clear multicast bit */
3893 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003894}
3895
Arjan van de Ven858119e2006-01-14 13:20:43 -08003896static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003897{
3898 struct ipw_station_entry entry;
3899 int i;
3900
3901 for (i = 0; i < priv->num_stations; i++) {
3902 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3903 /* Another node is active in network */
3904 priv->missed_adhoc_beacons = 0;
3905 if (!(priv->config & CFG_STATIC_CHANNEL))
3906 /* when other nodes drop out, we drop out */
3907 priv->config &= ~CFG_ADHOC_PERSIST;
3908
3909 return i;
3910 }
3911 }
3912
3913 if (i == MAX_STATIONS)
3914 return IPW_INVALID_STATION;
3915
Johannes Berge1749612008-10-27 15:59:26 -07003916 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003917
3918 entry.reserved = 0;
3919 entry.support_mode = 0;
3920 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3921 memcpy(priv->stations[i], bssid, ETH_ALEN);
3922 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003923 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003924 priv->num_stations++;
3925
3926 return i;
3927}
3928
Arjan van de Ven858119e2006-01-14 13:20:43 -08003929static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003930{
3931 int i;
3932
Jeff Garzikbf794512005-07-31 13:07:26 -04003933 for (i = 0; i < priv->num_stations; i++)
3934 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003935 return i;
3936
3937 return IPW_INVALID_STATION;
3938}
3939
3940static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3941{
3942 int err;
3943
Hong Liu7b996592005-08-25 17:36:13 +08003944 if (priv->status & STATUS_ASSOCIATING) {
3945 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3946 queue_work(priv->workqueue, &priv->disassociate);
3947 return;
3948 }
3949
3950 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003951 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3952 return;
3953 }
3954
Johannes Berge1749612008-10-27 15:59:26 -07003955 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003956 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003957 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003958 priv->assoc_request.channel);
3959
3960 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3961 priv->status |= STATUS_DISASSOCIATING;
3962
3963 if (quiet)
3964 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3965 else
3966 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003967
James Ketrenos43f66a62005-03-25 12:31:53 -06003968 err = ipw_send_associate(priv, &priv->assoc_request);
3969 if (err) {
3970 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3971 "failed.\n");
3972 return;
3973 }
3974
3975}
3976
James Ketrenosc848d0a2005-08-24 21:56:24 -05003977static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003978{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003979 struct ipw_priv *priv = data;
3980 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3981 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003982 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003983 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003984 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003985}
3986
David Howellsc4028952006-11-22 14:57:56 +00003987static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003988{
David Howellsc4028952006-11-22 14:57:56 +00003989 struct ipw_priv *priv =
3990 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003991 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003992 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003993 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003994}
3995
David Howellsc4028952006-11-22 14:57:56 +00003996static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003997{
David Howellsc4028952006-11-22 14:57:56 +00003998 struct ipw_priv *priv =
3999 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08004000
4001#ifdef CONFIG_IPW2200_PROMISCUOUS
4002 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
4003 priv->sys_config.accept_all_data_frames = 1;
4004 priv->sys_config.accept_non_directed_frames = 1;
4005 priv->sys_config.accept_all_mgmt_bcpr = 1;
4006 priv->sys_config.accept_all_mgmt_frames = 1;
4007 }
4008#endif
4009
4010 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004011}
4012
4013struct ipw_status_code {
4014 u16 status;
4015 const char *reason;
4016};
4017
4018static const struct ipw_status_code ipw_status_codes[] = {
4019 {0x00, "Successful"},
4020 {0x01, "Unspecified failure"},
4021 {0x0A, "Cannot support all requested capabilities in the "
4022 "Capability information field"},
4023 {0x0B, "Reassociation denied due to inability to confirm that "
4024 "association exists"},
4025 {0x0C, "Association denied due to reason outside the scope of this "
4026 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004027 {0x0D,
4028 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004029 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004030 {0x0E,
4031 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004032 "transaction sequence number out of expected sequence"},
4033 {0x0F, "Authentication rejected because of challenge failure"},
4034 {0x10, "Authentication rejected due to timeout waiting for next "
4035 "frame in sequence"},
4036 {0x11, "Association denied because AP is unable to handle additional "
4037 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004038 {0x12,
4039 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004040 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004041 {0x13,
4042 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004043 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004044 {0x14,
4045 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004046 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004047 {0x15,
4048 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004049 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004050 {0x19,
4051 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004052 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004053 {0x1A,
4054 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004055 "DSSS-OFDM operation"},
4056 {0x28, "Invalid Information Element"},
4057 {0x29, "Group Cipher is not valid"},
4058 {0x2A, "Pairwise Cipher is not valid"},
4059 {0x2B, "AKMP is not valid"},
4060 {0x2C, "Unsupported RSN IE version"},
4061 {0x2D, "Invalid RSN IE Capabilities"},
4062 {0x2E, "Cipher suite is rejected per security policy"},
4063};
4064
Jeff Garzikbf794512005-07-31 13:07:26 -04004065static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004066{
4067 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004068 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004069 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004070 return ipw_status_codes[i].reason;
4071 return "Unknown status value.";
4072}
James Ketrenos43f66a62005-03-25 12:31:53 -06004073
4074static void inline average_init(struct average *avg)
4075{
4076 memset(avg, 0, sizeof(*avg));
4077}
4078
Zhu Yi00d21de2006-04-13 17:19:02 +08004079#define DEPTH_RSSI 8
4080#define DEPTH_NOISE 16
4081static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4082{
4083 return ((depth-1)*prev_avg + val)/depth;
4084}
4085
Arjan van de Ven858119e2006-01-14 13:20:43 -08004086static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004087{
4088 avg->sum -= avg->entries[avg->pos];
4089 avg->sum += val;
4090 avg->entries[avg->pos++] = val;
4091 if (unlikely(avg->pos == AVG_ENTRIES)) {
4092 avg->init = 1;
4093 avg->pos = 0;
4094 }
4095}
4096
Arjan van de Ven858119e2006-01-14 13:20:43 -08004097static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004098{
4099 if (!unlikely(avg->init)) {
4100 if (avg->pos)
4101 return avg->sum / avg->pos;
4102 return 0;
4103 }
4104
4105 return avg->sum / AVG_ENTRIES;
4106}
4107
4108static void ipw_reset_stats(struct ipw_priv *priv)
4109{
4110 u32 len = sizeof(u32);
4111
4112 priv->quality = 0;
4113
4114 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004115 priv->exp_avg_rssi = -60;
4116 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004117
4118 priv->last_rate = 0;
4119 priv->last_missed_beacons = 0;
4120 priv->last_rx_packets = 0;
4121 priv->last_tx_packets = 0;
4122 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004123
James Ketrenos43f66a62005-03-25 12:31:53 -06004124 /* Firmware managed, reset only when NIC is restarted, so we have to
4125 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004126 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004127 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004128 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004129 &priv->last_tx_failures, &len);
4130
4131 /* Driver managed, reset with each association */
4132 priv->missed_adhoc_beacons = 0;
4133 priv->missed_beacons = 0;
4134 priv->tx_packets = 0;
4135 priv->rx_packets = 0;
4136
4137}
4138
Arjan van de Ven858119e2006-01-14 13:20:43 -08004139static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004140{
4141 u32 i = 0x80000000;
4142 u32 mask = priv->rates_mask;
4143 /* If currently associated in B mode, restrict the maximum
4144 * rate match to B rates */
4145 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004146 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004147
4148 /* TODO: Verify that the rate is supported by the current rates
4149 * list. */
4150
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004151 while (i && !(mask & i))
4152 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004153 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004154 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004155 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004156 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004158 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004159 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004160 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004161 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004162 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004163 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004164 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004165 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004166 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004167 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004168 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004169 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004170 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004171 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004172 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004173 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004174 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004175 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004176 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004177 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004178 }
4179
Jeff Garzikbf794512005-07-31 13:07:26 -04004180 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004181 return 11000000;
4182 else
4183 return 54000000;
4184}
4185
4186static u32 ipw_get_current_rate(struct ipw_priv *priv)
4187{
4188 u32 rate, len = sizeof(rate);
4189 int err;
4190
Jeff Garzikbf794512005-07-31 13:07:26 -04004191 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004192 return 0;
4193
4194 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004195 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004196 &len);
4197 if (err) {
4198 IPW_DEBUG_INFO("failed querying ordinals.\n");
4199 return 0;
4200 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004201 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004202 return ipw_get_max_rate(priv);
4203
4204 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004205 case IPW_TX_RATE_1MB:
4206 return 1000000;
4207 case IPW_TX_RATE_2MB:
4208 return 2000000;
4209 case IPW_TX_RATE_5MB:
4210 return 5500000;
4211 case IPW_TX_RATE_6MB:
4212 return 6000000;
4213 case IPW_TX_RATE_9MB:
4214 return 9000000;
4215 case IPW_TX_RATE_11MB:
4216 return 11000000;
4217 case IPW_TX_RATE_12MB:
4218 return 12000000;
4219 case IPW_TX_RATE_18MB:
4220 return 18000000;
4221 case IPW_TX_RATE_24MB:
4222 return 24000000;
4223 case IPW_TX_RATE_36MB:
4224 return 36000000;
4225 case IPW_TX_RATE_48MB:
4226 return 48000000;
4227 case IPW_TX_RATE_54MB:
4228 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004229 }
4230
4231 return 0;
4232}
4233
James Ketrenos43f66a62005-03-25 12:31:53 -06004234#define IPW_STATS_INTERVAL (2 * HZ)
4235static void ipw_gather_stats(struct ipw_priv *priv)
4236{
4237 u32 rx_err, rx_err_delta, rx_packets_delta;
4238 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4239 u32 missed_beacons_percent, missed_beacons_delta;
4240 u32 quality = 0;
4241 u32 len = sizeof(u32);
4242 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004243 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004244 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004245 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004246
4247 if (!(priv->status & STATUS_ASSOCIATED)) {
4248 priv->quality = 0;
4249 return;
4250 }
4251
4252 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004253 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004254 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004255 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004256 priv->last_missed_beacons = priv->missed_beacons;
4257 if (priv->assoc_request.beacon_interval) {
4258 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004259 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004260 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004261 } else {
4262 missed_beacons_percent = 0;
4263 }
4264 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4265
4266 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4267 rx_err_delta = rx_err - priv->last_rx_err;
4268 priv->last_rx_err = rx_err;
4269
4270 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4271 tx_failures_delta = tx_failures - priv->last_tx_failures;
4272 priv->last_tx_failures = tx_failures;
4273
4274 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4275 priv->last_rx_packets = priv->rx_packets;
4276
4277 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4278 priv->last_tx_packets = priv->tx_packets;
4279
4280 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004281 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004282 * Missed beacon: 100% = 0, 0% = 70% missed
4283 * Rate: 60% = 1Mbs, 100% = Max
4284 * Rx and Tx errors represent a straight % of total Rx/Tx
4285 * RSSI: 100% = > -50, 0% = < -80
4286 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004287 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004288 * The lowest computed quality is used.
4289 *
4290 */
4291#define BEACON_THRESHOLD 5
4292 beacon_quality = 100 - missed_beacons_percent;
4293 if (beacon_quality < BEACON_THRESHOLD)
4294 beacon_quality = 0;
4295 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004296 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004297 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004298 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004299 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004300
James Ketrenos43f66a62005-03-25 12:31:53 -06004301 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004302 max_rate = ipw_get_max_rate(priv);
4303 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004304 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4305 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004306
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004307 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004308 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004309 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004310 else
4311 rx_quality = 100;
4312 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4313 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004314
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004315 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004316 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004317 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004318 else
4319 tx_quality = 100;
4320 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4321 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004322
Zhu Yi00d21de2006-04-13 17:19:02 +08004323 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004324 signal_quality =
4325 (100 *
4326 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4327 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4328 (priv->ieee->perfect_rssi - rssi) *
4329 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4330 62 * (priv->ieee->perfect_rssi - rssi))) /
4331 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4332 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4333 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004334 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004335 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004336 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004337
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004338 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004339 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004340
Reinette Chatre21f8a732009-08-18 10:25:05 -07004341 quality = min(rx_quality, signal_quality);
4342 quality = min(tx_quality, quality);
4343 quality = min(rate_quality, quality);
4344 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004345 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004346 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4347 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004348 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004349 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4350 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004351 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004352 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4353 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004354 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004355 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4356 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004357 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004358 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4359 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004360
4361 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004362
4363 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004364 IPW_STATS_INTERVAL);
4365}
4366
David Howellsc4028952006-11-22 14:57:56 +00004367static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004368{
David Howellsc4028952006-11-22 14:57:56 +00004369 struct ipw_priv *priv =
4370 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004371 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004372 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004373 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004374}
4375
Ben Cahille7582562005-10-06 15:34:41 -05004376/* Missed beacon behavior:
4377 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4378 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4379 * Above disassociate threshold, give up and stop scanning.
4380 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004381static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004382 int missed_count)
4383{
4384 priv->notif_missed_beacons = missed_count;
4385
James Ketrenosafbf30a2005-08-25 00:05:33 -05004386 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004387 priv->status & STATUS_ASSOCIATED) {
4388 /* If associated and we've hit the missed
4389 * beacon threshold, disassociate, turn
4390 * off roaming, and abort any active scans */
4391 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004392 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004393 "Missed beacon: %d - disassociate\n", missed_count);
4394 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004395 if (priv->status & STATUS_SCANNING) {
4396 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4397 IPW_DL_STATE,
4398 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004399 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004400 }
4401
James Ketrenosea2b26e2005-08-24 21:25:16 -05004402 queue_work(priv->workqueue, &priv->disassociate);
4403 return;
4404 }
4405
4406 if (priv->status & STATUS_ROAMING) {
4407 /* If we are currently roaming, then just
4408 * print a debug statement... */
4409 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4410 "Missed beacon: %d - roam in progress\n",
4411 missed_count);
4412 return;
4413 }
4414
Zhu Yi4bfdb912006-01-24 16:37:16 +08004415 if (roaming &&
4416 (missed_count > priv->roaming_threshold &&
4417 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004418 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004419 * bit in the status and kick off a scan.
4420 * This can happen several times before we reach
4421 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004422 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4423 "Missed beacon: %d - initiate "
4424 "roaming\n", missed_count);
4425 if (!(priv->status & STATUS_ROAMING)) {
4426 priv->status |= STATUS_ROAMING;
4427 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004428 queue_delayed_work(priv->workqueue,
4429 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004430 }
4431 return;
4432 }
4433
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004434 if (priv->status & STATUS_SCANNING &&
4435 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004436 /* Stop scan to keep fw from getting
4437 * stuck (only if we aren't roaming --
4438 * otherwise we'll never scan more than 2 or 3
4439 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004440 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4441 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004442 queue_work(priv->workqueue, &priv->abort_scan);
4443 }
4444
4445 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004446}
4447
Dan Williams0b531672007-10-09 13:55:24 -04004448static void ipw_scan_event(struct work_struct *work)
4449{
4450 union iwreq_data wrqu;
4451
4452 struct ipw_priv *priv =
4453 container_of(work, struct ipw_priv, scan_event.work);
4454
4455 wrqu.data.length = 0;
4456 wrqu.data.flags = 0;
4457 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4458}
4459
4460static void handle_scan_event(struct ipw_priv *priv)
4461{
4462 /* Only userspace-requested scan completion events go out immediately */
4463 if (!priv->user_requested_scan) {
4464 if (!delayed_work_pending(&priv->scan_event))
4465 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004466 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004467 } else {
4468 union iwreq_data wrqu;
4469
4470 priv->user_requested_scan = 0;
4471 cancel_delayed_work(&priv->scan_event);
4472
4473 wrqu.data.length = 0;
4474 wrqu.data.flags = 0;
4475 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4476 }
4477}
4478
James Ketrenos43f66a62005-03-25 12:31:53 -06004479/**
4480 * Handle host notification packet.
4481 * Called from interrupt routine
4482 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004483static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004484 struct ipw_rx_notification *notif)
4485{
John W. Linville9387b7c2008-09-30 20:59:05 -04004486 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004487 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004488
Al Viroe62e1ee2007-12-27 01:36:46 -05004489 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004490
James Ketrenos43f66a62005-03-25 12:31:53 -06004491 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004492 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4493 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004494
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004495 switch (assoc->state) {
4496 case CMAS_ASSOCIATED:{
4497 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4498 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004499 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004500 print_ssid(ssid, priv->essid,
4501 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004502 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004503
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004504 switch (priv->ieee->iw_mode) {
4505 case IW_MODE_INFRA:
4506 memcpy(priv->ieee->bssid,
4507 priv->bssid, ETH_ALEN);
4508 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004509
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004510 case IW_MODE_ADHOC:
4511 memcpy(priv->ieee->bssid,
4512 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004513
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004514 /* clear out the station table */
4515 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004516
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004517 IPW_DEBUG_ASSOC
4518 ("queueing adhoc check\n");
4519 queue_delayed_work(priv->
4520 workqueue,
4521 &priv->
4522 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004523 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004524 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004525 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004526 break;
4527 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004528
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004529 priv->status &= ~STATUS_ASSOCIATING;
4530 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004531 queue_work(priv->workqueue,
4532 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004533
Zhu Yie43e3c12006-04-13 17:20:45 +08004534#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004535#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004536 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004537 if ((priv->status & STATUS_AUTH) &&
4538 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4539 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004540 if ((sizeof
4541 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004542 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004543 <= size)
4544 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004545 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004546 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004547 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004548 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004549 };
4550
4551 IPW_DEBUG_QOS
4552 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004553 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004554 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004555 ieee,
4556 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004557 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004558 *)
4559 &notif->u.raw, &stats);
4560 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004561 }
James Ketrenosb095c382005-08-24 22:04:42 -05004562#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004563
James Ketrenosa613bff2005-08-24 21:43:11 -05004564 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004565
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004566 break;
4567 }
4568
4569 case CMAS_AUTHENTICATED:{
4570 if (priv->
4571 status & (STATUS_ASSOCIATED |
4572 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004573 struct notif_authenticate *auth
4574 = &notif->u.auth;
4575 IPW_DEBUG(IPW_DL_NOTIF |
4576 IPW_DL_STATE |
4577 IPW_DL_ASSOC,
4578 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004579 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004580 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004581 print_ssid(ssid,
4582 priv->
4583 essid,
4584 priv->
4585 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004586 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004587 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004588 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004589 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004590 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004591
4592 priv->status &=
4593 ~(STATUS_ASSOCIATING |
4594 STATUS_AUTH |
4595 STATUS_ASSOCIATED);
4596
James Ketrenosa613bff2005-08-24 21:43:11 -05004597 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004598 break;
4599 }
4600
4601 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4602 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004603 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004604 print_ssid(ssid, priv->essid,
4605 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004606 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004607 break;
4608 }
4609
4610 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004611 if (priv->status & STATUS_AUTH) {
4612 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004613 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004614 *resp;
4615 resp =
4616 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004617 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004618 *)&notif->u.raw;
4619 IPW_DEBUG(IPW_DL_NOTIF |
4620 IPW_DL_STATE |
4621 IPW_DL_ASSOC,
4622 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004623 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004624 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004625 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004626 (resp->status)));
4627 }
4628
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004629 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4630 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004631 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004632 print_ssid(ssid, priv->essid,
4633 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004634 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004635
4636 priv->status &=
4637 ~(STATUS_DISASSOCIATING |
4638 STATUS_ASSOCIATING |
4639 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004640 if (priv->assoc_network
4641 && (priv->assoc_network->
4642 capability &
4643 WLAN_CAPABILITY_IBSS))
4644 ipw_remove_current_network
4645 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004646
James Ketrenosa613bff2005-08-24 21:43:11 -05004647 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004648
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004649 break;
4650 }
4651
James Ketrenosb095c382005-08-24 22:04:42 -05004652 case CMAS_RX_ASSOC_RESP:
4653 break;
4654
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004655 default:
4656 IPW_ERROR("assoc: unknown (%d)\n",
4657 assoc->state);
4658 break;
4659 }
4660
James Ketrenos43f66a62005-03-25 12:31:53 -06004661 break;
4662 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004663
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004664 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4665 struct notif_authenticate *auth = &notif->u.auth;
4666 switch (auth->state) {
4667 case CMAS_AUTHENTICATED:
4668 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004669 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004670 print_ssid(ssid, priv->essid,
4671 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004672 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004673 priv->status |= STATUS_AUTH;
4674 break;
4675
4676 case CMAS_INIT:
4677 if (priv->status & STATUS_AUTH) {
4678 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4679 IPW_DL_ASSOC,
4680 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004681 le16_to_cpu(auth->status),
4682 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004683 (auth->
4684 status)));
4685 }
4686 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4687 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004688 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004689 print_ssid(ssid, priv->essid,
4690 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004691 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004692
4693 priv->status &= ~(STATUS_ASSOCIATING |
4694 STATUS_AUTH |
4695 STATUS_ASSOCIATED);
4696
James Ketrenosa613bff2005-08-24 21:43:11 -05004697 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004698 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004699
4700 case CMAS_TX_AUTH_SEQ_1:
4701 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4702 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4703 break;
4704 case CMAS_RX_AUTH_SEQ_2:
4705 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4706 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4707 break;
4708 case CMAS_AUTH_SEQ_1_PASS:
4709 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4710 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4711 break;
4712 case CMAS_AUTH_SEQ_1_FAIL:
4713 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4714 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4715 break;
4716 case CMAS_TX_AUTH_SEQ_3:
4717 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4718 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4719 break;
4720 case CMAS_RX_AUTH_SEQ_4:
4721 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4722 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4723 break;
4724 case CMAS_AUTH_SEQ_2_PASS:
4725 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4726 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4727 break;
4728 case CMAS_AUTH_SEQ_2_FAIL:
4729 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4730 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4731 break;
4732 case CMAS_TX_ASSOC:
4733 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4734 IPW_DL_ASSOC, "TX_ASSOC\n");
4735 break;
4736 case CMAS_RX_ASSOC_RESP:
4737 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4738 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004739
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004740 break;
4741 case CMAS_ASSOCIATED:
4742 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4743 IPW_DL_ASSOC, "ASSOCIATED\n");
4744 break;
4745 default:
4746 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4747 auth->state);
4748 break;
4749 }
4750 break;
4751 }
4752
4753 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4754 struct notif_channel_result *x =
4755 &notif->u.channel_result;
4756
Al Viroe62e1ee2007-12-27 01:36:46 -05004757 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004758 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4759 x->channel_num);
4760 } else {
4761 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4762 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004763 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004764 }
4765 break;
4766 }
4767
4768 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4769 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004770 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004771 IPW_DEBUG_SCAN
4772 ("Scan completed: type %d, %d channels, "
4773 "%d status\n", x->scan_type,
4774 x->num_channels, x->status);
4775 } else {
4776 IPW_ERROR("Scan completed of wrong size %d "
4777 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004778 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004779 }
4780
4781 priv->status &=
4782 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4783
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004784 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004785 cancel_delayed_work(&priv->scan_check);
4786
James Ketrenosb095c382005-08-24 22:04:42 -05004787 if (priv->status & STATUS_EXIT_PENDING)
4788 break;
4789
4790 priv->ieee->scans++;
4791
4792#ifdef CONFIG_IPW2200_MONITOR
4793 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004794 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004795 queue_delayed_work(priv->workqueue,
4796 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004797 break;
4798 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004799 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004800#endif /* CONFIG_IPW2200_MONITOR */
4801
Dan Williamsea177302008-06-02 17:51:23 -04004802 /* Do queued direct scans first */
4803 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4804 queue_delayed_work(priv->workqueue,
4805 &priv->request_direct_scan, 0);
4806 }
4807
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004808 if (!(priv->status & (STATUS_ASSOCIATED |
4809 STATUS_ASSOCIATING |
4810 STATUS_ROAMING |
4811 STATUS_DISASSOCIATING)))
4812 queue_work(priv->workqueue, &priv->associate);
4813 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004814 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4815 /* If a scan completed and we are in roam mode, then
4816 * the scan that completed was the one requested as a
4817 * result of entering roam... so, schedule the
4818 * roam work */
4819 queue_work(priv->workqueue,
4820 &priv->roam);
4821 else
4822 /* Don't schedule if we aborted the scan */
4823 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004824 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004825 queue_delayed_work(priv->workqueue,
4826 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004827 else if (priv->config & CFG_BACKGROUND_SCAN
4828 && priv->status & STATUS_ASSOCIATED)
4829 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004830 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004831 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004832
4833 /* Send an empty event to user space.
4834 * We don't send the received data on the event because
4835 * it would require us to do complex transcoding, and
4836 * we want to minimise the work done in the irq handler
4837 * Use a request to extract the data.
4838 * Also, we generate this even for any scan, regardless
4839 * on how the scan was initiated. User space can just
4840 * sync on periodic scan to get fresh data...
4841 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004842 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4843 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004844 break;
4845 }
4846
4847 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4848 struct notif_frag_length *x = &notif->u.frag_len;
4849
Al Viroe62e1ee2007-12-27 01:36:46 -05004850 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004851 IPW_ERROR("Frag length: %d\n",
4852 le16_to_cpu(x->frag_length));
4853 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004854 IPW_ERROR("Frag length of wrong size %d "
4855 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004856 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004857 break;
4858 }
4859
4860 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4861 struct notif_link_deterioration *x =
4862 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004863
Al Viroe62e1ee2007-12-27 01:36:46 -05004864 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004865 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004866 "link deterioration: type %d, cnt %d\n",
4867 x->silence_notification_type,
4868 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004869 memcpy(&priv->last_link_deterioration, x,
4870 sizeof(*x));
4871 } else {
4872 IPW_ERROR("Link Deterioration of wrong size %d "
4873 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004874 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004875 }
4876 break;
4877 }
4878
4879 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4880 IPW_ERROR("Dino config\n");
4881 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004882 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004883 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004884
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 break;
4886 }
4887
4888 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4889 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004890 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004891 IPW_ERROR
4892 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004893 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004894 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004895 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004896
James Ketrenosa613bff2005-08-24 21:43:11 -05004897 if (le32_to_cpu(x->state) ==
4898 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4899 ipw_handle_missed_beacon(priv,
4900 le32_to_cpu(x->
4901 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004902
James Ketrenos43f66a62005-03-25 12:31:53 -06004903 break;
4904 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004905
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004906 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4907 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004908 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004909 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4910 "0x%02x station %d\n",
4911 x->key_state, x->security_type,
4912 x->station_index);
4913 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004914 }
4915
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004916 IPW_ERROR
4917 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004918 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004919 break;
4920 }
4921
4922 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4923 struct notif_calibration *x = &notif->u.calibration;
4924
Al Viroe62e1ee2007-12-27 01:36:46 -05004925 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004926 memcpy(&priv->calib, x, sizeof(*x));
4927 IPW_DEBUG_INFO("TODO: Calibration\n");
4928 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004929 }
4930
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004931 IPW_ERROR
4932 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004933 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004934 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004935 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004936
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004937 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004938 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004939 priv->exp_avg_noise =
4940 exponential_average(priv->exp_avg_noise,
4941 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4942 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004943 break;
4944 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004945
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004946 IPW_ERROR
4947 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004948 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004949 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004950 }
4951
James Ketrenos43f66a62005-03-25 12:31:53 -06004952 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004953 IPW_DEBUG_NOTIF("Unknown notification: "
4954 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004955 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004956 }
4957}
4958
4959/**
4960 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004961 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004962 * @param priv
4963 * @return error code
4964 */
4965static int ipw_queue_reset(struct ipw_priv *priv)
4966{
4967 int rc = 0;
4968 /** @todo customize queue sizes */
4969 int nTx = 64, nTxCmd = 8;
4970 ipw_tx_queue_free(priv);
4971 /* Tx CMD queue */
4972 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004973 IPW_TX_CMD_QUEUE_READ_INDEX,
4974 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4975 IPW_TX_CMD_QUEUE_BD_BASE,
4976 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004977 if (rc) {
4978 IPW_ERROR("Tx Cmd queue init failed\n");
4979 goto error;
4980 }
4981 /* Tx queue(s) */
4982 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004983 IPW_TX_QUEUE_0_READ_INDEX,
4984 IPW_TX_QUEUE_0_WRITE_INDEX,
4985 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004986 if (rc) {
4987 IPW_ERROR("Tx 0 queue init failed\n");
4988 goto error;
4989 }
4990 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004991 IPW_TX_QUEUE_1_READ_INDEX,
4992 IPW_TX_QUEUE_1_WRITE_INDEX,
4993 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004994 if (rc) {
4995 IPW_ERROR("Tx 1 queue init failed\n");
4996 goto error;
4997 }
4998 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004999 IPW_TX_QUEUE_2_READ_INDEX,
5000 IPW_TX_QUEUE_2_WRITE_INDEX,
5001 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005002 if (rc) {
5003 IPW_ERROR("Tx 2 queue init failed\n");
5004 goto error;
5005 }
5006 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05005007 IPW_TX_QUEUE_3_READ_INDEX,
5008 IPW_TX_QUEUE_3_WRITE_INDEX,
5009 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005010 if (rc) {
5011 IPW_ERROR("Tx 3 queue init failed\n");
5012 goto error;
5013 }
5014 /* statistics */
5015 priv->rx_bufs_min = 0;
5016 priv->rx_pend_max = 0;
5017 return rc;
5018
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005019 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005020 ipw_tx_queue_free(priv);
5021 return rc;
5022}
5023
5024/**
5025 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005026 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005027 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 * new 'R' index need to be reclaimed. As result, some free space
5029 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005030 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005031 * @note Need to protect against garbage in 'R' index
5032 * @param priv
5033 * @param txq
5034 * @param qindex
5035 * @return Number of used entries remains in the queue
5036 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005037static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005038 struct clx2_tx_queue *txq, int qindex)
5039{
5040 u32 hw_tail;
5041 int used;
5042 struct clx2_queue *q = &txq->q;
5043
5044 hw_tail = ipw_read32(priv, q->reg_r);
5045 if (hw_tail >= q->n_bd) {
5046 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005047 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5048 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005049 goto done;
5050 }
5051 for (; q->last_used != hw_tail;
5052 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5053 ipw_queue_tx_free_tfd(priv, txq);
5054 priv->tx_packets++;
5055 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005056 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005057 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005058 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005059 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005060 used = q->first_empty - q->last_used;
5061 if (used < 0)
5062 used += q->n_bd;
5063
5064 return used;
5065}
5066
5067static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5068 int len, int sync)
5069{
5070 struct clx2_tx_queue *txq = &priv->txq_cmd;
5071 struct clx2_queue *q = &txq->q;
5072 struct tfd_frame *tfd;
5073
Dan Williams943dbef2008-02-14 17:49:41 -05005074 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005075 IPW_ERROR("No space for Tx\n");
5076 return -EBUSY;
5077 }
5078
5079 tfd = &txq->bd[q->first_empty];
5080 txq->txb[q->first_empty] = NULL;
5081
5082 memset(tfd, 0, sizeof(*tfd));
5083 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5084 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5085 priv->hcmd_seq++;
5086 tfd->u.cmd.index = hcmd;
5087 tfd->u.cmd.length = len;
5088 memcpy(tfd->u.cmd.payload, buf, len);
5089 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5090 ipw_write32(priv, q->reg_w, q->first_empty);
5091 _ipw_read32(priv, 0x90);
5092
5093 return 0;
5094}
5095
Jeff Garzikbf794512005-07-31 13:07:26 -04005096/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005097 * Rx theory of operation
5098 *
5099 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005100 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005101 * 0 to 31
5102 *
5103 * Rx Queue Indexes
5104 * The host/firmware share two index registers for managing the Rx buffers.
5105 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005106 * The READ index maps to the first position that the firmware may be writing
5107 * to -- the driver can read up to (but not including) this position and get
5108 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005109 * The READ index is managed by the firmware once the card is enabled.
5110 *
5111 * The WRITE index maps to the last position the driver has read from -- the
5112 * position preceding WRITE is the last slot the firmware can place a packet.
5113 *
5114 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005115 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005117 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005118 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5119 *
5120 * When the firmware places a packet in a buffer it will advance the READ index
5121 * and fire the RX interrupt. The driver can then query the READ index and
5122 * process as many packets as possible, moving the WRITE index forward as it
5123 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005124 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005125 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005126 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005127 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005128 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005129 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5130 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5131 * 'processed' and 'read' driver indexes as well)
5132 * + A received packet is processed and handed to the kernel network stack,
5133 * detached from the ipw->rxq. The driver 'processed' index is updated.
5134 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005135 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5136 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005137 * were enough free buffers and RX_STALLED is set it is cleared.
5138 *
5139 *
5140 * Driver sequence:
5141 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005142 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005143 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5144 * ipw_rx_queue_restock
5145 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5146 * queue, updates firmware pointers, and updates
5147 * the WRITE index. If insufficient rx_free buffers
5148 * are available, schedules ipw_rx_queue_replenish
5149 *
5150 * -- enable interrupts --
5151 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005153 * Moves the packet buffer from queue to rx_used.
5154 * Calls ipw_rx_queue_restock to refill any empty
5155 * slots.
5156 * ...
5157 *
5158 */
5159
Jeff Garzikbf794512005-07-31 13:07:26 -04005160/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005161 * If there are slots in the RX queue that need to be restocked,
5162 * and we have free pre-allocated buffers, fill the ranks as much
5163 * as we can pulling from rx_free.
5164 *
5165 * This moves the 'write' index forward to catch up with 'processed', and
5166 * also updates the memory address in the firmware to reference the new
5167 * target buffer.
5168 */
5169static void ipw_rx_queue_restock(struct ipw_priv *priv)
5170{
5171 struct ipw_rx_queue *rxq = priv->rxq;
5172 struct list_head *element;
5173 struct ipw_rx_mem_buffer *rxb;
5174 unsigned long flags;
5175 int write;
5176
5177 spin_lock_irqsave(&rxq->lock, flags);
5178 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005179 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005180 element = rxq->rx_free.next;
5181 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5182 list_del(element);
5183
James Ketrenosb095c382005-08-24 22:04:42 -05005184 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005185 rxb->dma_addr);
5186 rxq->queue[rxq->write] = rxb;
5187 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5188 rxq->free_count--;
5189 }
5190 spin_unlock_irqrestore(&rxq->lock, flags);
5191
Jeff Garzikbf794512005-07-31 13:07:26 -04005192 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005193 * refill it */
5194 if (rxq->free_count <= RX_LOW_WATERMARK)
5195 queue_work(priv->workqueue, &priv->rx_replenish);
5196
5197 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005198 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005199 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005200}
5201
5202/*
5203 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005204 * Also restock the Rx queue via ipw_rx_queue_restock.
5205 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005206 * This is called as a scheduled work item (except for during intialization)
5207 */
5208static void ipw_rx_queue_replenish(void *data)
5209{
5210 struct ipw_priv *priv = data;
5211 struct ipw_rx_queue *rxq = priv->rxq;
5212 struct list_head *element;
5213 struct ipw_rx_mem_buffer *rxb;
5214 unsigned long flags;
5215
5216 spin_lock_irqsave(&rxq->lock, flags);
5217 while (!list_empty(&rxq->rx_used)) {
5218 element = rxq->rx_used.next;
5219 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005220 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005221 if (!rxb->skb) {
5222 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5223 priv->net_dev->name);
5224 /* We don't reschedule replenish work here -- we will
5225 * call the restock method and if it still needs
5226 * more buffers it will schedule replenish */
5227 break;
5228 }
5229 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005230
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005231 rxb->dma_addr =
5232 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005233 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005234
James Ketrenos43f66a62005-03-25 12:31:53 -06005235 list_add_tail(&rxb->list, &rxq->rx_free);
5236 rxq->free_count++;
5237 }
5238 spin_unlock_irqrestore(&rxq->lock, flags);
5239
5240 ipw_rx_queue_restock(priv);
5241}
5242
David Howellsc4028952006-11-22 14:57:56 +00005243static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005244{
David Howellsc4028952006-11-22 14:57:56 +00005245 struct ipw_priv *priv =
5246 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005247 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005248 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005249 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005250}
5251
James Ketrenos43f66a62005-03-25 12:31:53 -06005252/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005253 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005254 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005255 * non NULL it is unmapped and freed
5256 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005257static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005258{
5259 int i;
5260
5261 if (!rxq)
5262 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005263
James Ketrenos43f66a62005-03-25 12:31:53 -06005264 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5265 if (rxq->pool[i].skb != NULL) {
5266 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005267 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005268 dev_kfree_skb(rxq->pool[i].skb);
5269 }
5270 }
5271
5272 kfree(rxq);
5273}
5274
5275static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5276{
5277 struct ipw_rx_queue *rxq;
5278 int i;
5279
Takisc75f4742005-12-01 01:41:45 -08005280 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005281 if (unlikely(!rxq)) {
5282 IPW_ERROR("memory allocation failed\n");
5283 return NULL;
5284 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005285 spin_lock_init(&rxq->lock);
5286 INIT_LIST_HEAD(&rxq->rx_free);
5287 INIT_LIST_HEAD(&rxq->rx_used);
5288
5289 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005290 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005291 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5292
5293 /* Set us so that we have processed and used all buffers, but have
5294 * not restocked the Rx queue with fresh buffers */
5295 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005296 rxq->free_count = 0;
5297
5298 return rxq;
5299}
5300
5301static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5302{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005303 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005304 if (ieee_mode == IEEE_A) {
5305 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005306 case LIBIPW_OFDM_RATE_6MB:
5307 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005308 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005309 case LIBIPW_OFDM_RATE_9MB:
5310 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005311 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005312 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005313 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005314 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5315 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005316 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005317 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5318 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005319 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005320 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5321 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005322 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005323 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5324 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005325 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005326 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5327 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005328 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005329 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005330 default:
5331 return 0;
5332 }
5333 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005334
James Ketrenos43f66a62005-03-25 12:31:53 -06005335 /* B and G mixed */
5336 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005337 case LIBIPW_CCK_RATE_1MB:
5338 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5339 case LIBIPW_CCK_RATE_2MB:
5340 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5341 case LIBIPW_CCK_RATE_5MB:
5342 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5343 case LIBIPW_CCK_RATE_11MB:
5344 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005345 }
5346
5347 /* If we are limited to B modulations, bail at this point */
5348 if (ieee_mode == IEEE_B)
5349 return 0;
5350
5351 /* G */
5352 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005353 case LIBIPW_OFDM_RATE_6MB:
5354 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5355 case LIBIPW_OFDM_RATE_9MB:
5356 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5357 case LIBIPW_OFDM_RATE_12MB:
5358 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5359 case LIBIPW_OFDM_RATE_18MB:
5360 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5361 case LIBIPW_OFDM_RATE_24MB:
5362 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5363 case LIBIPW_OFDM_RATE_36MB:
5364 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5365 case LIBIPW_OFDM_RATE_48MB:
5366 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5367 case LIBIPW_OFDM_RATE_54MB:
5368 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005369 }
5370
5371 return 0;
5372}
5373
Jeff Garzikbf794512005-07-31 13:07:26 -04005374static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005375 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005376 struct ipw_supported_rates *rates)
5377{
5378 int num_rates, i;
5379
5380 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005381 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005382 rates->num_rates = 0;
5383 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005384 if (!ipw_is_rate_in_mask(priv, network->mode,
5385 network->rates[i])) {
5386
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005387 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005388 IPW_DEBUG_SCAN("Adding masked mandatory "
5389 "rate %02X\n",
5390 network->rates[i]);
5391 rates->supported_rates[rates->num_rates++] =
5392 network->rates[i];
5393 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005394 }
5395
James Ketrenos43f66a62005-03-25 12:31:53 -06005396 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5397 network->rates[i], priv->rates_mask);
5398 continue;
5399 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005400
James Ketrenos43f66a62005-03-25 12:31:53 -06005401 rates->supported_rates[rates->num_rates++] = network->rates[i];
5402 }
5403
James Ketrenosa613bff2005-08-24 21:43:11 -05005404 num_rates = min(network->rates_ex_len,
5405 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005406 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005407 if (!ipw_is_rate_in_mask(priv, network->mode,
5408 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005409 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005410 IPW_DEBUG_SCAN("Adding masked mandatory "
5411 "rate %02X\n",
5412 network->rates_ex[i]);
5413 rates->supported_rates[rates->num_rates++] =
5414 network->rates[i];
5415 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005416 }
5417
James Ketrenos43f66a62005-03-25 12:31:53 -06005418 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5419 network->rates_ex[i], priv->rates_mask);
5420 continue;
5421 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005422
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005423 rates->supported_rates[rates->num_rates++] =
5424 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005425 }
5426
James Ketrenosea2b26e2005-08-24 21:25:16 -05005427 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005428}
5429
Arjan van de Ven858119e2006-01-14 13:20:43 -08005430static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005431 const struct ipw_supported_rates *src)
5432{
5433 u8 i;
5434 for (i = 0; i < src->num_rates; i++)
5435 dest->supported_rates[i] = src->supported_rates[i];
5436 dest->num_rates = src->num_rates;
5437}
5438
5439/* TODO: Look at sniffed packets in the air to determine if the basic rate
5440 * mask should ever be used -- right now all callers to add the scan rates are
5441 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5442static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005443 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005444{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005445 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5446 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005447
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 if (rate_mask & LIBIPW_CCK_RATE_1MB_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_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005451
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005452 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005453 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005454 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005455
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005456 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005457 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005459
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005460 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005461 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005462 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005463}
5464
5465static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005466 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005467{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005468 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5469 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005470
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005471 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005472 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005473 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005474
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005475 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005476 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005477 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005478
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005479 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005480 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005481 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005482
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005483 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005484 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005485 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005486
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005487 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005488 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005489 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005490
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005491 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005492 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005493 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005494
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005495 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005496 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005497 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005498
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005499 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005500 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005501 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005502}
5503
5504struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005505 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005506 struct ipw_supported_rates rates;
5507};
5508
James Ketrenosc848d0a2005-08-24 21:56:24 -05005509static int ipw_find_adhoc_network(struct ipw_priv *priv,
5510 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005511 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005512 int roaming)
5513{
5514 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005515 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005516
5517 /* Verify that this network's capability is compatible with the
5518 * current mode (AdHoc or Infrastructure) */
5519 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5520 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005521 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005522 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005523 print_ssid(ssid, network->ssid,
5524 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005525 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005526 return 0;
5527 }
5528
James Ketrenosc848d0a2005-08-24 21:56:24 -05005529 if (unlikely(roaming)) {
5530 /* If we are roaming, then ensure check if this is a valid
5531 * network to try and roam to */
5532 if ((network->ssid_len != match->network->ssid_len) ||
5533 memcmp(network->ssid, match->network->ssid,
5534 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005535 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005536 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005537 print_ssid(ssid, network->ssid,
5538 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005539 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005540 return 0;
5541 }
5542 } else {
5543 /* If an ESSID has been configured then compare the broadcast
5544 * ESSID to ours */
5545 if ((priv->config & CFG_STATIC_ESSID) &&
5546 ((network->ssid_len != priv->essid_len) ||
5547 memcmp(network->ssid, priv->essid,
5548 min(network->ssid_len, priv->essid_len)))) {
5549 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005550
James Ketrenosc848d0a2005-08-24 21:56:24 -05005551 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005552 print_ssid(ssid, network->ssid,
5553 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005554 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005555 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005556 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005557 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005558 print_ssid(ssid, priv->essid,
5559 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005560 return 0;
5561 }
5562 }
5563
5564 /* If the old network rate is better than this one, don't bother
5565 * testing everything else. */
5566
5567 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005568 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5569 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005570 print_ssid(ssid, match->network->ssid,
5571 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005572 return 0;
5573 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005574 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5575 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005576 print_ssid(ssid, match->network->ssid,
5577 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005578 return 0;
5579 }
5580
5581 /* Now go through and see if the requested network is valid... */
5582 if (priv->ieee->scan_age != 0 &&
5583 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005584 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005585 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005586 print_ssid(ssid, network->ssid,
5587 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005588 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005589 jiffies_to_msecs(jiffies -
5590 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005591 return 0;
5592 }
5593
5594 if ((priv->config & CFG_STATIC_CHANNEL) &&
5595 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005596 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005597 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005598 print_ssid(ssid, network->ssid,
5599 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005600 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005601 network->channel, priv->channel);
5602 return 0;
5603 }
5604
5605 /* Verify privacy compatability */
5606 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5607 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005608 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005609 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005610 print_ssid(ssid, network->ssid,
5611 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005612 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005613 priv->
5614 capability & CAP_PRIVACY_ON ? "on" : "off",
5615 network->
5616 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5617 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005618 return 0;
5619 }
5620
5621 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005622 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5623 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005624 ".\n", print_ssid(ssid, network->ssid,
5625 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005626 network->bssid,
5627 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005628 return 0;
5629 }
5630
5631 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005632 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005633 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005634 "because of invalid frequency/mode "
5635 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005636 print_ssid(ssid, network->ssid,
5637 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005638 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005639 return 0;
5640 }
5641
5642 /* Ensure that the rates supported by the driver are compatible with
5643 * this AP, including verification of basic rates (mandatory) */
5644 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005645 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005646 "because configured rate mask excludes "
5647 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005648 print_ssid(ssid, network->ssid,
5649 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005650 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005651 return 0;
5652 }
5653
5654 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005655 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005656 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005657 print_ssid(ssid, network->ssid,
5658 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005659 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005660 return 0;
5661 }
5662
5663 /* TODO: Perform any further minimal comparititive tests. We do not
5664 * want to put too much policy logic here; intelligent scan selection
5665 * should occur within a generic IEEE 802.11 user space tool. */
5666
5667 /* Set up 'new' AP to this network */
5668 ipw_copy_rates(&match->rates, &rates);
5669 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005670 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005671 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005672 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005673
5674 return 1;
5675}
5676
David Howellsc4028952006-11-22 14:57:56 +00005677static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005678{
John W. Linville9387b7c2008-09-30 20:59:05 -04005679 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005680 struct ipw_priv *priv =
5681 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005682 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005683 struct ipw_network_match match = {
5684 .network = priv->assoc_network
5685 };
5686
James Ketrenosafbf30a2005-08-25 00:05:33 -05005687 if ((priv->status & STATUS_ASSOCIATED) &&
5688 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005689 /* First pass through ROAM process -- look for a better
5690 * network */
5691 unsigned long flags;
5692
5693 spin_lock_irqsave(&priv->ieee->lock, flags);
5694 list_for_each_entry(network, &priv->ieee->network_list, list) {
5695 if (network != priv->assoc_network)
5696 ipw_find_adhoc_network(priv, &match, network,
5697 1);
5698 }
5699 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5700
5701 if (match.network == priv->assoc_network) {
5702 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5703 "merge to.\n");
5704 return;
5705 }
5706
Zhu Yi46441512006-01-24 16:37:59 +08005707 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005708 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5709 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005710 print_ssid(ssid, priv->essid,
5711 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005712 ipw_remove_current_network(priv);
5713 }
5714
5715 ipw_disassociate(priv);
5716 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005717 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005718 return;
5719 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005720}
5721
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005722static int ipw_best_network(struct ipw_priv *priv,
5723 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005724 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005725{
5726 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005727 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005728
5729 /* Verify that this network's capability is compatible with the
5730 * current mode (AdHoc or Infrastructure) */
5731 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005732 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005733 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5734 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005735 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005736 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005737 print_ssid(ssid, network->ssid,
5738 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005739 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005740 return 0;
5741 }
5742
James Ketrenos43f66a62005-03-25 12:31:53 -06005743 if (unlikely(roaming)) {
5744 /* If we are roaming, then ensure check if this is a valid
5745 * network to try and roam to */
5746 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005747 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005749 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005750 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005751 print_ssid(ssid, network->ssid,
5752 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005753 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005754 return 0;
5755 }
5756 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005757 /* If an ESSID has been configured then compare the broadcast
5758 * ESSID to ours */
5759 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005760 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005761 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005762 min(network->ssid_len, priv->essid_len)))) {
5763 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005764 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005765 print_ssid(ssid, network->ssid,
5766 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005767 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005768 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005769 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005770 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005771 print_ssid(ssid, priv->essid,
5772 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005773 return 0;
5774 }
5775 }
5776
5777 /* If the old network rate is better than this one, don't bother
5778 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005779 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005780 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005781 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005782 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005783 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005784 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5785 "'%s (%pM)' has a stronger signal.\n",
5786 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005787 print_ssid(ssid, match->network->ssid,
5788 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005789 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005790 return 0;
5791 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005792
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 /* If this network has already had an association attempt within the
5794 * last 3 seconds, do not try and associate again... */
5795 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005796 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005797 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005798 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005799 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005800 print_ssid(ssid, network->ssid,
5801 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005802 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005803 jiffies_to_msecs(jiffies -
5804 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005805 return 0;
5806 }
5807
5808 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005809 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005810 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005811 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005812 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005813 print_ssid(ssid, network->ssid,
5814 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005815 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005816 jiffies_to_msecs(jiffies -
5817 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005818 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005819 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005820
Jeff Garzikbf794512005-07-31 13:07:26 -04005821 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005823 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005824 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005825 print_ssid(ssid, network->ssid,
5826 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005827 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005828 network->channel, priv->channel);
5829 return 0;
5830 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005831
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005833 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005834 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005835 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005836 "because of privacy mismatch: %s != %s.\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,
Jeff Garzikbf794512005-07-31 13:07:26 -04005840 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005841 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005842 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005843 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 return 0;
5845 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005846
5847 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005848 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005849 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5850 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005851 print_ssid(ssid, network->ssid,
5852 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005853 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005854 return 0;
5855 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005856
James Ketrenos43f66a62005-03-25 12:31:53 -06005857 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005858 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005859 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005860 "because of invalid frequency/mode "
5861 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005862 print_ssid(ssid, network->ssid,
5863 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005864 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005865 return 0;
5866 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005867
Liu Hong1fe0adb2005-08-19 09:33:10 -05005868 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005869 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005870 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005871 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005872 print_ssid(ssid, network->ssid,
5873 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005874 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005875 return 0;
5876 }
5877
James Ketrenosea2b26e2005-08-24 21:25:16 -05005878 /* Ensure that the rates supported by the driver are compatible with
5879 * this AP, including verification of basic rates (mandatory) */
5880 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005881 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005882 "because configured rate mask excludes "
5883 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005884 print_ssid(ssid, network->ssid,
5885 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005886 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005887 return 0;
5888 }
5889
James Ketrenos43f66a62005-03-25 12:31:53 -06005890 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005891 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005892 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005893 print_ssid(ssid, network->ssid,
5894 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005895 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005896 return 0;
5897 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005898
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 /* TODO: Perform any further minimal comparititive tests. We do not
5900 * want to put too much policy logic here; intelligent scan selection
5901 * should occur within a generic IEEE 802.11 user space tool. */
5902
5903 /* Set up 'new' AP to this network */
5904 ipw_copy_rates(&match->rates, &rates);
5905 match->network = network;
5906
Johannes Berge1749612008-10-27 15:59:26 -07005907 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005908 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005909 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005910
5911 return 1;
5912}
5913
Jeff Garzikbf794512005-07-31 13:07:26 -04005914static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005915 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005916{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005917 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005918 int i;
5919
James Ketrenos43f66a62005-03-25 12:31:53 -06005920 /*
5921 * For the purposes of scanning, we can set our wireless mode
5922 * to trigger scans across combinations of bands, but when it
5923 * comes to creating a new ad-hoc network, we have tell the FW
5924 * exactly which band to use.
5925 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005926 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005927 * chossen band. Attempting to create a new ad-hoc network
5928 * with an invalid channel for wireless mode will trigger a
5929 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005930 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005931 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005932 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5933 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005934 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005935 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005936 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005937 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005938 IPW_WARNING("Overriding invalid channel\n");
5939 priv->channel = geo->a[0].channel;
5940 }
5941 break;
5942
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005943 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005944 if (priv->ieee->mode & IEEE_G)
5945 network->mode = IEEE_G;
5946 else
5947 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005948 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005949 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005950 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005951 IPW_WARNING("Overriding invalid channel\n");
5952 priv->channel = geo->bg[0].channel;
5953 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005954 break;
5955
5956 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005957 IPW_WARNING("Overriding invalid channel\n");
5958 if (priv->ieee->mode & IEEE_A) {
5959 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005960 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005961 } else if (priv->ieee->mode & IEEE_G) {
5962 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005963 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005964 } else {
5965 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005966 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005967 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005968 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005969 }
5970
5971 network->channel = priv->channel;
5972 priv->config |= CFG_ADHOC_PERSIST;
5973 ipw_create_bssid(priv, network->bssid);
5974 network->ssid_len = priv->essid_len;
5975 memcpy(network->ssid, priv->essid, priv->essid_len);
5976 memset(&network->stats, 0, sizeof(network->stats));
5977 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005978 if (!(priv->config & CFG_PREAMBLE_LONG))
5979 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005980 if (priv->capability & CAP_PRIVACY_ON)
5981 network->capability |= WLAN_CAPABILITY_PRIVACY;
5982 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005983 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005984 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005985 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005986 &priv->rates.supported_rates[network->rates_len],
5987 network->rates_ex_len);
5988 network->last_scanned = 0;
5989 network->flags = 0;
5990 network->last_associate = 0;
5991 network->time_stamp[0] = 0;
5992 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005993 network->beacon_interval = 100; /* Default */
5994 network->listen_interval = 10; /* Default */
5995 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005996 network->wpa_ie_len = 0;
5997 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005998}
5999
James Ketrenosb095c382005-08-24 22:04:42 -05006000static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
6001{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006002 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05006003
6004 if (!(priv->ieee->sec.flags & (1 << index)))
6005 return;
6006
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006007 key.key_id = index;
6008 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
6009 key.security_type = type;
6010 key.station_index = 0; /* always 0 for BSS */
6011 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006012 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08006013 key.tx_counter[0] = cpu_to_le32(0);
6014 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05006015
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006016 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05006017}
6018
6019static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06006020{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006021 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006022 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006023
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006024 key.cmd_id = DINO_CMD_WEP_KEY;
6025 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006026
James Ketrenosb095c382005-08-24 22:04:42 -05006027 /* Note: AES keys cannot be set for multiple times.
6028 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006029 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006030 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006031 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006032 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006033 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006034 }
6035
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006036 key.key_size = priv->ieee->sec.key_sizes[i];
6037 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006038
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006039 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006040 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006041}
6042
Zhu Yi1fbfea52005-08-05 17:22:56 +08006043static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6044{
6045 if (priv->ieee->host_encrypt)
6046 return;
6047
6048 switch (level) {
6049 case SEC_LEVEL_3:
6050 priv->sys_config.disable_unicast_decryption = 0;
6051 priv->ieee->host_decrypt = 0;
6052 break;
6053 case SEC_LEVEL_2:
6054 priv->sys_config.disable_unicast_decryption = 1;
6055 priv->ieee->host_decrypt = 1;
6056 break;
6057 case SEC_LEVEL_1:
6058 priv->sys_config.disable_unicast_decryption = 0;
6059 priv->ieee->host_decrypt = 0;
6060 break;
6061 case SEC_LEVEL_0:
6062 priv->sys_config.disable_unicast_decryption = 1;
6063 break;
6064 default:
6065 break;
6066 }
6067}
6068
6069static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6070{
6071 if (priv->ieee->host_encrypt)
6072 return;
6073
6074 switch (level) {
6075 case SEC_LEVEL_3:
6076 priv->sys_config.disable_multicast_decryption = 0;
6077 break;
6078 case SEC_LEVEL_2:
6079 priv->sys_config.disable_multicast_decryption = 1;
6080 break;
6081 case SEC_LEVEL_1:
6082 priv->sys_config.disable_multicast_decryption = 0;
6083 break;
6084 case SEC_LEVEL_0:
6085 priv->sys_config.disable_multicast_decryption = 1;
6086 break;
6087 default:
6088 break;
6089 }
6090}
6091
James Ketrenosb095c382005-08-24 22:04:42 -05006092static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6093{
6094 switch (priv->ieee->sec.level) {
6095 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006096 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6097 ipw_send_tgi_tx_key(priv,
6098 DCT_FLAG_EXT_SECURITY_CCM,
6099 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006100
Hong Liu567deaf2005-08-31 18:07:22 +08006101 if (!priv->ieee->host_mc_decrypt)
6102 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006103 break;
6104 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006105 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6106 ipw_send_tgi_tx_key(priv,
6107 DCT_FLAG_EXT_SECURITY_TKIP,
6108 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006109 break;
6110 case SEC_LEVEL_1:
6111 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006112 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6113 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006114 break;
6115 case SEC_LEVEL_0:
6116 default:
6117 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006118 }
6119}
6120
6121static void ipw_adhoc_check(void *data)
6122{
6123 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006124
James Ketrenosafbf30a2005-08-25 00:05:33 -05006125 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006126 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006127 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6128 IPW_DL_STATE | IPW_DL_ASSOC,
6129 "Missed beacon: %d - disassociate\n",
6130 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006131 ipw_remove_current_network(priv);
6132 ipw_disassociate(priv);
6133 return;
6134 }
6135
Jeff Garzikbf794512005-07-31 13:07:26 -04006136 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006137 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006138}
6139
David Howellsc4028952006-11-22 14:57:56 +00006140static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006141{
David Howellsc4028952006-11-22 14:57:56 +00006142 struct ipw_priv *priv =
6143 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006144 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006145 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006146 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006147}
6148
James Ketrenos43f66a62005-03-25 12:31:53 -06006149static void ipw_debug_config(struct ipw_priv *priv)
6150{
John W. Linville9387b7c2008-09-30 20:59:05 -04006151 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006152 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6153 "[CFG 0x%08X]\n", priv->config);
6154 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006155 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006156 else
6157 IPW_DEBUG_INFO("Channel unlocked.\n");
6158 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006159 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006160 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006161 else
6162 IPW_DEBUG_INFO("ESSID unlocked.\n");
6163 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006164 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006165 else
6166 IPW_DEBUG_INFO("BSSID unlocked.\n");
6167 if (priv->capability & CAP_PRIVACY_ON)
6168 IPW_DEBUG_INFO("PRIVACY on\n");
6169 else
6170 IPW_DEBUG_INFO("PRIVACY off\n");
6171 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6172}
James Ketrenos43f66a62005-03-25 12:31:53 -06006173
Arjan van de Ven858119e2006-01-14 13:20:43 -08006174static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006175{
6176 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006177 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006178 u32 reg;
6179 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006180 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006181
Jeff Garzikbf794512005-07-31 13:07:26 -04006182 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006183 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006184
James Ketrenos43f66a62005-03-25 12:31:53 -06006185 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006186 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006187 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006188 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006189 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006190 IPW_DEBUG_WX
6191 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006192 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006193 break;
6194 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006195
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006196 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006197 break;
6198
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006199 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006200 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006201 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006202 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006203 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006204 IPW_DEBUG_WX
6205 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006206 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006207 }
6208 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006209 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006210
6211 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006212 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6213 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006214 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006215 IPW_DEBUG_WX
6216 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006217 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006218 break;
6219 }
6220
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006221 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6222 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6223 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006224 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006225
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006226 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6227 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6228 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006229 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006230
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006231 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6232 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6233 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006234 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006235
Reinette Chatre21f8a732009-08-18 10:25:05 -07006236 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006237 break;
6238 }
6239
Reinette Chatre21f8a732009-08-18 10:25:05 -07006240 fr.tx_rates = cpu_to_le16(new_tx_rates);
6241
James Ketrenos43f66a62005-03-25 12:31:53 -06006242 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006243 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006244}
6245
James Ketrenosea2b26e2005-08-24 21:25:16 -05006246static void ipw_abort_scan(struct ipw_priv *priv)
6247{
6248 int err;
6249
6250 if (priv->status & STATUS_SCAN_ABORTING) {
6251 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6252 return;
6253 }
6254 priv->status |= STATUS_SCAN_ABORTING;
6255
6256 err = ipw_send_scan_abort(priv);
6257 if (err)
6258 IPW_DEBUG_HC("Request to abort scan failed.\n");
6259}
6260
James Ketrenosafbf30a2005-08-25 00:05:33 -05006261static void ipw_add_scan_channels(struct ipw_priv *priv,
6262 struct ipw_scan_request_ext *scan,
6263 int scan_type)
6264{
6265 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006266 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006267 int i;
6268
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006269 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006270
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006271 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006272 int start = channel_index;
6273 for (i = 0; i < geo->a_channels; i++) {
6274 if ((priv->status & STATUS_ASSOCIATED) &&
6275 geo->a[i].channel == priv->channel)
6276 continue;
6277 channel_index++;
6278 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006279 ipw_set_scan_type(scan, channel_index,
6280 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006281 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006282 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6283 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006284 }
6285
6286 if (start != channel_index) {
6287 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6288 (channel_index - start);
6289 channel_index++;
6290 }
6291 }
6292
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006293 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006294 int start = channel_index;
6295 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006296 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006297 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006298 /* nop out the list */
6299 [0] = 0
6300 };
6301
6302 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006303 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006304 channel =
6305 priv->speed_scan[priv->speed_scan_pos];
6306 if (channel == 0) {
6307 priv->speed_scan_pos = 0;
6308 channel = priv->speed_scan[0];
6309 }
6310 if ((priv->status & STATUS_ASSOCIATED) &&
6311 channel == priv->channel) {
6312 priv->speed_scan_pos++;
6313 continue;
6314 }
6315
6316 /* If this channel has already been
6317 * added in scan, break from loop
6318 * and this will be the first channel
6319 * in the next scan.
6320 */
6321 if (channels[channel - 1] != 0)
6322 break;
6323
6324 channels[channel - 1] = 1;
6325 priv->speed_scan_pos++;
6326 channel_index++;
6327 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006328 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006329 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006330 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006331 geo->bg[index].
6332 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006333 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006334 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6335 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006336 }
6337 } else {
6338 for (i = 0; i < geo->bg_channels; i++) {
6339 if ((priv->status & STATUS_ASSOCIATED) &&
6340 geo->bg[i].channel == priv->channel)
6341 continue;
6342 channel_index++;
6343 scan->channels_list[channel_index] =
6344 geo->bg[i].channel;
6345 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006346 geo->bg[i].
6347 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006348 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006349 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6350 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006351 }
6352 }
6353
6354 if (start != channel_index) {
6355 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6356 (channel_index - start);
6357 }
6358 }
6359}
6360
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006361static int ipw_passive_dwell_time(struct ipw_priv *priv)
6362{
6363 /* staying on passive channels longer than the DTIM interval during a
6364 * scan, while associated, causes the firmware to cancel the scan
6365 * without notification. Hence, don't stay on passive channels longer
6366 * than the beacon interval.
6367 */
6368 if (priv->status & STATUS_ASSOCIATED
6369 && priv->assoc_network->beacon_interval > 10)
6370 return priv->assoc_network->beacon_interval - 10;
6371 else
6372 return 120;
6373}
6374
Dan Williamsea177302008-06-02 17:51:23 -04006375static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006376{
6377 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006378 int err = 0, scan_type;
6379
6380 if (!(priv->status & STATUS_INIT) ||
6381 (priv->status & STATUS_EXIT_PENDING))
6382 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006383
Zhu Yi46441512006-01-24 16:37:59 +08006384 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006385
Dan Williamsea177302008-06-02 17:51:23 -04006386 if (direct && (priv->direct_scan_ssid_len == 0)) {
6387 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6388 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6389 goto done;
6390 }
6391
James Ketrenosea2b26e2005-08-24 21:25:16 -05006392 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006393 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6394 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6395 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006396 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006397 }
6398
James Ketrenosafbf30a2005-08-25 00:05:33 -05006399 if (!(priv->status & STATUS_SCAN_FORCED) &&
6400 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006401 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006402 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6403 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006404 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006405 }
6406
6407 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006408 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6409 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6410 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006411 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006412 }
6413
6414 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006415 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006416
Zhu Yi094c4d22006-08-21 11:39:03 +08006417 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006418 IPW_DEBUG_WX("use passive scanning\n");
6419 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006420 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006421 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006422 ipw_add_scan_channels(priv, &scan, scan_type);
6423 goto send_request;
6424 }
6425
6426 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006427 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006428 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006429 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006430 else
6431 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006432 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006433
James Ketrenosa613bff2005-08-24 21:43:11 -05006434 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006435 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006436
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006437 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6438 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006439 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006440
James Ketrenosb095c382005-08-24 22:04:42 -05006441#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006442 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006443 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006444 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006445
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006446 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6447 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006448 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006449 channel = priv->channel;
6450 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006451
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006452 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006453 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006454 channel = priv->channel;
6455 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006456
James Ketrenosb095c382005-08-24 22:04:42 -05006457 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006458 band = (u8) (IPW_B_MODE << 6) | 1;
6459 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006460 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006461 }
6462
James Ketrenosb095c382005-08-24 22:04:42 -05006463 scan.channels_list[0] = band;
6464 scan.channels_list[1] = channel;
6465 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006466
James Ketrenosb095c382005-08-24 22:04:42 -05006467 /* NOTE: The card will sit on this channel for this time
6468 * period. Scan aborts are timing sensitive and frequently
6469 * result in firmware restarts. As such, it is best to
6470 * set a small dwell_time here and just keep re-issuing
6471 * scans. Otherwise fast channel hopping will not actually
6472 * hop channels.
6473 *
6474 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006475 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006476 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006477 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006478#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006479 /* Honor direct scans first, otherwise if we are roaming make
6480 * this a direct scan for the current network. Finally,
6481 * ensure that every other scan is a fast channel hop scan */
6482 if (direct) {
6483 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6484 priv->direct_scan_ssid_len);
6485 if (err) {
6486 IPW_DEBUG_HC("Attempt to send SSID command "
6487 "failed\n");
6488 goto done;
6489 }
6490
6491 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6492 } else if ((priv->status & STATUS_ROAMING)
6493 || (!(priv->status & STATUS_ASSOCIATED)
6494 && (priv->config & CFG_STATIC_ESSID)
6495 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006496 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6497 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006498 IPW_DEBUG_HC("Attempt to send SSID command "
6499 "failed.\n");
6500 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006501 }
6502
6503 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006504 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006505 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006506
James Ketrenosafbf30a2005-08-25 00:05:33 -05006507 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006508#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006509 }
6510#endif
6511
Zhu Yi094c4d22006-08-21 11:39:03 +08006512send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006513 err = ipw_send_scan_request_ext(priv, &scan);
6514 if (err) {
6515 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006516 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006517 }
6518
6519 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006520 if (direct) {
6521 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6522 priv->direct_scan_ssid_len = 0;
6523 } else
6524 priv->status &= ~STATUS_SCAN_PENDING;
6525
James Ketrenosafbf30a2005-08-25 00:05:33 -05006526 queue_delayed_work(priv->workqueue, &priv->scan_check,
6527 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006528done:
Zhu Yi46441512006-01-24 16:37:59 +08006529 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006530 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006531}
6532
David Howellsc4028952006-11-22 14:57:56 +00006533static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006534{
David Howellsc4028952006-11-22 14:57:56 +00006535 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006536 container_of(work, struct ipw_priv, request_passive_scan.work);
6537 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006538}
6539
6540static void ipw_request_scan(struct work_struct *work)
6541{
6542 struct ipw_priv *priv =
6543 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006544 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6545}
6546
6547static void ipw_request_direct_scan(struct work_struct *work)
6548{
6549 struct ipw_priv *priv =
6550 container_of(work, struct ipw_priv, request_direct_scan.work);
6551 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006552}
6553
6554static void ipw_bg_abort_scan(struct work_struct *work)
6555{
6556 struct ipw_priv *priv =
6557 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006558 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006559 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006560 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006561}
6562
James Ketrenosea2b26e2005-08-24 21:25:16 -05006563static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6564{
James Ketrenosb095c382005-08-24 22:04:42 -05006565 /* This is called when wpa_supplicant loads and closes the driver
6566 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006567 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006568 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569}
6570
James Ketrenosea2b26e2005-08-24 21:25:16 -05006571static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6572{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006573 struct libipw_device *ieee = priv->ieee;
6574 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006575 .flags = SEC_AUTH_MODE,
6576 };
6577 int ret = 0;
6578
James Ketrenosafbf30a2005-08-25 00:05:33 -05006579 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006580 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6581 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006582 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006583 sec.auth_mode = WLAN_AUTH_OPEN;
6584 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006585 } else if (value & IW_AUTH_ALG_LEAP) {
6586 sec.auth_mode = WLAN_AUTH_LEAP;
6587 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588 } else
6589 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006590
6591 if (ieee->set_security)
6592 ieee->set_security(ieee->dev, &sec);
6593 else
6594 ret = -EOPNOTSUPP;
6595
6596 return ret;
6597}
6598
Adrian Bunka73e22b2006-01-21 01:39:42 +01006599static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6600 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006601{
6602 /* make sure WPA is enabled */
6603 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006604}
6605
6606static int ipw_set_rsn_capa(struct ipw_priv *priv,
6607 char *capabilities, int length)
6608{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006609 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6610
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006611 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006612 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006613}
6614
James Ketrenosafbf30a2005-08-25 00:05:33 -05006615/*
6616 * WE-18 support
6617 */
6618
6619/* SIOCSIWGENIE */
6620static int ipw_wx_set_genie(struct net_device *dev,
6621 struct iw_request_info *info,
6622 union iwreq_data *wrqu, char *extra)
6623{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006624 struct ipw_priv *priv = libipw_priv(dev);
6625 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006626 u8 *buf;
6627 int err = 0;
6628
6629 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6630 (wrqu->data.length && extra == NULL))
6631 return -EINVAL;
6632
James Ketrenosafbf30a2005-08-25 00:05:33 -05006633 if (wrqu->data.length) {
Julia Lawalld3e50332010-05-15 23:21:01 +02006634 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006635 if (buf == NULL) {
6636 err = -ENOMEM;
6637 goto out;
6638 }
6639
James Ketrenosafbf30a2005-08-25 00:05:33 -05006640 kfree(ieee->wpa_ie);
6641 ieee->wpa_ie = buf;
6642 ieee->wpa_ie_len = wrqu->data.length;
6643 } else {
6644 kfree(ieee->wpa_ie);
6645 ieee->wpa_ie = NULL;
6646 ieee->wpa_ie_len = 0;
6647 }
6648
6649 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6650 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006651 return err;
6652}
6653
6654/* SIOCGIWGENIE */
6655static int ipw_wx_get_genie(struct net_device *dev,
6656 struct iw_request_info *info,
6657 union iwreq_data *wrqu, char *extra)
6658{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006659 struct ipw_priv *priv = libipw_priv(dev);
6660 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006661 int err = 0;
6662
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6664 wrqu->data.length = 0;
6665 goto out;
6666 }
6667
6668 if (wrqu->data.length < ieee->wpa_ie_len) {
6669 err = -E2BIG;
6670 goto out;
6671 }
6672
6673 wrqu->data.length = ieee->wpa_ie_len;
6674 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6675
6676 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006677 return err;
6678}
6679
Zhu Yi1fbfea52005-08-05 17:22:56 +08006680static int wext_cipher2level(int cipher)
6681{
6682 switch (cipher) {
6683 case IW_AUTH_CIPHER_NONE:
6684 return SEC_LEVEL_0;
6685 case IW_AUTH_CIPHER_WEP40:
6686 case IW_AUTH_CIPHER_WEP104:
6687 return SEC_LEVEL_1;
6688 case IW_AUTH_CIPHER_TKIP:
6689 return SEC_LEVEL_2;
6690 case IW_AUTH_CIPHER_CCMP:
6691 return SEC_LEVEL_3;
6692 default:
6693 return -1;
6694 }
6695}
6696
James Ketrenosafbf30a2005-08-25 00:05:33 -05006697/* SIOCSIWAUTH */
6698static int ipw_wx_set_auth(struct net_device *dev,
6699 struct iw_request_info *info,
6700 union iwreq_data *wrqu, char *extra)
6701{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006702 struct ipw_priv *priv = libipw_priv(dev);
6703 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006704 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006705 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006706 unsigned long flags;
6707 int ret = 0;
6708
6709 switch (param->flags & IW_AUTH_INDEX) {
6710 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006711 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006712 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006713 ipw_set_hw_decrypt_unicast(priv,
6714 wext_cipher2level(param->value));
6715 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006716 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006717 ipw_set_hw_decrypt_multicast(priv,
6718 wext_cipher2level(param->value));
6719 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006720 case IW_AUTH_KEY_MGMT:
6721 /*
6722 * ipw2200 does not use these parameters
6723 */
6724 break;
6725
6726 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006727 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006728 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006729 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006730
6731 flags = crypt->ops->get_flags(crypt->priv);
6732
6733 if (param->value)
6734 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6735 else
6736 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6737
6738 crypt->ops->set_flags(flags, crypt->priv);
6739
6740 break;
6741
6742 case IW_AUTH_DROP_UNENCRYPTED:{
6743 /* HACK:
6744 *
6745 * wpa_supplicant calls set_wpa_enabled when the driver
6746 * is loaded and unloaded, regardless of if WPA is being
6747 * used. No other calls are made which can be used to
6748 * determine if encryption will be used or not prior to
6749 * association being expected. If encryption is not being
6750 * used, drop_unencrypted is set to false, else true -- we
6751 * can use this to determine if the CAP_PRIVACY_ON bit should
6752 * be set.
6753 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006754 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006755 .flags = SEC_ENABLED,
6756 .enabled = param->value,
6757 };
6758 priv->ieee->drop_unencrypted = param->value;
6759 /* We only change SEC_LEVEL for open mode. Others
6760 * are set by ipw_wpa_set_encryption.
6761 */
6762 if (!param->value) {
6763 sec.flags |= SEC_LEVEL;
6764 sec.level = SEC_LEVEL_0;
6765 } else {
6766 sec.flags |= SEC_LEVEL;
6767 sec.level = SEC_LEVEL_1;
6768 }
6769 if (priv->ieee->set_security)
6770 priv->ieee->set_security(priv->ieee->dev, &sec);
6771 break;
6772 }
6773
6774 case IW_AUTH_80211_AUTH_ALG:
6775 ret = ipw_wpa_set_auth_algs(priv, param->value);
6776 break;
6777
6778 case IW_AUTH_WPA_ENABLED:
6779 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006780 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006781 break;
6782
6783 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6784 ieee->ieee802_1x = param->value;
6785 break;
6786
James Ketrenosafbf30a2005-08-25 00:05:33 -05006787 case IW_AUTH_PRIVACY_INVOKED:
6788 ieee->privacy_invoked = param->value;
6789 break;
6790
6791 default:
6792 return -EOPNOTSUPP;
6793 }
6794 return ret;
6795}
6796
6797/* SIOCGIWAUTH */
6798static int ipw_wx_get_auth(struct net_device *dev,
6799 struct iw_request_info *info,
6800 union iwreq_data *wrqu, char *extra)
6801{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006802 struct ipw_priv *priv = libipw_priv(dev);
6803 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006804 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006805 struct iw_param *param = &wrqu->param;
6806 int ret = 0;
6807
6808 switch (param->flags & IW_AUTH_INDEX) {
6809 case IW_AUTH_WPA_VERSION:
6810 case IW_AUTH_CIPHER_PAIRWISE:
6811 case IW_AUTH_CIPHER_GROUP:
6812 case IW_AUTH_KEY_MGMT:
6813 /*
6814 * wpa_supplicant will control these internally
6815 */
6816 ret = -EOPNOTSUPP;
6817 break;
6818
6819 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006820 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006821 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006822 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006823
6824 param->value = (crypt->ops->get_flags(crypt->priv) &
6825 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6826
6827 break;
6828
6829 case IW_AUTH_DROP_UNENCRYPTED:
6830 param->value = ieee->drop_unencrypted;
6831 break;
6832
6833 case IW_AUTH_80211_AUTH_ALG:
6834 param->value = ieee->sec.auth_mode;
6835 break;
6836
6837 case IW_AUTH_WPA_ENABLED:
6838 param->value = ieee->wpa_enabled;
6839 break;
6840
6841 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6842 param->value = ieee->ieee802_1x;
6843 break;
6844
6845 case IW_AUTH_ROAMING_CONTROL:
6846 case IW_AUTH_PRIVACY_INVOKED:
6847 param->value = ieee->privacy_invoked;
6848 break;
6849
6850 default:
6851 return -EOPNOTSUPP;
6852 }
6853 return 0;
6854}
6855
6856/* SIOCSIWENCODEEXT */
6857static int ipw_wx_set_encodeext(struct net_device *dev,
6858 struct iw_request_info *info,
6859 union iwreq_data *wrqu, char *extra)
6860{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006861 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006862 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6863
6864 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006865 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006866 /* IPW HW can't build TKIP MIC,
6867 host decryption still needed */
6868 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6869 priv->ieee->host_mc_decrypt = 1;
6870 else {
6871 priv->ieee->host_encrypt = 0;
6872 priv->ieee->host_encrypt_msdu = 1;
6873 priv->ieee->host_decrypt = 1;
6874 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006875 } else {
6876 priv->ieee->host_encrypt = 0;
6877 priv->ieee->host_encrypt_msdu = 0;
6878 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006879 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006880 }
6881 }
6882
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006883 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006884}
6885
6886/* SIOCGIWENCODEEXT */
6887static int ipw_wx_get_encodeext(struct net_device *dev,
6888 struct iw_request_info *info,
6889 union iwreq_data *wrqu, char *extra)
6890{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006891 struct ipw_priv *priv = libipw_priv(dev);
6892 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006893}
6894
6895/* SIOCSIWMLME */
6896static int ipw_wx_set_mlme(struct net_device *dev,
6897 struct iw_request_info *info,
6898 union iwreq_data *wrqu, char *extra)
6899{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006900 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006901 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006902 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006903
6904 reason = cpu_to_le16(mlme->reason_code);
6905
6906 switch (mlme->cmd) {
6907 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006908 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006909 break;
6910
6911 case IW_MLME_DISASSOC:
6912 ipw_disassociate(priv);
6913 break;
6914
6915 default:
6916 return -EOPNOTSUPP;
6917 }
6918 return 0;
6919}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006920
Zhu Yie43e3c12006-04-13 17:20:45 +08006921#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006922
6923/* QoS */
6924/*
6925* get the modulation type of the current network or
6926* the card current mode
6927*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006928static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006929{
6930 u8 mode = 0;
6931
6932 if (priv->status & STATUS_ASSOCIATED) {
6933 unsigned long flags;
6934
6935 spin_lock_irqsave(&priv->ieee->lock, flags);
6936 mode = priv->assoc_network->mode;
6937 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6938 } else {
6939 mode = priv->ieee->mode;
6940 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006941 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006942 return mode;
6943}
6944
6945/*
6946* Handle management frame beacon and probe response
6947*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006948static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6949 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006950 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006951{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006952 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006953
James Ketrenosafbf30a2005-08-25 00:05:33 -05006954 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006955 network->qos_data.active = network->qos_data.supported;
6956
6957 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006958 if (active_network &&
6959 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006960 network->qos_data.active = network->qos_data.supported;
6961
6962 if ((network->qos_data.active == 1) && (active_network == 1) &&
6963 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6964 (network->qos_data.old_param_count !=
6965 network->qos_data.param_count)) {
6966 network->qos_data.old_param_count =
6967 network->qos_data.param_count;
6968 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006969 IPW_DEBUG_QOS("QoS parameters change call "
6970 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006971 }
6972 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006973 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6974 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006975 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006976 else
6977 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006978 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006979
James Ketrenosb095c382005-08-24 22:04:42 -05006980 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006981 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006982 schedule_work(&priv->qos_activate);
6983 }
6984
6985 network->qos_data.active = 0;
6986 network->qos_data.supported = 0;
6987 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006988 if ((priv->status & STATUS_ASSOCIATED) &&
6989 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6990 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006991 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006992 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006993 priv->assoc_network->ssid_len) &&
6994 !memcmp(network->ssid,
6995 priv->assoc_network->ssid,
6996 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006997 queue_work(priv->workqueue,
6998 &priv->merge_networks);
6999 }
James Ketrenosb095c382005-08-24 22:04:42 -05007000 }
7001
7002 return 0;
7003}
7004
7005/*
7006* This function set up the firmware to support QoS. It sends
7007* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
7008*/
7009static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007010 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05007011{
7012 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007013 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
7014 struct libipw_qos_parameters *active_one = NULL;
7015 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007016 u32 burst_duration;
7017 int i;
7018 u8 type;
7019
7020 type = ipw_qos_current_mode(priv);
7021
7022 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7023 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7024 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7025 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7026
7027 if (qos_network_data == NULL) {
7028 if (type == IEEE_B) {
7029 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7030 active_one = &def_parameters_CCK;
7031 } else
7032 active_one = &def_parameters_OFDM;
7033
James Ketrenosafbf30a2005-08-25 00:05:33 -05007034 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007035 burst_duration = ipw_qos_get_burst_duration(priv);
7036 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007037 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007038 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007039 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007040 if (type == IEEE_B) {
7041 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7042 type);
7043 if (priv->qos_data.qos_enable == 0)
7044 active_one = &def_parameters_CCK;
7045 else
7046 active_one = priv->qos_data.def_qos_parm_CCK;
7047 } else {
7048 if (priv->qos_data.qos_enable == 0)
7049 active_one = &def_parameters_OFDM;
7050 else
7051 active_one = priv->qos_data.def_qos_parm_OFDM;
7052 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007053 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007054 } else {
7055 unsigned long flags;
7056 int active;
7057
7058 spin_lock_irqsave(&priv->ieee->lock, flags);
7059 active_one = &(qos_network_data->parameters);
7060 qos_network_data->old_param_count =
7061 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007062 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007063 active = qos_network_data->supported;
7064 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7065
7066 if (active == 0) {
7067 burst_duration = ipw_qos_get_burst_duration(priv);
7068 for (i = 0; i < QOS_QUEUE_NUM; i++)
7069 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007070 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007071 }
7072 }
7073
7074 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007075 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007076 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007077 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007078 if (err)
7079 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7080
7081 return err;
7082}
7083
7084/*
7085* send IPW_CMD_WME_INFO to the firmware
7086*/
7087static int ipw_qos_set_info_element(struct ipw_priv *priv)
7088{
7089 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007090 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007091
7092 if (priv == NULL)
7093 return -1;
7094
7095 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007096 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007097
7098 qos_info.version = QOS_VERSION_1;
7099 qos_info.ac_info = 0;
7100
7101 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7102 qos_info.qui_type = QOS_OUI_TYPE;
7103 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7104
7105 ret = ipw_send_qos_info_command(priv, &qos_info);
7106 if (ret != 0) {
7107 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7108 }
7109 return ret;
7110}
7111
7112/*
7113* Set the QoS parameter with the association request structure
7114*/
7115static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007116 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007117{
7118 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007119 struct libipw_qos_data *qos_data = NULL;
7120 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007121 .supported = 1,
7122 .active = 1,
7123 };
7124
7125 switch (priv->ieee->iw_mode) {
7126 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007127 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007128
7129 qos_data = &ibss_data;
7130 break;
7131
7132 case IW_MODE_INFRA:
7133 qos_data = &network->qos_data;
7134 break;
7135
7136 default:
7137 BUG();
7138 break;
7139 }
7140
7141 err = ipw_qos_activate(priv, qos_data);
7142 if (err) {
7143 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7144 return err;
7145 }
7146
7147 if (priv->qos_data.qos_enable && qos_data->supported) {
7148 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7149 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7150 return ipw_qos_set_info_element(priv);
7151 }
7152
7153 return 0;
7154}
7155
7156/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007157* handling the beaconing responses. if we get different QoS setting
7158* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007159* setting
7160*/
7161static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007162 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007163{
7164 int ret = 0;
7165 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007166 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007167 int set_qos_param = 0;
7168
James Ketrenosafbf30a2005-08-25 00:05:33 -05007169 if ((priv == NULL) || (network == NULL) ||
7170 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007171 return ret;
7172
7173 if (!(priv->status & STATUS_ASSOCIATED))
7174 return ret;
7175
James Ketrenosafbf30a2005-08-25 00:05:33 -05007176 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007177 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007178
7179 spin_lock_irqsave(&priv->ieee->lock, flags);
7180 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007181 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007182 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007183 priv->assoc_network->qos_data.active = 1;
7184 if ((network->qos_data.old_param_count !=
7185 network->qos_data.param_count)) {
7186 set_qos_param = 1;
7187 network->qos_data.old_param_count =
7188 network->qos_data.param_count;
7189 }
7190
7191 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007192 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7193 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007194 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007195 else
7196 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007197 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007198 priv->assoc_network->qos_data.active = 0;
7199 priv->assoc_network->qos_data.supported = 0;
7200 set_qos_param = 1;
7201 }
7202
7203 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7204
7205 if (set_qos_param == 1)
7206 schedule_work(&priv->qos_activate);
7207
7208 return ret;
7209}
7210
7211static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7212{
7213 u32 ret = 0;
7214
7215 if ((priv == NULL))
7216 return 0;
7217
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007218 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007219 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007220 else
James Ketrenosb095c382005-08-24 22:04:42 -05007221 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007222
James Ketrenosb095c382005-08-24 22:04:42 -05007223 return ret;
7224}
7225
7226/*
7227* Initialize the setting of QoS global
7228*/
7229static void ipw_qos_init(struct ipw_priv *priv, int enable,
7230 int burst_enable, u32 burst_duration_CCK,
7231 u32 burst_duration_OFDM)
7232{
7233 priv->qos_data.qos_enable = enable;
7234
7235 if (priv->qos_data.qos_enable) {
7236 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7237 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7238 IPW_DEBUG_QOS("QoS is enabled\n");
7239 } else {
7240 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7241 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7242 IPW_DEBUG_QOS("QoS is not enabled\n");
7243 }
7244
7245 priv->qos_data.burst_enable = burst_enable;
7246
7247 if (burst_enable) {
7248 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7249 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7250 } else {
7251 priv->qos_data.burst_duration_CCK = 0;
7252 priv->qos_data.burst_duration_OFDM = 0;
7253 }
7254}
7255
7256/*
7257* map the packet priority to the right TX Queue
7258*/
7259static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7260{
7261 if (priority > 7 || !priv->qos_data.qos_enable)
7262 priority = 0;
7263
7264 return from_priority_to_tx_queue[priority] - 1;
7265}
7266
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007267static int ipw_is_qos_active(struct net_device *dev,
7268 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007269{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007270 struct ipw_priv *priv = libipw_priv(dev);
7271 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007272 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007273 u8 *daddr = skb->data + ETH_ALEN;
7274 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007275
7276 if (!(priv->status & STATUS_ASSOCIATED))
7277 return 0;
7278
7279 qos_data = &priv->assoc_network->qos_data;
7280
James Ketrenosb095c382005-08-24 22:04:42 -05007281 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7282 if (unicast == 0)
7283 qos_data->active = 0;
7284 else
7285 qos_data->active = qos_data->supported;
7286 }
James Ketrenosb095c382005-08-24 22:04:42 -05007287 active = qos_data->active;
7288 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007289 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7290 "unicast %d\n",
7291 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007292 if (active && priv->qos_data.qos_enable)
7293 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007294
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007295 return 0;
7296
7297}
7298/*
7299* add QoS parameter to the TX command
7300*/
7301static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7302 u16 priority,
7303 struct tfd_data *tfd)
7304{
7305 int tx_queue_id = 0;
7306
7307
7308 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7309 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7310
7311 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7312 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007313 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007314 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007315 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007316}
7317
7318/*
7319* background support to run QoS activate functionality
7320*/
David Howellsc4028952006-11-22 14:57:56 +00007321static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007322{
David Howellsc4028952006-11-22 14:57:56 +00007323 struct ipw_priv *priv =
7324 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007325
Zhu Yi46441512006-01-24 16:37:59 +08007326 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007327
7328 if (priv->status & STATUS_ASSOCIATED)
7329 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7330
Zhu Yi46441512006-01-24 16:37:59 +08007331 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007332}
7333
James Ketrenos3b9990c2005-08-19 13:18:55 -05007334static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007335 struct libipw_probe_response *resp,
7336 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007337{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007338 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007339 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7340 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007341
James Ketrenos3b9990c2005-08-19 13:18:55 -05007342 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007343
James Ketrenos3b9990c2005-08-19 13:18:55 -05007344 return 0;
7345}
James Ketrenosb095c382005-08-24 22:04:42 -05007346
James Ketrenos3b9990c2005-08-19 13:18:55 -05007347static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007348 struct libipw_beacon *resp,
7349 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007350{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007351 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007352 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7353 (network == priv->assoc_network));
7354
7355 ipw_qos_handle_probe_response(priv, active_network, network);
7356
7357 return 0;
7358}
7359
7360static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007361 struct libipw_assoc_response *resp,
7362 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007363{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007364 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007365 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007366 return 0;
7367}
7368
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007369static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007370 *qos_param)
7371{
Zhu Yi4e226992006-01-24 16:37:36 +08007372 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7373 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007374}
7375
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007376static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007377 *qos_param)
7378{
Zhu Yi4e226992006-01-24 16:37:36 +08007379 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7380 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007381}
7382
Zhu Yie43e3c12006-04-13 17:20:45 +08007383#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007384
James Ketrenos43f66a62005-03-25 12:31:53 -06007385static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007386 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007387 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007388{
7389 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007390 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007391
7392 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007393 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007394
7395 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007396 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007397 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007398 memcpy(priv->essid, network->ssid, priv->essid_len);
7399 }
7400
7401 network->last_associate = jiffies;
7402
7403 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7404 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007405 priv->assoc_request.auth_key = 0;
7406
James Ketrenos43f66a62005-03-25 12:31:53 -06007407 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007408 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007409 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007410 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7411
Zhu Yi1ba61e02006-02-15 13:00:55 +08007412 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007413 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007414
7415 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7416 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7417 priv->assoc_request.auth_type = AUTH_LEAP;
7418 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007419 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007420
James Ketrenosa613bff2005-08-24 21:43:11 -05007421 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007422 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007423 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7424 priv->ieee->wpa_ie_len);
7425 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007426
Jeff Garzikbf794512005-07-31 13:07:26 -04007427 /*
7428 * It is valid for our ieee device to support multiple modes, but
7429 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007430 * just one mode.
7431 */
7432 if (network->mode & priv->ieee->mode & IEEE_A)
7433 priv->assoc_request.ieee_mode = IPW_A_MODE;
7434 else if (network->mode & priv->ieee->mode & IEEE_G)
7435 priv->assoc_request.ieee_mode = IPW_G_MODE;
7436 else if (network->mode & priv->ieee->mode & IEEE_B)
7437 priv->assoc_request.ieee_mode = IPW_B_MODE;
7438
Al Viro5b5e8072007-12-27 01:54:06 -05007439 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007440 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7441 && !(priv->config & CFG_PREAMBLE_LONG)) {
7442 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7443 } else {
7444 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7445
7446 /* Clear the short preamble if we won't be supporting it */
7447 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007448 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007449 }
7450
James Ketrenosafbf30a2005-08-25 00:05:33 -05007451 /* Clear capability bits that aren't used in Ad Hoc */
7452 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7453 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007454 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007455
James Ketrenos43f66a62005-03-25 12:31:53 -06007456 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007457 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007458 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007459 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007460 network->channel,
7461 ipw_modes[priv->assoc_request.ieee_mode],
7462 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007463 (priv->assoc_request.preamble_length ==
7464 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7465 network->capability &
7466 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007467 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007468 priv->capability & CAP_PRIVACY_ON ?
7469 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007470 "(open)") : "",
7471 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007472 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007473 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007474 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007475
Al Viro5b5e8072007-12-27 01:54:06 -05007476 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007477 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007478 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007479 priv->assoc_request.assoc_type = HC_IBSS_START;
7480 priv->assoc_request.assoc_tsf_msw = 0;
7481 priv->assoc_request.assoc_tsf_lsw = 0;
7482 } else {
7483 if (unlikely(roaming))
7484 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7485 else
7486 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007487 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7488 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007489 }
7490
James Ketrenosafbf30a2005-08-25 00:05:33 -05007491 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007492
7493 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7494 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007495 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007496 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007497 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007498 priv->assoc_request.atim_window = 0;
7499 }
7500
Al Viro5b5e8072007-12-27 01:54:06 -05007501 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007502
James Ketrenos43f66a62005-03-25 12:31:53 -06007503 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7504 if (err) {
7505 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7506 return err;
7507 }
7508
7509 rates->ieee_mode = priv->assoc_request.ieee_mode;
7510 rates->purpose = IPW_RATE_CONNECT;
7511 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007512
James Ketrenos43f66a62005-03-25 12:31:53 -06007513 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7514 priv->sys_config.dot11g_auto_detection = 1;
7515 else
7516 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007517
7518 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7519 priv->sys_config.answer_broadcast_ssid_probe = 1;
7520 else
7521 priv->sys_config.answer_broadcast_ssid_probe = 0;
7522
Zhu Yid685b8c2006-04-13 17:20:27 +08007523 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007524 if (err) {
7525 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7526 return err;
7527 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007528
James Ketrenos43f66a62005-03-25 12:31:53 -06007529 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007530 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007531 if (err) {
7532 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7533 return err;
7534 }
7535
7536 /*
7537 * If preemption is enabled, it is possible for the association
7538 * to complete before we return from ipw_send_associate. Therefore
7539 * we have to be sure and update our priviate data first.
7540 */
7541 priv->channel = network->channel;
7542 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007543 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007544 priv->status &= ~STATUS_SECURITY_UPDATED;
7545
7546 priv->assoc_network = network;
7547
Zhu Yie43e3c12006-04-13 17:20:45 +08007548#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007549 ipw_qos_association(priv, network);
7550#endif
7551
James Ketrenos43f66a62005-03-25 12:31:53 -06007552 err = ipw_send_associate(priv, &priv->assoc_request);
7553 if (err) {
7554 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7555 return err;
7556 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007557
Frans Pop9fd1ea42010-03-24 19:46:31 +01007558 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007559 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007560 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007561
7562 return 0;
7563}
7564
7565static void ipw_roam(void *data)
7566{
7567 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007568 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007569 struct ipw_network_match match = {
7570 .network = priv->assoc_network
7571 };
7572
7573 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007574 *
7575 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007576 * setting the status ROAM bit and requesting a scan.
7577 * 2. When the scan completes, it schedules the ROAM work
7578 * 3. The ROAM work looks at all of the known networks for one that
7579 * is a better network than the currently associated. If none
7580 * found, the ROAM process is over (ROAM bit cleared)
7581 * 4. If a better network is found, a disassociation request is
7582 * sent.
7583 * 5. When the disassociation completes, the roam work is again
7584 * scheduled. The second time through, the driver is no longer
7585 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007586 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007587 * 6. At this point ,the roaming process is complete and the ROAM
7588 * status bit is cleared.
7589 */
7590
7591 /* If we are no longer associated, and the roaming bit is no longer
7592 * set, then we are not actively roaming, so just return */
7593 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7594 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007595
James Ketrenos43f66a62005-03-25 12:31:53 -06007596 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007597 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007598 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007599 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007600 u8 rssi = priv->assoc_network->stats.rssi;
7601 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007602 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007603 list_for_each_entry(network, &priv->ieee->network_list, list) {
7604 if (network != priv->assoc_network)
7605 ipw_best_network(priv, &match, network, 1);
7606 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007607 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007608 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007609
James Ketrenos43f66a62005-03-25 12:31:53 -06007610 if (match.network == priv->assoc_network) {
7611 IPW_DEBUG_ASSOC("No better APs in this network to "
7612 "roam to.\n");
7613 priv->status &= ~STATUS_ROAMING;
7614 ipw_debug_config(priv);
7615 return;
7616 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007617
James Ketrenos43f66a62005-03-25 12:31:53 -06007618 ipw_send_disassociate(priv, 1);
7619 priv->assoc_network = match.network;
7620
7621 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007622 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007623
7624 /* Second pass through ROAM process -- request association */
7625 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7626 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7627 priv->status &= ~STATUS_ROAMING;
7628}
7629
David Howellsc4028952006-11-22 14:57:56 +00007630static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007631{
David Howellsc4028952006-11-22 14:57:56 +00007632 struct ipw_priv *priv =
7633 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007634 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007635 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007636 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007637}
7638
7639static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007640{
7641 struct ipw_priv *priv = data;
7642
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007643 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007644 struct ipw_network_match match = {
7645 .network = NULL
7646 };
7647 struct ipw_supported_rates *rates;
7648 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007649 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007650 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007651
James Ketrenosb095c382005-08-24 22:04:42 -05007652 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7653 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7654 return 0;
7655 }
7656
James Ketrenosc848d0a2005-08-24 21:56:24 -05007657 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007658 IPW_DEBUG_ASSOC("Not attempting association (already in "
7659 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007660 return 0;
7661 }
7662
Hong Liue6324722005-09-14 21:04:15 -05007663 if (priv->status & STATUS_DISASSOCIATING) {
7664 IPW_DEBUG_ASSOC("Not attempting association (in "
7665 "disassociating)\n ");
7666 queue_work(priv->workqueue, &priv->associate);
7667 return 0;
7668 }
7669
James Ketrenosc848d0a2005-08-24 21:56:24 -05007670 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007671 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7672 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007673 return 0;
7674 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007675
7676 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007677 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007678 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007679 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007680 }
7681
James Ketrenosa613bff2005-08-24 21:43:11 -05007682 /* Protect our use of the network_list */
7683 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007684 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007685 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007686
7687 network = match.network;
7688 rates = &match.rates;
7689
7690 if (network == NULL &&
7691 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7692 priv->config & CFG_ADHOC_CREATE &&
7693 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007694 priv->config & CFG_STATIC_CHANNEL) {
7695 /* Use oldest network if the free list is empty */
7696 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007697 struct libipw_network *oldest = NULL;
7698 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007699
7700 list_for_each_entry(target, &priv->ieee->network_list, list) {
7701 if ((oldest == NULL) ||
7702 (target->last_scanned < oldest->last_scanned))
7703 oldest = target;
7704 }
7705
7706 /* If there are no more slots, expire the oldest */
7707 list_del(&oldest->list);
7708 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007709 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007710 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007711 print_ssid(ssid, target->ssid,
7712 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007713 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007714 list_add_tail(&target->list,
7715 &priv->ieee->network_free_list);
7716 }
7717
James Ketrenos43f66a62005-03-25 12:31:53 -06007718 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007719 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007720 ipw_adhoc_create(priv, network);
7721 rates = &priv->rates;
7722 list_del(element);
7723 list_add_tail(&network->list, &priv->ieee->network_list);
7724 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007725 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007726
James Ketrenos43f66a62005-03-25 12:31:53 -06007727 /* If we reached the end of the list, then we don't have any valid
7728 * matching APs */
7729 if (!network) {
7730 ipw_debug_config(priv);
7731
James Ketrenosb095c382005-08-24 22:04:42 -05007732 if (!(priv->status & STATUS_SCANNING)) {
7733 if (!(priv->config & CFG_SPEED_SCAN))
7734 queue_delayed_work(priv->workqueue,
7735 &priv->request_scan,
7736 SCAN_INTERVAL);
7737 else
David Howellsc4028952006-11-22 14:57:56 +00007738 queue_delayed_work(priv->workqueue,
7739 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007740 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007741
James Ketrenosc848d0a2005-08-24 21:56:24 -05007742 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007743 }
7744
7745 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007746
7747 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007748}
Jeff Garzikbf794512005-07-31 13:07:26 -04007749
David Howellsc4028952006-11-22 14:57:56 +00007750static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007751{
David Howellsc4028952006-11-22 14:57:56 +00007752 struct ipw_priv *priv =
7753 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007754 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007755 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007756 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007757}
7758
James Ketrenosb095c382005-08-24 22:04:42 -05007759static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7760 struct sk_buff *skb)
7761{
7762 struct ieee80211_hdr *hdr;
7763 u16 fc;
7764
7765 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007766 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007767 if (!(fc & IEEE80211_FCTL_PROTECTED))
7768 return;
7769
7770 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007771 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007772 switch (priv->ieee->sec.level) {
7773 case SEC_LEVEL_3:
7774 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007775 memmove(skb->data + LIBIPW_3ADDR_LEN,
7776 skb->data + LIBIPW_3ADDR_LEN + 8,
7777 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007778 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007779 break;
7780 case SEC_LEVEL_2:
7781 break;
7782 case SEC_LEVEL_1:
7783 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007784 memmove(skb->data + LIBIPW_3ADDR_LEN,
7785 skb->data + LIBIPW_3ADDR_LEN + 4,
7786 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007787 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007788 break;
7789 case SEC_LEVEL_0:
7790 break;
7791 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007792 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007793 priv->ieee->sec.level);
7794 break;
7795 }
7796}
7797
7798static void ipw_handle_data_packet(struct ipw_priv *priv,
7799 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007800 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007801{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007802 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007803 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007804 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7805
7806 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007807 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007808
Jeff Garzikbf794512005-07-31 13:07:26 -04007809 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007810 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007811 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007812 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007813 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007814 priv->wstats.discard.misc++;
7815 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7816 return;
7817 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007818 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007819 priv->wstats.discard.misc++;
7820 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7821 return;
7822 }
7823
7824 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007825 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007826
7827 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007828 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007829
7830 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7831
James Ketrenosb095c382005-08-24 22:04:42 -05007832 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007833 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007834 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007835 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007836 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007837 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7838
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007839 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007840 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007841 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007842 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007843 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007844 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007845}
7846
Zhu Yi459d4082006-04-13 17:21:00 +08007847#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007848static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7849 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007850 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007851{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007852 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007853 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7854 struct ipw_rx_frame *frame = &pkt->u.frame;
7855
7856 /* initial pull of some data */
7857 u16 received_channel = frame->received_channel;
7858 u8 antennaAndPhy = frame->antennaAndPhy;
7859 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7860 u16 pktrate = frame->rate;
7861
7862 /* Magic struct that slots into the radiotap header -- no reason
7863 * to build this manually element by element, we can write it much
7864 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007865 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007866
7867 short len = le16_to_cpu(pkt->u.frame.length);
7868
7869 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007870 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007871
7872 /* We only process data packets if the
7873 * interface is open */
7874 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7875 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007876 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007877 priv->wstats.discard.misc++;
7878 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7879 return;
7880 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007881 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007882 priv->wstats.discard.misc++;
7883 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7884 return;
7885 }
7886
7887 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7888 * that now */
7889 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7890 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007891 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007892 priv->wstats.discard.misc++;
7893 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7894 return;
7895 }
7896
7897 /* copy the frame itself */
7898 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7899 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7900
Mike Kershaw24a47db2005-08-26 00:41:54 -05007901 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7902
7903 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7904 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007905 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007906
7907 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007908 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7909 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007910 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007911 (1 << IEEE80211_RADIOTAP_RATE) |
7912 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7913 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007914 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007915 (1 << IEEE80211_RADIOTAP_ANTENNA));
7916
7917 /* Zero the flags, we'll add to them as we go */
7918 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007919 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7920 frame->parent_tsf[2] << 16 |
7921 frame->parent_tsf[1] << 8 |
7922 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007923
7924 /* Convert signal to DBM */
7925 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007926 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007927
7928 /* Convert the channel data and set the flags */
7929 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7930 if (received_channel > 14) { /* 802.11a */
7931 ipw_rt->rt_chbitmask =
7932 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7933 } else if (antennaAndPhy & 32) { /* 802.11b */
7934 ipw_rt->rt_chbitmask =
7935 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7936 } else { /* 802.11g */
7937 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007938 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007939 }
7940
7941 /* set the rate in multiples of 500k/s */
7942 switch (pktrate) {
7943 case IPW_TX_RATE_1MB:
7944 ipw_rt->rt_rate = 2;
7945 break;
7946 case IPW_TX_RATE_2MB:
7947 ipw_rt->rt_rate = 4;
7948 break;
7949 case IPW_TX_RATE_5MB:
7950 ipw_rt->rt_rate = 10;
7951 break;
7952 case IPW_TX_RATE_6MB:
7953 ipw_rt->rt_rate = 12;
7954 break;
7955 case IPW_TX_RATE_9MB:
7956 ipw_rt->rt_rate = 18;
7957 break;
7958 case IPW_TX_RATE_11MB:
7959 ipw_rt->rt_rate = 22;
7960 break;
7961 case IPW_TX_RATE_12MB:
7962 ipw_rt->rt_rate = 24;
7963 break;
7964 case IPW_TX_RATE_18MB:
7965 ipw_rt->rt_rate = 36;
7966 break;
7967 case IPW_TX_RATE_24MB:
7968 ipw_rt->rt_rate = 48;
7969 break;
7970 case IPW_TX_RATE_36MB:
7971 ipw_rt->rt_rate = 72;
7972 break;
7973 case IPW_TX_RATE_48MB:
7974 ipw_rt->rt_rate = 96;
7975 break;
7976 case IPW_TX_RATE_54MB:
7977 ipw_rt->rt_rate = 108;
7978 break;
7979 default:
7980 ipw_rt->rt_rate = 0;
7981 break;
7982 }
7983
7984 /* antenna number */
7985 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7986
7987 /* set the preamble flag if we have it */
7988 if ((antennaAndPhy & 64))
7989 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7990
7991 /* Set the size of the skb to the size of the frame */
7992 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007993
7994 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7995
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007996 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007997 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007998 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007999 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008000 /* no LED during capture */
8001 }
8002}
8003#endif
8004
Zhu Yid685b8c2006-04-13 17:20:27 +08008005#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008006#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008007 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
8008 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
8009
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008010#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008011 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
8012
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008013#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008014 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
8015
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008016#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008017 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8018
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008019#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008020 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8021
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008022#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008023 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8024
8025static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8026 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008027 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008028{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008029 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008030 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8031 struct ipw_rx_frame *frame = &pkt->u.frame;
8032 struct ipw_rt_hdr *ipw_rt;
8033
8034 /* First cache any information we need before we overwrite
8035 * the information provided in the skb from the hardware */
8036 struct ieee80211_hdr *hdr;
8037 u16 channel = frame->received_channel;
8038 u8 phy_flags = frame->antennaAndPhy;
8039 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008040 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008041 u8 rate = frame->rate;
8042 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008043 struct sk_buff *skb;
8044 int hdr_only = 0;
8045 u16 filter = priv->prom_priv->filter;
8046
8047 /* If the filter is set to not include Rx frames then return */
8048 if (filter & IPW_PROM_NO_RX)
8049 return;
8050
Zhu Yid685b8c2006-04-13 17:20:27 +08008051 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008052 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008053
8054 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008055 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008056 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8057 return;
8058 }
8059
8060 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008061 if (unlikely(!netif_running(dev))) {
8062 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008063 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8064 return;
8065 }
8066
8067 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8068 * that now */
8069 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8070 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008071 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008072 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8073 return;
8074 }
8075
8076 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008077 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008078 if (filter & IPW_PROM_NO_MGMT)
8079 return;
8080 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8081 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008082 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008083 if (filter & IPW_PROM_NO_CTL)
8084 return;
8085 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8086 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008087 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008088 if (filter & IPW_PROM_NO_DATA)
8089 return;
8090 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8091 hdr_only = 1;
8092 }
8093
8094 /* Copy the SKB since this is for the promiscuous side */
8095 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8096 if (skb == NULL) {
8097 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8098 return;
8099 }
8100
8101 /* copy the frame data to write after where the radiotap header goes */
8102 ipw_rt = (void *)skb->data;
8103
8104 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008105 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008106
8107 memcpy(ipw_rt->payload, hdr, len);
8108
Zhu Yid685b8c2006-04-13 17:20:27 +08008109 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8110 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008111 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008112
8113 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008114 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008115
8116 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008117 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8118 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008119 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008120 (1 << IEEE80211_RADIOTAP_RATE) |
8121 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8122 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8123 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8124 (1 << IEEE80211_RADIOTAP_ANTENNA));
8125
8126 /* Zero the flags, we'll add to them as we go */
8127 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008128 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8129 frame->parent_tsf[2] << 16 |
8130 frame->parent_tsf[1] << 8 |
8131 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008132
8133 /* Convert to DBM */
8134 ipw_rt->rt_dbmsignal = signal;
8135 ipw_rt->rt_dbmnoise = noise;
8136
8137 /* Convert the channel data and set the flags */
8138 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8139 if (channel > 14) { /* 802.11a */
8140 ipw_rt->rt_chbitmask =
8141 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8142 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8143 ipw_rt->rt_chbitmask =
8144 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8145 } else { /* 802.11g */
8146 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008147 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008148 }
8149
8150 /* set the rate in multiples of 500k/s */
8151 switch (rate) {
8152 case IPW_TX_RATE_1MB:
8153 ipw_rt->rt_rate = 2;
8154 break;
8155 case IPW_TX_RATE_2MB:
8156 ipw_rt->rt_rate = 4;
8157 break;
8158 case IPW_TX_RATE_5MB:
8159 ipw_rt->rt_rate = 10;
8160 break;
8161 case IPW_TX_RATE_6MB:
8162 ipw_rt->rt_rate = 12;
8163 break;
8164 case IPW_TX_RATE_9MB:
8165 ipw_rt->rt_rate = 18;
8166 break;
8167 case IPW_TX_RATE_11MB:
8168 ipw_rt->rt_rate = 22;
8169 break;
8170 case IPW_TX_RATE_12MB:
8171 ipw_rt->rt_rate = 24;
8172 break;
8173 case IPW_TX_RATE_18MB:
8174 ipw_rt->rt_rate = 36;
8175 break;
8176 case IPW_TX_RATE_24MB:
8177 ipw_rt->rt_rate = 48;
8178 break;
8179 case IPW_TX_RATE_36MB:
8180 ipw_rt->rt_rate = 72;
8181 break;
8182 case IPW_TX_RATE_48MB:
8183 ipw_rt->rt_rate = 96;
8184 break;
8185 case IPW_TX_RATE_54MB:
8186 ipw_rt->rt_rate = 108;
8187 break;
8188 default:
8189 ipw_rt->rt_rate = 0;
8190 break;
8191 }
8192
8193 /* antenna number */
8194 ipw_rt->rt_antenna = (phy_flags & 3);
8195
8196 /* set the preamble flag if we have it */
8197 if (phy_flags & (1 << 6))
8198 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8199
8200 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8201
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008202 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008203 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008204 dev_kfree_skb_any(skb);
8205 }
8206}
8207#endif
8208
Arjan van de Ven858119e2006-01-14 13:20:43 -08008209static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008210 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008211{
8212 /* Filter incoming packets to determine if they are targetted toward
8213 * this network, discarding packets coming from ourselves */
8214 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008215 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008216 /* packets from our adapter are dropped (echo) */
8217 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8218 return 0;
8219
Peter Jones90700fd2005-08-26 16:51:06 -05008220 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008221 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008222 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008223
8224 /* packets to our adapter go through */
8225 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8226 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008227
Peter Jones90700fd2005-08-26 16:51:06 -05008228 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008229 /* packets from our adapter are dropped (echo) */
8230 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8231 return 0;
8232
Peter Jones90700fd2005-08-26 16:51:06 -05008233 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008234 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008235 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8236
8237 /* packets to our adapter go through */
8238 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8239 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008240 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008241
James Ketrenosea2b26e2005-08-24 21:25:16 -05008242 return 1;
8243}
8244
James Ketrenosafbf30a2005-08-25 00:05:33 -05008245#define IPW_PACKET_RETRY_TIME HZ
8246
Arjan van de Ven858119e2006-01-14 13:20:43 -08008247static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008248 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008249{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008250 u16 sc = le16_to_cpu(header->seq_ctl);
8251 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8252 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8253 u16 *last_seq, *last_frag;
8254 unsigned long *last_time;
8255
8256 switch (priv->ieee->iw_mode) {
8257 case IW_MODE_ADHOC:
8258 {
8259 struct list_head *p;
8260 struct ipw_ibss_seq *entry = NULL;
8261 u8 *mac = header->addr2;
8262 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8263
8264 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8265 entry =
8266 list_entry(p, struct ipw_ibss_seq, list);
8267 if (!memcmp(entry->mac, mac, ETH_ALEN))
8268 break;
8269 }
8270 if (p == &priv->ibss_mac_hash[index]) {
8271 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8272 if (!entry) {
8273 IPW_ERROR
8274 ("Cannot malloc new mac entry\n");
8275 return 0;
8276 }
8277 memcpy(entry->mac, mac, ETH_ALEN);
8278 entry->seq_num = seq;
8279 entry->frag_num = frag;
8280 entry->packet_time = jiffies;
8281 list_add(&entry->list,
8282 &priv->ibss_mac_hash[index]);
8283 return 0;
8284 }
8285 last_seq = &entry->seq_num;
8286 last_frag = &entry->frag_num;
8287 last_time = &entry->packet_time;
8288 break;
8289 }
8290 case IW_MODE_INFRA:
8291 last_seq = &priv->last_seq_num;
8292 last_frag = &priv->last_frag_num;
8293 last_time = &priv->last_packet_time;
8294 break;
8295 default:
8296 return 0;
8297 }
8298 if ((*last_seq == seq) &&
8299 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8300 if (*last_frag == frag)
8301 goto drop;
8302 if (*last_frag + 1 != frag)
8303 /* out-of-order fragment */
8304 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008305 } else
8306 *last_seq = seq;
8307
Zhu Yif57ce7c2005-07-13 12:22:15 -05008308 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008309 *last_time = jiffies;
8310 return 0;
8311
8312 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008313 /* Comment this line now since we observed the card receives
8314 * duplicate packets but the FCTL_RETRY bit is not set in the
8315 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008316 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008317 return 1;
8318}
8319
James Ketrenosb095c382005-08-24 22:04:42 -05008320static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8321 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008322 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008323{
8324 struct sk_buff *skb = rxb->skb;
8325 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008326 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008327 (skb->data + IPW_RX_FRAME_SIZE);
8328
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008329 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008330
8331 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8332 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8333 IEEE80211_STYPE_PROBE_RESP) ||
8334 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8335 IEEE80211_STYPE_BEACON))) {
8336 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8337 ipw_add_station(priv, header->addr2);
8338 }
8339
8340 if (priv->config & CFG_NET_STATS) {
8341 IPW_DEBUG_HC("sending stat packet\n");
8342
8343 /* Set the size of the skb to the size of the full
8344 * ipw header and 802.11 frame */
8345 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8346 IPW_RX_FRAME_SIZE);
8347
8348 /* Advance past the ipw packet header to the 802.11 frame */
8349 skb_pull(skb, IPW_RX_FRAME_SIZE);
8350
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008351 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008352 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8353
8354 skb->dev = priv->ieee->dev;
8355
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008356 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008357 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008358
8359 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008360 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008361 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8362 netif_rx(skb);
8363 rxb->skb = NULL;
8364 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008365}
8366
James Ketrenos43f66a62005-03-25 12:31:53 -06008367/*
8368 * Main entry function for recieving a packet with 80211 headers. This
8369 * should be called when ever the FW has notified us that there is a new
8370 * skb in the recieve queue.
8371 */
8372static void ipw_rx(struct ipw_priv *priv)
8373{
8374 struct ipw_rx_mem_buffer *rxb;
8375 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008376 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008377 u32 r, w, i;
8378 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008379 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008380
James Ketrenosb095c382005-08-24 22:04:42 -05008381 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8382 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008383 i = priv->rxq->read;
8384
8385 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8386 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008387
8388 while (i != r) {
8389 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008390 if (unlikely(rxb == NULL)) {
8391 printk(KERN_CRIT "Queue not allocated!\n");
8392 break;
8393 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008394 priv->rxq->queue[i] = NULL;
8395
8396 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008397 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008398 PCI_DMA_FROMDEVICE);
8399
8400 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8401 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8402 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008403 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008404
8405 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008406 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008407 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008408 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008409 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008410 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008411 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008412 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008413 .noise =
8414 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008415 .rate = pkt->u.frame.rate,
8416 .mac_time = jiffies,
8417 .received_channel =
8418 pkt->u.frame.received_channel,
8419 .freq =
8420 (pkt->u.frame.
8421 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008422 LIBIPW_24GHZ_BAND :
8423 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008424 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008425 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008426
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008427 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008428 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008429 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008430 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008431 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008432 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008433 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008434 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008435
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008436 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008437
Zhu Yid685b8c2006-04-13 17:20:27 +08008438#ifdef CONFIG_IPW2200_PROMISCUOUS
8439 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8440 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8441#endif
8442
James Ketrenosb095c382005-08-24 22:04:42 -05008443#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008444 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008445#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008446
8447 ipw_handle_data_packet_monitor(priv,
8448 rxb,
8449 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008450#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008451 ipw_handle_data_packet(priv, rxb,
8452 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008453#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008454 break;
8455 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008456#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008457
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008458 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008459 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008460 data +
8461 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008462 /* TODO: Check Ad-Hoc dest/source and make sure
8463 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008464 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008465 * frame control of the packet and disregard
8466 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008467
James Ketrenosea2b26e2005-08-24 21:25:16 -05008468 network_packet =
8469 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008470 if (network_packet && priv->assoc_network) {
8471 priv->assoc_network->stats.rssi =
8472 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008473 priv->exp_avg_rssi =
8474 exponential_average(priv->exp_avg_rssi,
8475 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008476 }
8477
8478 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008479 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008480
James Ketrenosa613bff2005-08-24 21:43:11 -05008481 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008482 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008483 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008484 IPW_DEBUG_DROP
8485 ("Received packet is too small. "
8486 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008487 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008488 priv->wstats.discard.misc++;
8489 break;
8490 }
8491
James Ketrenosa613bff2005-08-24 21:43:11 -05008492 switch (WLAN_FC_GET_TYPE
8493 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008494
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008495 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008496 ipw_handle_mgmt_packet(priv, rxb,
8497 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008498 break;
8499
8500 case IEEE80211_FTYPE_CTL:
8501 break;
8502
8503 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008504 if (unlikely(!network_packet ||
8505 is_duplicate_packet(priv,
8506 header)))
8507 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008508 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008509 "%pM, "
8510 "%pM, "
8511 "%pM\n",
8512 header->addr1,
8513 header->addr2,
8514 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008515 break;
8516 }
8517
8518 ipw_handle_data_packet(priv, rxb,
8519 &stats);
8520
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008521 break;
8522 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008523 break;
8524 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008525
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008526 case RX_HOST_NOTIFICATION_TYPE:{
8527 IPW_DEBUG_RX
8528 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008529 pkt->u.notification.subtype,
8530 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008531 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008532 ipw_rx_notification(priv, &pkt->u.notification);
8533 break;
8534 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008535
8536 default:
8537 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8538 pkt->header.message_type);
8539 break;
8540 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008541
8542 /* For now we just don't re-use anything. We can tweak this
8543 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008544 * fail to Rx correctly */
8545 if (rxb->skb != NULL) {
8546 dev_kfree_skb_any(rxb->skb);
8547 rxb->skb = NULL;
8548 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008549
James Ketrenos43f66a62005-03-25 12:31:53 -06008550 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008551 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008552 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008553
James Ketrenos43f66a62005-03-25 12:31:53 -06008554 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008555
8556 /* If there are a lot of unsued frames, restock the Rx queue
8557 * so the ucode won't assert */
8558 if (fill_rx) {
8559 priv->rxq->read = i;
8560 ipw_rx_queue_replenish(priv);
8561 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 }
8563
8564 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008565 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008566 ipw_rx_queue_restock(priv);
8567}
8568
James Ketrenosafbf30a2005-08-25 00:05:33 -05008569#define DEFAULT_RTS_THRESHOLD 2304U
8570#define MIN_RTS_THRESHOLD 1U
8571#define MAX_RTS_THRESHOLD 2304U
8572#define DEFAULT_BEACON_INTERVAL 100U
8573#define DEFAULT_SHORT_RETRY_LIMIT 7U
8574#define DEFAULT_LONG_RETRY_LIMIT 4U
8575
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008576/**
8577 * ipw_sw_reset
8578 * @option: options to control different reset behaviour
8579 * 0 = reset everything except the 'disable' module_param
8580 * 1 = reset everything and print out driver info (for probe only)
8581 * 2 = reset everything
8582 */
8583static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008584{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008585 int band, modulation;
8586 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008587
James Ketrenosafbf30a2005-08-25 00:05:33 -05008588 /* Initialize module parameter values here */
8589 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008590
James Ketrenosafbf30a2005-08-25 00:05:33 -05008591 /* We default to disabling the LED code as right now it causes
8592 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008593 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008594 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008595
James Ketrenosafbf30a2005-08-25 00:05:33 -05008596 if (associate)
8597 priv->config |= CFG_ASSOCIATE;
8598 else
8599 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008600
James Ketrenosafbf30a2005-08-25 00:05:33 -05008601 if (auto_create)
8602 priv->config |= CFG_ADHOC_CREATE;
8603 else
8604 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8605
Zhu Yi17ed0812006-01-24 16:36:31 +08008606 priv->config &= ~CFG_STATIC_ESSID;
8607 priv->essid_len = 0;
8608 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8609
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008610 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008611 priv->status |= STATUS_RF_KILL_SW;
8612 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008613 }
8614
Reinette Chatre21f8a732009-08-18 10:25:05 -07008615 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008616 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008617 priv->channel = default_channel;
8618 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008619 /* TODO: Validate that provided channel is in range */
8620 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008621#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008622 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8623 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008624#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008625
Reinette Chatre21f8a732009-08-18 10:25:05 -07008626 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008627 case 1:
8628 priv->ieee->iw_mode = IW_MODE_ADHOC;
8629 priv->net_dev->type = ARPHRD_ETHER;
8630
8631 break;
8632#ifdef CONFIG_IPW2200_MONITOR
8633 case 2:
8634 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008635#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008636 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8637#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008638 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008639#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008640 break;
8641#endif
8642 default:
8643 case 0:
8644 priv->net_dev->type = ARPHRD_ETHER;
8645 priv->ieee->iw_mode = IW_MODE_INFRA;
8646 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008647 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008648
James Ketrenosafbf30a2005-08-25 00:05:33 -05008649 if (hwcrypto) {
8650 priv->ieee->host_encrypt = 0;
8651 priv->ieee->host_encrypt_msdu = 0;
8652 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008653 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008654 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008655 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008656
Zhu Yie402c932005-08-05 17:20:40 +08008657 /* IPW2200/2915 is abled to do hardware fragmentation. */
8658 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008659
James Ketrenosafbf30a2005-08-25 00:05:33 -05008660 if ((priv->pci_dev->device == 0x4223) ||
8661 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008662 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008663 printk(KERN_INFO DRV_NAME
8664 ": Detected Intel PRO/Wireless 2915ABG Network "
8665 "Connection\n");
8666 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008667 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8668 modulation = LIBIPW_OFDM_MODULATION |
8669 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008670 priv->adapter = IPW_2915ABG;
8671 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008672 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008673 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008674 printk(KERN_INFO DRV_NAME
8675 ": Detected Intel PRO/Wireless 2200BG Network "
8676 "Connection\n");
8677
8678 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008679 band = LIBIPW_24GHZ_BAND;
8680 modulation = LIBIPW_OFDM_MODULATION |
8681 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008682 priv->adapter = IPW_2200BG;
8683 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008684 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008685
James Ketrenosafbf30a2005-08-25 00:05:33 -05008686 priv->ieee->freq_band = band;
8687 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008688
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008689 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008690
James Ketrenosafbf30a2005-08-25 00:05:33 -05008691 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8692 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008693
James Ketrenosafbf30a2005-08-25 00:05:33 -05008694 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8695 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8696 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008697
James Ketrenosafbf30a2005-08-25 00:05:33 -05008698 /* If power management is turned on, default to AC mode */
8699 priv->power_mode = IPW_POWER_AC;
8700 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008701
Zhu Yi0ece35b2005-08-05 17:26:51 +08008702 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008703}
8704
8705/*
8706 * This file defines the Wireless Extension handlers. It does not
8707 * define any methods of hardware manipulation and relies on the
8708 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008709 *
8710 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008711 * function used to poll the hardware vs. making unecessary calls.
8712 *
8713 */
8714
James Ketrenos43f66a62005-03-25 12:31:53 -06008715static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8716{
8717 if (channel == 0) {
8718 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8719 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008720 IPW_DEBUG_ASSOC("Attempting to associate with new "
8721 "parameters.\n");
8722 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008723 return 0;
8724 }
8725
8726 priv->config |= CFG_STATIC_CHANNEL;
8727
8728 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008729 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8730 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008731 return 0;
8732 }
8733
8734 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8735 priv->channel = channel;
8736
James Ketrenosb095c382005-08-24 22:04:42 -05008737#ifdef CONFIG_IPW2200_MONITOR
8738 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008739 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008740 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008741 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008742 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008743 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008744 }
8745
8746 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8747 udelay(10);
8748
8749 if (priv->status & STATUS_SCANNING)
8750 IPW_DEBUG_SCAN("Still scanning...\n");
8751 else
8752 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8753 1000 - i);
8754
8755 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008756 }
James Ketrenosb095c382005-08-24 22:04:42 -05008757#endif /* CONFIG_IPW2200_MONITOR */
8758
James Ketrenosc848d0a2005-08-24 21:56:24 -05008759 /* Network configuration changed -- force [re]association */
8760 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8761 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008762 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008763
8764 return 0;
8765}
8766
Jeff Garzikbf794512005-07-31 13:07:26 -04008767static int ipw_wx_set_freq(struct net_device *dev,
8768 struct iw_request_info *info,
8769 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008770{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008771 struct ipw_priv *priv = libipw_priv(dev);
8772 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008773 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008774 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008775 u8 channel, flags;
8776 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008777
James Ketrenosb095c382005-08-24 22:04:42 -05008778 if (fwrq->m == 0) {
8779 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008780 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008781 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008782 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008783 return ret;
8784 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008785 /* if setting by freq convert to channel */
8786 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008787 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008788 if (channel == 0)
8789 return -EINVAL;
8790 } else
8791 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008792
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008793 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008794 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008795
Liu Hong1fe0adb2005-08-19 09:33:10 -05008796 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008797 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008798 if (i == -1)
8799 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008800
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008801 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008802 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008803 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008804 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8805 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008806 }
8807 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008808
Frans Pop9fd1ea42010-03-24 19:46:31 +01008809 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008810 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008811 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008812 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008813 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008814}
8815
Jeff Garzikbf794512005-07-31 13:07:26 -04008816static int ipw_wx_get_freq(struct net_device *dev,
8817 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008818 union iwreq_data *wrqu, char *extra)
8819{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008820 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008821
8822 wrqu->freq.e = 0;
8823
8824 /* If we are associated, trying to associate, or have a statically
8825 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008826 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008827 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008828 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8829 int i;
8830
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008831 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008832 BUG_ON(i == -1);
8833 wrqu->freq.e = 1;
8834
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008835 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8836 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008837 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8838 break;
8839
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008840 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008841 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8842 break;
8843
8844 default:
8845 BUG();
8846 }
8847 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008848 wrqu->freq.m = 0;
8849
Zhu Yi46441512006-01-24 16:37:59 +08008850 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008851 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 return 0;
8853}
8854
Jeff Garzikbf794512005-07-31 13:07:26 -04008855static int ipw_wx_set_mode(struct net_device *dev,
8856 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008857 union iwreq_data *wrqu, char *extra)
8858{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008859 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008860 int err = 0;
8861
8862 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8863
James Ketrenos43f66a62005-03-25 12:31:53 -06008864 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008865#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008866 case IW_MODE_MONITOR:
8867#endif
8868 case IW_MODE_ADHOC:
8869 case IW_MODE_INFRA:
8870 break;
8871 case IW_MODE_AUTO:
8872 wrqu->mode = IW_MODE_INFRA;
8873 break;
8874 default:
8875 return -EINVAL;
8876 }
James Ketrenosb095c382005-08-24 22:04:42 -05008877 if (wrqu->mode == priv->ieee->iw_mode)
8878 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008879
Zhu Yi46441512006-01-24 16:37:59 +08008880 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008881
8882 ipw_sw_reset(priv, 0);
8883
James Ketrenosb095c382005-08-24 22:04:42 -05008884#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008885 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008886 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008887
8888 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008889#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008890 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8891#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008892 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008893#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008894#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008895
Jeff Garzikbf794512005-07-31 13:07:26 -04008896 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008897 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008898 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008899
8900 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008901
James Ketrenosc848d0a2005-08-24 21:56:24 -05008902 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008903 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008904 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008905}
8906
Jeff Garzikbf794512005-07-31 13:07:26 -04008907static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008908 struct iw_request_info *info,
8909 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008910{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008911 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008912 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008913 wrqu->mode = priv->ieee->iw_mode;
8914 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008915 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008916 return 0;
8917}
8918
James Ketrenos43f66a62005-03-25 12:31:53 -06008919/* Values are in microsecond */
8920static const s32 timeout_duration[] = {
8921 350000,
8922 250000,
8923 75000,
8924 37000,
8925 25000,
8926};
8927
8928static const s32 period_duration[] = {
8929 400000,
8930 700000,
8931 1000000,
8932 1000000,
8933 1000000
8934};
8935
Jeff Garzikbf794512005-07-31 13:07:26 -04008936static int ipw_wx_get_range(struct net_device *dev,
8937 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008938 union iwreq_data *wrqu, char *extra)
8939{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008940 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008941 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008942 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008943 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008944
8945 wrqu->data.length = sizeof(*range);
8946 memset(range, 0, sizeof(*range));
8947
8948 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008949 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008950
8951 range->max_qual.qual = 100;
8952 /* TODO: Find real max RSSI and stick here */
8953 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008954 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008955 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008956
8957 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008958 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008959 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008960 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008961 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008962 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008963 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008964
Jeff Garzikbf794512005-07-31 13:07:26 -04008965 for (i = 0; i < range->num_bitrates; i++)
8966 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008967 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008968
James Ketrenos43f66a62005-03-25 12:31:53 -06008969 range->max_rts = DEFAULT_RTS_THRESHOLD;
8970 range->min_frag = MIN_FRAG_THRESHOLD;
8971 range->max_frag = MAX_FRAG_THRESHOLD;
8972
8973 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008974 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008975 range->num_encoding_sizes = 2;
8976 range->max_encoding_tokens = WEP_KEYS;
8977
8978 /* Set the Wireless Extension versions */
8979 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008980 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008981
James Ketrenosb095c382005-08-24 22:04:42 -05008982 i = 0;
8983 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008984 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8985 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008986 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008987 continue;
8988
James Ketrenosb095c382005-08-24 22:04:42 -05008989 range->freq[i].i = geo->bg[j].channel;
8990 range->freq[i].m = geo->bg[j].freq * 100000;
8991 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008992 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008993 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008994 }
James Ketrenosb095c382005-08-24 22:04:42 -05008995
8996 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008997 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8998 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008999 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08009000 continue;
9001
James Ketrenosb095c382005-08-24 22:04:42 -05009002 range->freq[i].i = geo->a[j].channel;
9003 range->freq[i].m = geo->a[j].freq * 100000;
9004 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08009005 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05009006 }
9007 }
9008
9009 range->num_channels = i;
9010 range->num_frequency = i;
9011
Zhu Yi46441512006-01-24 16:37:59 +08009012 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009013
9014 /* Event capability (kernel + driver) */
9015 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
9016 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08009017 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9018 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009019 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009020
Dan Williamsf1b50862006-01-30 13:58:56 -05009021 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9022 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9023
Dan Williams374fdfb2007-12-12 10:25:07 -05009024 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9025
James Ketrenos43f66a62005-03-25 12:31:53 -06009026 IPW_DEBUG_WX("GET Range\n");
9027 return 0;
9028}
9029
Jeff Garzikbf794512005-07-31 13:07:26 -04009030static int ipw_wx_set_wap(struct net_device *dev,
9031 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009032 union iwreq_data *wrqu, char *extra)
9033{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009034 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009035
9036 static const unsigned char any[] = {
9037 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9038 };
9039 static const unsigned char off[] = {
9040 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9041 };
9042
Jeff Garzikbf794512005-07-31 13:07:26 -04009043 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009044 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009045 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009046 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9047 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9048 /* we disable mandatory BSSID association */
9049 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9050 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009051 IPW_DEBUG_ASSOC("Attempting to associate with new "
9052 "parameters.\n");
9053 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009054 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009055 return 0;
9056 }
9057
9058 priv->config |= CFG_STATIC_BSSID;
9059 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9060 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009061 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009062 return 0;
9063 }
9064
Johannes Berge1749612008-10-27 15:59:26 -07009065 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9066 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009067
9068 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9069
James Ketrenosc848d0a2005-08-24 21:56:24 -05009070 /* Network configuration changed -- force [re]association */
9071 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9072 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009073 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009074
Zhu Yi46441512006-01-24 16:37:59 +08009075 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009076 return 0;
9077}
9078
Jeff Garzikbf794512005-07-31 13:07:26 -04009079static int ipw_wx_get_wap(struct net_device *dev,
9080 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009081 union iwreq_data *wrqu, char *extra)
9082{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009083 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009084
James Ketrenos43f66a62005-03-25 12:31:53 -06009085 /* If we are associated, trying to associate, or have a statically
9086 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009087 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009088 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009089 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9090 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009091 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009092 } else
9093 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9094
Johannes Berge1749612008-10-27 15:59:26 -07009095 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9096 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009097 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009098 return 0;
9099}
9100
Jeff Garzikbf794512005-07-31 13:07:26 -04009101static int ipw_wx_set_essid(struct net_device *dev,
9102 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009103 union iwreq_data *wrqu, char *extra)
9104{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009105 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009106 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009107 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009108
Zhu Yiab644b02006-08-21 11:37:13 +08009109 mutex_lock(&priv->mutex);
9110
9111 if (!wrqu->essid.flags)
9112 {
9113 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9114 ipw_disassociate(priv);
9115 priv->config &= ~CFG_STATIC_ESSID;
9116 ipw_associate(priv);
9117 mutex_unlock(&priv->mutex);
9118 return 0;
9119 }
9120
Zhu Yia9f0d422006-08-21 11:37:26 +08009121 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009122
9123 priv->config |= CFG_STATIC_ESSID;
9124
Zhu Yia9f0d422006-08-21 11:37:26 +08009125 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9126 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009127 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009128 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 return 0;
9130 }
9131
John W. Linville9387b7c2008-09-30 20:59:05 -04009132 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9133 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009134
9135 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009136 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009137
James Ketrenosc848d0a2005-08-24 21:56:24 -05009138 /* Network configuration changed -- force [re]association */
9139 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9140 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009141 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009142
Zhu Yi46441512006-01-24 16:37:59 +08009143 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 return 0;
9145}
9146
Jeff Garzikbf794512005-07-31 13:07:26 -04009147static int ipw_wx_get_essid(struct net_device *dev,
9148 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009149 union iwreq_data *wrqu, char *extra)
9150{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009151 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009152 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009153
9154 /* If we are associated, trying to associate, or have a statically
9155 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009156 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009157 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009158 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9159 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009160 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009161 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009162 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009163 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 } else {
9165 IPW_DEBUG_WX("Getting essid: ANY\n");
9166 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009168 }
Zhu Yi46441512006-01-24 16:37:59 +08009169 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009170 return 0;
9171}
9172
Jeff Garzikbf794512005-07-31 13:07:26 -04009173static int ipw_wx_set_nick(struct net_device *dev,
9174 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009175 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009176{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009177 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009178
9179 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9180 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9181 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009182 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009183 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009185 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009186 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009187 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009188 return 0;
9189
9190}
9191
Jeff Garzikbf794512005-07-31 13:07:26 -04009192static int ipw_wx_get_nick(struct net_device *dev,
9193 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009194 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009195{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009196 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009197 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009198 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009199 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009200 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009201 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009202 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009203 return 0;
9204}
9205
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009206static int ipw_wx_set_sens(struct net_device *dev,
9207 struct iw_request_info *info,
9208 union iwreq_data *wrqu, char *extra)
9209{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009210 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009211 int err = 0;
9212
9213 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9214 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9215 mutex_lock(&priv->mutex);
9216
9217 if (wrqu->sens.fixed == 0)
9218 {
9219 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9220 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9221 goto out;
9222 }
9223 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9224 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9225 err = -EINVAL;
9226 goto out;
9227 }
9228
9229 priv->roaming_threshold = wrqu->sens.value;
9230 priv->disassociate_threshold = 3*wrqu->sens.value;
9231 out:
9232 mutex_unlock(&priv->mutex);
9233 return err;
9234}
9235
9236static int ipw_wx_get_sens(struct net_device *dev,
9237 struct iw_request_info *info,
9238 union iwreq_data *wrqu, char *extra)
9239{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009240 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009241 mutex_lock(&priv->mutex);
9242 wrqu->sens.fixed = 1;
9243 wrqu->sens.value = priv->roaming_threshold;
9244 mutex_unlock(&priv->mutex);
9245
Frans Pop9fd1ea42010-03-24 19:46:31 +01009246 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009247 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9248
9249 return 0;
9250}
9251
James Ketrenos43f66a62005-03-25 12:31:53 -06009252static int ipw_wx_set_rate(struct net_device *dev,
9253 struct iw_request_info *info,
9254 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009255{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009256 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009257 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009258 u32 target_rate = wrqu->bitrate.value;
9259 u32 fixed, mask;
9260
9261 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9262 /* value = X, fixed = 1 means only rate X */
9263 /* value = X, fixed = 0 means all rates lower equal X */
9264
9265 if (target_rate == -1) {
9266 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009267 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009268 /* Now we should reassociate */
9269 goto apply;
9270 }
9271
9272 mask = 0;
9273 fixed = wrqu->bitrate.fixed;
9274
9275 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009276 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009277 if (target_rate == 1000000)
9278 goto apply;
9279
9280 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009281 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009282 if (target_rate == 2000000)
9283 goto apply;
9284
9285 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009286 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009287 if (target_rate == 5500000)
9288 goto apply;
9289
9290 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009291 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009292 if (target_rate == 6000000)
9293 goto apply;
9294
9295 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009296 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009297 if (target_rate == 9000000)
9298 goto apply;
9299
9300 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009301 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009302 if (target_rate == 11000000)
9303 goto apply;
9304
9305 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009306 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009307 if (target_rate == 12000000)
9308 goto apply;
9309
9310 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009311 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009312 if (target_rate == 18000000)
9313 goto apply;
9314
9315 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009316 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009317 if (target_rate == 24000000)
9318 goto apply;
9319
9320 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009321 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009322 if (target_rate == 36000000)
9323 goto apply;
9324
9325 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009326 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009327 if (target_rate == 48000000)
9328 goto apply;
9329
9330 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009331 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009332 if (target_rate == 54000000)
9333 goto apply;
9334
9335 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9336 return -EINVAL;
9337
9338 apply:
9339 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9340 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009341 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009342 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009343 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009344 ipw_set_fixed_rate(priv, priv->ieee->mode);
9345 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009346 priv->config |= CFG_FIXED_RATE;
9347
James Ketrenosc848d0a2005-08-24 21:56:24 -05009348 if (priv->rates_mask == mask) {
9349 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009350 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009351 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009352 }
9353
James Ketrenosc848d0a2005-08-24 21:56:24 -05009354 priv->rates_mask = mask;
9355
9356 /* Network configuration changed -- force [re]association */
9357 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9358 if (!ipw_disassociate(priv))
9359 ipw_associate(priv);
9360
Zhu Yi46441512006-01-24 16:37:59 +08009361 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009362 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009363}
9364
Jeff Garzikbf794512005-07-31 13:07:26 -04009365static int ipw_wx_get_rate(struct net_device *dev,
9366 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009367 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009368{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009369 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009370 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009371 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009372 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009373 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009374 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 return 0;
9376}
9377
Jeff Garzikbf794512005-07-31 13:07:26 -04009378static int ipw_wx_set_rts(struct net_device *dev,
9379 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009380 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009381{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009382 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009383 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009384 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009385 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9386 else {
9387 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009388 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009389 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009390 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009391 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009392 priv->rts_threshold = wrqu->rts.value;
9393 }
9394
9395 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009396 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009397 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009398 return 0;
9399}
9400
Jeff Garzikbf794512005-07-31 13:07:26 -04009401static int ipw_wx_get_rts(struct net_device *dev,
9402 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009403 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009404{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009405 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009406 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009407 wrqu->rts.value = priv->rts_threshold;
9408 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009409 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009410 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009411 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009412 return 0;
9413}
9414
Jeff Garzikbf794512005-07-31 13:07:26 -04009415static int ipw_wx_set_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 Yi6de9f7f2005-08-11 14:39:33 +08009420 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009421
Zhu Yi46441512006-01-24 16:37:59 +08009422 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009423 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009424 err = -EINPROGRESS;
9425 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009426 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009427
James Ketrenosb095c382005-08-24 22:04:42 -05009428 if (!wrqu->power.fixed)
9429 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009430
James Ketrenosc848d0a2005-08-24 21:56:24 -05009431 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009432 err = -EINVAL;
9433 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009434 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009435
James Ketrenosb095c382005-08-24 22:04:42 -05009436 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009437 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009438 err = -EINVAL;
9439 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009440 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009441
9442 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009443 err = ipw_set_tx_power(priv);
9444 out:
Zhu Yi46441512006-01-24 16:37:59 +08009445 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009446 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009447}
9448
Jeff Garzikbf794512005-07-31 13:07:26 -04009449static int ipw_wx_get_txpow(struct net_device *dev,
9450 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009451 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009452{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009453 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009454 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009455 wrqu->power.value = priv->tx_power;
9456 wrqu->power.fixed = 1;
9457 wrqu->power.flags = IW_TXPOW_DBM;
9458 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009459 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009460
Frans Pop9fd1ea42010-03-24 19:46:31 +01009461 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009462 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463
9464 return 0;
9465}
9466
Jeff Garzikbf794512005-07-31 13:07:26 -04009467static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009468 struct iw_request_info *info,
9469 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009470{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009471 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009472 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009473 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009474 priv->ieee->fts = DEFAULT_FTS;
9475 else {
9476 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009477 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009478 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009479 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009480 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009481
James Ketrenos43f66a62005-03-25 12:31:53 -06009482 priv->ieee->fts = wrqu->frag.value & ~0x1;
9483 }
9484
9485 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009486 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009487 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009488 return 0;
9489}
9490
Jeff Garzikbf794512005-07-31 13:07:26 -04009491static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009492 struct iw_request_info *info,
9493 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009494{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009495 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009496 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009497 wrqu->frag.value = priv->ieee->fts;
9498 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009499 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009500 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009501 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009502
9503 return 0;
9504}
9505
Jeff Garzikbf794512005-07-31 13:07:26 -04009506static int ipw_wx_set_retry(struct net_device *dev,
9507 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009508 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009509{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009510 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009511
9512 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9513 return -EINVAL;
9514
9515 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9516 return 0;
9517
Zhu Yid5f7ac22006-08-21 11:38:17 +08009518 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009519 return -EINVAL;
9520
Zhu Yi46441512006-01-24 16:37:59 +08009521 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009522 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009523 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009524 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009525 priv->long_retry_limit = (u8) wrqu->retry.value;
9526 else {
9527 priv->short_retry_limit = (u8) wrqu->retry.value;
9528 priv->long_retry_limit = (u8) wrqu->retry.value;
9529 }
9530
9531 ipw_send_retry_limit(priv, priv->short_retry_limit,
9532 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009533 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009534 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9535 priv->short_retry_limit, priv->long_retry_limit);
9536 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009537}
9538
Jeff Garzikbf794512005-07-31 13:07:26 -04009539static int ipw_wx_get_retry(struct net_device *dev,
9540 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009541 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009542{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009543 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009544
Zhu Yi46441512006-01-24 16:37:59 +08009545 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009546 wrqu->retry.disabled = 0;
9547
9548 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009549 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009550 return -EINVAL;
9551 }
9552
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009553 if (wrqu->retry.flags & IW_RETRY_LONG) {
9554 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009555 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009556 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9557 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009558 wrqu->retry.value = priv->short_retry_limit;
9559 } else {
9560 wrqu->retry.flags = IW_RETRY_LIMIT;
9561 wrqu->retry.value = priv->short_retry_limit;
9562 }
Zhu Yi46441512006-01-24 16:37:59 +08009563 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009564
Frans Pop9fd1ea42010-03-24 19:46:31 +01009565 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009566
9567 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009568}
9569
Jeff Garzikbf794512005-07-31 13:07:26 -04009570static int ipw_wx_set_scan(struct net_device *dev,
9571 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009572 union iwreq_data *wrqu, char *extra)
9573{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009574 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009575 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009576 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009577
Dan Williams0b531672007-10-09 13:55:24 -04009578 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009579
Dan Williams0b531672007-10-09 13:55:24 -04009580 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009581
Zhu Yi094c4d22006-08-21 11:39:03 +08009582 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009583 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009584 int len = min((int)req->essid_len,
9585 (int)sizeof(priv->direct_scan_ssid));
9586 memcpy(priv->direct_scan_ssid, req->essid, len);
9587 priv->direct_scan_ssid_len = len;
9588 work = &priv->request_direct_scan;
9589 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9590 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009591 }
Dan Williamsea177302008-06-02 17:51:23 -04009592 } else {
9593 /* Normal active broadcast scan */
9594 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009595 }
James Ketrenos8935f392005-10-05 15:59:08 -05009596
Dan Williamsea177302008-06-02 17:51:23 -04009597 mutex_unlock(&priv->mutex);
9598
James Ketrenos43f66a62005-03-25 12:31:53 -06009599 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009600
Dan Williamsea177302008-06-02 17:51:23 -04009601 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009602
James Ketrenos43f66a62005-03-25 12:31:53 -06009603 return 0;
9604}
9605
Jeff Garzikbf794512005-07-31 13:07:26 -04009606static int ipw_wx_get_scan(struct net_device *dev,
9607 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009608 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009609{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009610 struct ipw_priv *priv = libipw_priv(dev);
9611 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009612}
9613
Jeff Garzikbf794512005-07-31 13:07:26 -04009614static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009615 struct iw_request_info *info,
9616 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009617{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009618 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009619 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009620 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009621
Zhu Yi46441512006-01-24 16:37:59 +08009622 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009623 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009624
Hong Liucaeff812005-08-05 17:25:50 +08009625 /* In IBSS mode, we need to notify the firmware to update
9626 * the beacon info after we changed the capability. */
9627 if (cap != priv->capability &&
9628 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9629 priv->status & STATUS_ASSOCIATED)
9630 ipw_disassociate(priv);
9631
Zhu Yi46441512006-01-24 16:37:59 +08009632 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009633 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009634}
9635
Jeff Garzikbf794512005-07-31 13:07:26 -04009636static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009637 struct iw_request_info *info,
9638 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009639{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009640 struct ipw_priv *priv = libipw_priv(dev);
9641 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009642}
9643
Jeff Garzikbf794512005-07-31 13:07:26 -04009644static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009645 struct iw_request_info *info,
9646 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009647{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009648 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009649 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009650 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009651 if (wrqu->power.disabled) {
9652 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9653 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9654 if (err) {
9655 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009656 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009657 return err;
9658 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009659 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009660 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009661 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009662 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009663
9664 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009665 case IW_POWER_ON: /* If not specified */
9666 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009667 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009669 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9671 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009672 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009673 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009674 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009675
James Ketrenos43f66a62005-03-25 12:31:53 -06009676 /* If the user hasn't specified a power management mode yet, default
9677 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009678 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009679 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009680 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009681 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009682
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9684 if (err) {
9685 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009686 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 return err;
9688 }
9689
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009690 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009691 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 return 0;
9693}
9694
Jeff Garzikbf794512005-07-31 13:07:26 -04009695static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009696 struct iw_request_info *info,
9697 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009698{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009699 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009700 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009701 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009702 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009703 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009705
Zhu Yi46441512006-01-24 16:37:59 +08009706 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009707 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009708
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 return 0;
9710}
9711
Jeff Garzikbf794512005-07-31 13:07:26 -04009712static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009713 struct iw_request_info *info,
9714 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009715{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009716 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009717 int mode = *(int *)extra;
9718 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009719
Zhu Yi46441512006-01-24 16:37:59 +08009720 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009721 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009722 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009723
Zhu Yi4e157f02007-07-12 16:09:32 +08009724 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009725 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 if (err) {
9727 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009728 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009729 return err;
9730 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009731 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009732 }
Zhu Yi46441512006-01-24 16:37:59 +08009733 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009734 return 0;
9735}
9736
9737#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009738static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009739 struct iw_request_info *info,
9740 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009741{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009742 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009743 int level = IPW_POWER_LEVEL(priv->power_mode);
9744 char *p = extra;
9745
9746 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9747
9748 switch (level) {
9749 case IPW_POWER_AC:
9750 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9751 break;
9752 case IPW_POWER_BATTERY:
9753 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9754 break;
9755 default:
9756 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009757 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009758 timeout_duration[level - 1] / 1000,
9759 period_duration[level - 1] / 1000);
9760 }
9761
9762 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009763 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009764
9765 wrqu->data.length = p - extra + 1;
9766
9767 return 0;
9768}
9769
9770static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009771 struct iw_request_info *info,
9772 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009773{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009774 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 int mode = *(int *)extra;
9776 u8 band = 0, modulation = 0;
9777
9778 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009779 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009780 return -EINVAL;
9781 }
Zhu Yi46441512006-01-24 16:37:59 +08009782 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009783 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009784 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009785 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009786 band |= LIBIPW_52GHZ_BAND;
9787 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009788 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009789 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 } else {
9791 if (mode & IEEE_A) {
9792 IPW_WARNING("Attempt to set 2200BG into "
9793 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009794 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009795 return -EINVAL;
9796 }
9797
James Ketrenosa33a1982005-09-14 14:28:59 -05009798 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009799 }
9800
9801 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009802 band |= LIBIPW_24GHZ_BAND;
9803 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009804 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009805 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009806
James Ketrenos43f66a62005-03-25 12:31:53 -06009807 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009808 band |= LIBIPW_24GHZ_BAND;
9809 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009810 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009811 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009812
9813 priv->ieee->mode = mode;
9814 priv->ieee->freq_band = band;
9815 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009816 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009817
James Ketrenosc848d0a2005-08-24 21:56:24 -05009818 /* Network configuration changed -- force [re]association */
9819 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9820 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009821 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009822 ipw_associate(priv);
9823 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009824
James Ketrenosa613bff2005-08-24 21:43:11 -05009825 /* Update the band LEDs */
9826 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009827
Jeff Garzikbf794512005-07-31 13:07:26 -04009828 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009829 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009830 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009831 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009832 return 0;
9833}
9834
9835static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009836 struct iw_request_info *info,
9837 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009839 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009840 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009841 switch (priv->ieee->mode) {
9842 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009843 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9844 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009845 case IEEE_B:
9846 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9847 break;
9848 case IEEE_A | IEEE_B:
9849 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9850 break;
9851 case IEEE_G:
9852 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9853 break;
9854 case IEEE_A | IEEE_G:
9855 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9856 break;
9857 case IEEE_B | IEEE_G:
9858 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9859 break;
9860 case IEEE_A | IEEE_B | IEEE_G:
9861 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9862 break;
9863 default:
9864 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009865 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009866 }
9867
James Ketrenos43f66a62005-03-25 12:31:53 -06009868 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9869
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009870 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009871 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009872
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009873 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009874}
9875
James Ketrenosea2b26e2005-08-24 21:25:16 -05009876static int ipw_wx_set_preamble(struct net_device *dev,
9877 struct iw_request_info *info,
9878 union iwreq_data *wrqu, char *extra)
9879{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009880 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009882 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009883 /* Switching from SHORT -> LONG requires a disassociation */
9884 if (mode == 1) {
9885 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9886 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009887
9888 /* Network configuration changed -- force [re]association */
9889 IPW_DEBUG_ASSOC
9890 ("[re]association triggered due to preamble change.\n");
9891 if (!ipw_disassociate(priv))
9892 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009893 }
9894 goto done;
9895 }
9896
9897 if (mode == 0) {
9898 priv->config &= ~CFG_PREAMBLE_LONG;
9899 goto done;
9900 }
Zhu Yi46441512006-01-24 16:37:59 +08009901 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009902 return -EINVAL;
9903
9904 done:
Zhu Yi46441512006-01-24 16:37:59 +08009905 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009906 return 0;
9907}
9908
9909static int ipw_wx_get_preamble(struct net_device *dev,
9910 struct iw_request_info *info,
9911 union iwreq_data *wrqu, char *extra)
9912{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009913 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009914 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009915 if (priv->config & CFG_PREAMBLE_LONG)
9916 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9917 else
9918 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009919 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009920 return 0;
9921}
9922
James Ketrenosb095c382005-08-24 22:04:42 -05009923#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009924static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009925 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 int *parms = (int *)extra;
9930 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009931 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009932 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009933 if (enable) {
9934 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009935#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009936 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9937#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009938 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009939#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009940 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009941 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009942
James Ketrenos43f66a62005-03-25 12:31:53 -06009943 ipw_set_channel(priv, parms[1]);
9944 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009945 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009946 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009947 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009948 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009949 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009950 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009951 }
Zhu Yi46441512006-01-24 16:37:59 +08009952 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009953 return 0;
9954}
9955
Pavel Machek67fd6b42006-07-11 15:34:05 +02009956#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009957
Jeff Garzikbf794512005-07-31 13:07:26 -04009958static int ipw_wx_reset(struct net_device *dev,
9959 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009960 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009961{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009962 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009963 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009964 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009965 return 0;
9966}
James Ketrenosb095c382005-08-24 22:04:42 -05009967
James Ketrenosb095c382005-08-24 22:04:42 -05009968static int ipw_wx_sw_reset(struct net_device *dev,
9969 struct iw_request_info *info,
9970 union iwreq_data *wrqu, char *extra)
9971{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009972 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009973 union iwreq_data wrqu_sec = {
9974 .encoding = {
9975 .flags = IW_ENCODE_DISABLED,
9976 },
9977 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009978 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009979
9980 IPW_DEBUG_WX("SW_RESET\n");
9981
Zhu Yi46441512006-01-24 16:37:59 +08009982 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009983
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009984 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009985 if (!ret) {
9986 free_firmware();
9987 ipw_adapter_restart(priv);
9988 }
James Ketrenosb095c382005-08-24 22:04:42 -05009989
9990 /* The SW reset bit might have been toggled on by the 'disable'
9991 * module parameter, so take appropriate action */
9992 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9993
Zhu Yi46441512006-01-24 16:37:59 +08009994 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009995 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009996 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009997
9998 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9999 /* Configuration likely changed -- force [re]association */
10000 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
10001 "reset.\n");
10002 if (!ipw_disassociate(priv))
10003 ipw_associate(priv);
10004 }
10005
Zhu Yi46441512006-01-24 16:37:59 +080010006 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -050010007
10008 return 0;
10009}
James Ketrenos43f66a62005-03-25 12:31:53 -060010010
10011/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010012static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -070010013 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
10014 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
10015 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
10016 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
10017 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
10018 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
10019 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
10020 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
10021 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
10022 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
10023 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
10024 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10025 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10026 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10027 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10028 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10029 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10030 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10031 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10032 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10033 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10034 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10035 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10036 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10037 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10038 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10039 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10040 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10041 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10042 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10043 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10044 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10045 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10046 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10047 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10048 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10049 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10050 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10051 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10052 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10053 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010054};
10055
James Ketrenosb095c382005-08-24 22:04:42 -050010056enum {
10057 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10058 IPW_PRIV_GET_POWER,
10059 IPW_PRIV_SET_MODE,
10060 IPW_PRIV_GET_MODE,
10061 IPW_PRIV_SET_PREAMBLE,
10062 IPW_PRIV_GET_PREAMBLE,
10063 IPW_PRIV_RESET,
10064 IPW_PRIV_SW_RESET,
10065#ifdef CONFIG_IPW2200_MONITOR
10066 IPW_PRIV_SET_MONITOR,
10067#endif
10068};
James Ketrenos43f66a62005-03-25 12:31:53 -060010069
Jeff Garzikbf794512005-07-31 13:07:26 -040010070static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010072 .cmd = IPW_PRIV_SET_POWER,
10073 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10074 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010075 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010076 .cmd = IPW_PRIV_GET_POWER,
10077 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10078 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010079 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010080 .cmd = IPW_PRIV_SET_MODE,
10081 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10082 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010083 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010084 .cmd = IPW_PRIV_GET_MODE,
10085 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10086 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010087 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010088 .cmd = IPW_PRIV_SET_PREAMBLE,
10089 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10090 .name = "set_preamble"},
10091 {
10092 .cmd = IPW_PRIV_GET_PREAMBLE,
10093 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10094 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010095 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010096 IPW_PRIV_RESET,
10097 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010098 {
10099 IPW_PRIV_SW_RESET,
10100 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10101#ifdef CONFIG_IPW2200_MONITOR
10102 {
10103 IPW_PRIV_SET_MONITOR,
10104 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10105#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010106};
10107
10108static iw_handler ipw_priv_handler[] = {
10109 ipw_wx_set_powermode,
10110 ipw_wx_get_powermode,
10111 ipw_wx_set_wireless_mode,
10112 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010113 ipw_wx_set_preamble,
10114 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010115 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010116 ipw_wx_sw_reset,
10117#ifdef CONFIG_IPW2200_MONITOR
10118 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010119#endif
10120};
10121
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010122static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010123 .standard = ipw_wx_handlers,
10124 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10125 .num_private = ARRAY_SIZE(ipw_priv_handler),
10126 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10127 .private = ipw_priv_handler,
10128 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010129 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010130};
10131
James Ketrenos43f66a62005-03-25 12:31:53 -060010132/*
10133 * Get wireless statistics.
10134 * Called by /proc/net/wireless
10135 * Also called by SIOCGIWSTATS
10136 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010137static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010138{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010139 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010140 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010141
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 wstats = &priv->wstats;
10143
James Ketrenosea2b26e2005-08-24 21:25:16 -050010144 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010145 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010146 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10147 * and associated; if not associcated, the values are all meaningless
10148 * anyway, so set them all to NULL and INVALID */
10149 if (!(priv->status & STATUS_ASSOCIATED)) {
10150 wstats->miss.beacon = 0;
10151 wstats->discard.retries = 0;
10152 wstats->qual.qual = 0;
10153 wstats->qual.level = 0;
10154 wstats->qual.noise = 0;
10155 wstats->qual.updated = 7;
10156 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010157 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010158 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010159 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010160
10161 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010162 wstats->qual.level = priv->exp_avg_rssi;
10163 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010164 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010165 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010166
10167 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10168 wstats->discard.retries = priv->last_tx_failures;
10169 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010170
James Ketrenos43f66a62005-03-25 12:31:53 -060010171/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10172 goto fail_get_ordinal;
10173 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010174
James Ketrenos43f66a62005-03-25 12:31:53 -060010175 return wstats;
10176}
10177
James Ketrenos43f66a62005-03-25 12:31:53 -060010178/* net device stuff */
10179
Arjan van de Ven858119e2006-01-14 13:20:43 -080010180static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010181{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010182 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010183 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010184 sys_config->answer_broadcast_ssid_probe = 0;
10185 sys_config->accept_all_data_frames = 0;
10186 sys_config->accept_non_directed_frames = 1;
10187 sys_config->exclude_unicast_unencrypted = 0;
10188 sys_config->disable_unicast_decryption = 1;
10189 sys_config->exclude_multicast_unencrypted = 0;
10190 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010191 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10192 antenna = CFG_SYS_ANTENNA_BOTH;
10193 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010194 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010196 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010197 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010198 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010199 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010200}
10201
10202static int ipw_net_open(struct net_device *dev)
10203{
James Ketrenos43f66a62005-03-25 12:31:53 -060010204 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010205 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010206 return 0;
10207}
10208
10209static int ipw_net_stop(struct net_device *dev)
10210{
10211 IPW_DEBUG_INFO("dev->close\n");
10212 netif_stop_queue(dev);
10213 return 0;
10214}
10215
10216/*
10217todo:
10218
10219modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010220we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010221*/
10222
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010223static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010224 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010225{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010226 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010227 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010228 int i = 0;
10229 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010230#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010231 int tx_id = ipw_get_tx_queue_number(priv, pri);
10232 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10233#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010234 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010235#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010236 struct clx2_queue *q = &txq->q;
10237 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010238 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010239
Zhu Yib8ddafd2008-11-27 13:42:20 +080010240 if (!(priv->status & STATUS_ASSOCIATED))
10241 goto drop;
10242
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010243 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010244 switch (priv->ieee->iw_mode) {
10245 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010246 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010247 id = ipw_find_station(priv, hdr->addr1);
10248 if (id == IPW_INVALID_STATION) {
10249 id = ipw_add_station(priv, hdr->addr1);
10250 if (id == IPW_INVALID_STATION) {
10251 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010252 "invalid cell: %pM\n",
10253 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010254 goto drop;
10255 }
10256 }
10257 break;
10258
10259 case IW_MODE_INFRA:
10260 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010261 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010262 id = 0;
10263 break;
10264 }
10265
10266 tfd = &txq->bd[q->first_empty];
10267 txq->txb[q->first_empty] = txb;
10268 memset(tfd, 0, sizeof(*tfd));
10269 tfd->u.data.station_number = id;
10270
10271 tfd->control_flags.message_type = TX_FRAME_TYPE;
10272 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10273
10274 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010275 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010276
James Ketrenos43f66a62005-03-25 12:31:53 -060010277 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010278 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010279 else
James Ketrenosb095c382005-08-24 22:04:42 -050010280 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010281
James Ketrenosea2b26e2005-08-24 21:25:16 -050010282 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10283 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010284
James Ketrenosc848d0a2005-08-24 21:56:24 -050010285 fc = le16_to_cpu(hdr->frame_ctl);
10286 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010287
10288 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10289
James Ketrenosb095c382005-08-24 22:04:42 -050010290 if (likely(unicast))
10291 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10292
10293 if (txb->encrypted && !priv->ieee->host_encrypt) {
10294 switch (priv->ieee->sec.level) {
10295 case SEC_LEVEL_3:
10296 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010297 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010298 /* XXX: ACK flag must be set for CCMP even if it
10299 * is a multicast/broadcast packet, because CCMP
10300 * group communication encrypted by GTK is
10301 * actually done by the AP. */
10302 if (!unicast)
10303 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10304
10305 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10306 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10307 tfd->u.data.key_index = 0;
10308 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10309 break;
10310 case SEC_LEVEL_2:
10311 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010312 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010313 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10314 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10315 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10316 break;
10317 case SEC_LEVEL_1:
10318 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010319 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010320 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10321 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010322 40)
10323 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10324 else
10325 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10326 break;
10327 case SEC_LEVEL_0:
10328 break;
10329 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010330 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010331 priv->ieee->sec.level);
10332 break;
10333 }
10334 } else
10335 /* No hardware encryption */
10336 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10337
Zhu Yie43e3c12006-04-13 17:20:45 +080010338#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010339 if (fc & IEEE80211_STYPE_QOS_DATA)
10340 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010341#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010342
James Ketrenos43f66a62005-03-25 12:31:53 -060010343 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010344 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10345 txb->nr_frags));
10346 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10347 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10348 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10349 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10350 i, le32_to_cpu(tfd->u.data.num_chunks),
10351 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010352 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010353 i, tfd->u.data.num_chunks,
10354 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010355 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010356 txb->fragments[i]->len - hdr_len);
10357
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,
10361 txb->fragments[i]->data + hdr_len,
10362 txb->fragments[i]->len - hdr_len,
10363 PCI_DMA_TODEVICE));
10364 tfd->u.data.chunk_len[i] =
10365 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010366 }
10367
10368 if (i != txb->nr_frags) {
10369 struct sk_buff *skb;
10370 u16 remaining_bytes = 0;
10371 int j;
10372
10373 for (j = i; j < txb->nr_frags; j++)
10374 remaining_bytes += txb->fragments[j]->len - hdr_len;
10375
10376 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10377 remaining_bytes);
10378 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10379 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010380 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010381 for (j = i; j < txb->nr_frags; j++) {
10382 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010383
James Ketrenos43f66a62005-03-25 12:31:53 -060010384 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010385 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010386 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010387 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010388 }
10389 dev_kfree_skb_any(txb->fragments[i]);
10390 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010391 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010392 cpu_to_le32(pci_map_single
10393 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010394 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010395 PCI_DMA_TODEVICE));
10396
Marcin Slusarz5c058632008-02-13 00:06:12 +010010397 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010398 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010399 }
10400
10401 /* kick DMA */
10402 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10403 ipw_write32(priv, q->reg_w, q->first_empty);
10404
Dan Williams943dbef2008-02-14 17:49:41 -050010405 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010406 netif_stop_queue(priv->net_dev);
10407
James Ketrenos227d2dc2005-07-28 16:25:55 -050010408 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010409
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010410 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010411 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010412 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010413 return NETDEV_TX_OK;
10414}
10415
10416static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10417{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010418 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010419#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010420 int tx_id = ipw_get_tx_queue_number(priv, pri);
10421 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10422#else
10423 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010424#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010425
Dan Williams943dbef2008-02-14 17:49:41 -050010426 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010427 return 1;
10428
10429 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010430}
10431
Zhu Yid685b8c2006-04-13 17:20:27 +080010432#ifdef CONFIG_IPW2200_PROMISCUOUS
10433static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010434 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010435{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010436 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010437 struct ieee80211_hdr *hdr;
10438 u8 n;
10439 u16 filter = priv->prom_priv->filter;
10440 int hdr_only = 0;
10441
10442 if (filter & IPW_PROM_NO_TX)
10443 return;
10444
10445 memset(&dummystats, 0, sizeof(dummystats));
10446
10447 /* Filtering of fragment chains is done agains the first fragment */
10448 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010449 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010450 if (filter & IPW_PROM_NO_MGMT)
10451 return;
10452 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10453 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010454 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010455 if (filter & IPW_PROM_NO_CTL)
10456 return;
10457 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10458 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010459 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010460 if (filter & IPW_PROM_NO_DATA)
10461 return;
10462 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10463 hdr_only = 1;
10464 }
10465
10466 for(n=0; n<txb->nr_frags; ++n) {
10467 struct sk_buff *src = txb->fragments[n];
10468 struct sk_buff *dst;
10469 struct ieee80211_radiotap_header *rt_hdr;
10470 int len;
10471
10472 if (hdr_only) {
10473 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010474 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010475 } else
10476 len = src->len;
10477
Johannes Berg007e5dd2008-11-27 23:13:38 +010010478 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10479 if (!dst)
10480 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010481
10482 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10483
10484 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10485 rt_hdr->it_pad = 0;
10486 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010487 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010488
Al Viroe62e1ee2007-12-27 01:36:46 -050010489 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010490 ieee80211chan2mhz(priv->channel));
10491 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010492 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010493 cpu_to_le16(IEEE80211_CHAN_OFDM |
10494 IEEE80211_CHAN_5GHZ);
10495 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010496 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010497 cpu_to_le16(IEEE80211_CHAN_CCK |
10498 IEEE80211_CHAN_2GHZ);
10499 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010500 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010501 cpu_to_le16(IEEE80211_CHAN_OFDM |
10502 IEEE80211_CHAN_2GHZ);
10503
Al Viro743b84d2007-12-27 01:43:16 -050010504 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010505
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010506 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010507
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010508 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010509 dev_kfree_skb_any(dst);
10510 }
10511}
10512#endif
10513
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010514static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10515 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010516{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010517 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010518 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010519 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010520
10521 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010522 spin_lock_irqsave(&priv->lock, flags);
10523
Zhu Yid685b8c2006-04-13 17:20:27 +080010524#ifdef CONFIG_IPW2200_PROMISCUOUS
10525 if (rtap_iface && netif_running(priv->prom_net_dev))
10526 ipw_handle_promiscuous_tx(priv, txb);
10527#endif
10528
James Ketrenos227d2dc2005-07-28 16:25:55 -050010529 ret = ipw_tx_skb(priv, txb, pri);
10530 if (ret == NETDEV_TX_OK)
10531 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010532 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010533
James Ketrenos227d2dc2005-07-28 16:25:55 -050010534 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010535}
10536
James Ketrenos43f66a62005-03-25 12:31:53 -060010537static void ipw_net_set_multicast_list(struct net_device *dev)
10538{
10539
10540}
10541
10542static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10543{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010544 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010545 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010546
James Ketrenos43f66a62005-03-25 12:31:53 -060010547 if (!is_valid_ether_addr(addr->sa_data))
10548 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010549 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010550 priv->config |= CFG_CUSTOM_MAC;
10551 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010552 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10553 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010554 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010555 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010556 return 0;
10557}
10558
Jeff Garzikbf794512005-07-31 13:07:26 -040010559static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010560 struct ethtool_drvinfo *info)
10561{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010562 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010563 char vers[64];
10564 char date[32];
10565 u32 len;
10566
10567 strcpy(info->driver, DRV_NAME);
10568 strcpy(info->version, DRV_VERSION);
10569
10570 len = sizeof(vers);
10571 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10572 len = sizeof(date);
10573 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10574
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010575 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010576 vers, date);
10577 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010578 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010579}
10580
10581static u32 ipw_ethtool_get_link(struct net_device *dev)
10582{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010583 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010584 return (priv->status & STATUS_ASSOCIATED) != 0;
10585}
10586
10587static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10588{
James Ketrenosb095c382005-08-24 22:04:42 -050010589 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010590}
10591
10592static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010593 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010594{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010595 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010596
James Ketrenosb095c382005-08-24 22:04:42 -050010597 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010598 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010599 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010600 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010601 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010602 return 0;
10603}
10604
10605static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010606 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010607{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010608 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010609 int i;
10610
James Ketrenosb095c382005-08-24 22:04:42 -050010611 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010612 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010613 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010614 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010615 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10616 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010617 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010618 return 0;
10619}
10620
Jeff Garzik7282d492006-09-13 14:30:00 -040010621static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010622 .get_link = ipw_ethtool_get_link,
10623 .get_drvinfo = ipw_ethtool_get_drvinfo,
10624 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10625 .get_eeprom = ipw_ethtool_get_eeprom,
10626 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010627};
10628
David Howells7d12e782006-10-05 14:55:46 +010010629static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010630{
10631 struct ipw_priv *priv = data;
10632 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010633
James Ketrenos43f66a62005-03-25 12:31:53 -060010634 if (!priv)
10635 return IRQ_NONE;
10636
Zhu Yi89c318e2006-06-08 22:19:49 -070010637 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010638
10639 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010640 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010641 goto none;
10642 }
10643
James Ketrenosb095c382005-08-24 22:04:42 -050010644 inta = ipw_read32(priv, IPW_INTA_RW);
10645 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010646
James Ketrenos43f66a62005-03-25 12:31:53 -060010647 if (inta == 0xFFFFFFFF) {
10648 /* Hardware disappeared */
10649 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10650 goto none;
10651 }
10652
James Ketrenosb095c382005-08-24 22:04:42 -050010653 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010654 /* Shared interrupt */
10655 goto none;
10656 }
10657
10658 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010659 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010660
James Ketrenos43f66a62005-03-25 12:31:53 -060010661 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010662 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10663 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010664
James Ketrenos43f66a62005-03-25 12:31:53 -060010665 /* Cache INTA value for our tasklet */
10666 priv->isr_inta = inta;
10667
10668 tasklet_schedule(&priv->irq_tasklet);
10669
Zhu Yi89c318e2006-06-08 22:19:49 -070010670 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010671
10672 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010673 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010674 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010675 return IRQ_NONE;
10676}
10677
10678static void ipw_rf_kill(void *adapter)
10679{
10680 struct ipw_priv *priv = adapter;
10681 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010682
James Ketrenos43f66a62005-03-25 12:31:53 -060010683 spin_lock_irqsave(&priv->lock, flags);
10684
10685 if (rf_kill_active(priv)) {
10686 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10687 if (priv->workqueue)
10688 queue_delayed_work(priv->workqueue,
10689 &priv->rf_kill, 2 * HZ);
10690 goto exit_unlock;
10691 }
10692
10693 /* RF Kill is now disabled, so bring the device back up */
10694
10695 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10696 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10697 "device\n");
10698
10699 /* we can not do an adapter restart while inside an irq lock */
10700 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010701 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010702 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10703 "enabled\n");
10704
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010705 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010706 spin_unlock_irqrestore(&priv->lock, flags);
10707}
10708
David Howellsc4028952006-11-22 14:57:56 +000010709static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010710{
David Howellsc4028952006-11-22 14:57:56 +000010711 struct ipw_priv *priv =
10712 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010713 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010714 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010715 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010716}
10717
Adrian Bunka73e22b2006-01-21 01:39:42 +010010718static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010719{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010720 priv->last_seq_num = -1;
10721 priv->last_frag_num = -1;
10722 priv->last_packet_time = 0;
10723
James Ketrenosa613bff2005-08-24 21:43:11 -050010724 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010725
James Ketrenosc848d0a2005-08-24 21:56:24 -050010726 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010727 cancel_delayed_work(&priv->request_direct_scan);
10728 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010729 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010730 ipw_reset_stats(priv);
10731 /* Ensure the rate is updated immediately */
10732 priv->last_rate = ipw_get_current_rate(priv);
10733 ipw_gather_stats(priv);
10734 ipw_led_link_up(priv);
10735 notify_wx_assoc_event(priv);
10736
10737 if (priv->config & CFG_BACKGROUND_SCAN)
10738 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10739}
10740
David Howellsc4028952006-11-22 14:57:56 +000010741static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010742{
David Howellsc4028952006-11-22 14:57:56 +000010743 struct ipw_priv *priv =
10744 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010745 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010746 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010747 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010748}
10749
Adrian Bunka73e22b2006-01-21 01:39:42 +010010750static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010751{
10752 ipw_led_link_down(priv);
10753 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010754 notify_wx_assoc_event(priv);
10755
10756 /* Cancel any queued work ... */
10757 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010758 cancel_delayed_work(&priv->request_direct_scan);
10759 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010760 cancel_delayed_work(&priv->adhoc_check);
10761 cancel_delayed_work(&priv->gather_stats);
10762
10763 ipw_reset_stats(priv);
10764
James Ketrenosafbf30a2005-08-25 00:05:33 -050010765 if (!(priv->status & STATUS_EXIT_PENDING)) {
10766 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010767 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010768 } else
10769 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010770}
10771
David Howellsc4028952006-11-22 14:57:56 +000010772static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010773{
David Howellsc4028952006-11-22 14:57:56 +000010774 struct ipw_priv *priv =
10775 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010776 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010777 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010778 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010779}
10780
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010781static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010782{
10783 int ret = 0;
10784
James Ketrenos43f66a62005-03-25 12:31:53 -060010785 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010786 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010787 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010788
David Howellsc4028952006-11-22 14:57:56 +000010789 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10790 INIT_WORK(&priv->associate, ipw_bg_associate);
10791 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10792 INIT_WORK(&priv->system_config, ipw_system_config);
10793 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10794 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10795 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10796 INIT_WORK(&priv->up, ipw_bg_up);
10797 INIT_WORK(&priv->down, ipw_bg_down);
10798 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010799 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10800 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010801 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010802 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10803 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10804 INIT_WORK(&priv->roam, ipw_bg_roam);
10805 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10806 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10807 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10808 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10809 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10810 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10811 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010812
Zhu Yie43e3c12006-04-13 17:20:45 +080010813#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010814 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010815#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010816
10817 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10818 ipw_irq_tasklet, (unsigned long)priv);
10819
10820 return ret;
10821}
10822
James Ketrenos43f66a62005-03-25 12:31:53 -060010823static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010824 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010825{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010826 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010827 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010828 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010829 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010830 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010831 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010832 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010833 priv->ieee->sec.flags &= ~(1 << i);
10834 else {
10835 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010836 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010837 priv->ieee->sec.flags |= (1 << i);
10838 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010839 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010840 } else if (sec->level != SEC_LEVEL_1)
10841 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010842 }
10843
James Ketrenosb095c382005-08-24 22:04:42 -050010844 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010845 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010846 priv->ieee->sec.active_key = sec->active_key;
10847 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010848 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010849 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010850 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010851 } else
10852 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010853
10854 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010855 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10856 priv->ieee->sec.auth_mode = sec->auth_mode;
10857 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010858 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10859 priv->capability |= CAP_SHARED_KEY;
10860 else
10861 priv->capability &= ~CAP_SHARED_KEY;
10862 priv->status |= STATUS_SECURITY_UPDATED;
10863 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010864
James Ketrenosb095c382005-08-24 22:04:42 -050010865 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10866 priv->ieee->sec.flags |= SEC_ENABLED;
10867 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010868 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010869 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010870 priv->capability |= CAP_PRIVACY_ON;
10871 else
10872 priv->capability &= ~CAP_PRIVACY_ON;
10873 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010874
James Ketrenosafbf30a2005-08-25 00:05:33 -050010875 if (sec->flags & SEC_ENCRYPT)
10876 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010877
James Ketrenosb095c382005-08-24 22:04:42 -050010878 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10879 priv->ieee->sec.level = sec->level;
10880 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010881 priv->status |= STATUS_SECURITY_UPDATED;
10882 }
10883
Zhu Yi1fbfea52005-08-05 17:22:56 +080010884 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10885 ipw_set_hwcrypto_keys(priv);
10886
Jeff Garzikbf794512005-07-31 13:07:26 -040010887 /* To match current functionality of ipw2100 (which works well w/
10888 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010889 * privacy capability changes ... */
10890#if 0
10891 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010892 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010893 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010894 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010895 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010896 IPW_DEBUG_ASSOC("Disassociating due to capability "
10897 "change.\n");
10898 ipw_disassociate(priv);
10899 }
10900#endif
10901}
10902
Jeff Garzikbf794512005-07-31 13:07:26 -040010903static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010904 struct ipw_supported_rates *rates)
10905{
10906 /* TODO: Mask out rates based on priv->rates_mask */
10907
10908 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010909 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010910 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010911 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010912 rates->ieee_mode = IPW_A_MODE;
10913 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010914 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10915 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010916 break;
10917
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010918 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010919 rates->ieee_mode = IPW_G_MODE;
10920 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010921 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10922 LIBIPW_CCK_DEFAULT_RATES_MASK);
10923 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10924 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10925 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010926 }
10927 break;
10928 }
10929
10930 return 0;
10931}
10932
Jeff Garzikbf794512005-07-31 13:07:26 -040010933static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010934{
James Ketrenos43f66a62005-03-25 12:31:53 -060010935 /* This is only called from ipw_up, which resets/reloads the firmware
10936 so, we don't need to first disable the card before we configure
10937 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010938 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010939 goto error;
10940
10941 /* initialize adapter address */
10942 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10943 goto error;
10944
10945 /* set basic system config settings */
10946 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010947
10948 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10949 * Does not support BT priority yet (don't abort or defer our Tx) */
10950 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010951 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010952
10953 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10954 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010955 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010956 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10957 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010958 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010959 }
10960
Zhu Yid685b8c2006-04-13 17:20:27 +080010961#ifdef CONFIG_IPW2200_PROMISCUOUS
10962 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10963 priv->sys_config.accept_all_data_frames = 1;
10964 priv->sys_config.accept_non_directed_frames = 1;
10965 priv->sys_config.accept_all_mgmt_bcpr = 1;
10966 priv->sys_config.accept_all_mgmt_frames = 1;
10967 }
10968#endif
10969
James Ketrenosc848d0a2005-08-24 21:56:24 -050010970 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10971 priv->sys_config.answer_broadcast_ssid_probe = 1;
10972 else
10973 priv->sys_config.answer_broadcast_ssid_probe = 0;
10974
Zhu Yid685b8c2006-04-13 17:20:27 +080010975 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010976 goto error;
10977
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010978 init_supported_rates(priv, &priv->rates);
10979 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010980 goto error;
10981
10982 /* Set request-to-send threshold */
10983 if (priv->rts_threshold) {
10984 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10985 goto error;
10986 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010987#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010988 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10989 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010990#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010991
10992 if (ipw_set_random_seed(priv))
10993 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010994
James Ketrenos43f66a62005-03-25 12:31:53 -060010995 /* final state transition to the RUN state */
10996 if (ipw_send_host_complete(priv))
10997 goto error;
10998
James Ketrenose6666192005-08-12 09:17:04 -050010999 priv->status |= STATUS_INIT;
11000
11001 ipw_led_init(priv);
11002 ipw_led_radio_on(priv);
11003 priv->notif_missed_beacons = 0;
11004
11005 /* Set hardware WEP key if it is configured. */
11006 if ((priv->capability & CAP_PRIVACY_ON) &&
11007 (priv->ieee->sec.level == SEC_LEVEL_1) &&
11008 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
11009 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011010
11011 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040011012
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011013 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060011014 return -EIO;
11015}
11016
James Ketrenos4f36f802005-08-03 20:36:56 -050011017/*
11018 * NOTE:
11019 *
11020 * These tables have been tested in conjunction with the
11021 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11022 *
11023 * Altering this values, using it on other hardware, or in geographies
11024 * not intended for resale of the above mentioned Intel adapters has
11025 * not been tested.
11026 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011027 * Remember to update the table in README.ipw2200 when changing this
11028 * table.
11029 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011030 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011031static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011032 { /* Restricted */
11033 "---",
11034 .bg_channels = 11,
11035 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11036 {2427, 4}, {2432, 5}, {2437, 6},
11037 {2442, 7}, {2447, 8}, {2452, 9},
11038 {2457, 10}, {2462, 11}},
11039 },
11040
11041 { /* Custom US/Canada */
11042 "ZZF",
11043 .bg_channels = 11,
11044 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11}},
11048 .a_channels = 8,
11049 .a = {{5180, 36},
11050 {5200, 40},
11051 {5220, 44},
11052 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011053 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11054 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11055 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11056 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011057 },
11058
11059 { /* Rest of World */
11060 "ZZD",
11061 .bg_channels = 13,
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}, {2467, 12},
11066 {2472, 13}},
11067 },
11068
11069 { /* Custom USA & Europe & High */
11070 "ZZA",
11071 .bg_channels = 11,
11072 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11073 {2427, 4}, {2432, 5}, {2437, 6},
11074 {2442, 7}, {2447, 8}, {2452, 9},
11075 {2457, 10}, {2462, 11}},
11076 .a_channels = 13,
11077 .a = {{5180, 36},
11078 {5200, 40},
11079 {5220, 44},
11080 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011081 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11082 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11083 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11084 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011085 {5745, 149},
11086 {5765, 153},
11087 {5785, 157},
11088 {5805, 161},
11089 {5825, 165}},
11090 },
11091
11092 { /* Custom NA & Europe */
11093 "ZZB",
11094 .bg_channels = 11,
11095 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11096 {2427, 4}, {2432, 5}, {2437, 6},
11097 {2442, 7}, {2447, 8}, {2452, 9},
11098 {2457, 10}, {2462, 11}},
11099 .a_channels = 13,
11100 .a = {{5180, 36},
11101 {5200, 40},
11102 {5220, 44},
11103 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011104 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11105 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11106 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11107 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11108 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11109 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11110 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11111 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11112 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011113 },
11114
11115 { /* Custom Japan */
11116 "ZZC",
11117 .bg_channels = 11,
11118 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11119 {2427, 4}, {2432, 5}, {2437, 6},
11120 {2442, 7}, {2447, 8}, {2452, 9},
11121 {2457, 10}, {2462, 11}},
11122 .a_channels = 4,
11123 .a = {{5170, 34}, {5190, 38},
11124 {5210, 42}, {5230, 46}},
11125 },
11126
11127 { /* Custom */
11128 "ZZM",
11129 .bg_channels = 11,
11130 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11131 {2427, 4}, {2432, 5}, {2437, 6},
11132 {2442, 7}, {2447, 8}, {2452, 9},
11133 {2457, 10}, {2462, 11}},
11134 },
11135
11136 { /* Europe */
11137 "ZZE",
11138 .bg_channels = 13,
11139 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11140 {2427, 4}, {2432, 5}, {2437, 6},
11141 {2442, 7}, {2447, 8}, {2452, 9},
11142 {2457, 10}, {2462, 11}, {2467, 12},
11143 {2472, 13}},
11144 .a_channels = 19,
11145 .a = {{5180, 36},
11146 {5200, 40},
11147 {5220, 44},
11148 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011149 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11150 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11151 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11152 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11153 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11154 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11155 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11156 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11157 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11158 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11159 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11160 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11161 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11162 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11163 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011164 },
11165
11166 { /* Custom Japan */
11167 "ZZJ",
11168 .bg_channels = 14,
11169 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11170 {2427, 4}, {2432, 5}, {2437, 6},
11171 {2442, 7}, {2447, 8}, {2452, 9},
11172 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011173 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011174 .a_channels = 4,
11175 .a = {{5170, 34}, {5190, 38},
11176 {5210, 42}, {5230, 46}},
11177 },
11178
James Ketrenos03520572005-10-19 16:12:31 -050011179 { /* Rest of World */
11180 "ZZR",
11181 .bg_channels = 14,
11182 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11183 {2427, 4}, {2432, 5}, {2437, 6},
11184 {2442, 7}, {2447, 8}, {2452, 9},
11185 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011186 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11187 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011188 },
11189
James Ketrenos4f36f802005-08-03 20:36:56 -050011190 { /* High Band */
11191 "ZZH",
11192 .bg_channels = 13,
11193 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11194 {2427, 4}, {2432, 5}, {2437, 6},
11195 {2442, 7}, {2447, 8}, {2452, 9},
11196 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011197 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11198 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011199 .a_channels = 4,
11200 .a = {{5745, 149}, {5765, 153},
11201 {5785, 157}, {5805, 161}},
11202 },
11203
11204 { /* Custom Europe */
11205 "ZZG",
11206 .bg_channels = 13,
11207 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11208 {2427, 4}, {2432, 5}, {2437, 6},
11209 {2442, 7}, {2447, 8}, {2452, 9},
11210 {2457, 10}, {2462, 11},
11211 {2467, 12}, {2472, 13}},
11212 .a_channels = 4,
11213 .a = {{5180, 36}, {5200, 40},
11214 {5220, 44}, {5240, 48}},
11215 },
11216
11217 { /* Europe */
11218 "ZZK",
11219 .bg_channels = 13,
11220 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11221 {2427, 4}, {2432, 5}, {2437, 6},
11222 {2442, 7}, {2447, 8}, {2452, 9},
11223 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011224 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11225 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011226 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011227 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11228 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11229 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11230 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11231 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11232 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11233 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11234 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11235 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11236 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11237 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11238 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11239 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11240 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11241 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11242 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11243 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11244 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11245 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11246 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11247 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11248 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11249 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11250 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011251 },
11252
11253 { /* Europe */
11254 "ZZL",
11255 .bg_channels = 11,
11256 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11257 {2427, 4}, {2432, 5}, {2437, 6},
11258 {2442, 7}, {2447, 8}, {2452, 9},
11259 {2457, 10}, {2462, 11}},
11260 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011261 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11262 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11263 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11264 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11265 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11266 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11267 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11268 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11269 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11270 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11271 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11272 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11273 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011274 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011275};
11276
James Ketrenos43f66a62005-03-25 12:31:53 -060011277#define MAX_HW_RESTARTS 5
11278static int ipw_up(struct ipw_priv *priv)
11279{
James Ketrenos4f36f802005-08-03 20:36:56 -050011280 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011281
Dan Williamsc3d72b92009-02-11 13:26:06 -050011282 /* Age scan list entries found before suspend */
11283 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011284 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011285 priv->suspend_time = 0;
11286 }
11287
James Ketrenos43f66a62005-03-25 12:31:53 -060011288 if (priv->status & STATUS_EXIT_PENDING)
11289 return -EIO;
11290
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011291 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011292 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011293 GFP_KERNEL);
11294 if (priv->cmdlog == NULL) {
11295 IPW_ERROR("Error allocating %d command log entries.\n",
11296 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011297 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011298 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011299 priv->cmdlog_len = cmdlog;
11300 }
11301 }
11302
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011303 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011304 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011305 * Also start the clocks. */
11306 rc = ipw_load(priv);
11307 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011308 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011309 return rc;
11310 }
11311
11312 ipw_init_ordinals(priv);
11313 if (!(priv->config & CFG_CUSTOM_MAC))
11314 eeprom_parse_mac(priv, priv->mac_addr);
11315 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011316 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011317
James Ketrenos4f36f802005-08-03 20:36:56 -050011318 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11319 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11320 ipw_geos[j].name, 3))
11321 break;
11322 }
James Ketrenos03520572005-10-19 16:12:31 -050011323 if (j == ARRAY_SIZE(ipw_geos)) {
11324 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11325 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11326 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11327 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011328 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011329 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011330 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011331 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011332 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011333 }
11334
James Ketrenosb095c382005-08-24 22:04:42 -050011335 if (priv->status & STATUS_RF_KILL_SW) {
11336 IPW_WARNING("Radio disabled by module parameter.\n");
11337 return 0;
11338 } else if (rf_kill_active(priv)) {
11339 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11340 "Kill switch must be turned off for "
11341 "wireless networking to work.\n");
11342 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11343 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011344 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011345 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011346
11347 rc = ipw_config(priv);
11348 if (!rc) {
11349 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011350
James Ketrenose6666192005-08-12 09:17:04 -050011351 /* If configure to try and auto-associate, kick
11352 * off a scan. */
David Howellsc4028952006-11-22 14:57:56 +000011353 queue_delayed_work(priv->workqueue,
11354 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011355
James Ketrenos43f66a62005-03-25 12:31:53 -060011356 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011357 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011358
James Ketrenosc848d0a2005-08-24 21:56:24 -050011359 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011360 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11361 i, MAX_HW_RESTARTS);
11362
11363 /* We had an error bringing up the hardware, so take it
11364 * all the way back down so we can try again */
11365 ipw_down(priv);
11366 }
11367
Jeff Garzikbf794512005-07-31 13:07:26 -040011368 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011369 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011370 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011371
James Ketrenos43f66a62005-03-25 12:31:53 -060011372 return -EIO;
11373}
11374
David Howellsc4028952006-11-22 14:57:56 +000011375static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011376{
David Howellsc4028952006-11-22 14:57:56 +000011377 struct ipw_priv *priv =
11378 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011379 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011380 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011381 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011382}
11383
James Ketrenosb095c382005-08-24 22:04:42 -050011384static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011385{
James Ketrenosb095c382005-08-24 22:04:42 -050011386 int i;
11387
11388 if (priv->status & STATUS_SCANNING) {
11389 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11390 ipw_abort_scan(priv);
11391 }
11392
11393 if (priv->status & STATUS_ASSOCIATED) {
11394 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11395 ipw_disassociate(priv);
11396 }
11397
11398 ipw_led_shutdown(priv);
11399
11400 /* Wait up to 1s for status to change to not scanning and not
11401 * associated (disassociation can take a while for a ful 802.11
11402 * exchange */
11403 for (i = 1000; i && (priv->status &
11404 (STATUS_DISASSOCIATING |
11405 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11406 udelay(10);
11407
11408 if (priv->status & (STATUS_DISASSOCIATING |
11409 STATUS_ASSOCIATED | STATUS_SCANNING))
11410 IPW_DEBUG_INFO("Still associated or scanning...\n");
11411 else
11412 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11413
James Ketrenosc848d0a2005-08-24 21:56:24 -050011414 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011415 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011416
11417 priv->status &= ~STATUS_INIT;
11418}
11419
James Ketrenos43f66a62005-03-25 12:31:53 -060011420static void ipw_down(struct ipw_priv *priv)
11421{
James Ketrenosb095c382005-08-24 22:04:42 -050011422 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11423
11424 priv->status |= STATUS_EXIT_PENDING;
11425
11426 if (ipw_is_init(priv))
11427 ipw_deinit(priv);
11428
11429 /* Wipe out the EXIT_PENDING status bit if we are not actually
11430 * exiting the module */
11431 if (!exit_pending)
11432 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011433
11434 /* tell the device to stop sending interrupts */
11435 ipw_disable_interrupts(priv);
11436
11437 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011438 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011439 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011440
11441 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011442
11443 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011444}
11445
David Howellsc4028952006-11-22 14:57:56 +000011446static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011447{
David Howellsc4028952006-11-22 14:57:56 +000011448 struct ipw_priv *priv =
11449 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011450 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011451 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011452 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011453}
11454
11455/* Called by register_netdev() */
11456static int ipw_net_init(struct net_device *dev)
11457{
John W. Linvillea3caa992009-08-25 14:12:25 -040011458 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011459 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011460 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11461 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011462 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011463
James Ketrenosc848d0a2005-08-24 21:56:24 -050011464 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011465 rc = -EIO;
11466 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011467 }
11468
John W. Linvillea3caa992009-08-25 14:12:25 -040011469 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11470
11471 /* fill-out priv->ieee->bg_band */
11472 if (geo->bg_channels) {
11473 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11474
11475 bg_band->band = IEEE80211_BAND_2GHZ;
11476 bg_band->n_channels = geo->bg_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011477 bg_band->channels = kcalloc(geo->bg_channels,
11478 sizeof(struct ieee80211_channel),
11479 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011480 if (!bg_band->channels) {
11481 rc = -ENOMEM;
11482 goto out;
11483 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011484 /* translate geo->bg to bg_band.channels */
11485 for (i = 0; i < geo->bg_channels; i++) {
11486 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11487 bg_band->channels[i].center_freq = geo->bg[i].freq;
11488 bg_band->channels[i].hw_value = geo->bg[i].channel;
11489 bg_band->channels[i].max_power = geo->bg[i].max_power;
11490 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11491 bg_band->channels[i].flags |=
11492 IEEE80211_CHAN_PASSIVE_SCAN;
11493 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11494 bg_band->channels[i].flags |=
11495 IEEE80211_CHAN_NO_IBSS;
11496 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11497 bg_band->channels[i].flags |=
11498 IEEE80211_CHAN_RADAR;
11499 /* No equivalent for LIBIPW_CH_80211H_RULES,
11500 LIBIPW_CH_UNIFORM_SPREADING, or
11501 LIBIPW_CH_B_ONLY... */
11502 }
11503 /* point at bitrate info */
11504 bg_band->bitrates = ipw2200_bg_rates;
11505 bg_band->n_bitrates = ipw2200_num_bg_rates;
11506
11507 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11508 }
11509
11510 /* fill-out priv->ieee->a_band */
11511 if (geo->a_channels) {
11512 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11513
11514 a_band->band = IEEE80211_BAND_5GHZ;
11515 a_band->n_channels = geo->a_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011516 a_band->channels = kcalloc(geo->a_channels,
11517 sizeof(struct ieee80211_channel),
11518 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011519 if (!a_band->channels) {
11520 rc = -ENOMEM;
11521 goto out;
11522 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011523 /* translate geo->bg to a_band.channels */
11524 for (i = 0; i < geo->a_channels; i++) {
11525 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11526 a_band->channels[i].center_freq = geo->a[i].freq;
11527 a_band->channels[i].hw_value = geo->a[i].channel;
11528 a_band->channels[i].max_power = geo->a[i].max_power;
11529 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11530 a_band->channels[i].flags |=
11531 IEEE80211_CHAN_PASSIVE_SCAN;
11532 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11533 a_band->channels[i].flags |=
11534 IEEE80211_CHAN_NO_IBSS;
11535 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11536 a_band->channels[i].flags |=
11537 IEEE80211_CHAN_RADAR;
11538 /* No equivalent for LIBIPW_CH_80211H_RULES,
11539 LIBIPW_CH_UNIFORM_SPREADING, or
11540 LIBIPW_CH_B_ONLY... */
11541 }
11542 /* point at bitrate info */
11543 a_band->bitrates = ipw2200_a_rates;
11544 a_band->n_bitrates = ipw2200_num_a_rates;
11545
11546 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11547 }
11548
11549 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11550
11551 /* With that information in place, we can now register the wiphy... */
11552 if (wiphy_register(wdev->wiphy)) {
11553 rc = -EIO;
11554 goto out;
11555 }
11556
11557out:
Zhu Yi46441512006-01-24 16:37:59 +080011558 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011559 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011560}
11561
11562/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011563static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011564 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11565 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11566 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11567 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11568 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11569 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11570 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11571 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11572 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11573 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11574 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11575 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11576 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11577 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11578 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11579 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11580 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011581 {PCI_VDEVICE(INTEL, 0x104f), 0},
11582 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11583 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11584 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11585 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011586
James Ketrenos43f66a62005-03-25 12:31:53 -060011587 /* required last entry */
11588 {0,}
11589};
11590
11591MODULE_DEVICE_TABLE(pci, card_ids);
11592
11593static struct attribute *ipw_sysfs_entries[] = {
11594 &dev_attr_rf_kill.attr,
11595 &dev_attr_direct_dword.attr,
11596 &dev_attr_indirect_byte.attr,
11597 &dev_attr_indirect_dword.attr,
11598 &dev_attr_mem_gpio_reg.attr,
11599 &dev_attr_command_event_reg.attr,
11600 &dev_attr_nic_type.attr,
11601 &dev_attr_status.attr,
11602 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011603 &dev_attr_error.attr,
11604 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011605 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011606 &dev_attr_eeprom_delay.attr,
11607 &dev_attr_ucode_version.attr,
11608 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011609 &dev_attr_scan_age.attr,
11610 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011611 &dev_attr_speed_scan.attr,
11612 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011613 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011614#ifdef CONFIG_IPW2200_PROMISCUOUS
11615 &dev_attr_rtap_iface.attr,
11616 &dev_attr_rtap_filter.attr,
11617#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011618 NULL
11619};
11620
11621static struct attribute_group ipw_attribute_group = {
11622 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011623 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011624};
11625
Zhu Yid685b8c2006-04-13 17:20:27 +080011626#ifdef CONFIG_IPW2200_PROMISCUOUS
11627static int ipw_prom_open(struct net_device *dev)
11628{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011629 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011630 struct ipw_priv *priv = prom_priv->priv;
11631
11632 IPW_DEBUG_INFO("prom dev->open\n");
11633 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011634
11635 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11636 priv->sys_config.accept_all_data_frames = 1;
11637 priv->sys_config.accept_non_directed_frames = 1;
11638 priv->sys_config.accept_all_mgmt_bcpr = 1;
11639 priv->sys_config.accept_all_mgmt_frames = 1;
11640
11641 ipw_send_system_config(priv);
11642 }
11643
11644 return 0;
11645}
11646
11647static int ipw_prom_stop(struct net_device *dev)
11648{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011649 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011650 struct ipw_priv *priv = prom_priv->priv;
11651
11652 IPW_DEBUG_INFO("prom dev->stop\n");
11653
11654 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11655 priv->sys_config.accept_all_data_frames = 0;
11656 priv->sys_config.accept_non_directed_frames = 0;
11657 priv->sys_config.accept_all_mgmt_bcpr = 0;
11658 priv->sys_config.accept_all_mgmt_frames = 0;
11659
11660 ipw_send_system_config(priv);
11661 }
11662
11663 return 0;
11664}
11665
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011666static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11667 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011668{
11669 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011670 dev_kfree_skb(skb);
11671 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011672}
11673
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011674static const struct net_device_ops ipw_prom_netdev_ops = {
11675 .ndo_open = ipw_prom_open,
11676 .ndo_stop = ipw_prom_stop,
11677 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011678 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011679 .ndo_set_mac_address = eth_mac_addr,
11680 .ndo_validate_addr = eth_validate_addr,
11681};
11682
Zhu Yid685b8c2006-04-13 17:20:27 +080011683static int ipw_prom_alloc(struct ipw_priv *priv)
11684{
11685 int rc = 0;
11686
11687 if (priv->prom_net_dev)
11688 return -EPERM;
11689
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011690 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011691 if (priv->prom_net_dev == NULL)
11692 return -ENOMEM;
11693
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011694 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011695 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11696 priv->prom_priv->priv = priv;
11697
11698 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011699 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011700
11701 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011702 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011703
11704 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011705 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011706
11707 rc = register_netdev(priv->prom_net_dev);
11708 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011709 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011710 priv->prom_net_dev = NULL;
11711 return rc;
11712 }
11713
11714 return 0;
11715}
11716
11717static void ipw_prom_free(struct ipw_priv *priv)
11718{
11719 if (!priv->prom_net_dev)
11720 return;
11721
11722 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011723 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011724
11725 priv->prom_net_dev = NULL;
11726}
11727
11728#endif
11729
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011730static const struct net_device_ops ipw_netdev_ops = {
11731 .ndo_init = ipw_net_init,
11732 .ndo_open = ipw_net_open,
11733 .ndo_stop = ipw_net_stop,
11734 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11735 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011736 .ndo_start_xmit = libipw_xmit,
11737 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011738 .ndo_validate_addr = eth_validate_addr,
11739};
Zhu Yid685b8c2006-04-13 17:20:27 +080011740
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011741static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11742 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011743{
11744 int err = 0;
11745 struct net_device *net_dev;
11746 void __iomem *base;
11747 u32 length, val;
11748 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011749 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011750
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011751 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011752 if (net_dev == NULL) {
11753 err = -ENOMEM;
11754 goto out;
11755 }
11756
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011757 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011758 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011759
James Ketrenos43f66a62005-03-25 12:31:53 -060011760 priv->net_dev = net_dev;
11761 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011762 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011763 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011764 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011765 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11766 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011767
Zhu Yi46441512006-01-24 16:37:59 +080011768 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011769 if (pci_enable_device(pdev)) {
11770 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011771 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011772 }
11773
11774 pci_set_master(pdev);
11775
Yang Hongyang284901a2009-04-06 19:01:15 -070011776 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011777 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011778 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011779 if (err) {
11780 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11781 goto out_pci_disable_device;
11782 }
11783
11784 pci_set_drvdata(pdev, priv);
11785
11786 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011787 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011788 goto out_pci_disable_device;
11789
Jeff Garzikbf794512005-07-31 13:07:26 -040011790 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011791 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011792 pci_read_config_dword(pdev, 0x40, &val);
11793 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011794 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011795
James Ketrenos43f66a62005-03-25 12:31:53 -060011796 length = pci_resource_len(pdev, 0);
11797 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011798
Arjan van de Ven275f1652008-10-20 21:42:39 -070011799 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011800 if (!base) {
11801 err = -ENODEV;
11802 goto out_pci_release_regions;
11803 }
11804
11805 priv->hw_base = base;
11806 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11807 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11808
11809 err = ipw_setup_deferred_work(priv);
11810 if (err) {
11811 IPW_ERROR("Unable to setup deferred work\n");
11812 goto out_iounmap;
11813 }
11814
James Ketrenosb095c382005-08-24 22:04:42 -050011815 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011816
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011817 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011818 if (err) {
11819 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11820 goto out_destroy_workqueue;
11821 }
11822
James Ketrenos43f66a62005-03-25 12:31:53 -060011823 SET_NETDEV_DEV(net_dev, &pdev->dev);
11824
Zhu Yi46441512006-01-24 16:37:59 +080011825 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011826
James Ketrenos43f66a62005-03-25 12:31:53 -060011827 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11828 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011829 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011830
Zhu Yie43e3c12006-04-13 17:20:45 +080011831#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011832 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011833 priv->ieee->handle_probe_response = ipw_handle_beacon;
11834 priv->ieee->handle_beacon = ipw_handle_probe_response;
11835 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011836#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011837
James Ketrenosc848d0a2005-08-24 21:56:24 -050011838 priv->ieee->perfect_rssi = -20;
11839 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011840
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011841 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011842 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011843 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011844 net_dev->wireless_handlers = &ipw_wx_handler_def;
11845 net_dev->ethtool_ops = &ipw_ethtool_ops;
11846 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011847 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011848 net_dev->mem_start = pci_resource_start(pdev, 0);
11849 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11850
11851 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11852 if (err) {
11853 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011854 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011855 goto out_release_irq;
11856 }
11857
Zhu Yi46441512006-01-24 16:37:59 +080011858 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011859 err = register_netdev(net_dev);
11860 if (err) {
11861 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011862 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011863 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011864
Zhu Yid685b8c2006-04-13 17:20:27 +080011865#ifdef CONFIG_IPW2200_PROMISCUOUS
11866 if (rtap_iface) {
11867 err = ipw_prom_alloc(priv);
11868 if (err) {
11869 IPW_ERROR("Failed to register promiscuous network "
11870 "device (error %d).\n", err);
11871 unregister_netdev(priv->net_dev);
11872 goto out_remove_sysfs;
11873 }
11874 }
11875#endif
11876
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011877 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11878 "channels, %d 802.11a channels)\n",
11879 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11880 priv->ieee->geo.a_channels);
11881
James Ketrenos43f66a62005-03-25 12:31:53 -060011882 return 0;
11883
James Ketrenosa613bff2005-08-24 21:43:11 -050011884 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011885 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011886 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011887 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011888 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011889 destroy_workqueue(priv->workqueue);
11890 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011891 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011892 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011893 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011894 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011895 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011896 pci_disable_device(pdev);
11897 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011898 out_free_libipw:
11899 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011900 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011901 return err;
11902}
11903
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011904static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011905{
11906 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011907 struct list_head *p, *q;
11908 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011909
James Ketrenos43f66a62005-03-25 12:31:53 -060011910 if (!priv)
11911 return;
11912
Zhu Yi46441512006-01-24 16:37:59 +080011913 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011914
James Ketrenosafbf30a2005-08-25 00:05:33 -050011915 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011916 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011917 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11918
Zhu Yi46441512006-01-24 16:37:59 +080011919 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011920
11921 unregister_netdev(priv->net_dev);
11922
11923 if (priv->rxq) {
11924 ipw_rx_queue_free(priv, priv->rxq);
11925 priv->rxq = NULL;
11926 }
11927 ipw_tx_queue_free(priv);
11928
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011929 if (priv->cmdlog) {
11930 kfree(priv->cmdlog);
11931 priv->cmdlog = NULL;
11932 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011933 /* ipw_down will ensure that there is no more pending work
11934 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011935 cancel_delayed_work(&priv->adhoc_check);
11936 cancel_delayed_work(&priv->gather_stats);
11937 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011938 cancel_delayed_work(&priv->request_direct_scan);
11939 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011940 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011941 cancel_delayed_work(&priv->rf_kill);
11942 cancel_delayed_work(&priv->scan_check);
11943 destroy_workqueue(priv->workqueue);
11944 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011945
James Ketrenosafbf30a2005-08-25 00:05:33 -050011946 /* Free MAC hash list for ADHOC */
11947 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11948 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011949 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011950 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011951 }
11952 }
11953
Jesper Juhl8f760782006-06-27 02:55:06 -070011954 kfree(priv->error);
11955 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011956
Zhu Yid685b8c2006-04-13 17:20:27 +080011957#ifdef CONFIG_IPW2200_PROMISCUOUS
11958 ipw_prom_free(priv);
11959#endif
11960
James Ketrenos43f66a62005-03-25 12:31:53 -060011961 free_irq(pdev->irq, priv);
11962 iounmap(priv->hw_base);
11963 pci_release_regions(pdev);
11964 pci_disable_device(pdev);
11965 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011966 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011967 wiphy_unregister(priv->ieee->wdev.wiphy);
11968 kfree(priv->ieee->a_band.channels);
11969 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011970 free_libipw(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011971 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011972}
11973
James Ketrenos43f66a62005-03-25 12:31:53 -060011974#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011975static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011976{
11977 struct ipw_priv *priv = pci_get_drvdata(pdev);
11978 struct net_device *dev = priv->net_dev;
11979
11980 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11981
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011982 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011983 ipw_down(priv);
11984
11985 /* Remove the PRESENT state of the device */
11986 netif_device_detach(dev);
11987
James Ketrenos43f66a62005-03-25 12:31:53 -060011988 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011989 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011990 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011991
Dan Williamsc3d72b92009-02-11 13:26:06 -050011992 priv->suspend_at = get_seconds();
11993
James Ketrenos43f66a62005-03-25 12:31:53 -060011994 return 0;
11995}
11996
11997static int ipw_pci_resume(struct pci_dev *pdev)
11998{
11999 struct ipw_priv *priv = pci_get_drvdata(pdev);
12000 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050012001 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060012002 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040012003
James Ketrenos43f66a62005-03-25 12:31:53 -060012004 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
12005
James Ketrenosea2b26e2005-08-24 21:25:16 -050012006 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050012007 err = pci_enable_device(pdev);
12008 if (err) {
12009 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
12010 dev->name);
12011 return err;
12012 }
James Ketrenos43f66a62005-03-25 12:31:53 -060012013 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050012014
James Ketrenos43f66a62005-03-25 12:31:53 -060012015 /*
12016 * Suspend/Resume resets the PCI configuration space, so we have to
12017 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
12018 * from interfering with C3 CPU state. pci_restore_state won't help
12019 * here since it only restores the first 64 bytes pci config header.
12020 */
Jeff Garzikbf794512005-07-31 13:07:26 -040012021 pci_read_config_dword(pdev, 0x40, &val);
12022 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060012023 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12024
12025 /* Set the device back into the PRESENT state; this will also wake
12026 * the queue of needed */
12027 netif_device_attach(dev);
12028
Dan Williamsc3d72b92009-02-11 13:26:06 -050012029 priv->suspend_time = get_seconds() - priv->suspend_at;
12030
James Ketrenos43f66a62005-03-25 12:31:53 -060012031 /* Bring the device back up */
12032 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012033
James Ketrenos43f66a62005-03-25 12:31:53 -060012034 return 0;
12035}
12036#endif
12037
Zhu Yic8c22c92006-08-21 11:38:39 +080012038static void ipw_pci_shutdown(struct pci_dev *pdev)
12039{
12040 struct ipw_priv *priv = pci_get_drvdata(pdev);
12041
12042 /* Take down the device; powers it off, etc. */
12043 ipw_down(priv);
12044
12045 pci_disable_device(pdev);
12046}
12047
James Ketrenos43f66a62005-03-25 12:31:53 -060012048/* driver initialization stuff */
12049static struct pci_driver ipw_driver = {
12050 .name = DRV_NAME,
12051 .id_table = card_ids,
12052 .probe = ipw_pci_probe,
12053 .remove = __devexit_p(ipw_pci_remove),
12054#ifdef CONFIG_PM
12055 .suspend = ipw_pci_suspend,
12056 .resume = ipw_pci_resume,
12057#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012058 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012059};
12060
12061static int __init ipw_init(void)
12062{
12063 int ret;
12064
12065 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12066 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12067
Jeff Garzik29917622006-08-19 17:48:59 -040012068 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012069 if (ret) {
12070 IPW_ERROR("Unable to initialize PCI module\n");
12071 return ret;
12072 }
12073
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012074 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012075 if (ret) {
12076 IPW_ERROR("Unable to create driver sysfs file\n");
12077 pci_unregister_driver(&ipw_driver);
12078 return ret;
12079 }
12080
12081 return ret;
12082}
12083
12084static void __exit ipw_exit(void)
12085{
12086 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12087 pci_unregister_driver(&ipw_driver);
12088}
12089
12090module_param(disable, int, 0444);
12091MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12092
12093module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012094MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012095
12096module_param(auto_create, int, 0444);
12097MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12098
Reinette Chatre21f8a732009-08-18 10:25:05 -070012099module_param_named(led, led_support, int, 0444);
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000012100MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012101
James Ketrenos43f66a62005-03-25 12:31:53 -060012102module_param(debug, int, 0444);
12103MODULE_PARM_DESC(debug, "debug output mask");
12104
Reinette Chatre21f8a732009-08-18 10:25:05 -070012105module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012106MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012107
Zhu Yid685b8c2006-04-13 17:20:27 +080012108#ifdef CONFIG_IPW2200_PROMISCUOUS
12109module_param(rtap_iface, int, 0444);
12110MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12111#endif
12112
Zhu Yie43e3c12006-04-13 17:20:45 +080012113#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012114module_param(qos_enable, int, 0444);
12115MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012116
James Ketrenosb095c382005-08-24 22:04:42 -050012117module_param(qos_burst_enable, int, 0444);
12118MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12119
12120module_param(qos_no_ack_mask, int, 0444);
12121MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12122
12123module_param(burst_duration_CCK, int, 0444);
12124MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12125
12126module_param(burst_duration_OFDM, int, 0444);
12127MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012128#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012129
12130#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012131module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012132MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12133#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012134module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012135MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12136#endif
12137
Zhu Yi810dabd2006-01-24 16:36:59 +080012138module_param(bt_coexist, int, 0444);
12139MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12140
James Ketrenosb095c382005-08-24 22:04:42 -050012141module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012142MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012143
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012144module_param(cmdlog, int, 0444);
12145MODULE_PARM_DESC(cmdlog,
12146 "allocate a ring buffer for logging firmware commands");
12147
Zhu Yi4bfdb912006-01-24 16:37:16 +080012148module_param(roaming, int, 0444);
12149MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12150
Zhu Yid2b83e12006-04-13 17:19:36 +080012151module_param(antenna, int, 0444);
12152MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12153
James Ketrenos43f66a62005-03-25 12:31:53 -060012154module_exit(ipw_exit);
12155module_init(ipw_init);