blob: 553f66b67c16f9e6e870902471cdf891a4053e4c [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
Reinette Chatrec1eb2c82009-08-21 13:34:26 -070028 Intel Linux Wireless <ilw@linux.intel.com>
James Ketrenos43f66a62005-03-25 12:31:53 -060029 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040033#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035#include "ipw2200.h"
36
Zhu Yiae4af612006-04-13 17:20:34 +080037
38#ifndef KBUILD_EXTMOD
39#define VK "k"
40#else
41#define VK
42#endif
43
44#ifdef CONFIG_IPW2200_DEBUG
45#define VD "d"
46#else
47#define VD
48#endif
49
50#ifdef CONFIG_IPW2200_MONITOR
51#define VM "m"
52#else
53#define VM
54#endif
55
56#ifdef CONFIG_IPW2200_PROMISCUOUS
57#define VP "p"
58#else
59#define VP
60#endif
61
Zhu Yi459d4082006-04-13 17:21:00 +080062#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080063#define VR "r"
64#else
65#define VR
66#endif
67
68#ifdef CONFIG_IPW2200_QOS
69#define VQ "q"
70#else
71#define VQ
72#endif
73
Zhu Yiee2c4ad2007-07-12 16:09:47 +080074#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060075#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080076#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060077#define DRV_VERSION IPW2200_VERSION
78
James Ketrenosb095c382005-08-24 22:04:42 -050079#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
80
James Ketrenos43f66a62005-03-25 12:31:53 -060081MODULE_DESCRIPTION(DRV_DESCRIPTION);
82MODULE_VERSION(DRV_VERSION);
83MODULE_AUTHOR(DRV_COPYRIGHT);
84MODULE_LICENSE("GPL");
Ben Hutchings873395a2009-11-07 21:59:10 +000085MODULE_FIRMWARE("ipw2200-ibss.fw");
86#ifdef CONFIG_IPW2200_MONITOR
87MODULE_FIRMWARE("ipw2200-sniffer.fw");
88#endif
89MODULE_FIRMWARE("ipw2200-bss.fw");
James Ketrenos43f66a62005-03-25 12:31:53 -060090
James Ketrenosf6c5cb72005-08-25 00:39:09 -050091static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060092static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070093static int default_channel = 0;
94static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060095
96static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060097static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060098static int auto_create = 1;
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000099static int led_support = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600100static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +0800101static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +0800102static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +0800103static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600104static const char ipw_modes[] = {
105 'a', 'b', 'g', '?'
106};
Zhu Yid2b83e12006-04-13 17:19:36 +0800107static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600108
Zhu Yid685b8c2006-04-13 17:20:27 +0800109#ifdef CONFIG_IPW2200_PROMISCUOUS
110static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
111#endif
112
John W. Linvillea3caa992009-08-25 14:12:25 -0400113static struct ieee80211_rate ipw2200_rates[] = {
114 { .bitrate = 10 },
115 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
116 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
117 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
118 { .bitrate = 60 },
119 { .bitrate = 90 },
120 { .bitrate = 120 },
121 { .bitrate = 180 },
122 { .bitrate = 240 },
123 { .bitrate = 360 },
124 { .bitrate = 480 },
125 { .bitrate = 540 }
126};
127
128#define ipw2200_a_rates (ipw2200_rates + 4)
129#define ipw2200_num_a_rates 8
130#define ipw2200_bg_rates (ipw2200_rates + 0)
131#define ipw2200_num_bg_rates 12
Zhu Yid685b8c2006-04-13 17:20:27 +0800132
Zhu Yie43e3c12006-04-13 17:20:45 +0800133#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500134static int qos_enable = 0;
135static int qos_burst_enable = 0;
136static int qos_no_ack_mask = 0;
137static int burst_duration_CCK = 0;
138static int burst_duration_OFDM = 0;
139
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400140static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500141 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
142 QOS_TX3_CW_MIN_OFDM},
143 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
144 QOS_TX3_CW_MAX_OFDM},
145 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
146 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
147 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
148 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
149};
150
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400151static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500152 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
153 QOS_TX3_CW_MIN_CCK},
154 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
155 QOS_TX3_CW_MAX_CCK},
156 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
157 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
158 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
159 QOS_TX3_TXOP_LIMIT_CCK}
160};
161
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400162static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500163 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
164 DEF_TX3_CW_MIN_OFDM},
165 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
166 DEF_TX3_CW_MAX_OFDM},
167 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
168 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
169 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
170 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
171};
172
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400173static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500174 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
175 DEF_TX3_CW_MIN_CCK},
176 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
177 DEF_TX3_CW_MAX_CCK},
178 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
179 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
180 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
181 DEF_TX3_TXOP_LIMIT_CCK}
182};
183
184static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
185
186static int from_priority_to_tx_queue[] = {
187 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
188 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
189};
190
191static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
192
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400193static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500194 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400195static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500196 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800197#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500198
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000199static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500200static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600201static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400202static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600203 struct clx2_tx_queue *txq, int qindex);
204static int ipw_queue_reset(struct ipw_priv *priv);
205
206static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
207 int len, int sync);
208
209static void ipw_tx_queue_free(struct ipw_priv *);
210
211static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
212static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
213static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600214static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000215static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600216static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000217static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600218static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400219static int init_supported_rates(struct ipw_priv *priv,
220 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500221static void ipw_set_hwcrypto_keys(struct ipw_priv *);
222static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600223
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500224static int snprint_line(char *buf, size_t count,
225 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600226{
227 int out, i, j, l;
228 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400229
James Ketrenos43f66a62005-03-25 12:31:53 -0600230 out = snprintf(buf, count, "%08X", ofs);
231
232 for (l = 0, i = 0; i < 2; i++) {
233 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400234 for (j = 0; j < 8 && l < len; j++, l++)
235 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600236 data[(i * 8 + j)]);
237 for (; j < 8; j++)
238 out += snprintf(buf + out, count - out, " ");
239 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400240
James Ketrenos43f66a62005-03-25 12:31:53 -0600241 out += snprintf(buf + out, count - out, " ");
242 for (l = 0, i = 0; i < 2; i++) {
243 out += snprintf(buf + out, count - out, " ");
244 for (j = 0; j < 8 && l < len; j++, l++) {
245 c = data[(i * 8 + j)];
246 if (!isascii(c) || !isprint(c))
247 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400248
James Ketrenos43f66a62005-03-25 12:31:53 -0600249 out += snprintf(buf + out, count - out, "%c", c);
250 }
251
252 for (; j < 8; j++)
253 out += snprintf(buf + out, count - out, " ");
254 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400255
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500256 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600257}
258
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400259static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600260{
261 char line[81];
262 u32 ofs = 0;
263 if (!(ipw_debug_level & level))
264 return;
265
266 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500267 snprint_line(line, sizeof(line), &data[ofs],
268 min(len, 16U), ofs);
269 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600270 ofs += 16;
271 len -= min(len, 16U);
272 }
273}
274
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500275static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
276{
277 size_t out = size;
278 u32 ofs = 0;
279 int total = 0;
280
281 while (size && len) {
282 out = snprint_line(output, size, &data[ofs],
283 min_t(size_t, len, 16U), ofs);
284
285 ofs += 16;
286 output += out;
287 size -= out;
288 len -= min_t(size_t, len, 16U);
289 total += out;
290 }
291 return total;
292}
293
Zhu Yic8fe6672006-01-24 16:36:36 +0800294/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600295static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
296#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
297
Zhu Yic8fe6672006-01-24 16:36:36 +0800298/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600299static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
300#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
301
Zhu Yic8fe6672006-01-24 16:36:36 +0800302/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600303static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
304static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
305{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400306 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
307 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600308 _ipw_write_reg8(a, b, c);
309}
310
Zhu Yic8fe6672006-01-24 16:36:36 +0800311/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600312static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
313static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
314{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
316 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600317 _ipw_write_reg16(a, b, c);
318}
319
Zhu Yic8fe6672006-01-24 16:36:36 +0800320/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600321static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
322static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
323{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400324 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
325 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 _ipw_write_reg32(a, b, c);
327}
328
Zhu Yic8fe6672006-01-24 16:36:36 +0800329/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100330static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
331 u8 val)
332{
333 writeb(val, ipw->hw_base + ofs);
334}
Zhu Yic8fe6672006-01-24 16:36:36 +0800335
336/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200337#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100338 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
339 __LINE__, (u32)(ofs), (u32)(val)); \
340 _ipw_write8(ipw, ofs, val); \
341} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600342
Zhu Yic8fe6672006-01-24 16:36:36 +0800343/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100344static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
345 u16 val)
346{
347 writew(val, ipw->hw_base + ofs);
348}
Zhu Yic8fe6672006-01-24 16:36:36 +0800349
350/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100351#define ipw_write16(ipw, ofs, val) do { \
352 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
353 __LINE__, (u32)(ofs), (u32)(val)); \
354 _ipw_write16(ipw, ofs, val); \
355} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600356
Zhu Yic8fe6672006-01-24 16:36:36 +0800357/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100358static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
359 u32 val)
360{
361 writel(val, ipw->hw_base + ofs);
362}
Zhu Yic8fe6672006-01-24 16:36:36 +0800363
364/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100365#define ipw_write32(ipw, ofs, val) do { \
366 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
367 __LINE__, (u32)(ofs), (u32)(val)); \
368 _ipw_write32(ipw, ofs, val); \
369} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600370
Zhu Yic8fe6672006-01-24 16:36:36 +0800371/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100372static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400373{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100374 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600375}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400376
Zhu Yic8fe6672006-01-24 16:36:36 +0800377/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100378#define ipw_read8(ipw, ofs) ({ \
379 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
380 (u32)(ofs)); \
381 _ipw_read8(ipw, ofs); \
382})
James Ketrenos43f66a62005-03-25 12:31:53 -0600383
Zhu Yic8fe6672006-01-24 16:36:36 +0800384/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100385static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400386{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100387 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600388}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400389
Zhu Yic8fe6672006-01-24 16:36:36 +0800390/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100391#define ipw_read16(ipw, ofs) ({ \
392 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
393 (u32)(ofs)); \
394 _ipw_read16(ipw, ofs); \
395})
James Ketrenos43f66a62005-03-25 12:31:53 -0600396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100398static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400399{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100400 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600401}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400402
Zhu Yic8fe6672006-01-24 16:36:36 +0800403/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100404#define ipw_read32(ipw, ofs) ({ \
405 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
406 (u32)(ofs)); \
407 _ipw_read32(ipw, ofs); \
408})
James Ketrenos43f66a62005-03-25 12:31:53 -0600409
410static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800411/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100412#define ipw_read_indirect(a, b, c, d) ({ \
413 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
414 __LINE__, (u32)(b), (u32)(d)); \
415 _ipw_read_indirect(a, b, c, d); \
416})
James Ketrenos43f66a62005-03-25 12:31:53 -0600417
Zhu Yic8fe6672006-01-24 16:36:36 +0800418/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400419static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
420 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100421#define ipw_write_indirect(a, b, c, d) do { \
422 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
423 __LINE__, (u32)(b), (u32)(d)); \
424 _ipw_write_indirect(a, b, c, d); \
425} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600426
Zhu Yic8fe6672006-01-24 16:36:36 +0800427/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400428static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600429{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400430 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500431 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
432 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600433}
434
Zhu Yic8fe6672006-01-24 16:36:36 +0800435/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600436static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
437{
Zhu Yi2638bc32006-01-24 16:37:52 +0800438 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800439 u32 dif_len = reg - aligned_addr;
440
James Ketrenos43f66a62005-03-25 12:31:53 -0600441 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800442 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
443 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600444}
445
Zhu Yic8fe6672006-01-24 16:36:36 +0800446/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400447static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600448{
Zhu Yi2638bc32006-01-24 16:37:52 +0800449 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800450 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
451
James Ketrenos43f66a62005-03-25 12:31:53 -0600452 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800453 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
454 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600455}
456
Zhu Yic8fe6672006-01-24 16:36:36 +0800457/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600458static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
459{
460 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500461 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100462 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500463 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400464 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600465}
466
Zhu Yic8fe6672006-01-24 16:36:36 +0800467/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600468static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
469{
470 u32 value;
471
472 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
473
James Ketrenosb095c382005-08-24 22:04:42 -0500474 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
475 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100476 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600477 return value;
478}
479
Zhu Yic8fe6672006-01-24 16:36:36 +0800480/* General purpose, no alignment requirement, iterative (multi-byte) read, */
481/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600482static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
483 int num)
484{
Zhu Yi2638bc32006-01-24 16:37:52 +0800485 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400488
James Ketrenos43f66a62005-03-25 12:31:53 -0600489 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
490
James Ketrenosea2b26e2005-08-24 21:25:16 -0500491 if (num <= 0) {
492 return;
493 }
494
Zhu Yic8fe6672006-01-24 16:36:36 +0800495 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600496 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500497 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600498 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500499 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500500 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600501 aligned_addr += 4;
502 }
503
Zhu Yic8fe6672006-01-24 16:36:36 +0800504 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500505 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500506 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500507 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400508
Zhu Yic8fe6672006-01-24 16:36:36 +0800509 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500510 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500511 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500512 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500513 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500514 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600515}
516
Zhu Yic8fe6672006-01-24 16:36:36 +0800517/* General purpose, no alignment requirement, iterative (multi-byte) write, */
518/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400519static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600520 int num)
521{
Zhu Yi2638bc32006-01-24 16:37:52 +0800522 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600523 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400525
James Ketrenos43f66a62005-03-25 12:31:53 -0600526 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400527
James Ketrenosea2b26e2005-08-24 21:25:16 -0500528 if (num <= 0) {
529 return;
530 }
531
Zhu Yic8fe6672006-01-24 16:36:36 +0800532 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600533 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500534 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800535 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500536 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500537 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600538 aligned_addr += 4;
539 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400540
Zhu Yic8fe6672006-01-24 16:36:36 +0800541 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500542 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500543 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500544 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400545
Zhu Yic8fe6672006-01-24 16:36:36 +0800546 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500547 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500548 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500549 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500550 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500551 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600552}
553
Zhu Yic8fe6672006-01-24 16:36:36 +0800554/* General purpose, no alignment requirement, iterative (multi-byte) write, */
555/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400556static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600557 int num)
558{
559 memcpy_toio((priv->hw_base + addr), buf, num);
560}
561
Zhu Yic8fe6672006-01-24 16:36:36 +0800562/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600563static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
564{
565 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
566}
567
Zhu Yic8fe6672006-01-24 16:36:36 +0800568/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600569static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
570{
571 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
572}
573
Zhu Yi89c318e2006-06-08 22:19:49 -0700574static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600575{
576 if (priv->status & STATUS_INT_ENABLED)
577 return;
578 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500579 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600580}
581
Zhu Yi89c318e2006-06-08 22:19:49 -0700582static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600583{
584 if (!(priv->status & STATUS_INT_ENABLED))
585 return;
586 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500587 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600588}
589
Zhu Yi89c318e2006-06-08 22:19:49 -0700590static inline void ipw_enable_interrupts(struct ipw_priv *priv)
591{
592 unsigned long flags;
593
594 spin_lock_irqsave(&priv->irq_lock, flags);
595 __ipw_enable_interrupts(priv);
596 spin_unlock_irqrestore(&priv->irq_lock, flags);
597}
598
599static inline void ipw_disable_interrupts(struct ipw_priv *priv)
600{
601 unsigned long flags;
602
603 spin_lock_irqsave(&priv->irq_lock, flags);
604 __ipw_disable_interrupts(priv);
605 spin_unlock_irqrestore(&priv->irq_lock, flags);
606}
607
James Ketrenos43f66a62005-03-25 12:31:53 -0600608static char *ipw_error_desc(u32 val)
609{
610 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400611 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600612 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400613 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600614 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400615 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600616 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400617 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400619 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500620 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400621 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500622 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400623 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500624 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400625 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500626 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400627 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500628 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400629 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500630 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400631 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500632 return "DMA_STATUS";
633 case IPW_FW_ERROR_DINO_ERROR:
634 return "DINO_ERROR";
635 case IPW_FW_ERROR_EEPROM_ERROR:
636 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400637 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500638 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400639 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500640 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400641 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500642 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600643 }
644}
645
James Ketrenosb39860c2005-08-12 09:36:32 -0500646static void ipw_dump_error_log(struct ipw_priv *priv,
647 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600648{
James Ketrenosb39860c2005-08-12 09:36:32 -0500649 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600650
James Ketrenosb39860c2005-08-12 09:36:32 -0500651 if (!error) {
652 IPW_ERROR("Error allocating and capturing error log. "
653 "Nothing to dump.\n");
654 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600655 }
656
James Ketrenosb39860c2005-08-12 09:36:32 -0500657 IPW_ERROR("Start IPW Error Log Dump:\n");
658 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
659 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600660
James Ketrenosb39860c2005-08-12 09:36:32 -0500661 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400662 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500663 ipw_error_desc(error->elem[i].desc),
664 error->elem[i].time,
665 error->elem[i].blink1,
666 error->elem[i].blink2,
667 error->elem[i].link1,
668 error->elem[i].link2, error->elem[i].data);
669 for (i = 0; i < error->log_len; i++)
670 IPW_ERROR("%i\t0x%08x\t%i\n",
671 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500672 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600673}
James Ketrenos43f66a62005-03-25 12:31:53 -0600674
James Ketrenosc848d0a2005-08-24 21:56:24 -0500675static inline int ipw_is_init(struct ipw_priv *priv)
676{
677 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600678}
679
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400680static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600681{
682 u32 addr, field_info, field_len, field_count, total_len;
683
684 IPW_DEBUG_ORD("ordinal = %i\n", ord);
685
686 if (!priv || !val || !len) {
687 IPW_DEBUG_ORD("Invalid argument\n");
688 return -EINVAL;
689 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400690
James Ketrenos43f66a62005-03-25 12:31:53 -0600691 /* verify device ordinal tables have been initialized */
692 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
693 IPW_DEBUG_ORD("Access ordinals before initialization\n");
694 return -EINVAL;
695 }
696
697 switch (IPW_ORD_TABLE_ID_MASK & ord) {
698 case IPW_ORD_TABLE_0_MASK:
699 /*
700 * TABLE 0: Direct access to a table of 32 bit values
701 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400702 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600703 * read from the table
704 */
705
706 /* remove the table id from the ordinal */
707 ord &= IPW_ORD_TABLE_VALUE_MASK;
708
709 /* boundary check */
710 if (ord > priv->table0_len) {
711 IPW_DEBUG_ORD("ordinal value (%i) longer then "
712 "max (%i)\n", ord, priv->table0_len);
713 return -EINVAL;
714 }
715
716 /* verify we have enough room to store the value */
717 if (*len < sizeof(u32)) {
718 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200719 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600720 return -EINVAL;
721 }
722
723 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400724 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600725
726 *len = sizeof(u32);
727 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400728 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600729 break;
730
731 case IPW_ORD_TABLE_1_MASK:
732 /*
733 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400734 *
735 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600736 * representing starting addr for the data (which is
737 * also a u32)
738 */
739
740 /* remove the table id from the ordinal */
741 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400742
James Ketrenos43f66a62005-03-25 12:31:53 -0600743 /* boundary check */
744 if (ord > priv->table1_len) {
745 IPW_DEBUG_ORD("ordinal value too long\n");
746 return -EINVAL;
747 }
748
749 /* verify we have enough room to store the value */
750 if (*len < sizeof(u32)) {
751 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200752 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600753 return -EINVAL;
754 }
755
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400756 *((u32 *) val) =
757 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600758 *len = sizeof(u32);
759 break;
760
761 case IPW_ORD_TABLE_2_MASK:
762 /*
763 * TABLE 2: Indirect access to a table of variable sized values
764 *
765 * This table consist of six values, each containing
766 * - dword containing the starting offset of the data
767 * - dword containing the lengh in the first 16bits
768 * and the count in the second 16bits
769 */
770
771 /* remove the table id from the ordinal */
772 ord &= IPW_ORD_TABLE_VALUE_MASK;
773
774 /* boundary check */
775 if (ord > priv->table2_len) {
776 IPW_DEBUG_ORD("ordinal value too long\n");
777 return -EINVAL;
778 }
779
780 /* get the address of statistic */
781 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400782
783 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600784 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400785 field_info =
786 ipw_read_reg32(priv,
787 priv->table2_addr + (ord << 3) +
788 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400789
James Ketrenos43f66a62005-03-25 12:31:53 -0600790 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400791 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400792
James Ketrenos43f66a62005-03-25 12:31:53 -0600793 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400794 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400795
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200796 /* abort if not enough memory */
James Ketrenos43f66a62005-03-25 12:31:53 -0600797 total_len = field_len * field_count;
798 if (total_len > *len) {
799 *len = total_len;
800 return -EINVAL;
801 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400802
James Ketrenos43f66a62005-03-25 12:31:53 -0600803 *len = total_len;
804 if (!total_len)
805 return 0;
806
807 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400808 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600809 addr, total_len, field_info);
810 ipw_read_indirect(priv, addr, val, total_len);
811 break;
812
813 default:
814 IPW_DEBUG_ORD("Invalid ordinal!\n");
815 return -EINVAL;
816
817 }
818
James Ketrenos43f66a62005-03-25 12:31:53 -0600819 return 0;
820}
821
822static void ipw_init_ordinals(struct ipw_priv *priv)
823{
824 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400825 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600826
827 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
828 priv->table0_addr, priv->table0_len);
829
830 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
831 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
832
833 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
834 priv->table1_addr, priv->table1_len);
835
836 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
837 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400838 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600839
840 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
841 priv->table2_addr, priv->table2_len);
842
843}
844
Adrian Bunka73e22b2006-01-21 01:39:42 +0100845static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500846{
James Ketrenosb095c382005-08-24 22:04:42 -0500847 reg &= ~IPW_START_STANDBY;
848 if (reg & IPW_GATE_ODMA)
849 reg &= ~IPW_GATE_ODMA;
850 if (reg & IPW_GATE_IDMA)
851 reg &= ~IPW_GATE_IDMA;
852 if (reg & IPW_GATE_ADMA)
853 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500854 return reg;
855}
856
857/*
858 * LED behavior:
859 * - On radio ON, turn on any LEDs that require to be on during start
860 * - On initialization, start unassociated blink
861 * - On association, disable unassociated blink
862 * - On disassociation, start unassociated blink
863 * - On radio OFF, turn off any LEDs started during radio on
864 *
865 */
Zhu Yiede61112006-01-24 16:37:10 +0800866#define LD_TIME_LINK_ON msecs_to_jiffies(300)
867#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
868#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500869
Adrian Bunka73e22b2006-01-21 01:39:42 +0100870static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500871{
872 unsigned long flags;
873 u32 led;
874
875 /* If configured to not use LEDs, or nic_type is 1,
876 * then we don't toggle a LINK led */
877 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
878 return;
879
880 spin_lock_irqsave(&priv->lock, flags);
881
882 if (!(priv->status & STATUS_RF_KILL_MASK) &&
883 !(priv->status & STATUS_LED_LINK_ON)) {
884 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500885 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500886 led |= priv->led_association_on;
887
888 led = ipw_register_toggle(led);
889
890 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500891 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500892
893 priv->status |= STATUS_LED_LINK_ON;
894
895 /* If we aren't associated, schedule turning the LED off */
896 if (!(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100897 schedule_delayed_work(&priv->led_link_off,
898 LD_TIME_LINK_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500899 }
900
901 spin_unlock_irqrestore(&priv->lock, flags);
902}
903
David Howellsc4028952006-11-22 14:57:56 +0000904static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500905{
David Howellsc4028952006-11-22 14:57:56 +0000906 struct ipw_priv *priv =
907 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800908 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000909 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800910 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500911}
912
Adrian Bunka73e22b2006-01-21 01:39:42 +0100913static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500914{
915 unsigned long flags;
916 u32 led;
917
918 /* If configured not to use LEDs, or nic type is 1,
919 * then we don't goggle the LINK led. */
920 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
921 return;
922
923 spin_lock_irqsave(&priv->lock, flags);
924
925 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500926 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500927 led &= priv->led_association_off;
928 led = ipw_register_toggle(led);
929
930 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500931 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500932
933 IPW_DEBUG_LED("Link LED Off\n");
934
935 priv->status &= ~STATUS_LED_LINK_ON;
936
937 /* If we aren't associated and the radio is on, schedule
938 * turning the LED on (blink while unassociated) */
939 if (!(priv->status & STATUS_RF_KILL_MASK) &&
940 !(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100941 schedule_delayed_work(&priv->led_link_on,
942 LD_TIME_LINK_OFF);
James Ketrenosa613bff2005-08-24 21:43:11 -0500943
944 }
945
946 spin_unlock_irqrestore(&priv->lock, flags);
947}
948
David Howellsc4028952006-11-22 14:57:56 +0000949static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500950{
David Howellsc4028952006-11-22 14:57:56 +0000951 struct ipw_priv *priv =
952 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800953 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000954 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800955 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500956}
957
Arjan van de Ven858119e2006-01-14 13:20:43 -0800958static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500959{
James Ketrenosa613bff2005-08-24 21:43:11 -0500960 u32 led;
961
962 if (priv->config & CFG_NO_LED)
963 return;
964
James Ketrenosb095c382005-08-24 22:04:42 -0500965 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500966 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500967
968 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500969 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500970 led |= priv->led_activity_on;
971
972 led = ipw_register_toggle(led);
973
974 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500975 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500976
977 IPW_DEBUG_LED("Activity LED On\n");
978
979 priv->status |= STATUS_LED_ACT_ON;
980
James Ketrenosc848d0a2005-08-24 21:56:24 -0500981 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100982 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500983 } else {
984 /* Reschedule LED off for full time period */
985 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100986 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500987 }
James Ketrenosb095c382005-08-24 22:04:42 -0500988}
James Ketrenosa613bff2005-08-24 21:43:11 -0500989
Adrian Bunka73e22b2006-01-21 01:39:42 +0100990#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500991void ipw_led_activity_on(struct ipw_priv *priv)
992{
993 unsigned long flags;
994 spin_lock_irqsave(&priv->lock, flags);
995 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500996 spin_unlock_irqrestore(&priv->lock, flags);
997}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100998#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500999
Adrian Bunka73e22b2006-01-21 01:39:42 +01001000static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001001{
1002 unsigned long flags;
1003 u32 led;
1004
1005 if (priv->config & CFG_NO_LED)
1006 return;
1007
1008 spin_lock_irqsave(&priv->lock, flags);
1009
1010 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001011 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001012 led &= priv->led_activity_off;
1013
1014 led = ipw_register_toggle(led);
1015
1016 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001017 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001018
1019 IPW_DEBUG_LED("Activity LED Off\n");
1020
1021 priv->status &= ~STATUS_LED_ACT_ON;
1022 }
1023
1024 spin_unlock_irqrestore(&priv->lock, flags);
1025}
1026
David Howellsc4028952006-11-22 14:57:56 +00001027static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001028{
David Howellsc4028952006-11-22 14:57:56 +00001029 struct ipw_priv *priv =
1030 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001031 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001032 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001033 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001034}
1035
Adrian Bunka73e22b2006-01-21 01:39:42 +01001036static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001037{
1038 unsigned long flags;
1039 u32 led;
1040
1041 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001042 if (priv->config & CFG_NO_LED ||
1043 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001044 return;
1045
1046 spin_lock_irqsave(&priv->lock, flags);
1047
James Ketrenosb095c382005-08-24 22:04:42 -05001048 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001049 if (priv->assoc_network->mode == IEEE_A) {
1050 led |= priv->led_ofdm_on;
1051 led &= priv->led_association_off;
1052 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1053 } else if (priv->assoc_network->mode == IEEE_G) {
1054 led |= priv->led_ofdm_on;
1055 led |= priv->led_association_on;
1056 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1057 } else {
1058 led &= priv->led_ofdm_off;
1059 led |= priv->led_association_on;
1060 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1061 }
1062
1063 led = ipw_register_toggle(led);
1064
1065 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001066 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001067
1068 spin_unlock_irqrestore(&priv->lock, flags);
1069}
1070
Adrian Bunka73e22b2006-01-21 01:39:42 +01001071static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001072{
1073 unsigned long flags;
1074 u32 led;
1075
1076 /* Only nic type 1 supports mode LEDs */
1077 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1078 return;
1079
1080 spin_lock_irqsave(&priv->lock, flags);
1081
James Ketrenosb095c382005-08-24 22:04:42 -05001082 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001083 led &= priv->led_ofdm_off;
1084 led &= priv->led_association_off;
1085
1086 led = ipw_register_toggle(led);
1087
1088 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001089 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001090
1091 spin_unlock_irqrestore(&priv->lock, flags);
1092}
1093
Adrian Bunka73e22b2006-01-21 01:39:42 +01001094static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001095{
1096 ipw_led_link_on(priv);
1097}
1098
Adrian Bunka73e22b2006-01-21 01:39:42 +01001099static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001100{
1101 ipw_led_activity_off(priv);
1102 ipw_led_link_off(priv);
1103}
1104
Adrian Bunka73e22b2006-01-21 01:39:42 +01001105static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001106{
1107 /* Set the Link Led on for all nic types */
1108 ipw_led_link_on(priv);
1109}
1110
Adrian Bunka73e22b2006-01-21 01:39:42 +01001111static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001112{
1113 ipw_led_activity_off(priv);
1114 ipw_led_link_off(priv);
1115
1116 if (priv->status & STATUS_RF_KILL_MASK)
1117 ipw_led_radio_off(priv);
1118}
1119
Adrian Bunka73e22b2006-01-21 01:39:42 +01001120static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001121{
1122 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1123
1124 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001125 priv->led_activity_on = IPW_ACTIVITY_LED;
1126 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001127
James Ketrenosb095c382005-08-24 22:04:42 -05001128 priv->led_association_on = IPW_ASSOCIATED_LED;
1129 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001130
1131 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001132 priv->led_ofdm_on = IPW_OFDM_LED;
1133 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001134
1135 switch (priv->nic_type) {
1136 case EEPROM_NIC_TYPE_1:
1137 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001138 priv->led_activity_on = IPW_ASSOCIATED_LED;
1139 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1140 priv->led_association_on = IPW_ACTIVITY_LED;
1141 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001142
1143 if (!(priv->config & CFG_NO_LED))
1144 ipw_led_band_on(priv);
1145
1146 /* And we don't blink link LEDs for this nic, so
1147 * just return here */
1148 return;
1149
1150 case EEPROM_NIC_TYPE_3:
1151 case EEPROM_NIC_TYPE_2:
1152 case EEPROM_NIC_TYPE_4:
1153 case EEPROM_NIC_TYPE_0:
1154 break;
1155
1156 default:
1157 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1158 priv->nic_type);
1159 priv->nic_type = EEPROM_NIC_TYPE_0;
1160 break;
1161 }
1162
1163 if (!(priv->config & CFG_NO_LED)) {
1164 if (priv->status & STATUS_ASSOCIATED)
1165 ipw_led_link_on(priv);
1166 else
1167 ipw_led_link_off(priv);
1168 }
1169}
1170
Adrian Bunka73e22b2006-01-21 01:39:42 +01001171static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001172{
James Ketrenosa613bff2005-08-24 21:43:11 -05001173 ipw_led_activity_off(priv);
1174 ipw_led_link_off(priv);
1175 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001176 cancel_delayed_work(&priv->led_link_on);
1177 cancel_delayed_work(&priv->led_link_off);
1178 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001179}
1180
James Ketrenos43f66a62005-03-25 12:31:53 -06001181/*
1182 * The following adds a new attribute to the sysfs representation
1183 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001184 * used for controlling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001185 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001186 * See the level definitions in ipw for details.
1187 */
1188static ssize_t show_debug_level(struct device_driver *d, char *buf)
1189{
1190 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1191}
James Ketrenosa613bff2005-08-24 21:43:11 -05001192
1193static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1194 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001195{
1196 char *p = (char *)buf;
1197 u32 val;
1198
1199 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1200 p++;
1201 if (p[0] == 'x' || p[0] == 'X')
1202 p++;
1203 val = simple_strtoul(p, &p, 16);
1204 } else
1205 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001206 if (p == buf)
1207 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001208 ": %s is not in hex or decimal form.\n", buf);
1209 else
1210 ipw_debug_level = val;
1211
1212 return strnlen(buf, count);
1213}
1214
Jeff Garzikbf794512005-07-31 13:07:26 -04001215static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001216 show_debug_level, store_debug_level);
1217
James Ketrenosb39860c2005-08-12 09:36:32 -05001218static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1219{
Zhu Yic8fe6672006-01-24 16:36:36 +08001220 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001221 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1222}
1223
1224static void ipw_capture_event_log(struct ipw_priv *priv,
1225 u32 log_len, struct ipw_event *log)
1226{
1227 u32 base;
1228
1229 if (log_len) {
1230 base = ipw_read32(priv, IPW_EVENT_LOG);
1231 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1232 (u8 *) log, sizeof(*log) * log_len);
1233 }
1234}
1235
1236static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1237{
1238 struct ipw_fw_error *error;
1239 u32 log_len = ipw_get_event_log_len(priv);
1240 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1241 u32 elem_len = ipw_read_reg32(priv, base);
1242
1243 error = kmalloc(sizeof(*error) +
1244 sizeof(*error->elem) * elem_len +
1245 sizeof(*error->log) * log_len, GFP_ATOMIC);
1246 if (!error) {
1247 IPW_ERROR("Memory allocation for firmware error log "
1248 "failed.\n");
1249 return NULL;
1250 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001251 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001252 error->status = priv->status;
1253 error->config = priv->config;
1254 error->elem_len = elem_len;
1255 error->log_len = log_len;
1256 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001257 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001258
1259 ipw_capture_event_log(priv, log_len, error->log);
1260
1261 if (elem_len)
1262 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1263 sizeof(*error->elem) * elem_len);
1264
1265 return error;
1266}
1267
James Ketrenosb39860c2005-08-12 09:36:32 -05001268static ssize_t show_event_log(struct device *d,
1269 struct device_attribute *attr, char *buf)
1270{
1271 struct ipw_priv *priv = dev_get_drvdata(d);
1272 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001273 u32 log_size;
1274 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001275 u32 len = 0, i;
1276
Reinette Chatre412e9e72007-12-18 22:01:02 -08001277 /* not using min() because of its strict type checking */
1278 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1279 sizeof(*log) * log_len : PAGE_SIZE;
1280 log = kzalloc(log_size, GFP_KERNEL);
1281 if (!log) {
1282 IPW_ERROR("Unable to allocate memory for log\n");
1283 return 0;
1284 }
1285 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001286 ipw_capture_event_log(priv, log_len, log);
1287
1288 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1289 for (i = 0; i < log_len; i++)
1290 len += snprintf(buf + len, PAGE_SIZE - len,
1291 "\n%08X%08X%08X",
1292 log[i].time, log[i].event, log[i].data);
1293 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001294 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001295 return len;
1296}
1297
1298static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1299
1300static ssize_t show_error(struct device *d,
1301 struct device_attribute *attr, char *buf)
1302{
1303 struct ipw_priv *priv = dev_get_drvdata(d);
1304 u32 len = 0, i;
1305 if (!priv->error)
1306 return 0;
1307 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001308 "%08lX%08X%08X%08X",
1309 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001310 priv->error->status,
1311 priv->error->config, priv->error->elem_len);
1312 for (i = 0; i < priv->error->elem_len; i++)
1313 len += snprintf(buf + len, PAGE_SIZE - len,
1314 "\n%08X%08X%08X%08X%08X%08X%08X",
1315 priv->error->elem[i].time,
1316 priv->error->elem[i].desc,
1317 priv->error->elem[i].blink1,
1318 priv->error->elem[i].blink2,
1319 priv->error->elem[i].link1,
1320 priv->error->elem[i].link2,
1321 priv->error->elem[i].data);
1322
1323 len += snprintf(buf + len, PAGE_SIZE - len,
1324 "\n%08X", priv->error->log_len);
1325 for (i = 0; i < priv->error->log_len; i++)
1326 len += snprintf(buf + len, PAGE_SIZE - len,
1327 "\n%08X%08X%08X",
1328 priv->error->log[i].time,
1329 priv->error->log[i].event,
1330 priv->error->log[i].data);
1331 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1332 return len;
1333}
1334
1335static ssize_t clear_error(struct device *d,
1336 struct device_attribute *attr,
1337 const char *buf, size_t count)
1338{
1339 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001340
1341 kfree(priv->error);
1342 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001343 return count;
1344}
1345
1346static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1347
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001348static ssize_t show_cmd_log(struct device *d,
1349 struct device_attribute *attr, char *buf)
1350{
1351 struct ipw_priv *priv = dev_get_drvdata(d);
1352 u32 len = 0, i;
1353 if (!priv->cmdlog)
1354 return 0;
1355 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1356 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1357 i = (i + 1) % priv->cmdlog_len) {
1358 len +=
1359 snprintf(buf + len, PAGE_SIZE - len,
1360 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1361 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1362 priv->cmdlog[i].cmd.len);
1363 len +=
1364 snprintk_buf(buf + len, PAGE_SIZE - len,
1365 (u8 *) priv->cmdlog[i].cmd.param,
1366 priv->cmdlog[i].cmd.len);
1367 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1368 }
1369 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1370 return len;
1371}
1372
1373static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1374
Zhu Yid685b8c2006-04-13 17:20:27 +08001375#ifdef CONFIG_IPW2200_PROMISCUOUS
1376static void ipw_prom_free(struct ipw_priv *priv);
1377static int ipw_prom_alloc(struct ipw_priv *priv);
1378static ssize_t store_rtap_iface(struct device *d,
1379 struct device_attribute *attr,
1380 const char *buf, size_t count)
1381{
1382 struct ipw_priv *priv = dev_get_drvdata(d);
1383 int rc = 0;
1384
1385 if (count < 1)
1386 return -EINVAL;
1387
1388 switch (buf[0]) {
1389 case '0':
1390 if (!rtap_iface)
1391 return count;
1392
1393 if (netif_running(priv->prom_net_dev)) {
1394 IPW_WARNING("Interface is up. Cannot unregister.\n");
1395 return count;
1396 }
1397
1398 ipw_prom_free(priv);
1399 rtap_iface = 0;
1400 break;
1401
1402 case '1':
1403 if (rtap_iface)
1404 return count;
1405
1406 rc = ipw_prom_alloc(priv);
1407 if (!rc)
1408 rtap_iface = 1;
1409 break;
1410
1411 default:
1412 return -EINVAL;
1413 }
1414
1415 if (rc) {
1416 IPW_ERROR("Failed to register promiscuous network "
1417 "device (error %d).\n", rc);
1418 }
1419
1420 return count;
1421}
1422
1423static ssize_t show_rtap_iface(struct device *d,
1424 struct device_attribute *attr,
1425 char *buf)
1426{
1427 struct ipw_priv *priv = dev_get_drvdata(d);
1428 if (rtap_iface)
1429 return sprintf(buf, "%s", priv->prom_net_dev->name);
1430 else {
1431 buf[0] = '-';
1432 buf[1] = '1';
1433 buf[2] = '\0';
1434 return 3;
1435 }
1436}
1437
1438static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1439 store_rtap_iface);
1440
1441static ssize_t store_rtap_filter(struct device *d,
1442 struct device_attribute *attr,
1443 const char *buf, size_t count)
1444{
1445 struct ipw_priv *priv = dev_get_drvdata(d);
1446
1447 if (!priv->prom_priv) {
1448 IPW_ERROR("Attempting to set filter without "
1449 "rtap_iface enabled.\n");
1450 return -EPERM;
1451 }
1452
1453 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1454
1455 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1456 BIT_ARG16(priv->prom_priv->filter));
1457
1458 return count;
1459}
1460
1461static ssize_t show_rtap_filter(struct device *d,
1462 struct device_attribute *attr,
1463 char *buf)
1464{
1465 struct ipw_priv *priv = dev_get_drvdata(d);
1466 return sprintf(buf, "0x%04X",
1467 priv->prom_priv ? priv->prom_priv->filter : 0);
1468}
1469
1470static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1471 store_rtap_filter);
1472#endif
1473
James Ketrenosa613bff2005-08-24 21:43:11 -05001474static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1475 char *buf)
1476{
1477 struct ipw_priv *priv = dev_get_drvdata(d);
1478 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1479}
1480
1481static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1482 const char *buf, size_t count)
1483{
1484 struct ipw_priv *priv = dev_get_drvdata(d);
1485 struct net_device *dev = priv->net_dev;
1486 char buffer[] = "00000000";
1487 unsigned long len =
1488 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1489 unsigned long val;
1490 char *p = buffer;
1491
1492 IPW_DEBUG_INFO("enter\n");
1493
1494 strncpy(buffer, buf, len);
1495 buffer[len] = 0;
1496
1497 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1498 p++;
1499 if (p[0] == 'x' || p[0] == 'X')
1500 p++;
1501 val = simple_strtoul(p, &p, 16);
1502 } else
1503 val = simple_strtoul(p, &p, 10);
1504 if (p == buffer) {
1505 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1506 } else {
1507 priv->ieee->scan_age = val;
1508 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1509 }
1510
1511 IPW_DEBUG_INFO("exit\n");
1512 return len;
1513}
1514
1515static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1516
1517static ssize_t show_led(struct device *d, struct device_attribute *attr,
1518 char *buf)
1519{
1520 struct ipw_priv *priv = dev_get_drvdata(d);
1521 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1522}
1523
1524static ssize_t store_led(struct device *d, struct device_attribute *attr,
1525 const char *buf, size_t count)
1526{
1527 struct ipw_priv *priv = dev_get_drvdata(d);
1528
1529 IPW_DEBUG_INFO("enter\n");
1530
1531 if (count == 0)
1532 return 0;
1533
1534 if (*buf == 0) {
1535 IPW_DEBUG_LED("Disabling LED control.\n");
1536 priv->config |= CFG_NO_LED;
1537 ipw_led_shutdown(priv);
1538 } else {
1539 IPW_DEBUG_LED("Enabling LED control.\n");
1540 priv->config &= ~CFG_NO_LED;
1541 ipw_led_init(priv);
1542 }
1543
1544 IPW_DEBUG_INFO("exit\n");
1545 return count;
1546}
1547
1548static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1549
Andrew Mortonad3fee52005-06-20 14:30:36 -07001550static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001551 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001552{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001553 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001554 return sprintf(buf, "0x%08x\n", (int)p->status);
1555}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001556
James Ketrenos43f66a62005-03-25 12:31:53 -06001557static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1558
Andrew Mortonad3fee52005-06-20 14:30:36 -07001559static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1560 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001561{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001562 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001563 return sprintf(buf, "0x%08x\n", (int)p->config);
1564}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565
James Ketrenos43f66a62005-03-25 12:31:53 -06001566static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1567
Andrew Mortonad3fee52005-06-20 14:30:36 -07001568static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001569 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001570{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001571 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001572 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001573}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001574
James Ketrenos43f66a62005-03-25 12:31:53 -06001575static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1576
Andrew Mortonad3fee52005-06-20 14:30:36 -07001577static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001579{
1580 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001581 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001582
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001584 return 0;
1585
1586 return sprintf(buf, "0x%08x\n", tmp);
1587}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001588
1589static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001590
Andrew Mortonad3fee52005-06-20 14:30:36 -07001591static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1592 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001593{
1594 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001595 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001596
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001597 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001598 return 0;
1599
1600 return sprintf(buf, "0x%08x\n", tmp);
1601}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001602
1603static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001604
1605/*
1606 * Add a device attribute to view/control the delay between eeprom
1607 * operations.
1608 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001609static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001610 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001611{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001612 struct ipw_priv *p = dev_get_drvdata(d);
1613 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001614 return sprintf(buf, "%i\n", n);
1615}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001616static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001617 struct device_attribute *attr,
1618 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001619{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001620 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001621 sscanf(buf, "%i", &p->eeprom_delay);
1622 return strnlen(buf, count);
1623}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001624
1625static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1626 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001627
Andrew Mortonad3fee52005-06-20 14:30:36 -07001628static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001629 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001630{
1631 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001632 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001633
James Ketrenosb095c382005-08-24 22:04:42 -05001634 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001635 return sprintf(buf, "0x%08x\n", reg);
1636}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001637static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001638 struct device_attribute *attr,
1639 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001640{
1641 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001642 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001643
1644 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001645 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001646 return strnlen(buf, count);
1647}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001648
1649static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1650 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001651
Andrew Mortonad3fee52005-06-20 14:30:36 -07001652static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001653 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001654{
1655 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001656 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001657
1658 reg = ipw_read_reg32(p, 0x301100);
1659 return sprintf(buf, "0x%08x\n", reg);
1660}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001661static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001662 struct device_attribute *attr,
1663 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001664{
1665 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001666 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001667
1668 sscanf(buf, "%x", &reg);
1669 ipw_write_reg32(p, 0x301100, reg);
1670 return strnlen(buf, count);
1671}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001672
1673static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1674 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001675
Andrew Mortonad3fee52005-06-20 14:30:36 -07001676static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001677 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001678{
1679 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001680 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001681
Jeff Garzikbf794512005-07-31 13:07:26 -04001682 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001683 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001684 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001685 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001686
James Ketrenos43f66a62005-03-25 12:31:53 -06001687 return sprintf(buf, "0x%08x\n", reg);
1688}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001689static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001690 struct device_attribute *attr,
1691 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001692{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001693 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001694
1695 sscanf(buf, "%x", &priv->indirect_dword);
1696 priv->status |= STATUS_INDIRECT_DWORD;
1697 return strnlen(buf, count);
1698}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001699
1700static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1701 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001702
Andrew Mortonad3fee52005-06-20 14:30:36 -07001703static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001704 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001705{
1706 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001707 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001708
Jeff Garzikbf794512005-07-31 13:07:26 -04001709 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001710 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001711 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001712 reg = 0;
1713
1714 return sprintf(buf, "0x%02x\n", reg);
1715}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001716static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001717 struct device_attribute *attr,
1718 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001719{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001720 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001721
1722 sscanf(buf, "%x", &priv->indirect_byte);
1723 priv->status |= STATUS_INDIRECT_BYTE;
1724 return strnlen(buf, count);
1725}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001726
1727static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001728 show_indirect_byte, store_indirect_byte);
1729
Andrew Mortonad3fee52005-06-20 14:30:36 -07001730static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001731 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001732{
1733 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001734 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001735
Jeff Garzikbf794512005-07-31 13:07:26 -04001736 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001737 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001738 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 reg = 0;
1740
1741 return sprintf(buf, "0x%08x\n", reg);
1742}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001743static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001744 struct device_attribute *attr,
1745 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001746{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001747 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001748
1749 sscanf(buf, "%x", &priv->direct_dword);
1750 priv->status |= STATUS_DIRECT_DWORD;
1751 return strnlen(buf, count);
1752}
James Ketrenos43f66a62005-03-25 12:31:53 -06001753
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001754static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1755 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001756
Arjan van de Ven858119e2006-01-14 13:20:43 -08001757static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001758{
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001759 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001761 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1762 } else {
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, false);
1765 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001766
1767 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1768}
1769
Andrew Mortonad3fee52005-06-20 14:30:36 -07001770static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001771 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001772{
1773 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001774 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001775 2 - HW based RF kill active
1776 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001777 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001779 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001780 return sprintf(buf, "%i\n", val);
1781}
1782
1783static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1784{
Jeff Garzikbf794512005-07-31 13:07:26 -04001785 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001786 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001787 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001788
1789 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1790 disable_radio ? "OFF" : "ON");
1791
1792 if (disable_radio) {
1793 priv->status |= STATUS_RF_KILL_SW;
1794
Tejun Heobcb6d912011-01-26 12:12:50 +01001795 cancel_delayed_work(&priv->request_scan);
1796 cancel_delayed_work(&priv->request_direct_scan);
1797 cancel_delayed_work(&priv->request_passive_scan);
1798 cancel_delayed_work(&priv->scan_event);
1799 schedule_work(&priv->down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001800 } else {
1801 priv->status &= ~STATUS_RF_KILL_SW;
1802 if (rf_kill_active(priv)) {
1803 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1804 "disabled by HW switch\n");
1805 /* Make sure the RF_KILL check timer is running */
1806 cancel_delayed_work(&priv->rf_kill);
Tejun Heobcb6d912011-01-26 12:12:50 +01001807 schedule_delayed_work(&priv->rf_kill,
1808 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001809 } else
Tejun Heobcb6d912011-01-26 12:12:50 +01001810 schedule_work(&priv->up);
James Ketrenos43f66a62005-03-25 12:31:53 -06001811 }
1812
1813 return 1;
1814}
1815
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001816static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1817 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001818{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001819 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001820
James Ketrenos43f66a62005-03-25 12:31:53 -06001821 ipw_radio_kill_sw(priv, buf[0] == '1');
1822
1823 return count;
1824}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001825
1826static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001827
James Ketrenosb095c382005-08-24 22:04:42 -05001828static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1829 char *buf)
1830{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001831 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001832 int pos = 0, len = 0;
1833 if (priv->config & CFG_SPEED_SCAN) {
1834 while (priv->speed_scan[pos] != 0)
1835 len += sprintf(&buf[len], "%d ",
1836 priv->speed_scan[pos++]);
1837 return len + sprintf(&buf[len], "\n");
1838 }
1839
1840 return sprintf(buf, "0\n");
1841}
1842
1843static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1844 const char *buf, size_t count)
1845{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001846 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001847 int channel, pos = 0;
1848 const char *p = buf;
1849
1850 /* list of space separated channels to scan, optionally ending with 0 */
1851 while ((channel = simple_strtol(p, NULL, 0))) {
1852 if (pos == MAX_SPEED_SCAN - 1) {
1853 priv->speed_scan[pos] = 0;
1854 break;
1855 }
1856
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001857 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001858 priv->speed_scan[pos++] = channel;
1859 else
1860 IPW_WARNING("Skipping invalid channel request: %d\n",
1861 channel);
1862 p = strchr(p, ' ');
1863 if (!p)
1864 break;
1865 while (*p == ' ' || *p == '\t')
1866 p++;
1867 }
1868
1869 if (pos == 0)
1870 priv->config &= ~CFG_SPEED_SCAN;
1871 else {
1872 priv->speed_scan_pos = 0;
1873 priv->config |= CFG_SPEED_SCAN;
1874 }
1875
1876 return count;
1877}
1878
1879static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1880 store_speed_scan);
1881
1882static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1883 char *buf)
1884{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001885 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001886 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1887}
1888
1889static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1890 const char *buf, size_t count)
1891{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001892 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001893 if (buf[0] == '1')
1894 priv->config |= CFG_NET_STATS;
1895 else
1896 priv->config &= ~CFG_NET_STATS;
1897
1898 return count;
1899}
1900
James Ketrenosafbf30a2005-08-25 00:05:33 -05001901static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1902 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001903
Zhu Yi375dd242007-02-14 16:04:24 +08001904static ssize_t show_channels(struct device *d,
1905 struct device_attribute *attr,
1906 char *buf)
1907{
1908 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001909 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001910 int len = 0, i;
1911
1912 len = sprintf(&buf[len],
1913 "Displaying %d channels in 2.4Ghz band "
1914 "(802.11bg):\n", geo->bg_channels);
1915
1916 for (i = 0; i < geo->bg_channels; i++) {
1917 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1918 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001919 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001920 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001921 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1922 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001923 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001924 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001925 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001926 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001927 "B" : "B/G");
1928 }
1929
1930 len += sprintf(&buf[len],
1931 "Displaying %d channels in 5.2Ghz band "
1932 "(802.11a):\n", geo->a_channels);
1933 for (i = 0; i < geo->a_channels; i++) {
1934 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1935 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001936 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001937 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001938 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1939 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001940 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001941 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001942 "passive only" : "active/passive");
1943 }
1944
1945 return len;
1946}
1947
1948static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1949
James Ketrenosea2b26e2005-08-24 21:25:16 -05001950static void notify_wx_assoc_event(struct ipw_priv *priv)
1951{
1952 union iwreq_data wrqu;
1953 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1954 if (priv->status & STATUS_ASSOCIATED)
1955 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1956 else
1957 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1958 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1959}
1960
James Ketrenos43f66a62005-03-25 12:31:53 -06001961static void ipw_irq_tasklet(struct ipw_priv *priv)
1962{
1963 u32 inta, inta_mask, handled = 0;
1964 unsigned long flags;
1965 int rc = 0;
1966
Zhu Yi89c318e2006-06-08 22:19:49 -07001967 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001968
James Ketrenosb095c382005-08-24 22:04:42 -05001969 inta = ipw_read32(priv, IPW_INTA_RW);
1970 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Indan Zupancic3c4a8cc2011-01-08 12:17:27 +01001971
1972 if (inta == 0xFFFFFFFF) {
1973 /* Hardware disappeared */
1974 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1975 /* Only handle the cached INTA values */
1976 inta = 0;
1977 }
James Ketrenosb095c382005-08-24 22:04:42 -05001978 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001979
1980 /* Add any cached INTA values that need to be handled */
1981 inta |= priv->isr_inta;
1982
Zhu Yi89c318e2006-06-08 22:19:49 -07001983 spin_unlock_irqrestore(&priv->irq_lock, flags);
1984
1985 spin_lock_irqsave(&priv->lock, flags);
1986
James Ketrenos43f66a62005-03-25 12:31:53 -06001987 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001988 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001989 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001990 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001991 }
1992
James Ketrenosb095c382005-08-24 22:04:42 -05001993 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001995 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 priv->status &= ~STATUS_HCMD_ACTIVE;
1997 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001998 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 }
2000
James Ketrenosb095c382005-08-24 22:04:42 -05002001 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002002 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002003 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002004 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002005 }
2006
James Ketrenosb095c382005-08-24 22:04:42 -05002007 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002009 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002010 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002011 }
2012
James Ketrenosb095c382005-08-24 22:04:42 -05002013 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002014 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002015 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002016 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002017 }
2018
James Ketrenosb095c382005-08-24 22:04:42 -05002019 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002021 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002022 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 }
2024
James Ketrenosb095c382005-08-24 22:04:42 -05002025 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002027 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002028 }
2029
James Ketrenosb095c382005-08-24 22:04:42 -05002030 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002031 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002032 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002033 }
2034
James Ketrenosb095c382005-08-24 22:04:42 -05002035 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002036 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002037 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002038 }
2039
James Ketrenosb095c382005-08-24 22:04:42 -05002040 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002041 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002042 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002043 }
2044
James Ketrenosb095c382005-08-24 22:04:42 -05002045 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002046 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002047 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 }
2049
James Ketrenosb095c382005-08-24 22:04:42 -05002050 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002051 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2052 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002053 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002054 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002055 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002056 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002057 cancel_delayed_work(&priv->request_direct_scan);
2058 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002059 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002060 schedule_work(&priv->link_down);
Tejun Heobcb6d912011-01-26 12:12:50 +01002061 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002062 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002063 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002064
James Ketrenosb095c382005-08-24 22:04:42 -05002065 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002066 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002067 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002068 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002069 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2070 struct ipw_fw_error *error =
2071 ipw_alloc_error_log(priv);
2072 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002073 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002074 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002075 } else {
2076 priv->error = ipw_alloc_error_log(priv);
2077 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002078 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002079 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002080 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2081 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002082 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2083 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002084 }
2085
James Ketrenosb095c382005-08-24 22:04:42 -05002086 /* XXX: If hardware encryption is for WPA/WPA2,
2087 * we have to notify the supplicant. */
2088 if (priv->ieee->sec.encrypt) {
2089 priv->status &= ~STATUS_ASSOCIATED;
2090 notify_wx_assoc_event(priv);
2091 }
2092
2093 /* Keep the restart process from trying to send host
2094 * commands by clearing the INIT status bit */
2095 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002096
2097 /* Cancel currently queued command. */
2098 priv->status &= ~STATUS_HCMD_ACTIVE;
2099 wake_up_interruptible(&priv->wait_command_queue);
2100
Tejun Heobcb6d912011-01-26 12:12:50 +01002101 schedule_work(&priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002102 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002103 }
2104
James Ketrenosb095c382005-08-24 22:04:42 -05002105 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002106 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002107 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002108 }
2109
2110 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002111 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002112 }
2113
Zhu Yi89c318e2006-06-08 22:19:49 -07002114 spin_unlock_irqrestore(&priv->lock, flags);
2115
James Ketrenos43f66a62005-03-25 12:31:53 -06002116 /* enable all interrupts */
2117 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002118}
Jeff Garzikbf794512005-07-31 13:07:26 -04002119
James Ketrenos43f66a62005-03-25 12:31:53 -06002120#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2121static char *get_cmd_string(u8 cmd)
2122{
2123 switch (cmd) {
2124 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002125 IPW_CMD(POWER_DOWN);
2126 IPW_CMD(SYSTEM_CONFIG);
2127 IPW_CMD(MULTICAST_ADDRESS);
2128 IPW_CMD(SSID);
2129 IPW_CMD(ADAPTER_ADDRESS);
2130 IPW_CMD(PORT_TYPE);
2131 IPW_CMD(RTS_THRESHOLD);
2132 IPW_CMD(FRAG_THRESHOLD);
2133 IPW_CMD(POWER_MODE);
2134 IPW_CMD(WEP_KEY);
2135 IPW_CMD(TGI_TX_KEY);
2136 IPW_CMD(SCAN_REQUEST);
2137 IPW_CMD(SCAN_REQUEST_EXT);
2138 IPW_CMD(ASSOCIATE);
2139 IPW_CMD(SUPPORTED_RATES);
2140 IPW_CMD(SCAN_ABORT);
2141 IPW_CMD(TX_FLUSH);
2142 IPW_CMD(QOS_PARAMETERS);
2143 IPW_CMD(DINO_CONFIG);
2144 IPW_CMD(RSN_CAPABILITIES);
2145 IPW_CMD(RX_KEY);
2146 IPW_CMD(CARD_DISABLE);
2147 IPW_CMD(SEED_NUMBER);
2148 IPW_CMD(TX_POWER);
2149 IPW_CMD(COUNTRY_INFO);
2150 IPW_CMD(AIRONET_INFO);
2151 IPW_CMD(AP_TX_POWER);
2152 IPW_CMD(CCKM_INFO);
2153 IPW_CMD(CCX_VER_INFO);
2154 IPW_CMD(SET_CALIBRATION);
2155 IPW_CMD(SENSITIVITY_CALIB);
2156 IPW_CMD(RETRY_LIMIT);
2157 IPW_CMD(IPW_PRE_POWER_DOWN);
2158 IPW_CMD(VAP_BEACON_TEMPLATE);
2159 IPW_CMD(VAP_DTIM_PERIOD);
2160 IPW_CMD(EXT_SUPPORTED_RATES);
2161 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2162 IPW_CMD(VAP_QUIET_INTERVALS);
2163 IPW_CMD(VAP_CHANNEL_SWITCH);
2164 IPW_CMD(VAP_MANDATORY_CHANNELS);
2165 IPW_CMD(VAP_CELL_PWR_LIMIT);
2166 IPW_CMD(VAP_CF_PARAM_SET);
2167 IPW_CMD(VAP_SET_BEACONING_STATE);
2168 IPW_CMD(MEASUREMENT);
2169 IPW_CMD(POWER_CAPABILITY);
2170 IPW_CMD(SUPPORTED_CHANNELS);
2171 IPW_CMD(TPC_REPORT);
2172 IPW_CMD(WME_INFO);
2173 IPW_CMD(PRODUCTION_COMMAND);
2174 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002175 return "UNKNOWN";
2176 }
2177}
James Ketrenos43f66a62005-03-25 12:31:53 -06002178
2179#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002180
2181static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002182{
2183 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002184 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002185
James Ketrenosa613bff2005-08-24 21:43:11 -05002186 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002187 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002188 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2189 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002190 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002191 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002192 }
2193
2194 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002195
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002196 if (priv->cmdlog) {
2197 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2198 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2199 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2200 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2201 cmd->len);
2202 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2203 }
2204
James Ketrenosb095c382005-08-24 22:04:42 -05002205 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2206 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2207 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002208
2209#ifndef DEBUG_CMD_WEP_KEY
2210 if (cmd->cmd == IPW_CMD_WEP_KEY)
2211 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2212 else
2213#endif
2214 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2215
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002216 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002217 if (rc) {
2218 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002219 IPW_ERROR("Failed to send %s: Reason %d\n",
2220 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002221 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002222 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002223 }
2224 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002225
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002226 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2227 !(priv->
2228 status & STATUS_HCMD_ACTIVE),
2229 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002230 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002231 spin_lock_irqsave(&priv->lock, flags);
2232 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002233 IPW_ERROR("Failed to send %s: Command timed out.\n",
2234 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002235 priv->status &= ~STATUS_HCMD_ACTIVE;
2236 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002237 rc = -EIO;
2238 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002239 }
2240 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002241 } else
2242 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002243
James Ketrenosb095c382005-08-24 22:04:42 -05002244 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002245 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2246 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002247 rc = -EIO;
2248 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002249 }
2250
Zhu Yi2638bc32006-01-24 16:37:52 +08002251 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002252 if (priv->cmdlog) {
2253 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2254 priv->cmdlog_pos %= priv->cmdlog_len;
2255 }
2256 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002257}
2258
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002259static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002260{
2261 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002262 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002263 };
2264
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002265 return __ipw_send_cmd(priv, &cmd);
2266}
2267
2268static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2269 void *data)
2270{
2271 struct host_cmd cmd = {
2272 .cmd = command,
2273 .len = len,
2274 .param = data,
2275 };
2276
2277 return __ipw_send_cmd(priv, &cmd);
2278}
2279
2280static int ipw_send_host_complete(struct ipw_priv *priv)
2281{
James Ketrenos43f66a62005-03-25 12:31:53 -06002282 if (!priv) {
2283 IPW_ERROR("Invalid args\n");
2284 return -1;
2285 }
2286
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002287 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002288}
2289
Zhu Yid685b8c2006-04-13 17:20:27 +08002290static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002291{
Zhu Yid685b8c2006-04-13 17:20:27 +08002292 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2293 sizeof(priv->sys_config),
2294 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002295}
2296
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002297static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002298{
James Ketrenos43f66a62005-03-25 12:31:53 -06002299 if (!priv || !ssid) {
2300 IPW_ERROR("Invalid args\n");
2301 return -1;
2302 }
2303
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002304 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002305 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002306}
2307
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002308static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002309{
James Ketrenos43f66a62005-03-25 12:31:53 -06002310 if (!priv || !mac) {
2311 IPW_ERROR("Invalid args\n");
2312 return -1;
2313 }
2314
Johannes Berge1749612008-10-27 15:59:26 -07002315 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2316 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002317
Zhu Yi2638bc32006-01-24 16:37:52 +08002318 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002319}
2320
2321static void ipw_adapter_restart(void *adapter)
2322{
2323 struct ipw_priv *priv = adapter;
2324
2325 if (priv->status & STATUS_RF_KILL_MASK)
2326 return;
2327
2328 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002329
2330 if (priv->assoc_network &&
2331 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2332 ipw_remove_current_network(priv);
2333
James Ketrenos43f66a62005-03-25 12:31:53 -06002334 if (ipw_up(priv)) {
2335 IPW_ERROR("Failed to up device\n");
2336 return;
2337 }
2338}
2339
David Howellsc4028952006-11-22 14:57:56 +00002340static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002341{
David Howellsc4028952006-11-22 14:57:56 +00002342 struct ipw_priv *priv =
2343 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002344 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002345 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002346 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002347}
2348
Zhu Yie65054b2010-03-30 09:36:16 +08002349static void ipw_abort_scan(struct ipw_priv *priv);
2350
2351#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
James Ketrenos43f66a62005-03-25 12:31:53 -06002352
2353static void ipw_scan_check(void *data)
2354{
2355 struct ipw_priv *priv = data;
Zhu Yie65054b2010-03-30 09:36:16 +08002356
2357 if (priv->status & STATUS_SCAN_ABORTING) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002358 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));
Tejun Heobcb6d912011-01-26 12:12:50 +01002361 schedule_work(&priv->adapter_restart);
Zhu Yie65054b2010-03-30 09:36:16 +08002362 } else if (priv->status & STATUS_SCANNING) {
2363 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2364 "after (%dms).\n",
2365 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2366 ipw_abort_scan(priv);
Tejun Heobcb6d912011-01-26 12:12:50 +01002367 schedule_delayed_work(&priv->scan_check, HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002368 }
2369}
2370
David Howellsc4028952006-11-22 14:57:56 +00002371static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002372{
David Howellsc4028952006-11-22 14:57:56 +00002373 struct ipw_priv *priv =
2374 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002375 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002376 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002377 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002378}
2379
James Ketrenos43f66a62005-03-25 12:31:53 -06002380static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2381 struct ipw_scan_request_ext *request)
2382{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002383 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002384 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002385}
2386
2387static int ipw_send_scan_abort(struct ipw_priv *priv)
2388{
James Ketrenos43f66a62005-03-25 12:31:53 -06002389 if (!priv) {
2390 IPW_ERROR("Invalid args\n");
2391 return -1;
2392 }
2393
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002394 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002395}
2396
2397static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2398{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002399 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002400 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002401 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002402
2403 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002404 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002405}
2406
2407static int ipw_send_associate(struct ipw_priv *priv,
2408 struct ipw_associate *associate)
2409{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002410 if (!priv || !associate) {
2411 IPW_ERROR("Invalid args\n");
2412 return -1;
2413 }
2414
Al Viro5b5e8072007-12-27 01:54:06 -05002415 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2416 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002417}
2418
2419static int ipw_send_supported_rates(struct ipw_priv *priv,
2420 struct ipw_supported_rates *rates)
2421{
James Ketrenos43f66a62005-03-25 12:31:53 -06002422 if (!priv || !rates) {
2423 IPW_ERROR("Invalid args\n");
2424 return -1;
2425 }
2426
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002427 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002428 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002429}
2430
2431static int ipw_set_random_seed(struct ipw_priv *priv)
2432{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002433 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002434
2435 if (!priv) {
2436 IPW_ERROR("Invalid args\n");
2437 return -1;
2438 }
2439
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002440 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002441
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002442 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002443}
2444
James Ketrenos43f66a62005-03-25 12:31:53 -06002445static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2446{
Al Viroe62e1ee2007-12-27 01:36:46 -05002447 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002448 if (!priv) {
2449 IPW_ERROR("Invalid args\n");
2450 return -1;
2451 }
2452
Al Viroe62e1ee2007-12-27 01:36:46 -05002453 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002454}
James Ketrenos43f66a62005-03-25 12:31:53 -06002455
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002456static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002457{
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 if (!priv || !power) {
2459 IPW_ERROR("Invalid args\n");
2460 return -1;
2461 }
2462
Zhu Yi2638bc32006-01-24 16:37:52 +08002463 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002464}
James Ketrenos43f66a62005-03-25 12:31:53 -06002465
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002466static int ipw_set_tx_power(struct ipw_priv *priv)
2467{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002468 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002469 struct ipw_tx_power tx_power;
2470 s8 max_power;
2471 int i;
2472
2473 memset(&tx_power, 0, sizeof(tx_power));
2474
2475 /* configure device for 'G' band */
2476 tx_power.ieee_mode = IPW_G_MODE;
2477 tx_power.num_channels = geo->bg_channels;
2478 for (i = 0; i < geo->bg_channels; i++) {
2479 max_power = geo->bg[i].max_power;
2480 tx_power.channels_tx_power[i].channel_number =
2481 geo->bg[i].channel;
2482 tx_power.channels_tx_power[i].tx_power = max_power ?
2483 min(max_power, priv->tx_power) : priv->tx_power;
2484 }
2485 if (ipw_send_tx_power(priv, &tx_power))
2486 return -EIO;
2487
2488 /* configure device to also handle 'B' band */
2489 tx_power.ieee_mode = IPW_B_MODE;
2490 if (ipw_send_tx_power(priv, &tx_power))
2491 return -EIO;
2492
2493 /* configure device to also handle 'A' band */
2494 if (priv->ieee->abg_true) {
2495 tx_power.ieee_mode = IPW_A_MODE;
2496 tx_power.num_channels = geo->a_channels;
2497 for (i = 0; i < tx_power.num_channels; i++) {
2498 max_power = geo->a[i].max_power;
2499 tx_power.channels_tx_power[i].channel_number =
2500 geo->a[i].channel;
2501 tx_power.channels_tx_power[i].tx_power = max_power ?
2502 min(max_power, priv->tx_power) : priv->tx_power;
2503 }
2504 if (ipw_send_tx_power(priv, &tx_power))
2505 return -EIO;
2506 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002507 return 0;
2508}
2509
2510static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2511{
2512 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002513 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002514 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002515
2516 if (!priv) {
2517 IPW_ERROR("Invalid args\n");
2518 return -1;
2519 }
2520
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002521 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2522 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002523}
2524
2525static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2526{
2527 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002528 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002529 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002530
2531 if (!priv) {
2532 IPW_ERROR("Invalid args\n");
2533 return -1;
2534 }
2535
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002536 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2537 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002538}
2539
2540static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2541{
Al Viroe62e1ee2007-12-27 01:36:46 -05002542 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002543
2544 if (!priv) {
2545 IPW_ERROR("Invalid args\n");
2546 return -1;
2547 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002548
James Ketrenos43f66a62005-03-25 12:31:53 -06002549 /* If on battery, set to 3, if AC set to CAM, else user
2550 * level */
2551 switch (mode) {
2552 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002553 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002554 break;
2555 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002556 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002557 break;
2558 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002559 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002560 break;
2561 }
2562
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002563 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002564 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002565}
2566
James Ketrenosafbf30a2005-08-25 00:05:33 -05002567static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2568{
2569 struct ipw_retry_limit retry_limit = {
2570 .short_retry_limit = slimit,
2571 .long_retry_limit = llimit
2572 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002573
2574 if (!priv) {
2575 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002576 return -1;
2577 }
2578
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002579 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002580 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002581}
2582
2583/*
2584 * The IPW device contains a Microwire compatible EEPROM that stores
2585 * various data like the MAC address. Usually the firmware has exclusive
2586 * access to the eeprom, but during device initialization (before the
2587 * device driver has sent the HostComplete command to the firmware) the
2588 * device driver has read access to the EEPROM by way of indirect addressing
2589 * through a couple of memory mapped registers.
2590 *
2591 * The following is a simplified implementation for pulling data out of the
2592 * the eeprom, along with some helper functions to find information in
2593 * the per device private data's copy of the eeprom.
2594 *
2595 * NOTE: To better understand how these functions work (i.e what is a chip
2596 * select and why do have to keep driving the eeprom clock?), read
2597 * just about any data sheet for a Microwire compatible EEPROM.
2598 */
2599
2600/* write a 32 bit value into the indirect accessor register */
2601static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2602{
2603 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002604
James Ketrenos43f66a62005-03-25 12:31:53 -06002605 /* the eeprom requires some time to complete the operation */
2606 udelay(p->eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06002607}
2608
2609/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002610static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002611{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 eeprom_write_reg(priv, 0);
2613 eeprom_write_reg(priv, EEPROM_BIT_CS);
2614 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2615 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002616}
2617
2618/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002619static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002620{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002621 eeprom_write_reg(priv, EEPROM_BIT_CS);
2622 eeprom_write_reg(priv, 0);
2623 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002624}
2625
2626/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002627static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002628{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002629 int d = (bit ? EEPROM_BIT_DI : 0);
2630 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2631 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002632}
2633
2634/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002635static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002636{
2637 int i;
2638
2639 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002640 eeprom_write_bit(priv, 1);
2641 eeprom_write_bit(priv, op & 2);
2642 eeprom_write_bit(priv, op & 1);
2643 for (i = 7; i >= 0; i--) {
2644 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002645 }
2646}
2647
2648/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002649static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002650{
2651 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002652 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002653
James Ketrenos43f66a62005-03-25 12:31:53 -06002654 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002655 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002656
2657 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002661 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002662 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002663 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2664 eeprom_write_reg(priv, EEPROM_BIT_CS);
2665 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2666 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002667 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002668
James Ketrenos43f66a62005-03-25 12:31:53 -06002669 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002670 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002672
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 return r;
2674}
2675
2676/* helper function for pulling the mac address out of the private */
2677/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002679{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002680 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002681}
2682
2683/*
2684 * Either the device driver (i.e. the host) or the firmware can
2685 * load eeprom data into the designated region in SRAM. If neither
2686 * happens then the FW will shutdown with a fatal error.
2687 *
2688 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2689 * bit needs region of shared SRAM needs to be non-zero.
2690 */
2691static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2692{
2693 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002694 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002695
James Ketrenos43f66a62005-03-25 12:31:53 -06002696 IPW_DEBUG_TRACE(">>\n");
2697
2698 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002699 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002700 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002701
Jeff Garzikbf794512005-07-31 13:07:26 -04002702 /*
2703 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002704 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002705 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002706 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002707 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002708 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2709
2710 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002711 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002712 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002713
2714 /* Do not load eeprom data on fatal error or suspend */
2715 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2716 } else {
2717 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2718
2719 /* Load eeprom data on fatal error or suspend */
2720 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2721 }
2722
2723 IPW_DEBUG_TRACE("<<\n");
2724}
2725
Arjan van de Ven858119e2006-01-14 13:20:43 -08002726static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002727{
2728 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002729 if (!count)
2730 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002731 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002732 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002733 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002734}
2735
2736static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2737{
James Ketrenosb095c382005-08-24 22:04:42 -05002738 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002739 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002740 sizeof(struct command_block));
2741}
2742
2743static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002744{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002745
Frans Pop9fd1ea42010-03-24 19:46:31 +01002746 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002747
James Ketrenos43f66a62005-03-25 12:31:53 -06002748 /* Start the dma */
2749 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002750
James Ketrenos43f66a62005-03-25 12:31:53 -06002751 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002752 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002753
Frans Pop9fd1ea42010-03-24 19:46:31 +01002754 IPW_DEBUG_FW("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002755 return 0;
2756}
2757
2758static void ipw_fw_dma_abort(struct ipw_priv *priv)
2759{
2760 u32 control = 0;
2761
2762 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002763
Pavel Machek67fd6b42006-07-11 15:34:05 +02002764 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002765 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002766 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002768
Frans Pop9fd1ea42010-03-24 19:46:31 +01002769 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002770}
2771
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002772static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2773 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002774{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002775 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002776 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002777 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002778 IPW_DEBUG_FW(">> :\n");
2779
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002780 ipw_write_indirect(priv, address, (u8 *) cb,
2781 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002782
2783 IPW_DEBUG_FW("<< :\n");
2784 return 0;
2785
2786}
2787
2788static int ipw_fw_dma_kick(struct ipw_priv *priv)
2789{
2790 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002791 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002792
2793 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002794
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002796 ipw_fw_dma_write_command_block(priv, index,
2797 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002798
2799 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002800 ipw_clear_bit(priv, IPW_RESET_REG,
2801 IPW_RESET_REG_MASTER_DISABLED |
2802 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002803
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002804 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002805 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002806 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002807
2808 IPW_DEBUG_FW("<< :\n");
2809 return 0;
2810}
2811
2812static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2813{
2814 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002815 u32 register_value = 0;
2816 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002817
2818 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002819 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002820 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
2822 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002823 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002824 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002825
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002826 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002827 cb_fields_address = address;
2828 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002829 IPW_DEBUG_FW_INFO("Current CB Control 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);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002833 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002834
2835 cb_fields_address += sizeof(u32);
2836 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002837 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002838 register_value);
2839
2840 cb_fields_address += sizeof(u32);
2841 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002842 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002843
2844 IPW_DEBUG_FW(">> :\n");
2845}
2846
2847static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2848{
2849 u32 current_cb_address = 0;
2850 u32 current_cb_index = 0;
2851
2852 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002853 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002854
James Ketrenosb095c382005-08-24 22:04:42 -05002855 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002856 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002857
Frans Pop9fd1ea42010-03-24 19:46:31 +01002858 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002859 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002860
2861 IPW_DEBUG_FW(">> :\n");
2862 return current_cb_index;
2863
2864}
2865
2866static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2867 u32 src_address,
2868 u32 dest_address,
2869 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002870 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002871{
2872
Jeff Garzikbf794512005-07-31 13:07:26 -04002873 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002874 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2875 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002876 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002877 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002878
2879 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2880 src_address, dest_address, length);
2881
2882 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2883 return -1;
2884
2885 last_cb_element = priv->sram_desc.last_cb_index;
2886 cb = &priv->sram_desc.cb_list[last_cb_element];
2887 priv->sram_desc.last_cb_index++;
2888
2889 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002890 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002891 control |= CB_INT_ENABLED;
2892
2893 if (is_last)
2894 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002895
James Ketrenos43f66a62005-03-25 12:31:53 -06002896 control |= length;
2897
2898 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002899 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002900
2901 /* Copy the Source and Destination addresses */
2902 cb->dest_addr = dest_address;
2903 cb->source_addr = src_address;
2904
2905 /* Copy the Control Word last */
2906 cb->control = control;
2907
2908 return 0;
2909}
2910
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002911static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2912 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002913{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002914 int ret, i;
2915 u32 size;
2916
Frans Pop9fd1ea42010-03-24 19:46:31 +01002917 IPW_DEBUG_FW(">>\n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002918 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2919 nr, dest_address, len);
2920
2921 for (i = 0; i < nr; i++) {
2922 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2923 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2924 dest_address +
2925 i * CB_MAX_LENGTH, size,
2926 0, 0);
2927 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002928 IPW_DEBUG_FW_INFO(": Failed\n");
2929 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002930 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002931 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002933
Frans Pop9fd1ea42010-03-24 19:46:31 +01002934 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002935 return 0;
2936}
2937
2938static int ipw_fw_dma_wait(struct ipw_priv *priv)
2939{
Zhu Yi397ae122006-01-24 16:37:22 +08002940 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002941 u32 watchdog = 0;
2942
Frans Pop9fd1ea42010-03-24 19:46:31 +01002943 IPW_DEBUG_FW(">> :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002944
2945 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002946 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002947 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002948
2949 while (current_index < priv->sram_desc.last_cb_index) {
2950 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002951 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002952 current_index = ipw_fw_dma_command_block_index(priv);
2953
Zhu Yi397ae122006-01-24 16:37:22 +08002954 if (previous_index < current_index) {
2955 watchdog = 0;
2956 continue;
2957 }
2958 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002959 IPW_DEBUG_FW_INFO("Timeout\n");
2960 ipw_fw_dma_dump_command_block(priv);
2961 ipw_fw_dma_abort(priv);
2962 return -1;
2963 }
2964 }
2965
2966 ipw_fw_dma_abort(priv);
2967
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002968 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002969 ipw_set_bit(priv, IPW_RESET_REG,
2970 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002971
Frans Pop9fd1ea42010-03-24 19:46:31 +01002972 IPW_DEBUG_FW("<< dmaWaitSync\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002973 return 0;
2974}
2975
Jeff Garzikbf794512005-07-31 13:07:26 -04002976static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002977{
2978 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002979 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002980 unsigned long flags;
2981
2982 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002983 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002984 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002985 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2986 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002987 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002988 &priv->ieee->network_free_list);
2989 }
2990 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002991 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002992}
2993
2994/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002995 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002996 * Reads debug register from domain0.
2997 * If card is present, pre-defined value should
2998 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002999 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 * @param priv
3001 * @return 1 if card is present, 0 otherwise
3002 */
3003static inline int ipw_alive(struct ipw_priv *priv)
3004{
3005 return ipw_read32(priv, 0x90) == 0xd55555d5;
3006}
3007
Zhu Yic7b6a672006-01-24 16:37:05 +08003008/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003009static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003010 int timeout)
3011{
3012 int i = 0;
3013
3014 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003015 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003016 return i;
3017 mdelay(10);
3018 i += 10;
3019 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003020
James Ketrenos43f66a62005-03-25 12:31:53 -06003021 return -ETIME;
3022}
3023
Jeff Garzikbf794512005-07-31 13:07:26 -04003024/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 * the ipw hardware. It assumes the buffer has all the bits for the
3026 * image and the caller is handling the memory allocation and clean up.
3027 */
3028
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003029static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003030{
3031 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003032
Frans Pop9fd1ea42010-03-24 19:46:31 +01003033 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003034 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003035 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003036
Zhu Yic7b6a672006-01-24 16:37:05 +08003037 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003038 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3039 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003040 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003041 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003042 return -1;
3043 }
3044
3045 IPW_DEBUG_INFO("stop master %dms\n", rc);
3046
3047 return rc;
3048}
3049
3050static void ipw_arc_release(struct ipw_priv *priv)
3051{
Frans Pop9fd1ea42010-03-24 19:46:31 +01003052 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003053 mdelay(5);
3054
James Ketrenosb095c382005-08-24 22:04:42 -05003055 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003056
3057 /* no one knows timing, for safety add some delay */
3058 mdelay(5);
3059}
3060
James Ketrenos43f66a62005-03-25 12:31:53 -06003061struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003062 __le32 address;
3063 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003064};
3065
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003066static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003067{
3068 int rc = 0, i, addr;
3069 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003070 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003071
Al Viroe62e1ee2007-12-27 01:36:46 -05003072 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003073
Frans Pop9fd1ea42010-03-24 19:46:31 +01003074 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003075
3076 rc = ipw_stop_master(priv);
3077
3078 if (rc < 0)
3079 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003080
James Ketrenosb095c382005-08-24 22:04:42 -05003081 for (addr = IPW_SHARED_LOWER_BOUND;
3082 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003083 ipw_write32(priv, addr, 0);
3084 }
3085
3086 /* no ucode (yet) */
3087 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3088 /* destroy DMA queues */
3089 /* reset sequence */
3090
James Ketrenosb095c382005-08-24 22:04:42 -05003091 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003092 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003093 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 mdelay(1);
3095
3096 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003097 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003099
James Ketrenosb095c382005-08-24 22:04:42 -05003100 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003101 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003102
James Ketrenos43f66a62005-03-25 12:31:53 -06003103 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003104 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3105 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003106 mdelay(1);
3107
3108 /* write ucode */
3109 /**
3110 * @bug
3111 * Do NOT set indirect address register once and then
3112 * store data to indirect data register in the loop.
3113 * It seems very reasonable, but in this case DINO do not
3114 * accept ucode. It is essential to set address each time.
3115 */
3116 /* load new ipw uCode */
3117 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003118 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003119 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003120
James Ketrenos43f66a62005-03-25 12:31:53 -06003121 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003122 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3123 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003124
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003125 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003126
3127 /* wait for alive response */
3128 for (i = 0; i < 100; i++) {
3129 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003130 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003131 if (cr & DINO_RXFIFO_DATA)
3132 break;
3133 mdelay(1);
3134 }
3135
3136 if (cr & DINO_RXFIFO_DATA) {
3137 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003138 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003139
3140 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003141 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003142 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003143 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003144 memcpy(&priv->dino_alive, response_buffer,
3145 sizeof(priv->dino_alive));
3146 if (priv->dino_alive.alive_command == 1
3147 && priv->dino_alive.ucode_valid == 1) {
3148 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003149 IPW_DEBUG_INFO
3150 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3151 "of %02d/%02d/%02d %02d:%02d\n",
3152 priv->dino_alive.software_revision,
3153 priv->dino_alive.software_revision,
3154 priv->dino_alive.device_identifier,
3155 priv->dino_alive.device_identifier,
3156 priv->dino_alive.time_stamp[0],
3157 priv->dino_alive.time_stamp[1],
3158 priv->dino_alive.time_stamp[2],
3159 priv->dino_alive.time_stamp[3],
3160 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003161 } else {
3162 IPW_DEBUG_INFO("Microcode is not alive\n");
3163 rc = -EINVAL;
3164 }
3165 } else {
3166 IPW_DEBUG_INFO("No alive response from DINO\n");
3167 rc = -ETIME;
3168 }
3169
3170 /* disable DINO, otherwise for some reason
3171 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003172 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003173
James Ketrenos43f66a62005-03-25 12:31:53 -06003174 return rc;
3175}
3176
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003177static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003178{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003179 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003180 int offset = 0;
3181 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003182 int total_nr = 0;
3183 int i;
3184 struct pci_pool *pool;
Zhu Yi41093162010-03-09 16:05:31 +08003185 void **virts;
3186 dma_addr_t *phys;
James Ketrenos43f66a62005-03-25 12:31:53 -06003187
Frans Pop9fd1ea42010-03-24 19:46:31 +01003188 IPW_DEBUG_TRACE("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003189
Zhu Yi41093162010-03-09 16:05:31 +08003190 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3191 GFP_KERNEL);
3192 if (!virts)
3193 return -ENOMEM;
3194
3195 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3196 GFP_KERNEL);
3197 if (!phys) {
3198 kfree(virts);
3199 return -ENOMEM;
3200 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003201 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3202 if (!pool) {
3203 IPW_ERROR("pci_pool_create failed\n");
Zhu Yi41093162010-03-09 16:05:31 +08003204 kfree(phys);
3205 kfree(virts);
James Ketrenos43f66a62005-03-25 12:31:53 -06003206 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003207 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003208
3209 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003210 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003211
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003212 /* the DMA is already ready this would be a bug. */
3213 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003214
3215 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003216 u32 chunk_len;
3217 u8 *start;
3218 int size;
3219 int nr = 0;
3220
James Ketrenos43f66a62005-03-25 12:31:53 -06003221 chunk = (struct fw_chunk *)(data + offset);
3222 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003223 chunk_len = le32_to_cpu(chunk->length);
3224 start = data + offset;
3225
3226 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3227 for (i = 0; i < nr; i++) {
3228 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3229 &phys[total_nr]);
3230 if (!virts[total_nr]) {
3231 ret = -ENOMEM;
3232 goto out;
3233 }
3234 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3235 CB_MAX_LENGTH);
3236 memcpy(virts[total_nr], start, size);
3237 start += size;
3238 total_nr++;
3239 /* We don't support fw chunk larger than 64*8K */
3240 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3241 }
3242
James Ketrenos43f66a62005-03-25 12:31:53 -06003243 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003244 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003245 * offeset*/
3246 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003247 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3248 nr, le32_to_cpu(chunk->address),
3249 chunk_len);
3250 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003251 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3252 goto out;
3253 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003254
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003255 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003256 } while (offset < len);
3257
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003258 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003259 ret = ipw_fw_dma_kick(priv);
3260 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003261 IPW_ERROR("dmaKick Failed\n");
3262 goto out;
3263 }
3264
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003265 ret = ipw_fw_dma_wait(priv);
3266 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003267 IPW_ERROR("dmaWaitSync Failed\n");
3268 goto out;
3269 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003270 out:
3271 for (i = 0; i < total_nr; i++)
3272 pci_pool_free(pool, virts[i], phys[i]);
3273
3274 pci_pool_destroy(pool);
Zhu Yi41093162010-03-09 16:05:31 +08003275 kfree(phys);
3276 kfree(virts);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003277
3278 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003279}
3280
3281/* stop nic */
3282static int ipw_stop_nic(struct ipw_priv *priv)
3283{
3284 int rc = 0;
3285
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003286 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003287 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003288
James Ketrenosb095c382005-08-24 22:04:42 -05003289 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3290 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003291 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003292 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003293 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003294 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003295
James Ketrenosb095c382005-08-24 22:04:42 -05003296 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003297
James Ketrenos43f66a62005-03-25 12:31:53 -06003298 return rc;
3299}
3300
3301static void ipw_start_nic(struct ipw_priv *priv)
3302{
3303 IPW_DEBUG_TRACE(">>\n");
3304
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003305 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003306 ipw_clear_bit(priv, IPW_RESET_REG,
3307 IPW_RESET_REG_MASTER_DISABLED |
3308 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003309 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003310
James Ketrenos43f66a62005-03-25 12:31:53 -06003311 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003312 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3313 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003314
3315 IPW_DEBUG_TRACE("<<\n");
3316}
Jeff Garzikbf794512005-07-31 13:07:26 -04003317
James Ketrenos43f66a62005-03-25 12:31:53 -06003318static int ipw_init_nic(struct ipw_priv *priv)
3319{
3320 int rc;
3321
3322 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003323 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003324 /*prvHwInitNic */
3325 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003326 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003327
3328 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003329 ipw_write32(priv, IPW_READ_INT_REGISTER,
3330 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003331
3332 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003333 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3334 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003335 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003336 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3337
3338 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003339 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003340
3341 udelay(10);
3342
3343 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003344 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003345
3346 IPW_DEBUG_TRACE(">>\n");
3347 return 0;
3348}
3349
Jeff Garzikbf794512005-07-31 13:07:26 -04003350/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003351 * Probe is an ok place to call this from.
3352 */
3353static int ipw_reset_nic(struct ipw_priv *priv)
3354{
3355 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003356 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003357
3358 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003359
James Ketrenos43f66a62005-03-25 12:31:53 -06003360 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003361
James Ketrenosa613bff2005-08-24 21:43:11 -05003362 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003363 /* Clear the 'host command active' bit... */
3364 priv->status &= ~STATUS_HCMD_ACTIVE;
3365 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003366 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3367 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003368 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003369
3370 IPW_DEBUG_TRACE("<<\n");
3371 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003372}
James Ketrenos43f66a62005-03-25 12:31:53 -06003373
James Ketrenos9006ea72006-03-08 03:22:28 +08003374
3375struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003376 __le32 ver;
3377 __le32 boot_size;
3378 __le32 ucode_size;
3379 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003380 u8 data[0];
3381};
3382
Jeff Garzikbf794512005-07-31 13:07:26 -04003383static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003384 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003385{
James Ketrenos9006ea72006-03-08 03:22:28 +08003386 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003387 int rc;
3388
3389 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003390 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003391 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003392 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003393 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003394 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003395
James Ketrenos9006ea72006-03-08 03:22:28 +08003396 if ((*raw)->size < sizeof(*fw)) {
3397 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003398 return -EINVAL;
3399 }
3400
James Ketrenos9006ea72006-03-08 03:22:28 +08003401 fw = (void *)(*raw)->data;
3402
Zhu Yi0070f8c2006-04-13 17:20:12 +08003403 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3404 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003405 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3406 name, (*raw)->size);
3407 return -EINVAL;
3408 }
3409
3410 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003411 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003412 le32_to_cpu(fw->ver) >> 16,
3413 le32_to_cpu(fw->ver) & 0xff,
3414 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003415 return 0;
3416}
3417
James Ketrenosb095c382005-08-24 22:04:42 -05003418#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003419
Arjan van de Ven858119e2006-01-14 13:20:43 -08003420static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003421 struct ipw_rx_queue *rxq)
3422{
3423 unsigned long flags;
3424 int i;
3425
3426 spin_lock_irqsave(&rxq->lock, flags);
3427
3428 INIT_LIST_HEAD(&rxq->rx_free);
3429 INIT_LIST_HEAD(&rxq->rx_used);
3430
3431 /* Fill the rx_used queue with _all_ of the Rx buffers */
3432 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3433 /* In the reset function, these buffers may have been allocated
3434 * to an SKB, so we need to unmap and free potential storage */
3435 if (rxq->pool[i].skb != NULL) {
3436 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003437 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003438 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003439 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003440 }
3441 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3442 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003443
James Ketrenos43f66a62005-03-25 12:31:53 -06003444 /* Set us so that we have processed and used all buffers, but have
3445 * not restocked the Rx queue with fresh buffers */
3446 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003447 rxq->free_count = 0;
3448 spin_unlock_irqrestore(&rxq->lock, flags);
3449}
3450
3451#ifdef CONFIG_PM
3452static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003453static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003454
3455static void free_firmware(void)
3456{
3457 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003458 release_firmware(raw);
3459 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003460 fw_loaded = 0;
3461 }
3462}
3463#else
3464#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003465#endif
3466
3467static int ipw_load(struct ipw_priv *priv)
3468{
3469#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003470 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003471#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003472 struct ipw_fw *fw;
3473 u8 *boot_img, *ucode_img, *fw_img;
3474 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003475 int rc = 0, retries = 3;
3476
Zhu Yi397ae122006-01-24 16:37:22 +08003477 switch (priv->ieee->iw_mode) {
3478 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003479 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003480 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003481#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003482 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003483 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003484 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003485#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003486 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003487 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003488 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003489 }
Zhu Yi397ae122006-01-24 16:37:22 +08003490
James Ketrenos9006ea72006-03-08 03:22:28 +08003491 if (!name) {
3492 rc = -EINVAL;
3493 goto error;
3494 }
3495
3496#ifdef CONFIG_PM
3497 if (!fw_loaded) {
3498#endif
3499 rc = ipw_get_fw(priv, &raw, name);
3500 if (rc < 0)
3501 goto error;
3502#ifdef CONFIG_PM
3503 }
3504#endif
3505
3506 fw = (void *)raw->data;
3507 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003508 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3509 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3510 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003511
Zhu Yi397ae122006-01-24 16:37:22 +08003512 if (rc < 0)
3513 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003514
3515 if (!priv->rxq)
3516 priv->rxq = ipw_rx_queue_alloc(priv);
3517 else
3518 ipw_rx_queue_reset(priv, priv->rxq);
3519 if (!priv->rxq) {
3520 IPW_ERROR("Unable to initialize Rx queue\n");
3521 goto error;
3522 }
3523
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003524 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003525 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003526 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003527 priv->status &= ~STATUS_INT_ENABLED;
3528
3529 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003530 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003531
James Ketrenos43f66a62005-03-25 12:31:53 -06003532 ipw_stop_nic(priv);
3533
3534 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003535 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003536 IPW_ERROR("Unable to reset NIC\n");
3537 goto error;
3538 }
3539
James Ketrenosb095c382005-08-24 22:04:42 -05003540 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3541 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003542
3543 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003544 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003546 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003547 goto error;
3548 }
3549
3550 /* kick start the device */
3551 ipw_start_nic(priv);
3552
Zhu Yic7b6a672006-01-24 16:37:05 +08003553 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003554 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3555 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003556 if (rc < 0) {
3557 IPW_ERROR("device failed to boot initial fw image\n");
3558 goto error;
3559 }
3560 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3561
Jeff Garzikbf794512005-07-31 13:07:26 -04003562 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003563 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003564
3565 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003566 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003567 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003568 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003569 goto error;
3570 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003571
James Ketrenos43f66a62005-03-25 12:31:53 -06003572 /* stop nic */
3573 ipw_stop_nic(priv);
3574
3575 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003576 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003577 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003578 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003579 goto error;
3580 }
Zhu Yi397ae122006-01-24 16:37:22 +08003581#ifdef CONFIG_PM
3582 fw_loaded = 1;
3583#endif
3584
James Ketrenos43f66a62005-03-25 12:31:53 -06003585 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3586
3587 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003588 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003589 IPW_ERROR("Unable to initialize queues\n");
3590 goto error;
3591 }
3592
3593 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003594 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003595 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003596 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003597
James Ketrenos43f66a62005-03-25 12:31:53 -06003598 /* kick start the device */
3599 ipw_start_nic(priv);
3600
James Ketrenosb095c382005-08-24 22:04:42 -05003601 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003602 if (retries > 0) {
3603 IPW_WARNING("Parity error. Retrying init.\n");
3604 retries--;
3605 goto retry;
3606 }
3607
3608 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3609 rc = -EIO;
3610 goto error;
3611 }
3612
3613 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003614 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3615 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003616 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003617 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003618 goto error;
3619 }
3620 IPW_DEBUG_INFO("device response after %dms\n", rc);
3621
3622 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003623 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003624
3625 /* read eeprom data and initialize the eeprom region of sram */
3626 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003627 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003628
3629 /* enable interrupts */
3630 ipw_enable_interrupts(priv);
3631
3632 /* Ensure our queue has valid packets */
3633 ipw_rx_queue_replenish(priv);
3634
James Ketrenosb095c382005-08-24 22:04:42 -05003635 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003636
3637 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003638 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003639
3640#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003641 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003642#endif
3643 return 0;
3644
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003645 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003646 if (priv->rxq) {
3647 ipw_rx_queue_free(priv, priv->rxq);
3648 priv->rxq = NULL;
3649 }
3650 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003651 if (raw)
3652 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003653#ifdef CONFIG_PM
3654 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003655 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003656#endif
3657
3658 return rc;
3659}
3660
Jeff Garzikbf794512005-07-31 13:07:26 -04003661/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003662 * DMA services
3663 *
3664 * Theory of operation
3665 *
3666 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3667 * 2 empty entries always kept in the buffer to protect from overflow.
3668 *
3669 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003670 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3671 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003672 * Tx queue resumed.
3673 *
3674 * The IPW operates with six queues, one receive queue in the device's
3675 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003676 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003677 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003678 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003679 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003680 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003681 * we only utilize the first data transmit queue (queue1).
3682 */
3683
3684/**
3685 * Driver allocates buffers of this size for Rx
3686 */
3687
Dan Williams943dbef2008-02-14 17:49:41 -05003688/**
3689 * ipw_rx_queue_space - Return number of free slots available in queue.
3690 */
3691static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3692{
3693 int s = q->read - q->write;
3694 if (s <= 0)
3695 s += RX_QUEUE_SIZE;
3696 /* keep some buffer to not confuse full and empty queue */
3697 s -= 2;
3698 if (s < 0)
3699 s = 0;
3700 return s;
3701}
3702
3703static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003704{
3705 int s = q->last_used - q->first_empty;
3706 if (s <= 0)
3707 s += q->n_bd;
3708 s -= 2; /* keep some reserve to not confuse empty and full situations */
3709 if (s < 0)
3710 s = 0;
3711 return s;
3712}
3713
3714static inline int ipw_queue_inc_wrap(int index, int n_bd)
3715{
3716 return (++index == n_bd) ? 0 : index;
3717}
3718
3719/**
3720 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003721 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003722 * @param q queue to init
3723 * @param count Number of BD's to allocate. Should be power of 2
3724 * @param read_register Address for 'read' register
3725 * (not offset within BAR, full address)
3726 * @param write_register Address for 'write' register
3727 * (not offset within BAR, full address)
3728 * @param base_register Address for 'base' register
3729 * (not offset within BAR, full address)
3730 * @param size Address for 'size' register
3731 * (not offset within BAR, full address)
3732 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003733static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003734 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003735{
3736 q->n_bd = count;
3737
3738 q->low_mark = q->n_bd / 4;
3739 if (q->low_mark < 4)
3740 q->low_mark = 4;
3741
3742 q->high_mark = q->n_bd / 8;
3743 if (q->high_mark < 2)
3744 q->high_mark = 2;
3745
3746 q->first_empty = q->last_used = 0;
3747 q->reg_r = read;
3748 q->reg_w = write;
3749
3750 ipw_write32(priv, base, q->dma_addr);
3751 ipw_write32(priv, size, count);
3752 ipw_write32(priv, read, 0);
3753 ipw_write32(priv, write, 0);
3754
3755 _ipw_read32(priv, 0x90);
3756}
3757
Jeff Garzikbf794512005-07-31 13:07:26 -04003758static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003759 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003760 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003761{
3762 struct pci_dev *dev = priv->pci_dev;
3763
3764 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3765 if (!q->txb) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003766 IPW_ERROR("vmalloc for auxiliary BD structures failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003767 return -ENOMEM;
3768 }
3769
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003770 q->bd =
3771 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003772 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003773 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003774 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003775 kfree(q->txb);
3776 q->txb = NULL;
3777 return -ENOMEM;
3778 }
3779
3780 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3781 return 0;
3782}
3783
3784/**
3785 * Free one TFD, those at index [txq->q.last_used].
3786 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003787 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003788 * @param dev
3789 * @param txq
3790 */
3791static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3792 struct clx2_tx_queue *txq)
3793{
3794 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3795 struct pci_dev *dev = priv->pci_dev;
3796 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003797
James Ketrenos43f66a62005-03-25 12:31:53 -06003798 /* classify bd */
3799 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3800 /* nothing to cleanup after for host commands */
3801 return;
3802
3803 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003804 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3805 IPW_ERROR("Too many chunks: %i\n",
3806 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003807 /** @todo issue fatal error, it is quite serious situation */
3808 return;
3809 }
3810
3811 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003812 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3813 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3814 le16_to_cpu(bd->u.data.chunk_len[i]),
3815 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003816 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003817 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003818 txq->txb[txq->q.last_used] = NULL;
3819 }
3820 }
3821}
3822
3823/**
3824 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003825 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003826 * Empty queue by removing and destroying all BD's.
3827 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003828 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003829 * @param dev
3830 * @param q
3831 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003832static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003833{
3834 struct clx2_queue *q = &txq->q;
3835 struct pci_dev *dev = priv->pci_dev;
3836
Jeff Garzikbf794512005-07-31 13:07:26 -04003837 if (q->n_bd == 0)
3838 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003839
3840 /* first, empty all BD's */
3841 for (; q->first_empty != q->last_used;
3842 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3843 ipw_queue_tx_free_tfd(priv, txq);
3844 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003845
James Ketrenos43f66a62005-03-25 12:31:53 -06003846 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003847 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003848 q->dma_addr);
3849 kfree(txq->txb);
3850
3851 /* 0 fill whole structure */
3852 memset(txq, 0, sizeof(*txq));
3853}
3854
James Ketrenos43f66a62005-03-25 12:31:53 -06003855/**
3856 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003857 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003858 * @param priv
3859 */
3860static void ipw_tx_queue_free(struct ipw_priv *priv)
3861{
3862 /* Tx CMD queue */
3863 ipw_queue_tx_free(priv, &priv->txq_cmd);
3864
3865 /* Tx queues */
3866 ipw_queue_tx_free(priv, &priv->txq[0]);
3867 ipw_queue_tx_free(priv, &priv->txq[1]);
3868 ipw_queue_tx_free(priv, &priv->txq[2]);
3869 ipw_queue_tx_free(priv, &priv->txq[3]);
3870}
3871
Arjan van de Ven858119e2006-01-14 13:20:43 -08003872static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003873{
3874 /* First 3 bytes are manufacturer */
3875 bssid[0] = priv->mac_addr[0];
3876 bssid[1] = priv->mac_addr[1];
3877 bssid[2] = priv->mac_addr[2];
3878
3879 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003880 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003881
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003882 bssid[0] &= 0xfe; /* clear multicast bit */
3883 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003884}
3885
Arjan van de Ven858119e2006-01-14 13:20:43 -08003886static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003887{
3888 struct ipw_station_entry entry;
3889 int i;
3890
3891 for (i = 0; i < priv->num_stations; i++) {
3892 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3893 /* Another node is active in network */
3894 priv->missed_adhoc_beacons = 0;
3895 if (!(priv->config & CFG_STATIC_CHANNEL))
3896 /* when other nodes drop out, we drop out */
3897 priv->config &= ~CFG_ADHOC_PERSIST;
3898
3899 return i;
3900 }
3901 }
3902
3903 if (i == MAX_STATIONS)
3904 return IPW_INVALID_STATION;
3905
Johannes Berge1749612008-10-27 15:59:26 -07003906 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003907
3908 entry.reserved = 0;
3909 entry.support_mode = 0;
3910 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3911 memcpy(priv->stations[i], bssid, ETH_ALEN);
3912 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003913 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003914 priv->num_stations++;
3915
3916 return i;
3917}
3918
Arjan van de Ven858119e2006-01-14 13:20:43 -08003919static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003920{
3921 int i;
3922
Jeff Garzikbf794512005-07-31 13:07:26 -04003923 for (i = 0; i < priv->num_stations; i++)
3924 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003925 return i;
3926
3927 return IPW_INVALID_STATION;
3928}
3929
3930static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3931{
3932 int err;
3933
Hong Liu7b996592005-08-25 17:36:13 +08003934 if (priv->status & STATUS_ASSOCIATING) {
3935 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01003936 schedule_work(&priv->disassociate);
Hong Liu7b996592005-08-25 17:36:13 +08003937 return;
3938 }
3939
3940 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003941 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3942 return;
3943 }
3944
Johannes Berge1749612008-10-27 15:59:26 -07003945 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003946 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003947 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003948 priv->assoc_request.channel);
3949
3950 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3951 priv->status |= STATUS_DISASSOCIATING;
3952
3953 if (quiet)
3954 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3955 else
3956 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003957
James Ketrenos43f66a62005-03-25 12:31:53 -06003958 err = ipw_send_associate(priv, &priv->assoc_request);
3959 if (err) {
3960 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3961 "failed.\n");
3962 return;
3963 }
3964
3965}
3966
James Ketrenosc848d0a2005-08-24 21:56:24 -05003967static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003968{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003969 struct ipw_priv *priv = data;
3970 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3971 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003972 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003973 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003974 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003975}
3976
David Howellsc4028952006-11-22 14:57:56 +00003977static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003978{
David Howellsc4028952006-11-22 14:57:56 +00003979 struct ipw_priv *priv =
3980 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003981 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003982 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003983 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003984}
3985
David Howellsc4028952006-11-22 14:57:56 +00003986static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003987{
David Howellsc4028952006-11-22 14:57:56 +00003988 struct ipw_priv *priv =
3989 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003990
3991#ifdef CONFIG_IPW2200_PROMISCUOUS
3992 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3993 priv->sys_config.accept_all_data_frames = 1;
3994 priv->sys_config.accept_non_directed_frames = 1;
3995 priv->sys_config.accept_all_mgmt_bcpr = 1;
3996 priv->sys_config.accept_all_mgmt_frames = 1;
3997 }
3998#endif
3999
4000 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004001}
4002
4003struct ipw_status_code {
4004 u16 status;
4005 const char *reason;
4006};
4007
4008static const struct ipw_status_code ipw_status_codes[] = {
4009 {0x00, "Successful"},
4010 {0x01, "Unspecified failure"},
4011 {0x0A, "Cannot support all requested capabilities in the "
4012 "Capability information field"},
4013 {0x0B, "Reassociation denied due to inability to confirm that "
4014 "association exists"},
4015 {0x0C, "Association denied due to reason outside the scope of this "
4016 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004017 {0x0D,
4018 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004019 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004020 {0x0E,
4021 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004022 "transaction sequence number out of expected sequence"},
4023 {0x0F, "Authentication rejected because of challenge failure"},
4024 {0x10, "Authentication rejected due to timeout waiting for next "
4025 "frame in sequence"},
4026 {0x11, "Association denied because AP is unable to handle additional "
4027 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004028 {0x12,
4029 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004030 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004031 {0x13,
4032 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004033 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004034 {0x14,
4035 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004036 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004037 {0x15,
4038 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004039 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004040 {0x19,
4041 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004042 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004043 {0x1A,
4044 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004045 "DSSS-OFDM operation"},
4046 {0x28, "Invalid Information Element"},
4047 {0x29, "Group Cipher is not valid"},
4048 {0x2A, "Pairwise Cipher is not valid"},
4049 {0x2B, "AKMP is not valid"},
4050 {0x2C, "Unsupported RSN IE version"},
4051 {0x2D, "Invalid RSN IE Capabilities"},
4052 {0x2E, "Cipher suite is rejected per security policy"},
4053};
4054
Jeff Garzikbf794512005-07-31 13:07:26 -04004055static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004056{
4057 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004058 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004059 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004060 return ipw_status_codes[i].reason;
4061 return "Unknown status value.";
4062}
James Ketrenos43f66a62005-03-25 12:31:53 -06004063
4064static void inline average_init(struct average *avg)
4065{
4066 memset(avg, 0, sizeof(*avg));
4067}
4068
Zhu Yi00d21de2006-04-13 17:19:02 +08004069#define DEPTH_RSSI 8
4070#define DEPTH_NOISE 16
4071static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4072{
4073 return ((depth-1)*prev_avg + val)/depth;
4074}
4075
Arjan van de Ven858119e2006-01-14 13:20:43 -08004076static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004077{
4078 avg->sum -= avg->entries[avg->pos];
4079 avg->sum += val;
4080 avg->entries[avg->pos++] = val;
4081 if (unlikely(avg->pos == AVG_ENTRIES)) {
4082 avg->init = 1;
4083 avg->pos = 0;
4084 }
4085}
4086
Arjan van de Ven858119e2006-01-14 13:20:43 -08004087static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004088{
4089 if (!unlikely(avg->init)) {
4090 if (avg->pos)
4091 return avg->sum / avg->pos;
4092 return 0;
4093 }
4094
4095 return avg->sum / AVG_ENTRIES;
4096}
4097
4098static void ipw_reset_stats(struct ipw_priv *priv)
4099{
4100 u32 len = sizeof(u32);
4101
4102 priv->quality = 0;
4103
4104 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004105 priv->exp_avg_rssi = -60;
4106 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004107
4108 priv->last_rate = 0;
4109 priv->last_missed_beacons = 0;
4110 priv->last_rx_packets = 0;
4111 priv->last_tx_packets = 0;
4112 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004113
James Ketrenos43f66a62005-03-25 12:31:53 -06004114 /* Firmware managed, reset only when NIC is restarted, so we have to
4115 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004116 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004117 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004118 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004119 &priv->last_tx_failures, &len);
4120
4121 /* Driver managed, reset with each association */
4122 priv->missed_adhoc_beacons = 0;
4123 priv->missed_beacons = 0;
4124 priv->tx_packets = 0;
4125 priv->rx_packets = 0;
4126
4127}
4128
Arjan van de Ven858119e2006-01-14 13:20:43 -08004129static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004130{
4131 u32 i = 0x80000000;
4132 u32 mask = priv->rates_mask;
4133 /* If currently associated in B mode, restrict the maximum
4134 * rate match to B rates */
4135 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004136 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004137
4138 /* TODO: Verify that the rate is supported by the current rates
4139 * list. */
4140
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004141 while (i && !(mask & i))
4142 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004143 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004144 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004145 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004146 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004147 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004148 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004149 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004150 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004151 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004152 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004153 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004154 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004155 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004156 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004158 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004159 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004160 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004161 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004162 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004163 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004164 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004165 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004166 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004167 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004168 }
4169
Jeff Garzikbf794512005-07-31 13:07:26 -04004170 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 return 11000000;
4172 else
4173 return 54000000;
4174}
4175
4176static u32 ipw_get_current_rate(struct ipw_priv *priv)
4177{
4178 u32 rate, len = sizeof(rate);
4179 int err;
4180
Jeff Garzikbf794512005-07-31 13:07:26 -04004181 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004182 return 0;
4183
4184 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004185 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004186 &len);
4187 if (err) {
4188 IPW_DEBUG_INFO("failed querying ordinals.\n");
4189 return 0;
4190 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004191 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004192 return ipw_get_max_rate(priv);
4193
4194 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004195 case IPW_TX_RATE_1MB:
4196 return 1000000;
4197 case IPW_TX_RATE_2MB:
4198 return 2000000;
4199 case IPW_TX_RATE_5MB:
4200 return 5500000;
4201 case IPW_TX_RATE_6MB:
4202 return 6000000;
4203 case IPW_TX_RATE_9MB:
4204 return 9000000;
4205 case IPW_TX_RATE_11MB:
4206 return 11000000;
4207 case IPW_TX_RATE_12MB:
4208 return 12000000;
4209 case IPW_TX_RATE_18MB:
4210 return 18000000;
4211 case IPW_TX_RATE_24MB:
4212 return 24000000;
4213 case IPW_TX_RATE_36MB:
4214 return 36000000;
4215 case IPW_TX_RATE_48MB:
4216 return 48000000;
4217 case IPW_TX_RATE_54MB:
4218 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004219 }
4220
4221 return 0;
4222}
4223
James Ketrenos43f66a62005-03-25 12:31:53 -06004224#define IPW_STATS_INTERVAL (2 * HZ)
4225static void ipw_gather_stats(struct ipw_priv *priv)
4226{
4227 u32 rx_err, rx_err_delta, rx_packets_delta;
4228 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4229 u32 missed_beacons_percent, missed_beacons_delta;
4230 u32 quality = 0;
4231 u32 len = sizeof(u32);
4232 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004233 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004234 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004235 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004236
4237 if (!(priv->status & STATUS_ASSOCIATED)) {
4238 priv->quality = 0;
4239 return;
4240 }
4241
4242 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004243 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004244 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004245 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004246 priv->last_missed_beacons = priv->missed_beacons;
4247 if (priv->assoc_request.beacon_interval) {
4248 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004249 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004250 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004251 } else {
4252 missed_beacons_percent = 0;
4253 }
4254 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4255
4256 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4257 rx_err_delta = rx_err - priv->last_rx_err;
4258 priv->last_rx_err = rx_err;
4259
4260 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4261 tx_failures_delta = tx_failures - priv->last_tx_failures;
4262 priv->last_tx_failures = tx_failures;
4263
4264 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4265 priv->last_rx_packets = priv->rx_packets;
4266
4267 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4268 priv->last_tx_packets = priv->tx_packets;
4269
4270 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004271 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004272 * Missed beacon: 100% = 0, 0% = 70% missed
4273 * Rate: 60% = 1Mbs, 100% = Max
4274 * Rx and Tx errors represent a straight % of total Rx/Tx
4275 * RSSI: 100% = > -50, 0% = < -80
4276 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004277 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004278 * The lowest computed quality is used.
4279 *
4280 */
4281#define BEACON_THRESHOLD 5
4282 beacon_quality = 100 - missed_beacons_percent;
4283 if (beacon_quality < BEACON_THRESHOLD)
4284 beacon_quality = 0;
4285 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004286 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004287 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004288 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004289 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004290
James Ketrenos43f66a62005-03-25 12:31:53 -06004291 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004292 max_rate = ipw_get_max_rate(priv);
4293 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004294 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4295 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004296
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004297 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004298 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004299 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004300 else
4301 rx_quality = 100;
4302 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4303 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004304
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004305 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004306 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004307 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004308 else
4309 tx_quality = 100;
4310 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4311 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004312
Zhu Yi00d21de2006-04-13 17:19:02 +08004313 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004314 signal_quality =
4315 (100 *
4316 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4317 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4318 (priv->ieee->perfect_rssi - rssi) *
4319 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4320 62 * (priv->ieee->perfect_rssi - rssi))) /
4321 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4322 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4323 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004324 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004325 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004326 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004327
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004328 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004329 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004330
Reinette Chatre21f8a732009-08-18 10:25:05 -07004331 quality = min(rx_quality, signal_quality);
4332 quality = min(tx_quality, quality);
4333 quality = min(rate_quality, quality);
4334 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004335 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004336 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4337 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004338 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004339 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4340 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004341 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004342 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4343 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004344 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004345 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4346 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004347 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004348 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4349 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004350
4351 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004352
Tejun Heobcb6d912011-01-26 12:12:50 +01004353 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL);
James Ketrenos43f66a62005-03-25 12:31:53 -06004354}
4355
David Howellsc4028952006-11-22 14:57:56 +00004356static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004357{
David Howellsc4028952006-11-22 14:57:56 +00004358 struct ipw_priv *priv =
4359 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004360 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004361 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004362 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004363}
4364
Ben Cahille7582562005-10-06 15:34:41 -05004365/* Missed beacon behavior:
4366 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4367 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4368 * Above disassociate threshold, give up and stop scanning.
4369 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004370static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004371 int missed_count)
4372{
4373 priv->notif_missed_beacons = missed_count;
4374
James Ketrenosafbf30a2005-08-25 00:05:33 -05004375 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004376 priv->status & STATUS_ASSOCIATED) {
4377 /* If associated and we've hit the missed
4378 * beacon threshold, disassociate, turn
4379 * off roaming, and abort any active scans */
4380 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004381 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004382 "Missed beacon: %d - disassociate\n", missed_count);
4383 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004384 if (priv->status & STATUS_SCANNING) {
4385 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4386 IPW_DL_STATE,
4387 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004388 schedule_work(&priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004389 }
4390
Tejun Heobcb6d912011-01-26 12:12:50 +01004391 schedule_work(&priv->disassociate);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004392 return;
4393 }
4394
4395 if (priv->status & STATUS_ROAMING) {
4396 /* If we are currently roaming, then just
4397 * print a debug statement... */
4398 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4399 "Missed beacon: %d - roam in progress\n",
4400 missed_count);
4401 return;
4402 }
4403
Zhu Yi4bfdb912006-01-24 16:37:16 +08004404 if (roaming &&
4405 (missed_count > priv->roaming_threshold &&
4406 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004407 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004408 * bit in the status and kick off a scan.
4409 * This can happen several times before we reach
4410 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004411 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4412 "Missed beacon: %d - initiate "
4413 "roaming\n", missed_count);
4414 if (!(priv->status & STATUS_ROAMING)) {
4415 priv->status |= STATUS_ROAMING;
4416 if (!(priv->status & STATUS_SCANNING))
Tejun Heobcb6d912011-01-26 12:12:50 +01004417 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004418 }
4419 return;
4420 }
4421
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004422 if (priv->status & STATUS_SCANNING &&
4423 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004424 /* Stop scan to keep fw from getting
4425 * stuck (only if we aren't roaming --
4426 * otherwise we'll never scan more than 2 or 3
4427 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004428 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4429 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004430 schedule_work(&priv->abort_scan);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004431 }
4432
4433 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004434}
4435
Dan Williams0b531672007-10-09 13:55:24 -04004436static void ipw_scan_event(struct work_struct *work)
4437{
4438 union iwreq_data wrqu;
4439
4440 struct ipw_priv *priv =
4441 container_of(work, struct ipw_priv, scan_event.work);
4442
4443 wrqu.data.length = 0;
4444 wrqu.data.flags = 0;
4445 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4446}
4447
4448static void handle_scan_event(struct ipw_priv *priv)
4449{
4450 /* Only userspace-requested scan completion events go out immediately */
4451 if (!priv->user_requested_scan) {
4452 if (!delayed_work_pending(&priv->scan_event))
Tejun Heobcb6d912011-01-26 12:12:50 +01004453 schedule_delayed_work(&priv->scan_event,
4454 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004455 } else {
4456 union iwreq_data wrqu;
4457
4458 priv->user_requested_scan = 0;
4459 cancel_delayed_work(&priv->scan_event);
4460
4461 wrqu.data.length = 0;
4462 wrqu.data.flags = 0;
4463 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4464 }
4465}
4466
James Ketrenos43f66a62005-03-25 12:31:53 -06004467/**
4468 * Handle host notification packet.
4469 * Called from interrupt routine
4470 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004471static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004472 struct ipw_rx_notification *notif)
4473{
John W. Linville9387b7c2008-09-30 20:59:05 -04004474 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004475 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004476
Al Viroe62e1ee2007-12-27 01:36:46 -05004477 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004478
James Ketrenos43f66a62005-03-25 12:31:53 -06004479 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004480 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4481 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004482
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004483 switch (assoc->state) {
4484 case CMAS_ASSOCIATED:{
4485 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4486 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004487 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004488 print_ssid(ssid, priv->essid,
4489 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004490 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004491
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004492 switch (priv->ieee->iw_mode) {
4493 case IW_MODE_INFRA:
4494 memcpy(priv->ieee->bssid,
4495 priv->bssid, ETH_ALEN);
4496 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004497
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004498 case IW_MODE_ADHOC:
4499 memcpy(priv->ieee->bssid,
4500 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004501
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004502 /* clear out the station table */
4503 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004504
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004505 IPW_DEBUG_ASSOC
4506 ("queueing adhoc check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004507 schedule_delayed_work(
4508 &priv->adhoc_check,
4509 le16_to_cpu(priv->
4510 assoc_request.
4511 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;
Tejun Heobcb6d912011-01-26 12:12:50 +01004517 schedule_work(&priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004518
Zhu Yie43e3c12006-04-13 17:20:45 +08004519#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004520#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004521 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004522 if ((priv->status & STATUS_AUTH) &&
4523 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4524 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004525 if ((sizeof
4526 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004527 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004528 <= size)
4529 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004530 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004531 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004532 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004533 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004534 };
4535
4536 IPW_DEBUG_QOS
4537 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004538 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004539 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004540 ieee,
4541 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004542 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004543 *)
4544 &notif->u.raw, &stats);
4545 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004546 }
James Ketrenosb095c382005-08-24 22:04:42 -05004547#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004548
James Ketrenosa613bff2005-08-24 21:43:11 -05004549 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004550
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004551 break;
4552 }
4553
4554 case CMAS_AUTHENTICATED:{
4555 if (priv->
4556 status & (STATUS_ASSOCIATED |
4557 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004558 struct notif_authenticate *auth
4559 = &notif->u.auth;
4560 IPW_DEBUG(IPW_DL_NOTIF |
4561 IPW_DL_STATE |
4562 IPW_DL_ASSOC,
4563 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004564 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004565 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004566 print_ssid(ssid,
4567 priv->
4568 essid,
4569 priv->
4570 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004571 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004572 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004573 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004574 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004575 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004576
4577 priv->status &=
4578 ~(STATUS_ASSOCIATING |
4579 STATUS_AUTH |
4580 STATUS_ASSOCIATED);
4581
James Ketrenosa613bff2005-08-24 21:43:11 -05004582 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004583 break;
4584 }
4585
4586 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4587 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004588 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004589 print_ssid(ssid, priv->essid,
4590 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004591 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004592 break;
4593 }
4594
4595 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004596 if (priv->status & STATUS_AUTH) {
4597 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004598 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004599 *resp;
4600 resp =
4601 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004602 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004603 *)&notif->u.raw;
4604 IPW_DEBUG(IPW_DL_NOTIF |
4605 IPW_DL_STATE |
4606 IPW_DL_ASSOC,
4607 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004608 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004609 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004610 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004611 (resp->status)));
4612 }
4613
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4615 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004616 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004617 print_ssid(ssid, priv->essid,
4618 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004619 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004620
4621 priv->status &=
4622 ~(STATUS_DISASSOCIATING |
4623 STATUS_ASSOCIATING |
4624 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004625 if (priv->assoc_network
4626 && (priv->assoc_network->
4627 capability &
4628 WLAN_CAPABILITY_IBSS))
4629 ipw_remove_current_network
4630 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004631
James Ketrenosa613bff2005-08-24 21:43:11 -05004632 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004633
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004634 break;
4635 }
4636
James Ketrenosb095c382005-08-24 22:04:42 -05004637 case CMAS_RX_ASSOC_RESP:
4638 break;
4639
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004640 default:
4641 IPW_ERROR("assoc: unknown (%d)\n",
4642 assoc->state);
4643 break;
4644 }
4645
James Ketrenos43f66a62005-03-25 12:31:53 -06004646 break;
4647 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004648
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004649 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4650 struct notif_authenticate *auth = &notif->u.auth;
4651 switch (auth->state) {
4652 case CMAS_AUTHENTICATED:
4653 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004654 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004655 print_ssid(ssid, priv->essid,
4656 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004657 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004658 priv->status |= STATUS_AUTH;
4659 break;
4660
4661 case CMAS_INIT:
4662 if (priv->status & STATUS_AUTH) {
4663 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4664 IPW_DL_ASSOC,
4665 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004666 le16_to_cpu(auth->status),
4667 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004668 (auth->
4669 status)));
4670 }
4671 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4672 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004673 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004674 print_ssid(ssid, priv->essid,
4675 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004676 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004677
4678 priv->status &= ~(STATUS_ASSOCIATING |
4679 STATUS_AUTH |
4680 STATUS_ASSOCIATED);
4681
James Ketrenosa613bff2005-08-24 21:43:11 -05004682 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004683 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004684
4685 case CMAS_TX_AUTH_SEQ_1:
4686 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4687 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4688 break;
4689 case CMAS_RX_AUTH_SEQ_2:
4690 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4691 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4692 break;
4693 case CMAS_AUTH_SEQ_1_PASS:
4694 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4695 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4696 break;
4697 case CMAS_AUTH_SEQ_1_FAIL:
4698 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4699 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4700 break;
4701 case CMAS_TX_AUTH_SEQ_3:
4702 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4703 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4704 break;
4705 case CMAS_RX_AUTH_SEQ_4:
4706 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4707 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4708 break;
4709 case CMAS_AUTH_SEQ_2_PASS:
4710 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4711 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4712 break;
4713 case CMAS_AUTH_SEQ_2_FAIL:
4714 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4715 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4716 break;
4717 case CMAS_TX_ASSOC:
4718 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4719 IPW_DL_ASSOC, "TX_ASSOC\n");
4720 break;
4721 case CMAS_RX_ASSOC_RESP:
4722 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4723 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004724
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004725 break;
4726 case CMAS_ASSOCIATED:
4727 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4728 IPW_DL_ASSOC, "ASSOCIATED\n");
4729 break;
4730 default:
4731 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4732 auth->state);
4733 break;
4734 }
4735 break;
4736 }
4737
4738 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4739 struct notif_channel_result *x =
4740 &notif->u.channel_result;
4741
Al Viroe62e1ee2007-12-27 01:36:46 -05004742 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004743 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4744 x->channel_num);
4745 } else {
4746 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4747 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004748 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004749 }
4750 break;
4751 }
4752
4753 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4754 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004755 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004756 IPW_DEBUG_SCAN
4757 ("Scan completed: type %d, %d channels, "
4758 "%d status\n", x->scan_type,
4759 x->num_channels, x->status);
4760 } else {
4761 IPW_ERROR("Scan completed of wrong size %d "
4762 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004763 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004764 }
4765
4766 priv->status &=
4767 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4768
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004769 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004770 cancel_delayed_work(&priv->scan_check);
4771
James Ketrenosb095c382005-08-24 22:04:42 -05004772 if (priv->status & STATUS_EXIT_PENDING)
4773 break;
4774
4775 priv->ieee->scans++;
4776
4777#ifdef CONFIG_IPW2200_MONITOR
4778 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004779 priv->status |= STATUS_SCAN_FORCED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004780 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004781 break;
4782 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004783 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004784#endif /* CONFIG_IPW2200_MONITOR */
4785
Dan Williamsea177302008-06-02 17:51:23 -04004786 /* Do queued direct scans first */
Tejun Heobcb6d912011-01-26 12:12:50 +01004787 if (priv->status & STATUS_DIRECT_SCAN_PENDING)
4788 schedule_delayed_work(&priv->request_direct_scan, 0);
Dan Williamsea177302008-06-02 17:51:23 -04004789
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004790 if (!(priv->status & (STATUS_ASSOCIATED |
4791 STATUS_ASSOCIATING |
4792 STATUS_ROAMING |
4793 STATUS_DISASSOCIATING)))
Tejun Heobcb6d912011-01-26 12:12:50 +01004794 schedule_work(&priv->associate);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004795 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004796 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4797 /* If a scan completed and we are in roam mode, then
4798 * the scan that completed was the one requested as a
4799 * result of entering roam... so, schedule the
4800 * roam work */
Tejun Heobcb6d912011-01-26 12:12:50 +01004801 schedule_work(&priv->roam);
Ben Cahille7582562005-10-06 15:34:41 -05004802 else
4803 /* Don't schedule if we aborted the scan */
4804 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004805 } else if (priv->status & STATUS_SCAN_PENDING)
Tejun Heobcb6d912011-01-26 12:12:50 +01004806 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004807 else if (priv->config & CFG_BACKGROUND_SCAN
4808 && priv->status & STATUS_ASSOCIATED)
Tejun Heobcb6d912011-01-26 12:12:50 +01004809 schedule_delayed_work(&priv->request_scan,
4810 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004811
4812 /* Send an empty event to user space.
4813 * We don't send the received data on the event because
4814 * it would require us to do complex transcoding, and
4815 * we want to minimise the work done in the irq handler
4816 * Use a request to extract the data.
4817 * Also, we generate this even for any scan, regardless
4818 * on how the scan was initiated. User space can just
4819 * sync on periodic scan to get fresh data...
4820 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004821 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4822 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004823 break;
4824 }
4825
4826 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4827 struct notif_frag_length *x = &notif->u.frag_len;
4828
Al Viroe62e1ee2007-12-27 01:36:46 -05004829 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004830 IPW_ERROR("Frag length: %d\n",
4831 le16_to_cpu(x->frag_length));
4832 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004833 IPW_ERROR("Frag length of wrong size %d "
4834 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004835 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004836 break;
4837 }
4838
4839 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4840 struct notif_link_deterioration *x =
4841 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004842
Al Viroe62e1ee2007-12-27 01:36:46 -05004843 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004844 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004845 "link deterioration: type %d, cnt %d\n",
4846 x->silence_notification_type,
4847 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004848 memcpy(&priv->last_link_deterioration, x,
4849 sizeof(*x));
4850 } else {
4851 IPW_ERROR("Link Deterioration of wrong size %d "
4852 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004853 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004854 }
4855 break;
4856 }
4857
4858 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4859 IPW_ERROR("Dino config\n");
4860 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004861 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004862 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004863
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004864 break;
4865 }
4866
4867 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4868 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004869 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004870 IPW_ERROR
4871 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004872 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004874 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004875
James Ketrenosa613bff2005-08-24 21:43:11 -05004876 if (le32_to_cpu(x->state) ==
4877 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4878 ipw_handle_missed_beacon(priv,
4879 le32_to_cpu(x->
4880 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004881
James Ketrenos43f66a62005-03-25 12:31:53 -06004882 break;
4883 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004884
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4886 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004887 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004888 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4889 "0x%02x station %d\n",
4890 x->key_state, x->security_type,
4891 x->station_index);
4892 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004893 }
4894
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004895 IPW_ERROR
4896 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004897 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004898 break;
4899 }
4900
4901 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4902 struct notif_calibration *x = &notif->u.calibration;
4903
Al Viroe62e1ee2007-12-27 01:36:46 -05004904 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004905 memcpy(&priv->calib, x, sizeof(*x));
4906 IPW_DEBUG_INFO("TODO: Calibration\n");
4907 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004908 }
4909
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004910 IPW_ERROR
4911 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004912 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004913 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004914 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004915
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004916 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004917 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004918 priv->exp_avg_noise =
4919 exponential_average(priv->exp_avg_noise,
4920 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4921 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004922 break;
4923 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004924
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004925 IPW_ERROR
4926 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004927 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004929 }
4930
James Ketrenos43f66a62005-03-25 12:31:53 -06004931 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004932 IPW_DEBUG_NOTIF("Unknown notification: "
4933 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004934 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004935 }
4936}
4937
4938/**
4939 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004940 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 * @param priv
4942 * @return error code
4943 */
4944static int ipw_queue_reset(struct ipw_priv *priv)
4945{
4946 int rc = 0;
4947 /** @todo customize queue sizes */
4948 int nTx = 64, nTxCmd = 8;
4949 ipw_tx_queue_free(priv);
4950 /* Tx CMD queue */
4951 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004952 IPW_TX_CMD_QUEUE_READ_INDEX,
4953 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4954 IPW_TX_CMD_QUEUE_BD_BASE,
4955 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004956 if (rc) {
4957 IPW_ERROR("Tx Cmd queue init failed\n");
4958 goto error;
4959 }
4960 /* Tx queue(s) */
4961 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004962 IPW_TX_QUEUE_0_READ_INDEX,
4963 IPW_TX_QUEUE_0_WRITE_INDEX,
4964 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004965 if (rc) {
4966 IPW_ERROR("Tx 0 queue init failed\n");
4967 goto error;
4968 }
4969 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004970 IPW_TX_QUEUE_1_READ_INDEX,
4971 IPW_TX_QUEUE_1_WRITE_INDEX,
4972 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 if (rc) {
4974 IPW_ERROR("Tx 1 queue init failed\n");
4975 goto error;
4976 }
4977 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004978 IPW_TX_QUEUE_2_READ_INDEX,
4979 IPW_TX_QUEUE_2_WRITE_INDEX,
4980 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004981 if (rc) {
4982 IPW_ERROR("Tx 2 queue init failed\n");
4983 goto error;
4984 }
4985 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004986 IPW_TX_QUEUE_3_READ_INDEX,
4987 IPW_TX_QUEUE_3_WRITE_INDEX,
4988 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004989 if (rc) {
4990 IPW_ERROR("Tx 3 queue init failed\n");
4991 goto error;
4992 }
4993 /* statistics */
4994 priv->rx_bufs_min = 0;
4995 priv->rx_pend_max = 0;
4996 return rc;
4997
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004998 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004999 ipw_tx_queue_free(priv);
5000 return rc;
5001}
5002
5003/**
5004 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005005 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005006 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005007 * new 'R' index need to be reclaimed. As result, some free space
5008 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005009 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005010 * @note Need to protect against garbage in 'R' index
5011 * @param priv
5012 * @param txq
5013 * @param qindex
5014 * @return Number of used entries remains in the queue
5015 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005016static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 struct clx2_tx_queue *txq, int qindex)
5018{
5019 u32 hw_tail;
5020 int used;
5021 struct clx2_queue *q = &txq->q;
5022
5023 hw_tail = ipw_read32(priv, q->reg_r);
5024 if (hw_tail >= q->n_bd) {
5025 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005026 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5027 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 goto done;
5029 }
5030 for (; q->last_used != hw_tail;
5031 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5032 ipw_queue_tx_free_tfd(priv, txq);
5033 priv->tx_packets++;
5034 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005035 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005036 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005037 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005038 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005039 used = q->first_empty - q->last_used;
5040 if (used < 0)
5041 used += q->n_bd;
5042
5043 return used;
5044}
5045
5046static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5047 int len, int sync)
5048{
5049 struct clx2_tx_queue *txq = &priv->txq_cmd;
5050 struct clx2_queue *q = &txq->q;
5051 struct tfd_frame *tfd;
5052
Dan Williams943dbef2008-02-14 17:49:41 -05005053 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005054 IPW_ERROR("No space for Tx\n");
5055 return -EBUSY;
5056 }
5057
5058 tfd = &txq->bd[q->first_empty];
5059 txq->txb[q->first_empty] = NULL;
5060
5061 memset(tfd, 0, sizeof(*tfd));
5062 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5063 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5064 priv->hcmd_seq++;
5065 tfd->u.cmd.index = hcmd;
5066 tfd->u.cmd.length = len;
5067 memcpy(tfd->u.cmd.payload, buf, len);
5068 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5069 ipw_write32(priv, q->reg_w, q->first_empty);
5070 _ipw_read32(priv, 0x90);
5071
5072 return 0;
5073}
5074
Jeff Garzikbf794512005-07-31 13:07:26 -04005075/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005076 * Rx theory of operation
5077 *
5078 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005079 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005080 * 0 to 31
5081 *
5082 * Rx Queue Indexes
5083 * The host/firmware share two index registers for managing the Rx buffers.
5084 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005085 * The READ index maps to the first position that the firmware may be writing
5086 * to -- the driver can read up to (but not including) this position and get
5087 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 * The READ index is managed by the firmware once the card is enabled.
5089 *
5090 * The WRITE index maps to the last position the driver has read from -- the
5091 * position preceding WRITE is the last slot the firmware can place a packet.
5092 *
5093 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005094 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005096 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005097 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5098 *
5099 * When the firmware places a packet in a buffer it will advance the READ index
5100 * and fire the RX interrupt. The driver can then query the READ index and
5101 * process as many packets as possible, moving the WRITE index forward as it
5102 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005103 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005104 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005105 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005106 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005107 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005108 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5109 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5110 * 'processed' and 'read' driver indexes as well)
5111 * + A received packet is processed and handed to the kernel network stack,
5112 * detached from the ipw->rxq. The driver 'processed' index is updated.
5113 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005114 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5115 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 * were enough free buffers and RX_STALLED is set it is cleared.
5117 *
5118 *
5119 * Driver sequence:
5120 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005122 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5123 * ipw_rx_queue_restock
5124 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5125 * queue, updates firmware pointers, and updates
5126 * the WRITE index. If insufficient rx_free buffers
5127 * are available, schedules ipw_rx_queue_replenish
5128 *
5129 * -- enable interrupts --
5130 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005131 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005132 * Moves the packet buffer from queue to rx_used.
5133 * Calls ipw_rx_queue_restock to refill any empty
5134 * slots.
5135 * ...
5136 *
5137 */
5138
Jeff Garzikbf794512005-07-31 13:07:26 -04005139/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005140 * If there are slots in the RX queue that need to be restocked,
5141 * and we have free pre-allocated buffers, fill the ranks as much
5142 * as we can pulling from rx_free.
5143 *
5144 * This moves the 'write' index forward to catch up with 'processed', and
5145 * also updates the memory address in the firmware to reference the new
5146 * target buffer.
5147 */
5148static void ipw_rx_queue_restock(struct ipw_priv *priv)
5149{
5150 struct ipw_rx_queue *rxq = priv->rxq;
5151 struct list_head *element;
5152 struct ipw_rx_mem_buffer *rxb;
5153 unsigned long flags;
5154 int write;
5155
5156 spin_lock_irqsave(&rxq->lock, flags);
5157 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005158 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005159 element = rxq->rx_free.next;
5160 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5161 list_del(element);
5162
James Ketrenosb095c382005-08-24 22:04:42 -05005163 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005164 rxb->dma_addr);
5165 rxq->queue[rxq->write] = rxb;
5166 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5167 rxq->free_count--;
5168 }
5169 spin_unlock_irqrestore(&rxq->lock, flags);
5170
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005172 * refill it */
5173 if (rxq->free_count <= RX_LOW_WATERMARK)
Tejun Heobcb6d912011-01-26 12:12:50 +01005174 schedule_work(&priv->rx_replenish);
James Ketrenos43f66a62005-03-25 12:31:53 -06005175
5176 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005177 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005178 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005179}
5180
5181/*
5182 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 * Also restock the Rx queue via ipw_rx_queue_restock.
5184 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005185 * This is called as a scheduled work item (except for during intialization)
5186 */
5187static void ipw_rx_queue_replenish(void *data)
5188{
5189 struct ipw_priv *priv = data;
5190 struct ipw_rx_queue *rxq = priv->rxq;
5191 struct list_head *element;
5192 struct ipw_rx_mem_buffer *rxb;
5193 unsigned long flags;
5194
5195 spin_lock_irqsave(&rxq->lock, flags);
5196 while (!list_empty(&rxq->rx_used)) {
5197 element = rxq->rx_used.next;
5198 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005199 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005200 if (!rxb->skb) {
5201 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5202 priv->net_dev->name);
5203 /* We don't reschedule replenish work here -- we will
5204 * call the restock method and if it still needs
5205 * more buffers it will schedule replenish */
5206 break;
5207 }
5208 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005209
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005210 rxb->dma_addr =
5211 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005212 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005213
James Ketrenos43f66a62005-03-25 12:31:53 -06005214 list_add_tail(&rxb->list, &rxq->rx_free);
5215 rxq->free_count++;
5216 }
5217 spin_unlock_irqrestore(&rxq->lock, flags);
5218
5219 ipw_rx_queue_restock(priv);
5220}
5221
David Howellsc4028952006-11-22 14:57:56 +00005222static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005223{
David Howellsc4028952006-11-22 14:57:56 +00005224 struct ipw_priv *priv =
5225 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005226 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005227 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005228 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005229}
5230
James Ketrenos43f66a62005-03-25 12:31:53 -06005231/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005232 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005233 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005234 * non NULL it is unmapped and freed
5235 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005236static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005237{
5238 int i;
5239
5240 if (!rxq)
5241 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005242
James Ketrenos43f66a62005-03-25 12:31:53 -06005243 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5244 if (rxq->pool[i].skb != NULL) {
5245 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005246 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005247 dev_kfree_skb(rxq->pool[i].skb);
5248 }
5249 }
5250
5251 kfree(rxq);
5252}
5253
5254static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5255{
5256 struct ipw_rx_queue *rxq;
5257 int i;
5258
Takisc75f4742005-12-01 01:41:45 -08005259 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005260 if (unlikely(!rxq)) {
5261 IPW_ERROR("memory allocation failed\n");
5262 return NULL;
5263 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005264 spin_lock_init(&rxq->lock);
5265 INIT_LIST_HEAD(&rxq->rx_free);
5266 INIT_LIST_HEAD(&rxq->rx_used);
5267
5268 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005269 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005270 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5271
5272 /* Set us so that we have processed and used all buffers, but have
5273 * not restocked the Rx queue with fresh buffers */
5274 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005275 rxq->free_count = 0;
5276
5277 return rxq;
5278}
5279
5280static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5281{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005282 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283 if (ieee_mode == IEEE_A) {
5284 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005285 case LIBIPW_OFDM_RATE_6MB:
5286 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005287 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005288 case LIBIPW_OFDM_RATE_9MB:
5289 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005291 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005292 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005293 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5294 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005295 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005296 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5297 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005298 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005299 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5300 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005301 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005302 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5303 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005304 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005305 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5306 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005307 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005308 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005309 default:
5310 return 0;
5311 }
5312 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005313
James Ketrenos43f66a62005-03-25 12:31:53 -06005314 /* B and G mixed */
5315 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005316 case LIBIPW_CCK_RATE_1MB:
5317 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5318 case LIBIPW_CCK_RATE_2MB:
5319 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5320 case LIBIPW_CCK_RATE_5MB:
5321 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5322 case LIBIPW_CCK_RATE_11MB:
5323 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005324 }
5325
5326 /* If we are limited to B modulations, bail at this point */
5327 if (ieee_mode == IEEE_B)
5328 return 0;
5329
5330 /* G */
5331 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005332 case LIBIPW_OFDM_RATE_6MB:
5333 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5334 case LIBIPW_OFDM_RATE_9MB:
5335 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5336 case LIBIPW_OFDM_RATE_12MB:
5337 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5338 case LIBIPW_OFDM_RATE_18MB:
5339 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5340 case LIBIPW_OFDM_RATE_24MB:
5341 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5342 case LIBIPW_OFDM_RATE_36MB:
5343 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5344 case LIBIPW_OFDM_RATE_48MB:
5345 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5346 case LIBIPW_OFDM_RATE_54MB:
5347 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005348 }
5349
5350 return 0;
5351}
5352
Jeff Garzikbf794512005-07-31 13:07:26 -04005353static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005354 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005355 struct ipw_supported_rates *rates)
5356{
5357 int num_rates, i;
5358
5359 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005360 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005361 rates->num_rates = 0;
5362 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005363 if (!ipw_is_rate_in_mask(priv, network->mode,
5364 network->rates[i])) {
5365
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005366 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005367 IPW_DEBUG_SCAN("Adding masked mandatory "
5368 "rate %02X\n",
5369 network->rates[i]);
5370 rates->supported_rates[rates->num_rates++] =
5371 network->rates[i];
5372 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005373 }
5374
James Ketrenos43f66a62005-03-25 12:31:53 -06005375 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5376 network->rates[i], priv->rates_mask);
5377 continue;
5378 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005379
James Ketrenos43f66a62005-03-25 12:31:53 -06005380 rates->supported_rates[rates->num_rates++] = network->rates[i];
5381 }
5382
James Ketrenosa613bff2005-08-24 21:43:11 -05005383 num_rates = min(network->rates_ex_len,
5384 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005385 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005386 if (!ipw_is_rate_in_mask(priv, network->mode,
5387 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005388 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005389 IPW_DEBUG_SCAN("Adding masked mandatory "
5390 "rate %02X\n",
5391 network->rates_ex[i]);
5392 rates->supported_rates[rates->num_rates++] =
5393 network->rates[i];
5394 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005395 }
5396
James Ketrenos43f66a62005-03-25 12:31:53 -06005397 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5398 network->rates_ex[i], priv->rates_mask);
5399 continue;
5400 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005402 rates->supported_rates[rates->num_rates++] =
5403 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005404 }
5405
James Ketrenosea2b26e2005-08-24 21:25:16 -05005406 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005407}
5408
Arjan van de Ven858119e2006-01-14 13:20:43 -08005409static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005410 const struct ipw_supported_rates *src)
5411{
5412 u8 i;
5413 for (i = 0; i < src->num_rates; i++)
5414 dest->supported_rates[i] = src->supported_rates[i];
5415 dest->num_rates = src->num_rates;
5416}
5417
5418/* TODO: Look at sniffed packets in the air to determine if the basic rate
5419 * mask should ever be used -- right now all callers to add the scan rates are
5420 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5421static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005422 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005423{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005424 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5425 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005426
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005427 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005428 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005429 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005430
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005431 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005432 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005433 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005434
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005435 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005436 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005437 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005438
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005439 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005440 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005441 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005442}
5443
5444static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005445 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005446{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005447 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5448 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005449
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005450 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005451 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005452 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005453
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005454 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005455 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005456 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005457
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005459 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005460 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005461
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005462 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005463 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005464 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005465
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005466 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005467 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005468 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005469
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005470 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005471 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005472 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005473
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005474 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005475 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005476 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005477
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005478 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005479 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005480 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005481}
5482
5483struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005484 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005485 struct ipw_supported_rates rates;
5486};
5487
James Ketrenosc848d0a2005-08-24 21:56:24 -05005488static int ipw_find_adhoc_network(struct ipw_priv *priv,
5489 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005490 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005491 int roaming)
5492{
5493 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005494 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005495
5496 /* Verify that this network's capability is compatible with the
5497 * current mode (AdHoc or Infrastructure) */
5498 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5499 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005500 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005501 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005502 print_ssid(ssid, network->ssid,
5503 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005504 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005505 return 0;
5506 }
5507
James Ketrenosc848d0a2005-08-24 21:56:24 -05005508 if (unlikely(roaming)) {
5509 /* If we are roaming, then ensure check if this is a valid
5510 * network to try and roam to */
5511 if ((network->ssid_len != match->network->ssid_len) ||
5512 memcmp(network->ssid, match->network->ssid,
5513 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005514 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005515 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005516 print_ssid(ssid, network->ssid,
5517 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005518 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005519 return 0;
5520 }
5521 } else {
5522 /* If an ESSID has been configured then compare the broadcast
5523 * ESSID to ours */
5524 if ((priv->config & CFG_STATIC_ESSID) &&
5525 ((network->ssid_len != priv->essid_len) ||
5526 memcmp(network->ssid, priv->essid,
5527 min(network->ssid_len, priv->essid_len)))) {
5528 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005529
James Ketrenosc848d0a2005-08-24 21:56:24 -05005530 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005531 print_ssid(ssid, network->ssid,
5532 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005533 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005534 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005535 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005536 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005537 print_ssid(ssid, priv->essid,
5538 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005539 return 0;
5540 }
5541 }
5542
5543 /* If the old network rate is better than this one, don't bother
5544 * testing everything else. */
5545
5546 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005547 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5548 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005549 print_ssid(ssid, match->network->ssid,
5550 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005551 return 0;
5552 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005553 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5554 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005555 print_ssid(ssid, match->network->ssid,
5556 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005557 return 0;
5558 }
5559
5560 /* Now go through and see if the requested network is valid... */
5561 if (priv->ieee->scan_age != 0 &&
5562 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005563 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005564 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005565 print_ssid(ssid, network->ssid,
5566 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005567 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005568 jiffies_to_msecs(jiffies -
5569 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005570 return 0;
5571 }
5572
5573 if ((priv->config & CFG_STATIC_CHANNEL) &&
5574 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005575 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005576 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005577 print_ssid(ssid, network->ssid,
5578 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005579 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005580 network->channel, priv->channel);
5581 return 0;
5582 }
5583
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005584 /* Verify privacy compatibility */
James Ketrenosc848d0a2005-08-24 21:56:24 -05005585 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5586 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005587 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005588 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005589 print_ssid(ssid, network->ssid,
5590 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005591 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005592 priv->
5593 capability & CAP_PRIVACY_ON ? "on" : "off",
5594 network->
5595 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5596 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005597 return 0;
5598 }
5599
5600 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005601 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5602 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005603 ".\n", print_ssid(ssid, network->ssid,
5604 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005605 network->bssid,
5606 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005607 return 0;
5608 }
5609
5610 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005611 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005612 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005613 "because of invalid frequency/mode "
5614 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005615 print_ssid(ssid, network->ssid,
5616 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005617 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005618 return 0;
5619 }
5620
5621 /* Ensure that the rates supported by the driver are compatible with
5622 * this AP, including verification of basic rates (mandatory) */
5623 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005624 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625 "because configured rate mask excludes "
5626 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005627 print_ssid(ssid, network->ssid,
5628 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005629 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005630 return 0;
5631 }
5632
5633 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005634 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005635 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005636 print_ssid(ssid, network->ssid,
5637 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005638 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005639 return 0;
5640 }
5641
5642 /* TODO: Perform any further minimal comparititive tests. We do not
5643 * want to put too much policy logic here; intelligent scan selection
5644 * should occur within a generic IEEE 802.11 user space tool. */
5645
5646 /* Set up 'new' AP to this network */
5647 ipw_copy_rates(&match->rates, &rates);
5648 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005649 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005650 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005651 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005652
5653 return 1;
5654}
5655
David Howellsc4028952006-11-22 14:57:56 +00005656static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005657{
John W. Linville9387b7c2008-09-30 20:59:05 -04005658 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005659 struct ipw_priv *priv =
5660 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005661 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005662 struct ipw_network_match match = {
5663 .network = priv->assoc_network
5664 };
5665
James Ketrenosafbf30a2005-08-25 00:05:33 -05005666 if ((priv->status & STATUS_ASSOCIATED) &&
5667 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005668 /* First pass through ROAM process -- look for a better
5669 * network */
5670 unsigned long flags;
5671
5672 spin_lock_irqsave(&priv->ieee->lock, flags);
5673 list_for_each_entry(network, &priv->ieee->network_list, list) {
5674 if (network != priv->assoc_network)
5675 ipw_find_adhoc_network(priv, &match, network,
5676 1);
5677 }
5678 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5679
5680 if (match.network == priv->assoc_network) {
5681 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5682 "merge to.\n");
5683 return;
5684 }
5685
Zhu Yi46441512006-01-24 16:37:59 +08005686 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005687 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5688 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005689 print_ssid(ssid, priv->essid,
5690 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005691 ipw_remove_current_network(priv);
5692 }
5693
5694 ipw_disassociate(priv);
5695 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005696 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005697 return;
5698 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005699}
5700
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005701static int ipw_best_network(struct ipw_priv *priv,
5702 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005703 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005704{
5705 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005706 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005707
5708 /* Verify that this network's capability is compatible with the
5709 * current mode (AdHoc or Infrastructure) */
5710 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005711 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005712 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5713 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005714 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005715 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005716 print_ssid(ssid, network->ssid,
5717 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005718 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005719 return 0;
5720 }
5721
James Ketrenos43f66a62005-03-25 12:31:53 -06005722 if (unlikely(roaming)) {
5723 /* If we are roaming, then ensure check if this is a valid
5724 * network to try and roam to */
5725 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005726 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005728 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005729 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005730 print_ssid(ssid, network->ssid,
5731 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005732 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005733 return 0;
5734 }
5735 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005736 /* If an ESSID has been configured then compare the broadcast
5737 * ESSID to ours */
5738 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005739 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005740 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005741 min(network->ssid_len, priv->essid_len)))) {
5742 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005743 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005744 print_ssid(ssid, network->ssid,
5745 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005746 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005747 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005748 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005749 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005750 print_ssid(ssid, priv->essid,
5751 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005752 return 0;
5753 }
5754 }
5755
5756 /* If the old network rate is better than this one, don't bother
5757 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005758 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005759 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005760 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005761 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005762 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005763 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5764 "'%s (%pM)' has a stronger signal.\n",
5765 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005766 print_ssid(ssid, match->network->ssid,
5767 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005768 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005769 return 0;
5770 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005771
James Ketrenos43f66a62005-03-25 12:31:53 -06005772 /* If this network has already had an association attempt within the
5773 * last 3 seconds, do not try and associate again... */
5774 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005775 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005776 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005777 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005779 print_ssid(ssid, network->ssid,
5780 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005781 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005782 jiffies_to_msecs(jiffies -
5783 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005784 return 0;
5785 }
5786
5787 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005788 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005789 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005790 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005791 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005792 print_ssid(ssid, network->ssid,
5793 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005794 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005795 jiffies_to_msecs(jiffies -
5796 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005798 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005799
Jeff Garzikbf794512005-07-31 13:07:26 -04005800 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005801 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005802 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005803 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005804 print_ssid(ssid, network->ssid,
5805 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005806 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 network->channel, priv->channel);
5808 return 0;
5809 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005810
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005811 /* Verify privacy compatibility */
Jeff Garzikbf794512005-07-31 13:07:26 -04005812 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005813 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005814 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005816 print_ssid(ssid, network->ssid,
5817 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005818 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005819 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005821 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005822 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005823 return 0;
5824 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005825
5826 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005827 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005828 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5829 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005830 print_ssid(ssid, network->ssid,
5831 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005832 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005833 return 0;
5834 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005835
James Ketrenos43f66a62005-03-25 12:31:53 -06005836 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005837 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005838 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005839 "because of invalid frequency/mode "
5840 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005841 print_ssid(ssid, network->ssid,
5842 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005843 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 return 0;
5845 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005846
Liu Hong1fe0adb2005-08-19 09:33:10 -05005847 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005848 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005849 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005850 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005851 print_ssid(ssid, network->ssid,
5852 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005853 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005854 return 0;
5855 }
5856
James Ketrenosea2b26e2005-08-24 21:25:16 -05005857 /* Ensure that the rates supported by the driver are compatible with
5858 * this AP, including verification of basic rates (mandatory) */
5859 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005860 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005861 "because configured rate mask excludes "
5862 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005863 print_ssid(ssid, network->ssid,
5864 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005865 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005866 return 0;
5867 }
5868
James Ketrenos43f66a62005-03-25 12:31:53 -06005869 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005870 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005871 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005872 print_ssid(ssid, network->ssid,
5873 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005874 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005875 return 0;
5876 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005877
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 /* TODO: Perform any further minimal comparititive tests. We do not
5879 * want to put too much policy logic here; intelligent scan selection
5880 * should occur within a generic IEEE 802.11 user space tool. */
5881
5882 /* Set up 'new' AP to this network */
5883 ipw_copy_rates(&match->rates, &rates);
5884 match->network = network;
5885
Johannes Berge1749612008-10-27 15:59:26 -07005886 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005887 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005888 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005889
5890 return 1;
5891}
5892
Jeff Garzikbf794512005-07-31 13:07:26 -04005893static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005894 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005895{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005896 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005897 int i;
5898
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 /*
5900 * For the purposes of scanning, we can set our wireless mode
5901 * to trigger scans across combinations of bands, but when it
5902 * comes to creating a new ad-hoc network, we have tell the FW
5903 * exactly which band to use.
5904 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005905 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 * chossen band. Attempting to create a new ad-hoc network
5907 * with an invalid channel for wireless mode will trigger a
5908 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005909 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005910 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005911 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5912 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005913 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005914 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005915 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005916 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005917 IPW_WARNING("Overriding invalid channel\n");
5918 priv->channel = geo->a[0].channel;
5919 }
5920 break;
5921
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005922 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005923 if (priv->ieee->mode & IEEE_G)
5924 network->mode = IEEE_G;
5925 else
5926 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005927 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005928 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005929 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005930 IPW_WARNING("Overriding invalid channel\n");
5931 priv->channel = geo->bg[0].channel;
5932 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005933 break;
5934
5935 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005936 IPW_WARNING("Overriding invalid channel\n");
5937 if (priv->ieee->mode & IEEE_A) {
5938 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005939 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005940 } else if (priv->ieee->mode & IEEE_G) {
5941 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005942 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005943 } else {
5944 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005945 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005946 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005947 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005948 }
5949
5950 network->channel = priv->channel;
5951 priv->config |= CFG_ADHOC_PERSIST;
5952 ipw_create_bssid(priv, network->bssid);
5953 network->ssid_len = priv->essid_len;
5954 memcpy(network->ssid, priv->essid, priv->essid_len);
5955 memset(&network->stats, 0, sizeof(network->stats));
5956 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005957 if (!(priv->config & CFG_PREAMBLE_LONG))
5958 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005959 if (priv->capability & CAP_PRIVACY_ON)
5960 network->capability |= WLAN_CAPABILITY_PRIVACY;
5961 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005962 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005963 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005964 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005965 &priv->rates.supported_rates[network->rates_len],
5966 network->rates_ex_len);
5967 network->last_scanned = 0;
5968 network->flags = 0;
5969 network->last_associate = 0;
5970 network->time_stamp[0] = 0;
5971 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005972 network->beacon_interval = 100; /* Default */
5973 network->listen_interval = 10; /* Default */
5974 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005975 network->wpa_ie_len = 0;
5976 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005977}
5978
James Ketrenosb095c382005-08-24 22:04:42 -05005979static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5980{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005981 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005982
5983 if (!(priv->ieee->sec.flags & (1 << index)))
5984 return;
5985
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005986 key.key_id = index;
5987 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5988 key.security_type = type;
5989 key.station_index = 0; /* always 0 for BSS */
5990 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005991 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005992 key.tx_counter[0] = cpu_to_le32(0);
5993 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005994
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005995 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005996}
5997
5998static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005999{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006000 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006001 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006003 key.cmd_id = DINO_CMD_WEP_KEY;
6004 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006005
James Ketrenosb095c382005-08-24 22:04:42 -05006006 /* Note: AES keys cannot be set for multiple times.
6007 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006008 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006009 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006010 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006011 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006012 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006013 }
6014
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006015 key.key_size = priv->ieee->sec.key_sizes[i];
6016 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006017
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006018 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006019 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006020}
6021
Zhu Yi1fbfea52005-08-05 17:22:56 +08006022static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6023{
6024 if (priv->ieee->host_encrypt)
6025 return;
6026
6027 switch (level) {
6028 case SEC_LEVEL_3:
6029 priv->sys_config.disable_unicast_decryption = 0;
6030 priv->ieee->host_decrypt = 0;
6031 break;
6032 case SEC_LEVEL_2:
6033 priv->sys_config.disable_unicast_decryption = 1;
6034 priv->ieee->host_decrypt = 1;
6035 break;
6036 case SEC_LEVEL_1:
6037 priv->sys_config.disable_unicast_decryption = 0;
6038 priv->ieee->host_decrypt = 0;
6039 break;
6040 case SEC_LEVEL_0:
6041 priv->sys_config.disable_unicast_decryption = 1;
6042 break;
6043 default:
6044 break;
6045 }
6046}
6047
6048static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6049{
6050 if (priv->ieee->host_encrypt)
6051 return;
6052
6053 switch (level) {
6054 case SEC_LEVEL_3:
6055 priv->sys_config.disable_multicast_decryption = 0;
6056 break;
6057 case SEC_LEVEL_2:
6058 priv->sys_config.disable_multicast_decryption = 1;
6059 break;
6060 case SEC_LEVEL_1:
6061 priv->sys_config.disable_multicast_decryption = 0;
6062 break;
6063 case SEC_LEVEL_0:
6064 priv->sys_config.disable_multicast_decryption = 1;
6065 break;
6066 default:
6067 break;
6068 }
6069}
6070
James Ketrenosb095c382005-08-24 22:04:42 -05006071static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6072{
6073 switch (priv->ieee->sec.level) {
6074 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006075 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6076 ipw_send_tgi_tx_key(priv,
6077 DCT_FLAG_EXT_SECURITY_CCM,
6078 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006079
Hong Liu567deaf2005-08-31 18:07:22 +08006080 if (!priv->ieee->host_mc_decrypt)
6081 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006082 break;
6083 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006084 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6085 ipw_send_tgi_tx_key(priv,
6086 DCT_FLAG_EXT_SECURITY_TKIP,
6087 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006088 break;
6089 case SEC_LEVEL_1:
6090 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006091 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6092 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006093 break;
6094 case SEC_LEVEL_0:
6095 default:
6096 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006097 }
6098}
6099
6100static void ipw_adhoc_check(void *data)
6101{
6102 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006103
James Ketrenosafbf30a2005-08-25 00:05:33 -05006104 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006105 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006106 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6107 IPW_DL_STATE | IPW_DL_ASSOC,
6108 "Missed beacon: %d - disassociate\n",
6109 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006110 ipw_remove_current_network(priv);
6111 ipw_disassociate(priv);
6112 return;
6113 }
6114
Tejun Heobcb6d912011-01-26 12:12:50 +01006115 schedule_delayed_work(&priv->adhoc_check,
6116 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006117}
6118
David Howellsc4028952006-11-22 14:57:56 +00006119static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006120{
David Howellsc4028952006-11-22 14:57:56 +00006121 struct ipw_priv *priv =
6122 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006123 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006124 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006125 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006126}
6127
James Ketrenos43f66a62005-03-25 12:31:53 -06006128static void ipw_debug_config(struct ipw_priv *priv)
6129{
John W. Linville9387b7c2008-09-30 20:59:05 -04006130 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006131 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6132 "[CFG 0x%08X]\n", priv->config);
6133 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006134 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006135 else
6136 IPW_DEBUG_INFO("Channel unlocked.\n");
6137 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006138 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006139 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006140 else
6141 IPW_DEBUG_INFO("ESSID unlocked.\n");
6142 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006143 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006144 else
6145 IPW_DEBUG_INFO("BSSID unlocked.\n");
6146 if (priv->capability & CAP_PRIVACY_ON)
6147 IPW_DEBUG_INFO("PRIVACY on\n");
6148 else
6149 IPW_DEBUG_INFO("PRIVACY off\n");
6150 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6151}
James Ketrenos43f66a62005-03-25 12:31:53 -06006152
Arjan van de Ven858119e2006-01-14 13:20:43 -08006153static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006154{
6155 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006156 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006157 u32 reg;
6158 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006159 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006160
Jeff Garzikbf794512005-07-31 13:07:26 -04006161 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006162 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006163
James Ketrenos43f66a62005-03-25 12:31:53 -06006164 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006165 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006166 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006167 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006168 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006169 IPW_DEBUG_WX
6170 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006171 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006172 break;
6173 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006174
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006175 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006176 break;
6177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006178 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006179 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006180 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006181 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006182 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006183 IPW_DEBUG_WX
6184 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006185 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006186 }
6187 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006188 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006189
6190 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006191 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6192 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006193 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006194 IPW_DEBUG_WX
6195 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006196 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006197 break;
6198 }
6199
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006200 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6201 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6202 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006203 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006204
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006205 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6206 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6207 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006208 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006209
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006210 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6211 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6212 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006213 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006214
Reinette Chatre21f8a732009-08-18 10:25:05 -07006215 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006216 break;
6217 }
6218
Reinette Chatre21f8a732009-08-18 10:25:05 -07006219 fr.tx_rates = cpu_to_le16(new_tx_rates);
6220
James Ketrenos43f66a62005-03-25 12:31:53 -06006221 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006222 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006223}
6224
James Ketrenosea2b26e2005-08-24 21:25:16 -05006225static void ipw_abort_scan(struct ipw_priv *priv)
6226{
6227 int err;
6228
6229 if (priv->status & STATUS_SCAN_ABORTING) {
6230 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6231 return;
6232 }
6233 priv->status |= STATUS_SCAN_ABORTING;
6234
6235 err = ipw_send_scan_abort(priv);
6236 if (err)
6237 IPW_DEBUG_HC("Request to abort scan failed.\n");
6238}
6239
James Ketrenosafbf30a2005-08-25 00:05:33 -05006240static void ipw_add_scan_channels(struct ipw_priv *priv,
6241 struct ipw_scan_request_ext *scan,
6242 int scan_type)
6243{
6244 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006245 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006246 int i;
6247
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006248 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006249
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006250 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006251 int start = channel_index;
6252 for (i = 0; i < geo->a_channels; i++) {
6253 if ((priv->status & STATUS_ASSOCIATED) &&
6254 geo->a[i].channel == priv->channel)
6255 continue;
6256 channel_index++;
6257 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006258 ipw_set_scan_type(scan, channel_index,
6259 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006260 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006261 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6262 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006263 }
6264
6265 if (start != channel_index) {
6266 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6267 (channel_index - start);
6268 channel_index++;
6269 }
6270 }
6271
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006272 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006273 int start = channel_index;
6274 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006275 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006276 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006277 /* nop out the list */
6278 [0] = 0
6279 };
6280
6281 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006282 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006283 channel =
6284 priv->speed_scan[priv->speed_scan_pos];
6285 if (channel == 0) {
6286 priv->speed_scan_pos = 0;
6287 channel = priv->speed_scan[0];
6288 }
6289 if ((priv->status & STATUS_ASSOCIATED) &&
6290 channel == priv->channel) {
6291 priv->speed_scan_pos++;
6292 continue;
6293 }
6294
6295 /* If this channel has already been
6296 * added in scan, break from loop
6297 * and this will be the first channel
6298 * in the next scan.
6299 */
6300 if (channels[channel - 1] != 0)
6301 break;
6302
6303 channels[channel - 1] = 1;
6304 priv->speed_scan_pos++;
6305 channel_index++;
6306 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006307 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006308 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006309 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006310 geo->bg[index].
6311 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006312 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006313 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6314 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006315 }
6316 } else {
6317 for (i = 0; i < geo->bg_channels; i++) {
6318 if ((priv->status & STATUS_ASSOCIATED) &&
6319 geo->bg[i].channel == priv->channel)
6320 continue;
6321 channel_index++;
6322 scan->channels_list[channel_index] =
6323 geo->bg[i].channel;
6324 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006325 geo->bg[i].
6326 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006327 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006328 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6329 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006330 }
6331 }
6332
6333 if (start != channel_index) {
6334 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6335 (channel_index - start);
6336 }
6337 }
6338}
6339
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006340static int ipw_passive_dwell_time(struct ipw_priv *priv)
6341{
6342 /* staying on passive channels longer than the DTIM interval during a
6343 * scan, while associated, causes the firmware to cancel the scan
6344 * without notification. Hence, don't stay on passive channels longer
6345 * than the beacon interval.
6346 */
6347 if (priv->status & STATUS_ASSOCIATED
6348 && priv->assoc_network->beacon_interval > 10)
6349 return priv->assoc_network->beacon_interval - 10;
6350 else
6351 return 120;
6352}
6353
Dan Williamsea177302008-06-02 17:51:23 -04006354static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006355{
6356 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006357 int err = 0, scan_type;
6358
6359 if (!(priv->status & STATUS_INIT) ||
6360 (priv->status & STATUS_EXIT_PENDING))
6361 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006362
Zhu Yi46441512006-01-24 16:37:59 +08006363 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006364
Dan Williamsea177302008-06-02 17:51:23 -04006365 if (direct && (priv->direct_scan_ssid_len == 0)) {
6366 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6367 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6368 goto done;
6369 }
6370
James Ketrenosea2b26e2005-08-24 21:25:16 -05006371 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006372 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6373 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6374 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006375 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006376 }
6377
James Ketrenosafbf30a2005-08-25 00:05:33 -05006378 if (!(priv->status & STATUS_SCAN_FORCED) &&
6379 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006380 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006381 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6382 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006383 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006384 }
6385
6386 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006387 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6388 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 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006394 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395
Zhu Yi094c4d22006-08-21 11:39:03 +08006396 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006397 IPW_DEBUG_WX("use passive scanning\n");
6398 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006399 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006400 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006401 ipw_add_scan_channels(priv, &scan, scan_type);
6402 goto send_request;
6403 }
6404
6405 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006406 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006407 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006408 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006409 else
6410 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006411 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006412
James Ketrenosa613bff2005-08-24 21:43:11 -05006413 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006414 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006415
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006416 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6417 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006418 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006419
James Ketrenosb095c382005-08-24 22:04:42 -05006420#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006421 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006422 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006423 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006424
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006425 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6426 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006427 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006428 channel = priv->channel;
6429 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006430
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006431 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006432 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006433 channel = priv->channel;
6434 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006435
James Ketrenosb095c382005-08-24 22:04:42 -05006436 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006437 band = (u8) (IPW_B_MODE << 6) | 1;
6438 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006439 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006440 }
6441
James Ketrenosb095c382005-08-24 22:04:42 -05006442 scan.channels_list[0] = band;
6443 scan.channels_list[1] = channel;
6444 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006445
James Ketrenosb095c382005-08-24 22:04:42 -05006446 /* NOTE: The card will sit on this channel for this time
6447 * period. Scan aborts are timing sensitive and frequently
6448 * result in firmware restarts. As such, it is best to
6449 * set a small dwell_time here and just keep re-issuing
6450 * scans. Otherwise fast channel hopping will not actually
6451 * hop channels.
6452 *
6453 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006454 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006455 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006456 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006457#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006458 /* Honor direct scans first, otherwise if we are roaming make
6459 * this a direct scan for the current network. Finally,
6460 * ensure that every other scan is a fast channel hop scan */
6461 if (direct) {
6462 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6463 priv->direct_scan_ssid_len);
6464 if (err) {
6465 IPW_DEBUG_HC("Attempt to send SSID command "
6466 "failed\n");
6467 goto done;
6468 }
6469
6470 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6471 } else if ((priv->status & STATUS_ROAMING)
6472 || (!(priv->status & STATUS_ASSOCIATED)
6473 && (priv->config & CFG_STATIC_ESSID)
6474 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006475 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6476 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006477 IPW_DEBUG_HC("Attempt to send SSID command "
6478 "failed.\n");
6479 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006480 }
6481
6482 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006483 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006484 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006485
James Ketrenosafbf30a2005-08-25 00:05:33 -05006486 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006487#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006488 }
6489#endif
6490
Zhu Yi094c4d22006-08-21 11:39:03 +08006491send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006492 err = ipw_send_scan_request_ext(priv, &scan);
6493 if (err) {
6494 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006495 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006496 }
6497
6498 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006499 if (direct) {
6500 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6501 priv->direct_scan_ssid_len = 0;
6502 } else
6503 priv->status &= ~STATUS_SCAN_PENDING;
6504
Tejun Heobcb6d912011-01-26 12:12:50 +01006505 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006506done:
Zhu Yi46441512006-01-24 16:37:59 +08006507 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006508 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006509}
6510
David Howellsc4028952006-11-22 14:57:56 +00006511static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006512{
David Howellsc4028952006-11-22 14:57:56 +00006513 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006514 container_of(work, struct ipw_priv, request_passive_scan.work);
6515 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006516}
6517
6518static void ipw_request_scan(struct work_struct *work)
6519{
6520 struct ipw_priv *priv =
6521 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006522 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6523}
6524
6525static void ipw_request_direct_scan(struct work_struct *work)
6526{
6527 struct ipw_priv *priv =
6528 container_of(work, struct ipw_priv, request_direct_scan.work);
6529 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006530}
6531
6532static void ipw_bg_abort_scan(struct work_struct *work)
6533{
6534 struct ipw_priv *priv =
6535 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006536 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006537 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006538 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006539}
6540
James Ketrenosea2b26e2005-08-24 21:25:16 -05006541static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6542{
James Ketrenosb095c382005-08-24 22:04:42 -05006543 /* This is called when wpa_supplicant loads and closes the driver
6544 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006545 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006546 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006547}
6548
James Ketrenosea2b26e2005-08-24 21:25:16 -05006549static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6550{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006551 struct libipw_device *ieee = priv->ieee;
6552 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006553 .flags = SEC_AUTH_MODE,
6554 };
6555 int ret = 0;
6556
James Ketrenosafbf30a2005-08-25 00:05:33 -05006557 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006558 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6559 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006560 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006561 sec.auth_mode = WLAN_AUTH_OPEN;
6562 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006563 } else if (value & IW_AUTH_ALG_LEAP) {
6564 sec.auth_mode = WLAN_AUTH_LEAP;
6565 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006566 } else
6567 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006568
6569 if (ieee->set_security)
6570 ieee->set_security(ieee->dev, &sec);
6571 else
6572 ret = -EOPNOTSUPP;
6573
6574 return ret;
6575}
6576
Adrian Bunka73e22b2006-01-21 01:39:42 +01006577static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6578 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006579{
6580 /* make sure WPA is enabled */
6581 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006582}
6583
6584static int ipw_set_rsn_capa(struct ipw_priv *priv,
6585 char *capabilities, int length)
6586{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006587 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6588
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006589 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006590 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006591}
6592
James Ketrenosafbf30a2005-08-25 00:05:33 -05006593/*
6594 * WE-18 support
6595 */
6596
6597/* SIOCSIWGENIE */
6598static int ipw_wx_set_genie(struct net_device *dev,
6599 struct iw_request_info *info,
6600 union iwreq_data *wrqu, char *extra)
6601{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006602 struct ipw_priv *priv = libipw_priv(dev);
6603 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006604 u8 *buf;
6605 int err = 0;
6606
6607 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6608 (wrqu->data.length && extra == NULL))
6609 return -EINVAL;
6610
James Ketrenosafbf30a2005-08-25 00:05:33 -05006611 if (wrqu->data.length) {
Julia Lawalld3e50332010-05-15 23:21:01 +02006612 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006613 if (buf == NULL) {
6614 err = -ENOMEM;
6615 goto out;
6616 }
6617
James Ketrenosafbf30a2005-08-25 00:05:33 -05006618 kfree(ieee->wpa_ie);
6619 ieee->wpa_ie = buf;
6620 ieee->wpa_ie_len = wrqu->data.length;
6621 } else {
6622 kfree(ieee->wpa_ie);
6623 ieee->wpa_ie = NULL;
6624 ieee->wpa_ie_len = 0;
6625 }
6626
6627 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6628 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006629 return err;
6630}
6631
6632/* SIOCGIWGENIE */
6633static int ipw_wx_get_genie(struct net_device *dev,
6634 struct iw_request_info *info,
6635 union iwreq_data *wrqu, char *extra)
6636{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006637 struct ipw_priv *priv = libipw_priv(dev);
6638 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006639 int err = 0;
6640
James Ketrenosafbf30a2005-08-25 00:05:33 -05006641 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6642 wrqu->data.length = 0;
6643 goto out;
6644 }
6645
6646 if (wrqu->data.length < ieee->wpa_ie_len) {
6647 err = -E2BIG;
6648 goto out;
6649 }
6650
6651 wrqu->data.length = ieee->wpa_ie_len;
6652 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6653
6654 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006655 return err;
6656}
6657
Zhu Yi1fbfea52005-08-05 17:22:56 +08006658static int wext_cipher2level(int cipher)
6659{
6660 switch (cipher) {
6661 case IW_AUTH_CIPHER_NONE:
6662 return SEC_LEVEL_0;
6663 case IW_AUTH_CIPHER_WEP40:
6664 case IW_AUTH_CIPHER_WEP104:
6665 return SEC_LEVEL_1;
6666 case IW_AUTH_CIPHER_TKIP:
6667 return SEC_LEVEL_2;
6668 case IW_AUTH_CIPHER_CCMP:
6669 return SEC_LEVEL_3;
6670 default:
6671 return -1;
6672 }
6673}
6674
James Ketrenosafbf30a2005-08-25 00:05:33 -05006675/* SIOCSIWAUTH */
6676static int ipw_wx_set_auth(struct net_device *dev,
6677 struct iw_request_info *info,
6678 union iwreq_data *wrqu, char *extra)
6679{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006680 struct ipw_priv *priv = libipw_priv(dev);
6681 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006682 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006683 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006684 unsigned long flags;
6685 int ret = 0;
6686
6687 switch (param->flags & IW_AUTH_INDEX) {
6688 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006689 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006690 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006691 ipw_set_hw_decrypt_unicast(priv,
6692 wext_cipher2level(param->value));
6693 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006694 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006695 ipw_set_hw_decrypt_multicast(priv,
6696 wext_cipher2level(param->value));
6697 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006698 case IW_AUTH_KEY_MGMT:
6699 /*
6700 * ipw2200 does not use these parameters
6701 */
6702 break;
6703
6704 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006705 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006706 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006707 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006708
6709 flags = crypt->ops->get_flags(crypt->priv);
6710
6711 if (param->value)
6712 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6713 else
6714 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6715
6716 crypt->ops->set_flags(flags, crypt->priv);
6717
6718 break;
6719
6720 case IW_AUTH_DROP_UNENCRYPTED:{
6721 /* HACK:
6722 *
6723 * wpa_supplicant calls set_wpa_enabled when the driver
6724 * is loaded and unloaded, regardless of if WPA is being
6725 * used. No other calls are made which can be used to
6726 * determine if encryption will be used or not prior to
6727 * association being expected. If encryption is not being
6728 * used, drop_unencrypted is set to false, else true -- we
6729 * can use this to determine if the CAP_PRIVACY_ON bit should
6730 * be set.
6731 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006732 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006733 .flags = SEC_ENABLED,
6734 .enabled = param->value,
6735 };
6736 priv->ieee->drop_unencrypted = param->value;
6737 /* We only change SEC_LEVEL for open mode. Others
6738 * are set by ipw_wpa_set_encryption.
6739 */
6740 if (!param->value) {
6741 sec.flags |= SEC_LEVEL;
6742 sec.level = SEC_LEVEL_0;
6743 } else {
6744 sec.flags |= SEC_LEVEL;
6745 sec.level = SEC_LEVEL_1;
6746 }
6747 if (priv->ieee->set_security)
6748 priv->ieee->set_security(priv->ieee->dev, &sec);
6749 break;
6750 }
6751
6752 case IW_AUTH_80211_AUTH_ALG:
6753 ret = ipw_wpa_set_auth_algs(priv, param->value);
6754 break;
6755
6756 case IW_AUTH_WPA_ENABLED:
6757 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006758 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006759 break;
6760
6761 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6762 ieee->ieee802_1x = param->value;
6763 break;
6764
James Ketrenosafbf30a2005-08-25 00:05:33 -05006765 case IW_AUTH_PRIVACY_INVOKED:
6766 ieee->privacy_invoked = param->value;
6767 break;
6768
6769 default:
6770 return -EOPNOTSUPP;
6771 }
6772 return ret;
6773}
6774
6775/* SIOCGIWAUTH */
6776static int ipw_wx_get_auth(struct net_device *dev,
6777 struct iw_request_info *info,
6778 union iwreq_data *wrqu, char *extra)
6779{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006780 struct ipw_priv *priv = libipw_priv(dev);
6781 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006782 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006783 struct iw_param *param = &wrqu->param;
6784 int ret = 0;
6785
6786 switch (param->flags & IW_AUTH_INDEX) {
6787 case IW_AUTH_WPA_VERSION:
6788 case IW_AUTH_CIPHER_PAIRWISE:
6789 case IW_AUTH_CIPHER_GROUP:
6790 case IW_AUTH_KEY_MGMT:
6791 /*
6792 * wpa_supplicant will control these internally
6793 */
6794 ret = -EOPNOTSUPP;
6795 break;
6796
6797 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006798 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006799 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006800 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006801
6802 param->value = (crypt->ops->get_flags(crypt->priv) &
6803 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6804
6805 break;
6806
6807 case IW_AUTH_DROP_UNENCRYPTED:
6808 param->value = ieee->drop_unencrypted;
6809 break;
6810
6811 case IW_AUTH_80211_AUTH_ALG:
6812 param->value = ieee->sec.auth_mode;
6813 break;
6814
6815 case IW_AUTH_WPA_ENABLED:
6816 param->value = ieee->wpa_enabled;
6817 break;
6818
6819 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6820 param->value = ieee->ieee802_1x;
6821 break;
6822
6823 case IW_AUTH_ROAMING_CONTROL:
6824 case IW_AUTH_PRIVACY_INVOKED:
6825 param->value = ieee->privacy_invoked;
6826 break;
6827
6828 default:
6829 return -EOPNOTSUPP;
6830 }
6831 return 0;
6832}
6833
6834/* SIOCSIWENCODEEXT */
6835static int ipw_wx_set_encodeext(struct net_device *dev,
6836 struct iw_request_info *info,
6837 union iwreq_data *wrqu, char *extra)
6838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006839 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006840 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6841
6842 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006843 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006844 /* IPW HW can't build TKIP MIC,
6845 host decryption still needed */
6846 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6847 priv->ieee->host_mc_decrypt = 1;
6848 else {
6849 priv->ieee->host_encrypt = 0;
6850 priv->ieee->host_encrypt_msdu = 1;
6851 priv->ieee->host_decrypt = 1;
6852 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006853 } else {
6854 priv->ieee->host_encrypt = 0;
6855 priv->ieee->host_encrypt_msdu = 0;
6856 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006857 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006858 }
6859 }
6860
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006861 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006862}
6863
6864/* SIOCGIWENCODEEXT */
6865static int ipw_wx_get_encodeext(struct net_device *dev,
6866 struct iw_request_info *info,
6867 union iwreq_data *wrqu, char *extra)
6868{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006869 struct ipw_priv *priv = libipw_priv(dev);
6870 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006871}
6872
6873/* SIOCSIWMLME */
6874static int ipw_wx_set_mlme(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);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006879 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006880 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006881
6882 reason = cpu_to_le16(mlme->reason_code);
6883
6884 switch (mlme->cmd) {
6885 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006886 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006887 break;
6888
6889 case IW_MLME_DISASSOC:
6890 ipw_disassociate(priv);
6891 break;
6892
6893 default:
6894 return -EOPNOTSUPP;
6895 }
6896 return 0;
6897}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006898
Zhu Yie43e3c12006-04-13 17:20:45 +08006899#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006900
6901/* QoS */
6902/*
6903* get the modulation type of the current network or
6904* the card current mode
6905*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006906static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006907{
6908 u8 mode = 0;
6909
6910 if (priv->status & STATUS_ASSOCIATED) {
6911 unsigned long flags;
6912
6913 spin_lock_irqsave(&priv->ieee->lock, flags);
6914 mode = priv->assoc_network->mode;
6915 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6916 } else {
6917 mode = priv->ieee->mode;
6918 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006919 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006920 return mode;
6921}
6922
6923/*
6924* Handle management frame beacon and probe response
6925*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006926static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6927 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006928 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006929{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006930 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006931
James Ketrenosafbf30a2005-08-25 00:05:33 -05006932 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006933 network->qos_data.active = network->qos_data.supported;
6934
6935 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006936 if (active_network &&
6937 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006938 network->qos_data.active = network->qos_data.supported;
6939
6940 if ((network->qos_data.active == 1) && (active_network == 1) &&
6941 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6942 (network->qos_data.old_param_count !=
6943 network->qos_data.param_count)) {
6944 network->qos_data.old_param_count =
6945 network->qos_data.param_count;
6946 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006947 IPW_DEBUG_QOS("QoS parameters change call "
6948 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006949 }
6950 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006951 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6952 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006953 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006954 else
6955 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006956 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006957
James Ketrenosb095c382005-08-24 22:04:42 -05006958 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006959 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006960 schedule_work(&priv->qos_activate);
6961 }
6962
6963 network->qos_data.active = 0;
6964 network->qos_data.supported = 0;
6965 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006966 if ((priv->status & STATUS_ASSOCIATED) &&
6967 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6968 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006969 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006970 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006971 priv->assoc_network->ssid_len) &&
6972 !memcmp(network->ssid,
6973 priv->assoc_network->ssid,
6974 network->ssid_len)) {
Tejun Heobcb6d912011-01-26 12:12:50 +01006975 schedule_work(&priv->merge_networks);
James Ketrenosb095c382005-08-24 22:04:42 -05006976 }
James Ketrenosb095c382005-08-24 22:04:42 -05006977 }
6978
6979 return 0;
6980}
6981
6982/*
6983* This function set up the firmware to support QoS. It sends
6984* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6985*/
6986static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006987 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006988{
6989 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006990 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6991 struct libipw_qos_parameters *active_one = NULL;
6992 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006993 u32 burst_duration;
6994 int i;
6995 u8 type;
6996
6997 type = ipw_qos_current_mode(priv);
6998
6999 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7000 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7001 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7002 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7003
7004 if (qos_network_data == NULL) {
7005 if (type == IEEE_B) {
7006 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7007 active_one = &def_parameters_CCK;
7008 } else
7009 active_one = &def_parameters_OFDM;
7010
James Ketrenosafbf30a2005-08-25 00:05:33 -05007011 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007012 burst_duration = ipw_qos_get_burst_duration(priv);
7013 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007014 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007015 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007016 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007017 if (type == IEEE_B) {
7018 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7019 type);
7020 if (priv->qos_data.qos_enable == 0)
7021 active_one = &def_parameters_CCK;
7022 else
7023 active_one = priv->qos_data.def_qos_parm_CCK;
7024 } else {
7025 if (priv->qos_data.qos_enable == 0)
7026 active_one = &def_parameters_OFDM;
7027 else
7028 active_one = priv->qos_data.def_qos_parm_OFDM;
7029 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007030 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007031 } else {
7032 unsigned long flags;
7033 int active;
7034
7035 spin_lock_irqsave(&priv->ieee->lock, flags);
7036 active_one = &(qos_network_data->parameters);
7037 qos_network_data->old_param_count =
7038 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007039 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007040 active = qos_network_data->supported;
7041 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7042
7043 if (active == 0) {
7044 burst_duration = ipw_qos_get_burst_duration(priv);
7045 for (i = 0; i < QOS_QUEUE_NUM; i++)
7046 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007047 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007048 }
7049 }
7050
7051 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007052 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007053 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007054 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007055 if (err)
7056 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7057
7058 return err;
7059}
7060
7061/*
7062* send IPW_CMD_WME_INFO to the firmware
7063*/
7064static int ipw_qos_set_info_element(struct ipw_priv *priv)
7065{
7066 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007067 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007068
7069 if (priv == NULL)
7070 return -1;
7071
7072 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007073 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007074
7075 qos_info.version = QOS_VERSION_1;
7076 qos_info.ac_info = 0;
7077
7078 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7079 qos_info.qui_type = QOS_OUI_TYPE;
7080 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7081
7082 ret = ipw_send_qos_info_command(priv, &qos_info);
7083 if (ret != 0) {
7084 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7085 }
7086 return ret;
7087}
7088
7089/*
7090* Set the QoS parameter with the association request structure
7091*/
7092static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007093 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007094{
7095 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007096 struct libipw_qos_data *qos_data = NULL;
7097 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007098 .supported = 1,
7099 .active = 1,
7100 };
7101
7102 switch (priv->ieee->iw_mode) {
7103 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007104 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007105
7106 qos_data = &ibss_data;
7107 break;
7108
7109 case IW_MODE_INFRA:
7110 qos_data = &network->qos_data;
7111 break;
7112
7113 default:
7114 BUG();
7115 break;
7116 }
7117
7118 err = ipw_qos_activate(priv, qos_data);
7119 if (err) {
7120 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7121 return err;
7122 }
7123
7124 if (priv->qos_data.qos_enable && qos_data->supported) {
7125 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7126 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7127 return ipw_qos_set_info_element(priv);
7128 }
7129
7130 return 0;
7131}
7132
7133/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007134* handling the beaconing responses. if we get different QoS setting
7135* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007136* setting
7137*/
7138static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007139 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007140{
7141 int ret = 0;
7142 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007143 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007144 int set_qos_param = 0;
7145
James Ketrenosafbf30a2005-08-25 00:05:33 -05007146 if ((priv == NULL) || (network == NULL) ||
7147 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007148 return ret;
7149
7150 if (!(priv->status & STATUS_ASSOCIATED))
7151 return ret;
7152
James Ketrenosafbf30a2005-08-25 00:05:33 -05007153 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007154 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007155
7156 spin_lock_irqsave(&priv->ieee->lock, flags);
7157 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007158 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007159 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007160 priv->assoc_network->qos_data.active = 1;
7161 if ((network->qos_data.old_param_count !=
7162 network->qos_data.param_count)) {
7163 set_qos_param = 1;
7164 network->qos_data.old_param_count =
7165 network->qos_data.param_count;
7166 }
7167
7168 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007169 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7170 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007171 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007172 else
7173 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007174 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007175 priv->assoc_network->qos_data.active = 0;
7176 priv->assoc_network->qos_data.supported = 0;
7177 set_qos_param = 1;
7178 }
7179
7180 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7181
7182 if (set_qos_param == 1)
7183 schedule_work(&priv->qos_activate);
7184
7185 return ret;
7186}
7187
7188static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7189{
7190 u32 ret = 0;
7191
7192 if ((priv == NULL))
7193 return 0;
7194
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007195 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007196 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007197 else
James Ketrenosb095c382005-08-24 22:04:42 -05007198 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007199
James Ketrenosb095c382005-08-24 22:04:42 -05007200 return ret;
7201}
7202
7203/*
7204* Initialize the setting of QoS global
7205*/
7206static void ipw_qos_init(struct ipw_priv *priv, int enable,
7207 int burst_enable, u32 burst_duration_CCK,
7208 u32 burst_duration_OFDM)
7209{
7210 priv->qos_data.qos_enable = enable;
7211
7212 if (priv->qos_data.qos_enable) {
7213 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7214 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7215 IPW_DEBUG_QOS("QoS is enabled\n");
7216 } else {
7217 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7218 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7219 IPW_DEBUG_QOS("QoS is not enabled\n");
7220 }
7221
7222 priv->qos_data.burst_enable = burst_enable;
7223
7224 if (burst_enable) {
7225 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7226 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7227 } else {
7228 priv->qos_data.burst_duration_CCK = 0;
7229 priv->qos_data.burst_duration_OFDM = 0;
7230 }
7231}
7232
7233/*
7234* map the packet priority to the right TX Queue
7235*/
7236static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7237{
7238 if (priority > 7 || !priv->qos_data.qos_enable)
7239 priority = 0;
7240
7241 return from_priority_to_tx_queue[priority] - 1;
7242}
7243
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007244static int ipw_is_qos_active(struct net_device *dev,
7245 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007246{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007247 struct ipw_priv *priv = libipw_priv(dev);
7248 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007249 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007250 u8 *daddr = skb->data + ETH_ALEN;
7251 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007252
7253 if (!(priv->status & STATUS_ASSOCIATED))
7254 return 0;
7255
7256 qos_data = &priv->assoc_network->qos_data;
7257
James Ketrenosb095c382005-08-24 22:04:42 -05007258 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7259 if (unicast == 0)
7260 qos_data->active = 0;
7261 else
7262 qos_data->active = qos_data->supported;
7263 }
James Ketrenosb095c382005-08-24 22:04:42 -05007264 active = qos_data->active;
7265 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007266 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7267 "unicast %d\n",
7268 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007269 if (active && priv->qos_data.qos_enable)
7270 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007271
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007272 return 0;
7273
7274}
7275/*
7276* add QoS parameter to the TX command
7277*/
7278static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7279 u16 priority,
7280 struct tfd_data *tfd)
7281{
7282 int tx_queue_id = 0;
7283
7284
7285 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7286 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7287
7288 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7289 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007290 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007291 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007292 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007293}
7294
7295/*
7296* background support to run QoS activate functionality
7297*/
David Howellsc4028952006-11-22 14:57:56 +00007298static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007299{
David Howellsc4028952006-11-22 14:57:56 +00007300 struct ipw_priv *priv =
7301 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007302
Zhu Yi46441512006-01-24 16:37:59 +08007303 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007304
7305 if (priv->status & STATUS_ASSOCIATED)
7306 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7307
Zhu Yi46441512006-01-24 16:37:59 +08007308 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007309}
7310
James Ketrenos3b9990c2005-08-19 13:18:55 -05007311static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007312 struct libipw_probe_response *resp,
7313 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007314{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007315 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007316 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7317 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007318
James Ketrenos3b9990c2005-08-19 13:18:55 -05007319 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007320
James Ketrenos3b9990c2005-08-19 13:18:55 -05007321 return 0;
7322}
James Ketrenosb095c382005-08-24 22:04:42 -05007323
James Ketrenos3b9990c2005-08-19 13:18:55 -05007324static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007325 struct libipw_beacon *resp,
7326 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007327{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007328 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007329 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7330 (network == priv->assoc_network));
7331
7332 ipw_qos_handle_probe_response(priv, active_network, network);
7333
7334 return 0;
7335}
7336
7337static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007338 struct libipw_assoc_response *resp,
7339 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007340{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007341 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007342 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007343 return 0;
7344}
7345
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007346static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007347 *qos_param)
7348{
Zhu Yi4e226992006-01-24 16:37:36 +08007349 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7350 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007351}
7352
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007353static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007354 *qos_param)
7355{
Zhu Yi4e226992006-01-24 16:37:36 +08007356 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7357 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007358}
7359
Zhu Yie43e3c12006-04-13 17:20:45 +08007360#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007361
James Ketrenos43f66a62005-03-25 12:31:53 -06007362static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007363 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007364 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007365{
7366 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007367 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007368
7369 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007370 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007371
7372 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007373 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007374 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007375 memcpy(priv->essid, network->ssid, priv->essid_len);
7376 }
7377
7378 network->last_associate = jiffies;
7379
7380 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7381 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007382 priv->assoc_request.auth_key = 0;
7383
James Ketrenos43f66a62005-03-25 12:31:53 -06007384 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007385 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007386 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007387 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7388
Zhu Yi1ba61e02006-02-15 13:00:55 +08007389 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007390 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007391
7392 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7393 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7394 priv->assoc_request.auth_type = AUTH_LEAP;
7395 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007396 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007397
James Ketrenosa613bff2005-08-24 21:43:11 -05007398 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007399 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007400 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7401 priv->ieee->wpa_ie_len);
7402 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007403
Jeff Garzikbf794512005-07-31 13:07:26 -04007404 /*
7405 * It is valid for our ieee device to support multiple modes, but
7406 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007407 * just one mode.
7408 */
7409 if (network->mode & priv->ieee->mode & IEEE_A)
7410 priv->assoc_request.ieee_mode = IPW_A_MODE;
7411 else if (network->mode & priv->ieee->mode & IEEE_G)
7412 priv->assoc_request.ieee_mode = IPW_G_MODE;
7413 else if (network->mode & priv->ieee->mode & IEEE_B)
7414 priv->assoc_request.ieee_mode = IPW_B_MODE;
7415
Al Viro5b5e8072007-12-27 01:54:06 -05007416 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007417 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7418 && !(priv->config & CFG_PREAMBLE_LONG)) {
7419 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7420 } else {
7421 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7422
7423 /* Clear the short preamble if we won't be supporting it */
7424 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007425 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007426 }
7427
James Ketrenosafbf30a2005-08-25 00:05:33 -05007428 /* Clear capability bits that aren't used in Ad Hoc */
7429 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7430 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007431 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007432
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02007433 IPW_DEBUG_ASSOC("%ssociation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007434 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007435 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007436 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007437 network->channel,
7438 ipw_modes[priv->assoc_request.ieee_mode],
7439 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007440 (priv->assoc_request.preamble_length ==
7441 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7442 network->capability &
7443 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007444 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007445 priv->capability & CAP_PRIVACY_ON ?
7446 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007447 "(open)") : "",
7448 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007449 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007450 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007451 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007452
Al Viro5b5e8072007-12-27 01:54:06 -05007453 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007454 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007455 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007456 priv->assoc_request.assoc_type = HC_IBSS_START;
7457 priv->assoc_request.assoc_tsf_msw = 0;
7458 priv->assoc_request.assoc_tsf_lsw = 0;
7459 } else {
7460 if (unlikely(roaming))
7461 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7462 else
7463 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007464 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7465 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007466 }
7467
James Ketrenosafbf30a2005-08-25 00:05:33 -05007468 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007469
7470 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7471 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007472 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007473 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007474 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007475 priv->assoc_request.atim_window = 0;
7476 }
7477
Al Viro5b5e8072007-12-27 01:54:06 -05007478 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007479
James Ketrenos43f66a62005-03-25 12:31:53 -06007480 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7481 if (err) {
7482 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7483 return err;
7484 }
7485
7486 rates->ieee_mode = priv->assoc_request.ieee_mode;
7487 rates->purpose = IPW_RATE_CONNECT;
7488 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007489
James Ketrenos43f66a62005-03-25 12:31:53 -06007490 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7491 priv->sys_config.dot11g_auto_detection = 1;
7492 else
7493 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007494
7495 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7496 priv->sys_config.answer_broadcast_ssid_probe = 1;
7497 else
7498 priv->sys_config.answer_broadcast_ssid_probe = 0;
7499
Zhu Yid685b8c2006-04-13 17:20:27 +08007500 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007501 if (err) {
7502 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7503 return err;
7504 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007505
James Ketrenos43f66a62005-03-25 12:31:53 -06007506 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007507 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007508 if (err) {
7509 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7510 return err;
7511 }
7512
7513 /*
7514 * If preemption is enabled, it is possible for the association
7515 * to complete before we return from ipw_send_associate. Therefore
7516 * we have to be sure and update our priviate data first.
7517 */
7518 priv->channel = network->channel;
7519 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007520 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007521 priv->status &= ~STATUS_SECURITY_UPDATED;
7522
7523 priv->assoc_network = network;
7524
Zhu Yie43e3c12006-04-13 17:20:45 +08007525#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007526 ipw_qos_association(priv, network);
7527#endif
7528
James Ketrenos43f66a62005-03-25 12:31:53 -06007529 err = ipw_send_associate(priv, &priv->assoc_request);
7530 if (err) {
7531 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7532 return err;
7533 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007534
Frans Pop9fd1ea42010-03-24 19:46:31 +01007535 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007536 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007537 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007538
7539 return 0;
7540}
7541
7542static void ipw_roam(void *data)
7543{
7544 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007545 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 struct ipw_network_match match = {
7547 .network = priv->assoc_network
7548 };
7549
7550 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007551 *
7552 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007553 * setting the status ROAM bit and requesting a scan.
7554 * 2. When the scan completes, it schedules the ROAM work
7555 * 3. The ROAM work looks at all of the known networks for one that
7556 * is a better network than the currently associated. If none
7557 * found, the ROAM process is over (ROAM bit cleared)
7558 * 4. If a better network is found, a disassociation request is
7559 * sent.
7560 * 5. When the disassociation completes, the roam work is again
7561 * scheduled. The second time through, the driver is no longer
7562 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007563 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007564 * 6. At this point ,the roaming process is complete and the ROAM
7565 * status bit is cleared.
7566 */
7567
7568 /* If we are no longer associated, and the roaming bit is no longer
7569 * set, then we are not actively roaming, so just return */
7570 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7571 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007572
James Ketrenos43f66a62005-03-25 12:31:53 -06007573 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007574 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007575 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007576 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007577 u8 rssi = priv->assoc_network->stats.rssi;
7578 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007579 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007580 list_for_each_entry(network, &priv->ieee->network_list, list) {
7581 if (network != priv->assoc_network)
7582 ipw_best_network(priv, &match, network, 1);
7583 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007584 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007585 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007586
James Ketrenos43f66a62005-03-25 12:31:53 -06007587 if (match.network == priv->assoc_network) {
7588 IPW_DEBUG_ASSOC("No better APs in this network to "
7589 "roam to.\n");
7590 priv->status &= ~STATUS_ROAMING;
7591 ipw_debug_config(priv);
7592 return;
7593 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007594
James Ketrenos43f66a62005-03-25 12:31:53 -06007595 ipw_send_disassociate(priv, 1);
7596 priv->assoc_network = match.network;
7597
7598 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007599 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007600
7601 /* Second pass through ROAM process -- request association */
7602 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7603 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7604 priv->status &= ~STATUS_ROAMING;
7605}
7606
David Howellsc4028952006-11-22 14:57:56 +00007607static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007608{
David Howellsc4028952006-11-22 14:57:56 +00007609 struct ipw_priv *priv =
7610 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007611 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007612 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007613 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007614}
7615
7616static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007617{
7618 struct ipw_priv *priv = data;
7619
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007620 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007621 struct ipw_network_match match = {
7622 .network = NULL
7623 };
7624 struct ipw_supported_rates *rates;
7625 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007626 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007627 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007628
James Ketrenosb095c382005-08-24 22:04:42 -05007629 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7630 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7631 return 0;
7632 }
7633
James Ketrenosc848d0a2005-08-24 21:56:24 -05007634 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007635 IPW_DEBUG_ASSOC("Not attempting association (already in "
7636 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007637 return 0;
7638 }
7639
Hong Liue6324722005-09-14 21:04:15 -05007640 if (priv->status & STATUS_DISASSOCIATING) {
7641 IPW_DEBUG_ASSOC("Not attempting association (in "
7642 "disassociating)\n ");
Tejun Heobcb6d912011-01-26 12:12:50 +01007643 schedule_work(&priv->associate);
Hong Liue6324722005-09-14 21:04:15 -05007644 return 0;
7645 }
7646
James Ketrenosc848d0a2005-08-24 21:56:24 -05007647 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007648 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7649 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007650 return 0;
7651 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007652
7653 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007654 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007655 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007656 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007657 }
7658
James Ketrenosa613bff2005-08-24 21:43:11 -05007659 /* Protect our use of the network_list */
7660 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007661 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007662 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007663
7664 network = match.network;
7665 rates = &match.rates;
7666
7667 if (network == NULL &&
7668 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7669 priv->config & CFG_ADHOC_CREATE &&
7670 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007671 priv->config & CFG_STATIC_CHANNEL) {
7672 /* Use oldest network if the free list is empty */
7673 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007674 struct libipw_network *oldest = NULL;
7675 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007676
7677 list_for_each_entry(target, &priv->ieee->network_list, list) {
7678 if ((oldest == NULL) ||
7679 (target->last_scanned < oldest->last_scanned))
7680 oldest = target;
7681 }
7682
7683 /* If there are no more slots, expire the oldest */
7684 list_del(&oldest->list);
7685 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007686 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007687 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007688 print_ssid(ssid, target->ssid,
7689 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007690 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007691 list_add_tail(&target->list,
7692 &priv->ieee->network_free_list);
7693 }
7694
James Ketrenos43f66a62005-03-25 12:31:53 -06007695 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007696 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007697 ipw_adhoc_create(priv, network);
7698 rates = &priv->rates;
7699 list_del(element);
7700 list_add_tail(&network->list, &priv->ieee->network_list);
7701 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007702 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007703
James Ketrenos43f66a62005-03-25 12:31:53 -06007704 /* If we reached the end of the list, then we don't have any valid
7705 * matching APs */
7706 if (!network) {
7707 ipw_debug_config(priv);
7708
James Ketrenosb095c382005-08-24 22:04:42 -05007709 if (!(priv->status & STATUS_SCANNING)) {
7710 if (!(priv->config & CFG_SPEED_SCAN))
Tejun Heobcb6d912011-01-26 12:12:50 +01007711 schedule_delayed_work(&priv->request_scan,
7712 SCAN_INTERVAL);
James Ketrenosb095c382005-08-24 22:04:42 -05007713 else
Tejun Heobcb6d912011-01-26 12:12:50 +01007714 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007715 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007716
James Ketrenosc848d0a2005-08-24 21:56:24 -05007717 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007718 }
7719
7720 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007721
7722 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007723}
Jeff Garzikbf794512005-07-31 13:07:26 -04007724
David Howellsc4028952006-11-22 14:57:56 +00007725static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007726{
David Howellsc4028952006-11-22 14:57:56 +00007727 struct ipw_priv *priv =
7728 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007729 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007730 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007731 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007732}
7733
James Ketrenosb095c382005-08-24 22:04:42 -05007734static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7735 struct sk_buff *skb)
7736{
7737 struct ieee80211_hdr *hdr;
7738 u16 fc;
7739
7740 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007741 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007742 if (!(fc & IEEE80211_FCTL_PROTECTED))
7743 return;
7744
7745 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007746 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007747 switch (priv->ieee->sec.level) {
7748 case SEC_LEVEL_3:
7749 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007750 memmove(skb->data + LIBIPW_3ADDR_LEN,
7751 skb->data + LIBIPW_3ADDR_LEN + 8,
7752 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007753 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007754 break;
7755 case SEC_LEVEL_2:
7756 break;
7757 case SEC_LEVEL_1:
7758 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007759 memmove(skb->data + LIBIPW_3ADDR_LEN,
7760 skb->data + LIBIPW_3ADDR_LEN + 4,
7761 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007762 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007763 break;
7764 case SEC_LEVEL_0:
7765 break;
7766 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007767 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007768 priv->ieee->sec.level);
7769 break;
7770 }
7771}
7772
7773static void ipw_handle_data_packet(struct ipw_priv *priv,
7774 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007775 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007776{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007777 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007778 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007779 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7780
7781 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007782 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007783
Jeff Garzikbf794512005-07-31 13:07:26 -04007784 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007785 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007786 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007787 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007788 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007789 priv->wstats.discard.misc++;
7790 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7791 return;
7792 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007793 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007794 priv->wstats.discard.misc++;
7795 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7796 return;
7797 }
7798
7799 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007800 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007801
7802 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007803 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007804
7805 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7806
James Ketrenosb095c382005-08-24 22:04:42 -05007807 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007808 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007809 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007810 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007811 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007812 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7813
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007814 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007815 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007816 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007817 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007818 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007819 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007820}
7821
Zhu Yi459d4082006-04-13 17:21:00 +08007822#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007823static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7824 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007825 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007826{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007827 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007828 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7829 struct ipw_rx_frame *frame = &pkt->u.frame;
7830
7831 /* initial pull of some data */
7832 u16 received_channel = frame->received_channel;
7833 u8 antennaAndPhy = frame->antennaAndPhy;
7834 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7835 u16 pktrate = frame->rate;
7836
7837 /* Magic struct that slots into the radiotap header -- no reason
7838 * to build this manually element by element, we can write it much
7839 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007840 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007841
7842 short len = le16_to_cpu(pkt->u.frame.length);
7843
7844 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007845 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007846
7847 /* We only process data packets if the
7848 * interface is open */
7849 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7850 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007851 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007852 priv->wstats.discard.misc++;
7853 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7854 return;
7855 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007856 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007857 priv->wstats.discard.misc++;
7858 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7859 return;
7860 }
7861
7862 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7863 * that now */
7864 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7865 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007866 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007867 priv->wstats.discard.misc++;
7868 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7869 return;
7870 }
7871
7872 /* copy the frame itself */
7873 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7874 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7875
Mike Kershaw24a47db2005-08-26 00:41:54 -05007876 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7877
7878 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7879 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007880 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007881
7882 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007883 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7884 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007885 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007886 (1 << IEEE80211_RADIOTAP_RATE) |
7887 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7888 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007889 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007890 (1 << IEEE80211_RADIOTAP_ANTENNA));
7891
7892 /* Zero the flags, we'll add to them as we go */
7893 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007894 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7895 frame->parent_tsf[2] << 16 |
7896 frame->parent_tsf[1] << 8 |
7897 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007898
7899 /* Convert signal to DBM */
7900 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007901 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007902
7903 /* Convert the channel data and set the flags */
7904 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7905 if (received_channel > 14) { /* 802.11a */
7906 ipw_rt->rt_chbitmask =
7907 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7908 } else if (antennaAndPhy & 32) { /* 802.11b */
7909 ipw_rt->rt_chbitmask =
7910 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7911 } else { /* 802.11g */
7912 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007913 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007914 }
7915
7916 /* set the rate in multiples of 500k/s */
7917 switch (pktrate) {
7918 case IPW_TX_RATE_1MB:
7919 ipw_rt->rt_rate = 2;
7920 break;
7921 case IPW_TX_RATE_2MB:
7922 ipw_rt->rt_rate = 4;
7923 break;
7924 case IPW_TX_RATE_5MB:
7925 ipw_rt->rt_rate = 10;
7926 break;
7927 case IPW_TX_RATE_6MB:
7928 ipw_rt->rt_rate = 12;
7929 break;
7930 case IPW_TX_RATE_9MB:
7931 ipw_rt->rt_rate = 18;
7932 break;
7933 case IPW_TX_RATE_11MB:
7934 ipw_rt->rt_rate = 22;
7935 break;
7936 case IPW_TX_RATE_12MB:
7937 ipw_rt->rt_rate = 24;
7938 break;
7939 case IPW_TX_RATE_18MB:
7940 ipw_rt->rt_rate = 36;
7941 break;
7942 case IPW_TX_RATE_24MB:
7943 ipw_rt->rt_rate = 48;
7944 break;
7945 case IPW_TX_RATE_36MB:
7946 ipw_rt->rt_rate = 72;
7947 break;
7948 case IPW_TX_RATE_48MB:
7949 ipw_rt->rt_rate = 96;
7950 break;
7951 case IPW_TX_RATE_54MB:
7952 ipw_rt->rt_rate = 108;
7953 break;
7954 default:
7955 ipw_rt->rt_rate = 0;
7956 break;
7957 }
7958
7959 /* antenna number */
7960 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7961
7962 /* set the preamble flag if we have it */
7963 if ((antennaAndPhy & 64))
7964 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7965
7966 /* Set the size of the skb to the size of the frame */
7967 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007968
7969 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7970
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007971 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007972 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007973 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007974 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007975 /* no LED during capture */
7976 }
7977}
7978#endif
7979
Zhu Yid685b8c2006-04-13 17:20:27 +08007980#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007981#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007982 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7983 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7984
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007985#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007986 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7987
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007988#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007989 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7990
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007991#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007992 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7993
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007994#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007995 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7996
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007997#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007998 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7999
8000static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8001 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008002 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008003{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008004 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008005 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8006 struct ipw_rx_frame *frame = &pkt->u.frame;
8007 struct ipw_rt_hdr *ipw_rt;
8008
8009 /* First cache any information we need before we overwrite
8010 * the information provided in the skb from the hardware */
8011 struct ieee80211_hdr *hdr;
8012 u16 channel = frame->received_channel;
8013 u8 phy_flags = frame->antennaAndPhy;
8014 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008015 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008016 u8 rate = frame->rate;
8017 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008018 struct sk_buff *skb;
8019 int hdr_only = 0;
8020 u16 filter = priv->prom_priv->filter;
8021
8022 /* If the filter is set to not include Rx frames then return */
8023 if (filter & IPW_PROM_NO_RX)
8024 return;
8025
Zhu Yid685b8c2006-04-13 17:20:27 +08008026 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008027 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008028
8029 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008030 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008031 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8032 return;
8033 }
8034
8035 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008036 if (unlikely(!netif_running(dev))) {
8037 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008038 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8039 return;
8040 }
8041
8042 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8043 * that now */
8044 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8045 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008046 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008047 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8048 return;
8049 }
8050
8051 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008052 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008053 if (filter & IPW_PROM_NO_MGMT)
8054 return;
8055 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8056 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008057 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008058 if (filter & IPW_PROM_NO_CTL)
8059 return;
8060 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8061 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008062 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008063 if (filter & IPW_PROM_NO_DATA)
8064 return;
8065 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8066 hdr_only = 1;
8067 }
8068
8069 /* Copy the SKB since this is for the promiscuous side */
8070 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8071 if (skb == NULL) {
8072 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8073 return;
8074 }
8075
8076 /* copy the frame data to write after where the radiotap header goes */
8077 ipw_rt = (void *)skb->data;
8078
8079 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008080 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008081
8082 memcpy(ipw_rt->payload, hdr, len);
8083
Zhu Yid685b8c2006-04-13 17:20:27 +08008084 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8085 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008086 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008087
8088 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008089 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008090
8091 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008092 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8093 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008094 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008095 (1 << IEEE80211_RADIOTAP_RATE) |
8096 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8097 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8098 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8099 (1 << IEEE80211_RADIOTAP_ANTENNA));
8100
8101 /* Zero the flags, we'll add to them as we go */
8102 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008103 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8104 frame->parent_tsf[2] << 16 |
8105 frame->parent_tsf[1] << 8 |
8106 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008107
8108 /* Convert to DBM */
8109 ipw_rt->rt_dbmsignal = signal;
8110 ipw_rt->rt_dbmnoise = noise;
8111
8112 /* Convert the channel data and set the flags */
8113 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8114 if (channel > 14) { /* 802.11a */
8115 ipw_rt->rt_chbitmask =
8116 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8117 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8118 ipw_rt->rt_chbitmask =
8119 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8120 } else { /* 802.11g */
8121 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008122 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008123 }
8124
8125 /* set the rate in multiples of 500k/s */
8126 switch (rate) {
8127 case IPW_TX_RATE_1MB:
8128 ipw_rt->rt_rate = 2;
8129 break;
8130 case IPW_TX_RATE_2MB:
8131 ipw_rt->rt_rate = 4;
8132 break;
8133 case IPW_TX_RATE_5MB:
8134 ipw_rt->rt_rate = 10;
8135 break;
8136 case IPW_TX_RATE_6MB:
8137 ipw_rt->rt_rate = 12;
8138 break;
8139 case IPW_TX_RATE_9MB:
8140 ipw_rt->rt_rate = 18;
8141 break;
8142 case IPW_TX_RATE_11MB:
8143 ipw_rt->rt_rate = 22;
8144 break;
8145 case IPW_TX_RATE_12MB:
8146 ipw_rt->rt_rate = 24;
8147 break;
8148 case IPW_TX_RATE_18MB:
8149 ipw_rt->rt_rate = 36;
8150 break;
8151 case IPW_TX_RATE_24MB:
8152 ipw_rt->rt_rate = 48;
8153 break;
8154 case IPW_TX_RATE_36MB:
8155 ipw_rt->rt_rate = 72;
8156 break;
8157 case IPW_TX_RATE_48MB:
8158 ipw_rt->rt_rate = 96;
8159 break;
8160 case IPW_TX_RATE_54MB:
8161 ipw_rt->rt_rate = 108;
8162 break;
8163 default:
8164 ipw_rt->rt_rate = 0;
8165 break;
8166 }
8167
8168 /* antenna number */
8169 ipw_rt->rt_antenna = (phy_flags & 3);
8170
8171 /* set the preamble flag if we have it */
8172 if (phy_flags & (1 << 6))
8173 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8174
8175 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8176
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008177 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008178 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008179 dev_kfree_skb_any(skb);
8180 }
8181}
8182#endif
8183
Arjan van de Ven858119e2006-01-14 13:20:43 -08008184static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008185 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008186{
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008187 /* Filter incoming packets to determine if they are targeted toward
James Ketrenosea2b26e2005-08-24 21:25:16 -05008188 * this network, discarding packets coming from ourselves */
8189 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008190 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008191 /* packets from our adapter are dropped (echo) */
8192 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8193 return 0;
8194
Peter Jones90700fd2005-08-26 16:51:06 -05008195 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008196 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008197 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008198
8199 /* packets to our adapter go through */
8200 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8201 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008202
Peter Jones90700fd2005-08-26 16:51:06 -05008203 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008204 /* packets from our adapter are dropped (echo) */
8205 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8206 return 0;
8207
Peter Jones90700fd2005-08-26 16:51:06 -05008208 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008209 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008210 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8211
8212 /* packets to our adapter go through */
8213 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8214 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008215 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008216
James Ketrenosea2b26e2005-08-24 21:25:16 -05008217 return 1;
8218}
8219
James Ketrenosafbf30a2005-08-25 00:05:33 -05008220#define IPW_PACKET_RETRY_TIME HZ
8221
Arjan van de Ven858119e2006-01-14 13:20:43 -08008222static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008223 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008224{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008225 u16 sc = le16_to_cpu(header->seq_ctl);
8226 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8227 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8228 u16 *last_seq, *last_frag;
8229 unsigned long *last_time;
8230
8231 switch (priv->ieee->iw_mode) {
8232 case IW_MODE_ADHOC:
8233 {
8234 struct list_head *p;
8235 struct ipw_ibss_seq *entry = NULL;
8236 u8 *mac = header->addr2;
8237 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8238
8239 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8240 entry =
8241 list_entry(p, struct ipw_ibss_seq, list);
8242 if (!memcmp(entry->mac, mac, ETH_ALEN))
8243 break;
8244 }
8245 if (p == &priv->ibss_mac_hash[index]) {
8246 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8247 if (!entry) {
8248 IPW_ERROR
8249 ("Cannot malloc new mac entry\n");
8250 return 0;
8251 }
8252 memcpy(entry->mac, mac, ETH_ALEN);
8253 entry->seq_num = seq;
8254 entry->frag_num = frag;
8255 entry->packet_time = jiffies;
8256 list_add(&entry->list,
8257 &priv->ibss_mac_hash[index]);
8258 return 0;
8259 }
8260 last_seq = &entry->seq_num;
8261 last_frag = &entry->frag_num;
8262 last_time = &entry->packet_time;
8263 break;
8264 }
8265 case IW_MODE_INFRA:
8266 last_seq = &priv->last_seq_num;
8267 last_frag = &priv->last_frag_num;
8268 last_time = &priv->last_packet_time;
8269 break;
8270 default:
8271 return 0;
8272 }
8273 if ((*last_seq == seq) &&
8274 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8275 if (*last_frag == frag)
8276 goto drop;
8277 if (*last_frag + 1 != frag)
8278 /* out-of-order fragment */
8279 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008280 } else
8281 *last_seq = seq;
8282
Zhu Yif57ce7c2005-07-13 12:22:15 -05008283 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008284 *last_time = jiffies;
8285 return 0;
8286
8287 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008288 /* Comment this line now since we observed the card receives
8289 * duplicate packets but the FCTL_RETRY bit is not set in the
8290 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008291 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008292 return 1;
8293}
8294
James Ketrenosb095c382005-08-24 22:04:42 -05008295static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8296 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008297 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008298{
8299 struct sk_buff *skb = rxb->skb;
8300 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008301 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008302 (skb->data + IPW_RX_FRAME_SIZE);
8303
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008304 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008305
8306 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8307 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8308 IEEE80211_STYPE_PROBE_RESP) ||
8309 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8310 IEEE80211_STYPE_BEACON))) {
8311 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8312 ipw_add_station(priv, header->addr2);
8313 }
8314
8315 if (priv->config & CFG_NET_STATS) {
8316 IPW_DEBUG_HC("sending stat packet\n");
8317
8318 /* Set the size of the skb to the size of the full
8319 * ipw header and 802.11 frame */
8320 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8321 IPW_RX_FRAME_SIZE);
8322
8323 /* Advance past the ipw packet header to the 802.11 frame */
8324 skb_pull(skb, IPW_RX_FRAME_SIZE);
8325
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008326 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008327 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8328
8329 skb->dev = priv->ieee->dev;
8330
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008331 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008332 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008333
8334 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008335 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008336 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8337 netif_rx(skb);
8338 rxb->skb = NULL;
8339 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008340}
8341
James Ketrenos43f66a62005-03-25 12:31:53 -06008342/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008343 * Main entry function for receiving a packet with 80211 headers. This
James Ketrenos43f66a62005-03-25 12:31:53 -06008344 * should be called when ever the FW has notified us that there is a new
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008345 * skb in the receive queue.
James Ketrenos43f66a62005-03-25 12:31:53 -06008346 */
8347static void ipw_rx(struct ipw_priv *priv)
8348{
8349 struct ipw_rx_mem_buffer *rxb;
8350 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008351 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008352 u32 r, w, i;
8353 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008354 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008355
James Ketrenosb095c382005-08-24 22:04:42 -05008356 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8357 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008358 i = priv->rxq->read;
8359
8360 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8361 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008362
8363 while (i != r) {
8364 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008365 if (unlikely(rxb == NULL)) {
8366 printk(KERN_CRIT "Queue not allocated!\n");
8367 break;
8368 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008369 priv->rxq->queue[i] = NULL;
8370
8371 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008372 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008373 PCI_DMA_FROMDEVICE);
8374
8375 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8376 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8377 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008378 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008379
8380 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008381 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008382 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008383 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008384 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008385 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008386 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008387 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008388 .noise =
8389 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008390 .rate = pkt->u.frame.rate,
8391 .mac_time = jiffies,
8392 .received_channel =
8393 pkt->u.frame.received_channel,
8394 .freq =
8395 (pkt->u.frame.
8396 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008397 LIBIPW_24GHZ_BAND :
8398 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008399 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008400 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008402 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008403 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008404 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008405 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008406 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008407 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008408 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008409 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008410
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008411 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008412
Zhu Yid685b8c2006-04-13 17:20:27 +08008413#ifdef CONFIG_IPW2200_PROMISCUOUS
8414 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8415 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8416#endif
8417
James Ketrenosb095c382005-08-24 22:04:42 -05008418#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008419 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008420#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008421
8422 ipw_handle_data_packet_monitor(priv,
8423 rxb,
8424 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008425#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008426 ipw_handle_data_packet(priv, rxb,
8427 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008428#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008429 break;
8430 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008431#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008432
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008433 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008434 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008435 data +
8436 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008437 /* TODO: Check Ad-Hoc dest/source and make sure
8438 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008439 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008440 * frame control of the packet and disregard
8441 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008442
James Ketrenosea2b26e2005-08-24 21:25:16 -05008443 network_packet =
8444 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008445 if (network_packet && priv->assoc_network) {
8446 priv->assoc_network->stats.rssi =
8447 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008448 priv->exp_avg_rssi =
8449 exponential_average(priv->exp_avg_rssi,
8450 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008451 }
8452
8453 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008454 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008455
James Ketrenosa613bff2005-08-24 21:43:11 -05008456 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008457 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008458 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008459 IPW_DEBUG_DROP
8460 ("Received packet is too small. "
8461 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008462 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008463 priv->wstats.discard.misc++;
8464 break;
8465 }
8466
James Ketrenosa613bff2005-08-24 21:43:11 -05008467 switch (WLAN_FC_GET_TYPE
8468 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008469
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008470 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008471 ipw_handle_mgmt_packet(priv, rxb,
8472 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008473 break;
8474
8475 case IEEE80211_FTYPE_CTL:
8476 break;
8477
8478 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008479 if (unlikely(!network_packet ||
8480 is_duplicate_packet(priv,
8481 header)))
8482 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008483 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008484 "%pM, "
8485 "%pM, "
8486 "%pM\n",
8487 header->addr1,
8488 header->addr2,
8489 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008490 break;
8491 }
8492
8493 ipw_handle_data_packet(priv, rxb,
8494 &stats);
8495
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008496 break;
8497 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008498 break;
8499 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008501 case RX_HOST_NOTIFICATION_TYPE:{
8502 IPW_DEBUG_RX
8503 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008504 pkt->u.notification.subtype,
8505 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008506 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008507 ipw_rx_notification(priv, &pkt->u.notification);
8508 break;
8509 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008510
8511 default:
8512 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8513 pkt->header.message_type);
8514 break;
8515 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008516
8517 /* For now we just don't re-use anything. We can tweak this
8518 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008519 * fail to Rx correctly */
8520 if (rxb->skb != NULL) {
8521 dev_kfree_skb_any(rxb->skb);
8522 rxb->skb = NULL;
8523 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008524
James Ketrenos43f66a62005-03-25 12:31:53 -06008525 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008526 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008527 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008528
James Ketrenos43f66a62005-03-25 12:31:53 -06008529 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008530
8531 /* If there are a lot of unsued frames, restock the Rx queue
8532 * so the ucode won't assert */
8533 if (fill_rx) {
8534 priv->rxq->read = i;
8535 ipw_rx_queue_replenish(priv);
8536 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008537 }
8538
8539 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008540 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008541 ipw_rx_queue_restock(priv);
8542}
8543
James Ketrenosafbf30a2005-08-25 00:05:33 -05008544#define DEFAULT_RTS_THRESHOLD 2304U
8545#define MIN_RTS_THRESHOLD 1U
8546#define MAX_RTS_THRESHOLD 2304U
8547#define DEFAULT_BEACON_INTERVAL 100U
8548#define DEFAULT_SHORT_RETRY_LIMIT 7U
8549#define DEFAULT_LONG_RETRY_LIMIT 4U
8550
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008551/**
8552 * ipw_sw_reset
8553 * @option: options to control different reset behaviour
8554 * 0 = reset everything except the 'disable' module_param
8555 * 1 = reset everything and print out driver info (for probe only)
8556 * 2 = reset everything
8557 */
8558static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008559{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008560 int band, modulation;
8561 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008562
James Ketrenosafbf30a2005-08-25 00:05:33 -05008563 /* Initialize module parameter values here */
8564 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008565
James Ketrenosafbf30a2005-08-25 00:05:33 -05008566 /* We default to disabling the LED code as right now it causes
8567 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008568 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008569 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008570
James Ketrenosafbf30a2005-08-25 00:05:33 -05008571 if (associate)
8572 priv->config |= CFG_ASSOCIATE;
8573 else
8574 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008575
James Ketrenosafbf30a2005-08-25 00:05:33 -05008576 if (auto_create)
8577 priv->config |= CFG_ADHOC_CREATE;
8578 else
8579 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8580
Zhu Yi17ed0812006-01-24 16:36:31 +08008581 priv->config &= ~CFG_STATIC_ESSID;
8582 priv->essid_len = 0;
8583 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8584
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008585 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008586 priv->status |= STATUS_RF_KILL_SW;
8587 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008588 }
8589
Reinette Chatre21f8a732009-08-18 10:25:05 -07008590 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008591 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008592 priv->channel = default_channel;
8593 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008594 /* TODO: Validate that provided channel is in range */
8595 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008596#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008597 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8598 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008599#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008600
Reinette Chatre21f8a732009-08-18 10:25:05 -07008601 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008602 case 1:
8603 priv->ieee->iw_mode = IW_MODE_ADHOC;
8604 priv->net_dev->type = ARPHRD_ETHER;
8605
8606 break;
8607#ifdef CONFIG_IPW2200_MONITOR
8608 case 2:
8609 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008610#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008611 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8612#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008613 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008614#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008615 break;
8616#endif
8617 default:
8618 case 0:
8619 priv->net_dev->type = ARPHRD_ETHER;
8620 priv->ieee->iw_mode = IW_MODE_INFRA;
8621 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008622 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008623
James Ketrenosafbf30a2005-08-25 00:05:33 -05008624 if (hwcrypto) {
8625 priv->ieee->host_encrypt = 0;
8626 priv->ieee->host_encrypt_msdu = 0;
8627 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008628 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008629 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008630 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008631
Zhu Yie402c932005-08-05 17:20:40 +08008632 /* IPW2200/2915 is abled to do hardware fragmentation. */
8633 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008634
James Ketrenosafbf30a2005-08-25 00:05:33 -05008635 if ((priv->pci_dev->device == 0x4223) ||
8636 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008637 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008638 printk(KERN_INFO DRV_NAME
8639 ": Detected Intel PRO/Wireless 2915ABG Network "
8640 "Connection\n");
8641 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008642 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8643 modulation = LIBIPW_OFDM_MODULATION |
8644 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008645 priv->adapter = IPW_2915ABG;
8646 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008647 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008648 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008649 printk(KERN_INFO DRV_NAME
8650 ": Detected Intel PRO/Wireless 2200BG Network "
8651 "Connection\n");
8652
8653 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008654 band = LIBIPW_24GHZ_BAND;
8655 modulation = LIBIPW_OFDM_MODULATION |
8656 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008657 priv->adapter = IPW_2200BG;
8658 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008659 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008660
James Ketrenosafbf30a2005-08-25 00:05:33 -05008661 priv->ieee->freq_band = band;
8662 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008663
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008664 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008665
James Ketrenosafbf30a2005-08-25 00:05:33 -05008666 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8667 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008668
James Ketrenosafbf30a2005-08-25 00:05:33 -05008669 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8670 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8671 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008672
James Ketrenosafbf30a2005-08-25 00:05:33 -05008673 /* If power management is turned on, default to AC mode */
8674 priv->power_mode = IPW_POWER_AC;
8675 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008676
Zhu Yi0ece35b2005-08-05 17:26:51 +08008677 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008678}
8679
8680/*
8681 * This file defines the Wireless Extension handlers. It does not
8682 * define any methods of hardware manipulation and relies on the
8683 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008684 *
8685 * The exception to this is the use of the ipw_get_ordinal()
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008686 * function used to poll the hardware vs. making unnecessary calls.
James Ketrenos43f66a62005-03-25 12:31:53 -06008687 *
8688 */
8689
James Ketrenos43f66a62005-03-25 12:31:53 -06008690static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8691{
8692 if (channel == 0) {
8693 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8694 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008695 IPW_DEBUG_ASSOC("Attempting to associate with new "
8696 "parameters.\n");
8697 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008698 return 0;
8699 }
8700
8701 priv->config |= CFG_STATIC_CHANNEL;
8702
8703 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008704 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8705 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008706 return 0;
8707 }
8708
8709 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8710 priv->channel = channel;
8711
James Ketrenosb095c382005-08-24 22:04:42 -05008712#ifdef CONFIG_IPW2200_MONITOR
8713 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008714 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008715 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008716 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008717 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008718 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008719 }
8720
8721 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8722 udelay(10);
8723
8724 if (priv->status & STATUS_SCANNING)
8725 IPW_DEBUG_SCAN("Still scanning...\n");
8726 else
8727 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8728 1000 - i);
8729
8730 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008731 }
James Ketrenosb095c382005-08-24 22:04:42 -05008732#endif /* CONFIG_IPW2200_MONITOR */
8733
James Ketrenosc848d0a2005-08-24 21:56:24 -05008734 /* Network configuration changed -- force [re]association */
8735 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8736 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008737 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008738
8739 return 0;
8740}
8741
Jeff Garzikbf794512005-07-31 13:07:26 -04008742static int ipw_wx_set_freq(struct net_device *dev,
8743 struct iw_request_info *info,
8744 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008745{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008746 struct ipw_priv *priv = libipw_priv(dev);
8747 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008748 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008749 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008750 u8 channel, flags;
8751 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008752
James Ketrenosb095c382005-08-24 22:04:42 -05008753 if (fwrq->m == 0) {
8754 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008755 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008756 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008757 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008758 return ret;
8759 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 /* if setting by freq convert to channel */
8761 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008762 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008763 if (channel == 0)
8764 return -EINVAL;
8765 } else
8766 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008767
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008768 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008769 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008770
Liu Hong1fe0adb2005-08-19 09:33:10 -05008771 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008772 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008773 if (i == -1)
8774 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008775
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008776 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008777 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008778 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008779 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8780 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008781 }
8782 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008783
Frans Pop9fd1ea42010-03-24 19:46:31 +01008784 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008785 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008786 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008787 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008788 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008789}
8790
Jeff Garzikbf794512005-07-31 13:07:26 -04008791static int ipw_wx_get_freq(struct net_device *dev,
8792 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 union iwreq_data *wrqu, char *extra)
8794{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008795 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008796
8797 wrqu->freq.e = 0;
8798
8799 /* If we are associated, trying to associate, or have a statically
8800 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008801 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008802 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008803 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8804 int i;
8805
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008806 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008807 BUG_ON(i == -1);
8808 wrqu->freq.e = 1;
8809
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008810 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8811 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008812 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8813 break;
8814
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008815 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008816 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8817 break;
8818
8819 default:
8820 BUG();
8821 }
8822 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008823 wrqu->freq.m = 0;
8824
Zhu Yi46441512006-01-24 16:37:59 +08008825 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008826 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008827 return 0;
8828}
8829
Jeff Garzikbf794512005-07-31 13:07:26 -04008830static int ipw_wx_set_mode(struct net_device *dev,
8831 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 union iwreq_data *wrqu, char *extra)
8833{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008834 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008835 int err = 0;
8836
8837 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8838
James Ketrenos43f66a62005-03-25 12:31:53 -06008839 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008840#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008841 case IW_MODE_MONITOR:
8842#endif
8843 case IW_MODE_ADHOC:
8844 case IW_MODE_INFRA:
8845 break;
8846 case IW_MODE_AUTO:
8847 wrqu->mode = IW_MODE_INFRA;
8848 break;
8849 default:
8850 return -EINVAL;
8851 }
James Ketrenosb095c382005-08-24 22:04:42 -05008852 if (wrqu->mode == priv->ieee->iw_mode)
8853 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008854
Zhu Yi46441512006-01-24 16:37:59 +08008855 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008856
8857 ipw_sw_reset(priv, 0);
8858
James Ketrenosb095c382005-08-24 22:04:42 -05008859#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008860 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008862
8863 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008864#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008865 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8866#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008867 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008868#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008869#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008870
Jeff Garzikbf794512005-07-31 13:07:26 -04008871 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008872 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008873 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008874
8875 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008876
Tejun Heobcb6d912011-01-26 12:12:50 +01008877 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008878 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008879 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008880}
8881
Jeff Garzikbf794512005-07-31 13:07:26 -04008882static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008883 struct iw_request_info *info,
8884 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008885{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008886 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008887 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008888 wrqu->mode = priv->ieee->iw_mode;
8889 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008890 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008891 return 0;
8892}
8893
James Ketrenos43f66a62005-03-25 12:31:53 -06008894/* Values are in microsecond */
8895static const s32 timeout_duration[] = {
8896 350000,
8897 250000,
8898 75000,
8899 37000,
8900 25000,
8901};
8902
8903static const s32 period_duration[] = {
8904 400000,
8905 700000,
8906 1000000,
8907 1000000,
8908 1000000
8909};
8910
Jeff Garzikbf794512005-07-31 13:07:26 -04008911static int ipw_wx_get_range(struct net_device *dev,
8912 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008913 union iwreq_data *wrqu, char *extra)
8914{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008915 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008916 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008917 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008918 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008919
8920 wrqu->data.length = sizeof(*range);
8921 memset(range, 0, sizeof(*range));
8922
8923 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008924 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008925
8926 range->max_qual.qual = 100;
8927 /* TODO: Find real max RSSI and stick here */
8928 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008929 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008930 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008931
8932 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008933 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008934 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008935 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008936 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008937 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008938 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008939
Jeff Garzikbf794512005-07-31 13:07:26 -04008940 for (i = 0; i < range->num_bitrates; i++)
8941 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008942 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008943
James Ketrenos43f66a62005-03-25 12:31:53 -06008944 range->max_rts = DEFAULT_RTS_THRESHOLD;
8945 range->min_frag = MIN_FRAG_THRESHOLD;
8946 range->max_frag = MAX_FRAG_THRESHOLD;
8947
8948 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008949 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008950 range->num_encoding_sizes = 2;
8951 range->max_encoding_tokens = WEP_KEYS;
8952
8953 /* Set the Wireless Extension versions */
8954 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008955 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008956
James Ketrenosb095c382005-08-24 22:04:42 -05008957 i = 0;
8958 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008959 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8960 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008961 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008962 continue;
8963
James Ketrenosb095c382005-08-24 22:04:42 -05008964 range->freq[i].i = geo->bg[j].channel;
8965 range->freq[i].m = geo->bg[j].freq * 100000;
8966 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008967 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008968 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008969 }
James Ketrenosb095c382005-08-24 22:04:42 -05008970
8971 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008972 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8973 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008974 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008975 continue;
8976
James Ketrenosb095c382005-08-24 22:04:42 -05008977 range->freq[i].i = geo->a[j].channel;
8978 range->freq[i].m = geo->a[j].freq * 100000;
8979 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008980 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008981 }
8982 }
8983
8984 range->num_channels = i;
8985 range->num_frequency = i;
8986
Zhu Yi46441512006-01-24 16:37:59 +08008987 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008988
8989 /* Event capability (kernel + driver) */
8990 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8991 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008992 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8993 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008994 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008995
Dan Williamsf1b50862006-01-30 13:58:56 -05008996 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8997 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8998
Dan Williams374fdfb2007-12-12 10:25:07 -05008999 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9000
James Ketrenos43f66a62005-03-25 12:31:53 -06009001 IPW_DEBUG_WX("GET Range\n");
9002 return 0;
9003}
9004
Jeff Garzikbf794512005-07-31 13:07:26 -04009005static int ipw_wx_set_wap(struct net_device *dev,
9006 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009007 union iwreq_data *wrqu, char *extra)
9008{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009009 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009010
9011 static const unsigned char any[] = {
9012 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9013 };
9014 static const unsigned char off[] = {
9015 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9016 };
9017
Jeff Garzikbf794512005-07-31 13:07:26 -04009018 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009019 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009020 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009021 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9022 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9023 /* we disable mandatory BSSID association */
9024 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9025 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009026 IPW_DEBUG_ASSOC("Attempting to associate with new "
9027 "parameters.\n");
9028 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009029 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009030 return 0;
9031 }
9032
9033 priv->config |= CFG_STATIC_BSSID;
9034 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9035 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009036 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009037 return 0;
9038 }
9039
Johannes Berge1749612008-10-27 15:59:26 -07009040 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9041 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009042
9043 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9044
James Ketrenosc848d0a2005-08-24 21:56:24 -05009045 /* Network configuration changed -- force [re]association */
9046 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9047 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009048 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009049
Zhu Yi46441512006-01-24 16:37:59 +08009050 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009051 return 0;
9052}
9053
Jeff Garzikbf794512005-07-31 13:07:26 -04009054static int ipw_wx_get_wap(struct net_device *dev,
9055 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009056 union iwreq_data *wrqu, char *extra)
9057{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009058 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009059
James Ketrenos43f66a62005-03-25 12:31:53 -06009060 /* If we are associated, trying to associate, or have a statically
9061 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009062 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009063 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9065 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009066 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009067 } else
9068 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9069
Johannes Berge1749612008-10-27 15:59:26 -07009070 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9071 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009072 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009073 return 0;
9074}
9075
Jeff Garzikbf794512005-07-31 13:07:26 -04009076static int ipw_wx_set_essid(struct net_device *dev,
9077 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009078 union iwreq_data *wrqu, char *extra)
9079{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009080 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009081 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009082 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009083
Zhu Yiab644b02006-08-21 11:37:13 +08009084 mutex_lock(&priv->mutex);
9085
9086 if (!wrqu->essid.flags)
9087 {
9088 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9089 ipw_disassociate(priv);
9090 priv->config &= ~CFG_STATIC_ESSID;
9091 ipw_associate(priv);
9092 mutex_unlock(&priv->mutex);
9093 return 0;
9094 }
9095
Zhu Yia9f0d422006-08-21 11:37:26 +08009096 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009097
9098 priv->config |= CFG_STATIC_ESSID;
9099
Zhu Yia9f0d422006-08-21 11:37:26 +08009100 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9101 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009102 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009103 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009104 return 0;
9105 }
9106
John W. Linville9387b7c2008-09-30 20:59:05 -04009107 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9108 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009109
9110 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009111 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009112
James Ketrenosc848d0a2005-08-24 21:56:24 -05009113 /* Network configuration changed -- force [re]association */
9114 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9115 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009116 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009117
Zhu Yi46441512006-01-24 16:37:59 +08009118 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009119 return 0;
9120}
9121
Jeff Garzikbf794512005-07-31 13:07:26 -04009122static int ipw_wx_get_essid(struct net_device *dev,
9123 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009124 union iwreq_data *wrqu, char *extra)
9125{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009126 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009127 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009128
9129 /* If we are associated, trying to associate, or have a statically
9130 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009131 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009132 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009133 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9134 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009135 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009136 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009138 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009139 } else {
9140 IPW_DEBUG_WX("Getting essid: ANY\n");
9141 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009142 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009143 }
Zhu Yi46441512006-01-24 16:37:59 +08009144 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009145 return 0;
9146}
9147
Jeff Garzikbf794512005-07-31 13:07:26 -04009148static int ipw_wx_set_nick(struct net_device *dev,
9149 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009151{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009152 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009153
9154 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9155 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9156 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009157 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009158 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009159 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009160 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009161 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009162 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009163 return 0;
9164
9165}
9166
Jeff Garzikbf794512005-07-31 13:07:26 -04009167static int ipw_wx_get_nick(struct net_device *dev,
9168 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009170{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009171 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009172 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009173 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009174 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009175 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009176 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009177 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009178 return 0;
9179}
9180
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009181static int ipw_wx_set_sens(struct net_device *dev,
9182 struct iw_request_info *info,
9183 union iwreq_data *wrqu, char *extra)
9184{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009185 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009186 int err = 0;
9187
9188 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9189 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9190 mutex_lock(&priv->mutex);
9191
9192 if (wrqu->sens.fixed == 0)
9193 {
9194 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9195 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9196 goto out;
9197 }
9198 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9199 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9200 err = -EINVAL;
9201 goto out;
9202 }
9203
9204 priv->roaming_threshold = wrqu->sens.value;
9205 priv->disassociate_threshold = 3*wrqu->sens.value;
9206 out:
9207 mutex_unlock(&priv->mutex);
9208 return err;
9209}
9210
9211static int ipw_wx_get_sens(struct net_device *dev,
9212 struct iw_request_info *info,
9213 union iwreq_data *wrqu, char *extra)
9214{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009215 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009216 mutex_lock(&priv->mutex);
9217 wrqu->sens.fixed = 1;
9218 wrqu->sens.value = priv->roaming_threshold;
9219 mutex_unlock(&priv->mutex);
9220
Frans Pop9fd1ea42010-03-24 19:46:31 +01009221 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009222 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9223
9224 return 0;
9225}
9226
James Ketrenos43f66a62005-03-25 12:31:53 -06009227static int ipw_wx_set_rate(struct net_device *dev,
9228 struct iw_request_info *info,
9229 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009230{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009231 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009232 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009233 u32 target_rate = wrqu->bitrate.value;
9234 u32 fixed, mask;
9235
9236 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9237 /* value = X, fixed = 1 means only rate X */
9238 /* value = X, fixed = 0 means all rates lower equal X */
9239
9240 if (target_rate == -1) {
9241 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009242 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009243 /* Now we should reassociate */
9244 goto apply;
9245 }
9246
9247 mask = 0;
9248 fixed = wrqu->bitrate.fixed;
9249
9250 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009251 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009252 if (target_rate == 1000000)
9253 goto apply;
9254
9255 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009256 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009257 if (target_rate == 2000000)
9258 goto apply;
9259
9260 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009261 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009262 if (target_rate == 5500000)
9263 goto apply;
9264
9265 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009266 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009267 if (target_rate == 6000000)
9268 goto apply;
9269
9270 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009271 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009272 if (target_rate == 9000000)
9273 goto apply;
9274
9275 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009276 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009277 if (target_rate == 11000000)
9278 goto apply;
9279
9280 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009281 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009282 if (target_rate == 12000000)
9283 goto apply;
9284
9285 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009286 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009287 if (target_rate == 18000000)
9288 goto apply;
9289
9290 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009291 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009292 if (target_rate == 24000000)
9293 goto apply;
9294
9295 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009296 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009297 if (target_rate == 36000000)
9298 goto apply;
9299
9300 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009301 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009302 if (target_rate == 48000000)
9303 goto apply;
9304
9305 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009306 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009307 if (target_rate == 54000000)
9308 goto apply;
9309
9310 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9311 return -EINVAL;
9312
9313 apply:
9314 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9315 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009316 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009317 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009318 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009319 ipw_set_fixed_rate(priv, priv->ieee->mode);
9320 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009321 priv->config |= CFG_FIXED_RATE;
9322
James Ketrenosc848d0a2005-08-24 21:56:24 -05009323 if (priv->rates_mask == mask) {
9324 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009325 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009326 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009327 }
9328
James Ketrenosc848d0a2005-08-24 21:56:24 -05009329 priv->rates_mask = mask;
9330
9331 /* Network configuration changed -- force [re]association */
9332 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9333 if (!ipw_disassociate(priv))
9334 ipw_associate(priv);
9335
Zhu Yi46441512006-01-24 16:37:59 +08009336 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009337 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009338}
9339
Jeff Garzikbf794512005-07-31 13:07:26 -04009340static int ipw_wx_get_rate(struct net_device *dev,
9341 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009342 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009343{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009344 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009345 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009347 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009348 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009349 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009350 return 0;
9351}
9352
Jeff Garzikbf794512005-07-31 13:07:26 -04009353static int ipw_wx_set_rts(struct net_device *dev,
9354 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009355 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009356{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009357 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009358 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009359 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009360 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9361 else {
9362 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009363 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009364 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009365 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009366 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009367 priv->rts_threshold = wrqu->rts.value;
9368 }
9369
9370 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009371 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009372 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 return 0;
9374}
9375
Jeff Garzikbf794512005-07-31 13:07:26 -04009376static int ipw_wx_get_rts(struct net_device *dev,
9377 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009378 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009379{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009380 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009381 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009382 wrqu->rts.value = priv->rts_threshold;
9383 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009384 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009385 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009386 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009387 return 0;
9388}
9389
Jeff Garzikbf794512005-07-31 13:07:26 -04009390static int ipw_wx_set_txpow(struct net_device *dev,
9391 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009392 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009393{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009394 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009395 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009396
Zhu Yi46441512006-01-24 16:37:59 +08009397 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009398 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009399 err = -EINPROGRESS;
9400 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009401 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009402
James Ketrenosb095c382005-08-24 22:04:42 -05009403 if (!wrqu->power.fixed)
9404 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009405
James Ketrenosc848d0a2005-08-24 21:56:24 -05009406 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009407 err = -EINVAL;
9408 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009409 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009410
James Ketrenosb095c382005-08-24 22:04:42 -05009411 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009412 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009413 err = -EINVAL;
9414 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009415 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009416
9417 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009418 err = ipw_set_tx_power(priv);
9419 out:
Zhu Yi46441512006-01-24 16:37:59 +08009420 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009421 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009422}
9423
Jeff Garzikbf794512005-07-31 13:07:26 -04009424static int ipw_wx_get_txpow(struct net_device *dev,
9425 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009426 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009427{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009428 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009429 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009430 wrqu->power.value = priv->tx_power;
9431 wrqu->power.fixed = 1;
9432 wrqu->power.flags = IW_TXPOW_DBM;
9433 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009434 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009435
Frans Pop9fd1ea42010-03-24 19:46:31 +01009436 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009437 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009438
9439 return 0;
9440}
9441
Jeff Garzikbf794512005-07-31 13:07:26 -04009442static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009443 struct iw_request_info *info,
9444 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009445{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009446 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009447 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009448 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009449 priv->ieee->fts = DEFAULT_FTS;
9450 else {
9451 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009452 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009453 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009454 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009455 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009456
James Ketrenos43f66a62005-03-25 12:31:53 -06009457 priv->ieee->fts = wrqu->frag.value & ~0x1;
9458 }
9459
9460 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009461 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009462 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463 return 0;
9464}
9465
Jeff Garzikbf794512005-07-31 13:07:26 -04009466static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009467 struct iw_request_info *info,
9468 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009469{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009470 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009471 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 wrqu->frag.value = priv->ieee->fts;
9473 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009474 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009475 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009476 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009477
9478 return 0;
9479}
9480
Jeff Garzikbf794512005-07-31 13:07:26 -04009481static int ipw_wx_set_retry(struct net_device *dev,
9482 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009483 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009484{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009485 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009486
9487 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9488 return -EINVAL;
9489
9490 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9491 return 0;
9492
Zhu Yid5f7ac22006-08-21 11:38:17 +08009493 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009494 return -EINVAL;
9495
Zhu Yi46441512006-01-24 16:37:59 +08009496 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009497 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009498 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009499 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009500 priv->long_retry_limit = (u8) wrqu->retry.value;
9501 else {
9502 priv->short_retry_limit = (u8) wrqu->retry.value;
9503 priv->long_retry_limit = (u8) wrqu->retry.value;
9504 }
9505
9506 ipw_send_retry_limit(priv, priv->short_retry_limit,
9507 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009508 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009509 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9510 priv->short_retry_limit, priv->long_retry_limit);
9511 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009512}
9513
Jeff Garzikbf794512005-07-31 13:07:26 -04009514static int ipw_wx_get_retry(struct net_device *dev,
9515 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009516 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009517{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009518 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009519
Zhu Yi46441512006-01-24 16:37:59 +08009520 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009521 wrqu->retry.disabled = 0;
9522
9523 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009524 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009525 return -EINVAL;
9526 }
9527
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009528 if (wrqu->retry.flags & IW_RETRY_LONG) {
9529 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009530 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009531 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9532 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009533 wrqu->retry.value = priv->short_retry_limit;
9534 } else {
9535 wrqu->retry.flags = IW_RETRY_LIMIT;
9536 wrqu->retry.value = priv->short_retry_limit;
9537 }
Zhu Yi46441512006-01-24 16:37:59 +08009538 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009539
Frans Pop9fd1ea42010-03-24 19:46:31 +01009540 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009541
9542 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009543}
9544
Jeff Garzikbf794512005-07-31 13:07:26 -04009545static int ipw_wx_set_scan(struct net_device *dev,
9546 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009547 union iwreq_data *wrqu, char *extra)
9548{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009549 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009550 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009551 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009552
Dan Williams0b531672007-10-09 13:55:24 -04009553 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009554
Dan Williams0b531672007-10-09 13:55:24 -04009555 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009556
Zhu Yi094c4d22006-08-21 11:39:03 +08009557 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009558 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009559 int len = min((int)req->essid_len,
9560 (int)sizeof(priv->direct_scan_ssid));
9561 memcpy(priv->direct_scan_ssid, req->essid, len);
9562 priv->direct_scan_ssid_len = len;
9563 work = &priv->request_direct_scan;
9564 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9565 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009566 }
Dan Williamsea177302008-06-02 17:51:23 -04009567 } else {
9568 /* Normal active broadcast scan */
9569 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009570 }
James Ketrenos8935f392005-10-05 15:59:08 -05009571
Dan Williamsea177302008-06-02 17:51:23 -04009572 mutex_unlock(&priv->mutex);
9573
James Ketrenos43f66a62005-03-25 12:31:53 -06009574 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009575
Tejun Heobcb6d912011-01-26 12:12:50 +01009576 schedule_delayed_work(work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009577
James Ketrenos43f66a62005-03-25 12:31:53 -06009578 return 0;
9579}
9580
Jeff Garzikbf794512005-07-31 13:07:26 -04009581static int ipw_wx_get_scan(struct net_device *dev,
9582 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009583 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009584{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009585 struct ipw_priv *priv = libipw_priv(dev);
9586 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009587}
9588
Jeff Garzikbf794512005-07-31 13:07:26 -04009589static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009590 struct iw_request_info *info,
9591 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009592{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009593 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009594 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009595 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009596
Zhu Yi46441512006-01-24 16:37:59 +08009597 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009598 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009599
Hong Liucaeff812005-08-05 17:25:50 +08009600 /* In IBSS mode, we need to notify the firmware to update
9601 * the beacon info after we changed the capability. */
9602 if (cap != priv->capability &&
9603 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9604 priv->status & STATUS_ASSOCIATED)
9605 ipw_disassociate(priv);
9606
Zhu Yi46441512006-01-24 16:37:59 +08009607 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009608 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009609}
9610
Jeff Garzikbf794512005-07-31 13:07:26 -04009611static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009612 struct iw_request_info *info,
9613 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009614{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009615 struct ipw_priv *priv = libipw_priv(dev);
9616 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009617}
9618
Jeff Garzikbf794512005-07-31 13:07:26 -04009619static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009620 struct iw_request_info *info,
9621 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009622{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009623 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009624 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009625 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009626 if (wrqu->power.disabled) {
9627 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9628 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9629 if (err) {
9630 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009631 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009632 return err;
9633 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009635 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009636 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009637 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009638
9639 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009640 case IW_POWER_ON: /* If not specified */
9641 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009642 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009643 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009644 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9646 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009647 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009648 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009649 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009650
James Ketrenos43f66a62005-03-25 12:31:53 -06009651 /* If the user hasn't specified a power management mode yet, default
9652 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009653 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009654 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009655 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009656 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009657
James Ketrenos43f66a62005-03-25 12:31:53 -06009658 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9659 if (err) {
9660 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009661 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009662 return err;
9663 }
9664
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009665 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009666 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009667 return 0;
9668}
9669
Jeff Garzikbf794512005-07-31 13:07:26 -04009670static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009671 struct iw_request_info *info,
9672 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009673{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009674 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009675 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009676 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009677 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009678 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009679 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009680
Zhu Yi46441512006-01-24 16:37:59 +08009681 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009682 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009683
James Ketrenos43f66a62005-03-25 12:31:53 -06009684 return 0;
9685}
9686
Jeff Garzikbf794512005-07-31 13:07:26 -04009687static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009688 struct iw_request_info *info,
9689 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009690{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009691 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 int mode = *(int *)extra;
9693 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009694
Zhu Yi46441512006-01-24 16:37:59 +08009695 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009696 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009697 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009698
Zhu Yi4e157f02007-07-12 16:09:32 +08009699 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009700 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009701 if (err) {
9702 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009703 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 return err;
9705 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009706 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009707 }
Zhu Yi46441512006-01-24 16:37:59 +08009708 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 return 0;
9710}
9711
9712#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009713static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009714 struct iw_request_info *info,
9715 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009716{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009717 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 int level = IPW_POWER_LEVEL(priv->power_mode);
9719 char *p = extra;
9720
9721 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9722
9723 switch (level) {
9724 case IPW_POWER_AC:
9725 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9726 break;
9727 case IPW_POWER_BATTERY:
9728 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9729 break;
9730 default:
9731 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009732 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009733 timeout_duration[level - 1] / 1000,
9734 period_duration[level - 1] / 1000);
9735 }
9736
9737 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009738 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009739
9740 wrqu->data.length = p - extra + 1;
9741
9742 return 0;
9743}
9744
9745static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009746 struct iw_request_info *info,
9747 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009748{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009749 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009750 int mode = *(int *)extra;
9751 u8 band = 0, modulation = 0;
9752
9753 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009754 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009755 return -EINVAL;
9756 }
Zhu Yi46441512006-01-24 16:37:59 +08009757 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009758 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009759 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009760 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009761 band |= LIBIPW_52GHZ_BAND;
9762 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009763 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009764 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 } else {
9766 if (mode & IEEE_A) {
9767 IPW_WARNING("Attempt to set 2200BG into "
9768 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009769 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 return -EINVAL;
9771 }
9772
James Ketrenosa33a1982005-09-14 14:28:59 -05009773 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009774 }
9775
9776 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009777 band |= LIBIPW_24GHZ_BAND;
9778 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009779 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009780 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009781
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009783 band |= LIBIPW_24GHZ_BAND;
9784 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009785 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009786 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009787
9788 priv->ieee->mode = mode;
9789 priv->ieee->freq_band = band;
9790 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009791 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009792
James Ketrenosc848d0a2005-08-24 21:56:24 -05009793 /* Network configuration changed -- force [re]association */
9794 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9795 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009796 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009797 ipw_associate(priv);
9798 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009799
James Ketrenosa613bff2005-08-24 21:43:11 -05009800 /* Update the band LEDs */
9801 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009802
Jeff Garzikbf794512005-07-31 13:07:26 -04009803 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009804 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009805 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009806 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009807 return 0;
9808}
9809
9810static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009811 struct iw_request_info *info,
9812 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009813{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009814 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009815 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009816 switch (priv->ieee->mode) {
9817 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009818 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9819 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009820 case IEEE_B:
9821 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9822 break;
9823 case IEEE_A | IEEE_B:
9824 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9825 break;
9826 case IEEE_G:
9827 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9828 break;
9829 case IEEE_A | IEEE_G:
9830 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9831 break;
9832 case IEEE_B | IEEE_G:
9833 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9834 break;
9835 case IEEE_A | IEEE_B | IEEE_G:
9836 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9837 break;
9838 default:
9839 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009840 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009841 }
9842
James Ketrenos43f66a62005-03-25 12:31:53 -06009843 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9844
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009845 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009846 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009847
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009848 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009849}
9850
James Ketrenosea2b26e2005-08-24 21:25:16 -05009851static int ipw_wx_set_preamble(struct net_device *dev,
9852 struct iw_request_info *info,
9853 union iwreq_data *wrqu, char *extra)
9854{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009855 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009856 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009857 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009858 /* Switching from SHORT -> LONG requires a disassociation */
9859 if (mode == 1) {
9860 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9861 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009862
9863 /* Network configuration changed -- force [re]association */
9864 IPW_DEBUG_ASSOC
9865 ("[re]association triggered due to preamble change.\n");
9866 if (!ipw_disassociate(priv))
9867 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009868 }
9869 goto done;
9870 }
9871
9872 if (mode == 0) {
9873 priv->config &= ~CFG_PREAMBLE_LONG;
9874 goto done;
9875 }
Zhu Yi46441512006-01-24 16:37:59 +08009876 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009877 return -EINVAL;
9878
9879 done:
Zhu Yi46441512006-01-24 16:37:59 +08009880 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 return 0;
9882}
9883
9884static int ipw_wx_get_preamble(struct net_device *dev,
9885 struct iw_request_info *info,
9886 union iwreq_data *wrqu, char *extra)
9887{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009888 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009889 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009890 if (priv->config & CFG_PREAMBLE_LONG)
9891 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9892 else
9893 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009894 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009895 return 0;
9896}
9897
James Ketrenosb095c382005-08-24 22:04:42 -05009898#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009899static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009900 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009901 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009902{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009903 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009904 int *parms = (int *)extra;
9905 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009906 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009907 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009908 if (enable) {
9909 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009910#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009911 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9912#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009914#endif
Tejun Heobcb6d912011-01-26 12:12:50 +01009915 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009916 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009917
James Ketrenos43f66a62005-03-25 12:31:53 -06009918 ipw_set_channel(priv, parms[1]);
9919 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009920 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009921 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009922 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009923 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009924 priv->net_dev->type = ARPHRD_ETHER;
Tejun Heobcb6d912011-01-26 12:12:50 +01009925 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009926 }
Zhu Yi46441512006-01-24 16:37:59 +08009927 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009928 return 0;
9929}
9930
Pavel Machek67fd6b42006-07-11 15:34:05 +02009931#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009932
Jeff Garzikbf794512005-07-31 13:07:26 -04009933static int ipw_wx_reset(struct net_device *dev,
9934 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009935 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009936{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009937 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009938 IPW_DEBUG_WX("RESET\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01009939 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009940 return 0;
9941}
James Ketrenosb095c382005-08-24 22:04:42 -05009942
James Ketrenosb095c382005-08-24 22:04:42 -05009943static int ipw_wx_sw_reset(struct net_device *dev,
9944 struct iw_request_info *info,
9945 union iwreq_data *wrqu, char *extra)
9946{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009947 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009948 union iwreq_data wrqu_sec = {
9949 .encoding = {
9950 .flags = IW_ENCODE_DISABLED,
9951 },
9952 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009953 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009954
9955 IPW_DEBUG_WX("SW_RESET\n");
9956
Zhu Yi46441512006-01-24 16:37:59 +08009957 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009958
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009959 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009960 if (!ret) {
9961 free_firmware();
9962 ipw_adapter_restart(priv);
9963 }
James Ketrenosb095c382005-08-24 22:04:42 -05009964
9965 /* The SW reset bit might have been toggled on by the 'disable'
9966 * module parameter, so take appropriate action */
9967 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9968
Zhu Yi46441512006-01-24 16:37:59 +08009969 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009970 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009971 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009972
9973 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9974 /* Configuration likely changed -- force [re]association */
9975 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9976 "reset.\n");
9977 if (!ipw_disassociate(priv))
9978 ipw_associate(priv);
9979 }
9980
Zhu Yi46441512006-01-24 16:37:59 +08009981 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009982
9983 return 0;
9984}
James Ketrenos43f66a62005-03-25 12:31:53 -06009985
9986/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009987static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -07009988 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
9989 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9990 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
9991 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
9992 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
9993 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
9994 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
9995 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
9996 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
9997 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
9998 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
9999 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10000 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10001 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10002 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10003 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10004 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10005 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10006 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10007 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10008 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10009 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10010 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10011 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10012 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10013 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10014 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10015 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10016 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10017 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10018 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10019 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10020 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10021 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10022 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10023 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10024 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10025 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10026 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10027 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10028 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010029};
10030
James Ketrenosb095c382005-08-24 22:04:42 -050010031enum {
10032 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10033 IPW_PRIV_GET_POWER,
10034 IPW_PRIV_SET_MODE,
10035 IPW_PRIV_GET_MODE,
10036 IPW_PRIV_SET_PREAMBLE,
10037 IPW_PRIV_GET_PREAMBLE,
10038 IPW_PRIV_RESET,
10039 IPW_PRIV_SW_RESET,
10040#ifdef CONFIG_IPW2200_MONITOR
10041 IPW_PRIV_SET_MONITOR,
10042#endif
10043};
James Ketrenos43f66a62005-03-25 12:31:53 -060010044
Jeff Garzikbf794512005-07-31 13:07:26 -040010045static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010047 .cmd = IPW_PRIV_SET_POWER,
10048 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10049 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010051 .cmd = IPW_PRIV_GET_POWER,
10052 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10053 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010055 .cmd = IPW_PRIV_SET_MODE,
10056 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10057 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010058 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010059 .cmd = IPW_PRIV_GET_MODE,
10060 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10061 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010063 .cmd = IPW_PRIV_SET_PREAMBLE,
10064 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10065 .name = "set_preamble"},
10066 {
10067 .cmd = IPW_PRIV_GET_PREAMBLE,
10068 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10069 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010070 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010071 IPW_PRIV_RESET,
10072 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010073 {
10074 IPW_PRIV_SW_RESET,
10075 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10076#ifdef CONFIG_IPW2200_MONITOR
10077 {
10078 IPW_PRIV_SET_MONITOR,
10079 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10080#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010081};
10082
10083static iw_handler ipw_priv_handler[] = {
10084 ipw_wx_set_powermode,
10085 ipw_wx_get_powermode,
10086 ipw_wx_set_wireless_mode,
10087 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010088 ipw_wx_set_preamble,
10089 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010090 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010091 ipw_wx_sw_reset,
10092#ifdef CONFIG_IPW2200_MONITOR
10093 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010094#endif
10095};
10096
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010097static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010098 .standard = ipw_wx_handlers,
10099 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10100 .num_private = ARRAY_SIZE(ipw_priv_handler),
10101 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10102 .private = ipw_priv_handler,
10103 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010104 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010105};
10106
James Ketrenos43f66a62005-03-25 12:31:53 -060010107/*
10108 * Get wireless statistics.
10109 * Called by /proc/net/wireless
10110 * Also called by SIOCGIWSTATS
10111 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010112static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010113{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010114 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010115 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010116
James Ketrenos43f66a62005-03-25 12:31:53 -060010117 wstats = &priv->wstats;
10118
James Ketrenosea2b26e2005-08-24 21:25:16 -050010119 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010120 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010121 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10122 * and associated; if not associcated, the values are all meaningless
10123 * anyway, so set them all to NULL and INVALID */
10124 if (!(priv->status & STATUS_ASSOCIATED)) {
10125 wstats->miss.beacon = 0;
10126 wstats->discard.retries = 0;
10127 wstats->qual.qual = 0;
10128 wstats->qual.level = 0;
10129 wstats->qual.noise = 0;
10130 wstats->qual.updated = 7;
10131 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010132 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010133 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010134 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010135
10136 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010137 wstats->qual.level = priv->exp_avg_rssi;
10138 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010139 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010140 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010141
10142 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10143 wstats->discard.retries = priv->last_tx_failures;
10144 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010145
James Ketrenos43f66a62005-03-25 12:31:53 -060010146/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10147 goto fail_get_ordinal;
10148 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010149
James Ketrenos43f66a62005-03-25 12:31:53 -060010150 return wstats;
10151}
10152
James Ketrenos43f66a62005-03-25 12:31:53 -060010153/* net device stuff */
10154
Arjan van de Ven858119e2006-01-14 13:20:43 -080010155static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010156{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010157 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010158 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010159 sys_config->answer_broadcast_ssid_probe = 0;
10160 sys_config->accept_all_data_frames = 0;
10161 sys_config->accept_non_directed_frames = 1;
10162 sys_config->exclude_unicast_unencrypted = 0;
10163 sys_config->disable_unicast_decryption = 1;
10164 sys_config->exclude_multicast_unencrypted = 0;
10165 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010166 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10167 antenna = CFG_SYS_ANTENNA_BOTH;
10168 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010169 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010170 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010171 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010172 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010173 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010174 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010175}
10176
10177static int ipw_net_open(struct net_device *dev)
10178{
James Ketrenos43f66a62005-03-25 12:31:53 -060010179 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010180 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010181 return 0;
10182}
10183
10184static int ipw_net_stop(struct net_device *dev)
10185{
10186 IPW_DEBUG_INFO("dev->close\n");
10187 netif_stop_queue(dev);
10188 return 0;
10189}
10190
10191/*
10192todo:
10193
10194modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010195we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010196*/
10197
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010198static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010199 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010200{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010201 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010202 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 int i = 0;
10204 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010205#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010206 int tx_id = ipw_get_tx_queue_number(priv, pri);
10207 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10208#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010209 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010210#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 struct clx2_queue *q = &txq->q;
10212 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010213 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010214
Zhu Yib8ddafd2008-11-27 13:42:20 +080010215 if (!(priv->status & STATUS_ASSOCIATED))
10216 goto drop;
10217
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010218 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010219 switch (priv->ieee->iw_mode) {
10220 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010221 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010222 id = ipw_find_station(priv, hdr->addr1);
10223 if (id == IPW_INVALID_STATION) {
10224 id = ipw_add_station(priv, hdr->addr1);
10225 if (id == IPW_INVALID_STATION) {
10226 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010227 "invalid cell: %pM\n",
10228 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010229 goto drop;
10230 }
10231 }
10232 break;
10233
10234 case IW_MODE_INFRA:
10235 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010236 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010237 id = 0;
10238 break;
10239 }
10240
10241 tfd = &txq->bd[q->first_empty];
10242 txq->txb[q->first_empty] = txb;
10243 memset(tfd, 0, sizeof(*tfd));
10244 tfd->u.data.station_number = id;
10245
10246 tfd->control_flags.message_type = TX_FRAME_TYPE;
10247 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10248
10249 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010250 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010251
James Ketrenos43f66a62005-03-25 12:31:53 -060010252 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010253 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010254 else
James Ketrenosb095c382005-08-24 22:04:42 -050010255 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010256
James Ketrenosea2b26e2005-08-24 21:25:16 -050010257 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10258 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010259
James Ketrenosc848d0a2005-08-24 21:56:24 -050010260 fc = le16_to_cpu(hdr->frame_ctl);
10261 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010262
10263 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10264
James Ketrenosb095c382005-08-24 22:04:42 -050010265 if (likely(unicast))
10266 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10267
10268 if (txb->encrypted && !priv->ieee->host_encrypt) {
10269 switch (priv->ieee->sec.level) {
10270 case SEC_LEVEL_3:
10271 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010272 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010273 /* XXX: ACK flag must be set for CCMP even if it
10274 * is a multicast/broadcast packet, because CCMP
10275 * group communication encrypted by GTK is
10276 * actually done by the AP. */
10277 if (!unicast)
10278 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10279
10280 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10281 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10282 tfd->u.data.key_index = 0;
10283 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10284 break;
10285 case SEC_LEVEL_2:
10286 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010287 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010288 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10289 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10290 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10291 break;
10292 case SEC_LEVEL_1:
10293 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010294 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010295 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10296 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010297 40)
10298 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10299 else
10300 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10301 break;
10302 case SEC_LEVEL_0:
10303 break;
10304 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010305 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010306 priv->ieee->sec.level);
10307 break;
10308 }
10309 } else
10310 /* No hardware encryption */
10311 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10312
Zhu Yie43e3c12006-04-13 17:20:45 +080010313#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010314 if (fc & IEEE80211_STYPE_QOS_DATA)
10315 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010316#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010317
James Ketrenos43f66a62005-03-25 12:31:53 -060010318 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010319 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10320 txb->nr_frags));
10321 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10322 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10323 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10324 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10325 i, le32_to_cpu(tfd->u.data.num_chunks),
10326 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010327 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010328 i, tfd->u.data.num_chunks,
10329 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010330 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010331 txb->fragments[i]->len - hdr_len);
10332
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010333 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010334 cpu_to_le32(pci_map_single
10335 (priv->pci_dev,
10336 txb->fragments[i]->data + hdr_len,
10337 txb->fragments[i]->len - hdr_len,
10338 PCI_DMA_TODEVICE));
10339 tfd->u.data.chunk_len[i] =
10340 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010341 }
10342
10343 if (i != txb->nr_frags) {
10344 struct sk_buff *skb;
10345 u16 remaining_bytes = 0;
10346 int j;
10347
10348 for (j = i; j < txb->nr_frags; j++)
10349 remaining_bytes += txb->fragments[j]->len - hdr_len;
10350
10351 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10352 remaining_bytes);
10353 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10354 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010355 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010356 for (j = i; j < txb->nr_frags; j++) {
10357 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010358
James Ketrenos43f66a62005-03-25 12:31:53 -060010359 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010360 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010361 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010362 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010363 }
10364 dev_kfree_skb_any(txb->fragments[i]);
10365 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010366 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010367 cpu_to_le32(pci_map_single
10368 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010369 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010370 PCI_DMA_TODEVICE));
10371
Marcin Slusarz5c058632008-02-13 00:06:12 +010010372 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010373 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010374 }
10375
10376 /* kick DMA */
10377 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10378 ipw_write32(priv, q->reg_w, q->first_empty);
10379
Dan Williams943dbef2008-02-14 17:49:41 -050010380 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010381 netif_stop_queue(priv->net_dev);
10382
James Ketrenos227d2dc2005-07-28 16:25:55 -050010383 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010384
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010385 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010386 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010387 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010388 return NETDEV_TX_OK;
10389}
10390
10391static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10392{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010393 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010394#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010395 int tx_id = ipw_get_tx_queue_number(priv, pri);
10396 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10397#else
10398 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010399#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010400
Dan Williams943dbef2008-02-14 17:49:41 -050010401 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010402 return 1;
10403
10404 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010405}
10406
Zhu Yid685b8c2006-04-13 17:20:27 +080010407#ifdef CONFIG_IPW2200_PROMISCUOUS
10408static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010409 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010410{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010411 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010412 struct ieee80211_hdr *hdr;
10413 u8 n;
10414 u16 filter = priv->prom_priv->filter;
10415 int hdr_only = 0;
10416
10417 if (filter & IPW_PROM_NO_TX)
10418 return;
10419
10420 memset(&dummystats, 0, sizeof(dummystats));
10421
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010422 /* Filtering of fragment chains is done against the first fragment */
Zhu Yid685b8c2006-04-13 17:20:27 +080010423 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010424 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010425 if (filter & IPW_PROM_NO_MGMT)
10426 return;
10427 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10428 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010429 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010430 if (filter & IPW_PROM_NO_CTL)
10431 return;
10432 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10433 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010434 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010435 if (filter & IPW_PROM_NO_DATA)
10436 return;
10437 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10438 hdr_only = 1;
10439 }
10440
10441 for(n=0; n<txb->nr_frags; ++n) {
10442 struct sk_buff *src = txb->fragments[n];
10443 struct sk_buff *dst;
10444 struct ieee80211_radiotap_header *rt_hdr;
10445 int len;
10446
10447 if (hdr_only) {
10448 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010449 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010450 } else
10451 len = src->len;
10452
Johannes Berg007e5dd2008-11-27 23:13:38 +010010453 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10454 if (!dst)
10455 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010456
10457 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10458
10459 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10460 rt_hdr->it_pad = 0;
10461 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010462 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010463
Al Viroe62e1ee2007-12-27 01:36:46 -050010464 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010465 ieee80211chan2mhz(priv->channel));
10466 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010467 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010468 cpu_to_le16(IEEE80211_CHAN_OFDM |
10469 IEEE80211_CHAN_5GHZ);
10470 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010471 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010472 cpu_to_le16(IEEE80211_CHAN_CCK |
10473 IEEE80211_CHAN_2GHZ);
10474 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010475 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010476 cpu_to_le16(IEEE80211_CHAN_OFDM |
10477 IEEE80211_CHAN_2GHZ);
10478
Al Viro743b84d2007-12-27 01:43:16 -050010479 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010480
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010481 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010482
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010483 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010484 dev_kfree_skb_any(dst);
10485 }
10486}
10487#endif
10488
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010489static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10490 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010491{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010492 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010493 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010494 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010495
10496 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010497 spin_lock_irqsave(&priv->lock, flags);
10498
Zhu Yid685b8c2006-04-13 17:20:27 +080010499#ifdef CONFIG_IPW2200_PROMISCUOUS
10500 if (rtap_iface && netif_running(priv->prom_net_dev))
10501 ipw_handle_promiscuous_tx(priv, txb);
10502#endif
10503
James Ketrenos227d2dc2005-07-28 16:25:55 -050010504 ret = ipw_tx_skb(priv, txb, pri);
10505 if (ret == NETDEV_TX_OK)
10506 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010507 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010508
James Ketrenos227d2dc2005-07-28 16:25:55 -050010509 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010510}
10511
James Ketrenos43f66a62005-03-25 12:31:53 -060010512static void ipw_net_set_multicast_list(struct net_device *dev)
10513{
10514
10515}
10516
10517static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10518{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010519 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010520 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010521
James Ketrenos43f66a62005-03-25 12:31:53 -060010522 if (!is_valid_ether_addr(addr->sa_data))
10523 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010524 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010525 priv->config |= CFG_CUSTOM_MAC;
10526 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010527 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10528 priv->net_dev->name, priv->mac_addr);
Tejun Heobcb6d912011-01-26 12:12:50 +010010529 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010530 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010531 return 0;
10532}
10533
Jeff Garzikbf794512005-07-31 13:07:26 -040010534static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010535 struct ethtool_drvinfo *info)
10536{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010537 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010538 char vers[64];
10539 char date[32];
10540 u32 len;
10541
10542 strcpy(info->driver, DRV_NAME);
10543 strcpy(info->version, DRV_VERSION);
10544
10545 len = sizeof(vers);
10546 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10547 len = sizeof(date);
10548 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10549
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010550 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010551 vers, date);
10552 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010553 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010554}
10555
10556static u32 ipw_ethtool_get_link(struct net_device *dev)
10557{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010558 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010559 return (priv->status & STATUS_ASSOCIATED) != 0;
10560}
10561
10562static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10563{
James Ketrenosb095c382005-08-24 22:04:42 -050010564 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010565}
10566
10567static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010568 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010569{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010570 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010571
James Ketrenosb095c382005-08-24 22:04:42 -050010572 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010573 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010574 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010575 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010576 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010577 return 0;
10578}
10579
10580static int ipw_ethtool_set_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 int i;
10585
James Ketrenosb095c382005-08-24 22:04:42 -050010586 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010587 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010588 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010589 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010590 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10591 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010592 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010593 return 0;
10594}
10595
Jeff Garzik7282d492006-09-13 14:30:00 -040010596static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010597 .get_link = ipw_ethtool_get_link,
10598 .get_drvinfo = ipw_ethtool_get_drvinfo,
10599 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10600 .get_eeprom = ipw_ethtool_get_eeprom,
10601 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010602};
10603
David Howells7d12e782006-10-05 14:55:46 +010010604static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010605{
10606 struct ipw_priv *priv = data;
10607 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010608
James Ketrenos43f66a62005-03-25 12:31:53 -060010609 if (!priv)
10610 return IRQ_NONE;
10611
Zhu Yi89c318e2006-06-08 22:19:49 -070010612 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010613
10614 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010615 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010616 goto none;
10617 }
10618
James Ketrenosb095c382005-08-24 22:04:42 -050010619 inta = ipw_read32(priv, IPW_INTA_RW);
10620 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010621
James Ketrenos43f66a62005-03-25 12:31:53 -060010622 if (inta == 0xFFFFFFFF) {
10623 /* Hardware disappeared */
10624 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10625 goto none;
10626 }
10627
James Ketrenosb095c382005-08-24 22:04:42 -050010628 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010629 /* Shared interrupt */
10630 goto none;
10631 }
10632
10633 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010634 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010635
James Ketrenos43f66a62005-03-25 12:31:53 -060010636 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010637 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10638 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010639
James Ketrenos43f66a62005-03-25 12:31:53 -060010640 /* Cache INTA value for our tasklet */
10641 priv->isr_inta = inta;
10642
10643 tasklet_schedule(&priv->irq_tasklet);
10644
Zhu Yi89c318e2006-06-08 22:19:49 -070010645 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010646
10647 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010648 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010649 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010650 return IRQ_NONE;
10651}
10652
10653static void ipw_rf_kill(void *adapter)
10654{
10655 struct ipw_priv *priv = adapter;
10656 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010657
James Ketrenos43f66a62005-03-25 12:31:53 -060010658 spin_lock_irqsave(&priv->lock, flags);
10659
10660 if (rf_kill_active(priv)) {
10661 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010010662 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010663 goto exit_unlock;
10664 }
10665
10666 /* RF Kill is now disabled, so bring the device back up */
10667
10668 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10669 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10670 "device\n");
10671
10672 /* we can not do an adapter restart while inside an irq lock */
Tejun Heobcb6d912011-01-26 12:12:50 +010010673 schedule_work(&priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010674 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010675 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10676 "enabled\n");
10677
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010678 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010679 spin_unlock_irqrestore(&priv->lock, flags);
10680}
10681
David Howellsc4028952006-11-22 14:57:56 +000010682static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010683{
David Howellsc4028952006-11-22 14:57:56 +000010684 struct ipw_priv *priv =
10685 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010686 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010687 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010688 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010689}
10690
Adrian Bunka73e22b2006-01-21 01:39:42 +010010691static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010692{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010693 priv->last_seq_num = -1;
10694 priv->last_frag_num = -1;
10695 priv->last_packet_time = 0;
10696
James Ketrenosa613bff2005-08-24 21:43:11 -050010697 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010698
James Ketrenosc848d0a2005-08-24 21:56:24 -050010699 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010700 cancel_delayed_work(&priv->request_direct_scan);
10701 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010702 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010703 ipw_reset_stats(priv);
10704 /* Ensure the rate is updated immediately */
10705 priv->last_rate = ipw_get_current_rate(priv);
10706 ipw_gather_stats(priv);
10707 ipw_led_link_up(priv);
10708 notify_wx_assoc_event(priv);
10709
10710 if (priv->config & CFG_BACKGROUND_SCAN)
Tejun Heobcb6d912011-01-26 12:12:50 +010010711 schedule_delayed_work(&priv->request_scan, HZ);
James Ketrenosa613bff2005-08-24 21:43:11 -050010712}
10713
David Howellsc4028952006-11-22 14:57:56 +000010714static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010715{
David Howellsc4028952006-11-22 14:57:56 +000010716 struct ipw_priv *priv =
10717 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010718 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010719 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010720 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010721}
10722
Adrian Bunka73e22b2006-01-21 01:39:42 +010010723static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010724{
10725 ipw_led_link_down(priv);
10726 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010727 notify_wx_assoc_event(priv);
10728
10729 /* Cancel any queued work ... */
10730 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010731 cancel_delayed_work(&priv->request_direct_scan);
10732 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010733 cancel_delayed_work(&priv->adhoc_check);
10734 cancel_delayed_work(&priv->gather_stats);
10735
10736 ipw_reset_stats(priv);
10737
James Ketrenosafbf30a2005-08-25 00:05:33 -050010738 if (!(priv->status & STATUS_EXIT_PENDING)) {
10739 /* Queue up another scan... */
Tejun Heobcb6d912011-01-26 12:12:50 +010010740 schedule_delayed_work(&priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010741 } else
10742 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010743}
10744
David Howellsc4028952006-11-22 14:57:56 +000010745static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010746{
David Howellsc4028952006-11-22 14:57:56 +000010747 struct ipw_priv *priv =
10748 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010749 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010750 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010751 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010752}
10753
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010754static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010755{
10756 int ret = 0;
10757
James Ketrenos43f66a62005-03-25 12:31:53 -060010758 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010759 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010760
David Howellsc4028952006-11-22 14:57:56 +000010761 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10762 INIT_WORK(&priv->associate, ipw_bg_associate);
10763 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10764 INIT_WORK(&priv->system_config, ipw_system_config);
10765 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10766 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10767 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10768 INIT_WORK(&priv->up, ipw_bg_up);
10769 INIT_WORK(&priv->down, ipw_bg_down);
10770 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010771 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10772 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010773 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010774 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10775 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10776 INIT_WORK(&priv->roam, ipw_bg_roam);
10777 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10778 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10779 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10780 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10781 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10782 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10783 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010784
Zhu Yie43e3c12006-04-13 17:20:45 +080010785#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010786 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010787#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010788
10789 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10790 ipw_irq_tasklet, (unsigned long)priv);
10791
10792 return ret;
10793}
10794
James Ketrenos43f66a62005-03-25 12:31:53 -060010795static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010796 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010797{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010798 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010799 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010800 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010801 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010802 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010803 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010804 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010805 priv->ieee->sec.flags &= ~(1 << i);
10806 else {
10807 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010808 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010809 priv->ieee->sec.flags |= (1 << i);
10810 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010811 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010812 } else if (sec->level != SEC_LEVEL_1)
10813 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010814 }
10815
James Ketrenosb095c382005-08-24 22:04:42 -050010816 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010818 priv->ieee->sec.active_key = sec->active_key;
10819 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010820 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010821 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010822 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010823 } else
10824 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010825
10826 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010827 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10828 priv->ieee->sec.auth_mode = sec->auth_mode;
10829 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010830 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10831 priv->capability |= CAP_SHARED_KEY;
10832 else
10833 priv->capability &= ~CAP_SHARED_KEY;
10834 priv->status |= STATUS_SECURITY_UPDATED;
10835 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010836
James Ketrenosb095c382005-08-24 22:04:42 -050010837 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10838 priv->ieee->sec.flags |= SEC_ENABLED;
10839 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010840 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010841 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010842 priv->capability |= CAP_PRIVACY_ON;
10843 else
10844 priv->capability &= ~CAP_PRIVACY_ON;
10845 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010846
James Ketrenosafbf30a2005-08-25 00:05:33 -050010847 if (sec->flags & SEC_ENCRYPT)
10848 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010849
James Ketrenosb095c382005-08-24 22:04:42 -050010850 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10851 priv->ieee->sec.level = sec->level;
10852 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010853 priv->status |= STATUS_SECURITY_UPDATED;
10854 }
10855
Zhu Yi1fbfea52005-08-05 17:22:56 +080010856 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10857 ipw_set_hwcrypto_keys(priv);
10858
Jeff Garzikbf794512005-07-31 13:07:26 -040010859 /* To match current functionality of ipw2100 (which works well w/
10860 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010861 * privacy capability changes ... */
10862#if 0
10863 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010864 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010865 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010866 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010867 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010868 IPW_DEBUG_ASSOC("Disassociating due to capability "
10869 "change.\n");
10870 ipw_disassociate(priv);
10871 }
10872#endif
10873}
10874
Jeff Garzikbf794512005-07-31 13:07:26 -040010875static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010876 struct ipw_supported_rates *rates)
10877{
10878 /* TODO: Mask out rates based on priv->rates_mask */
10879
10880 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010881 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010882 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010883 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010884 rates->ieee_mode = IPW_A_MODE;
10885 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010886 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10887 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010888 break;
10889
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010890 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010891 rates->ieee_mode = IPW_G_MODE;
10892 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010893 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10894 LIBIPW_CCK_DEFAULT_RATES_MASK);
10895 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10896 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10897 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010898 }
10899 break;
10900 }
10901
10902 return 0;
10903}
10904
Jeff Garzikbf794512005-07-31 13:07:26 -040010905static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010906{
James Ketrenos43f66a62005-03-25 12:31:53 -060010907 /* This is only called from ipw_up, which resets/reloads the firmware
10908 so, we don't need to first disable the card before we configure
10909 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010910 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010911 goto error;
10912
10913 /* initialize adapter address */
10914 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10915 goto error;
10916
10917 /* set basic system config settings */
10918 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010919
10920 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10921 * Does not support BT priority yet (don't abort or defer our Tx) */
10922 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010923 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010924
10925 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10926 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010927 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010928 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10929 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010930 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010931 }
10932
Zhu Yid685b8c2006-04-13 17:20:27 +080010933#ifdef CONFIG_IPW2200_PROMISCUOUS
10934 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10935 priv->sys_config.accept_all_data_frames = 1;
10936 priv->sys_config.accept_non_directed_frames = 1;
10937 priv->sys_config.accept_all_mgmt_bcpr = 1;
10938 priv->sys_config.accept_all_mgmt_frames = 1;
10939 }
10940#endif
10941
James Ketrenosc848d0a2005-08-24 21:56:24 -050010942 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10943 priv->sys_config.answer_broadcast_ssid_probe = 1;
10944 else
10945 priv->sys_config.answer_broadcast_ssid_probe = 0;
10946
Zhu Yid685b8c2006-04-13 17:20:27 +080010947 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010948 goto error;
10949
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010950 init_supported_rates(priv, &priv->rates);
10951 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010952 goto error;
10953
10954 /* Set request-to-send threshold */
10955 if (priv->rts_threshold) {
10956 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10957 goto error;
10958 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010959#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010960 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10961 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010962#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010963
10964 if (ipw_set_random_seed(priv))
10965 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010966
James Ketrenos43f66a62005-03-25 12:31:53 -060010967 /* final state transition to the RUN state */
10968 if (ipw_send_host_complete(priv))
10969 goto error;
10970
James Ketrenose6666192005-08-12 09:17:04 -050010971 priv->status |= STATUS_INIT;
10972
10973 ipw_led_init(priv);
10974 ipw_led_radio_on(priv);
10975 priv->notif_missed_beacons = 0;
10976
10977 /* Set hardware WEP key if it is configured. */
10978 if ((priv->capability & CAP_PRIVACY_ON) &&
10979 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10980 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10981 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010982
10983 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010984
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010985 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010986 return -EIO;
10987}
10988
James Ketrenos4f36f802005-08-03 20:36:56 -050010989/*
10990 * NOTE:
10991 *
10992 * These tables have been tested in conjunction with the
10993 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10994 *
10995 * Altering this values, using it on other hardware, or in geographies
10996 * not intended for resale of the above mentioned Intel adapters has
10997 * not been tested.
10998 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010999 * Remember to update the table in README.ipw2200 when changing this
11000 * table.
11001 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011002 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011003static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011004 { /* Restricted */
11005 "---",
11006 .bg_channels = 11,
11007 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11008 {2427, 4}, {2432, 5}, {2437, 6},
11009 {2442, 7}, {2447, 8}, {2452, 9},
11010 {2457, 10}, {2462, 11}},
11011 },
11012
11013 { /* Custom US/Canada */
11014 "ZZF",
11015 .bg_channels = 11,
11016 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11017 {2427, 4}, {2432, 5}, {2437, 6},
11018 {2442, 7}, {2447, 8}, {2452, 9},
11019 {2457, 10}, {2462, 11}},
11020 .a_channels = 8,
11021 .a = {{5180, 36},
11022 {5200, 40},
11023 {5220, 44},
11024 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011025 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11026 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11027 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11028 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011029 },
11030
11031 { /* Rest of World */
11032 "ZZD",
11033 .bg_channels = 13,
11034 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11035 {2427, 4}, {2432, 5}, {2437, 6},
11036 {2442, 7}, {2447, 8}, {2452, 9},
11037 {2457, 10}, {2462, 11}, {2467, 12},
11038 {2472, 13}},
11039 },
11040
11041 { /* Custom USA & Europe & High */
11042 "ZZA",
11043 .bg_channels = 11,
11044 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11}},
11048 .a_channels = 13,
11049 .a = {{5180, 36},
11050 {5200, 40},
11051 {5220, 44},
11052 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011053 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11054 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11055 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11056 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011057 {5745, 149},
11058 {5765, 153},
11059 {5785, 157},
11060 {5805, 161},
11061 {5825, 165}},
11062 },
11063
11064 { /* Custom NA & Europe */
11065 "ZZB",
11066 .bg_channels = 11,
11067 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11068 {2427, 4}, {2432, 5}, {2437, 6},
11069 {2442, 7}, {2447, 8}, {2452, 9},
11070 {2457, 10}, {2462, 11}},
11071 .a_channels = 13,
11072 .a = {{5180, 36},
11073 {5200, 40},
11074 {5220, 44},
11075 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011076 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11077 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11078 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11079 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11080 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11081 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11082 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11083 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11084 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011085 },
11086
11087 { /* Custom Japan */
11088 "ZZC",
11089 .bg_channels = 11,
11090 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11091 {2427, 4}, {2432, 5}, {2437, 6},
11092 {2442, 7}, {2447, 8}, {2452, 9},
11093 {2457, 10}, {2462, 11}},
11094 .a_channels = 4,
11095 .a = {{5170, 34}, {5190, 38},
11096 {5210, 42}, {5230, 46}},
11097 },
11098
11099 { /* Custom */
11100 "ZZM",
11101 .bg_channels = 11,
11102 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11103 {2427, 4}, {2432, 5}, {2437, 6},
11104 {2442, 7}, {2447, 8}, {2452, 9},
11105 {2457, 10}, {2462, 11}},
11106 },
11107
11108 { /* Europe */
11109 "ZZE",
11110 .bg_channels = 13,
11111 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11112 {2427, 4}, {2432, 5}, {2437, 6},
11113 {2442, 7}, {2447, 8}, {2452, 9},
11114 {2457, 10}, {2462, 11}, {2467, 12},
11115 {2472, 13}},
11116 .a_channels = 19,
11117 .a = {{5180, 36},
11118 {5200, 40},
11119 {5220, 44},
11120 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011121 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11122 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11123 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11124 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11125 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11126 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11127 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11128 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11129 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11130 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11131 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11132 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11133 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11134 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11135 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011136 },
11137
11138 { /* Custom Japan */
11139 "ZZJ",
11140 .bg_channels = 14,
11141 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11142 {2427, 4}, {2432, 5}, {2437, 6},
11143 {2442, 7}, {2447, 8}, {2452, 9},
11144 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011145 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011146 .a_channels = 4,
11147 .a = {{5170, 34}, {5190, 38},
11148 {5210, 42}, {5230, 46}},
11149 },
11150
James Ketrenos03520572005-10-19 16:12:31 -050011151 { /* Rest of World */
11152 "ZZR",
11153 .bg_channels = 14,
11154 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11155 {2427, 4}, {2432, 5}, {2437, 6},
11156 {2442, 7}, {2447, 8}, {2452, 9},
11157 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011158 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11159 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011160 },
11161
James Ketrenos4f36f802005-08-03 20:36:56 -050011162 { /* High Band */
11163 "ZZH",
11164 .bg_channels = 13,
11165 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11166 {2427, 4}, {2432, 5}, {2437, 6},
11167 {2442, 7}, {2447, 8}, {2452, 9},
11168 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011169 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11170 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011171 .a_channels = 4,
11172 .a = {{5745, 149}, {5765, 153},
11173 {5785, 157}, {5805, 161}},
11174 },
11175
11176 { /* Custom Europe */
11177 "ZZG",
11178 .bg_channels = 13,
11179 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11180 {2427, 4}, {2432, 5}, {2437, 6},
11181 {2442, 7}, {2447, 8}, {2452, 9},
11182 {2457, 10}, {2462, 11},
11183 {2467, 12}, {2472, 13}},
11184 .a_channels = 4,
11185 .a = {{5180, 36}, {5200, 40},
11186 {5220, 44}, {5240, 48}},
11187 },
11188
11189 { /* Europe */
11190 "ZZK",
11191 .bg_channels = 13,
11192 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11193 {2427, 4}, {2432, 5}, {2437, 6},
11194 {2442, 7}, {2447, 8}, {2452, 9},
11195 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011196 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11197 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011198 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011199 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11200 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11201 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11202 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11203 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11204 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11205 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11206 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11207 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11208 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11209 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11210 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11211 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11212 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11213 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11214 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11215 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11216 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11217 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11218 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11219 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11220 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11221 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11222 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011223 },
11224
11225 { /* Europe */
11226 "ZZL",
11227 .bg_channels = 11,
11228 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11229 {2427, 4}, {2432, 5}, {2437, 6},
11230 {2442, 7}, {2447, 8}, {2452, 9},
11231 {2457, 10}, {2462, 11}},
11232 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011233 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11234 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11235 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11236 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11237 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11238 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11239 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11240 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11241 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11242 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11243 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11244 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11245 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011246 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011247};
11248
James Ketrenos43f66a62005-03-25 12:31:53 -060011249#define MAX_HW_RESTARTS 5
11250static int ipw_up(struct ipw_priv *priv)
11251{
James Ketrenos4f36f802005-08-03 20:36:56 -050011252 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011253
Dan Williamsc3d72b92009-02-11 13:26:06 -050011254 /* Age scan list entries found before suspend */
11255 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011256 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011257 priv->suspend_time = 0;
11258 }
11259
James Ketrenos43f66a62005-03-25 12:31:53 -060011260 if (priv->status & STATUS_EXIT_PENDING)
11261 return -EIO;
11262
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011263 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011264 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011265 GFP_KERNEL);
11266 if (priv->cmdlog == NULL) {
11267 IPW_ERROR("Error allocating %d command log entries.\n",
11268 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011269 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011270 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011271 priv->cmdlog_len = cmdlog;
11272 }
11273 }
11274
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011275 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011276 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011277 * Also start the clocks. */
11278 rc = ipw_load(priv);
11279 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011280 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011281 return rc;
11282 }
11283
11284 ipw_init_ordinals(priv);
11285 if (!(priv->config & CFG_CUSTOM_MAC))
11286 eeprom_parse_mac(priv, priv->mac_addr);
11287 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011288 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011289
James Ketrenos4f36f802005-08-03 20:36:56 -050011290 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11291 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11292 ipw_geos[j].name, 3))
11293 break;
11294 }
James Ketrenos03520572005-10-19 16:12:31 -050011295 if (j == ARRAY_SIZE(ipw_geos)) {
11296 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11297 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11298 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11299 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011300 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011301 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011302 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011303 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011304 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011305 }
11306
James Ketrenosb095c382005-08-24 22:04:42 -050011307 if (priv->status & STATUS_RF_KILL_SW) {
11308 IPW_WARNING("Radio disabled by module parameter.\n");
11309 return 0;
11310 } else if (rf_kill_active(priv)) {
11311 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11312 "Kill switch must be turned off for "
11313 "wireless networking to work.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010011314 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011315 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011316 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011317
11318 rc = ipw_config(priv);
11319 if (!rc) {
11320 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011321
James Ketrenose6666192005-08-12 09:17:04 -050011322 /* If configure to try and auto-associate, kick
11323 * off a scan. */
Tejun Heobcb6d912011-01-26 12:12:50 +010011324 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011325
James Ketrenos43f66a62005-03-25 12:31:53 -060011326 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011327 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011328
James Ketrenosc848d0a2005-08-24 21:56:24 -050011329 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011330 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11331 i, MAX_HW_RESTARTS);
11332
11333 /* We had an error bringing up the hardware, so take it
11334 * all the way back down so we can try again */
11335 ipw_down(priv);
11336 }
11337
Jeff Garzikbf794512005-07-31 13:07:26 -040011338 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011339 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011340 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011341
James Ketrenos43f66a62005-03-25 12:31:53 -060011342 return -EIO;
11343}
11344
David Howellsc4028952006-11-22 14:57:56 +000011345static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011346{
David Howellsc4028952006-11-22 14:57:56 +000011347 struct ipw_priv *priv =
11348 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011349 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011350 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011351 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011352}
11353
James Ketrenosb095c382005-08-24 22:04:42 -050011354static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011355{
James Ketrenosb095c382005-08-24 22:04:42 -050011356 int i;
11357
11358 if (priv->status & STATUS_SCANNING) {
11359 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11360 ipw_abort_scan(priv);
11361 }
11362
11363 if (priv->status & STATUS_ASSOCIATED) {
11364 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11365 ipw_disassociate(priv);
11366 }
11367
11368 ipw_led_shutdown(priv);
11369
11370 /* Wait up to 1s for status to change to not scanning and not
11371 * associated (disassociation can take a while for a ful 802.11
11372 * exchange */
11373 for (i = 1000; i && (priv->status &
11374 (STATUS_DISASSOCIATING |
11375 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11376 udelay(10);
11377
11378 if (priv->status & (STATUS_DISASSOCIATING |
11379 STATUS_ASSOCIATED | STATUS_SCANNING))
11380 IPW_DEBUG_INFO("Still associated or scanning...\n");
11381 else
11382 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11383
James Ketrenosc848d0a2005-08-24 21:56:24 -050011384 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011385 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011386
11387 priv->status &= ~STATUS_INIT;
11388}
11389
James Ketrenos43f66a62005-03-25 12:31:53 -060011390static void ipw_down(struct ipw_priv *priv)
11391{
James Ketrenosb095c382005-08-24 22:04:42 -050011392 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11393
11394 priv->status |= STATUS_EXIT_PENDING;
11395
11396 if (ipw_is_init(priv))
11397 ipw_deinit(priv);
11398
11399 /* Wipe out the EXIT_PENDING status bit if we are not actually
11400 * exiting the module */
11401 if (!exit_pending)
11402 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011403
11404 /* tell the device to stop sending interrupts */
11405 ipw_disable_interrupts(priv);
11406
11407 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011408 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011409 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011410
11411 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011412
11413 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011414}
11415
David Howellsc4028952006-11-22 14:57:56 +000011416static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011417{
David Howellsc4028952006-11-22 14:57:56 +000011418 struct ipw_priv *priv =
11419 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011420 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011421 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011422 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011423}
11424
11425/* Called by register_netdev() */
11426static int ipw_net_init(struct net_device *dev)
11427{
John W. Linvillea3caa992009-08-25 14:12:25 -040011428 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011429 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011430 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11431 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011432 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011433
James Ketrenosc848d0a2005-08-24 21:56:24 -050011434 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011435 rc = -EIO;
11436 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011437 }
11438
John W. Linvillea3caa992009-08-25 14:12:25 -040011439 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11440
11441 /* fill-out priv->ieee->bg_band */
11442 if (geo->bg_channels) {
11443 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11444
11445 bg_band->band = IEEE80211_BAND_2GHZ;
11446 bg_band->n_channels = geo->bg_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011447 bg_band->channels = kcalloc(geo->bg_channels,
11448 sizeof(struct ieee80211_channel),
11449 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011450 if (!bg_band->channels) {
11451 rc = -ENOMEM;
11452 goto out;
11453 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011454 /* translate geo->bg to bg_band.channels */
11455 for (i = 0; i < geo->bg_channels; i++) {
11456 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11457 bg_band->channels[i].center_freq = geo->bg[i].freq;
11458 bg_band->channels[i].hw_value = geo->bg[i].channel;
11459 bg_band->channels[i].max_power = geo->bg[i].max_power;
11460 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11461 bg_band->channels[i].flags |=
11462 IEEE80211_CHAN_PASSIVE_SCAN;
11463 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11464 bg_band->channels[i].flags |=
11465 IEEE80211_CHAN_NO_IBSS;
11466 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11467 bg_band->channels[i].flags |=
11468 IEEE80211_CHAN_RADAR;
11469 /* No equivalent for LIBIPW_CH_80211H_RULES,
11470 LIBIPW_CH_UNIFORM_SPREADING, or
11471 LIBIPW_CH_B_ONLY... */
11472 }
11473 /* point at bitrate info */
11474 bg_band->bitrates = ipw2200_bg_rates;
11475 bg_band->n_bitrates = ipw2200_num_bg_rates;
11476
11477 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11478 }
11479
11480 /* fill-out priv->ieee->a_band */
11481 if (geo->a_channels) {
11482 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11483
11484 a_band->band = IEEE80211_BAND_5GHZ;
11485 a_band->n_channels = geo->a_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011486 a_band->channels = kcalloc(geo->a_channels,
11487 sizeof(struct ieee80211_channel),
11488 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011489 if (!a_band->channels) {
11490 rc = -ENOMEM;
11491 goto out;
11492 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011493 /* translate geo->bg to a_band.channels */
11494 for (i = 0; i < geo->a_channels; i++) {
11495 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11496 a_band->channels[i].center_freq = geo->a[i].freq;
11497 a_band->channels[i].hw_value = geo->a[i].channel;
11498 a_band->channels[i].max_power = geo->a[i].max_power;
11499 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11500 a_band->channels[i].flags |=
11501 IEEE80211_CHAN_PASSIVE_SCAN;
11502 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11503 a_band->channels[i].flags |=
11504 IEEE80211_CHAN_NO_IBSS;
11505 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11506 a_band->channels[i].flags |=
11507 IEEE80211_CHAN_RADAR;
11508 /* No equivalent for LIBIPW_CH_80211H_RULES,
11509 LIBIPW_CH_UNIFORM_SPREADING, or
11510 LIBIPW_CH_B_ONLY... */
11511 }
11512 /* point at bitrate info */
11513 a_band->bitrates = ipw2200_a_rates;
11514 a_band->n_bitrates = ipw2200_num_a_rates;
11515
11516 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11517 }
11518
11519 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11520
11521 /* With that information in place, we can now register the wiphy... */
11522 if (wiphy_register(wdev->wiphy)) {
11523 rc = -EIO;
11524 goto out;
11525 }
11526
11527out:
Zhu Yi46441512006-01-24 16:37:59 +080011528 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011529 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011530}
11531
11532/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011533static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011534 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11535 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11536 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11537 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11538 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11539 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11540 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11541 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11542 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11543 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11544 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11545 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011551 {PCI_VDEVICE(INTEL, 0x104f), 0},
11552 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11553 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11554 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11555 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011556
James Ketrenos43f66a62005-03-25 12:31:53 -060011557 /* required last entry */
11558 {0,}
11559};
11560
11561MODULE_DEVICE_TABLE(pci, card_ids);
11562
11563static struct attribute *ipw_sysfs_entries[] = {
11564 &dev_attr_rf_kill.attr,
11565 &dev_attr_direct_dword.attr,
11566 &dev_attr_indirect_byte.attr,
11567 &dev_attr_indirect_dword.attr,
11568 &dev_attr_mem_gpio_reg.attr,
11569 &dev_attr_command_event_reg.attr,
11570 &dev_attr_nic_type.attr,
11571 &dev_attr_status.attr,
11572 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011573 &dev_attr_error.attr,
11574 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011575 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011576 &dev_attr_eeprom_delay.attr,
11577 &dev_attr_ucode_version.attr,
11578 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011579 &dev_attr_scan_age.attr,
11580 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011581 &dev_attr_speed_scan.attr,
11582 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011583 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011584#ifdef CONFIG_IPW2200_PROMISCUOUS
11585 &dev_attr_rtap_iface.attr,
11586 &dev_attr_rtap_filter.attr,
11587#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011588 NULL
11589};
11590
11591static struct attribute_group ipw_attribute_group = {
11592 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011593 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011594};
11595
Zhu Yid685b8c2006-04-13 17:20:27 +080011596#ifdef CONFIG_IPW2200_PROMISCUOUS
11597static int ipw_prom_open(struct net_device *dev)
11598{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011599 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011600 struct ipw_priv *priv = prom_priv->priv;
11601
11602 IPW_DEBUG_INFO("prom dev->open\n");
11603 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011604
11605 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11606 priv->sys_config.accept_all_data_frames = 1;
11607 priv->sys_config.accept_non_directed_frames = 1;
11608 priv->sys_config.accept_all_mgmt_bcpr = 1;
11609 priv->sys_config.accept_all_mgmt_frames = 1;
11610
11611 ipw_send_system_config(priv);
11612 }
11613
11614 return 0;
11615}
11616
11617static int ipw_prom_stop(struct net_device *dev)
11618{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011619 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011620 struct ipw_priv *priv = prom_priv->priv;
11621
11622 IPW_DEBUG_INFO("prom dev->stop\n");
11623
11624 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11625 priv->sys_config.accept_all_data_frames = 0;
11626 priv->sys_config.accept_non_directed_frames = 0;
11627 priv->sys_config.accept_all_mgmt_bcpr = 0;
11628 priv->sys_config.accept_all_mgmt_frames = 0;
11629
11630 ipw_send_system_config(priv);
11631 }
11632
11633 return 0;
11634}
11635
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011636static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11637 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011638{
11639 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011640 dev_kfree_skb(skb);
11641 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011642}
11643
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011644static const struct net_device_ops ipw_prom_netdev_ops = {
11645 .ndo_open = ipw_prom_open,
11646 .ndo_stop = ipw_prom_stop,
11647 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011648 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011649 .ndo_set_mac_address = eth_mac_addr,
11650 .ndo_validate_addr = eth_validate_addr,
11651};
11652
Zhu Yid685b8c2006-04-13 17:20:27 +080011653static int ipw_prom_alloc(struct ipw_priv *priv)
11654{
11655 int rc = 0;
11656
11657 if (priv->prom_net_dev)
11658 return -EPERM;
11659
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011660 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011661 if (priv->prom_net_dev == NULL)
11662 return -ENOMEM;
11663
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011664 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011665 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11666 priv->prom_priv->priv = priv;
11667
11668 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011669 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011670
11671 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011672 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011673
11674 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011675 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011676
11677 rc = register_netdev(priv->prom_net_dev);
11678 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011679 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011680 priv->prom_net_dev = NULL;
11681 return rc;
11682 }
11683
11684 return 0;
11685}
11686
11687static void ipw_prom_free(struct ipw_priv *priv)
11688{
11689 if (!priv->prom_net_dev)
11690 return;
11691
11692 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011693 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011694
11695 priv->prom_net_dev = NULL;
11696}
11697
11698#endif
11699
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011700static const struct net_device_ops ipw_netdev_ops = {
11701 .ndo_init = ipw_net_init,
11702 .ndo_open = ipw_net_open,
11703 .ndo_stop = ipw_net_stop,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000011704 .ndo_set_rx_mode = ipw_net_set_multicast_list,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011705 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011706 .ndo_start_xmit = libipw_xmit,
11707 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011708 .ndo_validate_addr = eth_validate_addr,
11709};
Zhu Yid685b8c2006-04-13 17:20:27 +080011710
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011711static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11712 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011713{
11714 int err = 0;
11715 struct net_device *net_dev;
11716 void __iomem *base;
11717 u32 length, val;
11718 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011719 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011720
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011721 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011722 if (net_dev == NULL) {
11723 err = -ENOMEM;
11724 goto out;
11725 }
11726
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011727 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011728 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011729
James Ketrenos43f66a62005-03-25 12:31:53 -060011730 priv->net_dev = net_dev;
11731 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011732 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011733 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011734 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011735 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11736 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011737
Zhu Yi46441512006-01-24 16:37:59 +080011738 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011739 if (pci_enable_device(pdev)) {
11740 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011741 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011742 }
11743
11744 pci_set_master(pdev);
11745
Yang Hongyang284901a2009-04-06 19:01:15 -070011746 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011747 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011748 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011749 if (err) {
11750 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11751 goto out_pci_disable_device;
11752 }
11753
11754 pci_set_drvdata(pdev, priv);
11755
11756 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011757 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011758 goto out_pci_disable_device;
11759
Jeff Garzikbf794512005-07-31 13:07:26 -040011760 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011761 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011762 pci_read_config_dword(pdev, 0x40, &val);
11763 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011764 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011765
James Ketrenos43f66a62005-03-25 12:31:53 -060011766 length = pci_resource_len(pdev, 0);
11767 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011768
Arjan van de Ven275f1652008-10-20 21:42:39 -070011769 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011770 if (!base) {
11771 err = -ENODEV;
11772 goto out_pci_release_regions;
11773 }
11774
11775 priv->hw_base = base;
11776 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11777 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11778
11779 err = ipw_setup_deferred_work(priv);
11780 if (err) {
11781 IPW_ERROR("Unable to setup deferred work\n");
11782 goto out_iounmap;
11783 }
11784
James Ketrenosb095c382005-08-24 22:04:42 -050011785 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011786
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011787 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011788 if (err) {
11789 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
Tejun Heobcb6d912011-01-26 12:12:50 +010011790 goto out_iounmap;
James Ketrenos43f66a62005-03-25 12:31:53 -060011791 }
11792
James Ketrenos43f66a62005-03-25 12:31:53 -060011793 SET_NETDEV_DEV(net_dev, &pdev->dev);
11794
Zhu Yi46441512006-01-24 16:37:59 +080011795 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011796
James Ketrenos43f66a62005-03-25 12:31:53 -060011797 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11798 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011799 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011800
Zhu Yie43e3c12006-04-13 17:20:45 +080011801#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011802 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011803 priv->ieee->handle_probe_response = ipw_handle_beacon;
11804 priv->ieee->handle_beacon = ipw_handle_probe_response;
11805 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011806#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011807
James Ketrenosc848d0a2005-08-24 21:56:24 -050011808 priv->ieee->perfect_rssi = -20;
11809 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011810
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011811 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011812 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011813 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011814 net_dev->wireless_handlers = &ipw_wx_handler_def;
11815 net_dev->ethtool_ops = &ipw_ethtool_ops;
11816 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011817 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011818 net_dev->mem_start = pci_resource_start(pdev, 0);
11819 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11820
11821 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11822 if (err) {
11823 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011824 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011825 goto out_release_irq;
11826 }
11827
Zhu Yi46441512006-01-24 16:37:59 +080011828 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011829 err = register_netdev(net_dev);
11830 if (err) {
11831 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011832 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011833 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011834
Zhu Yid685b8c2006-04-13 17:20:27 +080011835#ifdef CONFIG_IPW2200_PROMISCUOUS
11836 if (rtap_iface) {
11837 err = ipw_prom_alloc(priv);
11838 if (err) {
11839 IPW_ERROR("Failed to register promiscuous network "
11840 "device (error %d).\n", err);
11841 unregister_netdev(priv->net_dev);
11842 goto out_remove_sysfs;
11843 }
11844 }
11845#endif
11846
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011847 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11848 "channels, %d 802.11a channels)\n",
11849 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11850 priv->ieee->geo.a_channels);
11851
James Ketrenos43f66a62005-03-25 12:31:53 -060011852 return 0;
11853
James Ketrenosa613bff2005-08-24 21:43:11 -050011854 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011855 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011856 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011857 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011858 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011859 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011860 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011861 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011862 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011863 pci_disable_device(pdev);
11864 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011865 out_free_libipw:
11866 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011867 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011868 return err;
11869}
11870
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011871static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011872{
11873 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011874 struct list_head *p, *q;
11875 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011876
James Ketrenos43f66a62005-03-25 12:31:53 -060011877 if (!priv)
11878 return;
11879
Zhu Yi46441512006-01-24 16:37:59 +080011880 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011881
James Ketrenosafbf30a2005-08-25 00:05:33 -050011882 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011883 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011884 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11885
Zhu Yi46441512006-01-24 16:37:59 +080011886 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011887
11888 unregister_netdev(priv->net_dev);
11889
11890 if (priv->rxq) {
11891 ipw_rx_queue_free(priv, priv->rxq);
11892 priv->rxq = NULL;
11893 }
11894 ipw_tx_queue_free(priv);
11895
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011896 if (priv->cmdlog) {
11897 kfree(priv->cmdlog);
11898 priv->cmdlog = NULL;
11899 }
Tejun Heobcb6d912011-01-26 12:12:50 +010011900
11901 /* make sure all works are inactive */
11902 cancel_delayed_work_sync(&priv->adhoc_check);
11903 cancel_work_sync(&priv->associate);
11904 cancel_work_sync(&priv->disassociate);
11905 cancel_work_sync(&priv->system_config);
11906 cancel_work_sync(&priv->rx_replenish);
11907 cancel_work_sync(&priv->adapter_restart);
11908 cancel_delayed_work_sync(&priv->rf_kill);
11909 cancel_work_sync(&priv->up);
11910 cancel_work_sync(&priv->down);
11911 cancel_delayed_work_sync(&priv->request_scan);
11912 cancel_delayed_work_sync(&priv->request_direct_scan);
11913 cancel_delayed_work_sync(&priv->request_passive_scan);
11914 cancel_delayed_work_sync(&priv->scan_event);
11915 cancel_delayed_work_sync(&priv->gather_stats);
11916 cancel_work_sync(&priv->abort_scan);
11917 cancel_work_sync(&priv->roam);
11918 cancel_delayed_work_sync(&priv->scan_check);
11919 cancel_work_sync(&priv->link_up);
11920 cancel_work_sync(&priv->link_down);
11921 cancel_delayed_work_sync(&priv->led_link_on);
11922 cancel_delayed_work_sync(&priv->led_link_off);
11923 cancel_delayed_work_sync(&priv->led_act_off);
11924 cancel_work_sync(&priv->merge_networks);
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);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011946 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011947 wiphy_unregister(priv->ieee->wdev.wiphy);
11948 kfree(priv->ieee->a_band.channels);
11949 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011950 free_libipw(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 */
Tejun Heobcb6d912011-01-26 12:12:50 +010012012 schedule_work(&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);
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000012080MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
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);