blob: 8d72e3d1958680bfaa9dbb79974cabf889e7b0ac [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;
Reinette Chatre21f8a732009-08-18 10:25:05 -070099static int led_support = 0;
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);
James Ketrenos43f66a62005-03-25 12:31:53 -0600462 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);
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
477 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);
1976 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001977
1978 /* Add any cached INTA values that need to be handled */
1979 inta |= priv->isr_inta;
1980
Zhu Yi89c318e2006-06-08 22:19:49 -07001981 spin_unlock_irqrestore(&priv->irq_lock, flags);
1982
1983 spin_lock_irqsave(&priv->lock, flags);
1984
James Ketrenos43f66a62005-03-25 12:31:53 -06001985 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001986 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001987 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001988 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001989 }
1990
James Ketrenosb095c382005-08-24 22:04:42 -05001991 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001993 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 priv->status &= ~STATUS_HCMD_ACTIVE;
1995 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001996 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001997 }
1998
James Ketrenosb095c382005-08-24 22:04:42 -05001999 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002000 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002001 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002002 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002003 }
2004
James Ketrenosb095c382005-08-24 22:04:42 -05002005 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002006 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002007 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002008 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002009 }
2010
James Ketrenosb095c382005-08-24 22:04:42 -05002011 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002012 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002013 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002014 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002015 }
2016
James Ketrenosb095c382005-08-24 22:04:42 -05002017 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002018 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002019 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002020 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 }
2022
James Ketrenosb095c382005-08-24 22:04:42 -05002023 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002024 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002025 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 }
2027
James Ketrenosb095c382005-08-24 22:04:42 -05002028 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002029 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002030 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002031 }
2032
James Ketrenosb095c382005-08-24 22:04:42 -05002033 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002034 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002035 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002036 }
2037
James Ketrenosb095c382005-08-24 22:04:42 -05002038 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002039 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002040 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002041 }
2042
James Ketrenosb095c382005-08-24 22:04:42 -05002043 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002044 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002045 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002046 }
2047
James Ketrenosb095c382005-08-24 22:04:42 -05002048 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002049 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2050 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002051 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002052 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002053 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002054 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002055 cancel_delayed_work(&priv->request_direct_scan);
2056 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002057 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002058 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002059 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002060 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002061 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002062
James Ketrenosb095c382005-08-24 22:04:42 -05002063 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002064 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002065 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002066 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002067 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2068 struct ipw_fw_error *error =
2069 ipw_alloc_error_log(priv);
2070 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002071 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002072 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002073 } else {
2074 priv->error = ipw_alloc_error_log(priv);
2075 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002076 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002077 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002078 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2079 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002080 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2081 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002082 }
2083
James Ketrenosb095c382005-08-24 22:04:42 -05002084 /* XXX: If hardware encryption is for WPA/WPA2,
2085 * we have to notify the supplicant. */
2086 if (priv->ieee->sec.encrypt) {
2087 priv->status &= ~STATUS_ASSOCIATED;
2088 notify_wx_assoc_event(priv);
2089 }
2090
2091 /* Keep the restart process from trying to send host
2092 * commands by clearing the INIT status bit */
2093 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002094
2095 /* Cancel currently queued command. */
2096 priv->status &= ~STATUS_HCMD_ACTIVE;
2097 wake_up_interruptible(&priv->wait_command_queue);
2098
James Ketrenos43f66a62005-03-25 12:31:53 -06002099 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002100 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002101 }
2102
James Ketrenosb095c382005-08-24 22:04:42 -05002103 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002104 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002105 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002106 }
2107
2108 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002109 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002110 }
2111
Zhu Yi89c318e2006-06-08 22:19:49 -07002112 spin_unlock_irqrestore(&priv->lock, flags);
2113
James Ketrenos43f66a62005-03-25 12:31:53 -06002114 /* enable all interrupts */
2115 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002116}
Jeff Garzikbf794512005-07-31 13:07:26 -04002117
James Ketrenos43f66a62005-03-25 12:31:53 -06002118#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2119static char *get_cmd_string(u8 cmd)
2120{
2121 switch (cmd) {
2122 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002123 IPW_CMD(POWER_DOWN);
2124 IPW_CMD(SYSTEM_CONFIG);
2125 IPW_CMD(MULTICAST_ADDRESS);
2126 IPW_CMD(SSID);
2127 IPW_CMD(ADAPTER_ADDRESS);
2128 IPW_CMD(PORT_TYPE);
2129 IPW_CMD(RTS_THRESHOLD);
2130 IPW_CMD(FRAG_THRESHOLD);
2131 IPW_CMD(POWER_MODE);
2132 IPW_CMD(WEP_KEY);
2133 IPW_CMD(TGI_TX_KEY);
2134 IPW_CMD(SCAN_REQUEST);
2135 IPW_CMD(SCAN_REQUEST_EXT);
2136 IPW_CMD(ASSOCIATE);
2137 IPW_CMD(SUPPORTED_RATES);
2138 IPW_CMD(SCAN_ABORT);
2139 IPW_CMD(TX_FLUSH);
2140 IPW_CMD(QOS_PARAMETERS);
2141 IPW_CMD(DINO_CONFIG);
2142 IPW_CMD(RSN_CAPABILITIES);
2143 IPW_CMD(RX_KEY);
2144 IPW_CMD(CARD_DISABLE);
2145 IPW_CMD(SEED_NUMBER);
2146 IPW_CMD(TX_POWER);
2147 IPW_CMD(COUNTRY_INFO);
2148 IPW_CMD(AIRONET_INFO);
2149 IPW_CMD(AP_TX_POWER);
2150 IPW_CMD(CCKM_INFO);
2151 IPW_CMD(CCX_VER_INFO);
2152 IPW_CMD(SET_CALIBRATION);
2153 IPW_CMD(SENSITIVITY_CALIB);
2154 IPW_CMD(RETRY_LIMIT);
2155 IPW_CMD(IPW_PRE_POWER_DOWN);
2156 IPW_CMD(VAP_BEACON_TEMPLATE);
2157 IPW_CMD(VAP_DTIM_PERIOD);
2158 IPW_CMD(EXT_SUPPORTED_RATES);
2159 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2160 IPW_CMD(VAP_QUIET_INTERVALS);
2161 IPW_CMD(VAP_CHANNEL_SWITCH);
2162 IPW_CMD(VAP_MANDATORY_CHANNELS);
2163 IPW_CMD(VAP_CELL_PWR_LIMIT);
2164 IPW_CMD(VAP_CF_PARAM_SET);
2165 IPW_CMD(VAP_SET_BEACONING_STATE);
2166 IPW_CMD(MEASUREMENT);
2167 IPW_CMD(POWER_CAPABILITY);
2168 IPW_CMD(SUPPORTED_CHANNELS);
2169 IPW_CMD(TPC_REPORT);
2170 IPW_CMD(WME_INFO);
2171 IPW_CMD(PRODUCTION_COMMAND);
2172 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002173 return "UNKNOWN";
2174 }
2175}
James Ketrenos43f66a62005-03-25 12:31:53 -06002176
2177#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002178
2179static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002180{
2181 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002182 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002183
James Ketrenosa613bff2005-08-24 21:43:11 -05002184 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002185 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002186 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2187 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002188 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002189 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002190 }
2191
2192 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002193
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002194 if (priv->cmdlog) {
2195 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2196 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2197 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2198 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2199 cmd->len);
2200 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2201 }
2202
James Ketrenosb095c382005-08-24 22:04:42 -05002203 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2204 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2205 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002206
2207#ifndef DEBUG_CMD_WEP_KEY
2208 if (cmd->cmd == IPW_CMD_WEP_KEY)
2209 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2210 else
2211#endif
2212 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2213
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002214 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002215 if (rc) {
2216 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002217 IPW_ERROR("Failed to send %s: Reason %d\n",
2218 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002219 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002220 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002221 }
2222 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002223
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002224 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2225 !(priv->
2226 status & STATUS_HCMD_ACTIVE),
2227 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002228 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002229 spin_lock_irqsave(&priv->lock, flags);
2230 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002231 IPW_ERROR("Failed to send %s: Command timed out.\n",
2232 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002233 priv->status &= ~STATUS_HCMD_ACTIVE;
2234 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002235 rc = -EIO;
2236 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002237 }
2238 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002239 } else
2240 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002241
James Ketrenosb095c382005-08-24 22:04:42 -05002242 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002243 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2244 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002245 rc = -EIO;
2246 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002247 }
2248
Zhu Yi2638bc32006-01-24 16:37:52 +08002249 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002250 if (priv->cmdlog) {
2251 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2252 priv->cmdlog_pos %= priv->cmdlog_len;
2253 }
2254 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002255}
2256
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002257static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002258{
2259 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002260 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002261 };
2262
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002263 return __ipw_send_cmd(priv, &cmd);
2264}
2265
2266static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2267 void *data)
2268{
2269 struct host_cmd cmd = {
2270 .cmd = command,
2271 .len = len,
2272 .param = data,
2273 };
2274
2275 return __ipw_send_cmd(priv, &cmd);
2276}
2277
2278static int ipw_send_host_complete(struct ipw_priv *priv)
2279{
James Ketrenos43f66a62005-03-25 12:31:53 -06002280 if (!priv) {
2281 IPW_ERROR("Invalid args\n");
2282 return -1;
2283 }
2284
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002285 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002286}
2287
Zhu Yid685b8c2006-04-13 17:20:27 +08002288static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002289{
Zhu Yid685b8c2006-04-13 17:20:27 +08002290 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2291 sizeof(priv->sys_config),
2292 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002293}
2294
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002295static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002296{
James Ketrenos43f66a62005-03-25 12:31:53 -06002297 if (!priv || !ssid) {
2298 IPW_ERROR("Invalid args\n");
2299 return -1;
2300 }
2301
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002302 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002303 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002304}
2305
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002306static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002307{
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 if (!priv || !mac) {
2309 IPW_ERROR("Invalid args\n");
2310 return -1;
2311 }
2312
Johannes Berge1749612008-10-27 15:59:26 -07002313 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2314 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002315
Zhu Yi2638bc32006-01-24 16:37:52 +08002316 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002317}
2318
James Ketrenosa613bff2005-08-24 21:43:11 -05002319/*
2320 * NOTE: This must be executed from our workqueue as it results in udelay
2321 * being called which may corrupt the keyboard if executed on default
2322 * workqueue
2323 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002324static void ipw_adapter_restart(void *adapter)
2325{
2326 struct ipw_priv *priv = adapter;
2327
2328 if (priv->status & STATUS_RF_KILL_MASK)
2329 return;
2330
2331 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002332
2333 if (priv->assoc_network &&
2334 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2335 ipw_remove_current_network(priv);
2336
James Ketrenos43f66a62005-03-25 12:31:53 -06002337 if (ipw_up(priv)) {
2338 IPW_ERROR("Failed to up device\n");
2339 return;
2340 }
2341}
2342
David Howellsc4028952006-11-22 14:57:56 +00002343static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002344{
David Howellsc4028952006-11-22 14:57:56 +00002345 struct ipw_priv *priv =
2346 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002347 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002348 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002349 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002350}
2351
James Ketrenos43f66a62005-03-25 12:31:53 -06002352#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2353
2354static void ipw_scan_check(void *data)
2355{
2356 struct ipw_priv *priv = data;
2357 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2358 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002359 "adapter after (%dms).\n",
2360 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002361 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 }
2363}
2364
David Howellsc4028952006-11-22 14:57:56 +00002365static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002366{
David Howellsc4028952006-11-22 14:57:56 +00002367 struct ipw_priv *priv =
2368 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002369 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002370 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002371 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002372}
2373
James Ketrenos43f66a62005-03-25 12:31:53 -06002374static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2375 struct ipw_scan_request_ext *request)
2376{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002377 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002378 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002379}
2380
2381static int ipw_send_scan_abort(struct ipw_priv *priv)
2382{
James Ketrenos43f66a62005-03-25 12:31:53 -06002383 if (!priv) {
2384 IPW_ERROR("Invalid args\n");
2385 return -1;
2386 }
2387
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002388 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002389}
2390
2391static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2392{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002393 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002394 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002395 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002396
2397 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002398 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002399}
2400
2401static int ipw_send_associate(struct ipw_priv *priv,
2402 struct ipw_associate *associate)
2403{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002404 if (!priv || !associate) {
2405 IPW_ERROR("Invalid args\n");
2406 return -1;
2407 }
2408
Al Viro5b5e8072007-12-27 01:54:06 -05002409 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2410 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002411}
2412
2413static int ipw_send_supported_rates(struct ipw_priv *priv,
2414 struct ipw_supported_rates *rates)
2415{
James Ketrenos43f66a62005-03-25 12:31:53 -06002416 if (!priv || !rates) {
2417 IPW_ERROR("Invalid args\n");
2418 return -1;
2419 }
2420
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002421 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002422 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002423}
2424
2425static int ipw_set_random_seed(struct ipw_priv *priv)
2426{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002427 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002428
2429 if (!priv) {
2430 IPW_ERROR("Invalid args\n");
2431 return -1;
2432 }
2433
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002434 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002435
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002436 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002437}
2438
James Ketrenos43f66a62005-03-25 12:31:53 -06002439static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2440{
Al Viroe62e1ee2007-12-27 01:36:46 -05002441 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002442 if (!priv) {
2443 IPW_ERROR("Invalid args\n");
2444 return -1;
2445 }
2446
Al Viroe62e1ee2007-12-27 01:36:46 -05002447 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002448}
James Ketrenos43f66a62005-03-25 12:31:53 -06002449
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002450static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002451{
James Ketrenos43f66a62005-03-25 12:31:53 -06002452 if (!priv || !power) {
2453 IPW_ERROR("Invalid args\n");
2454 return -1;
2455 }
2456
Zhu Yi2638bc32006-01-24 16:37:52 +08002457 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002458}
James Ketrenos43f66a62005-03-25 12:31:53 -06002459
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002460static int ipw_set_tx_power(struct ipw_priv *priv)
2461{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002462 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002463 struct ipw_tx_power tx_power;
2464 s8 max_power;
2465 int i;
2466
2467 memset(&tx_power, 0, sizeof(tx_power));
2468
2469 /* configure device for 'G' band */
2470 tx_power.ieee_mode = IPW_G_MODE;
2471 tx_power.num_channels = geo->bg_channels;
2472 for (i = 0; i < geo->bg_channels; i++) {
2473 max_power = geo->bg[i].max_power;
2474 tx_power.channels_tx_power[i].channel_number =
2475 geo->bg[i].channel;
2476 tx_power.channels_tx_power[i].tx_power = max_power ?
2477 min(max_power, priv->tx_power) : priv->tx_power;
2478 }
2479 if (ipw_send_tx_power(priv, &tx_power))
2480 return -EIO;
2481
2482 /* configure device to also handle 'B' band */
2483 tx_power.ieee_mode = IPW_B_MODE;
2484 if (ipw_send_tx_power(priv, &tx_power))
2485 return -EIO;
2486
2487 /* configure device to also handle 'A' band */
2488 if (priv->ieee->abg_true) {
2489 tx_power.ieee_mode = IPW_A_MODE;
2490 tx_power.num_channels = geo->a_channels;
2491 for (i = 0; i < tx_power.num_channels; i++) {
2492 max_power = geo->a[i].max_power;
2493 tx_power.channels_tx_power[i].channel_number =
2494 geo->a[i].channel;
2495 tx_power.channels_tx_power[i].tx_power = max_power ?
2496 min(max_power, priv->tx_power) : priv->tx_power;
2497 }
2498 if (ipw_send_tx_power(priv, &tx_power))
2499 return -EIO;
2500 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002501 return 0;
2502}
2503
2504static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2505{
2506 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002507 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002508 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002509
2510 if (!priv) {
2511 IPW_ERROR("Invalid args\n");
2512 return -1;
2513 }
2514
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002515 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2516 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002517}
2518
2519static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2520{
2521 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002522 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002524
2525 if (!priv) {
2526 IPW_ERROR("Invalid args\n");
2527 return -1;
2528 }
2529
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002530 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2531 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002532}
2533
2534static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2535{
Al Viroe62e1ee2007-12-27 01:36:46 -05002536 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002537
2538 if (!priv) {
2539 IPW_ERROR("Invalid args\n");
2540 return -1;
2541 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002542
James Ketrenos43f66a62005-03-25 12:31:53 -06002543 /* If on battery, set to 3, if AC set to CAM, else user
2544 * level */
2545 switch (mode) {
2546 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002547 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002548 break;
2549 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002550 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 break;
2552 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002553 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002554 break;
2555 }
2556
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002557 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002558 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002559}
2560
James Ketrenosafbf30a2005-08-25 00:05:33 -05002561static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2562{
2563 struct ipw_retry_limit retry_limit = {
2564 .short_retry_limit = slimit,
2565 .long_retry_limit = llimit
2566 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002567
2568 if (!priv) {
2569 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002570 return -1;
2571 }
2572
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002573 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002574 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002575}
2576
2577/*
2578 * The IPW device contains a Microwire compatible EEPROM that stores
2579 * various data like the MAC address. Usually the firmware has exclusive
2580 * access to the eeprom, but during device initialization (before the
2581 * device driver has sent the HostComplete command to the firmware) the
2582 * device driver has read access to the EEPROM by way of indirect addressing
2583 * through a couple of memory mapped registers.
2584 *
2585 * The following is a simplified implementation for pulling data out of the
2586 * the eeprom, along with some helper functions to find information in
2587 * the per device private data's copy of the eeprom.
2588 *
2589 * NOTE: To better understand how these functions work (i.e what is a chip
2590 * select and why do have to keep driving the eeprom clock?), read
2591 * just about any data sheet for a Microwire compatible EEPROM.
2592 */
2593
2594/* write a 32 bit value into the indirect accessor register */
2595static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2596{
2597 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002598
James Ketrenos43f66a62005-03-25 12:31:53 -06002599 /* the eeprom requires some time to complete the operation */
2600 udelay(p->eeprom_delay);
2601
2602 return;
2603}
2604
2605/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002606static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002607{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002608 eeprom_write_reg(priv, 0);
2609 eeprom_write_reg(priv, EEPROM_BIT_CS);
2610 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2611 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002612}
2613
2614/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002615static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002616{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002617 eeprom_write_reg(priv, EEPROM_BIT_CS);
2618 eeprom_write_reg(priv, 0);
2619 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002620}
2621
2622/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002623static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002624{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625 int d = (bit ? EEPROM_BIT_DI : 0);
2626 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2627 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002628}
2629
2630/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002631static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002632{
2633 int i;
2634
2635 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002636 eeprom_write_bit(priv, 1);
2637 eeprom_write_bit(priv, op & 2);
2638 eeprom_write_bit(priv, op & 1);
2639 for (i = 7; i >= 0; i--) {
2640 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002641 }
2642}
2643
2644/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002645static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002646{
2647 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002648 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002649
James Ketrenos43f66a62005-03-25 12:31:53 -06002650 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002651 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002652
2653 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002654 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002655
2656 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002657 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002658 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2660 eeprom_write_reg(priv, EEPROM_BIT_CS);
2661 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2662 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002664
James Ketrenos43f66a62005-03-25 12:31:53 -06002665 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002666 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002667 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002668
James Ketrenos43f66a62005-03-25 12:31:53 -06002669 return r;
2670}
2671
2672/* helper function for pulling the mac address out of the private */
2673/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002674static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002675{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002676 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002677}
2678
2679/*
2680 * Either the device driver (i.e. the host) or the firmware can
2681 * load eeprom data into the designated region in SRAM. If neither
2682 * happens then the FW will shutdown with a fatal error.
2683 *
2684 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2685 * bit needs region of shared SRAM needs to be non-zero.
2686 */
2687static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2688{
2689 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002690 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002691
James Ketrenos43f66a62005-03-25 12:31:53 -06002692 IPW_DEBUG_TRACE(">>\n");
2693
2694 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002695 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002696 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002697
Jeff Garzikbf794512005-07-31 13:07:26 -04002698 /*
2699 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002700 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002701 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002703 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002704 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2705
2706 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002707 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002708 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002709
2710 /* Do not load eeprom data on fatal error or suspend */
2711 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2712 } else {
2713 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2714
2715 /* Load eeprom data on fatal error or suspend */
2716 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2717 }
2718
2719 IPW_DEBUG_TRACE("<<\n");
2720}
2721
Arjan van de Ven858119e2006-01-14 13:20:43 -08002722static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002723{
2724 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002725 if (!count)
2726 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002727 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002728 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002729 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002730}
2731
2732static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2733{
James Ketrenosb095c382005-08-24 22:04:42 -05002734 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002735 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002736 sizeof(struct command_block));
2737}
2738
2739static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002740{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002741
2742 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002743
James Ketrenos43f66a62005-03-25 12:31:53 -06002744 /* Start the dma */
2745 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002746
James Ketrenos43f66a62005-03-25 12:31:53 -06002747 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002748 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
2750 IPW_DEBUG_FW("<< : \n");
2751 return 0;
2752}
2753
2754static void ipw_fw_dma_abort(struct ipw_priv *priv)
2755{
2756 u32 control = 0;
2757
2758 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002759
Pavel Machek67fd6b42006-07-11 15:34:05 +02002760 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002761 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002762 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002763 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002764
James Ketrenos43f66a62005-03-25 12:31:53 -06002765 IPW_DEBUG_FW("<< \n");
2766}
2767
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002768static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2769 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002770{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002771 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002772 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002773 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002774 IPW_DEBUG_FW(">> :\n");
2775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 ipw_write_indirect(priv, address, (u8 *) cb,
2777 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002778
2779 IPW_DEBUG_FW("<< :\n");
2780 return 0;
2781
2782}
2783
2784static int ipw_fw_dma_kick(struct ipw_priv *priv)
2785{
2786 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002787 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002788
2789 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002790
James Ketrenos43f66a62005-03-25 12:31:53 -06002791 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002792 ipw_fw_dma_write_command_block(priv, index,
2793 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002794
2795 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002796 ipw_clear_bit(priv, IPW_RESET_REG,
2797 IPW_RESET_REG_MASTER_DISABLED |
2798 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002799
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002801 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002802 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002803
2804 IPW_DEBUG_FW("<< :\n");
2805 return 0;
2806}
2807
2808static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2809{
2810 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002811 u32 register_value = 0;
2812 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002813
2814 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002815 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002816 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002817
2818 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002819 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2820 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002822 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002823 cb_fields_address = address;
2824 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002825 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002826
2827 cb_fields_address += sizeof(u32);
2828 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002829 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002830
2831 cb_fields_address += sizeof(u32);
2832 register_value = ipw_read_reg32(priv, cb_fields_address);
2833 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2834 register_value);
2835
2836 cb_fields_address += sizeof(u32);
2837 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002838 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002839
2840 IPW_DEBUG_FW(">> :\n");
2841}
2842
2843static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2844{
2845 u32 current_cb_address = 0;
2846 u32 current_cb_index = 0;
2847
2848 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002849 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002850
James Ketrenosb095c382005-08-24 22:04:42 -05002851 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002852 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002853
James Ketrenos43f66a62005-03-25 12:31:53 -06002854 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002855 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002856
2857 IPW_DEBUG_FW(">> :\n");
2858 return current_cb_index;
2859
2860}
2861
2862static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2863 u32 src_address,
2864 u32 dest_address,
2865 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002866 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002867{
2868
Jeff Garzikbf794512005-07-31 13:07:26 -04002869 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002870 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2871 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002872 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002873 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002874
2875 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2876 src_address, dest_address, length);
2877
2878 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2879 return -1;
2880
2881 last_cb_element = priv->sram_desc.last_cb_index;
2882 cb = &priv->sram_desc.cb_list[last_cb_element];
2883 priv->sram_desc.last_cb_index++;
2884
2885 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002886 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002887 control |= CB_INT_ENABLED;
2888
2889 if (is_last)
2890 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002891
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 control |= length;
2893
2894 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002895 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002896
2897 /* Copy the Source and Destination addresses */
2898 cb->dest_addr = dest_address;
2899 cb->source_addr = src_address;
2900
2901 /* Copy the Control Word last */
2902 cb->control = control;
2903
2904 return 0;
2905}
2906
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002907static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2908 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002909{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002910 int ret, i;
2911 u32 size;
2912
James Ketrenos43f66a62005-03-25 12:31:53 -06002913 IPW_DEBUG_FW(">> \n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002914 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2915 nr, dest_address, len);
2916
2917 for (i = 0; i < nr; i++) {
2918 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2919 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2920 dest_address +
2921 i * CB_MAX_LENGTH, size,
2922 0, 0);
2923 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002924 IPW_DEBUG_FW_INFO(": Failed\n");
2925 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002926 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002927 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002928 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002929
James Ketrenos43f66a62005-03-25 12:31:53 -06002930 IPW_DEBUG_FW("<< \n");
2931 return 0;
2932}
2933
2934static int ipw_fw_dma_wait(struct ipw_priv *priv)
2935{
Zhu Yi397ae122006-01-24 16:37:22 +08002936 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002937 u32 watchdog = 0;
2938
2939 IPW_DEBUG_FW(">> : \n");
2940
2941 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002942 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002943 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002944
2945 while (current_index < priv->sram_desc.last_cb_index) {
2946 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002947 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002948 current_index = ipw_fw_dma_command_block_index(priv);
2949
Zhu Yi397ae122006-01-24 16:37:22 +08002950 if (previous_index < current_index) {
2951 watchdog = 0;
2952 continue;
2953 }
2954 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002955 IPW_DEBUG_FW_INFO("Timeout\n");
2956 ipw_fw_dma_dump_command_block(priv);
2957 ipw_fw_dma_abort(priv);
2958 return -1;
2959 }
2960 }
2961
2962 ipw_fw_dma_abort(priv);
2963
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002964 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002965 ipw_set_bit(priv, IPW_RESET_REG,
2966 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002967
2968 IPW_DEBUG_FW("<< dmaWaitSync \n");
2969 return 0;
2970}
2971
Jeff Garzikbf794512005-07-31 13:07:26 -04002972static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002973{
2974 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002975 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002976 unsigned long flags;
2977
2978 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002979 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002980 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002981 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2982 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002983 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002984 &priv->ieee->network_free_list);
2985 }
2986 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002987 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002988}
2989
2990/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002991 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002992 * Reads debug register from domain0.
2993 * If card is present, pre-defined value should
2994 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002995 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002996 * @param priv
2997 * @return 1 if card is present, 0 otherwise
2998 */
2999static inline int ipw_alive(struct ipw_priv *priv)
3000{
3001 return ipw_read32(priv, 0x90) == 0xd55555d5;
3002}
3003
Zhu Yic7b6a672006-01-24 16:37:05 +08003004/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003005static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 int timeout)
3007{
3008 int i = 0;
3009
3010 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003011 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003012 return i;
3013 mdelay(10);
3014 i += 10;
3015 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003016
James Ketrenos43f66a62005-03-25 12:31:53 -06003017 return -ETIME;
3018}
3019
Jeff Garzikbf794512005-07-31 13:07:26 -04003020/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003021 * the ipw hardware. It assumes the buffer has all the bits for the
3022 * image and the caller is handling the memory allocation and clean up.
3023 */
3024
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003025static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003026{
3027 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003028
James Ketrenos43f66a62005-03-25 12:31:53 -06003029 IPW_DEBUG_TRACE(">> \n");
3030 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003031 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003032
Zhu Yic7b6a672006-01-24 16:37:05 +08003033 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003034 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3035 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003036 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003037 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003038 return -1;
3039 }
3040
3041 IPW_DEBUG_INFO("stop master %dms\n", rc);
3042
3043 return rc;
3044}
3045
3046static void ipw_arc_release(struct ipw_priv *priv)
3047{
3048 IPW_DEBUG_TRACE(">> \n");
3049 mdelay(5);
3050
James Ketrenosb095c382005-08-24 22:04:42 -05003051 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003052
3053 /* no one knows timing, for safety add some delay */
3054 mdelay(5);
3055}
3056
James Ketrenos43f66a62005-03-25 12:31:53 -06003057struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003058 __le32 address;
3059 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003060};
3061
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003062static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003063{
3064 int rc = 0, i, addr;
3065 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003066 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003067
Al Viroe62e1ee2007-12-27 01:36:46 -05003068 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003069
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 IPW_DEBUG_TRACE(">> \n");
3071
3072 rc = ipw_stop_master(priv);
3073
3074 if (rc < 0)
3075 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003076
James Ketrenosb095c382005-08-24 22:04:42 -05003077 for (addr = IPW_SHARED_LOWER_BOUND;
3078 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003079 ipw_write32(priv, addr, 0);
3080 }
3081
3082 /* no ucode (yet) */
3083 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3084 /* destroy DMA queues */
3085 /* reset sequence */
3086
James Ketrenosb095c382005-08-24 22:04:42 -05003087 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003088 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003089 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003090 mdelay(1);
3091
3092 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003093 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003095
James Ketrenosb095c382005-08-24 22:04:42 -05003096 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003097 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003098
James Ketrenos43f66a62005-03-25 12:31:53 -06003099 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003100 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3101 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003102 mdelay(1);
3103
3104 /* write ucode */
3105 /**
3106 * @bug
3107 * Do NOT set indirect address register once and then
3108 * store data to indirect data register in the loop.
3109 * It seems very reasonable, but in this case DINO do not
3110 * accept ucode. It is essential to set address each time.
3111 */
3112 /* load new ipw uCode */
3113 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003114 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003115 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003116
James Ketrenos43f66a62005-03-25 12:31:53 -06003117 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003118 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3119 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003120
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003121 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003122
3123 /* wait for alive response */
3124 for (i = 0; i < 100; i++) {
3125 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003126 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003127 if (cr & DINO_RXFIFO_DATA)
3128 break;
3129 mdelay(1);
3130 }
3131
3132 if (cr & DINO_RXFIFO_DATA) {
3133 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003134 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003135
3136 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003137 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003138 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003139 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003140 memcpy(&priv->dino_alive, response_buffer,
3141 sizeof(priv->dino_alive));
3142 if (priv->dino_alive.alive_command == 1
3143 && priv->dino_alive.ucode_valid == 1) {
3144 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003145 IPW_DEBUG_INFO
3146 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3147 "of %02d/%02d/%02d %02d:%02d\n",
3148 priv->dino_alive.software_revision,
3149 priv->dino_alive.software_revision,
3150 priv->dino_alive.device_identifier,
3151 priv->dino_alive.device_identifier,
3152 priv->dino_alive.time_stamp[0],
3153 priv->dino_alive.time_stamp[1],
3154 priv->dino_alive.time_stamp[2],
3155 priv->dino_alive.time_stamp[3],
3156 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003157 } else {
3158 IPW_DEBUG_INFO("Microcode is not alive\n");
3159 rc = -EINVAL;
3160 }
3161 } else {
3162 IPW_DEBUG_INFO("No alive response from DINO\n");
3163 rc = -ETIME;
3164 }
3165
3166 /* disable DINO, otherwise for some reason
3167 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003168 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003169
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 return rc;
3171}
3172
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003173static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003174{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003175 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003176 int offset = 0;
3177 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003178 int total_nr = 0;
3179 int i;
3180 struct pci_pool *pool;
Zhu Yi41093162010-03-09 16:05:31 +08003181 void **virts;
3182 dma_addr_t *phys;
James Ketrenos43f66a62005-03-25 12:31:53 -06003183
3184 IPW_DEBUG_TRACE("<< : \n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003185
Zhu Yi41093162010-03-09 16:05:31 +08003186 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3187 GFP_KERNEL);
3188 if (!virts)
3189 return -ENOMEM;
3190
3191 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3192 GFP_KERNEL);
3193 if (!phys) {
3194 kfree(virts);
3195 return -ENOMEM;
3196 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003197 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3198 if (!pool) {
3199 IPW_ERROR("pci_pool_create failed\n");
Zhu Yi41093162010-03-09 16:05:31 +08003200 kfree(phys);
3201 kfree(virts);
James Ketrenos43f66a62005-03-25 12:31:53 -06003202 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003203 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003204
3205 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003206 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003207
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003208 /* the DMA is already ready this would be a bug. */
3209 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003210
3211 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003212 u32 chunk_len;
3213 u8 *start;
3214 int size;
3215 int nr = 0;
3216
James Ketrenos43f66a62005-03-25 12:31:53 -06003217 chunk = (struct fw_chunk *)(data + offset);
3218 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003219 chunk_len = le32_to_cpu(chunk->length);
3220 start = data + offset;
3221
3222 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3223 for (i = 0; i < nr; i++) {
3224 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3225 &phys[total_nr]);
3226 if (!virts[total_nr]) {
3227 ret = -ENOMEM;
3228 goto out;
3229 }
3230 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3231 CB_MAX_LENGTH);
3232 memcpy(virts[total_nr], start, size);
3233 start += size;
3234 total_nr++;
3235 /* We don't support fw chunk larger than 64*8K */
3236 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3237 }
3238
James Ketrenos43f66a62005-03-25 12:31:53 -06003239 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003240 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003241 * offeset*/
3242 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003243 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3244 nr, le32_to_cpu(chunk->address),
3245 chunk_len);
3246 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3248 goto out;
3249 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003250
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003251 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 } while (offset < len);
3253
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003254 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003255 ret = ipw_fw_dma_kick(priv);
3256 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003257 IPW_ERROR("dmaKick Failed\n");
3258 goto out;
3259 }
3260
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003261 ret = ipw_fw_dma_wait(priv);
3262 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003263 IPW_ERROR("dmaWaitSync Failed\n");
3264 goto out;
3265 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003266 out:
3267 for (i = 0; i < total_nr; i++)
3268 pci_pool_free(pool, virts[i], phys[i]);
3269
3270 pci_pool_destroy(pool);
Zhu Yi41093162010-03-09 16:05:31 +08003271 kfree(phys);
3272 kfree(virts);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003273
3274 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003275}
3276
3277/* stop nic */
3278static int ipw_stop_nic(struct ipw_priv *priv)
3279{
3280 int rc = 0;
3281
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003282 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003283 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003284
James Ketrenosb095c382005-08-24 22:04:42 -05003285 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3286 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003288 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003289 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003290 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003291
James Ketrenosb095c382005-08-24 22:04:42 -05003292 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003293
James Ketrenos43f66a62005-03-25 12:31:53 -06003294 return rc;
3295}
3296
3297static void ipw_start_nic(struct ipw_priv *priv)
3298{
3299 IPW_DEBUG_TRACE(">>\n");
3300
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003301 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003302 ipw_clear_bit(priv, IPW_RESET_REG,
3303 IPW_RESET_REG_MASTER_DISABLED |
3304 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003305 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003306
James Ketrenos43f66a62005-03-25 12:31:53 -06003307 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003308 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3309 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003310
3311 IPW_DEBUG_TRACE("<<\n");
3312}
Jeff Garzikbf794512005-07-31 13:07:26 -04003313
James Ketrenos43f66a62005-03-25 12:31:53 -06003314static int ipw_init_nic(struct ipw_priv *priv)
3315{
3316 int rc;
3317
3318 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003319 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 /*prvHwInitNic */
3321 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003322 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003323
3324 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003325 ipw_write32(priv, IPW_READ_INT_REGISTER,
3326 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003327
3328 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003329 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3330 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003331 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3333
3334 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003335 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003336
3337 udelay(10);
3338
3339 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003340 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003341
3342 IPW_DEBUG_TRACE(">>\n");
3343 return 0;
3344}
3345
Jeff Garzikbf794512005-07-31 13:07:26 -04003346/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003347 * Probe is an ok place to call this from.
3348 */
3349static int ipw_reset_nic(struct ipw_priv *priv)
3350{
3351 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003352 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003353
3354 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003355
James Ketrenos43f66a62005-03-25 12:31:53 -06003356 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003357
James Ketrenosa613bff2005-08-24 21:43:11 -05003358 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003359 /* Clear the 'host command active' bit... */
3360 priv->status &= ~STATUS_HCMD_ACTIVE;
3361 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003362 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3363 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003364 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003365
3366 IPW_DEBUG_TRACE("<<\n");
3367 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003368}
James Ketrenos43f66a62005-03-25 12:31:53 -06003369
James Ketrenos9006ea72006-03-08 03:22:28 +08003370
3371struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003372 __le32 ver;
3373 __le32 boot_size;
3374 __le32 ucode_size;
3375 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003376 u8 data[0];
3377};
3378
Jeff Garzikbf794512005-07-31 13:07:26 -04003379static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003380 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003381{
James Ketrenos9006ea72006-03-08 03:22:28 +08003382 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003383 int rc;
3384
3385 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003386 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003387 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003388 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003389 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003390 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003391
James Ketrenos9006ea72006-03-08 03:22:28 +08003392 if ((*raw)->size < sizeof(*fw)) {
3393 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003394 return -EINVAL;
3395 }
3396
James Ketrenos9006ea72006-03-08 03:22:28 +08003397 fw = (void *)(*raw)->data;
3398
Zhu Yi0070f8c2006-04-13 17:20:12 +08003399 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3400 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003401 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3402 name, (*raw)->size);
3403 return -EINVAL;
3404 }
3405
3406 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003407 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003408 le32_to_cpu(fw->ver) >> 16,
3409 le32_to_cpu(fw->ver) & 0xff,
3410 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003411 return 0;
3412}
3413
James Ketrenosb095c382005-08-24 22:04:42 -05003414#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003415
Arjan van de Ven858119e2006-01-14 13:20:43 -08003416static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003417 struct ipw_rx_queue *rxq)
3418{
3419 unsigned long flags;
3420 int i;
3421
3422 spin_lock_irqsave(&rxq->lock, flags);
3423
3424 INIT_LIST_HEAD(&rxq->rx_free);
3425 INIT_LIST_HEAD(&rxq->rx_used);
3426
3427 /* Fill the rx_used queue with _all_ of the Rx buffers */
3428 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3429 /* In the reset function, these buffers may have been allocated
3430 * to an SKB, so we need to unmap and free potential storage */
3431 if (rxq->pool[i].skb != NULL) {
3432 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003433 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003434 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003435 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003436 }
3437 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3438 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003439
James Ketrenos43f66a62005-03-25 12:31:53 -06003440 /* Set us so that we have processed and used all buffers, but have
3441 * not restocked the Rx queue with fresh buffers */
3442 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003443 rxq->free_count = 0;
3444 spin_unlock_irqrestore(&rxq->lock, flags);
3445}
3446
3447#ifdef CONFIG_PM
3448static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003449static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003450
3451static void free_firmware(void)
3452{
3453 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003454 release_firmware(raw);
3455 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003456 fw_loaded = 0;
3457 }
3458}
3459#else
3460#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003461#endif
3462
3463static int ipw_load(struct ipw_priv *priv)
3464{
3465#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003466 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003467#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003468 struct ipw_fw *fw;
3469 u8 *boot_img, *ucode_img, *fw_img;
3470 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003471 int rc = 0, retries = 3;
3472
Zhu Yi397ae122006-01-24 16:37:22 +08003473 switch (priv->ieee->iw_mode) {
3474 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003475 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003476 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003477#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003478 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003479 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003480 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003481#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003482 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003483 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003484 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003485 }
Zhu Yi397ae122006-01-24 16:37:22 +08003486
James Ketrenos9006ea72006-03-08 03:22:28 +08003487 if (!name) {
3488 rc = -EINVAL;
3489 goto error;
3490 }
3491
3492#ifdef CONFIG_PM
3493 if (!fw_loaded) {
3494#endif
3495 rc = ipw_get_fw(priv, &raw, name);
3496 if (rc < 0)
3497 goto error;
3498#ifdef CONFIG_PM
3499 }
3500#endif
3501
3502 fw = (void *)raw->data;
3503 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003504 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3505 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3506 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003507
Zhu Yi397ae122006-01-24 16:37:22 +08003508 if (rc < 0)
3509 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003510
3511 if (!priv->rxq)
3512 priv->rxq = ipw_rx_queue_alloc(priv);
3513 else
3514 ipw_rx_queue_reset(priv, priv->rxq);
3515 if (!priv->rxq) {
3516 IPW_ERROR("Unable to initialize Rx queue\n");
3517 goto error;
3518 }
3519
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003520 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003521 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003522 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003523 priv->status &= ~STATUS_INT_ENABLED;
3524
3525 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003526 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003527
James Ketrenos43f66a62005-03-25 12:31:53 -06003528 ipw_stop_nic(priv);
3529
3530 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003531 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003532 IPW_ERROR("Unable to reset NIC\n");
3533 goto error;
3534 }
3535
James Ketrenosb095c382005-08-24 22:04:42 -05003536 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3537 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003538
3539 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003540 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003541 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003542 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003543 goto error;
3544 }
3545
3546 /* kick start the device */
3547 ipw_start_nic(priv);
3548
Zhu Yic7b6a672006-01-24 16:37:05 +08003549 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003550 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3551 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003552 if (rc < 0) {
3553 IPW_ERROR("device failed to boot initial fw image\n");
3554 goto error;
3555 }
3556 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3557
Jeff Garzikbf794512005-07-31 13:07:26 -04003558 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003559 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003560
3561 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003562 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003563 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003564 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003565 goto error;
3566 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003567
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 /* stop nic */
3569 ipw_stop_nic(priv);
3570
3571 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003572 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003573 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003574 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003575 goto error;
3576 }
Zhu Yi397ae122006-01-24 16:37:22 +08003577#ifdef CONFIG_PM
3578 fw_loaded = 1;
3579#endif
3580
James Ketrenos43f66a62005-03-25 12:31:53 -06003581 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3582
3583 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003584 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003585 IPW_ERROR("Unable to initialize queues\n");
3586 goto error;
3587 }
3588
3589 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003590 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003591 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003592 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003593
James Ketrenos43f66a62005-03-25 12:31:53 -06003594 /* kick start the device */
3595 ipw_start_nic(priv);
3596
James Ketrenosb095c382005-08-24 22:04:42 -05003597 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003598 if (retries > 0) {
3599 IPW_WARNING("Parity error. Retrying init.\n");
3600 retries--;
3601 goto retry;
3602 }
3603
3604 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3605 rc = -EIO;
3606 goto error;
3607 }
3608
3609 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003610 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3611 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003612 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003613 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003614 goto error;
3615 }
3616 IPW_DEBUG_INFO("device response after %dms\n", rc);
3617
3618 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003619 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003620
3621 /* read eeprom data and initialize the eeprom region of sram */
3622 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003623 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003624
3625 /* enable interrupts */
3626 ipw_enable_interrupts(priv);
3627
3628 /* Ensure our queue has valid packets */
3629 ipw_rx_queue_replenish(priv);
3630
James Ketrenosb095c382005-08-24 22:04:42 -05003631 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003632
3633 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003634 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003635
3636#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003637 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003638#endif
3639 return 0;
3640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003641 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003642 if (priv->rxq) {
3643 ipw_rx_queue_free(priv, priv->rxq);
3644 priv->rxq = NULL;
3645 }
3646 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003647 if (raw)
3648 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003649#ifdef CONFIG_PM
3650 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003651 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003652#endif
3653
3654 return rc;
3655}
3656
Jeff Garzikbf794512005-07-31 13:07:26 -04003657/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003658 * DMA services
3659 *
3660 * Theory of operation
3661 *
3662 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3663 * 2 empty entries always kept in the buffer to protect from overflow.
3664 *
3665 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003666 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3667 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003668 * Tx queue resumed.
3669 *
3670 * The IPW operates with six queues, one receive queue in the device's
3671 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003672 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003673 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003674 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003675 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003676 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003677 * we only utilize the first data transmit queue (queue1).
3678 */
3679
3680/**
3681 * Driver allocates buffers of this size for Rx
3682 */
3683
Dan Williams943dbef2008-02-14 17:49:41 -05003684/**
3685 * ipw_rx_queue_space - Return number of free slots available in queue.
3686 */
3687static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3688{
3689 int s = q->read - q->write;
3690 if (s <= 0)
3691 s += RX_QUEUE_SIZE;
3692 /* keep some buffer to not confuse full and empty queue */
3693 s -= 2;
3694 if (s < 0)
3695 s = 0;
3696 return s;
3697}
3698
3699static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003700{
3701 int s = q->last_used - q->first_empty;
3702 if (s <= 0)
3703 s += q->n_bd;
3704 s -= 2; /* keep some reserve to not confuse empty and full situations */
3705 if (s < 0)
3706 s = 0;
3707 return s;
3708}
3709
3710static inline int ipw_queue_inc_wrap(int index, int n_bd)
3711{
3712 return (++index == n_bd) ? 0 : index;
3713}
3714
3715/**
3716 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003717 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003718 * @param q queue to init
3719 * @param count Number of BD's to allocate. Should be power of 2
3720 * @param read_register Address for 'read' register
3721 * (not offset within BAR, full address)
3722 * @param write_register Address for 'write' register
3723 * (not offset within BAR, full address)
3724 * @param base_register Address for 'base' register
3725 * (not offset within BAR, full address)
3726 * @param size Address for 'size' register
3727 * (not offset within BAR, full address)
3728 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003729static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003730 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003731{
3732 q->n_bd = count;
3733
3734 q->low_mark = q->n_bd / 4;
3735 if (q->low_mark < 4)
3736 q->low_mark = 4;
3737
3738 q->high_mark = q->n_bd / 8;
3739 if (q->high_mark < 2)
3740 q->high_mark = 2;
3741
3742 q->first_empty = q->last_used = 0;
3743 q->reg_r = read;
3744 q->reg_w = write;
3745
3746 ipw_write32(priv, base, q->dma_addr);
3747 ipw_write32(priv, size, count);
3748 ipw_write32(priv, read, 0);
3749 ipw_write32(priv, write, 0);
3750
3751 _ipw_read32(priv, 0x90);
3752}
3753
Jeff Garzikbf794512005-07-31 13:07:26 -04003754static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003755 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003756 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003757{
3758 struct pci_dev *dev = priv->pci_dev;
3759
3760 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3761 if (!q->txb) {
3762 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3763 return -ENOMEM;
3764 }
3765
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003766 q->bd =
3767 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003768 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003769 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003770 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003771 kfree(q->txb);
3772 q->txb = NULL;
3773 return -ENOMEM;
3774 }
3775
3776 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3777 return 0;
3778}
3779
3780/**
3781 * Free one TFD, those at index [txq->q.last_used].
3782 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003783 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003784 * @param dev
3785 * @param txq
3786 */
3787static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3788 struct clx2_tx_queue *txq)
3789{
3790 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3791 struct pci_dev *dev = priv->pci_dev;
3792 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003793
James Ketrenos43f66a62005-03-25 12:31:53 -06003794 /* classify bd */
3795 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3796 /* nothing to cleanup after for host commands */
3797 return;
3798
3799 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003800 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3801 IPW_ERROR("Too many chunks: %i\n",
3802 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003803 /** @todo issue fatal error, it is quite serious situation */
3804 return;
3805 }
3806
3807 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003808 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3809 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3810 le16_to_cpu(bd->u.data.chunk_len[i]),
3811 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003812 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003813 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003814 txq->txb[txq->q.last_used] = NULL;
3815 }
3816 }
3817}
3818
3819/**
3820 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003821 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003822 * Empty queue by removing and destroying all BD's.
3823 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003824 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003825 * @param dev
3826 * @param q
3827 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003828static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003829{
3830 struct clx2_queue *q = &txq->q;
3831 struct pci_dev *dev = priv->pci_dev;
3832
Jeff Garzikbf794512005-07-31 13:07:26 -04003833 if (q->n_bd == 0)
3834 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003835
3836 /* first, empty all BD's */
3837 for (; q->first_empty != q->last_used;
3838 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3839 ipw_queue_tx_free_tfd(priv, txq);
3840 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003841
James Ketrenos43f66a62005-03-25 12:31:53 -06003842 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003843 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003844 q->dma_addr);
3845 kfree(txq->txb);
3846
3847 /* 0 fill whole structure */
3848 memset(txq, 0, sizeof(*txq));
3849}
3850
James Ketrenos43f66a62005-03-25 12:31:53 -06003851/**
3852 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003853 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003854 * @param priv
3855 */
3856static void ipw_tx_queue_free(struct ipw_priv *priv)
3857{
3858 /* Tx CMD queue */
3859 ipw_queue_tx_free(priv, &priv->txq_cmd);
3860
3861 /* Tx queues */
3862 ipw_queue_tx_free(priv, &priv->txq[0]);
3863 ipw_queue_tx_free(priv, &priv->txq[1]);
3864 ipw_queue_tx_free(priv, &priv->txq[2]);
3865 ipw_queue_tx_free(priv, &priv->txq[3]);
3866}
3867
Arjan van de Ven858119e2006-01-14 13:20:43 -08003868static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003869{
3870 /* First 3 bytes are manufacturer */
3871 bssid[0] = priv->mac_addr[0];
3872 bssid[1] = priv->mac_addr[1];
3873 bssid[2] = priv->mac_addr[2];
3874
3875 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003876 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003877
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003878 bssid[0] &= 0xfe; /* clear multicast bit */
3879 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003880}
3881
Arjan van de Ven858119e2006-01-14 13:20:43 -08003882static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003883{
3884 struct ipw_station_entry entry;
3885 int i;
3886
3887 for (i = 0; i < priv->num_stations; i++) {
3888 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3889 /* Another node is active in network */
3890 priv->missed_adhoc_beacons = 0;
3891 if (!(priv->config & CFG_STATIC_CHANNEL))
3892 /* when other nodes drop out, we drop out */
3893 priv->config &= ~CFG_ADHOC_PERSIST;
3894
3895 return i;
3896 }
3897 }
3898
3899 if (i == MAX_STATIONS)
3900 return IPW_INVALID_STATION;
3901
Johannes Berge1749612008-10-27 15:59:26 -07003902 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003903
3904 entry.reserved = 0;
3905 entry.support_mode = 0;
3906 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3907 memcpy(priv->stations[i], bssid, ETH_ALEN);
3908 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003909 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003910 priv->num_stations++;
3911
3912 return i;
3913}
3914
Arjan van de Ven858119e2006-01-14 13:20:43 -08003915static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003916{
3917 int i;
3918
Jeff Garzikbf794512005-07-31 13:07:26 -04003919 for (i = 0; i < priv->num_stations; i++)
3920 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003921 return i;
3922
3923 return IPW_INVALID_STATION;
3924}
3925
3926static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3927{
3928 int err;
3929
Hong Liu7b996592005-08-25 17:36:13 +08003930 if (priv->status & STATUS_ASSOCIATING) {
3931 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3932 queue_work(priv->workqueue, &priv->disassociate);
3933 return;
3934 }
3935
3936 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003937 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3938 return;
3939 }
3940
Johannes Berge1749612008-10-27 15:59:26 -07003941 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003942 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003943 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003944 priv->assoc_request.channel);
3945
3946 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3947 priv->status |= STATUS_DISASSOCIATING;
3948
3949 if (quiet)
3950 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3951 else
3952 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003953
James Ketrenos43f66a62005-03-25 12:31:53 -06003954 err = ipw_send_associate(priv, &priv->assoc_request);
3955 if (err) {
3956 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3957 "failed.\n");
3958 return;
3959 }
3960
3961}
3962
James Ketrenosc848d0a2005-08-24 21:56:24 -05003963static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003964{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003965 struct ipw_priv *priv = data;
3966 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3967 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003968 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003969 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003970 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003971}
3972
David Howellsc4028952006-11-22 14:57:56 +00003973static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003974{
David Howellsc4028952006-11-22 14:57:56 +00003975 struct ipw_priv *priv =
3976 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003977 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003978 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003979 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003980}
3981
David Howellsc4028952006-11-22 14:57:56 +00003982static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003983{
David Howellsc4028952006-11-22 14:57:56 +00003984 struct ipw_priv *priv =
3985 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003986
3987#ifdef CONFIG_IPW2200_PROMISCUOUS
3988 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3989 priv->sys_config.accept_all_data_frames = 1;
3990 priv->sys_config.accept_non_directed_frames = 1;
3991 priv->sys_config.accept_all_mgmt_bcpr = 1;
3992 priv->sys_config.accept_all_mgmt_frames = 1;
3993 }
3994#endif
3995
3996 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003997}
3998
3999struct ipw_status_code {
4000 u16 status;
4001 const char *reason;
4002};
4003
4004static const struct ipw_status_code ipw_status_codes[] = {
4005 {0x00, "Successful"},
4006 {0x01, "Unspecified failure"},
4007 {0x0A, "Cannot support all requested capabilities in the "
4008 "Capability information field"},
4009 {0x0B, "Reassociation denied due to inability to confirm that "
4010 "association exists"},
4011 {0x0C, "Association denied due to reason outside the scope of this "
4012 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004013 {0x0D,
4014 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004015 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004016 {0x0E,
4017 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004018 "transaction sequence number out of expected sequence"},
4019 {0x0F, "Authentication rejected because of challenge failure"},
4020 {0x10, "Authentication rejected due to timeout waiting for next "
4021 "frame in sequence"},
4022 {0x11, "Association denied because AP is unable to handle additional "
4023 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004024 {0x12,
4025 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004026 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004027 {0x13,
4028 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004029 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004030 {0x14,
4031 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004032 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004033 {0x15,
4034 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004035 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004036 {0x19,
4037 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004038 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004039 {0x1A,
4040 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 "DSSS-OFDM operation"},
4042 {0x28, "Invalid Information Element"},
4043 {0x29, "Group Cipher is not valid"},
4044 {0x2A, "Pairwise Cipher is not valid"},
4045 {0x2B, "AKMP is not valid"},
4046 {0x2C, "Unsupported RSN IE version"},
4047 {0x2D, "Invalid RSN IE Capabilities"},
4048 {0x2E, "Cipher suite is rejected per security policy"},
4049};
4050
Jeff Garzikbf794512005-07-31 13:07:26 -04004051static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004052{
4053 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004054 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004055 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004056 return ipw_status_codes[i].reason;
4057 return "Unknown status value.";
4058}
James Ketrenos43f66a62005-03-25 12:31:53 -06004059
4060static void inline average_init(struct average *avg)
4061{
4062 memset(avg, 0, sizeof(*avg));
4063}
4064
Zhu Yi00d21de2006-04-13 17:19:02 +08004065#define DEPTH_RSSI 8
4066#define DEPTH_NOISE 16
4067static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4068{
4069 return ((depth-1)*prev_avg + val)/depth;
4070}
4071
Arjan van de Ven858119e2006-01-14 13:20:43 -08004072static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004073{
4074 avg->sum -= avg->entries[avg->pos];
4075 avg->sum += val;
4076 avg->entries[avg->pos++] = val;
4077 if (unlikely(avg->pos == AVG_ENTRIES)) {
4078 avg->init = 1;
4079 avg->pos = 0;
4080 }
4081}
4082
Arjan van de Ven858119e2006-01-14 13:20:43 -08004083static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004084{
4085 if (!unlikely(avg->init)) {
4086 if (avg->pos)
4087 return avg->sum / avg->pos;
4088 return 0;
4089 }
4090
4091 return avg->sum / AVG_ENTRIES;
4092}
4093
4094static void ipw_reset_stats(struct ipw_priv *priv)
4095{
4096 u32 len = sizeof(u32);
4097
4098 priv->quality = 0;
4099
4100 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004101 priv->exp_avg_rssi = -60;
4102 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004103
4104 priv->last_rate = 0;
4105 priv->last_missed_beacons = 0;
4106 priv->last_rx_packets = 0;
4107 priv->last_tx_packets = 0;
4108 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004109
James Ketrenos43f66a62005-03-25 12:31:53 -06004110 /* Firmware managed, reset only when NIC is restarted, so we have to
4111 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004112 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004113 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004114 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004115 &priv->last_tx_failures, &len);
4116
4117 /* Driver managed, reset with each association */
4118 priv->missed_adhoc_beacons = 0;
4119 priv->missed_beacons = 0;
4120 priv->tx_packets = 0;
4121 priv->rx_packets = 0;
4122
4123}
4124
Arjan van de Ven858119e2006-01-14 13:20:43 -08004125static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004126{
4127 u32 i = 0x80000000;
4128 u32 mask = priv->rates_mask;
4129 /* If currently associated in B mode, restrict the maximum
4130 * rate match to B rates */
4131 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004132 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004133
4134 /* TODO: Verify that the rate is supported by the current rates
4135 * list. */
4136
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004137 while (i && !(mask & i))
4138 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004139 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004140 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004141 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004142 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004143 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004144 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004145 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004146 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004147 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004148 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004149 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004150 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004151 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004152 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004153 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004154 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004155 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004156 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004158 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004159 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004160 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004161 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004162 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004163 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004164 }
4165
Jeff Garzikbf794512005-07-31 13:07:26 -04004166 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004167 return 11000000;
4168 else
4169 return 54000000;
4170}
4171
4172static u32 ipw_get_current_rate(struct ipw_priv *priv)
4173{
4174 u32 rate, len = sizeof(rate);
4175 int err;
4176
Jeff Garzikbf794512005-07-31 13:07:26 -04004177 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004178 return 0;
4179
4180 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004181 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004182 &len);
4183 if (err) {
4184 IPW_DEBUG_INFO("failed querying ordinals.\n");
4185 return 0;
4186 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004187 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004188 return ipw_get_max_rate(priv);
4189
4190 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004191 case IPW_TX_RATE_1MB:
4192 return 1000000;
4193 case IPW_TX_RATE_2MB:
4194 return 2000000;
4195 case IPW_TX_RATE_5MB:
4196 return 5500000;
4197 case IPW_TX_RATE_6MB:
4198 return 6000000;
4199 case IPW_TX_RATE_9MB:
4200 return 9000000;
4201 case IPW_TX_RATE_11MB:
4202 return 11000000;
4203 case IPW_TX_RATE_12MB:
4204 return 12000000;
4205 case IPW_TX_RATE_18MB:
4206 return 18000000;
4207 case IPW_TX_RATE_24MB:
4208 return 24000000;
4209 case IPW_TX_RATE_36MB:
4210 return 36000000;
4211 case IPW_TX_RATE_48MB:
4212 return 48000000;
4213 case IPW_TX_RATE_54MB:
4214 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004215 }
4216
4217 return 0;
4218}
4219
James Ketrenos43f66a62005-03-25 12:31:53 -06004220#define IPW_STATS_INTERVAL (2 * HZ)
4221static void ipw_gather_stats(struct ipw_priv *priv)
4222{
4223 u32 rx_err, rx_err_delta, rx_packets_delta;
4224 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4225 u32 missed_beacons_percent, missed_beacons_delta;
4226 u32 quality = 0;
4227 u32 len = sizeof(u32);
4228 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004229 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004230 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004231 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004232
4233 if (!(priv->status & STATUS_ASSOCIATED)) {
4234 priv->quality = 0;
4235 return;
4236 }
4237
4238 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004239 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004240 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004241 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004242 priv->last_missed_beacons = priv->missed_beacons;
4243 if (priv->assoc_request.beacon_interval) {
4244 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004245 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004246 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004247 } else {
4248 missed_beacons_percent = 0;
4249 }
4250 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4251
4252 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4253 rx_err_delta = rx_err - priv->last_rx_err;
4254 priv->last_rx_err = rx_err;
4255
4256 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4257 tx_failures_delta = tx_failures - priv->last_tx_failures;
4258 priv->last_tx_failures = tx_failures;
4259
4260 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4261 priv->last_rx_packets = priv->rx_packets;
4262
4263 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4264 priv->last_tx_packets = priv->tx_packets;
4265
4266 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004267 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004268 * Missed beacon: 100% = 0, 0% = 70% missed
4269 * Rate: 60% = 1Mbs, 100% = Max
4270 * Rx and Tx errors represent a straight % of total Rx/Tx
4271 * RSSI: 100% = > -50, 0% = < -80
4272 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004273 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004274 * The lowest computed quality is used.
4275 *
4276 */
4277#define BEACON_THRESHOLD 5
4278 beacon_quality = 100 - missed_beacons_percent;
4279 if (beacon_quality < BEACON_THRESHOLD)
4280 beacon_quality = 0;
4281 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004282 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004283 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004284 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004285 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004286
James Ketrenos43f66a62005-03-25 12:31:53 -06004287 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004288 max_rate = ipw_get_max_rate(priv);
4289 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004290 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4291 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004292
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004293 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004294 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004295 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004296 else
4297 rx_quality = 100;
4298 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4299 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004300
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004301 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004302 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004303 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004304 else
4305 tx_quality = 100;
4306 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4307 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004308
Zhu Yi00d21de2006-04-13 17:19:02 +08004309 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004310 signal_quality =
4311 (100 *
4312 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4313 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4314 (priv->ieee->perfect_rssi - rssi) *
4315 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4316 62 * (priv->ieee->perfect_rssi - rssi))) /
4317 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4318 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4319 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004320 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004321 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004322 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004323
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004324 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004325 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004326
Reinette Chatre21f8a732009-08-18 10:25:05 -07004327 quality = min(rx_quality, signal_quality);
4328 quality = min(tx_quality, quality);
4329 quality = min(rate_quality, quality);
4330 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004331 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004332 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4333 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004334 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004335 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4336 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004337 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004338 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4339 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004340 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004341 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4342 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004343 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004344 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4345 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004346
4347 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004348
4349 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004350 IPW_STATS_INTERVAL);
4351}
4352
David Howellsc4028952006-11-22 14:57:56 +00004353static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004354{
David Howellsc4028952006-11-22 14:57:56 +00004355 struct ipw_priv *priv =
4356 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004357 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004358 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004359 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004360}
4361
Ben Cahille7582562005-10-06 15:34:41 -05004362/* Missed beacon behavior:
4363 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4364 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4365 * Above disassociate threshold, give up and stop scanning.
4366 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004367static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004368 int missed_count)
4369{
4370 priv->notif_missed_beacons = missed_count;
4371
James Ketrenosafbf30a2005-08-25 00:05:33 -05004372 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004373 priv->status & STATUS_ASSOCIATED) {
4374 /* If associated and we've hit the missed
4375 * beacon threshold, disassociate, turn
4376 * off roaming, and abort any active scans */
4377 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004378 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004379 "Missed beacon: %d - disassociate\n", missed_count);
4380 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004381 if (priv->status & STATUS_SCANNING) {
4382 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4383 IPW_DL_STATE,
4384 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004385 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004386 }
4387
James Ketrenosea2b26e2005-08-24 21:25:16 -05004388 queue_work(priv->workqueue, &priv->disassociate);
4389 return;
4390 }
4391
4392 if (priv->status & STATUS_ROAMING) {
4393 /* If we are currently roaming, then just
4394 * print a debug statement... */
4395 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4396 "Missed beacon: %d - roam in progress\n",
4397 missed_count);
4398 return;
4399 }
4400
Zhu Yi4bfdb912006-01-24 16:37:16 +08004401 if (roaming &&
4402 (missed_count > priv->roaming_threshold &&
4403 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004404 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004405 * bit in the status and kick off a scan.
4406 * This can happen several times before we reach
4407 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4409 "Missed beacon: %d - initiate "
4410 "roaming\n", missed_count);
4411 if (!(priv->status & STATUS_ROAMING)) {
4412 priv->status |= STATUS_ROAMING;
4413 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004414 queue_delayed_work(priv->workqueue,
4415 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004416 }
4417 return;
4418 }
4419
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004420 if (priv->status & STATUS_SCANNING &&
4421 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004422 /* Stop scan to keep fw from getting
4423 * stuck (only if we aren't roaming --
4424 * otherwise we'll never scan more than 2 or 3
4425 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004426 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4427 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004428 queue_work(priv->workqueue, &priv->abort_scan);
4429 }
4430
4431 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004432}
4433
Dan Williams0b531672007-10-09 13:55:24 -04004434static void ipw_scan_event(struct work_struct *work)
4435{
4436 union iwreq_data wrqu;
4437
4438 struct ipw_priv *priv =
4439 container_of(work, struct ipw_priv, scan_event.work);
4440
4441 wrqu.data.length = 0;
4442 wrqu.data.flags = 0;
4443 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4444}
4445
4446static void handle_scan_event(struct ipw_priv *priv)
4447{
4448 /* Only userspace-requested scan completion events go out immediately */
4449 if (!priv->user_requested_scan) {
4450 if (!delayed_work_pending(&priv->scan_event))
4451 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004452 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004453 } else {
4454 union iwreq_data wrqu;
4455
4456 priv->user_requested_scan = 0;
4457 cancel_delayed_work(&priv->scan_event);
4458
4459 wrqu.data.length = 0;
4460 wrqu.data.flags = 0;
4461 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4462 }
4463}
4464
James Ketrenos43f66a62005-03-25 12:31:53 -06004465/**
4466 * Handle host notification packet.
4467 * Called from interrupt routine
4468 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004469static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004470 struct ipw_rx_notification *notif)
4471{
John W. Linville9387b7c2008-09-30 20:59:05 -04004472 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004473 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004474
Al Viroe62e1ee2007-12-27 01:36:46 -05004475 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004476
James Ketrenos43f66a62005-03-25 12:31:53 -06004477 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004478 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4479 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004480
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004481 switch (assoc->state) {
4482 case CMAS_ASSOCIATED:{
4483 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4484 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004485 "associated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004486 print_ssid(ssid, priv->essid,
4487 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004488 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004489
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004490 switch (priv->ieee->iw_mode) {
4491 case IW_MODE_INFRA:
4492 memcpy(priv->ieee->bssid,
4493 priv->bssid, ETH_ALEN);
4494 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004495
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004496 case IW_MODE_ADHOC:
4497 memcpy(priv->ieee->bssid,
4498 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004499
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004500 /* clear out the station table */
4501 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004502
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 IPW_DEBUG_ASSOC
4504 ("queueing adhoc check\n");
4505 queue_delayed_work(priv->
4506 workqueue,
4507 &priv->
4508 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004509 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004510 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004511 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004512 break;
4513 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004514
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004515 priv->status &= ~STATUS_ASSOCIATING;
4516 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004517 queue_work(priv->workqueue,
4518 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004519
Zhu Yie43e3c12006-04-13 17:20:45 +08004520#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004521#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004522 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004523 if ((priv->status & STATUS_AUTH) &&
4524 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4525 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004526 if ((sizeof
4527 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004528 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004529 <= size)
4530 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004531 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004532 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004533 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004534 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004535 };
4536
4537 IPW_DEBUG_QOS
4538 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004539 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004540 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004541 ieee,
4542 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004543 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004544 *)
4545 &notif->u.raw, &stats);
4546 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004547 }
James Ketrenosb095c382005-08-24 22:04:42 -05004548#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004549
James Ketrenosa613bff2005-08-24 21:43:11 -05004550 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 break;
4553 }
4554
4555 case CMAS_AUTHENTICATED:{
4556 if (priv->
4557 status & (STATUS_ASSOCIATED |
4558 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004559 struct notif_authenticate *auth
4560 = &notif->u.auth;
4561 IPW_DEBUG(IPW_DL_NOTIF |
4562 IPW_DL_STATE |
4563 IPW_DL_ASSOC,
4564 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004565 "%pM"
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004566 ": (0x%04X) - %s \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004567 print_ssid(ssid,
4568 priv->
4569 essid,
4570 priv->
4571 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004572 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004573 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004574 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004575 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004576 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004577
4578 priv->status &=
4579 ~(STATUS_ASSOCIATING |
4580 STATUS_AUTH |
4581 STATUS_ASSOCIATED);
4582
James Ketrenosa613bff2005-08-24 21:43:11 -05004583 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584 break;
4585 }
4586
4587 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4588 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004589 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004590 print_ssid(ssid, priv->essid,
4591 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004592 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004593 break;
4594 }
4595
4596 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004597 if (priv->status & STATUS_AUTH) {
4598 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004599 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004600 *resp;
4601 resp =
4602 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004603 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004604 *)&notif->u.raw;
4605 IPW_DEBUG(IPW_DL_NOTIF |
4606 IPW_DL_STATE |
4607 IPW_DL_ASSOC,
4608 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004609 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004610 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004611 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004612 (resp->status)));
4613 }
4614
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4616 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004617 "disassociated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004618 print_ssid(ssid, priv->essid,
4619 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004620 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004621
4622 priv->status &=
4623 ~(STATUS_DISASSOCIATING |
4624 STATUS_ASSOCIATING |
4625 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004626 if (priv->assoc_network
4627 && (priv->assoc_network->
4628 capability &
4629 WLAN_CAPABILITY_IBSS))
4630 ipw_remove_current_network
4631 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004632
James Ketrenosa613bff2005-08-24 21:43:11 -05004633 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004635 break;
4636 }
4637
James Ketrenosb095c382005-08-24 22:04:42 -05004638 case CMAS_RX_ASSOC_RESP:
4639 break;
4640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004641 default:
4642 IPW_ERROR("assoc: unknown (%d)\n",
4643 assoc->state);
4644 break;
4645 }
4646
James Ketrenos43f66a62005-03-25 12:31:53 -06004647 break;
4648 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004649
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004650 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4651 struct notif_authenticate *auth = &notif->u.auth;
4652 switch (auth->state) {
4653 case CMAS_AUTHENTICATED:
4654 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Johannes Berge1749612008-10-27 15:59:26 -07004655 "authenticated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004656 print_ssid(ssid, priv->essid,
4657 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004658 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004659 priv->status |= STATUS_AUTH;
4660 break;
4661
4662 case CMAS_INIT:
4663 if (priv->status & STATUS_AUTH) {
4664 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4665 IPW_DL_ASSOC,
4666 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004667 le16_to_cpu(auth->status),
4668 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004669 (auth->
4670 status)));
4671 }
4672 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4673 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004674 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004675 print_ssid(ssid, priv->essid,
4676 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004677 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004678
4679 priv->status &= ~(STATUS_ASSOCIATING |
4680 STATUS_AUTH |
4681 STATUS_ASSOCIATED);
4682
James Ketrenosa613bff2005-08-24 21:43:11 -05004683 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004684 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004685
4686 case CMAS_TX_AUTH_SEQ_1:
4687 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4688 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4689 break;
4690 case CMAS_RX_AUTH_SEQ_2:
4691 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4692 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4693 break;
4694 case CMAS_AUTH_SEQ_1_PASS:
4695 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4696 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4697 break;
4698 case CMAS_AUTH_SEQ_1_FAIL:
4699 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4700 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4701 break;
4702 case CMAS_TX_AUTH_SEQ_3:
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4704 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4705 break;
4706 case CMAS_RX_AUTH_SEQ_4:
4707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4708 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4709 break;
4710 case CMAS_AUTH_SEQ_2_PASS:
4711 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4712 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4713 break;
4714 case CMAS_AUTH_SEQ_2_FAIL:
4715 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4716 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4717 break;
4718 case CMAS_TX_ASSOC:
4719 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4720 IPW_DL_ASSOC, "TX_ASSOC\n");
4721 break;
4722 case CMAS_RX_ASSOC_RESP:
4723 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4724 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004725
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004726 break;
4727 case CMAS_ASSOCIATED:
4728 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4729 IPW_DL_ASSOC, "ASSOCIATED\n");
4730 break;
4731 default:
4732 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4733 auth->state);
4734 break;
4735 }
4736 break;
4737 }
4738
4739 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4740 struct notif_channel_result *x =
4741 &notif->u.channel_result;
4742
Al Viroe62e1ee2007-12-27 01:36:46 -05004743 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004744 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4745 x->channel_num);
4746 } else {
4747 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4748 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004749 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004750 }
4751 break;
4752 }
4753
4754 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4755 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004756 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004757 IPW_DEBUG_SCAN
4758 ("Scan completed: type %d, %d channels, "
4759 "%d status\n", x->scan_type,
4760 x->num_channels, x->status);
4761 } else {
4762 IPW_ERROR("Scan completed of wrong size %d "
4763 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004764 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004765 }
4766
4767 priv->status &=
4768 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4769
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004770 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004771 cancel_delayed_work(&priv->scan_check);
4772
James Ketrenosb095c382005-08-24 22:04:42 -05004773 if (priv->status & STATUS_EXIT_PENDING)
4774 break;
4775
4776 priv->ieee->scans++;
4777
4778#ifdef CONFIG_IPW2200_MONITOR
4779 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004780 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004781 queue_delayed_work(priv->workqueue,
4782 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004783 break;
4784 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004785 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004786#endif /* CONFIG_IPW2200_MONITOR */
4787
Dan Williamsea177302008-06-02 17:51:23 -04004788 /* Do queued direct scans first */
4789 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4790 queue_delayed_work(priv->workqueue,
4791 &priv->request_direct_scan, 0);
4792 }
4793
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004794 if (!(priv->status & (STATUS_ASSOCIATED |
4795 STATUS_ASSOCIATING |
4796 STATUS_ROAMING |
4797 STATUS_DISASSOCIATING)))
4798 queue_work(priv->workqueue, &priv->associate);
4799 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004800 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4801 /* If a scan completed and we are in roam mode, then
4802 * the scan that completed was the one requested as a
4803 * result of entering roam... so, schedule the
4804 * roam work */
4805 queue_work(priv->workqueue,
4806 &priv->roam);
4807 else
4808 /* Don't schedule if we aborted the scan */
4809 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004810 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004811 queue_delayed_work(priv->workqueue,
4812 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004813 else if (priv->config & CFG_BACKGROUND_SCAN
4814 && priv->status & STATUS_ASSOCIATED)
4815 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004816 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004817 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004818
4819 /* Send an empty event to user space.
4820 * We don't send the received data on the event because
4821 * it would require us to do complex transcoding, and
4822 * we want to minimise the work done in the irq handler
4823 * Use a request to extract the data.
4824 * Also, we generate this even for any scan, regardless
4825 * on how the scan was initiated. User space can just
4826 * sync on periodic scan to get fresh data...
4827 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004828 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4829 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004830 break;
4831 }
4832
4833 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4834 struct notif_frag_length *x = &notif->u.frag_len;
4835
Al Viroe62e1ee2007-12-27 01:36:46 -05004836 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004837 IPW_ERROR("Frag length: %d\n",
4838 le16_to_cpu(x->frag_length));
4839 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004840 IPW_ERROR("Frag length of wrong size %d "
4841 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004842 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004843 break;
4844 }
4845
4846 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4847 struct notif_link_deterioration *x =
4848 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004849
Al Viroe62e1ee2007-12-27 01:36:46 -05004850 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004851 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004852 "link deterioration: type %d, cnt %d\n",
4853 x->silence_notification_type,
4854 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004855 memcpy(&priv->last_link_deterioration, x,
4856 sizeof(*x));
4857 } else {
4858 IPW_ERROR("Link Deterioration of wrong size %d "
4859 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004860 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004861 }
4862 break;
4863 }
4864
4865 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4866 IPW_ERROR("Dino config\n");
4867 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004868 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004869 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004870
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004871 break;
4872 }
4873
4874 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4875 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004876 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004877 IPW_ERROR
4878 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004879 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004880 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004881 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004882
James Ketrenosa613bff2005-08-24 21:43:11 -05004883 if (le32_to_cpu(x->state) ==
4884 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4885 ipw_handle_missed_beacon(priv,
4886 le32_to_cpu(x->
4887 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004888
James Ketrenos43f66a62005-03-25 12:31:53 -06004889 break;
4890 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004891
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004892 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4893 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004894 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004895 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4896 "0x%02x station %d\n",
4897 x->key_state, x->security_type,
4898 x->station_index);
4899 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004900 }
4901
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004902 IPW_ERROR
4903 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004904 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004905 break;
4906 }
4907
4908 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4909 struct notif_calibration *x = &notif->u.calibration;
4910
Al Viroe62e1ee2007-12-27 01:36:46 -05004911 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004912 memcpy(&priv->calib, x, sizeof(*x));
4913 IPW_DEBUG_INFO("TODO: Calibration\n");
4914 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004915 }
4916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004917 IPW_ERROR
4918 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004919 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004920 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004921 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004922
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004923 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004924 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004925 priv->exp_avg_noise =
4926 exponential_average(priv->exp_avg_noise,
4927 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4928 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004929 break;
4930 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004931
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004932 IPW_ERROR
4933 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004934 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004935 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004936 }
4937
James Ketrenos43f66a62005-03-25 12:31:53 -06004938 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004939 IPW_DEBUG_NOTIF("Unknown notification: "
4940 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004941 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004942 }
4943}
4944
4945/**
4946 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004947 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004948 * @param priv
4949 * @return error code
4950 */
4951static int ipw_queue_reset(struct ipw_priv *priv)
4952{
4953 int rc = 0;
4954 /** @todo customize queue sizes */
4955 int nTx = 64, nTxCmd = 8;
4956 ipw_tx_queue_free(priv);
4957 /* Tx CMD queue */
4958 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004959 IPW_TX_CMD_QUEUE_READ_INDEX,
4960 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4961 IPW_TX_CMD_QUEUE_BD_BASE,
4962 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004963 if (rc) {
4964 IPW_ERROR("Tx Cmd queue init failed\n");
4965 goto error;
4966 }
4967 /* Tx queue(s) */
4968 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004969 IPW_TX_QUEUE_0_READ_INDEX,
4970 IPW_TX_QUEUE_0_WRITE_INDEX,
4971 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004972 if (rc) {
4973 IPW_ERROR("Tx 0 queue init failed\n");
4974 goto error;
4975 }
4976 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004977 IPW_TX_QUEUE_1_READ_INDEX,
4978 IPW_TX_QUEUE_1_WRITE_INDEX,
4979 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004980 if (rc) {
4981 IPW_ERROR("Tx 1 queue init failed\n");
4982 goto error;
4983 }
4984 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004985 IPW_TX_QUEUE_2_READ_INDEX,
4986 IPW_TX_QUEUE_2_WRITE_INDEX,
4987 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004988 if (rc) {
4989 IPW_ERROR("Tx 2 queue init failed\n");
4990 goto error;
4991 }
4992 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004993 IPW_TX_QUEUE_3_READ_INDEX,
4994 IPW_TX_QUEUE_3_WRITE_INDEX,
4995 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004996 if (rc) {
4997 IPW_ERROR("Tx 3 queue init failed\n");
4998 goto error;
4999 }
5000 /* statistics */
5001 priv->rx_bufs_min = 0;
5002 priv->rx_pend_max = 0;
5003 return rc;
5004
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005005 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005006 ipw_tx_queue_free(priv);
5007 return rc;
5008}
5009
5010/**
5011 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005012 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005013 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005014 * new 'R' index need to be reclaimed. As result, some free space
5015 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005016 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 * @note Need to protect against garbage in 'R' index
5018 * @param priv
5019 * @param txq
5020 * @param qindex
5021 * @return Number of used entries remains in the queue
5022 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005023static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 struct clx2_tx_queue *txq, int qindex)
5025{
5026 u32 hw_tail;
5027 int used;
5028 struct clx2_queue *q = &txq->q;
5029
5030 hw_tail = ipw_read32(priv, q->reg_r);
5031 if (hw_tail >= q->n_bd) {
5032 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005033 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5034 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005035 goto done;
5036 }
5037 for (; q->last_used != hw_tail;
5038 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5039 ipw_queue_tx_free_tfd(priv, txq);
5040 priv->tx_packets++;
5041 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005042 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005043 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005044 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005045 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005046 used = q->first_empty - q->last_used;
5047 if (used < 0)
5048 used += q->n_bd;
5049
5050 return used;
5051}
5052
5053static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5054 int len, int sync)
5055{
5056 struct clx2_tx_queue *txq = &priv->txq_cmd;
5057 struct clx2_queue *q = &txq->q;
5058 struct tfd_frame *tfd;
5059
Dan Williams943dbef2008-02-14 17:49:41 -05005060 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005061 IPW_ERROR("No space for Tx\n");
5062 return -EBUSY;
5063 }
5064
5065 tfd = &txq->bd[q->first_empty];
5066 txq->txb[q->first_empty] = NULL;
5067
5068 memset(tfd, 0, sizeof(*tfd));
5069 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5070 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5071 priv->hcmd_seq++;
5072 tfd->u.cmd.index = hcmd;
5073 tfd->u.cmd.length = len;
5074 memcpy(tfd->u.cmd.payload, buf, len);
5075 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5076 ipw_write32(priv, q->reg_w, q->first_empty);
5077 _ipw_read32(priv, 0x90);
5078
5079 return 0;
5080}
5081
Jeff Garzikbf794512005-07-31 13:07:26 -04005082/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005083 * Rx theory of operation
5084 *
5085 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005086 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005087 * 0 to 31
5088 *
5089 * Rx Queue Indexes
5090 * The host/firmware share two index registers for managing the Rx buffers.
5091 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005092 * The READ index maps to the first position that the firmware may be writing
5093 * to -- the driver can read up to (but not including) this position and get
5094 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 * The READ index is managed by the firmware once the card is enabled.
5096 *
5097 * The WRITE index maps to the last position the driver has read from -- the
5098 * position preceding WRITE is the last slot the firmware can place a packet.
5099 *
5100 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005101 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005102 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005103 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005104 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5105 *
5106 * When the firmware places a packet in a buffer it will advance the READ index
5107 * and fire the RX interrupt. The driver can then query the READ index and
5108 * process as many packets as possible, moving the WRITE index forward as it
5109 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005110 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005111 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005112 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005113 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005114 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005115 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5116 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5117 * 'processed' and 'read' driver indexes as well)
5118 * + A received packet is processed and handed to the kernel network stack,
5119 * detached from the ipw->rxq. The driver 'processed' index is updated.
5120 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5122 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005123 * were enough free buffers and RX_STALLED is set it is cleared.
5124 *
5125 *
5126 * Driver sequence:
5127 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005128 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005129 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5130 * ipw_rx_queue_restock
5131 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5132 * queue, updates firmware pointers, and updates
5133 * the WRITE index. If insufficient rx_free buffers
5134 * are available, schedules ipw_rx_queue_replenish
5135 *
5136 * -- enable interrupts --
5137 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005138 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005139 * Moves the packet buffer from queue to rx_used.
5140 * Calls ipw_rx_queue_restock to refill any empty
5141 * slots.
5142 * ...
5143 *
5144 */
5145
Jeff Garzikbf794512005-07-31 13:07:26 -04005146/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005147 * If there are slots in the RX queue that need to be restocked,
5148 * and we have free pre-allocated buffers, fill the ranks as much
5149 * as we can pulling from rx_free.
5150 *
5151 * This moves the 'write' index forward to catch up with 'processed', and
5152 * also updates the memory address in the firmware to reference the new
5153 * target buffer.
5154 */
5155static void ipw_rx_queue_restock(struct ipw_priv *priv)
5156{
5157 struct ipw_rx_queue *rxq = priv->rxq;
5158 struct list_head *element;
5159 struct ipw_rx_mem_buffer *rxb;
5160 unsigned long flags;
5161 int write;
5162
5163 spin_lock_irqsave(&rxq->lock, flags);
5164 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005165 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005166 element = rxq->rx_free.next;
5167 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5168 list_del(element);
5169
James Ketrenosb095c382005-08-24 22:04:42 -05005170 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005171 rxb->dma_addr);
5172 rxq->queue[rxq->write] = rxb;
5173 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5174 rxq->free_count--;
5175 }
5176 spin_unlock_irqrestore(&rxq->lock, flags);
5177
Jeff Garzikbf794512005-07-31 13:07:26 -04005178 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005179 * refill it */
5180 if (rxq->free_count <= RX_LOW_WATERMARK)
5181 queue_work(priv->workqueue, &priv->rx_replenish);
5182
5183 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005184 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005185 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005186}
5187
5188/*
5189 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005190 * Also restock the Rx queue via ipw_rx_queue_restock.
5191 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005192 * This is called as a scheduled work item (except for during intialization)
5193 */
5194static void ipw_rx_queue_replenish(void *data)
5195{
5196 struct ipw_priv *priv = data;
5197 struct ipw_rx_queue *rxq = priv->rxq;
5198 struct list_head *element;
5199 struct ipw_rx_mem_buffer *rxb;
5200 unsigned long flags;
5201
5202 spin_lock_irqsave(&rxq->lock, flags);
5203 while (!list_empty(&rxq->rx_used)) {
5204 element = rxq->rx_used.next;
5205 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005206 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005207 if (!rxb->skb) {
5208 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5209 priv->net_dev->name);
5210 /* We don't reschedule replenish work here -- we will
5211 * call the restock method and if it still needs
5212 * more buffers it will schedule replenish */
5213 break;
5214 }
5215 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005216
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005217 rxb->dma_addr =
5218 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005219 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005220
James Ketrenos43f66a62005-03-25 12:31:53 -06005221 list_add_tail(&rxb->list, &rxq->rx_free);
5222 rxq->free_count++;
5223 }
5224 spin_unlock_irqrestore(&rxq->lock, flags);
5225
5226 ipw_rx_queue_restock(priv);
5227}
5228
David Howellsc4028952006-11-22 14:57:56 +00005229static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005230{
David Howellsc4028952006-11-22 14:57:56 +00005231 struct ipw_priv *priv =
5232 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005233 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005234 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005235 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005236}
5237
James Ketrenos43f66a62005-03-25 12:31:53 -06005238/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005239 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005240 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005241 * non NULL it is unmapped and freed
5242 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005243static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005244{
5245 int i;
5246
5247 if (!rxq)
5248 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005249
James Ketrenos43f66a62005-03-25 12:31:53 -06005250 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5251 if (rxq->pool[i].skb != NULL) {
5252 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005253 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005254 dev_kfree_skb(rxq->pool[i].skb);
5255 }
5256 }
5257
5258 kfree(rxq);
5259}
5260
5261static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5262{
5263 struct ipw_rx_queue *rxq;
5264 int i;
5265
Takisc75f4742005-12-01 01:41:45 -08005266 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005267 if (unlikely(!rxq)) {
5268 IPW_ERROR("memory allocation failed\n");
5269 return NULL;
5270 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005271 spin_lock_init(&rxq->lock);
5272 INIT_LIST_HEAD(&rxq->rx_free);
5273 INIT_LIST_HEAD(&rxq->rx_used);
5274
5275 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005276 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005277 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5278
5279 /* Set us so that we have processed and used all buffers, but have
5280 * not restocked the Rx queue with fresh buffers */
5281 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005282 rxq->free_count = 0;
5283
5284 return rxq;
5285}
5286
5287static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5288{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005289 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005290 if (ieee_mode == IEEE_A) {
5291 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005292 case LIBIPW_OFDM_RATE_6MB:
5293 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005294 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005295 case LIBIPW_OFDM_RATE_9MB:
5296 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005297 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005298 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005299 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005300 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5301 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005302 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005303 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5304 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005305 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005306 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5307 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005308 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005309 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5310 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005311 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005312 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5313 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005314 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005315 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005316 default:
5317 return 0;
5318 }
5319 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005320
James Ketrenos43f66a62005-03-25 12:31:53 -06005321 /* B and G mixed */
5322 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005323 case LIBIPW_CCK_RATE_1MB:
5324 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5325 case LIBIPW_CCK_RATE_2MB:
5326 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5327 case LIBIPW_CCK_RATE_5MB:
5328 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5329 case LIBIPW_CCK_RATE_11MB:
5330 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005331 }
5332
5333 /* If we are limited to B modulations, bail at this point */
5334 if (ieee_mode == IEEE_B)
5335 return 0;
5336
5337 /* G */
5338 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005339 case LIBIPW_OFDM_RATE_6MB:
5340 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5341 case LIBIPW_OFDM_RATE_9MB:
5342 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5343 case LIBIPW_OFDM_RATE_12MB:
5344 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5345 case LIBIPW_OFDM_RATE_18MB:
5346 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5347 case LIBIPW_OFDM_RATE_24MB:
5348 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5349 case LIBIPW_OFDM_RATE_36MB:
5350 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5351 case LIBIPW_OFDM_RATE_48MB:
5352 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5353 case LIBIPW_OFDM_RATE_54MB:
5354 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005355 }
5356
5357 return 0;
5358}
5359
Jeff Garzikbf794512005-07-31 13:07:26 -04005360static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005361 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005362 struct ipw_supported_rates *rates)
5363{
5364 int num_rates, i;
5365
5366 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005367 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005368 rates->num_rates = 0;
5369 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005370 if (!ipw_is_rate_in_mask(priv, network->mode,
5371 network->rates[i])) {
5372
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005373 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005374 IPW_DEBUG_SCAN("Adding masked mandatory "
5375 "rate %02X\n",
5376 network->rates[i]);
5377 rates->supported_rates[rates->num_rates++] =
5378 network->rates[i];
5379 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005380 }
5381
James Ketrenos43f66a62005-03-25 12:31:53 -06005382 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5383 network->rates[i], priv->rates_mask);
5384 continue;
5385 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005386
James Ketrenos43f66a62005-03-25 12:31:53 -06005387 rates->supported_rates[rates->num_rates++] = network->rates[i];
5388 }
5389
James Ketrenosa613bff2005-08-24 21:43:11 -05005390 num_rates = min(network->rates_ex_len,
5391 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005392 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005393 if (!ipw_is_rate_in_mask(priv, network->mode,
5394 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005395 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005396 IPW_DEBUG_SCAN("Adding masked mandatory "
5397 "rate %02X\n",
5398 network->rates_ex[i]);
5399 rates->supported_rates[rates->num_rates++] =
5400 network->rates[i];
5401 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005402 }
5403
James Ketrenos43f66a62005-03-25 12:31:53 -06005404 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5405 network->rates_ex[i], priv->rates_mask);
5406 continue;
5407 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005408
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005409 rates->supported_rates[rates->num_rates++] =
5410 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005411 }
5412
James Ketrenosea2b26e2005-08-24 21:25:16 -05005413 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005414}
5415
Arjan van de Ven858119e2006-01-14 13:20:43 -08005416static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005417 const struct ipw_supported_rates *src)
5418{
5419 u8 i;
5420 for (i = 0; i < src->num_rates; i++)
5421 dest->supported_rates[i] = src->supported_rates[i];
5422 dest->num_rates = src->num_rates;
5423}
5424
5425/* TODO: Look at sniffed packets in the air to determine if the basic rate
5426 * mask should ever be used -- right now all callers to add the scan rates are
5427 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5428static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005429 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005430{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005431 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5432 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005433
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005434 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005435 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005436 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005437
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005438 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005439 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005440 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005441
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005442 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005443 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005444 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005445
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005446 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005447 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005449}
5450
5451static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005452 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005453{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005454 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5455 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005456
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005457 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005458 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005459 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005460
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005461 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005462 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005463 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005464
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005465 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005466 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005467 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005468
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005469 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005470 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005471 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005472
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005473 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005474 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005475 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005476
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005477 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005478 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005479 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005480
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005481 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005482 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005483 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005484
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005485 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005486 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005487 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005488}
5489
5490struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005491 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005492 struct ipw_supported_rates rates;
5493};
5494
James Ketrenosc848d0a2005-08-24 21:56:24 -05005495static int ipw_find_adhoc_network(struct ipw_priv *priv,
5496 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005497 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005498 int roaming)
5499{
5500 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005501 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005502
5503 /* Verify that this network's capability is compatible with the
5504 * current mode (AdHoc or Infrastructure) */
5505 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5506 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005507 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005508 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005509 print_ssid(ssid, network->ssid,
5510 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005511 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005512 return 0;
5513 }
5514
James Ketrenosc848d0a2005-08-24 21:56:24 -05005515 if (unlikely(roaming)) {
5516 /* If we are roaming, then ensure check if this is a valid
5517 * network to try and roam to */
5518 if ((network->ssid_len != match->network->ssid_len) ||
5519 memcmp(network->ssid, match->network->ssid,
5520 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005521 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005522 "because of non-network ESSID.\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 } else {
5529 /* If an ESSID has been configured then compare the broadcast
5530 * ESSID to ours */
5531 if ((priv->config & CFG_STATIC_ESSID) &&
5532 ((network->ssid_len != priv->essid_len) ||
5533 memcmp(network->ssid, priv->essid,
5534 min(network->ssid_len, priv->essid_len)))) {
5535 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005536
James Ketrenosc848d0a2005-08-24 21:56:24 -05005537 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005538 print_ssid(ssid, network->ssid,
5539 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005540 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005541 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005542 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005543 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005544 print_ssid(ssid, priv->essid,
5545 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005546 return 0;
5547 }
5548 }
5549
5550 /* If the old network rate is better than this one, don't bother
5551 * testing everything else. */
5552
5553 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005554 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5555 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005556 print_ssid(ssid, match->network->ssid,
5557 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005558 return 0;
5559 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005560 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5561 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005562 print_ssid(ssid, match->network->ssid,
5563 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005564 return 0;
5565 }
5566
5567 /* Now go through and see if the requested network is valid... */
5568 if (priv->ieee->scan_age != 0 &&
5569 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005570 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005571 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005572 print_ssid(ssid, network->ssid,
5573 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005574 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005575 jiffies_to_msecs(jiffies -
5576 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005577 return 0;
5578 }
5579
5580 if ((priv->config & CFG_STATIC_CHANNEL) &&
5581 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005582 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005583 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005584 print_ssid(ssid, network->ssid,
5585 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005586 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005587 network->channel, priv->channel);
5588 return 0;
5589 }
5590
5591 /* Verify privacy compatability */
5592 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5593 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005594 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005595 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005596 print_ssid(ssid, network->ssid,
5597 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005598 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005599 priv->
5600 capability & CAP_PRIVACY_ON ? "on" : "off",
5601 network->
5602 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5603 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005604 return 0;
5605 }
5606
5607 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005608 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5609 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005610 ".\n", print_ssid(ssid, network->ssid,
5611 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005612 network->bssid,
5613 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005614 return 0;
5615 }
5616
5617 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005618 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005619 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005620 "because of invalid frequency/mode "
5621 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005622 print_ssid(ssid, network->ssid,
5623 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005624 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625 return 0;
5626 }
5627
5628 /* Ensure that the rates supported by the driver are compatible with
5629 * this AP, including verification of basic rates (mandatory) */
5630 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005631 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005632 "because configured rate mask excludes "
5633 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005634 print_ssid(ssid, network->ssid,
5635 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005636 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005637 return 0;
5638 }
5639
5640 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005641 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005642 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005643 print_ssid(ssid, network->ssid,
5644 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005645 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005646 return 0;
5647 }
5648
5649 /* TODO: Perform any further minimal comparititive tests. We do not
5650 * want to put too much policy logic here; intelligent scan selection
5651 * should occur within a generic IEEE 802.11 user space tool. */
5652
5653 /* Set up 'new' AP to this network */
5654 ipw_copy_rates(&match->rates, &rates);
5655 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005656 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005657 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005658 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005659
5660 return 1;
5661}
5662
David Howellsc4028952006-11-22 14:57:56 +00005663static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005664{
John W. Linville9387b7c2008-09-30 20:59:05 -04005665 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005666 struct ipw_priv *priv =
5667 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005668 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005669 struct ipw_network_match match = {
5670 .network = priv->assoc_network
5671 };
5672
James Ketrenosafbf30a2005-08-25 00:05:33 -05005673 if ((priv->status & STATUS_ASSOCIATED) &&
5674 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005675 /* First pass through ROAM process -- look for a better
5676 * network */
5677 unsigned long flags;
5678
5679 spin_lock_irqsave(&priv->ieee->lock, flags);
5680 list_for_each_entry(network, &priv->ieee->network_list, list) {
5681 if (network != priv->assoc_network)
5682 ipw_find_adhoc_network(priv, &match, network,
5683 1);
5684 }
5685 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5686
5687 if (match.network == priv->assoc_network) {
5688 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5689 "merge to.\n");
5690 return;
5691 }
5692
Zhu Yi46441512006-01-24 16:37:59 +08005693 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005694 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5695 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005696 print_ssid(ssid, priv->essid,
5697 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005698 ipw_remove_current_network(priv);
5699 }
5700
5701 ipw_disassociate(priv);
5702 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005703 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005704 return;
5705 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005706}
5707
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005708static int ipw_best_network(struct ipw_priv *priv,
5709 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005710 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005711{
5712 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005713 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005714
5715 /* Verify that this network's capability is compatible with the
5716 * current mode (AdHoc or Infrastructure) */
5717 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005718 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005719 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5720 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005721 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005722 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005723 print_ssid(ssid, network->ssid,
5724 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005725 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005726 return 0;
5727 }
5728
James Ketrenos43f66a62005-03-25 12:31:53 -06005729 if (unlikely(roaming)) {
5730 /* If we are roaming, then ensure check if this is a valid
5731 * network to try and roam to */
5732 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005733 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005734 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005735 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005736 "because of non-network ESSID.\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 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005743 /* If an ESSID has been configured then compare the broadcast
5744 * ESSID to ours */
5745 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005746 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005747 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 min(network->ssid_len, priv->essid_len)))) {
5749 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005750 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005751 print_ssid(ssid, network->ssid,
5752 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005753 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005754 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005755 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005756 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005757 print_ssid(ssid, priv->essid,
5758 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005759 return 0;
5760 }
5761 }
5762
5763 /* If the old network rate is better than this one, don't bother
5764 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005765 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005766 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005767 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005768 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005769 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005770 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5771 "'%s (%pM)' has a stronger signal.\n",
5772 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005773 print_ssid(ssid, match->network->ssid,
5774 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005775 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005776 return 0;
5777 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005778
James Ketrenos43f66a62005-03-25 12:31:53 -06005779 /* If this network has already had an association attempt within the
5780 * last 3 seconds, do not try and associate again... */
5781 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005782 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005783 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005784 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005785 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005786 print_ssid(ssid, network->ssid,
5787 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005788 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005789 jiffies_to_msecs(jiffies -
5790 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005791 return 0;
5792 }
5793
5794 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005795 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005796 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
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 age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005799 print_ssid(ssid, network->ssid,
5800 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005801 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005802 jiffies_to_msecs(jiffies -
5803 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005805 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005806
Jeff Garzikbf794512005-07-31 13:07:26 -04005807 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005808 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005809 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005810 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005811 print_ssid(ssid, network->ssid,
5812 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005813 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005814 network->channel, priv->channel);
5815 return 0;
5816 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005817
James Ketrenos43f66a62005-03-25 12:31:53 -06005818 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005819 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005821 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005823 print_ssid(ssid, network->ssid,
5824 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005825 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005826 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005827 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005828 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005829 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005830 return 0;
5831 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005832
5833 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005834 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005835 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5836 "because of BSSID mismatch: %pM.\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, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005840 return 0;
5841 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005842
James Ketrenos43f66a62005-03-25 12:31:53 -06005843 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005844 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005845 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005846 "because of invalid frequency/mode "
5847 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005848 print_ssid(ssid, network->ssid,
5849 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005850 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005851 return 0;
5852 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005853
Liu Hong1fe0adb2005-08-19 09:33:10 -05005854 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005855 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005856 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005857 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005858 print_ssid(ssid, network->ssid,
5859 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005860 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005861 return 0;
5862 }
5863
James Ketrenosea2b26e2005-08-24 21:25:16 -05005864 /* Ensure that the rates supported by the driver are compatible with
5865 * this AP, including verification of basic rates (mandatory) */
5866 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005867 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005868 "because configured rate mask excludes "
5869 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005870 print_ssid(ssid, network->ssid,
5871 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005872 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005873 return 0;
5874 }
5875
James Ketrenos43f66a62005-03-25 12:31:53 -06005876 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005877 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005879 print_ssid(ssid, network->ssid,
5880 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005881 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005882 return 0;
5883 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005884
James Ketrenos43f66a62005-03-25 12:31:53 -06005885 /* TODO: Perform any further minimal comparititive tests. We do not
5886 * want to put too much policy logic here; intelligent scan selection
5887 * should occur within a generic IEEE 802.11 user space tool. */
5888
5889 /* Set up 'new' AP to this network */
5890 ipw_copy_rates(&match->rates, &rates);
5891 match->network = network;
5892
Johannes Berge1749612008-10-27 15:59:26 -07005893 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005894 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005895 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005896
5897 return 1;
5898}
5899
Jeff Garzikbf794512005-07-31 13:07:26 -04005900static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005901 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005902{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005903 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005904 int i;
5905
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 /*
5907 * For the purposes of scanning, we can set our wireless mode
5908 * to trigger scans across combinations of bands, but when it
5909 * comes to creating a new ad-hoc network, we have tell the FW
5910 * exactly which band to use.
5911 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005912 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005913 * chossen band. Attempting to create a new ad-hoc network
5914 * with an invalid channel for wireless mode will trigger a
5915 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005916 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005917 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005918 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5919 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005920 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005921 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005922 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005923 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005924 IPW_WARNING("Overriding invalid channel\n");
5925 priv->channel = geo->a[0].channel;
5926 }
5927 break;
5928
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005929 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005930 if (priv->ieee->mode & IEEE_G)
5931 network->mode = IEEE_G;
5932 else
5933 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005934 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005935 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005936 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005937 IPW_WARNING("Overriding invalid channel\n");
5938 priv->channel = geo->bg[0].channel;
5939 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005940 break;
5941
5942 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005943 IPW_WARNING("Overriding invalid channel\n");
5944 if (priv->ieee->mode & IEEE_A) {
5945 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005946 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005947 } else if (priv->ieee->mode & IEEE_G) {
5948 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005949 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005950 } else {
5951 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005952 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005953 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005954 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005955 }
5956
5957 network->channel = priv->channel;
5958 priv->config |= CFG_ADHOC_PERSIST;
5959 ipw_create_bssid(priv, network->bssid);
5960 network->ssid_len = priv->essid_len;
5961 memcpy(network->ssid, priv->essid, priv->essid_len);
5962 memset(&network->stats, 0, sizeof(network->stats));
5963 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005964 if (!(priv->config & CFG_PREAMBLE_LONG))
5965 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005966 if (priv->capability & CAP_PRIVACY_ON)
5967 network->capability |= WLAN_CAPABILITY_PRIVACY;
5968 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005969 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005970 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005971 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005972 &priv->rates.supported_rates[network->rates_len],
5973 network->rates_ex_len);
5974 network->last_scanned = 0;
5975 network->flags = 0;
5976 network->last_associate = 0;
5977 network->time_stamp[0] = 0;
5978 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005979 network->beacon_interval = 100; /* Default */
5980 network->listen_interval = 10; /* Default */
5981 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005982 network->wpa_ie_len = 0;
5983 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005984}
5985
James Ketrenosb095c382005-08-24 22:04:42 -05005986static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5987{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005988 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005989
5990 if (!(priv->ieee->sec.flags & (1 << index)))
5991 return;
5992
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005993 key.key_id = index;
5994 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5995 key.security_type = type;
5996 key.station_index = 0; /* always 0 for BSS */
5997 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005998 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005999 key.tx_counter[0] = cpu_to_le32(0);
6000 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05006001
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006002 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05006003}
6004
6005static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06006006{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006007 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006008 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006009
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006010 key.cmd_id = DINO_CMD_WEP_KEY;
6011 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006012
James Ketrenosb095c382005-08-24 22:04:42 -05006013 /* Note: AES keys cannot be set for multiple times.
6014 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006015 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006016 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006017 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006018 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006019 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006020 }
6021
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006022 key.key_size = priv->ieee->sec.key_sizes[i];
6023 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006024
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006025 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006026 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006027}
6028
Zhu Yi1fbfea52005-08-05 17:22:56 +08006029static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6030{
6031 if (priv->ieee->host_encrypt)
6032 return;
6033
6034 switch (level) {
6035 case SEC_LEVEL_3:
6036 priv->sys_config.disable_unicast_decryption = 0;
6037 priv->ieee->host_decrypt = 0;
6038 break;
6039 case SEC_LEVEL_2:
6040 priv->sys_config.disable_unicast_decryption = 1;
6041 priv->ieee->host_decrypt = 1;
6042 break;
6043 case SEC_LEVEL_1:
6044 priv->sys_config.disable_unicast_decryption = 0;
6045 priv->ieee->host_decrypt = 0;
6046 break;
6047 case SEC_LEVEL_0:
6048 priv->sys_config.disable_unicast_decryption = 1;
6049 break;
6050 default:
6051 break;
6052 }
6053}
6054
6055static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6056{
6057 if (priv->ieee->host_encrypt)
6058 return;
6059
6060 switch (level) {
6061 case SEC_LEVEL_3:
6062 priv->sys_config.disable_multicast_decryption = 0;
6063 break;
6064 case SEC_LEVEL_2:
6065 priv->sys_config.disable_multicast_decryption = 1;
6066 break;
6067 case SEC_LEVEL_1:
6068 priv->sys_config.disable_multicast_decryption = 0;
6069 break;
6070 case SEC_LEVEL_0:
6071 priv->sys_config.disable_multicast_decryption = 1;
6072 break;
6073 default:
6074 break;
6075 }
6076}
6077
James Ketrenosb095c382005-08-24 22:04:42 -05006078static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6079{
6080 switch (priv->ieee->sec.level) {
6081 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006082 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6083 ipw_send_tgi_tx_key(priv,
6084 DCT_FLAG_EXT_SECURITY_CCM,
6085 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006086
Hong Liu567deaf2005-08-31 18:07:22 +08006087 if (!priv->ieee->host_mc_decrypt)
6088 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006089 break;
6090 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006091 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6092 ipw_send_tgi_tx_key(priv,
6093 DCT_FLAG_EXT_SECURITY_TKIP,
6094 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006095 break;
6096 case SEC_LEVEL_1:
6097 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006098 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6099 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006100 break;
6101 case SEC_LEVEL_0:
6102 default:
6103 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006104 }
6105}
6106
6107static void ipw_adhoc_check(void *data)
6108{
6109 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006110
James Ketrenosafbf30a2005-08-25 00:05:33 -05006111 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006112 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006113 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6114 IPW_DL_STATE | IPW_DL_ASSOC,
6115 "Missed beacon: %d - disassociate\n",
6116 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006117 ipw_remove_current_network(priv);
6118 ipw_disassociate(priv);
6119 return;
6120 }
6121
Jeff Garzikbf794512005-07-31 13:07:26 -04006122 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006123 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006124}
6125
David Howellsc4028952006-11-22 14:57:56 +00006126static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006127{
David Howellsc4028952006-11-22 14:57:56 +00006128 struct ipw_priv *priv =
6129 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006130 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006131 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006132 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006133}
6134
James Ketrenos43f66a62005-03-25 12:31:53 -06006135static void ipw_debug_config(struct ipw_priv *priv)
6136{
John W. Linville9387b7c2008-09-30 20:59:05 -04006137 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006138 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6139 "[CFG 0x%08X]\n", priv->config);
6140 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006141 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006142 else
6143 IPW_DEBUG_INFO("Channel unlocked.\n");
6144 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006145 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006146 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006147 else
6148 IPW_DEBUG_INFO("ESSID unlocked.\n");
6149 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006150 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006151 else
6152 IPW_DEBUG_INFO("BSSID unlocked.\n");
6153 if (priv->capability & CAP_PRIVACY_ON)
6154 IPW_DEBUG_INFO("PRIVACY on\n");
6155 else
6156 IPW_DEBUG_INFO("PRIVACY off\n");
6157 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6158}
James Ketrenos43f66a62005-03-25 12:31:53 -06006159
Arjan van de Ven858119e2006-01-14 13:20:43 -08006160static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006161{
6162 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006163 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006164 u32 reg;
6165 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006166 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006167
Jeff Garzikbf794512005-07-31 13:07:26 -04006168 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006169 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006170
James Ketrenos43f66a62005-03-25 12:31:53 -06006171 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006172 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006173 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006174 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006175 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006176 IPW_DEBUG_WX
6177 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006178 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006179 break;
6180 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006181
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006182 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006183 break;
6184
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006185 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006186 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006187 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006188 if (new_tx_rates & ~LIBIPW_CCK_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 }
6194 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006195 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006196
6197 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006198 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6199 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006200 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006201 IPW_DEBUG_WX
6202 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006203 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006204 break;
6205 }
6206
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006207 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6208 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6209 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006210 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006211
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006212 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6213 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6214 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006215 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006216
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006217 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6218 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6219 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006220 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006221
Reinette Chatre21f8a732009-08-18 10:25:05 -07006222 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006223 break;
6224 }
6225
Reinette Chatre21f8a732009-08-18 10:25:05 -07006226 fr.tx_rates = cpu_to_le16(new_tx_rates);
6227
James Ketrenos43f66a62005-03-25 12:31:53 -06006228 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006229 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006230}
6231
James Ketrenosea2b26e2005-08-24 21:25:16 -05006232static void ipw_abort_scan(struct ipw_priv *priv)
6233{
6234 int err;
6235
6236 if (priv->status & STATUS_SCAN_ABORTING) {
6237 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6238 return;
6239 }
6240 priv->status |= STATUS_SCAN_ABORTING;
6241
6242 err = ipw_send_scan_abort(priv);
6243 if (err)
6244 IPW_DEBUG_HC("Request to abort scan failed.\n");
6245}
6246
James Ketrenosafbf30a2005-08-25 00:05:33 -05006247static void ipw_add_scan_channels(struct ipw_priv *priv,
6248 struct ipw_scan_request_ext *scan,
6249 int scan_type)
6250{
6251 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006252 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006253 int i;
6254
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006255 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006256
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006257 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006258 int start = channel_index;
6259 for (i = 0; i < geo->a_channels; i++) {
6260 if ((priv->status & STATUS_ASSOCIATED) &&
6261 geo->a[i].channel == priv->channel)
6262 continue;
6263 channel_index++;
6264 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006265 ipw_set_scan_type(scan, channel_index,
6266 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006267 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006268 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6269 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006270 }
6271
6272 if (start != channel_index) {
6273 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6274 (channel_index - start);
6275 channel_index++;
6276 }
6277 }
6278
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006279 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006280 int start = channel_index;
6281 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006282 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006283 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006284 /* nop out the list */
6285 [0] = 0
6286 };
6287
6288 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006289 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006290 channel =
6291 priv->speed_scan[priv->speed_scan_pos];
6292 if (channel == 0) {
6293 priv->speed_scan_pos = 0;
6294 channel = priv->speed_scan[0];
6295 }
6296 if ((priv->status & STATUS_ASSOCIATED) &&
6297 channel == priv->channel) {
6298 priv->speed_scan_pos++;
6299 continue;
6300 }
6301
6302 /* If this channel has already been
6303 * added in scan, break from loop
6304 * and this will be the first channel
6305 * in the next scan.
6306 */
6307 if (channels[channel - 1] != 0)
6308 break;
6309
6310 channels[channel - 1] = 1;
6311 priv->speed_scan_pos++;
6312 channel_index++;
6313 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006314 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006315 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006316 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006317 geo->bg[index].
6318 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006319 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006320 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6321 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006322 }
6323 } else {
6324 for (i = 0; i < geo->bg_channels; i++) {
6325 if ((priv->status & STATUS_ASSOCIATED) &&
6326 geo->bg[i].channel == priv->channel)
6327 continue;
6328 channel_index++;
6329 scan->channels_list[channel_index] =
6330 geo->bg[i].channel;
6331 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006332 geo->bg[i].
6333 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006334 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006335 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6336 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006337 }
6338 }
6339
6340 if (start != channel_index) {
6341 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6342 (channel_index - start);
6343 }
6344 }
6345}
6346
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006347static int ipw_passive_dwell_time(struct ipw_priv *priv)
6348{
6349 /* staying on passive channels longer than the DTIM interval during a
6350 * scan, while associated, causes the firmware to cancel the scan
6351 * without notification. Hence, don't stay on passive channels longer
6352 * than the beacon interval.
6353 */
6354 if (priv->status & STATUS_ASSOCIATED
6355 && priv->assoc_network->beacon_interval > 10)
6356 return priv->assoc_network->beacon_interval - 10;
6357 else
6358 return 120;
6359}
6360
Dan Williamsea177302008-06-02 17:51:23 -04006361static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006362{
6363 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006364 int err = 0, scan_type;
6365
6366 if (!(priv->status & STATUS_INIT) ||
6367 (priv->status & STATUS_EXIT_PENDING))
6368 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006369
Zhu Yi46441512006-01-24 16:37:59 +08006370 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006371
Dan Williamsea177302008-06-02 17:51:23 -04006372 if (direct && (priv->direct_scan_ssid_len == 0)) {
6373 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6374 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6375 goto done;
6376 }
6377
James Ketrenosea2b26e2005-08-24 21:25:16 -05006378 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006379 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6380 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6381 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006382 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006383 }
6384
James Ketrenosafbf30a2005-08-25 00:05:33 -05006385 if (!(priv->status & STATUS_SCAN_FORCED) &&
6386 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006387 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006388 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6389 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006390 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006391 }
6392
6393 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006394 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6395 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6396 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006397 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006398 }
6399
6400 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006401 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006402
Zhu Yi094c4d22006-08-21 11:39:03 +08006403 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006404 IPW_DEBUG_WX("use passive scanning\n");
6405 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006406 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006407 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006408 ipw_add_scan_channels(priv, &scan, scan_type);
6409 goto send_request;
6410 }
6411
6412 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006413 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006414 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006415 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006416 else
6417 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006418 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006419
James Ketrenosa613bff2005-08-24 21:43:11 -05006420 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006421 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006422
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006423 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6424 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006425 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006426
James Ketrenosb095c382005-08-24 22:04:42 -05006427#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006428 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006429 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006430 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006431
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006432 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6433 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006434 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006435 channel = priv->channel;
6436 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006437
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006438 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006439 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006440 channel = priv->channel;
6441 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006442
James Ketrenosb095c382005-08-24 22:04:42 -05006443 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006444 band = (u8) (IPW_B_MODE << 6) | 1;
6445 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006446 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006447 }
6448
James Ketrenosb095c382005-08-24 22:04:42 -05006449 scan.channels_list[0] = band;
6450 scan.channels_list[1] = channel;
6451 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006452
James Ketrenosb095c382005-08-24 22:04:42 -05006453 /* NOTE: The card will sit on this channel for this time
6454 * period. Scan aborts are timing sensitive and frequently
6455 * result in firmware restarts. As such, it is best to
6456 * set a small dwell_time here and just keep re-issuing
6457 * scans. Otherwise fast channel hopping will not actually
6458 * hop channels.
6459 *
6460 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006461 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006462 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006463 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006464#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006465 /* Honor direct scans first, otherwise if we are roaming make
6466 * this a direct scan for the current network. Finally,
6467 * ensure that every other scan is a fast channel hop scan */
6468 if (direct) {
6469 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6470 priv->direct_scan_ssid_len);
6471 if (err) {
6472 IPW_DEBUG_HC("Attempt to send SSID command "
6473 "failed\n");
6474 goto done;
6475 }
6476
6477 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6478 } else if ((priv->status & STATUS_ROAMING)
6479 || (!(priv->status & STATUS_ASSOCIATED)
6480 && (priv->config & CFG_STATIC_ESSID)
6481 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006482 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6483 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006484 IPW_DEBUG_HC("Attempt to send SSID command "
6485 "failed.\n");
6486 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006487 }
6488
6489 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006490 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006491 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006492
James Ketrenosafbf30a2005-08-25 00:05:33 -05006493 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006494#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006495 }
6496#endif
6497
Zhu Yi094c4d22006-08-21 11:39:03 +08006498send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006499 err = ipw_send_scan_request_ext(priv, &scan);
6500 if (err) {
6501 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006502 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006503 }
6504
6505 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006506 if (direct) {
6507 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6508 priv->direct_scan_ssid_len = 0;
6509 } else
6510 priv->status &= ~STATUS_SCAN_PENDING;
6511
James Ketrenosafbf30a2005-08-25 00:05:33 -05006512 queue_delayed_work(priv->workqueue, &priv->scan_check,
6513 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006514done:
Zhu Yi46441512006-01-24 16:37:59 +08006515 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006516 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006517}
6518
David Howellsc4028952006-11-22 14:57:56 +00006519static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006520{
David Howellsc4028952006-11-22 14:57:56 +00006521 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006522 container_of(work, struct ipw_priv, request_passive_scan.work);
6523 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006524}
6525
6526static void ipw_request_scan(struct work_struct *work)
6527{
6528 struct ipw_priv *priv =
6529 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006530 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6531}
6532
6533static void ipw_request_direct_scan(struct work_struct *work)
6534{
6535 struct ipw_priv *priv =
6536 container_of(work, struct ipw_priv, request_direct_scan.work);
6537 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006538}
6539
6540static void ipw_bg_abort_scan(struct work_struct *work)
6541{
6542 struct ipw_priv *priv =
6543 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006544 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006545 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006546 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006547}
6548
James Ketrenosea2b26e2005-08-24 21:25:16 -05006549static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6550{
James Ketrenosb095c382005-08-24 22:04:42 -05006551 /* This is called when wpa_supplicant loads and closes the driver
6552 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006553 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006554 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006555}
6556
James Ketrenosea2b26e2005-08-24 21:25:16 -05006557static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6558{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006559 struct libipw_device *ieee = priv->ieee;
6560 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006561 .flags = SEC_AUTH_MODE,
6562 };
6563 int ret = 0;
6564
James Ketrenosafbf30a2005-08-25 00:05:33 -05006565 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006566 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6567 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006568 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569 sec.auth_mode = WLAN_AUTH_OPEN;
6570 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006571 } else if (value & IW_AUTH_ALG_LEAP) {
6572 sec.auth_mode = WLAN_AUTH_LEAP;
6573 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006574 } else
6575 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006576
6577 if (ieee->set_security)
6578 ieee->set_security(ieee->dev, &sec);
6579 else
6580 ret = -EOPNOTSUPP;
6581
6582 return ret;
6583}
6584
Adrian Bunka73e22b2006-01-21 01:39:42 +01006585static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6586 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006587{
6588 /* make sure WPA is enabled */
6589 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006590}
6591
6592static int ipw_set_rsn_capa(struct ipw_priv *priv,
6593 char *capabilities, int length)
6594{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006595 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6596
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006597 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006598 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006599}
6600
James Ketrenosafbf30a2005-08-25 00:05:33 -05006601/*
6602 * WE-18 support
6603 */
6604
6605/* SIOCSIWGENIE */
6606static int ipw_wx_set_genie(struct net_device *dev,
6607 struct iw_request_info *info,
6608 union iwreq_data *wrqu, char *extra)
6609{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006610 struct ipw_priv *priv = libipw_priv(dev);
6611 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 u8 *buf;
6613 int err = 0;
6614
6615 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6616 (wrqu->data.length && extra == NULL))
6617 return -EINVAL;
6618
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 if (wrqu->data.length) {
6620 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6621 if (buf == NULL) {
6622 err = -ENOMEM;
6623 goto out;
6624 }
6625
6626 memcpy(buf, extra, wrqu->data.length);
6627 kfree(ieee->wpa_ie);
6628 ieee->wpa_ie = buf;
6629 ieee->wpa_ie_len = wrqu->data.length;
6630 } else {
6631 kfree(ieee->wpa_ie);
6632 ieee->wpa_ie = NULL;
6633 ieee->wpa_ie_len = 0;
6634 }
6635
6636 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6637 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006638 return err;
6639}
6640
6641/* SIOCGIWGENIE */
6642static int ipw_wx_get_genie(struct net_device *dev,
6643 struct iw_request_info *info,
6644 union iwreq_data *wrqu, char *extra)
6645{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006646 struct ipw_priv *priv = libipw_priv(dev);
6647 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006648 int err = 0;
6649
James Ketrenosafbf30a2005-08-25 00:05:33 -05006650 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6651 wrqu->data.length = 0;
6652 goto out;
6653 }
6654
6655 if (wrqu->data.length < ieee->wpa_ie_len) {
6656 err = -E2BIG;
6657 goto out;
6658 }
6659
6660 wrqu->data.length = ieee->wpa_ie_len;
6661 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6662
6663 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006664 return err;
6665}
6666
Zhu Yi1fbfea52005-08-05 17:22:56 +08006667static int wext_cipher2level(int cipher)
6668{
6669 switch (cipher) {
6670 case IW_AUTH_CIPHER_NONE:
6671 return SEC_LEVEL_0;
6672 case IW_AUTH_CIPHER_WEP40:
6673 case IW_AUTH_CIPHER_WEP104:
6674 return SEC_LEVEL_1;
6675 case IW_AUTH_CIPHER_TKIP:
6676 return SEC_LEVEL_2;
6677 case IW_AUTH_CIPHER_CCMP:
6678 return SEC_LEVEL_3;
6679 default:
6680 return -1;
6681 }
6682}
6683
James Ketrenosafbf30a2005-08-25 00:05:33 -05006684/* SIOCSIWAUTH */
6685static int ipw_wx_set_auth(struct net_device *dev,
6686 struct iw_request_info *info,
6687 union iwreq_data *wrqu, char *extra)
6688{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006689 struct ipw_priv *priv = libipw_priv(dev);
6690 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006692 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006693 unsigned long flags;
6694 int ret = 0;
6695
6696 switch (param->flags & IW_AUTH_INDEX) {
6697 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006698 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006699 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006700 ipw_set_hw_decrypt_unicast(priv,
6701 wext_cipher2level(param->value));
6702 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006703 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006704 ipw_set_hw_decrypt_multicast(priv,
6705 wext_cipher2level(param->value));
6706 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006707 case IW_AUTH_KEY_MGMT:
6708 /*
6709 * ipw2200 does not use these parameters
6710 */
6711 break;
6712
6713 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006714 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006715 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006716 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006717
6718 flags = crypt->ops->get_flags(crypt->priv);
6719
6720 if (param->value)
6721 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6722 else
6723 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6724
6725 crypt->ops->set_flags(flags, crypt->priv);
6726
6727 break;
6728
6729 case IW_AUTH_DROP_UNENCRYPTED:{
6730 /* HACK:
6731 *
6732 * wpa_supplicant calls set_wpa_enabled when the driver
6733 * is loaded and unloaded, regardless of if WPA is being
6734 * used. No other calls are made which can be used to
6735 * determine if encryption will be used or not prior to
6736 * association being expected. If encryption is not being
6737 * used, drop_unencrypted is set to false, else true -- we
6738 * can use this to determine if the CAP_PRIVACY_ON bit should
6739 * be set.
6740 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006741 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006742 .flags = SEC_ENABLED,
6743 .enabled = param->value,
6744 };
6745 priv->ieee->drop_unencrypted = param->value;
6746 /* We only change SEC_LEVEL for open mode. Others
6747 * are set by ipw_wpa_set_encryption.
6748 */
6749 if (!param->value) {
6750 sec.flags |= SEC_LEVEL;
6751 sec.level = SEC_LEVEL_0;
6752 } else {
6753 sec.flags |= SEC_LEVEL;
6754 sec.level = SEC_LEVEL_1;
6755 }
6756 if (priv->ieee->set_security)
6757 priv->ieee->set_security(priv->ieee->dev, &sec);
6758 break;
6759 }
6760
6761 case IW_AUTH_80211_AUTH_ALG:
6762 ret = ipw_wpa_set_auth_algs(priv, param->value);
6763 break;
6764
6765 case IW_AUTH_WPA_ENABLED:
6766 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006767 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006768 break;
6769
6770 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6771 ieee->ieee802_1x = param->value;
6772 break;
6773
James Ketrenosafbf30a2005-08-25 00:05:33 -05006774 case IW_AUTH_PRIVACY_INVOKED:
6775 ieee->privacy_invoked = param->value;
6776 break;
6777
6778 default:
6779 return -EOPNOTSUPP;
6780 }
6781 return ret;
6782}
6783
6784/* SIOCGIWAUTH */
6785static int ipw_wx_get_auth(struct net_device *dev,
6786 struct iw_request_info *info,
6787 union iwreq_data *wrqu, char *extra)
6788{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006789 struct ipw_priv *priv = libipw_priv(dev);
6790 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006791 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006792 struct iw_param *param = &wrqu->param;
6793 int ret = 0;
6794
6795 switch (param->flags & IW_AUTH_INDEX) {
6796 case IW_AUTH_WPA_VERSION:
6797 case IW_AUTH_CIPHER_PAIRWISE:
6798 case IW_AUTH_CIPHER_GROUP:
6799 case IW_AUTH_KEY_MGMT:
6800 /*
6801 * wpa_supplicant will control these internally
6802 */
6803 ret = -EOPNOTSUPP;
6804 break;
6805
6806 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006807 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006808 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006809 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006810
6811 param->value = (crypt->ops->get_flags(crypt->priv) &
6812 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6813
6814 break;
6815
6816 case IW_AUTH_DROP_UNENCRYPTED:
6817 param->value = ieee->drop_unencrypted;
6818 break;
6819
6820 case IW_AUTH_80211_AUTH_ALG:
6821 param->value = ieee->sec.auth_mode;
6822 break;
6823
6824 case IW_AUTH_WPA_ENABLED:
6825 param->value = ieee->wpa_enabled;
6826 break;
6827
6828 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6829 param->value = ieee->ieee802_1x;
6830 break;
6831
6832 case IW_AUTH_ROAMING_CONTROL:
6833 case IW_AUTH_PRIVACY_INVOKED:
6834 param->value = ieee->privacy_invoked;
6835 break;
6836
6837 default:
6838 return -EOPNOTSUPP;
6839 }
6840 return 0;
6841}
6842
6843/* SIOCSIWENCODEEXT */
6844static int ipw_wx_set_encodeext(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6847{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006848 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006849 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6850
6851 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006852 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006853 /* IPW HW can't build TKIP MIC,
6854 host decryption still needed */
6855 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6856 priv->ieee->host_mc_decrypt = 1;
6857 else {
6858 priv->ieee->host_encrypt = 0;
6859 priv->ieee->host_encrypt_msdu = 1;
6860 priv->ieee->host_decrypt = 1;
6861 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006862 } else {
6863 priv->ieee->host_encrypt = 0;
6864 priv->ieee->host_encrypt_msdu = 0;
6865 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006866 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006867 }
6868 }
6869
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006870 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006871}
6872
6873/* SIOCGIWENCODEEXT */
6874static int ipw_wx_get_encodeext(struct net_device *dev,
6875 struct iw_request_info *info,
6876 union iwreq_data *wrqu, char *extra)
6877{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006878 struct ipw_priv *priv = libipw_priv(dev);
6879 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006880}
6881
6882/* SIOCSIWMLME */
6883static int ipw_wx_set_mlme(struct net_device *dev,
6884 struct iw_request_info *info,
6885 union iwreq_data *wrqu, char *extra)
6886{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006887 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006888 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006889 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006890
6891 reason = cpu_to_le16(mlme->reason_code);
6892
6893 switch (mlme->cmd) {
6894 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006895 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006896 break;
6897
6898 case IW_MLME_DISASSOC:
6899 ipw_disassociate(priv);
6900 break;
6901
6902 default:
6903 return -EOPNOTSUPP;
6904 }
6905 return 0;
6906}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006907
Zhu Yie43e3c12006-04-13 17:20:45 +08006908#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006909
6910/* QoS */
6911/*
6912* get the modulation type of the current network or
6913* the card current mode
6914*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006915static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006916{
6917 u8 mode = 0;
6918
6919 if (priv->status & STATUS_ASSOCIATED) {
6920 unsigned long flags;
6921
6922 spin_lock_irqsave(&priv->ieee->lock, flags);
6923 mode = priv->assoc_network->mode;
6924 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6925 } else {
6926 mode = priv->ieee->mode;
6927 }
6928 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6929 return mode;
6930}
6931
6932/*
6933* Handle management frame beacon and probe response
6934*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006935static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6936 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006937 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006938{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006939 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006940
James Ketrenosafbf30a2005-08-25 00:05:33 -05006941 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006942 network->qos_data.active = network->qos_data.supported;
6943
6944 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006945 if (active_network &&
6946 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006947 network->qos_data.active = network->qos_data.supported;
6948
6949 if ((network->qos_data.active == 1) && (active_network == 1) &&
6950 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6951 (network->qos_data.old_param_count !=
6952 network->qos_data.param_count)) {
6953 network->qos_data.old_param_count =
6954 network->qos_data.param_count;
6955 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006956 IPW_DEBUG_QOS("QoS parameters change call "
6957 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006958 }
6959 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006960 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6961 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006962 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006963 else
6964 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006965 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006966
James Ketrenosb095c382005-08-24 22:04:42 -05006967 if ((network->qos_data.active == 1) && (active_network == 1)) {
6968 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6969 schedule_work(&priv->qos_activate);
6970 }
6971
6972 network->qos_data.active = 0;
6973 network->qos_data.supported = 0;
6974 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006975 if ((priv->status & STATUS_ASSOCIATED) &&
6976 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6977 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006978 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006979 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006980 priv->assoc_network->ssid_len) &&
6981 !memcmp(network->ssid,
6982 priv->assoc_network->ssid,
6983 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006984 queue_work(priv->workqueue,
6985 &priv->merge_networks);
6986 }
James Ketrenosb095c382005-08-24 22:04:42 -05006987 }
6988
6989 return 0;
6990}
6991
6992/*
6993* This function set up the firmware to support QoS. It sends
6994* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6995*/
6996static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006997 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006998{
6999 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007000 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
7001 struct libipw_qos_parameters *active_one = NULL;
7002 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007003 u32 burst_duration;
7004 int i;
7005 u8 type;
7006
7007 type = ipw_qos_current_mode(priv);
7008
7009 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7010 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7011 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7012 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7013
7014 if (qos_network_data == NULL) {
7015 if (type == IEEE_B) {
7016 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7017 active_one = &def_parameters_CCK;
7018 } else
7019 active_one = &def_parameters_OFDM;
7020
James Ketrenosafbf30a2005-08-25 00:05:33 -05007021 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007022 burst_duration = ipw_qos_get_burst_duration(priv);
7023 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007024 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007025 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007026 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007027 if (type == IEEE_B) {
7028 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7029 type);
7030 if (priv->qos_data.qos_enable == 0)
7031 active_one = &def_parameters_CCK;
7032 else
7033 active_one = priv->qos_data.def_qos_parm_CCK;
7034 } else {
7035 if (priv->qos_data.qos_enable == 0)
7036 active_one = &def_parameters_OFDM;
7037 else
7038 active_one = priv->qos_data.def_qos_parm_OFDM;
7039 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007040 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007041 } else {
7042 unsigned long flags;
7043 int active;
7044
7045 spin_lock_irqsave(&priv->ieee->lock, flags);
7046 active_one = &(qos_network_data->parameters);
7047 qos_network_data->old_param_count =
7048 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007049 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007050 active = qos_network_data->supported;
7051 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7052
7053 if (active == 0) {
7054 burst_duration = ipw_qos_get_burst_duration(priv);
7055 for (i = 0; i < QOS_QUEUE_NUM; i++)
7056 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007057 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007058 }
7059 }
7060
7061 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007062 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007063 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007064 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007065 if (err)
7066 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7067
7068 return err;
7069}
7070
7071/*
7072* send IPW_CMD_WME_INFO to the firmware
7073*/
7074static int ipw_qos_set_info_element(struct ipw_priv *priv)
7075{
7076 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007077 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007078
7079 if (priv == NULL)
7080 return -1;
7081
7082 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007083 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007084
7085 qos_info.version = QOS_VERSION_1;
7086 qos_info.ac_info = 0;
7087
7088 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7089 qos_info.qui_type = QOS_OUI_TYPE;
7090 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7091
7092 ret = ipw_send_qos_info_command(priv, &qos_info);
7093 if (ret != 0) {
7094 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7095 }
7096 return ret;
7097}
7098
7099/*
7100* Set the QoS parameter with the association request structure
7101*/
7102static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007103 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007104{
7105 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007106 struct libipw_qos_data *qos_data = NULL;
7107 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007108 .supported = 1,
7109 .active = 1,
7110 };
7111
7112 switch (priv->ieee->iw_mode) {
7113 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007114 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007115
7116 qos_data = &ibss_data;
7117 break;
7118
7119 case IW_MODE_INFRA:
7120 qos_data = &network->qos_data;
7121 break;
7122
7123 default:
7124 BUG();
7125 break;
7126 }
7127
7128 err = ipw_qos_activate(priv, qos_data);
7129 if (err) {
7130 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7131 return err;
7132 }
7133
7134 if (priv->qos_data.qos_enable && qos_data->supported) {
7135 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7136 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7137 return ipw_qos_set_info_element(priv);
7138 }
7139
7140 return 0;
7141}
7142
7143/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007144* handling the beaconing responses. if we get different QoS setting
7145* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007146* setting
7147*/
7148static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007149 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007150{
7151 int ret = 0;
7152 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007153 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007154 int set_qos_param = 0;
7155
James Ketrenosafbf30a2005-08-25 00:05:33 -05007156 if ((priv == NULL) || (network == NULL) ||
7157 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007158 return ret;
7159
7160 if (!(priv->status & STATUS_ASSOCIATED))
7161 return ret;
7162
James Ketrenosafbf30a2005-08-25 00:05:33 -05007163 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007164 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007165
7166 spin_lock_irqsave(&priv->ieee->lock, flags);
7167 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007168 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007169 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007170 priv->assoc_network->qos_data.active = 1;
7171 if ((network->qos_data.old_param_count !=
7172 network->qos_data.param_count)) {
7173 set_qos_param = 1;
7174 network->qos_data.old_param_count =
7175 network->qos_data.param_count;
7176 }
7177
7178 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007179 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7180 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007181 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007182 else
7183 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007184 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007185 priv->assoc_network->qos_data.active = 0;
7186 priv->assoc_network->qos_data.supported = 0;
7187 set_qos_param = 1;
7188 }
7189
7190 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7191
7192 if (set_qos_param == 1)
7193 schedule_work(&priv->qos_activate);
7194
7195 return ret;
7196}
7197
7198static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7199{
7200 u32 ret = 0;
7201
7202 if ((priv == NULL))
7203 return 0;
7204
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007205 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007206 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007207 else
James Ketrenosb095c382005-08-24 22:04:42 -05007208 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007209
James Ketrenosb095c382005-08-24 22:04:42 -05007210 return ret;
7211}
7212
7213/*
7214* Initialize the setting of QoS global
7215*/
7216static void ipw_qos_init(struct ipw_priv *priv, int enable,
7217 int burst_enable, u32 burst_duration_CCK,
7218 u32 burst_duration_OFDM)
7219{
7220 priv->qos_data.qos_enable = enable;
7221
7222 if (priv->qos_data.qos_enable) {
7223 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7224 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7225 IPW_DEBUG_QOS("QoS is enabled\n");
7226 } else {
7227 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7228 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7229 IPW_DEBUG_QOS("QoS is not enabled\n");
7230 }
7231
7232 priv->qos_data.burst_enable = burst_enable;
7233
7234 if (burst_enable) {
7235 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7236 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7237 } else {
7238 priv->qos_data.burst_duration_CCK = 0;
7239 priv->qos_data.burst_duration_OFDM = 0;
7240 }
7241}
7242
7243/*
7244* map the packet priority to the right TX Queue
7245*/
7246static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7247{
7248 if (priority > 7 || !priv->qos_data.qos_enable)
7249 priority = 0;
7250
7251 return from_priority_to_tx_queue[priority] - 1;
7252}
7253
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007254static int ipw_is_qos_active(struct net_device *dev,
7255 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007256{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007257 struct ipw_priv *priv = libipw_priv(dev);
7258 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007259 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007260 u8 *daddr = skb->data + ETH_ALEN;
7261 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007262
7263 if (!(priv->status & STATUS_ASSOCIATED))
7264 return 0;
7265
7266 qos_data = &priv->assoc_network->qos_data;
7267
James Ketrenosb095c382005-08-24 22:04:42 -05007268 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7269 if (unicast == 0)
7270 qos_data->active = 0;
7271 else
7272 qos_data->active = qos_data->supported;
7273 }
James Ketrenosb095c382005-08-24 22:04:42 -05007274 active = qos_data->active;
7275 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007276 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7277 "unicast %d\n",
7278 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007279 if (active && priv->qos_data.qos_enable)
7280 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007281
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007282 return 0;
7283
7284}
7285/*
7286* add QoS parameter to the TX command
7287*/
7288static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7289 u16 priority,
7290 struct tfd_data *tfd)
7291{
7292 int tx_queue_id = 0;
7293
7294
7295 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7296 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7297
7298 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7299 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007300 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007301 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007302 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007303}
7304
7305/*
7306* background support to run QoS activate functionality
7307*/
David Howellsc4028952006-11-22 14:57:56 +00007308static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007309{
David Howellsc4028952006-11-22 14:57:56 +00007310 struct ipw_priv *priv =
7311 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007312
Zhu Yi46441512006-01-24 16:37:59 +08007313 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007314
7315 if (priv->status & STATUS_ASSOCIATED)
7316 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7317
Zhu Yi46441512006-01-24 16:37:59 +08007318 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007319}
7320
James Ketrenos3b9990c2005-08-19 13:18:55 -05007321static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007322 struct libipw_probe_response *resp,
7323 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007324{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007325 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007326 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7327 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007328
James Ketrenos3b9990c2005-08-19 13:18:55 -05007329 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007330
James Ketrenos3b9990c2005-08-19 13:18:55 -05007331 return 0;
7332}
James Ketrenosb095c382005-08-24 22:04:42 -05007333
James Ketrenos3b9990c2005-08-19 13:18:55 -05007334static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007335 struct libipw_beacon *resp,
7336 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -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));
7341
7342 ipw_qos_handle_probe_response(priv, active_network, network);
7343
7344 return 0;
7345}
7346
7347static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007348 struct libipw_assoc_response *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 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007353 return 0;
7354}
7355
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007356static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007357 *qos_param)
7358{
Zhu Yi4e226992006-01-24 16:37:36 +08007359 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7360 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007361}
7362
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007363static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007364 *qos_param)
7365{
Zhu Yi4e226992006-01-24 16:37:36 +08007366 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7367 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007368}
7369
Zhu Yie43e3c12006-04-13 17:20:45 +08007370#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007371
James Ketrenos43f66a62005-03-25 12:31:53 -06007372static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007373 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007374 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007375{
7376 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007377 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007378
7379 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007380 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007381
7382 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007383 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007384 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 memcpy(priv->essid, network->ssid, priv->essid_len);
7386 }
7387
7388 network->last_associate = jiffies;
7389
7390 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7391 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007392 priv->assoc_request.auth_key = 0;
7393
James Ketrenos43f66a62005-03-25 12:31:53 -06007394 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007395 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007396 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007397 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7398
Zhu Yi1ba61e02006-02-15 13:00:55 +08007399 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007400 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007401
7402 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7403 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7404 priv->assoc_request.auth_type = AUTH_LEAP;
7405 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007406 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007407
James Ketrenosa613bff2005-08-24 21:43:11 -05007408 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007409 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007410 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7411 priv->ieee->wpa_ie_len);
7412 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007413
Jeff Garzikbf794512005-07-31 13:07:26 -04007414 /*
7415 * It is valid for our ieee device to support multiple modes, but
7416 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007417 * just one mode.
7418 */
7419 if (network->mode & priv->ieee->mode & IEEE_A)
7420 priv->assoc_request.ieee_mode = IPW_A_MODE;
7421 else if (network->mode & priv->ieee->mode & IEEE_G)
7422 priv->assoc_request.ieee_mode = IPW_G_MODE;
7423 else if (network->mode & priv->ieee->mode & IEEE_B)
7424 priv->assoc_request.ieee_mode = IPW_B_MODE;
7425
Al Viro5b5e8072007-12-27 01:54:06 -05007426 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007427 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7428 && !(priv->config & CFG_PREAMBLE_LONG)) {
7429 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7430 } else {
7431 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7432
7433 /* Clear the short preamble if we won't be supporting it */
7434 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007435 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007436 }
7437
James Ketrenosafbf30a2005-08-25 00:05:33 -05007438 /* Clear capability bits that aren't used in Ad Hoc */
7439 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7440 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007441 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007442
James Ketrenos43f66a62005-03-25 12:31:53 -06007443 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007444 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007445 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007446 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007447 network->channel,
7448 ipw_modes[priv->assoc_request.ieee_mode],
7449 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007450 (priv->assoc_request.preamble_length ==
7451 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7452 network->capability &
7453 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007454 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007455 priv->capability & CAP_PRIVACY_ON ?
7456 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007457 "(open)") : "",
7458 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007459 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007460 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007461 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007462
Al Viro5b5e8072007-12-27 01:54:06 -05007463 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007465 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007466 priv->assoc_request.assoc_type = HC_IBSS_START;
7467 priv->assoc_request.assoc_tsf_msw = 0;
7468 priv->assoc_request.assoc_tsf_lsw = 0;
7469 } else {
7470 if (unlikely(roaming))
7471 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7472 else
7473 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007474 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7475 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007476 }
7477
James Ketrenosafbf30a2005-08-25 00:05:33 -05007478 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007479
7480 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7481 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007482 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007483 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007484 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007485 priv->assoc_request.atim_window = 0;
7486 }
7487
Al Viro5b5e8072007-12-27 01:54:06 -05007488 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007489
James Ketrenos43f66a62005-03-25 12:31:53 -06007490 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7491 if (err) {
7492 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7493 return err;
7494 }
7495
7496 rates->ieee_mode = priv->assoc_request.ieee_mode;
7497 rates->purpose = IPW_RATE_CONNECT;
7498 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007499
James Ketrenos43f66a62005-03-25 12:31:53 -06007500 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7501 priv->sys_config.dot11g_auto_detection = 1;
7502 else
7503 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007504
7505 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7506 priv->sys_config.answer_broadcast_ssid_probe = 1;
7507 else
7508 priv->sys_config.answer_broadcast_ssid_probe = 0;
7509
Zhu Yid685b8c2006-04-13 17:20:27 +08007510 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007511 if (err) {
7512 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7513 return err;
7514 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007515
James Ketrenos43f66a62005-03-25 12:31:53 -06007516 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007517 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007518 if (err) {
7519 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7520 return err;
7521 }
7522
7523 /*
7524 * If preemption is enabled, it is possible for the association
7525 * to complete before we return from ipw_send_associate. Therefore
7526 * we have to be sure and update our priviate data first.
7527 */
7528 priv->channel = network->channel;
7529 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007530 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007531 priv->status &= ~STATUS_SECURITY_UPDATED;
7532
7533 priv->assoc_network = network;
7534
Zhu Yie43e3c12006-04-13 17:20:45 +08007535#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007536 ipw_qos_association(priv, network);
7537#endif
7538
James Ketrenos43f66a62005-03-25 12:31:53 -06007539 err = ipw_send_associate(priv, &priv->assoc_request);
7540 if (err) {
7541 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7542 return err;
7543 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007544
Johannes Berge1749612008-10-27 15:59:26 -07007545 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007546 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007547 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007548
7549 return 0;
7550}
7551
7552static void ipw_roam(void *data)
7553{
7554 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007555 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 struct ipw_network_match match = {
7557 .network = priv->assoc_network
7558 };
7559
7560 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007561 *
7562 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007563 * setting the status ROAM bit and requesting a scan.
7564 * 2. When the scan completes, it schedules the ROAM work
7565 * 3. The ROAM work looks at all of the known networks for one that
7566 * is a better network than the currently associated. If none
7567 * found, the ROAM process is over (ROAM bit cleared)
7568 * 4. If a better network is found, a disassociation request is
7569 * sent.
7570 * 5. When the disassociation completes, the roam work is again
7571 * scheduled. The second time through, the driver is no longer
7572 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007573 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007574 * 6. At this point ,the roaming process is complete and the ROAM
7575 * status bit is cleared.
7576 */
7577
7578 /* If we are no longer associated, and the roaming bit is no longer
7579 * set, then we are not actively roaming, so just return */
7580 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7581 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007582
James Ketrenos43f66a62005-03-25 12:31:53 -06007583 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007584 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007585 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007586 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007587 u8 rssi = priv->assoc_network->stats.rssi;
7588 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007589 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007590 list_for_each_entry(network, &priv->ieee->network_list, list) {
7591 if (network != priv->assoc_network)
7592 ipw_best_network(priv, &match, network, 1);
7593 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007594 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007595 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007596
James Ketrenos43f66a62005-03-25 12:31:53 -06007597 if (match.network == priv->assoc_network) {
7598 IPW_DEBUG_ASSOC("No better APs in this network to "
7599 "roam to.\n");
7600 priv->status &= ~STATUS_ROAMING;
7601 ipw_debug_config(priv);
7602 return;
7603 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007604
James Ketrenos43f66a62005-03-25 12:31:53 -06007605 ipw_send_disassociate(priv, 1);
7606 priv->assoc_network = match.network;
7607
7608 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007609 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007610
7611 /* Second pass through ROAM process -- request association */
7612 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7613 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7614 priv->status &= ~STATUS_ROAMING;
7615}
7616
David Howellsc4028952006-11-22 14:57:56 +00007617static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007618{
David Howellsc4028952006-11-22 14:57:56 +00007619 struct ipw_priv *priv =
7620 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007621 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007622 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007623 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007624}
7625
7626static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007627{
7628 struct ipw_priv *priv = data;
7629
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007630 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007631 struct ipw_network_match match = {
7632 .network = NULL
7633 };
7634 struct ipw_supported_rates *rates;
7635 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007636 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007637 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007638
James Ketrenosb095c382005-08-24 22:04:42 -05007639 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7640 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7641 return 0;
7642 }
7643
James Ketrenosc848d0a2005-08-24 21:56:24 -05007644 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007645 IPW_DEBUG_ASSOC("Not attempting association (already in "
7646 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007647 return 0;
7648 }
7649
Hong Liue6324722005-09-14 21:04:15 -05007650 if (priv->status & STATUS_DISASSOCIATING) {
7651 IPW_DEBUG_ASSOC("Not attempting association (in "
7652 "disassociating)\n ");
7653 queue_work(priv->workqueue, &priv->associate);
7654 return 0;
7655 }
7656
James Ketrenosc848d0a2005-08-24 21:56:24 -05007657 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007658 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7659 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007660 return 0;
7661 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007662
7663 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007664 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007665 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007666 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007667 }
7668
James Ketrenosa613bff2005-08-24 21:43:11 -05007669 /* Protect our use of the network_list */
7670 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007671 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007672 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007673
7674 network = match.network;
7675 rates = &match.rates;
7676
7677 if (network == NULL &&
7678 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7679 priv->config & CFG_ADHOC_CREATE &&
7680 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007681 priv->config & CFG_STATIC_CHANNEL) {
7682 /* Use oldest network if the free list is empty */
7683 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007684 struct libipw_network *oldest = NULL;
7685 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007686
7687 list_for_each_entry(target, &priv->ieee->network_list, list) {
7688 if ((oldest == NULL) ||
7689 (target->last_scanned < oldest->last_scanned))
7690 oldest = target;
7691 }
7692
7693 /* If there are no more slots, expire the oldest */
7694 list_del(&oldest->list);
7695 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007696 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007697 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007698 print_ssid(ssid, target->ssid,
7699 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007700 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007701 list_add_tail(&target->list,
7702 &priv->ieee->network_free_list);
7703 }
7704
James Ketrenos43f66a62005-03-25 12:31:53 -06007705 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007706 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007707 ipw_adhoc_create(priv, network);
7708 rates = &priv->rates;
7709 list_del(element);
7710 list_add_tail(&network->list, &priv->ieee->network_list);
7711 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007712 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007713
James Ketrenos43f66a62005-03-25 12:31:53 -06007714 /* If we reached the end of the list, then we don't have any valid
7715 * matching APs */
7716 if (!network) {
7717 ipw_debug_config(priv);
7718
James Ketrenosb095c382005-08-24 22:04:42 -05007719 if (!(priv->status & STATUS_SCANNING)) {
7720 if (!(priv->config & CFG_SPEED_SCAN))
7721 queue_delayed_work(priv->workqueue,
7722 &priv->request_scan,
7723 SCAN_INTERVAL);
7724 else
David Howellsc4028952006-11-22 14:57:56 +00007725 queue_delayed_work(priv->workqueue,
7726 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007727 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007728
James Ketrenosc848d0a2005-08-24 21:56:24 -05007729 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007730 }
7731
7732 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007733
7734 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007735}
Jeff Garzikbf794512005-07-31 13:07:26 -04007736
David Howellsc4028952006-11-22 14:57:56 +00007737static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007738{
David Howellsc4028952006-11-22 14:57:56 +00007739 struct ipw_priv *priv =
7740 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007741 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007742 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007743 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007744}
7745
James Ketrenosb095c382005-08-24 22:04:42 -05007746static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7747 struct sk_buff *skb)
7748{
7749 struct ieee80211_hdr *hdr;
7750 u16 fc;
7751
7752 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007753 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007754 if (!(fc & IEEE80211_FCTL_PROTECTED))
7755 return;
7756
7757 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007758 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007759 switch (priv->ieee->sec.level) {
7760 case SEC_LEVEL_3:
7761 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007762 memmove(skb->data + LIBIPW_3ADDR_LEN,
7763 skb->data + LIBIPW_3ADDR_LEN + 8,
7764 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007765 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007766 break;
7767 case SEC_LEVEL_2:
7768 break;
7769 case SEC_LEVEL_1:
7770 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007771 memmove(skb->data + LIBIPW_3ADDR_LEN,
7772 skb->data + LIBIPW_3ADDR_LEN + 4,
7773 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007774 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007775 break;
7776 case SEC_LEVEL_0:
7777 break;
7778 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007779 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007780 priv->ieee->sec.level);
7781 break;
7782 }
7783}
7784
7785static void ipw_handle_data_packet(struct ipw_priv *priv,
7786 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007787 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007788{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007789 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007790 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007791 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7792
7793 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007794 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007795
Jeff Garzikbf794512005-07-31 13:07:26 -04007796 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007797 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007798 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007799 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007800 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007801 priv->wstats.discard.misc++;
7802 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7803 return;
7804 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007805 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007806 priv->wstats.discard.misc++;
7807 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7808 return;
7809 }
7810
7811 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007812 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007813
7814 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007815 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007816
7817 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7818
James Ketrenosb095c382005-08-24 22:04:42 -05007819 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007820 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007821 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007822 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007823 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007824 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7825
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007826 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007827 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007828 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007829 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007830 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007831 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007832}
7833
Zhu Yi459d4082006-04-13 17:21:00 +08007834#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007835static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7836 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007837 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007838{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007839 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007840 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7841 struct ipw_rx_frame *frame = &pkt->u.frame;
7842
7843 /* initial pull of some data */
7844 u16 received_channel = frame->received_channel;
7845 u8 antennaAndPhy = frame->antennaAndPhy;
7846 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7847 u16 pktrate = frame->rate;
7848
7849 /* Magic struct that slots into the radiotap header -- no reason
7850 * to build this manually element by element, we can write it much
7851 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007852 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007853
7854 short len = le16_to_cpu(pkt->u.frame.length);
7855
7856 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007857 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007858
7859 /* We only process data packets if the
7860 * interface is open */
7861 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7862 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007863 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007864 priv->wstats.discard.misc++;
7865 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7866 return;
7867 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007868 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007869 priv->wstats.discard.misc++;
7870 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7871 return;
7872 }
7873
7874 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7875 * that now */
7876 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7877 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007878 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007879 priv->wstats.discard.misc++;
7880 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7881 return;
7882 }
7883
7884 /* copy the frame itself */
7885 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7886 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7887
Mike Kershaw24a47db2005-08-26 00:41:54 -05007888 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7889
7890 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7891 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007892 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007893
7894 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007895 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7896 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007897 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007898 (1 << IEEE80211_RADIOTAP_RATE) |
7899 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7900 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007901 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007902 (1 << IEEE80211_RADIOTAP_ANTENNA));
7903
7904 /* Zero the flags, we'll add to them as we go */
7905 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007906 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7907 frame->parent_tsf[2] << 16 |
7908 frame->parent_tsf[1] << 8 |
7909 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007910
7911 /* Convert signal to DBM */
7912 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007913 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007914
7915 /* Convert the channel data and set the flags */
7916 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7917 if (received_channel > 14) { /* 802.11a */
7918 ipw_rt->rt_chbitmask =
7919 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7920 } else if (antennaAndPhy & 32) { /* 802.11b */
7921 ipw_rt->rt_chbitmask =
7922 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7923 } else { /* 802.11g */
7924 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007925 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007926 }
7927
7928 /* set the rate in multiples of 500k/s */
7929 switch (pktrate) {
7930 case IPW_TX_RATE_1MB:
7931 ipw_rt->rt_rate = 2;
7932 break;
7933 case IPW_TX_RATE_2MB:
7934 ipw_rt->rt_rate = 4;
7935 break;
7936 case IPW_TX_RATE_5MB:
7937 ipw_rt->rt_rate = 10;
7938 break;
7939 case IPW_TX_RATE_6MB:
7940 ipw_rt->rt_rate = 12;
7941 break;
7942 case IPW_TX_RATE_9MB:
7943 ipw_rt->rt_rate = 18;
7944 break;
7945 case IPW_TX_RATE_11MB:
7946 ipw_rt->rt_rate = 22;
7947 break;
7948 case IPW_TX_RATE_12MB:
7949 ipw_rt->rt_rate = 24;
7950 break;
7951 case IPW_TX_RATE_18MB:
7952 ipw_rt->rt_rate = 36;
7953 break;
7954 case IPW_TX_RATE_24MB:
7955 ipw_rt->rt_rate = 48;
7956 break;
7957 case IPW_TX_RATE_36MB:
7958 ipw_rt->rt_rate = 72;
7959 break;
7960 case IPW_TX_RATE_48MB:
7961 ipw_rt->rt_rate = 96;
7962 break;
7963 case IPW_TX_RATE_54MB:
7964 ipw_rt->rt_rate = 108;
7965 break;
7966 default:
7967 ipw_rt->rt_rate = 0;
7968 break;
7969 }
7970
7971 /* antenna number */
7972 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7973
7974 /* set the preamble flag if we have it */
7975 if ((antennaAndPhy & 64))
7976 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7977
7978 /* Set the size of the skb to the size of the frame */
7979 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007980
7981 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7982
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007983 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007984 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007985 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007986 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007987 /* no LED during capture */
7988 }
7989}
7990#endif
7991
Zhu Yid685b8c2006-04-13 17:20:27 +08007992#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007993#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007994 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7995 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7996
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007997#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007998 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7999
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008000#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008001 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
8002
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008003#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008004 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8005
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008006#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008007 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8008
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008009#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008010 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8011
8012static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8013 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008014 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008015{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008016 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008017 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8018 struct ipw_rx_frame *frame = &pkt->u.frame;
8019 struct ipw_rt_hdr *ipw_rt;
8020
8021 /* First cache any information we need before we overwrite
8022 * the information provided in the skb from the hardware */
8023 struct ieee80211_hdr *hdr;
8024 u16 channel = frame->received_channel;
8025 u8 phy_flags = frame->antennaAndPhy;
8026 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008027 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008028 u8 rate = frame->rate;
8029 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008030 struct sk_buff *skb;
8031 int hdr_only = 0;
8032 u16 filter = priv->prom_priv->filter;
8033
8034 /* If the filter is set to not include Rx frames then return */
8035 if (filter & IPW_PROM_NO_RX)
8036 return;
8037
Zhu Yid685b8c2006-04-13 17:20:27 +08008038 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008039 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008040
8041 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008042 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008043 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8044 return;
8045 }
8046
8047 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008048 if (unlikely(!netif_running(dev))) {
8049 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008050 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8051 return;
8052 }
8053
8054 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8055 * that now */
8056 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8057 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008058 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008059 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8060 return;
8061 }
8062
8063 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008064 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008065 if (filter & IPW_PROM_NO_MGMT)
8066 return;
8067 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8068 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008069 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008070 if (filter & IPW_PROM_NO_CTL)
8071 return;
8072 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8073 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008074 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008075 if (filter & IPW_PROM_NO_DATA)
8076 return;
8077 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8078 hdr_only = 1;
8079 }
8080
8081 /* Copy the SKB since this is for the promiscuous side */
8082 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8083 if (skb == NULL) {
8084 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8085 return;
8086 }
8087
8088 /* copy the frame data to write after where the radiotap header goes */
8089 ipw_rt = (void *)skb->data;
8090
8091 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008092 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008093
8094 memcpy(ipw_rt->payload, hdr, len);
8095
Zhu Yid685b8c2006-04-13 17:20:27 +08008096 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8097 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008098 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008099
8100 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008101 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008102
8103 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008104 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8105 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008106 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008107 (1 << IEEE80211_RADIOTAP_RATE) |
8108 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8109 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8110 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8111 (1 << IEEE80211_RADIOTAP_ANTENNA));
8112
8113 /* Zero the flags, we'll add to them as we go */
8114 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008115 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8116 frame->parent_tsf[2] << 16 |
8117 frame->parent_tsf[1] << 8 |
8118 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008119
8120 /* Convert to DBM */
8121 ipw_rt->rt_dbmsignal = signal;
8122 ipw_rt->rt_dbmnoise = noise;
8123
8124 /* Convert the channel data and set the flags */
8125 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8126 if (channel > 14) { /* 802.11a */
8127 ipw_rt->rt_chbitmask =
8128 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8129 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8130 ipw_rt->rt_chbitmask =
8131 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8132 } else { /* 802.11g */
8133 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008134 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008135 }
8136
8137 /* set the rate in multiples of 500k/s */
8138 switch (rate) {
8139 case IPW_TX_RATE_1MB:
8140 ipw_rt->rt_rate = 2;
8141 break;
8142 case IPW_TX_RATE_2MB:
8143 ipw_rt->rt_rate = 4;
8144 break;
8145 case IPW_TX_RATE_5MB:
8146 ipw_rt->rt_rate = 10;
8147 break;
8148 case IPW_TX_RATE_6MB:
8149 ipw_rt->rt_rate = 12;
8150 break;
8151 case IPW_TX_RATE_9MB:
8152 ipw_rt->rt_rate = 18;
8153 break;
8154 case IPW_TX_RATE_11MB:
8155 ipw_rt->rt_rate = 22;
8156 break;
8157 case IPW_TX_RATE_12MB:
8158 ipw_rt->rt_rate = 24;
8159 break;
8160 case IPW_TX_RATE_18MB:
8161 ipw_rt->rt_rate = 36;
8162 break;
8163 case IPW_TX_RATE_24MB:
8164 ipw_rt->rt_rate = 48;
8165 break;
8166 case IPW_TX_RATE_36MB:
8167 ipw_rt->rt_rate = 72;
8168 break;
8169 case IPW_TX_RATE_48MB:
8170 ipw_rt->rt_rate = 96;
8171 break;
8172 case IPW_TX_RATE_54MB:
8173 ipw_rt->rt_rate = 108;
8174 break;
8175 default:
8176 ipw_rt->rt_rate = 0;
8177 break;
8178 }
8179
8180 /* antenna number */
8181 ipw_rt->rt_antenna = (phy_flags & 3);
8182
8183 /* set the preamble flag if we have it */
8184 if (phy_flags & (1 << 6))
8185 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8186
8187 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8188
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008189 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008190 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008191 dev_kfree_skb_any(skb);
8192 }
8193}
8194#endif
8195
Arjan van de Ven858119e2006-01-14 13:20:43 -08008196static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008197 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008198{
8199 /* Filter incoming packets to determine if they are targetted toward
8200 * this network, discarding packets coming from ourselves */
8201 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008202 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008203 /* packets from our adapter are dropped (echo) */
8204 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8205 return 0;
8206
Peter Jones90700fd2005-08-26 16:51:06 -05008207 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008208 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008209 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008210
8211 /* packets to our adapter go through */
8212 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8213 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008214
Peter Jones90700fd2005-08-26 16:51:06 -05008215 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008216 /* packets from our adapter are dropped (echo) */
8217 if (!memcmp(header->addr3, 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 BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008221 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008222 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8223
8224 /* packets to our adapter go through */
8225 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8226 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008227 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008228
James Ketrenosea2b26e2005-08-24 21:25:16 -05008229 return 1;
8230}
8231
James Ketrenosafbf30a2005-08-25 00:05:33 -05008232#define IPW_PACKET_RETRY_TIME HZ
8233
Arjan van de Ven858119e2006-01-14 13:20:43 -08008234static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008235 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008236{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008237 u16 sc = le16_to_cpu(header->seq_ctl);
8238 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8239 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8240 u16 *last_seq, *last_frag;
8241 unsigned long *last_time;
8242
8243 switch (priv->ieee->iw_mode) {
8244 case IW_MODE_ADHOC:
8245 {
8246 struct list_head *p;
8247 struct ipw_ibss_seq *entry = NULL;
8248 u8 *mac = header->addr2;
8249 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8250
8251 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8252 entry =
8253 list_entry(p, struct ipw_ibss_seq, list);
8254 if (!memcmp(entry->mac, mac, ETH_ALEN))
8255 break;
8256 }
8257 if (p == &priv->ibss_mac_hash[index]) {
8258 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8259 if (!entry) {
8260 IPW_ERROR
8261 ("Cannot malloc new mac entry\n");
8262 return 0;
8263 }
8264 memcpy(entry->mac, mac, ETH_ALEN);
8265 entry->seq_num = seq;
8266 entry->frag_num = frag;
8267 entry->packet_time = jiffies;
8268 list_add(&entry->list,
8269 &priv->ibss_mac_hash[index]);
8270 return 0;
8271 }
8272 last_seq = &entry->seq_num;
8273 last_frag = &entry->frag_num;
8274 last_time = &entry->packet_time;
8275 break;
8276 }
8277 case IW_MODE_INFRA:
8278 last_seq = &priv->last_seq_num;
8279 last_frag = &priv->last_frag_num;
8280 last_time = &priv->last_packet_time;
8281 break;
8282 default:
8283 return 0;
8284 }
8285 if ((*last_seq == seq) &&
8286 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8287 if (*last_frag == frag)
8288 goto drop;
8289 if (*last_frag + 1 != frag)
8290 /* out-of-order fragment */
8291 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008292 } else
8293 *last_seq = seq;
8294
Zhu Yif57ce7c2005-07-13 12:22:15 -05008295 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008296 *last_time = jiffies;
8297 return 0;
8298
8299 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008300 /* Comment this line now since we observed the card receives
8301 * duplicate packets but the FCTL_RETRY bit is not set in the
8302 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008303 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008304 return 1;
8305}
8306
James Ketrenosb095c382005-08-24 22:04:42 -05008307static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8308 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008309 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008310{
8311 struct sk_buff *skb = rxb->skb;
8312 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008313 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008314 (skb->data + IPW_RX_FRAME_SIZE);
8315
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008316 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008317
8318 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8319 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8320 IEEE80211_STYPE_PROBE_RESP) ||
8321 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8322 IEEE80211_STYPE_BEACON))) {
8323 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8324 ipw_add_station(priv, header->addr2);
8325 }
8326
8327 if (priv->config & CFG_NET_STATS) {
8328 IPW_DEBUG_HC("sending stat packet\n");
8329
8330 /* Set the size of the skb to the size of the full
8331 * ipw header and 802.11 frame */
8332 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8333 IPW_RX_FRAME_SIZE);
8334
8335 /* Advance past the ipw packet header to the 802.11 frame */
8336 skb_pull(skb, IPW_RX_FRAME_SIZE);
8337
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008338 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008339 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8340
8341 skb->dev = priv->ieee->dev;
8342
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008343 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008344 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008345
8346 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008347 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008348 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8349 netif_rx(skb);
8350 rxb->skb = NULL;
8351 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008352}
8353
James Ketrenos43f66a62005-03-25 12:31:53 -06008354/*
8355 * Main entry function for recieving a packet with 80211 headers. This
8356 * should be called when ever the FW has notified us that there is a new
8357 * skb in the recieve queue.
8358 */
8359static void ipw_rx(struct ipw_priv *priv)
8360{
8361 struct ipw_rx_mem_buffer *rxb;
8362 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008363 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008364 u32 r, w, i;
8365 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008366 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008367
James Ketrenosb095c382005-08-24 22:04:42 -05008368 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8369 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008370 i = priv->rxq->read;
8371
8372 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8373 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008374
8375 while (i != r) {
8376 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008377 if (unlikely(rxb == NULL)) {
8378 printk(KERN_CRIT "Queue not allocated!\n");
8379 break;
8380 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008381 priv->rxq->queue[i] = NULL;
8382
8383 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008384 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008385 PCI_DMA_FROMDEVICE);
8386
8387 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8388 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8389 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008390 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008391
8392 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008393 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008394 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008395 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008396 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008397 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008398 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008399 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008400 .noise =
8401 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008402 .rate = pkt->u.frame.rate,
8403 .mac_time = jiffies,
8404 .received_channel =
8405 pkt->u.frame.received_channel,
8406 .freq =
8407 (pkt->u.frame.
8408 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008409 LIBIPW_24GHZ_BAND :
8410 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008411 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008412 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008413
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008414 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008415 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008416 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008417 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008418 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008419 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008420 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008421 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008422
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008423 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008424
Zhu Yid685b8c2006-04-13 17:20:27 +08008425#ifdef CONFIG_IPW2200_PROMISCUOUS
8426 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8427 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8428#endif
8429
James Ketrenosb095c382005-08-24 22:04:42 -05008430#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008431 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008432#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008433
8434 ipw_handle_data_packet_monitor(priv,
8435 rxb,
8436 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008437#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008438 ipw_handle_data_packet(priv, rxb,
8439 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008440#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008441 break;
8442 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008443#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008444
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008445 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008446 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008447 data +
8448 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008449 /* TODO: Check Ad-Hoc dest/source and make sure
8450 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008451 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008452 * frame control of the packet and disregard
8453 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008454
James Ketrenosea2b26e2005-08-24 21:25:16 -05008455 network_packet =
8456 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008457 if (network_packet && priv->assoc_network) {
8458 priv->assoc_network->stats.rssi =
8459 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008460 priv->exp_avg_rssi =
8461 exponential_average(priv->exp_avg_rssi,
8462 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008463 }
8464
8465 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008466 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008467
James Ketrenosa613bff2005-08-24 21:43:11 -05008468 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008469 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008470 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008471 IPW_DEBUG_DROP
8472 ("Received packet is too small. "
8473 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008474 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008475 priv->wstats.discard.misc++;
8476 break;
8477 }
8478
James Ketrenosa613bff2005-08-24 21:43:11 -05008479 switch (WLAN_FC_GET_TYPE
8480 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008481
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008482 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008483 ipw_handle_mgmt_packet(priv, rxb,
8484 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008485 break;
8486
8487 case IEEE80211_FTYPE_CTL:
8488 break;
8489
8490 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008491 if (unlikely(!network_packet ||
8492 is_duplicate_packet(priv,
8493 header)))
8494 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008495 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008496 "%pM, "
8497 "%pM, "
8498 "%pM\n",
8499 header->addr1,
8500 header->addr2,
8501 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008502 break;
8503 }
8504
8505 ipw_handle_data_packet(priv, rxb,
8506 &stats);
8507
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008508 break;
8509 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008510 break;
8511 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008512
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008513 case RX_HOST_NOTIFICATION_TYPE:{
8514 IPW_DEBUG_RX
8515 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008516 pkt->u.notification.subtype,
8517 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008518 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008519 ipw_rx_notification(priv, &pkt->u.notification);
8520 break;
8521 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008522
8523 default:
8524 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8525 pkt->header.message_type);
8526 break;
8527 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008528
8529 /* For now we just don't re-use anything. We can tweak this
8530 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008531 * fail to Rx correctly */
8532 if (rxb->skb != NULL) {
8533 dev_kfree_skb_any(rxb->skb);
8534 rxb->skb = NULL;
8535 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008536
James Ketrenos43f66a62005-03-25 12:31:53 -06008537 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008538 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008539 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008540
James Ketrenos43f66a62005-03-25 12:31:53 -06008541 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008542
8543 /* If there are a lot of unsued frames, restock the Rx queue
8544 * so the ucode won't assert */
8545 if (fill_rx) {
8546 priv->rxq->read = i;
8547 ipw_rx_queue_replenish(priv);
8548 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008549 }
8550
8551 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008552 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008553 ipw_rx_queue_restock(priv);
8554}
8555
James Ketrenosafbf30a2005-08-25 00:05:33 -05008556#define DEFAULT_RTS_THRESHOLD 2304U
8557#define MIN_RTS_THRESHOLD 1U
8558#define MAX_RTS_THRESHOLD 2304U
8559#define DEFAULT_BEACON_INTERVAL 100U
8560#define DEFAULT_SHORT_RETRY_LIMIT 7U
8561#define DEFAULT_LONG_RETRY_LIMIT 4U
8562
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008563/**
8564 * ipw_sw_reset
8565 * @option: options to control different reset behaviour
8566 * 0 = reset everything except the 'disable' module_param
8567 * 1 = reset everything and print out driver info (for probe only)
8568 * 2 = reset everything
8569 */
8570static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008571{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008572 int band, modulation;
8573 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008574
James Ketrenosafbf30a2005-08-25 00:05:33 -05008575 /* Initialize module parameter values here */
8576 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008577
James Ketrenosafbf30a2005-08-25 00:05:33 -05008578 /* We default to disabling the LED code as right now it causes
8579 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008580 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008581 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008582
James Ketrenosafbf30a2005-08-25 00:05:33 -05008583 if (associate)
8584 priv->config |= CFG_ASSOCIATE;
8585 else
8586 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008587
James Ketrenosafbf30a2005-08-25 00:05:33 -05008588 if (auto_create)
8589 priv->config |= CFG_ADHOC_CREATE;
8590 else
8591 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8592
Zhu Yi17ed0812006-01-24 16:36:31 +08008593 priv->config &= ~CFG_STATIC_ESSID;
8594 priv->essid_len = 0;
8595 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8596
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008597 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008598 priv->status |= STATUS_RF_KILL_SW;
8599 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008600 }
8601
Reinette Chatre21f8a732009-08-18 10:25:05 -07008602 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008603 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008604 priv->channel = default_channel;
8605 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008606 /* TODO: Validate that provided channel is in range */
8607 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008608#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008609 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8610 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008611#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008612
Reinette Chatre21f8a732009-08-18 10:25:05 -07008613 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008614 case 1:
8615 priv->ieee->iw_mode = IW_MODE_ADHOC;
8616 priv->net_dev->type = ARPHRD_ETHER;
8617
8618 break;
8619#ifdef CONFIG_IPW2200_MONITOR
8620 case 2:
8621 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008622#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008623 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8624#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008625 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008626#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008627 break;
8628#endif
8629 default:
8630 case 0:
8631 priv->net_dev->type = ARPHRD_ETHER;
8632 priv->ieee->iw_mode = IW_MODE_INFRA;
8633 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008634 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008635
James Ketrenosafbf30a2005-08-25 00:05:33 -05008636 if (hwcrypto) {
8637 priv->ieee->host_encrypt = 0;
8638 priv->ieee->host_encrypt_msdu = 0;
8639 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008640 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008641 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008642 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008643
Zhu Yie402c932005-08-05 17:20:40 +08008644 /* IPW2200/2915 is abled to do hardware fragmentation. */
8645 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008646
James Ketrenosafbf30a2005-08-25 00:05:33 -05008647 if ((priv->pci_dev->device == 0x4223) ||
8648 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008649 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008650 printk(KERN_INFO DRV_NAME
8651 ": Detected Intel PRO/Wireless 2915ABG Network "
8652 "Connection\n");
8653 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008654 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8655 modulation = LIBIPW_OFDM_MODULATION |
8656 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008657 priv->adapter = IPW_2915ABG;
8658 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008659 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008660 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008661 printk(KERN_INFO DRV_NAME
8662 ": Detected Intel PRO/Wireless 2200BG Network "
8663 "Connection\n");
8664
8665 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008666 band = LIBIPW_24GHZ_BAND;
8667 modulation = LIBIPW_OFDM_MODULATION |
8668 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008669 priv->adapter = IPW_2200BG;
8670 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008671 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008672
James Ketrenosafbf30a2005-08-25 00:05:33 -05008673 priv->ieee->freq_band = band;
8674 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008675
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008676 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008677
James Ketrenosafbf30a2005-08-25 00:05:33 -05008678 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8679 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008680
James Ketrenosafbf30a2005-08-25 00:05:33 -05008681 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8682 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8683 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008684
James Ketrenosafbf30a2005-08-25 00:05:33 -05008685 /* If power management is turned on, default to AC mode */
8686 priv->power_mode = IPW_POWER_AC;
8687 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008688
Zhu Yi0ece35b2005-08-05 17:26:51 +08008689 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008690}
8691
8692/*
8693 * This file defines the Wireless Extension handlers. It does not
8694 * define any methods of hardware manipulation and relies on the
8695 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008696 *
8697 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008698 * function used to poll the hardware vs. making unecessary calls.
8699 *
8700 */
8701
James Ketrenos43f66a62005-03-25 12:31:53 -06008702static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8703{
8704 if (channel == 0) {
8705 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8706 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008707 IPW_DEBUG_ASSOC("Attempting to associate with new "
8708 "parameters.\n");
8709 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008710 return 0;
8711 }
8712
8713 priv->config |= CFG_STATIC_CHANNEL;
8714
8715 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008716 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8717 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008718 return 0;
8719 }
8720
8721 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8722 priv->channel = channel;
8723
James Ketrenosb095c382005-08-24 22:04:42 -05008724#ifdef CONFIG_IPW2200_MONITOR
8725 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008726 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008727 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008728 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008729 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008730 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008731 }
8732
8733 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8734 udelay(10);
8735
8736 if (priv->status & STATUS_SCANNING)
8737 IPW_DEBUG_SCAN("Still scanning...\n");
8738 else
8739 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8740 1000 - i);
8741
8742 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008743 }
James Ketrenosb095c382005-08-24 22:04:42 -05008744#endif /* CONFIG_IPW2200_MONITOR */
8745
James Ketrenosc848d0a2005-08-24 21:56:24 -05008746 /* Network configuration changed -- force [re]association */
8747 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8748 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008749 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008750
8751 return 0;
8752}
8753
Jeff Garzikbf794512005-07-31 13:07:26 -04008754static int ipw_wx_set_freq(struct net_device *dev,
8755 struct iw_request_info *info,
8756 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008757{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008758 struct ipw_priv *priv = libipw_priv(dev);
8759 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008761 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008762 u8 channel, flags;
8763 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008764
James Ketrenosb095c382005-08-24 22:04:42 -05008765 if (fwrq->m == 0) {
8766 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008767 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008768 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008769 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008770 return ret;
8771 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 /* if setting by freq convert to channel */
8773 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008774 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008775 if (channel == 0)
8776 return -EINVAL;
8777 } else
8778 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008779
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008780 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008781 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008782
Liu Hong1fe0adb2005-08-19 09:33:10 -05008783 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008784 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008785 if (i == -1)
8786 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008787
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008788 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008789 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008790 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008791 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8792 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 }
8794 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008795
James Ketrenos43f66a62005-03-25 12:31:53 -06008796 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008797 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008798 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008799 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008800 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008801}
8802
Jeff Garzikbf794512005-07-31 13:07:26 -04008803static int ipw_wx_get_freq(struct net_device *dev,
8804 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008805 union iwreq_data *wrqu, char *extra)
8806{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008807 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008808
8809 wrqu->freq.e = 0;
8810
8811 /* If we are associated, trying to associate, or have a statically
8812 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008813 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008814 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008815 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8816 int i;
8817
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008818 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008819 BUG_ON(i == -1);
8820 wrqu->freq.e = 1;
8821
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008822 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8823 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008824 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8825 break;
8826
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008827 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008828 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8829 break;
8830
8831 default:
8832 BUG();
8833 }
8834 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008835 wrqu->freq.m = 0;
8836
Zhu Yi46441512006-01-24 16:37:59 +08008837 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008838 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8839 return 0;
8840}
8841
Jeff Garzikbf794512005-07-31 13:07:26 -04008842static int ipw_wx_set_mode(struct net_device *dev,
8843 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 union iwreq_data *wrqu, char *extra)
8845{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008846 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008847 int err = 0;
8848
8849 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8850
James Ketrenos43f66a62005-03-25 12:31:53 -06008851 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008852#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008853 case IW_MODE_MONITOR:
8854#endif
8855 case IW_MODE_ADHOC:
8856 case IW_MODE_INFRA:
8857 break;
8858 case IW_MODE_AUTO:
8859 wrqu->mode = IW_MODE_INFRA;
8860 break;
8861 default:
8862 return -EINVAL;
8863 }
James Ketrenosb095c382005-08-24 22:04:42 -05008864 if (wrqu->mode == priv->ieee->iw_mode)
8865 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008866
Zhu Yi46441512006-01-24 16:37:59 +08008867 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008868
8869 ipw_sw_reset(priv, 0);
8870
James Ketrenosb095c382005-08-24 22:04:42 -05008871#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008872 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008873 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008874
8875 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008876#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008877 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8878#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008880#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008881#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008882
Jeff Garzikbf794512005-07-31 13:07:26 -04008883 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008884 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008885 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008886
8887 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008888
James Ketrenosc848d0a2005-08-24 21:56:24 -05008889 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008890 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008891 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008892}
8893
Jeff Garzikbf794512005-07-31 13:07:26 -04008894static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008895 struct iw_request_info *info,
8896 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008897{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008898 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008899 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008900 wrqu->mode = priv->ieee->iw_mode;
8901 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008902 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008903 return 0;
8904}
8905
James Ketrenos43f66a62005-03-25 12:31:53 -06008906/* Values are in microsecond */
8907static const s32 timeout_duration[] = {
8908 350000,
8909 250000,
8910 75000,
8911 37000,
8912 25000,
8913};
8914
8915static const s32 period_duration[] = {
8916 400000,
8917 700000,
8918 1000000,
8919 1000000,
8920 1000000
8921};
8922
Jeff Garzikbf794512005-07-31 13:07:26 -04008923static int ipw_wx_get_range(struct net_device *dev,
8924 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008925 union iwreq_data *wrqu, char *extra)
8926{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008927 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008928 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008929 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008930 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008931
8932 wrqu->data.length = sizeof(*range);
8933 memset(range, 0, sizeof(*range));
8934
8935 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008936 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008937
8938 range->max_qual.qual = 100;
8939 /* TODO: Find real max RSSI and stick here */
8940 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008941 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008942 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008943
8944 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008945 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008946 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008947 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008948 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008949 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008950 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008951
Jeff Garzikbf794512005-07-31 13:07:26 -04008952 for (i = 0; i < range->num_bitrates; i++)
8953 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008954 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008955
James Ketrenos43f66a62005-03-25 12:31:53 -06008956 range->max_rts = DEFAULT_RTS_THRESHOLD;
8957 range->min_frag = MIN_FRAG_THRESHOLD;
8958 range->max_frag = MAX_FRAG_THRESHOLD;
8959
8960 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008961 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008962 range->num_encoding_sizes = 2;
8963 range->max_encoding_tokens = WEP_KEYS;
8964
8965 /* Set the Wireless Extension versions */
8966 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008967 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008968
James Ketrenosb095c382005-08-24 22:04:42 -05008969 i = 0;
8970 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008971 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8972 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008973 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008974 continue;
8975
James Ketrenosb095c382005-08-24 22:04:42 -05008976 range->freq[i].i = geo->bg[j].channel;
8977 range->freq[i].m = geo->bg[j].freq * 100000;
8978 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008979 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008980 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008981 }
James Ketrenosb095c382005-08-24 22:04:42 -05008982
8983 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008984 for (j = 0; j < geo->a_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->a[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->a[j].channel;
8990 range->freq[i].m = geo->a[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 }
8994 }
8995
8996 range->num_channels = i;
8997 range->num_frequency = i;
8998
Zhu Yi46441512006-01-24 16:37:59 +08008999 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009000
9001 /* Event capability (kernel + driver) */
9002 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
9003 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08009004 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9005 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009006 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009007
Dan Williamsf1b50862006-01-30 13:58:56 -05009008 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9009 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9010
Dan Williams374fdfb2007-12-12 10:25:07 -05009011 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9012
James Ketrenos43f66a62005-03-25 12:31:53 -06009013 IPW_DEBUG_WX("GET Range\n");
9014 return 0;
9015}
9016
Jeff Garzikbf794512005-07-31 13:07:26 -04009017static int ipw_wx_set_wap(struct net_device *dev,
9018 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009019 union iwreq_data *wrqu, char *extra)
9020{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009021 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009022
9023 static const unsigned char any[] = {
9024 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9025 };
9026 static const unsigned char off[] = {
9027 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9028 };
9029
Jeff Garzikbf794512005-07-31 13:07:26 -04009030 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009031 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009032 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009033 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9034 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9035 /* we disable mandatory BSSID association */
9036 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9037 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009038 IPW_DEBUG_ASSOC("Attempting to associate with new "
9039 "parameters.\n");
9040 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009041 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 return 0;
9043 }
9044
9045 priv->config |= CFG_STATIC_BSSID;
9046 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9047 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009048 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009049 return 0;
9050 }
9051
Johannes Berge1749612008-10-27 15:59:26 -07009052 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9053 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009054
9055 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9056
James Ketrenosc848d0a2005-08-24 21:56:24 -05009057 /* Network configuration changed -- force [re]association */
9058 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9059 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009060 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009061
Zhu Yi46441512006-01-24 16:37:59 +08009062 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009063 return 0;
9064}
9065
Jeff Garzikbf794512005-07-31 13:07:26 -04009066static int ipw_wx_get_wap(struct net_device *dev,
9067 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009068 union iwreq_data *wrqu, char *extra)
9069{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009070 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009071
James Ketrenos43f66a62005-03-25 12:31:53 -06009072 /* If we are associated, trying to associate, or have a statically
9073 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009074 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009075 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009076 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9077 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009078 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009079 } else
9080 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9081
Johannes Berge1749612008-10-27 15:59:26 -07009082 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9083 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009084 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009085 return 0;
9086}
9087
Jeff Garzikbf794512005-07-31 13:07:26 -04009088static int ipw_wx_set_essid(struct net_device *dev,
9089 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009090 union iwreq_data *wrqu, char *extra)
9091{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009092 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009093 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009094 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009095
Zhu Yiab644b02006-08-21 11:37:13 +08009096 mutex_lock(&priv->mutex);
9097
9098 if (!wrqu->essid.flags)
9099 {
9100 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9101 ipw_disassociate(priv);
9102 priv->config &= ~CFG_STATIC_ESSID;
9103 ipw_associate(priv);
9104 mutex_unlock(&priv->mutex);
9105 return 0;
9106 }
9107
Zhu Yia9f0d422006-08-21 11:37:26 +08009108 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009109
9110 priv->config |= CFG_STATIC_ESSID;
9111
Zhu Yia9f0d422006-08-21 11:37:26 +08009112 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9113 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009114 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009115 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009116 return 0;
9117 }
9118
John W. Linville9387b7c2008-09-30 20:59:05 -04009119 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9120 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009121
9122 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009123 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009124
James Ketrenosc848d0a2005-08-24 21:56:24 -05009125 /* Network configuration changed -- force [re]association */
9126 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9127 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009129
Zhu Yi46441512006-01-24 16:37:59 +08009130 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009131 return 0;
9132}
9133
Jeff Garzikbf794512005-07-31 13:07:26 -04009134static int ipw_wx_get_essid(struct net_device *dev,
9135 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 union iwreq_data *wrqu, char *extra)
9137{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009138 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009139 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009140
9141 /* If we are associated, trying to associate, or have a statically
9142 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009143 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009145 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9146 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009147 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009148 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009149 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009150 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009151 } else {
9152 IPW_DEBUG_WX("Getting essid: ANY\n");
9153 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009154 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009155 }
Zhu Yi46441512006-01-24 16:37:59 +08009156 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009157 return 0;
9158}
9159
Jeff Garzikbf794512005-07-31 13:07:26 -04009160static int ipw_wx_set_nick(struct net_device *dev,
9161 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009162 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009163{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009164 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009165
9166 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9167 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9168 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009169 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009170 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009171 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009172 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009173 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009174 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009175 return 0;
9176
9177}
9178
Jeff Garzikbf794512005-07-31 13:07:26 -04009179static int ipw_wx_get_nick(struct net_device *dev,
9180 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009181 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009182{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009183 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009185 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009186 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009187 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009188 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009189 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009190 return 0;
9191}
9192
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009193static int ipw_wx_set_sens(struct net_device *dev,
9194 struct iw_request_info *info,
9195 union iwreq_data *wrqu, char *extra)
9196{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009197 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009198 int err = 0;
9199
9200 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9201 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9202 mutex_lock(&priv->mutex);
9203
9204 if (wrqu->sens.fixed == 0)
9205 {
9206 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9207 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9208 goto out;
9209 }
9210 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9211 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9212 err = -EINVAL;
9213 goto out;
9214 }
9215
9216 priv->roaming_threshold = wrqu->sens.value;
9217 priv->disassociate_threshold = 3*wrqu->sens.value;
9218 out:
9219 mutex_unlock(&priv->mutex);
9220 return err;
9221}
9222
9223static int ipw_wx_get_sens(struct net_device *dev,
9224 struct iw_request_info *info,
9225 union iwreq_data *wrqu, char *extra)
9226{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009227 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009228 mutex_lock(&priv->mutex);
9229 wrqu->sens.fixed = 1;
9230 wrqu->sens.value = priv->roaming_threshold;
9231 mutex_unlock(&priv->mutex);
9232
9233 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9234 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9235
9236 return 0;
9237}
9238
James Ketrenos43f66a62005-03-25 12:31:53 -06009239static int ipw_wx_set_rate(struct net_device *dev,
9240 struct iw_request_info *info,
9241 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009242{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009243 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009244 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009245 u32 target_rate = wrqu->bitrate.value;
9246 u32 fixed, mask;
9247
9248 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9249 /* value = X, fixed = 1 means only rate X */
9250 /* value = X, fixed = 0 means all rates lower equal X */
9251
9252 if (target_rate == -1) {
9253 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009254 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009255 /* Now we should reassociate */
9256 goto apply;
9257 }
9258
9259 mask = 0;
9260 fixed = wrqu->bitrate.fixed;
9261
9262 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009263 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009264 if (target_rate == 1000000)
9265 goto apply;
9266
9267 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009268 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009269 if (target_rate == 2000000)
9270 goto apply;
9271
9272 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009273 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009274 if (target_rate == 5500000)
9275 goto apply;
9276
9277 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009278 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009279 if (target_rate == 6000000)
9280 goto apply;
9281
9282 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009283 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009284 if (target_rate == 9000000)
9285 goto apply;
9286
9287 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009288 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009289 if (target_rate == 11000000)
9290 goto apply;
9291
9292 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009293 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009294 if (target_rate == 12000000)
9295 goto apply;
9296
9297 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009298 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009299 if (target_rate == 18000000)
9300 goto apply;
9301
9302 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009303 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009304 if (target_rate == 24000000)
9305 goto apply;
9306
9307 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009308 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009309 if (target_rate == 36000000)
9310 goto apply;
9311
9312 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009313 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009314 if (target_rate == 48000000)
9315 goto apply;
9316
9317 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009318 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009319 if (target_rate == 54000000)
9320 goto apply;
9321
9322 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9323 return -EINVAL;
9324
9325 apply:
9326 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9327 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009328 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009329 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009330 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009331 ipw_set_fixed_rate(priv, priv->ieee->mode);
9332 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009333 priv->config |= CFG_FIXED_RATE;
9334
James Ketrenosc848d0a2005-08-24 21:56:24 -05009335 if (priv->rates_mask == mask) {
9336 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009337 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009338 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009339 }
9340
James Ketrenosc848d0a2005-08-24 21:56:24 -05009341 priv->rates_mask = mask;
9342
9343 /* Network configuration changed -- force [re]association */
9344 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9345 if (!ipw_disassociate(priv))
9346 ipw_associate(priv);
9347
Zhu Yi46441512006-01-24 16:37:59 +08009348 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009349 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009350}
9351
Jeff Garzikbf794512005-07-31 13:07:26 -04009352static int ipw_wx_get_rate(struct net_device *dev,
9353 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009354 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009355{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009356 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009357 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009359 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009360 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9362 return 0;
9363}
9364
Jeff Garzikbf794512005-07-31 13:07:26 -04009365static int ipw_wx_set_rts(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);
Zhu Yiea8862d2007-01-11 17:32:54 +08009371 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009372 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9373 else {
9374 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009375 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009376 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009377 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009378 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009379 priv->rts_threshold = wrqu->rts.value;
9380 }
9381
9382 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009383 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009384 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9385 return 0;
9386}
9387
Jeff Garzikbf794512005-07-31 13:07:26 -04009388static int ipw_wx_get_rts(struct net_device *dev,
9389 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009390 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009391{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009392 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009393 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009394 wrqu->rts.value = priv->rts_threshold;
9395 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009396 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009397 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009398 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9399 return 0;
9400}
9401
Jeff Garzikbf794512005-07-31 13:07:26 -04009402static int ipw_wx_set_txpow(struct net_device *dev,
9403 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009404 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009405{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009406 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009407 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009408
Zhu Yi46441512006-01-24 16:37:59 +08009409 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009410 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009411 err = -EINPROGRESS;
9412 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009413 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009414
James Ketrenosb095c382005-08-24 22:04:42 -05009415 if (!wrqu->power.fixed)
9416 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009417
James Ketrenosc848d0a2005-08-24 21:56:24 -05009418 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009419 err = -EINVAL;
9420 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009421 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009422
James Ketrenosb095c382005-08-24 22:04:42 -05009423 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009424 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009425 err = -EINVAL;
9426 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009427 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009428
9429 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009430 err = ipw_set_tx_power(priv);
9431 out:
Zhu Yi46441512006-01-24 16:37:59 +08009432 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009433 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009434}
9435
Jeff Garzikbf794512005-07-31 13:07:26 -04009436static int ipw_wx_get_txpow(struct net_device *dev,
9437 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009438 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009439{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009440 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009441 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009442 wrqu->power.value = priv->tx_power;
9443 wrqu->power.fixed = 1;
9444 wrqu->power.flags = IW_TXPOW_DBM;
9445 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009446 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009447
Jeff Garzikbf794512005-07-31 13:07:26 -04009448 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009449 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009450
9451 return 0;
9452}
9453
Jeff Garzikbf794512005-07-31 13:07:26 -04009454static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009455 struct iw_request_info *info,
9456 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009457{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009458 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009459 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009460 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009461 priv->ieee->fts = DEFAULT_FTS;
9462 else {
9463 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009464 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009465 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009466 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009467 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009468
James Ketrenos43f66a62005-03-25 12:31:53 -06009469 priv->ieee->fts = wrqu->frag.value & ~0x1;
9470 }
9471
9472 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009473 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009474 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9475 return 0;
9476}
9477
Jeff Garzikbf794512005-07-31 13:07:26 -04009478static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009479 struct iw_request_info *info,
9480 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009481{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009482 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009483 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009484 wrqu->frag.value = priv->ieee->fts;
9485 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009486 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009487 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009488 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9489
9490 return 0;
9491}
9492
Jeff Garzikbf794512005-07-31 13:07:26 -04009493static int ipw_wx_set_retry(struct net_device *dev,
9494 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009495 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009496{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009497 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009498
9499 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9500 return -EINVAL;
9501
9502 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9503 return 0;
9504
Zhu Yid5f7ac22006-08-21 11:38:17 +08009505 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009506 return -EINVAL;
9507
Zhu Yi46441512006-01-24 16:37:59 +08009508 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009509 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009510 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009511 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009512 priv->long_retry_limit = (u8) wrqu->retry.value;
9513 else {
9514 priv->short_retry_limit = (u8) wrqu->retry.value;
9515 priv->long_retry_limit = (u8) wrqu->retry.value;
9516 }
9517
9518 ipw_send_retry_limit(priv, priv->short_retry_limit,
9519 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009520 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009521 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9522 priv->short_retry_limit, priv->long_retry_limit);
9523 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009524}
9525
Jeff Garzikbf794512005-07-31 13:07:26 -04009526static int ipw_wx_get_retry(struct net_device *dev,
9527 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009528 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009529{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009530 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009531
Zhu Yi46441512006-01-24 16:37:59 +08009532 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009533 wrqu->retry.disabled = 0;
9534
9535 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009536 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009537 return -EINVAL;
9538 }
9539
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009540 if (wrqu->retry.flags & IW_RETRY_LONG) {
9541 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009542 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009543 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9544 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009545 wrqu->retry.value = priv->short_retry_limit;
9546 } else {
9547 wrqu->retry.flags = IW_RETRY_LIMIT;
9548 wrqu->retry.value = priv->short_retry_limit;
9549 }
Zhu Yi46441512006-01-24 16:37:59 +08009550 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009551
9552 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9553
9554 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009555}
9556
Jeff Garzikbf794512005-07-31 13:07:26 -04009557static int ipw_wx_set_scan(struct net_device *dev,
9558 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009559 union iwreq_data *wrqu, char *extra)
9560{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009561 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009562 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009563 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009564
Dan Williams0b531672007-10-09 13:55:24 -04009565 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009566
Dan Williams0b531672007-10-09 13:55:24 -04009567 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009568
Zhu Yi094c4d22006-08-21 11:39:03 +08009569 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009570 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009571 int len = min((int)req->essid_len,
9572 (int)sizeof(priv->direct_scan_ssid));
9573 memcpy(priv->direct_scan_ssid, req->essid, len);
9574 priv->direct_scan_ssid_len = len;
9575 work = &priv->request_direct_scan;
9576 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9577 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009578 }
Dan Williamsea177302008-06-02 17:51:23 -04009579 } else {
9580 /* Normal active broadcast scan */
9581 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009582 }
James Ketrenos8935f392005-10-05 15:59:08 -05009583
Dan Williamsea177302008-06-02 17:51:23 -04009584 mutex_unlock(&priv->mutex);
9585
James Ketrenos43f66a62005-03-25 12:31:53 -06009586 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009587
Dan Williamsea177302008-06-02 17:51:23 -04009588 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009589
James Ketrenos43f66a62005-03-25 12:31:53 -06009590 return 0;
9591}
9592
Jeff Garzikbf794512005-07-31 13:07:26 -04009593static int ipw_wx_get_scan(struct net_device *dev,
9594 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009595 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009596{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009597 struct ipw_priv *priv = libipw_priv(dev);
9598 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009599}
9600
Jeff Garzikbf794512005-07-31 13:07:26 -04009601static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009602 struct iw_request_info *info,
9603 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009604{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009605 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009606 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009607 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009608
Zhu Yi46441512006-01-24 16:37:59 +08009609 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009610 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009611
Hong Liucaeff812005-08-05 17:25:50 +08009612 /* In IBSS mode, we need to notify the firmware to update
9613 * the beacon info after we changed the capability. */
9614 if (cap != priv->capability &&
9615 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9616 priv->status & STATUS_ASSOCIATED)
9617 ipw_disassociate(priv);
9618
Zhu Yi46441512006-01-24 16:37:59 +08009619 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009620 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009621}
9622
Jeff Garzikbf794512005-07-31 13:07:26 -04009623static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009624 struct iw_request_info *info,
9625 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009626{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009627 struct ipw_priv *priv = libipw_priv(dev);
9628 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009629}
9630
Jeff Garzikbf794512005-07-31 13:07:26 -04009631static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009632 struct iw_request_info *info,
9633 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009634{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009635 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009636 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009637 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009638 if (wrqu->power.disabled) {
9639 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9640 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9641 if (err) {
9642 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009643 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 return err;
9645 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009646 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009647 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009648 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009649 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009650
9651 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009652 case IW_POWER_ON: /* If not specified */
9653 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009654 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009655 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009656 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009657 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9658 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009659 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009660 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009661 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009662
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 /* If the user hasn't specified a power management mode yet, default
9664 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009665 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009666 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009667 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009669
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9671 if (err) {
9672 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009673 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009674 return err;
9675 }
9676
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009677 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009678 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009679 return 0;
9680}
9681
Jeff Garzikbf794512005-07-31 13:07:26 -04009682static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009683 struct iw_request_info *info,
9684 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009685{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009686 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009687 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009688 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009689 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009690 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009691 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009692
Zhu Yi46441512006-01-24 16:37:59 +08009693 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009694 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009695
James Ketrenos43f66a62005-03-25 12:31:53 -06009696 return 0;
9697}
9698
Jeff Garzikbf794512005-07-31 13:07:26 -04009699static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009700 struct iw_request_info *info,
9701 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009702{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009703 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 int mode = *(int *)extra;
9705 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009706
Zhu Yi46441512006-01-24 16:37:59 +08009707 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009708 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009710
Zhu Yi4e157f02007-07-12 16:09:32 +08009711 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009712 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009713 if (err) {
9714 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009715 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009716 return err;
9717 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009718 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009719 }
Zhu Yi46441512006-01-24 16:37:59 +08009720 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009721 return 0;
9722}
9723
9724#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009725static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009726 struct iw_request_info *info,
9727 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009728{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009729 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009730 int level = IPW_POWER_LEVEL(priv->power_mode);
9731 char *p = extra;
9732
9733 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9734
9735 switch (level) {
9736 case IPW_POWER_AC:
9737 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9738 break;
9739 case IPW_POWER_BATTERY:
9740 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9741 break;
9742 default:
9743 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009744 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009745 timeout_duration[level - 1] / 1000,
9746 period_duration[level - 1] / 1000);
9747 }
9748
9749 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009750 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009751
9752 wrqu->data.length = p - extra + 1;
9753
9754 return 0;
9755}
9756
9757static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009758 struct iw_request_info *info,
9759 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009760{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009761 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 int mode = *(int *)extra;
9763 u8 band = 0, modulation = 0;
9764
9765 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009766 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009767 return -EINVAL;
9768 }
Zhu Yi46441512006-01-24 16:37:59 +08009769 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009771 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009772 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009773 band |= LIBIPW_52GHZ_BAND;
9774 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009776 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009777 } else {
9778 if (mode & IEEE_A) {
9779 IPW_WARNING("Attempt to set 2200BG into "
9780 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009781 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 return -EINVAL;
9783 }
9784
James Ketrenosa33a1982005-09-14 14:28:59 -05009785 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009786 }
9787
9788 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009789 band |= LIBIPW_24GHZ_BAND;
9790 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009791 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009792 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009793
James Ketrenos43f66a62005-03-25 12:31:53 -06009794 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009795 band |= LIBIPW_24GHZ_BAND;
9796 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009797 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009798 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009799
9800 priv->ieee->mode = mode;
9801 priv->ieee->freq_band = band;
9802 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009803 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009804
James Ketrenosc848d0a2005-08-24 21:56:24 -05009805 /* Network configuration changed -- force [re]association */
9806 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9807 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009808 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009809 ipw_associate(priv);
9810 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009811
James Ketrenosa613bff2005-08-24 21:43:11 -05009812 /* Update the band LEDs */
9813 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009814
Jeff Garzikbf794512005-07-31 13:07:26 -04009815 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009816 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009817 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009818 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009819 return 0;
9820}
9821
9822static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009823 struct iw_request_info *info,
9824 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009825{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009826 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009827 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009828 switch (priv->ieee->mode) {
9829 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009830 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9831 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009832 case IEEE_B:
9833 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9834 break;
9835 case IEEE_A | IEEE_B:
9836 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9837 break;
9838 case IEEE_G:
9839 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9840 break;
9841 case IEEE_A | IEEE_G:
9842 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9843 break;
9844 case IEEE_B | IEEE_G:
9845 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9846 break;
9847 case IEEE_A | IEEE_B | IEEE_G:
9848 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9849 break;
9850 default:
9851 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009852 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009853 }
9854
James Ketrenos43f66a62005-03-25 12:31:53 -06009855 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9856
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009857 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009858 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009859
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009860 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009861}
9862
James Ketrenosea2b26e2005-08-24 21:25:16 -05009863static int ipw_wx_set_preamble(struct net_device *dev,
9864 struct iw_request_info *info,
9865 union iwreq_data *wrqu, char *extra)
9866{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009867 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009868 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009869 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009870 /* Switching from SHORT -> LONG requires a disassociation */
9871 if (mode == 1) {
9872 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9873 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009874
9875 /* Network configuration changed -- force [re]association */
9876 IPW_DEBUG_ASSOC
9877 ("[re]association triggered due to preamble change.\n");
9878 if (!ipw_disassociate(priv))
9879 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009880 }
9881 goto done;
9882 }
9883
9884 if (mode == 0) {
9885 priv->config &= ~CFG_PREAMBLE_LONG;
9886 goto done;
9887 }
Zhu Yi46441512006-01-24 16:37:59 +08009888 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009889 return -EINVAL;
9890
9891 done:
Zhu Yi46441512006-01-24 16:37:59 +08009892 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009893 return 0;
9894}
9895
9896static int ipw_wx_get_preamble(struct net_device *dev,
9897 struct iw_request_info *info,
9898 union iwreq_data *wrqu, char *extra)
9899{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009900 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009901 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009902 if (priv->config & CFG_PREAMBLE_LONG)
9903 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9904 else
9905 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009906 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009907 return 0;
9908}
9909
James Ketrenosb095c382005-08-24 22:04:42 -05009910#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009911static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009912 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009914{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009915 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009916 int *parms = (int *)extra;
9917 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009918 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009919 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009920 if (enable) {
9921 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009922#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009923 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9924#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009926#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009927 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009928 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009929
James Ketrenos43f66a62005-03-25 12:31:53 -06009930 ipw_set_channel(priv, parms[1]);
9931 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009932 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009933 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009934 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009935 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009936 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009937 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009938 }
Zhu Yi46441512006-01-24 16:37:59 +08009939 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009940 return 0;
9941}
9942
Pavel Machek67fd6b42006-07-11 15:34:05 +02009943#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009944
Jeff Garzikbf794512005-07-31 13:07:26 -04009945static int ipw_wx_reset(struct net_device *dev,
9946 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009947 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009948{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009949 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009950 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009951 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009952 return 0;
9953}
James Ketrenosb095c382005-08-24 22:04:42 -05009954
James Ketrenosb095c382005-08-24 22:04:42 -05009955static int ipw_wx_sw_reset(struct net_device *dev,
9956 struct iw_request_info *info,
9957 union iwreq_data *wrqu, char *extra)
9958{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009959 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009960 union iwreq_data wrqu_sec = {
9961 .encoding = {
9962 .flags = IW_ENCODE_DISABLED,
9963 },
9964 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009965 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009966
9967 IPW_DEBUG_WX("SW_RESET\n");
9968
Zhu Yi46441512006-01-24 16:37:59 +08009969 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009970
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009971 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009972 if (!ret) {
9973 free_firmware();
9974 ipw_adapter_restart(priv);
9975 }
James Ketrenosb095c382005-08-24 22:04:42 -05009976
9977 /* The SW reset bit might have been toggled on by the 'disable'
9978 * module parameter, so take appropriate action */
9979 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9980
Zhu Yi46441512006-01-24 16:37:59 +08009981 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009982 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009983 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009984
9985 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9986 /* Configuration likely changed -- force [re]association */
9987 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9988 "reset.\n");
9989 if (!ipw_disassociate(priv))
9990 ipw_associate(priv);
9991 }
9992
Zhu Yi46441512006-01-24 16:37:59 +08009993 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009994
9995 return 0;
9996}
James Ketrenos43f66a62005-03-25 12:31:53 -06009997
9998/* Rebase the WE IOCTLs to zero for the handler array */
9999#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010000static iw_handler ipw_wx_handlers[] = {
John W. Linvillea3caa992009-08-25 14:12:25 -040010001 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010002 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
10003 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
10004 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
10005 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +080010006 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
10007 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010008 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
10009 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
10010 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
10011 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
10012 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
10013 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
10014 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
10015 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
10016 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
10017 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
10018 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
10019 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
10020 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
10021 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
10022 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
10023 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
10024 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
10025 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10026 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10027 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10028 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10029 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10030 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -050010031 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10032 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10033 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10034 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -050010035 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10036 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10037 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10038 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10039 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10040 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10041 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -060010042};
10043
James Ketrenosb095c382005-08-24 22:04:42 -050010044enum {
10045 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10046 IPW_PRIV_GET_POWER,
10047 IPW_PRIV_SET_MODE,
10048 IPW_PRIV_GET_MODE,
10049 IPW_PRIV_SET_PREAMBLE,
10050 IPW_PRIV_GET_PREAMBLE,
10051 IPW_PRIV_RESET,
10052 IPW_PRIV_SW_RESET,
10053#ifdef CONFIG_IPW2200_MONITOR
10054 IPW_PRIV_SET_MONITOR,
10055#endif
10056};
James Ketrenos43f66a62005-03-25 12:31:53 -060010057
Jeff Garzikbf794512005-07-31 13:07:26 -040010058static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010060 .cmd = IPW_PRIV_SET_POWER,
10061 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10062 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010063 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010064 .cmd = IPW_PRIV_GET_POWER,
10065 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10066 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010067 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010068 .cmd = IPW_PRIV_SET_MODE,
10069 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10070 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010072 .cmd = IPW_PRIV_GET_MODE,
10073 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10074 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010075 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010076 .cmd = IPW_PRIV_SET_PREAMBLE,
10077 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10078 .name = "set_preamble"},
10079 {
10080 .cmd = IPW_PRIV_GET_PREAMBLE,
10081 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10082 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010083 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010084 IPW_PRIV_RESET,
10085 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010086 {
10087 IPW_PRIV_SW_RESET,
10088 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10089#ifdef CONFIG_IPW2200_MONITOR
10090 {
10091 IPW_PRIV_SET_MONITOR,
10092 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10093#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010094};
10095
10096static iw_handler ipw_priv_handler[] = {
10097 ipw_wx_set_powermode,
10098 ipw_wx_get_powermode,
10099 ipw_wx_set_wireless_mode,
10100 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010101 ipw_wx_set_preamble,
10102 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010103 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010104 ipw_wx_sw_reset,
10105#ifdef CONFIG_IPW2200_MONITOR
10106 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010107#endif
10108};
10109
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010110static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010111 .standard = ipw_wx_handlers,
10112 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10113 .num_private = ARRAY_SIZE(ipw_priv_handler),
10114 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10115 .private = ipw_priv_handler,
10116 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010117 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010118};
10119
James Ketrenos43f66a62005-03-25 12:31:53 -060010120/*
10121 * Get wireless statistics.
10122 * Called by /proc/net/wireless
10123 * Also called by SIOCGIWSTATS
10124 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010125static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010126{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010127 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010128 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010129
James Ketrenos43f66a62005-03-25 12:31:53 -060010130 wstats = &priv->wstats;
10131
James Ketrenosea2b26e2005-08-24 21:25:16 -050010132 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010133 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010134 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10135 * and associated; if not associcated, the values are all meaningless
10136 * anyway, so set them all to NULL and INVALID */
10137 if (!(priv->status & STATUS_ASSOCIATED)) {
10138 wstats->miss.beacon = 0;
10139 wstats->discard.retries = 0;
10140 wstats->qual.qual = 0;
10141 wstats->qual.level = 0;
10142 wstats->qual.noise = 0;
10143 wstats->qual.updated = 7;
10144 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010145 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010146 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010147 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010148
10149 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010150 wstats->qual.level = priv->exp_avg_rssi;
10151 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010152 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010153 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010154
10155 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10156 wstats->discard.retries = priv->last_tx_failures;
10157 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010158
James Ketrenos43f66a62005-03-25 12:31:53 -060010159/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10160 goto fail_get_ordinal;
10161 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010162
James Ketrenos43f66a62005-03-25 12:31:53 -060010163 return wstats;
10164}
10165
James Ketrenos43f66a62005-03-25 12:31:53 -060010166/* net device stuff */
10167
Arjan van de Ven858119e2006-01-14 13:20:43 -080010168static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010169{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010170 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010171 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010172 sys_config->answer_broadcast_ssid_probe = 0;
10173 sys_config->accept_all_data_frames = 0;
10174 sys_config->accept_non_directed_frames = 1;
10175 sys_config->exclude_unicast_unencrypted = 0;
10176 sys_config->disable_unicast_decryption = 1;
10177 sys_config->exclude_multicast_unencrypted = 0;
10178 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010179 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10180 antenna = CFG_SYS_ANTENNA_BOTH;
10181 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010182 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010183 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010184 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010185 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010186 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010187 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010188}
10189
10190static int ipw_net_open(struct net_device *dev)
10191{
James Ketrenos43f66a62005-03-25 12:31:53 -060010192 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010193 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010194 return 0;
10195}
10196
10197static int ipw_net_stop(struct net_device *dev)
10198{
10199 IPW_DEBUG_INFO("dev->close\n");
10200 netif_stop_queue(dev);
10201 return 0;
10202}
10203
10204/*
10205todo:
10206
10207modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010208we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010209*/
10210
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010211static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010212 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010213{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010214 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010215 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010216 int i = 0;
10217 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010218#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010219 int tx_id = ipw_get_tx_queue_number(priv, pri);
10220 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10221#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010222 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010223#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010224 struct clx2_queue *q = &txq->q;
10225 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010226 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010227
Zhu Yib8ddafd2008-11-27 13:42:20 +080010228 if (!(priv->status & STATUS_ASSOCIATED))
10229 goto drop;
10230
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010231 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010232 switch (priv->ieee->iw_mode) {
10233 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010234 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010235 id = ipw_find_station(priv, hdr->addr1);
10236 if (id == IPW_INVALID_STATION) {
10237 id = ipw_add_station(priv, hdr->addr1);
10238 if (id == IPW_INVALID_STATION) {
10239 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010240 "invalid cell: %pM\n",
10241 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010242 goto drop;
10243 }
10244 }
10245 break;
10246
10247 case IW_MODE_INFRA:
10248 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010249 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010250 id = 0;
10251 break;
10252 }
10253
10254 tfd = &txq->bd[q->first_empty];
10255 txq->txb[q->first_empty] = txb;
10256 memset(tfd, 0, sizeof(*tfd));
10257 tfd->u.data.station_number = id;
10258
10259 tfd->control_flags.message_type = TX_FRAME_TYPE;
10260 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10261
10262 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010263 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010264
James Ketrenos43f66a62005-03-25 12:31:53 -060010265 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010266 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010267 else
James Ketrenosb095c382005-08-24 22:04:42 -050010268 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010269
James Ketrenosea2b26e2005-08-24 21:25:16 -050010270 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10271 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010272
James Ketrenosc848d0a2005-08-24 21:56:24 -050010273 fc = le16_to_cpu(hdr->frame_ctl);
10274 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010275
10276 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10277
James Ketrenosb095c382005-08-24 22:04:42 -050010278 if (likely(unicast))
10279 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10280
10281 if (txb->encrypted && !priv->ieee->host_encrypt) {
10282 switch (priv->ieee->sec.level) {
10283 case SEC_LEVEL_3:
10284 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010285 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010286 /* XXX: ACK flag must be set for CCMP even if it
10287 * is a multicast/broadcast packet, because CCMP
10288 * group communication encrypted by GTK is
10289 * actually done by the AP. */
10290 if (!unicast)
10291 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10292
10293 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10294 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10295 tfd->u.data.key_index = 0;
10296 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10297 break;
10298 case SEC_LEVEL_2:
10299 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010300 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010301 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10302 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10303 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10304 break;
10305 case SEC_LEVEL_1:
10306 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010307 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010308 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10309 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010310 40)
10311 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10312 else
10313 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10314 break;
10315 case SEC_LEVEL_0:
10316 break;
10317 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010318 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010319 priv->ieee->sec.level);
10320 break;
10321 }
10322 } else
10323 /* No hardware encryption */
10324 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10325
Zhu Yie43e3c12006-04-13 17:20:45 +080010326#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010327 if (fc & IEEE80211_STYPE_QOS_DATA)
10328 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010329#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010330
James Ketrenos43f66a62005-03-25 12:31:53 -060010331 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010332 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10333 txb->nr_frags));
10334 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10335 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10336 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10337 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10338 i, le32_to_cpu(tfd->u.data.num_chunks),
10339 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010340 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010341 i, tfd->u.data.num_chunks,
10342 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010343 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010344 txb->fragments[i]->len - hdr_len);
10345
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010346 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010347 cpu_to_le32(pci_map_single
10348 (priv->pci_dev,
10349 txb->fragments[i]->data + hdr_len,
10350 txb->fragments[i]->len - hdr_len,
10351 PCI_DMA_TODEVICE));
10352 tfd->u.data.chunk_len[i] =
10353 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010354 }
10355
10356 if (i != txb->nr_frags) {
10357 struct sk_buff *skb;
10358 u16 remaining_bytes = 0;
10359 int j;
10360
10361 for (j = i; j < txb->nr_frags; j++)
10362 remaining_bytes += txb->fragments[j]->len - hdr_len;
10363
10364 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10365 remaining_bytes);
10366 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10367 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010368 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010369 for (j = i; j < txb->nr_frags; j++) {
10370 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010371
James Ketrenos43f66a62005-03-25 12:31:53 -060010372 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010373 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010374 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010375 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010376 }
10377 dev_kfree_skb_any(txb->fragments[i]);
10378 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010379 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010380 cpu_to_le32(pci_map_single
10381 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010382 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010383 PCI_DMA_TODEVICE));
10384
Marcin Slusarz5c058632008-02-13 00:06:12 +010010385 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010386 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010387 }
10388
10389 /* kick DMA */
10390 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10391 ipw_write32(priv, q->reg_w, q->first_empty);
10392
Dan Williams943dbef2008-02-14 17:49:41 -050010393 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010394 netif_stop_queue(priv->net_dev);
10395
James Ketrenos227d2dc2005-07-28 16:25:55 -050010396 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010397
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010398 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010399 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010400 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010401 return NETDEV_TX_OK;
10402}
10403
10404static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10405{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010406 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010407#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010408 int tx_id = ipw_get_tx_queue_number(priv, pri);
10409 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10410#else
10411 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010412#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010413
Dan Williams943dbef2008-02-14 17:49:41 -050010414 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010415 return 1;
10416
10417 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010418}
10419
Zhu Yid685b8c2006-04-13 17:20:27 +080010420#ifdef CONFIG_IPW2200_PROMISCUOUS
10421static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010422 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010423{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010424 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010425 struct ieee80211_hdr *hdr;
10426 u8 n;
10427 u16 filter = priv->prom_priv->filter;
10428 int hdr_only = 0;
10429
10430 if (filter & IPW_PROM_NO_TX)
10431 return;
10432
10433 memset(&dummystats, 0, sizeof(dummystats));
10434
10435 /* Filtering of fragment chains is done agains the first fragment */
10436 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010437 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010438 if (filter & IPW_PROM_NO_MGMT)
10439 return;
10440 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10441 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010442 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010443 if (filter & IPW_PROM_NO_CTL)
10444 return;
10445 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10446 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010447 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010448 if (filter & IPW_PROM_NO_DATA)
10449 return;
10450 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10451 hdr_only = 1;
10452 }
10453
10454 for(n=0; n<txb->nr_frags; ++n) {
10455 struct sk_buff *src = txb->fragments[n];
10456 struct sk_buff *dst;
10457 struct ieee80211_radiotap_header *rt_hdr;
10458 int len;
10459
10460 if (hdr_only) {
10461 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010462 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010463 } else
10464 len = src->len;
10465
Johannes Berg007e5dd2008-11-27 23:13:38 +010010466 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10467 if (!dst)
10468 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010469
10470 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10471
10472 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10473 rt_hdr->it_pad = 0;
10474 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010475 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010476
Al Viroe62e1ee2007-12-27 01:36:46 -050010477 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010478 ieee80211chan2mhz(priv->channel));
10479 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010480 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010481 cpu_to_le16(IEEE80211_CHAN_OFDM |
10482 IEEE80211_CHAN_5GHZ);
10483 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010484 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010485 cpu_to_le16(IEEE80211_CHAN_CCK |
10486 IEEE80211_CHAN_2GHZ);
10487 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010488 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010489 cpu_to_le16(IEEE80211_CHAN_OFDM |
10490 IEEE80211_CHAN_2GHZ);
10491
Al Viro743b84d2007-12-27 01:43:16 -050010492 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010493
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010494 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010495
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010496 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010497 dev_kfree_skb_any(dst);
10498 }
10499}
10500#endif
10501
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010502static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10503 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010504{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010505 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010506 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010507 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010508
10509 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010510 spin_lock_irqsave(&priv->lock, flags);
10511
Zhu Yid685b8c2006-04-13 17:20:27 +080010512#ifdef CONFIG_IPW2200_PROMISCUOUS
10513 if (rtap_iface && netif_running(priv->prom_net_dev))
10514 ipw_handle_promiscuous_tx(priv, txb);
10515#endif
10516
James Ketrenos227d2dc2005-07-28 16:25:55 -050010517 ret = ipw_tx_skb(priv, txb, pri);
10518 if (ret == NETDEV_TX_OK)
10519 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010520 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010521
James Ketrenos227d2dc2005-07-28 16:25:55 -050010522 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010523}
10524
James Ketrenos43f66a62005-03-25 12:31:53 -060010525static void ipw_net_set_multicast_list(struct net_device *dev)
10526{
10527
10528}
10529
10530static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10531{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010532 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010533 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010534
James Ketrenos43f66a62005-03-25 12:31:53 -060010535 if (!is_valid_ether_addr(addr->sa_data))
10536 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010537 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010538 priv->config |= CFG_CUSTOM_MAC;
10539 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010540 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10541 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010542 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010543 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010544 return 0;
10545}
10546
Jeff Garzikbf794512005-07-31 13:07:26 -040010547static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010548 struct ethtool_drvinfo *info)
10549{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010550 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010551 char vers[64];
10552 char date[32];
10553 u32 len;
10554
10555 strcpy(info->driver, DRV_NAME);
10556 strcpy(info->version, DRV_VERSION);
10557
10558 len = sizeof(vers);
10559 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10560 len = sizeof(date);
10561 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10562
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010563 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010564 vers, date);
10565 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010566 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010567}
10568
10569static u32 ipw_ethtool_get_link(struct net_device *dev)
10570{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010571 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010572 return (priv->status & STATUS_ASSOCIATED) != 0;
10573}
10574
10575static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10576{
James Ketrenosb095c382005-08-24 22:04:42 -050010577 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010578}
10579
10580static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010581 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010582{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010583 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010584
James Ketrenosb095c382005-08-24 22:04:42 -050010585 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010586 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010587 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010588 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010589 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010590 return 0;
10591}
10592
10593static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010594 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010595{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010596 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010597 int i;
10598
James Ketrenosb095c382005-08-24 22:04:42 -050010599 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010600 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010601 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010602 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010603 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10604 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010605 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010606 return 0;
10607}
10608
Jeff Garzik7282d492006-09-13 14:30:00 -040010609static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010610 .get_link = ipw_ethtool_get_link,
10611 .get_drvinfo = ipw_ethtool_get_drvinfo,
10612 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10613 .get_eeprom = ipw_ethtool_get_eeprom,
10614 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010615};
10616
David Howells7d12e782006-10-05 14:55:46 +010010617static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010618{
10619 struct ipw_priv *priv = data;
10620 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010621
James Ketrenos43f66a62005-03-25 12:31:53 -060010622 if (!priv)
10623 return IRQ_NONE;
10624
Zhu Yi89c318e2006-06-08 22:19:49 -070010625 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010626
10627 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010628 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010629 goto none;
10630 }
10631
James Ketrenosb095c382005-08-24 22:04:42 -050010632 inta = ipw_read32(priv, IPW_INTA_RW);
10633 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010634
James Ketrenos43f66a62005-03-25 12:31:53 -060010635 if (inta == 0xFFFFFFFF) {
10636 /* Hardware disappeared */
10637 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10638 goto none;
10639 }
10640
James Ketrenosb095c382005-08-24 22:04:42 -050010641 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010642 /* Shared interrupt */
10643 goto none;
10644 }
10645
10646 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010647 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010648
James Ketrenos43f66a62005-03-25 12:31:53 -060010649 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010650 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10651 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010652
James Ketrenos43f66a62005-03-25 12:31:53 -060010653 /* Cache INTA value for our tasklet */
10654 priv->isr_inta = inta;
10655
10656 tasklet_schedule(&priv->irq_tasklet);
10657
Zhu Yi89c318e2006-06-08 22:19:49 -070010658 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010659
10660 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010661 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010662 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010663 return IRQ_NONE;
10664}
10665
10666static void ipw_rf_kill(void *adapter)
10667{
10668 struct ipw_priv *priv = adapter;
10669 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010670
James Ketrenos43f66a62005-03-25 12:31:53 -060010671 spin_lock_irqsave(&priv->lock, flags);
10672
10673 if (rf_kill_active(priv)) {
10674 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10675 if (priv->workqueue)
10676 queue_delayed_work(priv->workqueue,
10677 &priv->rf_kill, 2 * HZ);
10678 goto exit_unlock;
10679 }
10680
10681 /* RF Kill is now disabled, so bring the device back up */
10682
10683 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10684 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10685 "device\n");
10686
10687 /* we can not do an adapter restart while inside an irq lock */
10688 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010689 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010690 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10691 "enabled\n");
10692
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010693 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010694 spin_unlock_irqrestore(&priv->lock, flags);
10695}
10696
David Howellsc4028952006-11-22 14:57:56 +000010697static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010698{
David Howellsc4028952006-11-22 14:57:56 +000010699 struct ipw_priv *priv =
10700 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010701 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010702 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010703 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010704}
10705
Adrian Bunka73e22b2006-01-21 01:39:42 +010010706static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010707{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010708 priv->last_seq_num = -1;
10709 priv->last_frag_num = -1;
10710 priv->last_packet_time = 0;
10711
James Ketrenosa613bff2005-08-24 21:43:11 -050010712 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010713
James Ketrenosc848d0a2005-08-24 21:56:24 -050010714 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010715 cancel_delayed_work(&priv->request_direct_scan);
10716 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010717 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010718 ipw_reset_stats(priv);
10719 /* Ensure the rate is updated immediately */
10720 priv->last_rate = ipw_get_current_rate(priv);
10721 ipw_gather_stats(priv);
10722 ipw_led_link_up(priv);
10723 notify_wx_assoc_event(priv);
10724
10725 if (priv->config & CFG_BACKGROUND_SCAN)
10726 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10727}
10728
David Howellsc4028952006-11-22 14:57:56 +000010729static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010730{
David Howellsc4028952006-11-22 14:57:56 +000010731 struct ipw_priv *priv =
10732 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010733 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010734 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010735 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010736}
10737
Adrian Bunka73e22b2006-01-21 01:39:42 +010010738static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010739{
10740 ipw_led_link_down(priv);
10741 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010742 notify_wx_assoc_event(priv);
10743
10744 /* Cancel any queued work ... */
10745 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010746 cancel_delayed_work(&priv->request_direct_scan);
10747 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010748 cancel_delayed_work(&priv->adhoc_check);
10749 cancel_delayed_work(&priv->gather_stats);
10750
10751 ipw_reset_stats(priv);
10752
James Ketrenosafbf30a2005-08-25 00:05:33 -050010753 if (!(priv->status & STATUS_EXIT_PENDING)) {
10754 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010755 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010756 } else
10757 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010758}
10759
David Howellsc4028952006-11-22 14:57:56 +000010760static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010761{
David Howellsc4028952006-11-22 14:57:56 +000010762 struct ipw_priv *priv =
10763 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010764 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010765 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010766 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010767}
10768
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010769static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010770{
10771 int ret = 0;
10772
James Ketrenos43f66a62005-03-25 12:31:53 -060010773 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010774 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010775 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010776
David Howellsc4028952006-11-22 14:57:56 +000010777 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10778 INIT_WORK(&priv->associate, ipw_bg_associate);
10779 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10780 INIT_WORK(&priv->system_config, ipw_system_config);
10781 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10782 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10783 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10784 INIT_WORK(&priv->up, ipw_bg_up);
10785 INIT_WORK(&priv->down, ipw_bg_down);
10786 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010787 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10788 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010789 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010790 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10791 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10792 INIT_WORK(&priv->roam, ipw_bg_roam);
10793 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10794 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10795 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10796 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10797 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10798 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10799 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010800
Zhu Yie43e3c12006-04-13 17:20:45 +080010801#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010802 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010803#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010804
10805 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10806 ipw_irq_tasklet, (unsigned long)priv);
10807
10808 return ret;
10809}
10810
James Ketrenos43f66a62005-03-25 12:31:53 -060010811static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010812 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010813{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010814 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010815 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010816 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010818 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010819 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010820 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010821 priv->ieee->sec.flags &= ~(1 << i);
10822 else {
10823 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010824 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010825 priv->ieee->sec.flags |= (1 << i);
10826 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010827 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010828 } else if (sec->level != SEC_LEVEL_1)
10829 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010830 }
10831
James Ketrenosb095c382005-08-24 22:04:42 -050010832 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010833 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010834 priv->ieee->sec.active_key = sec->active_key;
10835 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010836 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010837 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010838 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010839 } else
10840 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010841
10842 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010843 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10844 priv->ieee->sec.auth_mode = sec->auth_mode;
10845 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010846 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10847 priv->capability |= CAP_SHARED_KEY;
10848 else
10849 priv->capability &= ~CAP_SHARED_KEY;
10850 priv->status |= STATUS_SECURITY_UPDATED;
10851 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010852
James Ketrenosb095c382005-08-24 22:04:42 -050010853 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10854 priv->ieee->sec.flags |= SEC_ENABLED;
10855 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010856 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010857 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010858 priv->capability |= CAP_PRIVACY_ON;
10859 else
10860 priv->capability &= ~CAP_PRIVACY_ON;
10861 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010862
James Ketrenosafbf30a2005-08-25 00:05:33 -050010863 if (sec->flags & SEC_ENCRYPT)
10864 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010865
James Ketrenosb095c382005-08-24 22:04:42 -050010866 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10867 priv->ieee->sec.level = sec->level;
10868 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010869 priv->status |= STATUS_SECURITY_UPDATED;
10870 }
10871
Zhu Yi1fbfea52005-08-05 17:22:56 +080010872 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10873 ipw_set_hwcrypto_keys(priv);
10874
Jeff Garzikbf794512005-07-31 13:07:26 -040010875 /* To match current functionality of ipw2100 (which works well w/
10876 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010877 * privacy capability changes ... */
10878#if 0
10879 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010880 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010881 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010882 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010883 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010884 IPW_DEBUG_ASSOC("Disassociating due to capability "
10885 "change.\n");
10886 ipw_disassociate(priv);
10887 }
10888#endif
10889}
10890
Jeff Garzikbf794512005-07-31 13:07:26 -040010891static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 struct ipw_supported_rates *rates)
10893{
10894 /* TODO: Mask out rates based on priv->rates_mask */
10895
10896 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010897 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010898 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010899 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010900 rates->ieee_mode = IPW_A_MODE;
10901 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010902 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10903 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010904 break;
10905
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010906 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010907 rates->ieee_mode = IPW_G_MODE;
10908 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010909 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10910 LIBIPW_CCK_DEFAULT_RATES_MASK);
10911 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10912 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10913 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010914 }
10915 break;
10916 }
10917
10918 return 0;
10919}
10920
Jeff Garzikbf794512005-07-31 13:07:26 -040010921static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010922{
James Ketrenos43f66a62005-03-25 12:31:53 -060010923 /* This is only called from ipw_up, which resets/reloads the firmware
10924 so, we don't need to first disable the card before we configure
10925 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010926 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010927 goto error;
10928
10929 /* initialize adapter address */
10930 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10931 goto error;
10932
10933 /* set basic system config settings */
10934 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010935
10936 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10937 * Does not support BT priority yet (don't abort or defer our Tx) */
10938 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010939 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010940
10941 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10942 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010943 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010944 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10945 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010946 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010947 }
10948
Zhu Yid685b8c2006-04-13 17:20:27 +080010949#ifdef CONFIG_IPW2200_PROMISCUOUS
10950 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10951 priv->sys_config.accept_all_data_frames = 1;
10952 priv->sys_config.accept_non_directed_frames = 1;
10953 priv->sys_config.accept_all_mgmt_bcpr = 1;
10954 priv->sys_config.accept_all_mgmt_frames = 1;
10955 }
10956#endif
10957
James Ketrenosc848d0a2005-08-24 21:56:24 -050010958 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10959 priv->sys_config.answer_broadcast_ssid_probe = 1;
10960 else
10961 priv->sys_config.answer_broadcast_ssid_probe = 0;
10962
Zhu Yid685b8c2006-04-13 17:20:27 +080010963 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010964 goto error;
10965
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010966 init_supported_rates(priv, &priv->rates);
10967 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010968 goto error;
10969
10970 /* Set request-to-send threshold */
10971 if (priv->rts_threshold) {
10972 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10973 goto error;
10974 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010975#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010976 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10977 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010978#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010979
10980 if (ipw_set_random_seed(priv))
10981 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010982
James Ketrenos43f66a62005-03-25 12:31:53 -060010983 /* final state transition to the RUN state */
10984 if (ipw_send_host_complete(priv))
10985 goto error;
10986
James Ketrenose6666192005-08-12 09:17:04 -050010987 priv->status |= STATUS_INIT;
10988
10989 ipw_led_init(priv);
10990 ipw_led_radio_on(priv);
10991 priv->notif_missed_beacons = 0;
10992
10993 /* Set hardware WEP key if it is configured. */
10994 if ((priv->capability & CAP_PRIVACY_ON) &&
10995 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10996 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10997 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010998
10999 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040011000
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011001 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060011002 return -EIO;
11003}
11004
James Ketrenos4f36f802005-08-03 20:36:56 -050011005/*
11006 * NOTE:
11007 *
11008 * These tables have been tested in conjunction with the
11009 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11010 *
11011 * Altering this values, using it on other hardware, or in geographies
11012 * not intended for resale of the above mentioned Intel adapters has
11013 * not been tested.
11014 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011015 * Remember to update the table in README.ipw2200 when changing this
11016 * table.
11017 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011018 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011019static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011020 { /* Restricted */
11021 "---",
11022 .bg_channels = 11,
11023 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11024 {2427, 4}, {2432, 5}, {2437, 6},
11025 {2442, 7}, {2447, 8}, {2452, 9},
11026 {2457, 10}, {2462, 11}},
11027 },
11028
11029 { /* Custom US/Canada */
11030 "ZZF",
11031 .bg_channels = 11,
11032 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11033 {2427, 4}, {2432, 5}, {2437, 6},
11034 {2442, 7}, {2447, 8}, {2452, 9},
11035 {2457, 10}, {2462, 11}},
11036 .a_channels = 8,
11037 .a = {{5180, 36},
11038 {5200, 40},
11039 {5220, 44},
11040 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011041 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11042 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11043 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11044 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011045 },
11046
11047 { /* Rest of World */
11048 "ZZD",
11049 .bg_channels = 13,
11050 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11051 {2427, 4}, {2432, 5}, {2437, 6},
11052 {2442, 7}, {2447, 8}, {2452, 9},
11053 {2457, 10}, {2462, 11}, {2467, 12},
11054 {2472, 13}},
11055 },
11056
11057 { /* Custom USA & Europe & High */
11058 "ZZA",
11059 .bg_channels = 11,
11060 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11061 {2427, 4}, {2432, 5}, {2437, 6},
11062 {2442, 7}, {2447, 8}, {2452, 9},
11063 {2457, 10}, {2462, 11}},
11064 .a_channels = 13,
11065 .a = {{5180, 36},
11066 {5200, 40},
11067 {5220, 44},
11068 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011069 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11070 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11071 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11072 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011073 {5745, 149},
11074 {5765, 153},
11075 {5785, 157},
11076 {5805, 161},
11077 {5825, 165}},
11078 },
11079
11080 { /* Custom NA & Europe */
11081 "ZZB",
11082 .bg_channels = 11,
11083 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11084 {2427, 4}, {2432, 5}, {2437, 6},
11085 {2442, 7}, {2447, 8}, {2452, 9},
11086 {2457, 10}, {2462, 11}},
11087 .a_channels = 13,
11088 .a = {{5180, 36},
11089 {5200, 40},
11090 {5220, 44},
11091 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011092 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11093 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11094 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11095 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11096 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11097 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11098 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11099 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11100 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011101 },
11102
11103 { /* Custom Japan */
11104 "ZZC",
11105 .bg_channels = 11,
11106 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11107 {2427, 4}, {2432, 5}, {2437, 6},
11108 {2442, 7}, {2447, 8}, {2452, 9},
11109 {2457, 10}, {2462, 11}},
11110 .a_channels = 4,
11111 .a = {{5170, 34}, {5190, 38},
11112 {5210, 42}, {5230, 46}},
11113 },
11114
11115 { /* Custom */
11116 "ZZM",
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 },
11123
11124 { /* Europe */
11125 "ZZE",
11126 .bg_channels = 13,
11127 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11128 {2427, 4}, {2432, 5}, {2437, 6},
11129 {2442, 7}, {2447, 8}, {2452, 9},
11130 {2457, 10}, {2462, 11}, {2467, 12},
11131 {2472, 13}},
11132 .a_channels = 19,
11133 .a = {{5180, 36},
11134 {5200, 40},
11135 {5220, 44},
11136 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011137 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11138 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11139 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11140 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11141 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11142 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11143 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11144 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11145 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11146 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11147 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11148 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11149 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11150 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11151 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011152 },
11153
11154 { /* Custom Japan */
11155 "ZZJ",
11156 .bg_channels = 14,
11157 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11158 {2427, 4}, {2432, 5}, {2437, 6},
11159 {2442, 7}, {2447, 8}, {2452, 9},
11160 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011161 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011162 .a_channels = 4,
11163 .a = {{5170, 34}, {5190, 38},
11164 {5210, 42}, {5230, 46}},
11165 },
11166
James Ketrenos03520572005-10-19 16:12:31 -050011167 { /* Rest of World */
11168 "ZZR",
11169 .bg_channels = 14,
11170 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11171 {2427, 4}, {2432, 5}, {2437, 6},
11172 {2442, 7}, {2447, 8}, {2452, 9},
11173 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011174 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11175 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011176 },
11177
James Ketrenos4f36f802005-08-03 20:36:56 -050011178 { /* High Band */
11179 "ZZH",
11180 .bg_channels = 13,
11181 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11182 {2427, 4}, {2432, 5}, {2437, 6},
11183 {2442, 7}, {2447, 8}, {2452, 9},
11184 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011185 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11186 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011187 .a_channels = 4,
11188 .a = {{5745, 149}, {5765, 153},
11189 {5785, 157}, {5805, 161}},
11190 },
11191
11192 { /* Custom Europe */
11193 "ZZG",
11194 .bg_channels = 13,
11195 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11196 {2427, 4}, {2432, 5}, {2437, 6},
11197 {2442, 7}, {2447, 8}, {2452, 9},
11198 {2457, 10}, {2462, 11},
11199 {2467, 12}, {2472, 13}},
11200 .a_channels = 4,
11201 .a = {{5180, 36}, {5200, 40},
11202 {5220, 44}, {5240, 48}},
11203 },
11204
11205 { /* Europe */
11206 "ZZK",
11207 .bg_channels = 13,
11208 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11209 {2427, 4}, {2432, 5}, {2437, 6},
11210 {2442, 7}, {2447, 8}, {2452, 9},
11211 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011212 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11213 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011214 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011215 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11216 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11217 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11218 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11219 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11220 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11221 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11222 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11223 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11224 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11225 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11226 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11227 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11228 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11229 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11230 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11231 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11232 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11233 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11234 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11235 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11236 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11237 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11238 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011239 },
11240
11241 { /* Europe */
11242 "ZZL",
11243 .bg_channels = 11,
11244 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11245 {2427, 4}, {2432, 5}, {2437, 6},
11246 {2442, 7}, {2447, 8}, {2452, 9},
11247 {2457, 10}, {2462, 11}},
11248 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011249 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11250 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11251 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11252 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11253 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11254 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11255 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11256 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11257 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11258 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11259 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11260 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11261 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011262 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011263};
11264
James Ketrenos43f66a62005-03-25 12:31:53 -060011265#define MAX_HW_RESTARTS 5
11266static int ipw_up(struct ipw_priv *priv)
11267{
James Ketrenos4f36f802005-08-03 20:36:56 -050011268 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011269
Dan Williamsc3d72b92009-02-11 13:26:06 -050011270 /* Age scan list entries found before suspend */
11271 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011272 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011273 priv->suspend_time = 0;
11274 }
11275
James Ketrenos43f66a62005-03-25 12:31:53 -060011276 if (priv->status & STATUS_EXIT_PENDING)
11277 return -EIO;
11278
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011279 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011280 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011281 GFP_KERNEL);
11282 if (priv->cmdlog == NULL) {
11283 IPW_ERROR("Error allocating %d command log entries.\n",
11284 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011285 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011286 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011287 priv->cmdlog_len = cmdlog;
11288 }
11289 }
11290
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011291 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011292 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011293 * Also start the clocks. */
11294 rc = ipw_load(priv);
11295 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011296 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011297 return rc;
11298 }
11299
11300 ipw_init_ordinals(priv);
11301 if (!(priv->config & CFG_CUSTOM_MAC))
11302 eeprom_parse_mac(priv, priv->mac_addr);
11303 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011304 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011305
James Ketrenos4f36f802005-08-03 20:36:56 -050011306 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11307 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11308 ipw_geos[j].name, 3))
11309 break;
11310 }
James Ketrenos03520572005-10-19 16:12:31 -050011311 if (j == ARRAY_SIZE(ipw_geos)) {
11312 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11313 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11314 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11315 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011316 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011317 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011318 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011319 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011320 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011321 }
11322
James Ketrenosb095c382005-08-24 22:04:42 -050011323 if (priv->status & STATUS_RF_KILL_SW) {
11324 IPW_WARNING("Radio disabled by module parameter.\n");
11325 return 0;
11326 } else if (rf_kill_active(priv)) {
11327 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11328 "Kill switch must be turned off for "
11329 "wireless networking to work.\n");
11330 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11331 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011332 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011333 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011334
11335 rc = ipw_config(priv);
11336 if (!rc) {
11337 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011338
James Ketrenose6666192005-08-12 09:17:04 -050011339 /* If configure to try and auto-associate, kick
11340 * off a scan. */
David Howellsc4028952006-11-22 14:57:56 +000011341 queue_delayed_work(priv->workqueue,
11342 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011343
James Ketrenos43f66a62005-03-25 12:31:53 -060011344 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011345 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011346
James Ketrenosc848d0a2005-08-24 21:56:24 -050011347 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011348 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11349 i, MAX_HW_RESTARTS);
11350
11351 /* We had an error bringing up the hardware, so take it
11352 * all the way back down so we can try again */
11353 ipw_down(priv);
11354 }
11355
Jeff Garzikbf794512005-07-31 13:07:26 -040011356 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011357 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011358 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011359
James Ketrenos43f66a62005-03-25 12:31:53 -060011360 return -EIO;
11361}
11362
David Howellsc4028952006-11-22 14:57:56 +000011363static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011364{
David Howellsc4028952006-11-22 14:57:56 +000011365 struct ipw_priv *priv =
11366 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011367 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011368 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011369 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011370}
11371
James Ketrenosb095c382005-08-24 22:04:42 -050011372static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011373{
James Ketrenosb095c382005-08-24 22:04:42 -050011374 int i;
11375
11376 if (priv->status & STATUS_SCANNING) {
11377 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11378 ipw_abort_scan(priv);
11379 }
11380
11381 if (priv->status & STATUS_ASSOCIATED) {
11382 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11383 ipw_disassociate(priv);
11384 }
11385
11386 ipw_led_shutdown(priv);
11387
11388 /* Wait up to 1s for status to change to not scanning and not
11389 * associated (disassociation can take a while for a ful 802.11
11390 * exchange */
11391 for (i = 1000; i && (priv->status &
11392 (STATUS_DISASSOCIATING |
11393 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11394 udelay(10);
11395
11396 if (priv->status & (STATUS_DISASSOCIATING |
11397 STATUS_ASSOCIATED | STATUS_SCANNING))
11398 IPW_DEBUG_INFO("Still associated or scanning...\n");
11399 else
11400 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11401
James Ketrenosc848d0a2005-08-24 21:56:24 -050011402 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011403 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011404
11405 priv->status &= ~STATUS_INIT;
11406}
11407
James Ketrenos43f66a62005-03-25 12:31:53 -060011408static void ipw_down(struct ipw_priv *priv)
11409{
James Ketrenosb095c382005-08-24 22:04:42 -050011410 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11411
11412 priv->status |= STATUS_EXIT_PENDING;
11413
11414 if (ipw_is_init(priv))
11415 ipw_deinit(priv);
11416
11417 /* Wipe out the EXIT_PENDING status bit if we are not actually
11418 * exiting the module */
11419 if (!exit_pending)
11420 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011421
11422 /* tell the device to stop sending interrupts */
11423 ipw_disable_interrupts(priv);
11424
11425 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011426 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011427 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011428
11429 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011430
11431 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011432}
11433
David Howellsc4028952006-11-22 14:57:56 +000011434static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011435{
David Howellsc4028952006-11-22 14:57:56 +000011436 struct ipw_priv *priv =
11437 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011438 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011439 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011440 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011441}
11442
11443/* Called by register_netdev() */
11444static int ipw_net_init(struct net_device *dev)
11445{
John W. Linvillea3caa992009-08-25 14:12:25 -040011446 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011447 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011448 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11449 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011450 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011451
James Ketrenosc848d0a2005-08-24 21:56:24 -050011452 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011453 rc = -EIO;
11454 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011455 }
11456
John W. Linvillea3caa992009-08-25 14:12:25 -040011457 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11458
11459 /* fill-out priv->ieee->bg_band */
11460 if (geo->bg_channels) {
11461 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11462
11463 bg_band->band = IEEE80211_BAND_2GHZ;
11464 bg_band->n_channels = geo->bg_channels;
11465 bg_band->channels =
11466 kzalloc(geo->bg_channels *
11467 sizeof(struct ieee80211_channel), GFP_KERNEL);
11468 /* translate geo->bg to bg_band.channels */
11469 for (i = 0; i < geo->bg_channels; i++) {
11470 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11471 bg_band->channels[i].center_freq = geo->bg[i].freq;
11472 bg_band->channels[i].hw_value = geo->bg[i].channel;
11473 bg_band->channels[i].max_power = geo->bg[i].max_power;
11474 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11475 bg_band->channels[i].flags |=
11476 IEEE80211_CHAN_PASSIVE_SCAN;
11477 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11478 bg_band->channels[i].flags |=
11479 IEEE80211_CHAN_NO_IBSS;
11480 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11481 bg_band->channels[i].flags |=
11482 IEEE80211_CHAN_RADAR;
11483 /* No equivalent for LIBIPW_CH_80211H_RULES,
11484 LIBIPW_CH_UNIFORM_SPREADING, or
11485 LIBIPW_CH_B_ONLY... */
11486 }
11487 /* point at bitrate info */
11488 bg_band->bitrates = ipw2200_bg_rates;
11489 bg_band->n_bitrates = ipw2200_num_bg_rates;
11490
11491 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11492 }
11493
11494 /* fill-out priv->ieee->a_band */
11495 if (geo->a_channels) {
11496 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11497
11498 a_band->band = IEEE80211_BAND_5GHZ;
11499 a_band->n_channels = geo->a_channels;
11500 a_band->channels =
11501 kzalloc(geo->a_channels *
11502 sizeof(struct ieee80211_channel), GFP_KERNEL);
11503 /* translate geo->bg to a_band.channels */
11504 for (i = 0; i < geo->a_channels; i++) {
11505 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11506 a_band->channels[i].center_freq = geo->a[i].freq;
11507 a_band->channels[i].hw_value = geo->a[i].channel;
11508 a_band->channels[i].max_power = geo->a[i].max_power;
11509 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11510 a_band->channels[i].flags |=
11511 IEEE80211_CHAN_PASSIVE_SCAN;
11512 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11513 a_band->channels[i].flags |=
11514 IEEE80211_CHAN_NO_IBSS;
11515 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11516 a_band->channels[i].flags |=
11517 IEEE80211_CHAN_RADAR;
11518 /* No equivalent for LIBIPW_CH_80211H_RULES,
11519 LIBIPW_CH_UNIFORM_SPREADING, or
11520 LIBIPW_CH_B_ONLY... */
11521 }
11522 /* point at bitrate info */
11523 a_band->bitrates = ipw2200_a_rates;
11524 a_band->n_bitrates = ipw2200_num_a_rates;
11525
11526 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11527 }
11528
11529 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11530
11531 /* With that information in place, we can now register the wiphy... */
11532 if (wiphy_register(wdev->wiphy)) {
11533 rc = -EIO;
11534 goto out;
11535 }
11536
11537out:
Zhu Yi46441512006-01-24 16:37:59 +080011538 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011539 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011540}
11541
11542/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011543static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011544 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11545 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11552 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11553 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11554 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11555 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11556 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11557 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11558 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11559 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11560 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011561 {PCI_VDEVICE(INTEL, 0x104f), 0},
11562 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11563 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11564 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11565 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011566
James Ketrenos43f66a62005-03-25 12:31:53 -060011567 /* required last entry */
11568 {0,}
11569};
11570
11571MODULE_DEVICE_TABLE(pci, card_ids);
11572
11573static struct attribute *ipw_sysfs_entries[] = {
11574 &dev_attr_rf_kill.attr,
11575 &dev_attr_direct_dword.attr,
11576 &dev_attr_indirect_byte.attr,
11577 &dev_attr_indirect_dword.attr,
11578 &dev_attr_mem_gpio_reg.attr,
11579 &dev_attr_command_event_reg.attr,
11580 &dev_attr_nic_type.attr,
11581 &dev_attr_status.attr,
11582 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011583 &dev_attr_error.attr,
11584 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011585 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011586 &dev_attr_eeprom_delay.attr,
11587 &dev_attr_ucode_version.attr,
11588 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011589 &dev_attr_scan_age.attr,
11590 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011591 &dev_attr_speed_scan.attr,
11592 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011593 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011594#ifdef CONFIG_IPW2200_PROMISCUOUS
11595 &dev_attr_rtap_iface.attr,
11596 &dev_attr_rtap_filter.attr,
11597#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011598 NULL
11599};
11600
11601static struct attribute_group ipw_attribute_group = {
11602 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011603 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011604};
11605
Zhu Yid685b8c2006-04-13 17:20:27 +080011606#ifdef CONFIG_IPW2200_PROMISCUOUS
11607static int ipw_prom_open(struct net_device *dev)
11608{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011609 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011610 struct ipw_priv *priv = prom_priv->priv;
11611
11612 IPW_DEBUG_INFO("prom dev->open\n");
11613 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011614
11615 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11616 priv->sys_config.accept_all_data_frames = 1;
11617 priv->sys_config.accept_non_directed_frames = 1;
11618 priv->sys_config.accept_all_mgmt_bcpr = 1;
11619 priv->sys_config.accept_all_mgmt_frames = 1;
11620
11621 ipw_send_system_config(priv);
11622 }
11623
11624 return 0;
11625}
11626
11627static int ipw_prom_stop(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->stop\n");
11633
11634 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11635 priv->sys_config.accept_all_data_frames = 0;
11636 priv->sys_config.accept_non_directed_frames = 0;
11637 priv->sys_config.accept_all_mgmt_bcpr = 0;
11638 priv->sys_config.accept_all_mgmt_frames = 0;
11639
11640 ipw_send_system_config(priv);
11641 }
11642
11643 return 0;
11644}
11645
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011646static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11647 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011648{
11649 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011650 dev_kfree_skb(skb);
11651 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011652}
11653
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011654static const struct net_device_ops ipw_prom_netdev_ops = {
11655 .ndo_open = ipw_prom_open,
11656 .ndo_stop = ipw_prom_stop,
11657 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011658 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011659 .ndo_set_mac_address = eth_mac_addr,
11660 .ndo_validate_addr = eth_validate_addr,
11661};
11662
Zhu Yid685b8c2006-04-13 17:20:27 +080011663static int ipw_prom_alloc(struct ipw_priv *priv)
11664{
11665 int rc = 0;
11666
11667 if (priv->prom_net_dev)
11668 return -EPERM;
11669
John W. Linvillea3caa992009-08-25 14:12:25 -040011670 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011671 if (priv->prom_net_dev == NULL)
11672 return -ENOMEM;
11673
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011674 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011675 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11676 priv->prom_priv->priv = priv;
11677
11678 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011679 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011680
11681 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011682 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011683
11684 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011685 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011686
11687 rc = register_netdev(priv->prom_net_dev);
11688 if (rc) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011689 free_ieee80211(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011690 priv->prom_net_dev = NULL;
11691 return rc;
11692 }
11693
11694 return 0;
11695}
11696
11697static void ipw_prom_free(struct ipw_priv *priv)
11698{
11699 if (!priv->prom_net_dev)
11700 return;
11701
11702 unregister_netdev(priv->prom_net_dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011703 free_ieee80211(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011704
11705 priv->prom_net_dev = NULL;
11706}
11707
11708#endif
11709
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011710static const struct net_device_ops ipw_netdev_ops = {
11711 .ndo_init = ipw_net_init,
11712 .ndo_open = ipw_net_open,
11713 .ndo_stop = ipw_net_stop,
11714 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11715 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011716 .ndo_start_xmit = libipw_xmit,
11717 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011718 .ndo_validate_addr = eth_validate_addr,
11719};
Zhu Yid685b8c2006-04-13 17:20:27 +080011720
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011721static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11722 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011723{
11724 int err = 0;
11725 struct net_device *net_dev;
11726 void __iomem *base;
11727 u32 length, val;
11728 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011729 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011730
John W. Linvillea3caa992009-08-25 14:12:25 -040011731 net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011732 if (net_dev == NULL) {
11733 err = -ENOMEM;
11734 goto out;
11735 }
11736
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011737 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011738 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011739
James Ketrenos43f66a62005-03-25 12:31:53 -060011740 priv->net_dev = net_dev;
11741 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011742 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011743 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011744 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011745 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11746 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011747
Zhu Yi46441512006-01-24 16:37:59 +080011748 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011749 if (pci_enable_device(pdev)) {
11750 err = -ENODEV;
11751 goto out_free_ieee80211;
11752 }
11753
11754 pci_set_master(pdev);
11755
Yang Hongyang284901a2009-04-06 19:01:15 -070011756 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011757 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011758 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011759 if (err) {
11760 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11761 goto out_pci_disable_device;
11762 }
11763
11764 pci_set_drvdata(pdev, priv);
11765
11766 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011767 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011768 goto out_pci_disable_device;
11769
Jeff Garzikbf794512005-07-31 13:07:26 -040011770 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011771 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011772 pci_read_config_dword(pdev, 0x40, &val);
11773 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011774 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011775
James Ketrenos43f66a62005-03-25 12:31:53 -060011776 length = pci_resource_len(pdev, 0);
11777 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011778
Arjan van de Ven275f1652008-10-20 21:42:39 -070011779 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011780 if (!base) {
11781 err = -ENODEV;
11782 goto out_pci_release_regions;
11783 }
11784
11785 priv->hw_base = base;
11786 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11787 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11788
11789 err = ipw_setup_deferred_work(priv);
11790 if (err) {
11791 IPW_ERROR("Unable to setup deferred work\n");
11792 goto out_iounmap;
11793 }
11794
James Ketrenosb095c382005-08-24 22:04:42 -050011795 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011796
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011797 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011798 if (err) {
11799 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11800 goto out_destroy_workqueue;
11801 }
11802
James Ketrenos43f66a62005-03-25 12:31:53 -060011803 SET_NETDEV_DEV(net_dev, &pdev->dev);
11804
Zhu Yi46441512006-01-24 16:37:59 +080011805 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011806
James Ketrenos43f66a62005-03-25 12:31:53 -060011807 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11808 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011809 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011810
Zhu Yie43e3c12006-04-13 17:20:45 +080011811#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011812 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011813 priv->ieee->handle_probe_response = ipw_handle_beacon;
11814 priv->ieee->handle_beacon = ipw_handle_probe_response;
11815 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011816#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011817
James Ketrenosc848d0a2005-08-24 21:56:24 -050011818 priv->ieee->perfect_rssi = -20;
11819 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011820
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011821 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011822 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011823 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011824 net_dev->wireless_handlers = &ipw_wx_handler_def;
11825 net_dev->ethtool_ops = &ipw_ethtool_ops;
11826 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011827 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011828 net_dev->mem_start = pci_resource_start(pdev, 0);
11829 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11830
11831 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11832 if (err) {
11833 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011834 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011835 goto out_release_irq;
11836 }
11837
Zhu Yi46441512006-01-24 16:37:59 +080011838 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011839 err = register_netdev(net_dev);
11840 if (err) {
11841 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011842 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011843 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011844
Zhu Yid685b8c2006-04-13 17:20:27 +080011845#ifdef CONFIG_IPW2200_PROMISCUOUS
11846 if (rtap_iface) {
11847 err = ipw_prom_alloc(priv);
11848 if (err) {
11849 IPW_ERROR("Failed to register promiscuous network "
11850 "device (error %d).\n", err);
11851 unregister_netdev(priv->net_dev);
11852 goto out_remove_sysfs;
11853 }
11854 }
11855#endif
11856
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011857 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11858 "channels, %d 802.11a channels)\n",
11859 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11860 priv->ieee->geo.a_channels);
11861
James Ketrenos43f66a62005-03-25 12:31:53 -060011862 return 0;
11863
James Ketrenosa613bff2005-08-24 21:43:11 -050011864 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011865 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011866 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011867 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011868 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011869 destroy_workqueue(priv->workqueue);
11870 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011871 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011872 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011873 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011874 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011875 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011876 pci_disable_device(pdev);
11877 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011878 out_free_ieee80211:
John W. Linvillea3caa992009-08-25 14:12:25 -040011879 free_ieee80211(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011880 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011881 return err;
11882}
11883
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011884static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011885{
11886 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011887 struct list_head *p, *q;
11888 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011889
James Ketrenos43f66a62005-03-25 12:31:53 -060011890 if (!priv)
11891 return;
11892
Zhu Yi46441512006-01-24 16:37:59 +080011893 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011894
James Ketrenosafbf30a2005-08-25 00:05:33 -050011895 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011896 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011897 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11898
Zhu Yi46441512006-01-24 16:37:59 +080011899 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011900
11901 unregister_netdev(priv->net_dev);
11902
11903 if (priv->rxq) {
11904 ipw_rx_queue_free(priv, priv->rxq);
11905 priv->rxq = NULL;
11906 }
11907 ipw_tx_queue_free(priv);
11908
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011909 if (priv->cmdlog) {
11910 kfree(priv->cmdlog);
11911 priv->cmdlog = NULL;
11912 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011913 /* ipw_down will ensure that there is no more pending work
11914 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011915 cancel_delayed_work(&priv->adhoc_check);
11916 cancel_delayed_work(&priv->gather_stats);
11917 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011918 cancel_delayed_work(&priv->request_direct_scan);
11919 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011920 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011921 cancel_delayed_work(&priv->rf_kill);
11922 cancel_delayed_work(&priv->scan_check);
11923 destroy_workqueue(priv->workqueue);
11924 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011925
James Ketrenosafbf30a2005-08-25 00:05:33 -050011926 /* Free MAC hash list for ADHOC */
11927 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11928 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011929 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011930 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011931 }
11932 }
11933
Jesper Juhl8f760782006-06-27 02:55:06 -070011934 kfree(priv->error);
11935 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011936
Zhu Yid685b8c2006-04-13 17:20:27 +080011937#ifdef CONFIG_IPW2200_PROMISCUOUS
11938 ipw_prom_free(priv);
11939#endif
11940
James Ketrenos43f66a62005-03-25 12:31:53 -060011941 free_irq(pdev->irq, priv);
11942 iounmap(priv->hw_base);
11943 pci_release_regions(pdev);
11944 pci_disable_device(pdev);
11945 pci_set_drvdata(pdev, NULL);
John W. Linvillea3caa992009-08-25 14:12:25 -040011946 /* wiphy_unregister needs to be here, before free_ieee80211 */
11947 wiphy_unregister(priv->ieee->wdev.wiphy);
11948 kfree(priv->ieee->a_band.channels);
11949 kfree(priv->ieee->bg_band.channels);
11950 free_ieee80211(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011951 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011952}
11953
James Ketrenos43f66a62005-03-25 12:31:53 -060011954#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011955static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011956{
11957 struct ipw_priv *priv = pci_get_drvdata(pdev);
11958 struct net_device *dev = priv->net_dev;
11959
11960 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11961
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011962 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011963 ipw_down(priv);
11964
11965 /* Remove the PRESENT state of the device */
11966 netif_device_detach(dev);
11967
James Ketrenos43f66a62005-03-25 12:31:53 -060011968 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011969 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011970 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011971
Dan Williamsc3d72b92009-02-11 13:26:06 -050011972 priv->suspend_at = get_seconds();
11973
James Ketrenos43f66a62005-03-25 12:31:53 -060011974 return 0;
11975}
11976
11977static int ipw_pci_resume(struct pci_dev *pdev)
11978{
11979 struct ipw_priv *priv = pci_get_drvdata(pdev);
11980 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011981 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011982 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011983
James Ketrenos43f66a62005-03-25 12:31:53 -060011984 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11985
James Ketrenosea2b26e2005-08-24 21:25:16 -050011986 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011987 err = pci_enable_device(pdev);
11988 if (err) {
11989 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11990 dev->name);
11991 return err;
11992 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011993 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011994
James Ketrenos43f66a62005-03-25 12:31:53 -060011995 /*
11996 * Suspend/Resume resets the PCI configuration space, so we have to
11997 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11998 * from interfering with C3 CPU state. pci_restore_state won't help
11999 * here since it only restores the first 64 bytes pci config header.
12000 */
Jeff Garzikbf794512005-07-31 13:07:26 -040012001 pci_read_config_dword(pdev, 0x40, &val);
12002 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060012003 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12004
12005 /* Set the device back into the PRESENT state; this will also wake
12006 * the queue of needed */
12007 netif_device_attach(dev);
12008
Dan Williamsc3d72b92009-02-11 13:26:06 -050012009 priv->suspend_time = get_seconds() - priv->suspend_at;
12010
James Ketrenos43f66a62005-03-25 12:31:53 -060012011 /* Bring the device back up */
12012 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012013
James Ketrenos43f66a62005-03-25 12:31:53 -060012014 return 0;
12015}
12016#endif
12017
Zhu Yic8c22c92006-08-21 11:38:39 +080012018static void ipw_pci_shutdown(struct pci_dev *pdev)
12019{
12020 struct ipw_priv *priv = pci_get_drvdata(pdev);
12021
12022 /* Take down the device; powers it off, etc. */
12023 ipw_down(priv);
12024
12025 pci_disable_device(pdev);
12026}
12027
James Ketrenos43f66a62005-03-25 12:31:53 -060012028/* driver initialization stuff */
12029static struct pci_driver ipw_driver = {
12030 .name = DRV_NAME,
12031 .id_table = card_ids,
12032 .probe = ipw_pci_probe,
12033 .remove = __devexit_p(ipw_pci_remove),
12034#ifdef CONFIG_PM
12035 .suspend = ipw_pci_suspend,
12036 .resume = ipw_pci_resume,
12037#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012038 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012039};
12040
12041static int __init ipw_init(void)
12042{
12043 int ret;
12044
12045 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12046 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12047
Jeff Garzik29917622006-08-19 17:48:59 -040012048 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012049 if (ret) {
12050 IPW_ERROR("Unable to initialize PCI module\n");
12051 return ret;
12052 }
12053
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012054 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012055 if (ret) {
12056 IPW_ERROR("Unable to create driver sysfs file\n");
12057 pci_unregister_driver(&ipw_driver);
12058 return ret;
12059 }
12060
12061 return ret;
12062}
12063
12064static void __exit ipw_exit(void)
12065{
12066 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12067 pci_unregister_driver(&ipw_driver);
12068}
12069
12070module_param(disable, int, 0444);
12071MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12072
12073module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012074MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012075
12076module_param(auto_create, int, 0444);
12077MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12078
Reinette Chatre21f8a732009-08-18 10:25:05 -070012079module_param_named(led, led_support, int, 0444);
Niels de Vos61a2d072008-07-31 00:07:23 -070012080MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012081
James Ketrenos43f66a62005-03-25 12:31:53 -060012082module_param(debug, int, 0444);
12083MODULE_PARM_DESC(debug, "debug output mask");
12084
Reinette Chatre21f8a732009-08-18 10:25:05 -070012085module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012086MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012087
Zhu Yid685b8c2006-04-13 17:20:27 +080012088#ifdef CONFIG_IPW2200_PROMISCUOUS
12089module_param(rtap_iface, int, 0444);
12090MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12091#endif
12092
Zhu Yie43e3c12006-04-13 17:20:45 +080012093#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012094module_param(qos_enable, int, 0444);
12095MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012096
James Ketrenosb095c382005-08-24 22:04:42 -050012097module_param(qos_burst_enable, int, 0444);
12098MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12099
12100module_param(qos_no_ack_mask, int, 0444);
12101MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12102
12103module_param(burst_duration_CCK, int, 0444);
12104MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12105
12106module_param(burst_duration_OFDM, int, 0444);
12107MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012108#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012109
12110#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012111module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012112MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12113#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012114module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012115MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12116#endif
12117
Zhu Yi810dabd2006-01-24 16:36:59 +080012118module_param(bt_coexist, int, 0444);
12119MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12120
James Ketrenosb095c382005-08-24 22:04:42 -050012121module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012122MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012123
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012124module_param(cmdlog, int, 0444);
12125MODULE_PARM_DESC(cmdlog,
12126 "allocate a ring buffer for logging firmware commands");
12127
Zhu Yi4bfdb912006-01-24 16:37:16 +080012128module_param(roaming, int, 0444);
12129MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12130
Zhu Yid2b83e12006-04-13 17:19:36 +080012131module_param(antenna, int, 0444);
12132MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12133
James Ketrenos43f66a62005-03-25 12:31:53 -060012134module_exit(ipw_exit);
12135module_init(ipw_init);