blob: 4395977d536969c208ab148957b04eaf3441369e [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>
Johannes Berg262eb9b22011-07-13 10:39:09 +020035#include <net/cfg80211-wext.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060036#include "ipw2200.h"
37
Zhu Yiae4af612006-04-13 17:20:34 +080038
39#ifndef KBUILD_EXTMOD
40#define VK "k"
41#else
42#define VK
43#endif
44
45#ifdef CONFIG_IPW2200_DEBUG
46#define VD "d"
47#else
48#define VD
49#endif
50
51#ifdef CONFIG_IPW2200_MONITOR
52#define VM "m"
53#else
54#define VM
55#endif
56
57#ifdef CONFIG_IPW2200_PROMISCUOUS
58#define VP "p"
59#else
60#define VP
61#endif
62
Zhu Yi459d4082006-04-13 17:21:00 +080063#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080064#define VR "r"
65#else
66#define VR
67#endif
68
69#ifdef CONFIG_IPW2200_QOS
70#define VQ "q"
71#else
72#define VQ
73#endif
74
Zhu Yiee2c4ad2007-07-12 16:09:47 +080075#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060076#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080077#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060078#define DRV_VERSION IPW2200_VERSION
79
James Ketrenosb095c382005-08-24 22:04:42 -050080#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
81
James Ketrenos43f66a62005-03-25 12:31:53 -060082MODULE_DESCRIPTION(DRV_DESCRIPTION);
83MODULE_VERSION(DRV_VERSION);
84MODULE_AUTHOR(DRV_COPYRIGHT);
85MODULE_LICENSE("GPL");
Ben Hutchings873395a2009-11-07 21:59:10 +000086MODULE_FIRMWARE("ipw2200-ibss.fw");
87#ifdef CONFIG_IPW2200_MONITOR
88MODULE_FIRMWARE("ipw2200-sniffer.fw");
89#endif
90MODULE_FIRMWARE("ipw2200-bss.fw");
James Ketrenos43f66a62005-03-25 12:31:53 -060091
James Ketrenosf6c5cb72005-08-25 00:39:09 -050092static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060093static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070094static int default_channel = 0;
95static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060096
97static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060098static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060099static int auto_create = 1;
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +0000100static int led_support = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600101static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +0800102static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +0800103static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +0800104static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600105static const char ipw_modes[] = {
106 'a', 'b', 'g', '?'
107};
Zhu Yid2b83e12006-04-13 17:19:36 +0800108static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600109
Zhu Yid685b8c2006-04-13 17:20:27 +0800110#ifdef CONFIG_IPW2200_PROMISCUOUS
111static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
112#endif
113
John W. Linvillea3caa992009-08-25 14:12:25 -0400114static struct ieee80211_rate ipw2200_rates[] = {
115 { .bitrate = 10 },
116 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
117 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
118 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
119 { .bitrate = 60 },
120 { .bitrate = 90 },
121 { .bitrate = 120 },
122 { .bitrate = 180 },
123 { .bitrate = 240 },
124 { .bitrate = 360 },
125 { .bitrate = 480 },
126 { .bitrate = 540 }
127};
128
129#define ipw2200_a_rates (ipw2200_rates + 4)
130#define ipw2200_num_a_rates 8
131#define ipw2200_bg_rates (ipw2200_rates + 0)
132#define ipw2200_num_bg_rates 12
Zhu Yid685b8c2006-04-13 17:20:27 +0800133
Zhu Yie43e3c12006-04-13 17:20:45 +0800134#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500135static int qos_enable = 0;
136static int qos_burst_enable = 0;
137static int qos_no_ack_mask = 0;
138static int burst_duration_CCK = 0;
139static int burst_duration_OFDM = 0;
140
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400141static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500142 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
143 QOS_TX3_CW_MIN_OFDM},
144 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
145 QOS_TX3_CW_MAX_OFDM},
146 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
147 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
148 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
149 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
150};
151
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400152static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500153 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
154 QOS_TX3_CW_MIN_CCK},
155 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
156 QOS_TX3_CW_MAX_CCK},
157 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
158 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
159 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
160 QOS_TX3_TXOP_LIMIT_CCK}
161};
162
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400163static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500164 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
165 DEF_TX3_CW_MIN_OFDM},
166 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
167 DEF_TX3_CW_MAX_OFDM},
168 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
169 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
170 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
171 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
172};
173
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400174static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500175 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
176 DEF_TX3_CW_MIN_CCK},
177 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
178 DEF_TX3_CW_MAX_CCK},
179 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
180 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
181 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
182 DEF_TX3_TXOP_LIMIT_CCK}
183};
184
185static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
186
187static int from_priority_to_tx_queue[] = {
188 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
189 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
190};
191
192static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
193
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400194static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500195 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400196static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500197 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800198#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500199
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000200static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500201static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600202static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400203static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600204 struct clx2_tx_queue *txq, int qindex);
205static int ipw_queue_reset(struct ipw_priv *priv);
206
207static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
208 int len, int sync);
209
210static void ipw_tx_queue_free(struct ipw_priv *);
211
212static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
213static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
214static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600215static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000216static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600217static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000218static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600219static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400220static int init_supported_rates(struct ipw_priv *priv,
221 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500222static void ipw_set_hwcrypto_keys(struct ipw_priv *);
223static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600224
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500225static int snprint_line(char *buf, size_t count,
226 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600227{
228 int out, i, j, l;
229 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400230
James Ketrenos43f66a62005-03-25 12:31:53 -0600231 out = snprintf(buf, count, "%08X", ofs);
232
233 for (l = 0, i = 0; i < 2; i++) {
234 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400235 for (j = 0; j < 8 && l < len; j++, l++)
236 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600237 data[(i * 8 + j)]);
238 for (; j < 8; j++)
239 out += snprintf(buf + out, count - out, " ");
240 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400241
James Ketrenos43f66a62005-03-25 12:31:53 -0600242 out += snprintf(buf + out, count - out, " ");
243 for (l = 0, i = 0; i < 2; i++) {
244 out += snprintf(buf + out, count - out, " ");
245 for (j = 0; j < 8 && l < len; j++, l++) {
246 c = data[(i * 8 + j)];
247 if (!isascii(c) || !isprint(c))
248 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400249
James Ketrenos43f66a62005-03-25 12:31:53 -0600250 out += snprintf(buf + out, count - out, "%c", c);
251 }
252
253 for (; j < 8; j++)
254 out += snprintf(buf + out, count - out, " ");
255 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400256
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500257 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600258}
259
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400260static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600261{
262 char line[81];
263 u32 ofs = 0;
264 if (!(ipw_debug_level & level))
265 return;
266
267 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500268 snprint_line(line, sizeof(line), &data[ofs],
269 min(len, 16U), ofs);
270 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600271 ofs += 16;
272 len -= min(len, 16U);
273 }
274}
275
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500276static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
277{
278 size_t out = size;
279 u32 ofs = 0;
280 int total = 0;
281
282 while (size && len) {
283 out = snprint_line(output, size, &data[ofs],
284 min_t(size_t, len, 16U), ofs);
285
286 ofs += 16;
287 output += out;
288 size -= out;
289 len -= min_t(size_t, len, 16U);
290 total += out;
291 }
292 return total;
293}
294
Zhu Yic8fe6672006-01-24 16:36:36 +0800295/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600296static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
297#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
298
Zhu Yic8fe6672006-01-24 16:36:36 +0800299/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600300static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
301#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
302
Zhu Yic8fe6672006-01-24 16:36:36 +0800303/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600304static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
305static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
306{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400307 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
308 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600309 _ipw_write_reg8(a, b, c);
310}
311
Zhu Yic8fe6672006-01-24 16:36:36 +0800312/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600313static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
314static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
315{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400316 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
317 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600318 _ipw_write_reg16(a, b, c);
319}
320
Zhu Yic8fe6672006-01-24 16:36:36 +0800321/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600322static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
323static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
324{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400325 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
326 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600327 _ipw_write_reg32(a, b, c);
328}
329
Zhu Yic8fe6672006-01-24 16:36:36 +0800330/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100331static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
332 u8 val)
333{
334 writeb(val, ipw->hw_base + ofs);
335}
Zhu Yic8fe6672006-01-24 16:36:36 +0800336
337/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200338#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100339 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
340 __LINE__, (u32)(ofs), (u32)(val)); \
341 _ipw_write8(ipw, ofs, val); \
342} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600343
Zhu Yic8fe6672006-01-24 16:36:36 +0800344/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100345static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
346 u16 val)
347{
348 writew(val, ipw->hw_base + ofs);
349}
Zhu Yic8fe6672006-01-24 16:36:36 +0800350
351/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100352#define ipw_write16(ipw, ofs, val) do { \
353 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
354 __LINE__, (u32)(ofs), (u32)(val)); \
355 _ipw_write16(ipw, ofs, val); \
356} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600357
Zhu Yic8fe6672006-01-24 16:36:36 +0800358/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100359static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
360 u32 val)
361{
362 writel(val, ipw->hw_base + ofs);
363}
Zhu Yic8fe6672006-01-24 16:36:36 +0800364
365/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100366#define ipw_write32(ipw, ofs, val) do { \
367 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
368 __LINE__, (u32)(ofs), (u32)(val)); \
369 _ipw_write32(ipw, ofs, val); \
370} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600371
Zhu Yic8fe6672006-01-24 16:36:36 +0800372/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100373static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400374{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100375 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600376}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400377
Zhu Yic8fe6672006-01-24 16:36:36 +0800378/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100379#define ipw_read8(ipw, ofs) ({ \
380 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
381 (u32)(ofs)); \
382 _ipw_read8(ipw, ofs); \
383})
James Ketrenos43f66a62005-03-25 12:31:53 -0600384
Zhu Yic8fe6672006-01-24 16:36:36 +0800385/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100386static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400387{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100388 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600389}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400390
Zhu Yic8fe6672006-01-24 16:36:36 +0800391/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100392#define ipw_read16(ipw, ofs) ({ \
393 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
394 (u32)(ofs)); \
395 _ipw_read16(ipw, ofs); \
396})
James Ketrenos43f66a62005-03-25 12:31:53 -0600397
Zhu Yic8fe6672006-01-24 16:36:36 +0800398/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100399static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400400{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100401 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600402}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400403
Zhu Yic8fe6672006-01-24 16:36:36 +0800404/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100405#define ipw_read32(ipw, ofs) ({ \
406 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
407 (u32)(ofs)); \
408 _ipw_read32(ipw, ofs); \
409})
James Ketrenos43f66a62005-03-25 12:31:53 -0600410
411static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800412/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100413#define ipw_read_indirect(a, b, c, d) ({ \
414 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
415 __LINE__, (u32)(b), (u32)(d)); \
416 _ipw_read_indirect(a, b, c, d); \
417})
James Ketrenos43f66a62005-03-25 12:31:53 -0600418
Zhu Yic8fe6672006-01-24 16:36:36 +0800419/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400420static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
421 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100422#define ipw_write_indirect(a, b, c, d) do { \
423 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
424 __LINE__, (u32)(b), (u32)(d)); \
425 _ipw_write_indirect(a, b, c, d); \
426} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600427
Zhu Yic8fe6672006-01-24 16:36:36 +0800428/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400429static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600430{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400431 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500432 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
433 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600434}
435
Zhu Yic8fe6672006-01-24 16:36:36 +0800436/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600437static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
438{
Zhu Yi2638bc32006-01-24 16:37:52 +0800439 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800440 u32 dif_len = reg - aligned_addr;
441
James Ketrenos43f66a62005-03-25 12:31:53 -0600442 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800443 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
444 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600445}
446
Zhu Yic8fe6672006-01-24 16:36:36 +0800447/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400448static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600449{
Zhu Yi2638bc32006-01-24 16:37:52 +0800450 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800451 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
452
James Ketrenos43f66a62005-03-25 12:31:53 -0600453 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800454 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
455 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600456}
457
Zhu Yic8fe6672006-01-24 16:36:36 +0800458/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600459static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
460{
461 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500462 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100463 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500464 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400465 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600466}
467
Zhu Yic8fe6672006-01-24 16:36:36 +0800468/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600469static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
470{
471 u32 value;
472
473 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
474
James Ketrenosb095c382005-08-24 22:04:42 -0500475 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
476 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100477 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600478 return value;
479}
480
Zhu Yic8fe6672006-01-24 16:36:36 +0800481/* General purpose, no alignment requirement, iterative (multi-byte) read, */
482/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600483static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
484 int num)
485{
Zhu Yi2638bc32006-01-24 16:37:52 +0800486 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600488 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400489
James Ketrenos43f66a62005-03-25 12:31:53 -0600490 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
491
James Ketrenosea2b26e2005-08-24 21:25:16 -0500492 if (num <= 0) {
493 return;
494 }
495
Zhu Yic8fe6672006-01-24 16:36:36 +0800496 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600497 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500498 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600499 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500500 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500501 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600502 aligned_addr += 4;
503 }
504
Zhu Yic8fe6672006-01-24 16:36:36 +0800505 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500506 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500507 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500508 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400509
Zhu Yic8fe6672006-01-24 16:36:36 +0800510 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500511 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500512 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500513 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500514 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500515 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600516}
517
Zhu Yic8fe6672006-01-24 16:36:36 +0800518/* General purpose, no alignment requirement, iterative (multi-byte) write, */
519/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400520static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600521 int num)
522{
Zhu Yi2638bc32006-01-24 16:37:52 +0800523 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600525 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400526
James Ketrenos43f66a62005-03-25 12:31:53 -0600527 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400528
James Ketrenosea2b26e2005-08-24 21:25:16 -0500529 if (num <= 0) {
530 return;
531 }
532
Zhu Yic8fe6672006-01-24 16:36:36 +0800533 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600534 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500535 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800536 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500537 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500538 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600539 aligned_addr += 4;
540 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400541
Zhu Yic8fe6672006-01-24 16:36:36 +0800542 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500543 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500544 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500545 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400546
Zhu Yic8fe6672006-01-24 16:36:36 +0800547 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500548 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500549 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500550 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500551 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500552 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600553}
554
Zhu Yic8fe6672006-01-24 16:36:36 +0800555/* General purpose, no alignment requirement, iterative (multi-byte) write, */
556/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400557static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600558 int num)
559{
560 memcpy_toio((priv->hw_base + addr), buf, num);
561}
562
Zhu Yic8fe6672006-01-24 16:36:36 +0800563/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600564static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
565{
566 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
567}
568
Zhu Yic8fe6672006-01-24 16:36:36 +0800569/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600570static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
571{
572 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
573}
574
Zhu Yi89c318e2006-06-08 22:19:49 -0700575static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600576{
577 if (priv->status & STATUS_INT_ENABLED)
578 return;
579 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500580 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600581}
582
Zhu Yi89c318e2006-06-08 22:19:49 -0700583static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600584{
585 if (!(priv->status & STATUS_INT_ENABLED))
586 return;
587 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500588 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600589}
590
Zhu Yi89c318e2006-06-08 22:19:49 -0700591static inline void ipw_enable_interrupts(struct ipw_priv *priv)
592{
593 unsigned long flags;
594
595 spin_lock_irqsave(&priv->irq_lock, flags);
596 __ipw_enable_interrupts(priv);
597 spin_unlock_irqrestore(&priv->irq_lock, flags);
598}
599
600static inline void ipw_disable_interrupts(struct ipw_priv *priv)
601{
602 unsigned long flags;
603
604 spin_lock_irqsave(&priv->irq_lock, flags);
605 __ipw_disable_interrupts(priv);
606 spin_unlock_irqrestore(&priv->irq_lock, flags);
607}
608
James Ketrenos43f66a62005-03-25 12:31:53 -0600609static char *ipw_error_desc(u32 val)
610{
611 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400612 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600613 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400614 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600615 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400616 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600617 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400618 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600619 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400620 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500621 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400622 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500623 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400624 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500625 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400626 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500627 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400628 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500629 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400630 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500631 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400632 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500633 return "DMA_STATUS";
634 case IPW_FW_ERROR_DINO_ERROR:
635 return "DINO_ERROR";
636 case IPW_FW_ERROR_EEPROM_ERROR:
637 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400638 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500639 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400640 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500641 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400642 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500643 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600644 }
645}
646
James Ketrenosb39860c2005-08-12 09:36:32 -0500647static void ipw_dump_error_log(struct ipw_priv *priv,
648 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600649{
James Ketrenosb39860c2005-08-12 09:36:32 -0500650 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600651
James Ketrenosb39860c2005-08-12 09:36:32 -0500652 if (!error) {
653 IPW_ERROR("Error allocating and capturing error log. "
654 "Nothing to dump.\n");
655 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600656 }
657
James Ketrenosb39860c2005-08-12 09:36:32 -0500658 IPW_ERROR("Start IPW Error Log Dump:\n");
659 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
660 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600661
James Ketrenosb39860c2005-08-12 09:36:32 -0500662 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400663 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500664 ipw_error_desc(error->elem[i].desc),
665 error->elem[i].time,
666 error->elem[i].blink1,
667 error->elem[i].blink2,
668 error->elem[i].link1,
669 error->elem[i].link2, error->elem[i].data);
670 for (i = 0; i < error->log_len; i++)
671 IPW_ERROR("%i\t0x%08x\t%i\n",
672 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500673 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600674}
James Ketrenos43f66a62005-03-25 12:31:53 -0600675
James Ketrenosc848d0a2005-08-24 21:56:24 -0500676static inline int ipw_is_init(struct ipw_priv *priv)
677{
678 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600679}
680
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400681static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600682{
683 u32 addr, field_info, field_len, field_count, total_len;
684
685 IPW_DEBUG_ORD("ordinal = %i\n", ord);
686
687 if (!priv || !val || !len) {
688 IPW_DEBUG_ORD("Invalid argument\n");
689 return -EINVAL;
690 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400691
James Ketrenos43f66a62005-03-25 12:31:53 -0600692 /* verify device ordinal tables have been initialized */
693 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
694 IPW_DEBUG_ORD("Access ordinals before initialization\n");
695 return -EINVAL;
696 }
697
698 switch (IPW_ORD_TABLE_ID_MASK & ord) {
699 case IPW_ORD_TABLE_0_MASK:
700 /*
701 * TABLE 0: Direct access to a table of 32 bit values
702 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400703 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600704 * read from the table
705 */
706
707 /* remove the table id from the ordinal */
708 ord &= IPW_ORD_TABLE_VALUE_MASK;
709
710 /* boundary check */
711 if (ord > priv->table0_len) {
712 IPW_DEBUG_ORD("ordinal value (%i) longer then "
713 "max (%i)\n", ord, priv->table0_len);
714 return -EINVAL;
715 }
716
717 /* verify we have enough room to store the value */
718 if (*len < sizeof(u32)) {
719 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200720 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600721 return -EINVAL;
722 }
723
724 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400725 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600726
727 *len = sizeof(u32);
728 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400729 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600730 break;
731
732 case IPW_ORD_TABLE_1_MASK:
733 /*
734 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400735 *
736 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600737 * representing starting addr for the data (which is
738 * also a u32)
739 */
740
741 /* remove the table id from the ordinal */
742 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400743
James Ketrenos43f66a62005-03-25 12:31:53 -0600744 /* boundary check */
745 if (ord > priv->table1_len) {
746 IPW_DEBUG_ORD("ordinal value too long\n");
747 return -EINVAL;
748 }
749
750 /* verify we have enough room to store the value */
751 if (*len < sizeof(u32)) {
752 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200753 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600754 return -EINVAL;
755 }
756
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400757 *((u32 *) val) =
758 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600759 *len = sizeof(u32);
760 break;
761
762 case IPW_ORD_TABLE_2_MASK:
763 /*
764 * TABLE 2: Indirect access to a table of variable sized values
765 *
766 * This table consist of six values, each containing
767 * - dword containing the starting offset of the data
768 * - dword containing the lengh in the first 16bits
769 * and the count in the second 16bits
770 */
771
772 /* remove the table id from the ordinal */
773 ord &= IPW_ORD_TABLE_VALUE_MASK;
774
775 /* boundary check */
776 if (ord > priv->table2_len) {
777 IPW_DEBUG_ORD("ordinal value too long\n");
778 return -EINVAL;
779 }
780
781 /* get the address of statistic */
782 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400783
784 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600785 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400786 field_info =
787 ipw_read_reg32(priv,
788 priv->table2_addr + (ord << 3) +
789 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400790
James Ketrenos43f66a62005-03-25 12:31:53 -0600791 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400792 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400793
James Ketrenos43f66a62005-03-25 12:31:53 -0600794 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400795 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400796
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200797 /* abort if not enough memory */
James Ketrenos43f66a62005-03-25 12:31:53 -0600798 total_len = field_len * field_count;
799 if (total_len > *len) {
800 *len = total_len;
801 return -EINVAL;
802 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400803
James Ketrenos43f66a62005-03-25 12:31:53 -0600804 *len = total_len;
805 if (!total_len)
806 return 0;
807
808 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400809 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600810 addr, total_len, field_info);
811 ipw_read_indirect(priv, addr, val, total_len);
812 break;
813
814 default:
815 IPW_DEBUG_ORD("Invalid ordinal!\n");
816 return -EINVAL;
817
818 }
819
James Ketrenos43f66a62005-03-25 12:31:53 -0600820 return 0;
821}
822
823static void ipw_init_ordinals(struct ipw_priv *priv)
824{
825 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400826 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600827
828 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
829 priv->table0_addr, priv->table0_len);
830
831 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
832 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
833
834 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
835 priv->table1_addr, priv->table1_len);
836
837 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
838 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400839 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600840
841 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
842 priv->table2_addr, priv->table2_len);
843
844}
845
Adrian Bunka73e22b2006-01-21 01:39:42 +0100846static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500847{
James Ketrenosb095c382005-08-24 22:04:42 -0500848 reg &= ~IPW_START_STANDBY;
849 if (reg & IPW_GATE_ODMA)
850 reg &= ~IPW_GATE_ODMA;
851 if (reg & IPW_GATE_IDMA)
852 reg &= ~IPW_GATE_IDMA;
853 if (reg & IPW_GATE_ADMA)
854 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500855 return reg;
856}
857
858/*
859 * LED behavior:
860 * - On radio ON, turn on any LEDs that require to be on during start
861 * - On initialization, start unassociated blink
862 * - On association, disable unassociated blink
863 * - On disassociation, start unassociated blink
864 * - On radio OFF, turn off any LEDs started during radio on
865 *
866 */
Zhu Yiede61112006-01-24 16:37:10 +0800867#define LD_TIME_LINK_ON msecs_to_jiffies(300)
868#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
869#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500870
Adrian Bunka73e22b2006-01-21 01:39:42 +0100871static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500872{
873 unsigned long flags;
874 u32 led;
875
876 /* If configured to not use LEDs, or nic_type is 1,
877 * then we don't toggle a LINK led */
878 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
879 return;
880
881 spin_lock_irqsave(&priv->lock, flags);
882
883 if (!(priv->status & STATUS_RF_KILL_MASK) &&
884 !(priv->status & STATUS_LED_LINK_ON)) {
885 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500886 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500887 led |= priv->led_association_on;
888
889 led = ipw_register_toggle(led);
890
891 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500892 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500893
894 priv->status |= STATUS_LED_LINK_ON;
895
896 /* If we aren't associated, schedule turning the LED off */
897 if (!(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100898 schedule_delayed_work(&priv->led_link_off,
899 LD_TIME_LINK_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500900 }
901
902 spin_unlock_irqrestore(&priv->lock, flags);
903}
904
David Howellsc4028952006-11-22 14:57:56 +0000905static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500906{
David Howellsc4028952006-11-22 14:57:56 +0000907 struct ipw_priv *priv =
908 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800909 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000910 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800911 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500912}
913
Adrian Bunka73e22b2006-01-21 01:39:42 +0100914static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500915{
916 unsigned long flags;
917 u32 led;
918
919 /* If configured not to use LEDs, or nic type is 1,
920 * then we don't goggle the LINK led. */
921 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
922 return;
923
924 spin_lock_irqsave(&priv->lock, flags);
925
926 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500927 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500928 led &= priv->led_association_off;
929 led = ipw_register_toggle(led);
930
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500932 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933
934 IPW_DEBUG_LED("Link LED Off\n");
935
936 priv->status &= ~STATUS_LED_LINK_ON;
937
938 /* If we aren't associated and the radio is on, schedule
939 * turning the LED on (blink while unassociated) */
940 if (!(priv->status & STATUS_RF_KILL_MASK) &&
941 !(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100942 schedule_delayed_work(&priv->led_link_on,
943 LD_TIME_LINK_OFF);
James Ketrenosa613bff2005-08-24 21:43:11 -0500944
945 }
946
947 spin_unlock_irqrestore(&priv->lock, flags);
948}
949
David Howellsc4028952006-11-22 14:57:56 +0000950static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500951{
David Howellsc4028952006-11-22 14:57:56 +0000952 struct ipw_priv *priv =
953 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800954 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000955 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800956 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500957}
958
Arjan van de Ven858119e2006-01-14 13:20:43 -0800959static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500960{
James Ketrenosa613bff2005-08-24 21:43:11 -0500961 u32 led;
962
963 if (priv->config & CFG_NO_LED)
964 return;
965
James Ketrenosb095c382005-08-24 22:04:42 -0500966 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500967 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500968
969 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500970 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500971 led |= priv->led_activity_on;
972
973 led = ipw_register_toggle(led);
974
975 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500976 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500977
978 IPW_DEBUG_LED("Activity LED On\n");
979
980 priv->status |= STATUS_LED_ACT_ON;
981
James Ketrenosc848d0a2005-08-24 21:56:24 -0500982 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100983 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500984 } else {
985 /* Reschedule LED off for full time period */
986 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100987 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500988 }
James Ketrenosb095c382005-08-24 22:04:42 -0500989}
James Ketrenosa613bff2005-08-24 21:43:11 -0500990
Adrian Bunka73e22b2006-01-21 01:39:42 +0100991#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500992void ipw_led_activity_on(struct ipw_priv *priv)
993{
994 unsigned long flags;
995 spin_lock_irqsave(&priv->lock, flags);
996 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500997 spin_unlock_irqrestore(&priv->lock, flags);
998}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100999#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -05001000
Adrian Bunka73e22b2006-01-21 01:39:42 +01001001static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001002{
1003 unsigned long flags;
1004 u32 led;
1005
1006 if (priv->config & CFG_NO_LED)
1007 return;
1008
1009 spin_lock_irqsave(&priv->lock, flags);
1010
1011 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001013 led &= priv->led_activity_off;
1014
1015 led = ipw_register_toggle(led);
1016
1017 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001018 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001019
1020 IPW_DEBUG_LED("Activity LED Off\n");
1021
1022 priv->status &= ~STATUS_LED_ACT_ON;
1023 }
1024
1025 spin_unlock_irqrestore(&priv->lock, flags);
1026}
1027
David Howellsc4028952006-11-22 14:57:56 +00001028static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001029{
David Howellsc4028952006-11-22 14:57:56 +00001030 struct ipw_priv *priv =
1031 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001032 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001033 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001034 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001035}
1036
Adrian Bunka73e22b2006-01-21 01:39:42 +01001037static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001038{
1039 unsigned long flags;
1040 u32 led;
1041
1042 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001043 if (priv->config & CFG_NO_LED ||
1044 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001045 return;
1046
1047 spin_lock_irqsave(&priv->lock, flags);
1048
James Ketrenosb095c382005-08-24 22:04:42 -05001049 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001050 if (priv->assoc_network->mode == IEEE_A) {
1051 led |= priv->led_ofdm_on;
1052 led &= priv->led_association_off;
1053 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1054 } else if (priv->assoc_network->mode == IEEE_G) {
1055 led |= priv->led_ofdm_on;
1056 led |= priv->led_association_on;
1057 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1058 } else {
1059 led &= priv->led_ofdm_off;
1060 led |= priv->led_association_on;
1061 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1062 }
1063
1064 led = ipw_register_toggle(led);
1065
1066 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001067 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001068
1069 spin_unlock_irqrestore(&priv->lock, flags);
1070}
1071
Adrian Bunka73e22b2006-01-21 01:39:42 +01001072static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001073{
1074 unsigned long flags;
1075 u32 led;
1076
1077 /* Only nic type 1 supports mode LEDs */
1078 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1079 return;
1080
1081 spin_lock_irqsave(&priv->lock, flags);
1082
James Ketrenosb095c382005-08-24 22:04:42 -05001083 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001084 led &= priv->led_ofdm_off;
1085 led &= priv->led_association_off;
1086
1087 led = ipw_register_toggle(led);
1088
1089 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001090 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001091
1092 spin_unlock_irqrestore(&priv->lock, flags);
1093}
1094
Adrian Bunka73e22b2006-01-21 01:39:42 +01001095static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001096{
1097 ipw_led_link_on(priv);
1098}
1099
Adrian Bunka73e22b2006-01-21 01:39:42 +01001100static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001101{
1102 ipw_led_activity_off(priv);
1103 ipw_led_link_off(priv);
1104}
1105
Adrian Bunka73e22b2006-01-21 01:39:42 +01001106static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001107{
1108 /* Set the Link Led on for all nic types */
1109 ipw_led_link_on(priv);
1110}
1111
Adrian Bunka73e22b2006-01-21 01:39:42 +01001112static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001113{
1114 ipw_led_activity_off(priv);
1115 ipw_led_link_off(priv);
1116
1117 if (priv->status & STATUS_RF_KILL_MASK)
1118 ipw_led_radio_off(priv);
1119}
1120
Adrian Bunka73e22b2006-01-21 01:39:42 +01001121static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001122{
1123 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1124
1125 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001126 priv->led_activity_on = IPW_ACTIVITY_LED;
1127 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001128
James Ketrenosb095c382005-08-24 22:04:42 -05001129 priv->led_association_on = IPW_ASSOCIATED_LED;
1130 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001131
1132 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001133 priv->led_ofdm_on = IPW_OFDM_LED;
1134 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001135
1136 switch (priv->nic_type) {
1137 case EEPROM_NIC_TYPE_1:
1138 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001139 priv->led_activity_on = IPW_ASSOCIATED_LED;
1140 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1141 priv->led_association_on = IPW_ACTIVITY_LED;
1142 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001143
1144 if (!(priv->config & CFG_NO_LED))
1145 ipw_led_band_on(priv);
1146
1147 /* And we don't blink link LEDs for this nic, so
1148 * just return here */
1149 return;
1150
1151 case EEPROM_NIC_TYPE_3:
1152 case EEPROM_NIC_TYPE_2:
1153 case EEPROM_NIC_TYPE_4:
1154 case EEPROM_NIC_TYPE_0:
1155 break;
1156
1157 default:
1158 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1159 priv->nic_type);
1160 priv->nic_type = EEPROM_NIC_TYPE_0;
1161 break;
1162 }
1163
1164 if (!(priv->config & CFG_NO_LED)) {
1165 if (priv->status & STATUS_ASSOCIATED)
1166 ipw_led_link_on(priv);
1167 else
1168 ipw_led_link_off(priv);
1169 }
1170}
1171
Adrian Bunka73e22b2006-01-21 01:39:42 +01001172static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001173{
James Ketrenosa613bff2005-08-24 21:43:11 -05001174 ipw_led_activity_off(priv);
1175 ipw_led_link_off(priv);
1176 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001177 cancel_delayed_work(&priv->led_link_on);
1178 cancel_delayed_work(&priv->led_link_off);
1179 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001180}
1181
James Ketrenos43f66a62005-03-25 12:31:53 -06001182/*
1183 * The following adds a new attribute to the sysfs representation
1184 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001185 * used for controlling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001186 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001187 * See the level definitions in ipw for details.
1188 */
1189static ssize_t show_debug_level(struct device_driver *d, char *buf)
1190{
1191 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1192}
James Ketrenosa613bff2005-08-24 21:43:11 -05001193
1194static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1195 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001196{
1197 char *p = (char *)buf;
1198 u32 val;
1199
1200 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1201 p++;
1202 if (p[0] == 'x' || p[0] == 'X')
1203 p++;
1204 val = simple_strtoul(p, &p, 16);
1205 } else
1206 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001207 if (p == buf)
1208 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001209 ": %s is not in hex or decimal form.\n", buf);
1210 else
1211 ipw_debug_level = val;
1212
1213 return strnlen(buf, count);
1214}
1215
Jeff Garzikbf794512005-07-31 13:07:26 -04001216static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001217 show_debug_level, store_debug_level);
1218
James Ketrenosb39860c2005-08-12 09:36:32 -05001219static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1220{
Zhu Yic8fe6672006-01-24 16:36:36 +08001221 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001222 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1223}
1224
1225static void ipw_capture_event_log(struct ipw_priv *priv,
1226 u32 log_len, struct ipw_event *log)
1227{
1228 u32 base;
1229
1230 if (log_len) {
1231 base = ipw_read32(priv, IPW_EVENT_LOG);
1232 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1233 (u8 *) log, sizeof(*log) * log_len);
1234 }
1235}
1236
1237static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1238{
1239 struct ipw_fw_error *error;
1240 u32 log_len = ipw_get_event_log_len(priv);
1241 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1242 u32 elem_len = ipw_read_reg32(priv, base);
1243
1244 error = kmalloc(sizeof(*error) +
1245 sizeof(*error->elem) * elem_len +
1246 sizeof(*error->log) * log_len, GFP_ATOMIC);
1247 if (!error) {
1248 IPW_ERROR("Memory allocation for firmware error log "
1249 "failed.\n");
1250 return NULL;
1251 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001252 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001253 error->status = priv->status;
1254 error->config = priv->config;
1255 error->elem_len = elem_len;
1256 error->log_len = log_len;
1257 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001258 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001259
1260 ipw_capture_event_log(priv, log_len, error->log);
1261
1262 if (elem_len)
1263 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1264 sizeof(*error->elem) * elem_len);
1265
1266 return error;
1267}
1268
James Ketrenosb39860c2005-08-12 09:36:32 -05001269static ssize_t show_event_log(struct device *d,
1270 struct device_attribute *attr, char *buf)
1271{
1272 struct ipw_priv *priv = dev_get_drvdata(d);
1273 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001274 u32 log_size;
1275 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001276 u32 len = 0, i;
1277
Reinette Chatre412e9e72007-12-18 22:01:02 -08001278 /* not using min() because of its strict type checking */
1279 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1280 sizeof(*log) * log_len : PAGE_SIZE;
1281 log = kzalloc(log_size, GFP_KERNEL);
1282 if (!log) {
1283 IPW_ERROR("Unable to allocate memory for log\n");
1284 return 0;
1285 }
1286 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001287 ipw_capture_event_log(priv, log_len, log);
1288
1289 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1290 for (i = 0; i < log_len; i++)
1291 len += snprintf(buf + len, PAGE_SIZE - len,
1292 "\n%08X%08X%08X",
1293 log[i].time, log[i].event, log[i].data);
1294 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001295 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001296 return len;
1297}
1298
1299static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1300
1301static ssize_t show_error(struct device *d,
1302 struct device_attribute *attr, char *buf)
1303{
1304 struct ipw_priv *priv = dev_get_drvdata(d);
1305 u32 len = 0, i;
1306 if (!priv->error)
1307 return 0;
1308 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001309 "%08lX%08X%08X%08X",
1310 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001311 priv->error->status,
1312 priv->error->config, priv->error->elem_len);
1313 for (i = 0; i < priv->error->elem_len; i++)
1314 len += snprintf(buf + len, PAGE_SIZE - len,
1315 "\n%08X%08X%08X%08X%08X%08X%08X",
1316 priv->error->elem[i].time,
1317 priv->error->elem[i].desc,
1318 priv->error->elem[i].blink1,
1319 priv->error->elem[i].blink2,
1320 priv->error->elem[i].link1,
1321 priv->error->elem[i].link2,
1322 priv->error->elem[i].data);
1323
1324 len += snprintf(buf + len, PAGE_SIZE - len,
1325 "\n%08X", priv->error->log_len);
1326 for (i = 0; i < priv->error->log_len; i++)
1327 len += snprintf(buf + len, PAGE_SIZE - len,
1328 "\n%08X%08X%08X",
1329 priv->error->log[i].time,
1330 priv->error->log[i].event,
1331 priv->error->log[i].data);
1332 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1333 return len;
1334}
1335
1336static ssize_t clear_error(struct device *d,
1337 struct device_attribute *attr,
1338 const char *buf, size_t count)
1339{
1340 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001341
1342 kfree(priv->error);
1343 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001344 return count;
1345}
1346
1347static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1348
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001349static ssize_t show_cmd_log(struct device *d,
1350 struct device_attribute *attr, char *buf)
1351{
1352 struct ipw_priv *priv = dev_get_drvdata(d);
1353 u32 len = 0, i;
1354 if (!priv->cmdlog)
1355 return 0;
1356 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1357 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1358 i = (i + 1) % priv->cmdlog_len) {
1359 len +=
1360 snprintf(buf + len, PAGE_SIZE - len,
1361 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1362 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1363 priv->cmdlog[i].cmd.len);
1364 len +=
1365 snprintk_buf(buf + len, PAGE_SIZE - len,
1366 (u8 *) priv->cmdlog[i].cmd.param,
1367 priv->cmdlog[i].cmd.len);
1368 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1369 }
1370 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1371 return len;
1372}
1373
1374static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1375
Zhu Yid685b8c2006-04-13 17:20:27 +08001376#ifdef CONFIG_IPW2200_PROMISCUOUS
1377static void ipw_prom_free(struct ipw_priv *priv);
1378static int ipw_prom_alloc(struct ipw_priv *priv);
1379static ssize_t store_rtap_iface(struct device *d,
1380 struct device_attribute *attr,
1381 const char *buf, size_t count)
1382{
1383 struct ipw_priv *priv = dev_get_drvdata(d);
1384 int rc = 0;
1385
1386 if (count < 1)
1387 return -EINVAL;
1388
1389 switch (buf[0]) {
1390 case '0':
1391 if (!rtap_iface)
1392 return count;
1393
1394 if (netif_running(priv->prom_net_dev)) {
1395 IPW_WARNING("Interface is up. Cannot unregister.\n");
1396 return count;
1397 }
1398
1399 ipw_prom_free(priv);
1400 rtap_iface = 0;
1401 break;
1402
1403 case '1':
1404 if (rtap_iface)
1405 return count;
1406
1407 rc = ipw_prom_alloc(priv);
1408 if (!rc)
1409 rtap_iface = 1;
1410 break;
1411
1412 default:
1413 return -EINVAL;
1414 }
1415
1416 if (rc) {
1417 IPW_ERROR("Failed to register promiscuous network "
1418 "device (error %d).\n", rc);
1419 }
1420
1421 return count;
1422}
1423
1424static ssize_t show_rtap_iface(struct device *d,
1425 struct device_attribute *attr,
1426 char *buf)
1427{
1428 struct ipw_priv *priv = dev_get_drvdata(d);
1429 if (rtap_iface)
1430 return sprintf(buf, "%s", priv->prom_net_dev->name);
1431 else {
1432 buf[0] = '-';
1433 buf[1] = '1';
1434 buf[2] = '\0';
1435 return 3;
1436 }
1437}
1438
1439static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1440 store_rtap_iface);
1441
1442static ssize_t store_rtap_filter(struct device *d,
1443 struct device_attribute *attr,
1444 const char *buf, size_t count)
1445{
1446 struct ipw_priv *priv = dev_get_drvdata(d);
1447
1448 if (!priv->prom_priv) {
1449 IPW_ERROR("Attempting to set filter without "
1450 "rtap_iface enabled.\n");
1451 return -EPERM;
1452 }
1453
1454 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1455
1456 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1457 BIT_ARG16(priv->prom_priv->filter));
1458
1459 return count;
1460}
1461
1462static ssize_t show_rtap_filter(struct device *d,
1463 struct device_attribute *attr,
1464 char *buf)
1465{
1466 struct ipw_priv *priv = dev_get_drvdata(d);
1467 return sprintf(buf, "0x%04X",
1468 priv->prom_priv ? priv->prom_priv->filter : 0);
1469}
1470
1471static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1472 store_rtap_filter);
1473#endif
1474
James Ketrenosa613bff2005-08-24 21:43:11 -05001475static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1476 char *buf)
1477{
1478 struct ipw_priv *priv = dev_get_drvdata(d);
1479 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1480}
1481
1482static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1483 const char *buf, size_t count)
1484{
1485 struct ipw_priv *priv = dev_get_drvdata(d);
1486 struct net_device *dev = priv->net_dev;
1487 char buffer[] = "00000000";
1488 unsigned long len =
1489 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1490 unsigned long val;
1491 char *p = buffer;
1492
1493 IPW_DEBUG_INFO("enter\n");
1494
1495 strncpy(buffer, buf, len);
1496 buffer[len] = 0;
1497
1498 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1499 p++;
1500 if (p[0] == 'x' || p[0] == 'X')
1501 p++;
1502 val = simple_strtoul(p, &p, 16);
1503 } else
1504 val = simple_strtoul(p, &p, 10);
1505 if (p == buffer) {
1506 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1507 } else {
1508 priv->ieee->scan_age = val;
1509 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1510 }
1511
1512 IPW_DEBUG_INFO("exit\n");
1513 return len;
1514}
1515
1516static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1517
1518static ssize_t show_led(struct device *d, struct device_attribute *attr,
1519 char *buf)
1520{
1521 struct ipw_priv *priv = dev_get_drvdata(d);
1522 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1523}
1524
1525static ssize_t store_led(struct device *d, struct device_attribute *attr,
1526 const char *buf, size_t count)
1527{
1528 struct ipw_priv *priv = dev_get_drvdata(d);
1529
1530 IPW_DEBUG_INFO("enter\n");
1531
1532 if (count == 0)
1533 return 0;
1534
1535 if (*buf == 0) {
1536 IPW_DEBUG_LED("Disabling LED control.\n");
1537 priv->config |= CFG_NO_LED;
1538 ipw_led_shutdown(priv);
1539 } else {
1540 IPW_DEBUG_LED("Enabling LED control.\n");
1541 priv->config &= ~CFG_NO_LED;
1542 ipw_led_init(priv);
1543 }
1544
1545 IPW_DEBUG_INFO("exit\n");
1546 return count;
1547}
1548
1549static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1550
Andrew Mortonad3fee52005-06-20 14:30:36 -07001551static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001553{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001554 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001555 return sprintf(buf, "0x%08x\n", (int)p->status);
1556}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557
James Ketrenos43f66a62005-03-25 12:31:53 -06001558static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1559
Andrew Mortonad3fee52005-06-20 14:30:36 -07001560static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1561 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001562{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001563 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001564 return sprintf(buf, "0x%08x\n", (int)p->config);
1565}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001566
James Ketrenos43f66a62005-03-25 12:31:53 -06001567static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1568
Andrew Mortonad3fee52005-06-20 14:30:36 -07001569static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001570 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001571{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001572 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001573 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001574}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575
James Ketrenos43f66a62005-03-25 12:31:53 -06001576static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1577
Andrew Mortonad3fee52005-06-20 14:30:36 -07001578static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001579 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001580{
1581 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001582 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001583
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001584 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001585 return 0;
1586
1587 return sprintf(buf, "0x%08x\n", tmp);
1588}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001589
1590static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001591
Andrew Mortonad3fee52005-06-20 14:30:36 -07001592static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1593 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001594{
1595 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001596 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001597
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001598 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001599 return 0;
1600
1601 return sprintf(buf, "0x%08x\n", tmp);
1602}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001603
1604static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
1606/*
1607 * Add a device attribute to view/control the delay between eeprom
1608 * operations.
1609 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001610static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001611 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001612{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001613 struct ipw_priv *p = dev_get_drvdata(d);
1614 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001615 return sprintf(buf, "%i\n", n);
1616}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001617static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001618 struct device_attribute *attr,
1619 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001620{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001621 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001622 sscanf(buf, "%i", &p->eeprom_delay);
1623 return strnlen(buf, count);
1624}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001625
1626static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1627 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001628
Andrew Mortonad3fee52005-06-20 14:30:36 -07001629static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001630 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001631{
1632 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001633 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001634
James Ketrenosb095c382005-08-24 22:04:42 -05001635 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001636 return sprintf(buf, "0x%08x\n", reg);
1637}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001638static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001639 struct device_attribute *attr,
1640 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001641{
1642 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001643 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001644
1645 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001646 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001647 return strnlen(buf, count);
1648}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001649
1650static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1651 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001652
Andrew Mortonad3fee52005-06-20 14:30:36 -07001653static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001654 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001655{
1656 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001657 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001658
1659 reg = ipw_read_reg32(p, 0x301100);
1660 return sprintf(buf, "0x%08x\n", reg);
1661}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001662static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001663 struct device_attribute *attr,
1664 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001665{
1666 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001667 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001668
1669 sscanf(buf, "%x", &reg);
1670 ipw_write_reg32(p, 0x301100, reg);
1671 return strnlen(buf, count);
1672}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001673
1674static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1675 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001676
Andrew Mortonad3fee52005-06-20 14:30:36 -07001677static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001678 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001679{
1680 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001681 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001682
Jeff Garzikbf794512005-07-31 13:07:26 -04001683 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001684 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001685 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001686 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001687
James Ketrenos43f66a62005-03-25 12:31:53 -06001688 return sprintf(buf, "0x%08x\n", reg);
1689}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001690static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001691 struct device_attribute *attr,
1692 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001693{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001694 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001695
1696 sscanf(buf, "%x", &priv->indirect_dword);
1697 priv->status |= STATUS_INDIRECT_DWORD;
1698 return strnlen(buf, count);
1699}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001700
1701static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1702 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001703
Andrew Mortonad3fee52005-06-20 14:30:36 -07001704static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001705 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001706{
1707 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001708 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001709
Jeff Garzikbf794512005-07-31 13:07:26 -04001710 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001711 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001712 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001713 reg = 0;
1714
1715 return sprintf(buf, "0x%02x\n", reg);
1716}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001717static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001718 struct device_attribute *attr,
1719 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001720{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001721 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001722
1723 sscanf(buf, "%x", &priv->indirect_byte);
1724 priv->status |= STATUS_INDIRECT_BYTE;
1725 return strnlen(buf, count);
1726}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001727
1728static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001729 show_indirect_byte, store_indirect_byte);
1730
Andrew Mortonad3fee52005-06-20 14:30:36 -07001731static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001732 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001733{
1734 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001735 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001736
Jeff Garzikbf794512005-07-31 13:07:26 -04001737 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001738 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001739 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 reg = 0;
1741
1742 return sprintf(buf, "0x%08x\n", reg);
1743}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001744static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001745 struct device_attribute *attr,
1746 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001747{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001748 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001749
1750 sscanf(buf, "%x", &priv->direct_dword);
1751 priv->status |= STATUS_DIRECT_DWORD;
1752 return strnlen(buf, count);
1753}
James Ketrenos43f66a62005-03-25 12:31:53 -06001754
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001755static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1756 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001757
Arjan van de Ven858119e2006-01-14 13:20:43 -08001758static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001759{
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001760 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001761 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001762 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1763 } else {
James Ketrenos43f66a62005-03-25 12:31:53 -06001764 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001765 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1766 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001767
1768 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1769}
1770
Andrew Mortonad3fee52005-06-20 14:30:36 -07001771static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001772 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001773{
1774 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001775 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 2 - HW based RF kill active
1777 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001778 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001779 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001780 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 return sprintf(buf, "%i\n", val);
1782}
1783
1784static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1785{
Jeff Garzikbf794512005-07-31 13:07:26 -04001786 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001787 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001788 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001789
1790 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1791 disable_radio ? "OFF" : "ON");
1792
1793 if (disable_radio) {
1794 priv->status |= STATUS_RF_KILL_SW;
1795
Tejun Heobcb6d912011-01-26 12:12:50 +01001796 cancel_delayed_work(&priv->request_scan);
1797 cancel_delayed_work(&priv->request_direct_scan);
1798 cancel_delayed_work(&priv->request_passive_scan);
1799 cancel_delayed_work(&priv->scan_event);
1800 schedule_work(&priv->down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001801 } else {
1802 priv->status &= ~STATUS_RF_KILL_SW;
1803 if (rf_kill_active(priv)) {
1804 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1805 "disabled by HW switch\n");
1806 /* Make sure the RF_KILL check timer is running */
1807 cancel_delayed_work(&priv->rf_kill);
Tejun Heobcb6d912011-01-26 12:12:50 +01001808 schedule_delayed_work(&priv->rf_kill,
1809 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001810 } else
Tejun Heobcb6d912011-01-26 12:12:50 +01001811 schedule_work(&priv->up);
James Ketrenos43f66a62005-03-25 12:31:53 -06001812 }
1813
1814 return 1;
1815}
1816
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001817static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1818 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001819{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001820 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001821
James Ketrenos43f66a62005-03-25 12:31:53 -06001822 ipw_radio_kill_sw(priv, buf[0] == '1');
1823
1824 return count;
1825}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001826
1827static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001828
James Ketrenosb095c382005-08-24 22:04:42 -05001829static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1830 char *buf)
1831{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001832 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001833 int pos = 0, len = 0;
1834 if (priv->config & CFG_SPEED_SCAN) {
1835 while (priv->speed_scan[pos] != 0)
1836 len += sprintf(&buf[len], "%d ",
1837 priv->speed_scan[pos++]);
1838 return len + sprintf(&buf[len], "\n");
1839 }
1840
1841 return sprintf(buf, "0\n");
1842}
1843
1844static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1845 const char *buf, size_t count)
1846{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001847 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001848 int channel, pos = 0;
1849 const char *p = buf;
1850
1851 /* list of space separated channels to scan, optionally ending with 0 */
1852 while ((channel = simple_strtol(p, NULL, 0))) {
1853 if (pos == MAX_SPEED_SCAN - 1) {
1854 priv->speed_scan[pos] = 0;
1855 break;
1856 }
1857
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001858 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001859 priv->speed_scan[pos++] = channel;
1860 else
1861 IPW_WARNING("Skipping invalid channel request: %d\n",
1862 channel);
1863 p = strchr(p, ' ');
1864 if (!p)
1865 break;
1866 while (*p == ' ' || *p == '\t')
1867 p++;
1868 }
1869
1870 if (pos == 0)
1871 priv->config &= ~CFG_SPEED_SCAN;
1872 else {
1873 priv->speed_scan_pos = 0;
1874 priv->config |= CFG_SPEED_SCAN;
1875 }
1876
1877 return count;
1878}
1879
1880static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1881 store_speed_scan);
1882
1883static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1884 char *buf)
1885{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001886 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001887 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1888}
1889
1890static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1891 const char *buf, size_t count)
1892{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001893 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001894 if (buf[0] == '1')
1895 priv->config |= CFG_NET_STATS;
1896 else
1897 priv->config &= ~CFG_NET_STATS;
1898
1899 return count;
1900}
1901
James Ketrenosafbf30a2005-08-25 00:05:33 -05001902static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1903 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001904
Zhu Yi375dd242007-02-14 16:04:24 +08001905static ssize_t show_channels(struct device *d,
1906 struct device_attribute *attr,
1907 char *buf)
1908{
1909 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001910 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001911 int len = 0, i;
1912
1913 len = sprintf(&buf[len],
1914 "Displaying %d channels in 2.4Ghz band "
1915 "(802.11bg):\n", geo->bg_channels);
1916
1917 for (i = 0; i < geo->bg_channels; i++) {
1918 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1919 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001920 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001921 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001922 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1923 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001924 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001925 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001926 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001927 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001928 "B" : "B/G");
1929 }
1930
1931 len += sprintf(&buf[len],
1932 "Displaying %d channels in 5.2Ghz band "
1933 "(802.11a):\n", geo->a_channels);
1934 for (i = 0; i < geo->a_channels; i++) {
1935 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1936 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001937 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001938 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001939 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1940 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001941 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001942 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001943 "passive only" : "active/passive");
1944 }
1945
1946 return len;
1947}
1948
1949static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1950
James Ketrenosea2b26e2005-08-24 21:25:16 -05001951static void notify_wx_assoc_event(struct ipw_priv *priv)
1952{
1953 union iwreq_data wrqu;
1954 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1955 if (priv->status & STATUS_ASSOCIATED)
1956 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1957 else
1958 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1959 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1960}
1961
James Ketrenos43f66a62005-03-25 12:31:53 -06001962static void ipw_irq_tasklet(struct ipw_priv *priv)
1963{
1964 u32 inta, inta_mask, handled = 0;
1965 unsigned long flags;
1966 int rc = 0;
1967
Zhu Yi89c318e2006-06-08 22:19:49 -07001968 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001969
James Ketrenosb095c382005-08-24 22:04:42 -05001970 inta = ipw_read32(priv, IPW_INTA_RW);
1971 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Indan Zupancic3c4a8cc2011-01-08 12:17:27 +01001972
1973 if (inta == 0xFFFFFFFF) {
1974 /* Hardware disappeared */
1975 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1976 /* Only handle the cached INTA values */
1977 inta = 0;
1978 }
James Ketrenosb095c382005-08-24 22:04:42 -05001979 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001980
1981 /* Add any cached INTA values that need to be handled */
1982 inta |= priv->isr_inta;
1983
Zhu Yi89c318e2006-06-08 22:19:49 -07001984 spin_unlock_irqrestore(&priv->irq_lock, flags);
1985
1986 spin_lock_irqsave(&priv->lock, flags);
1987
James Ketrenos43f66a62005-03-25 12:31:53 -06001988 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001989 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001990 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001991 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 }
1993
James Ketrenosb095c382005-08-24 22:04:42 -05001994 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001995 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001996 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001997 priv->status &= ~STATUS_HCMD_ACTIVE;
1998 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001999 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002000 }
2001
James Ketrenosb095c382005-08-24 22:04:42 -05002002 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002003 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002004 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002005 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002006 }
2007
James Ketrenosb095c382005-08-24 22:04:42 -05002008 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002009 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002010 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002011 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002012 }
2013
James Ketrenosb095c382005-08-24 22:04:42 -05002014 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002015 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002016 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002017 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002018 }
2019
James Ketrenosb095c382005-08-24 22:04:42 -05002020 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002022 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002023 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002024 }
2025
James Ketrenosb095c382005-08-24 22:04:42 -05002026 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002027 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002028 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002029 }
2030
James Ketrenosb095c382005-08-24 22:04:42 -05002031 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002033 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002034 }
2035
James Ketrenosb095c382005-08-24 22:04:42 -05002036 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002037 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002038 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002039 }
2040
James Ketrenosb095c382005-08-24 22:04:42 -05002041 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002042 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002043 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002044 }
2045
James Ketrenosb095c382005-08-24 22:04:42 -05002046 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002047 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002048 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002049 }
2050
James Ketrenosb095c382005-08-24 22:04:42 -05002051 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002052 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2053 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002054 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002055 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002056 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002057 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002058 cancel_delayed_work(&priv->request_direct_scan);
2059 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002060 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002061 schedule_work(&priv->link_down);
Tejun Heobcb6d912011-01-26 12:12:50 +01002062 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002063 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002064 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002065
James Ketrenosb095c382005-08-24 22:04:42 -05002066 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002067 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002068 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002069 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002070 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2071 struct ipw_fw_error *error =
2072 ipw_alloc_error_log(priv);
2073 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002074 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002075 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002076 } else {
2077 priv->error = ipw_alloc_error_log(priv);
2078 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002079 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002080 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002081 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2082 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002083 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2084 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002085 }
2086
James Ketrenosb095c382005-08-24 22:04:42 -05002087 /* XXX: If hardware encryption is for WPA/WPA2,
2088 * we have to notify the supplicant. */
2089 if (priv->ieee->sec.encrypt) {
2090 priv->status &= ~STATUS_ASSOCIATED;
2091 notify_wx_assoc_event(priv);
2092 }
2093
2094 /* Keep the restart process from trying to send host
2095 * commands by clearing the INIT status bit */
2096 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002097
2098 /* Cancel currently queued command. */
2099 priv->status &= ~STATUS_HCMD_ACTIVE;
2100 wake_up_interruptible(&priv->wait_command_queue);
2101
Tejun Heobcb6d912011-01-26 12:12:50 +01002102 schedule_work(&priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002103 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002104 }
2105
James Ketrenosb095c382005-08-24 22:04:42 -05002106 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002107 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002108 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002109 }
2110
2111 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002112 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002113 }
2114
Zhu Yi89c318e2006-06-08 22:19:49 -07002115 spin_unlock_irqrestore(&priv->lock, flags);
2116
James Ketrenos43f66a62005-03-25 12:31:53 -06002117 /* enable all interrupts */
2118 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002119}
Jeff Garzikbf794512005-07-31 13:07:26 -04002120
James Ketrenos43f66a62005-03-25 12:31:53 -06002121#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2122static char *get_cmd_string(u8 cmd)
2123{
2124 switch (cmd) {
2125 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002126 IPW_CMD(POWER_DOWN);
2127 IPW_CMD(SYSTEM_CONFIG);
2128 IPW_CMD(MULTICAST_ADDRESS);
2129 IPW_CMD(SSID);
2130 IPW_CMD(ADAPTER_ADDRESS);
2131 IPW_CMD(PORT_TYPE);
2132 IPW_CMD(RTS_THRESHOLD);
2133 IPW_CMD(FRAG_THRESHOLD);
2134 IPW_CMD(POWER_MODE);
2135 IPW_CMD(WEP_KEY);
2136 IPW_CMD(TGI_TX_KEY);
2137 IPW_CMD(SCAN_REQUEST);
2138 IPW_CMD(SCAN_REQUEST_EXT);
2139 IPW_CMD(ASSOCIATE);
2140 IPW_CMD(SUPPORTED_RATES);
2141 IPW_CMD(SCAN_ABORT);
2142 IPW_CMD(TX_FLUSH);
2143 IPW_CMD(QOS_PARAMETERS);
2144 IPW_CMD(DINO_CONFIG);
2145 IPW_CMD(RSN_CAPABILITIES);
2146 IPW_CMD(RX_KEY);
2147 IPW_CMD(CARD_DISABLE);
2148 IPW_CMD(SEED_NUMBER);
2149 IPW_CMD(TX_POWER);
2150 IPW_CMD(COUNTRY_INFO);
2151 IPW_CMD(AIRONET_INFO);
2152 IPW_CMD(AP_TX_POWER);
2153 IPW_CMD(CCKM_INFO);
2154 IPW_CMD(CCX_VER_INFO);
2155 IPW_CMD(SET_CALIBRATION);
2156 IPW_CMD(SENSITIVITY_CALIB);
2157 IPW_CMD(RETRY_LIMIT);
2158 IPW_CMD(IPW_PRE_POWER_DOWN);
2159 IPW_CMD(VAP_BEACON_TEMPLATE);
2160 IPW_CMD(VAP_DTIM_PERIOD);
2161 IPW_CMD(EXT_SUPPORTED_RATES);
2162 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2163 IPW_CMD(VAP_QUIET_INTERVALS);
2164 IPW_CMD(VAP_CHANNEL_SWITCH);
2165 IPW_CMD(VAP_MANDATORY_CHANNELS);
2166 IPW_CMD(VAP_CELL_PWR_LIMIT);
2167 IPW_CMD(VAP_CF_PARAM_SET);
2168 IPW_CMD(VAP_SET_BEACONING_STATE);
2169 IPW_CMD(MEASUREMENT);
2170 IPW_CMD(POWER_CAPABILITY);
2171 IPW_CMD(SUPPORTED_CHANNELS);
2172 IPW_CMD(TPC_REPORT);
2173 IPW_CMD(WME_INFO);
2174 IPW_CMD(PRODUCTION_COMMAND);
2175 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002176 return "UNKNOWN";
2177 }
2178}
James Ketrenos43f66a62005-03-25 12:31:53 -06002179
2180#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002181
2182static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002183{
2184 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002185 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002186
James Ketrenosa613bff2005-08-24 21:43:11 -05002187 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002188 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002189 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2190 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002191 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002192 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002193 }
2194
2195 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002196
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002197 if (priv->cmdlog) {
2198 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2199 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2200 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2201 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2202 cmd->len);
2203 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2204 }
2205
James Ketrenosb095c382005-08-24 22:04:42 -05002206 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2207 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2208 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002209
2210#ifndef DEBUG_CMD_WEP_KEY
2211 if (cmd->cmd == IPW_CMD_WEP_KEY)
2212 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2213 else
2214#endif
2215 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2216
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002217 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002218 if (rc) {
2219 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002220 IPW_ERROR("Failed to send %s: Reason %d\n",
2221 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002222 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002223 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002224 }
2225 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002226
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002227 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2228 !(priv->
2229 status & STATUS_HCMD_ACTIVE),
2230 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002231 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002232 spin_lock_irqsave(&priv->lock, flags);
2233 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002234 IPW_ERROR("Failed to send %s: Command timed out.\n",
2235 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002236 priv->status &= ~STATUS_HCMD_ACTIVE;
2237 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002238 rc = -EIO;
2239 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002240 }
2241 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002242 } else
2243 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002244
James Ketrenosb095c382005-08-24 22:04:42 -05002245 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002246 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2247 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002248 rc = -EIO;
2249 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002250 }
2251
Zhu Yi2638bc32006-01-24 16:37:52 +08002252 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002253 if (priv->cmdlog) {
2254 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2255 priv->cmdlog_pos %= priv->cmdlog_len;
2256 }
2257 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002258}
2259
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002260static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002261{
2262 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002263 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002264 };
2265
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002266 return __ipw_send_cmd(priv, &cmd);
2267}
2268
2269static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2270 void *data)
2271{
2272 struct host_cmd cmd = {
2273 .cmd = command,
2274 .len = len,
2275 .param = data,
2276 };
2277
2278 return __ipw_send_cmd(priv, &cmd);
2279}
2280
2281static int ipw_send_host_complete(struct ipw_priv *priv)
2282{
James Ketrenos43f66a62005-03-25 12:31:53 -06002283 if (!priv) {
2284 IPW_ERROR("Invalid args\n");
2285 return -1;
2286 }
2287
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002288 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002289}
2290
Zhu Yid685b8c2006-04-13 17:20:27 +08002291static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002292{
Zhu Yid685b8c2006-04-13 17:20:27 +08002293 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2294 sizeof(priv->sys_config),
2295 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002296}
2297
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002298static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002299{
James Ketrenos43f66a62005-03-25 12:31:53 -06002300 if (!priv || !ssid) {
2301 IPW_ERROR("Invalid args\n");
2302 return -1;
2303 }
2304
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002305 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002306 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002307}
2308
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002309static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002310{
James Ketrenos43f66a62005-03-25 12:31:53 -06002311 if (!priv || !mac) {
2312 IPW_ERROR("Invalid args\n");
2313 return -1;
2314 }
2315
Johannes Berge1749612008-10-27 15:59:26 -07002316 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2317 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002318
Zhu Yi2638bc32006-01-24 16:37:52 +08002319 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002320}
2321
2322static void ipw_adapter_restart(void *adapter)
2323{
2324 struct ipw_priv *priv = adapter;
2325
2326 if (priv->status & STATUS_RF_KILL_MASK)
2327 return;
2328
2329 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002330
2331 if (priv->assoc_network &&
2332 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2333 ipw_remove_current_network(priv);
2334
James Ketrenos43f66a62005-03-25 12:31:53 -06002335 if (ipw_up(priv)) {
2336 IPW_ERROR("Failed to up device\n");
2337 return;
2338 }
2339}
2340
David Howellsc4028952006-11-22 14:57:56 +00002341static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002342{
David Howellsc4028952006-11-22 14:57:56 +00002343 struct ipw_priv *priv =
2344 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002345 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002346 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002347 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002348}
2349
Zhu Yie65054b2010-03-30 09:36:16 +08002350static void ipw_abort_scan(struct ipw_priv *priv);
2351
2352#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
James Ketrenos43f66a62005-03-25 12:31:53 -06002353
2354static void ipw_scan_check(void *data)
2355{
2356 struct ipw_priv *priv = data;
Zhu Yie65054b2010-03-30 09:36:16 +08002357
2358 if (priv->status & STATUS_SCAN_ABORTING) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002359 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002360 "adapter after (%dms).\n",
2361 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
Tejun Heobcb6d912011-01-26 12:12:50 +01002362 schedule_work(&priv->adapter_restart);
Zhu Yie65054b2010-03-30 09:36:16 +08002363 } else if (priv->status & STATUS_SCANNING) {
2364 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2365 "after (%dms).\n",
2366 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2367 ipw_abort_scan(priv);
Tejun Heobcb6d912011-01-26 12:12:50 +01002368 schedule_delayed_work(&priv->scan_check, HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002369 }
2370}
2371
David Howellsc4028952006-11-22 14:57:56 +00002372static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002373{
David Howellsc4028952006-11-22 14:57:56 +00002374 struct ipw_priv *priv =
2375 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002376 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002377 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002378 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002379}
2380
James Ketrenos43f66a62005-03-25 12:31:53 -06002381static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2382 struct ipw_scan_request_ext *request)
2383{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002384 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002385 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002386}
2387
2388static int ipw_send_scan_abort(struct ipw_priv *priv)
2389{
James Ketrenos43f66a62005-03-25 12:31:53 -06002390 if (!priv) {
2391 IPW_ERROR("Invalid args\n");
2392 return -1;
2393 }
2394
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002395 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002396}
2397
2398static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2399{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002400 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002401 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002402 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002403
2404 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002405 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002406}
2407
2408static int ipw_send_associate(struct ipw_priv *priv,
2409 struct ipw_associate *associate)
2410{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002411 if (!priv || !associate) {
2412 IPW_ERROR("Invalid args\n");
2413 return -1;
2414 }
2415
Al Viro5b5e8072007-12-27 01:54:06 -05002416 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2417 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002418}
2419
2420static int ipw_send_supported_rates(struct ipw_priv *priv,
2421 struct ipw_supported_rates *rates)
2422{
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 if (!priv || !rates) {
2424 IPW_ERROR("Invalid args\n");
2425 return -1;
2426 }
2427
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002428 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002429 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002430}
2431
2432static int ipw_set_random_seed(struct ipw_priv *priv)
2433{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002434 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002435
2436 if (!priv) {
2437 IPW_ERROR("Invalid args\n");
2438 return -1;
2439 }
2440
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002441 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002442
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002443 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002444}
2445
James Ketrenos43f66a62005-03-25 12:31:53 -06002446static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2447{
Al Viroe62e1ee2007-12-27 01:36:46 -05002448 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002449 if (!priv) {
2450 IPW_ERROR("Invalid args\n");
2451 return -1;
2452 }
2453
Al Viroe62e1ee2007-12-27 01:36:46 -05002454 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002455}
James Ketrenos43f66a62005-03-25 12:31:53 -06002456
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002457static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002458{
James Ketrenos43f66a62005-03-25 12:31:53 -06002459 if (!priv || !power) {
2460 IPW_ERROR("Invalid args\n");
2461 return -1;
2462 }
2463
Zhu Yi2638bc32006-01-24 16:37:52 +08002464 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002465}
James Ketrenos43f66a62005-03-25 12:31:53 -06002466
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002467static int ipw_set_tx_power(struct ipw_priv *priv)
2468{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002469 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002470 struct ipw_tx_power tx_power;
2471 s8 max_power;
2472 int i;
2473
2474 memset(&tx_power, 0, sizeof(tx_power));
2475
2476 /* configure device for 'G' band */
2477 tx_power.ieee_mode = IPW_G_MODE;
2478 tx_power.num_channels = geo->bg_channels;
2479 for (i = 0; i < geo->bg_channels; i++) {
2480 max_power = geo->bg[i].max_power;
2481 tx_power.channels_tx_power[i].channel_number =
2482 geo->bg[i].channel;
2483 tx_power.channels_tx_power[i].tx_power = max_power ?
2484 min(max_power, priv->tx_power) : priv->tx_power;
2485 }
2486 if (ipw_send_tx_power(priv, &tx_power))
2487 return -EIO;
2488
2489 /* configure device to also handle 'B' band */
2490 tx_power.ieee_mode = IPW_B_MODE;
2491 if (ipw_send_tx_power(priv, &tx_power))
2492 return -EIO;
2493
2494 /* configure device to also handle 'A' band */
2495 if (priv->ieee->abg_true) {
2496 tx_power.ieee_mode = IPW_A_MODE;
2497 tx_power.num_channels = geo->a_channels;
2498 for (i = 0; i < tx_power.num_channels; i++) {
2499 max_power = geo->a[i].max_power;
2500 tx_power.channels_tx_power[i].channel_number =
2501 geo->a[i].channel;
2502 tx_power.channels_tx_power[i].tx_power = max_power ?
2503 min(max_power, priv->tx_power) : priv->tx_power;
2504 }
2505 if (ipw_send_tx_power(priv, &tx_power))
2506 return -EIO;
2507 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002508 return 0;
2509}
2510
2511static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2512{
2513 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002514 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002515 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002516
2517 if (!priv) {
2518 IPW_ERROR("Invalid args\n");
2519 return -1;
2520 }
2521
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002522 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2523 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002524}
2525
2526static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2527{
2528 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002529 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002530 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002531
2532 if (!priv) {
2533 IPW_ERROR("Invalid args\n");
2534 return -1;
2535 }
2536
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002537 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2538 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002539}
2540
2541static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2542{
Al Viroe62e1ee2007-12-27 01:36:46 -05002543 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002544
2545 if (!priv) {
2546 IPW_ERROR("Invalid args\n");
2547 return -1;
2548 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002549
James Ketrenos43f66a62005-03-25 12:31:53 -06002550 /* If on battery, set to 3, if AC set to CAM, else user
2551 * level */
2552 switch (mode) {
2553 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002554 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002555 break;
2556 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002557 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002558 break;
2559 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002560 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002561 break;
2562 }
2563
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002564 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002565 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002566}
2567
James Ketrenosafbf30a2005-08-25 00:05:33 -05002568static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2569{
2570 struct ipw_retry_limit retry_limit = {
2571 .short_retry_limit = slimit,
2572 .long_retry_limit = llimit
2573 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002574
2575 if (!priv) {
2576 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002577 return -1;
2578 }
2579
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002580 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002581 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002582}
2583
2584/*
2585 * The IPW device contains a Microwire compatible EEPROM that stores
2586 * various data like the MAC address. Usually the firmware has exclusive
2587 * access to the eeprom, but during device initialization (before the
2588 * device driver has sent the HostComplete command to the firmware) the
2589 * device driver has read access to the EEPROM by way of indirect addressing
2590 * through a couple of memory mapped registers.
2591 *
2592 * The following is a simplified implementation for pulling data out of the
2593 * the eeprom, along with some helper functions to find information in
2594 * the per device private data's copy of the eeprom.
2595 *
2596 * NOTE: To better understand how these functions work (i.e what is a chip
2597 * select and why do have to keep driving the eeprom clock?), read
2598 * just about any data sheet for a Microwire compatible EEPROM.
2599 */
2600
2601/* write a 32 bit value into the indirect accessor register */
2602static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2603{
2604 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002605
James Ketrenos43f66a62005-03-25 12:31:53 -06002606 /* the eeprom requires some time to complete the operation */
2607 udelay(p->eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06002608}
2609
2610/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002611static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002612{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002613 eeprom_write_reg(priv, 0);
2614 eeprom_write_reg(priv, EEPROM_BIT_CS);
2615 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2616 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002617}
2618
2619/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002620static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002621{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002622 eeprom_write_reg(priv, EEPROM_BIT_CS);
2623 eeprom_write_reg(priv, 0);
2624 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002625}
2626
2627/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002628static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002629{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 int d = (bit ? EEPROM_BIT_DI : 0);
2631 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2632 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002633}
2634
2635/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002636static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002637{
2638 int i;
2639
2640 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002641 eeprom_write_bit(priv, 1);
2642 eeprom_write_bit(priv, op & 2);
2643 eeprom_write_bit(priv, op & 1);
2644 for (i = 7; i >= 0; i--) {
2645 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002646 }
2647}
2648
2649/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002650static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002651{
2652 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002653 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002654
James Ketrenos43f66a62005-03-25 12:31:53 -06002655 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002656 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002657
2658 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002660
2661 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002662 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002664 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2665 eeprom_write_reg(priv, EEPROM_BIT_CS);
2666 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2667 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002668 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002669
James Ketrenos43f66a62005-03-25 12:31:53 -06002670 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002671 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002672 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002673
James Ketrenos43f66a62005-03-25 12:31:53 -06002674 return r;
2675}
2676
2677/* helper function for pulling the mac address out of the private */
2678/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002679static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002680{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002681 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002682}
2683
2684/*
2685 * Either the device driver (i.e. the host) or the firmware can
2686 * load eeprom data into the designated region in SRAM. If neither
2687 * happens then the FW will shutdown with a fatal error.
2688 *
2689 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2690 * bit needs region of shared SRAM needs to be non-zero.
2691 */
2692static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2693{
2694 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002695 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002696
James Ketrenos43f66a62005-03-25 12:31:53 -06002697 IPW_DEBUG_TRACE(">>\n");
2698
2699 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002700 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002701 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002702
Jeff Garzikbf794512005-07-31 13:07:26 -04002703 /*
2704 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002705 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002706 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002707 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002708 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002709 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2710
2711 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002712 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002713 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002714
2715 /* Do not load eeprom data on fatal error or suspend */
2716 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2717 } else {
2718 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2719
2720 /* Load eeprom data on fatal error or suspend */
2721 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2722 }
2723
2724 IPW_DEBUG_TRACE("<<\n");
2725}
2726
Arjan van de Ven858119e2006-01-14 13:20:43 -08002727static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002728{
2729 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002730 if (!count)
2731 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002732 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002733 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002734 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002735}
2736
2737static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2738{
James Ketrenosb095c382005-08-24 22:04:42 -05002739 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002740 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002741 sizeof(struct command_block));
2742}
2743
2744static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002745{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002746
Frans Pop9fd1ea42010-03-24 19:46:31 +01002747 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002748
James Ketrenos43f66a62005-03-25 12:31:53 -06002749 /* Start the dma */
2750 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002751
James Ketrenos43f66a62005-03-25 12:31:53 -06002752 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002753 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002754
Frans Pop9fd1ea42010-03-24 19:46:31 +01002755 IPW_DEBUG_FW("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002756 return 0;
2757}
2758
2759static void ipw_fw_dma_abort(struct ipw_priv *priv)
2760{
2761 u32 control = 0;
2762
2763 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002764
Pavel Machek67fd6b42006-07-11 15:34:05 +02002765 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002766 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002767 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002768 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002769
Frans Pop9fd1ea42010-03-24 19:46:31 +01002770 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002771}
2772
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002773static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2774 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002775{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002777 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002778 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002779 IPW_DEBUG_FW(">> :\n");
2780
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002781 ipw_write_indirect(priv, address, (u8 *) cb,
2782 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002783
2784 IPW_DEBUG_FW("<< :\n");
2785 return 0;
2786
2787}
2788
2789static int ipw_fw_dma_kick(struct ipw_priv *priv)
2790{
2791 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002792 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002793
2794 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002795
James Ketrenos43f66a62005-03-25 12:31:53 -06002796 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002797 ipw_fw_dma_write_command_block(priv, index,
2798 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002799
2800 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002801 ipw_clear_bit(priv, IPW_RESET_REG,
2802 IPW_RESET_REG_MASTER_DISABLED |
2803 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002804
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002806 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002807 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002808
2809 IPW_DEBUG_FW("<< :\n");
2810 return 0;
2811}
2812
2813static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2814{
2815 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002816 u32 register_value = 0;
2817 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002818
2819 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002820 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002821 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002822
2823 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002824 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002825 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002826
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002827 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002828 cb_fields_address = address;
2829 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002830 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002831
2832 cb_fields_address += sizeof(u32);
2833 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002834 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002835
2836 cb_fields_address += sizeof(u32);
2837 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002838 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002839 register_value);
2840
2841 cb_fields_address += sizeof(u32);
2842 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002843 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002844
2845 IPW_DEBUG_FW(">> :\n");
2846}
2847
2848static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2849{
2850 u32 current_cb_address = 0;
2851 u32 current_cb_index = 0;
2852
2853 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002854 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002855
James Ketrenosb095c382005-08-24 22:04:42 -05002856 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002857 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002858
Frans Pop9fd1ea42010-03-24 19:46:31 +01002859 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002860 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002861
2862 IPW_DEBUG_FW(">> :\n");
2863 return current_cb_index;
2864
2865}
2866
2867static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2868 u32 src_address,
2869 u32 dest_address,
2870 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002871 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002872{
2873
Jeff Garzikbf794512005-07-31 13:07:26 -04002874 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002875 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2876 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002877 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002878 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002879
2880 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2881 src_address, dest_address, length);
2882
2883 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2884 return -1;
2885
2886 last_cb_element = priv->sram_desc.last_cb_index;
2887 cb = &priv->sram_desc.cb_list[last_cb_element];
2888 priv->sram_desc.last_cb_index++;
2889
2890 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002891 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 control |= CB_INT_ENABLED;
2893
2894 if (is_last)
2895 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002896
James Ketrenos43f66a62005-03-25 12:31:53 -06002897 control |= length;
2898
2899 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002900 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002901
2902 /* Copy the Source and Destination addresses */
2903 cb->dest_addr = dest_address;
2904 cb->source_addr = src_address;
2905
2906 /* Copy the Control Word last */
2907 cb->control = control;
2908
2909 return 0;
2910}
2911
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002912static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2913 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002914{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002915 int ret, i;
2916 u32 size;
2917
Frans Pop9fd1ea42010-03-24 19:46:31 +01002918 IPW_DEBUG_FW(">>\n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002919 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2920 nr, dest_address, len);
2921
2922 for (i = 0; i < nr; i++) {
2923 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2924 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2925 dest_address +
2926 i * CB_MAX_LENGTH, size,
2927 0, 0);
2928 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002929 IPW_DEBUG_FW_INFO(": Failed\n");
2930 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002931 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002933 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002934
Frans Pop9fd1ea42010-03-24 19:46:31 +01002935 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002936 return 0;
2937}
2938
2939static int ipw_fw_dma_wait(struct ipw_priv *priv)
2940{
Zhu Yi397ae122006-01-24 16:37:22 +08002941 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 u32 watchdog = 0;
2943
Frans Pop9fd1ea42010-03-24 19:46:31 +01002944 IPW_DEBUG_FW(">> :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002945
2946 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002947 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002948 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002949
2950 while (current_index < priv->sram_desc.last_cb_index) {
2951 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002952 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002953 current_index = ipw_fw_dma_command_block_index(priv);
2954
Zhu Yi397ae122006-01-24 16:37:22 +08002955 if (previous_index < current_index) {
2956 watchdog = 0;
2957 continue;
2958 }
2959 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002960 IPW_DEBUG_FW_INFO("Timeout\n");
2961 ipw_fw_dma_dump_command_block(priv);
2962 ipw_fw_dma_abort(priv);
2963 return -1;
2964 }
2965 }
2966
2967 ipw_fw_dma_abort(priv);
2968
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002969 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002970 ipw_set_bit(priv, IPW_RESET_REG,
2971 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002972
Frans Pop9fd1ea42010-03-24 19:46:31 +01002973 IPW_DEBUG_FW("<< dmaWaitSync\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002974 return 0;
2975}
2976
Jeff Garzikbf794512005-07-31 13:07:26 -04002977static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002978{
2979 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002980 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002981 unsigned long flags;
2982
2983 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002984 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002985 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002986 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2987 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002988 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002989 &priv->ieee->network_free_list);
2990 }
2991 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002992 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002993}
2994
2995/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002996 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002997 * Reads debug register from domain0.
2998 * If card is present, pre-defined value should
2999 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04003000 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003001 * @param priv
3002 * @return 1 if card is present, 0 otherwise
3003 */
3004static inline int ipw_alive(struct ipw_priv *priv)
3005{
3006 return ipw_read32(priv, 0x90) == 0xd55555d5;
3007}
3008
Zhu Yic7b6a672006-01-24 16:37:05 +08003009/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003010static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003011 int timeout)
3012{
3013 int i = 0;
3014
3015 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003016 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003017 return i;
3018 mdelay(10);
3019 i += 10;
3020 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003021
James Ketrenos43f66a62005-03-25 12:31:53 -06003022 return -ETIME;
3023}
3024
Jeff Garzikbf794512005-07-31 13:07:26 -04003025/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003026 * the ipw hardware. It assumes the buffer has all the bits for the
3027 * image and the caller is handling the memory allocation and clean up.
3028 */
3029
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003030static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003031{
3032 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003033
Frans Pop9fd1ea42010-03-24 19:46:31 +01003034 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003035 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003036 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003037
Zhu Yic7b6a672006-01-24 16:37:05 +08003038 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003039 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3040 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003041 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003042 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003043 return -1;
3044 }
3045
3046 IPW_DEBUG_INFO("stop master %dms\n", rc);
3047
3048 return rc;
3049}
3050
3051static void ipw_arc_release(struct ipw_priv *priv)
3052{
Frans Pop9fd1ea42010-03-24 19:46:31 +01003053 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003054 mdelay(5);
3055
James Ketrenosb095c382005-08-24 22:04:42 -05003056 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003057
3058 /* no one knows timing, for safety add some delay */
3059 mdelay(5);
3060}
3061
James Ketrenos43f66a62005-03-25 12:31:53 -06003062struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003063 __le32 address;
3064 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003065};
3066
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003067static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003068{
3069 int rc = 0, i, addr;
3070 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003071 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003072
Al Viroe62e1ee2007-12-27 01:36:46 -05003073 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003074
Frans Pop9fd1ea42010-03-24 19:46:31 +01003075 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003076
3077 rc = ipw_stop_master(priv);
3078
3079 if (rc < 0)
3080 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003081
James Ketrenosb095c382005-08-24 22:04:42 -05003082 for (addr = IPW_SHARED_LOWER_BOUND;
3083 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003084 ipw_write32(priv, addr, 0);
3085 }
3086
3087 /* no ucode (yet) */
3088 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3089 /* destroy DMA queues */
3090 /* reset sequence */
3091
James Ketrenosb095c382005-08-24 22:04:42 -05003092 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003093 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003094 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003095 mdelay(1);
3096
3097 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003098 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003099 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003100
James Ketrenosb095c382005-08-24 22:04:42 -05003101 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003102 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003103
James Ketrenos43f66a62005-03-25 12:31:53 -06003104 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003105 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3106 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003107 mdelay(1);
3108
3109 /* write ucode */
3110 /**
3111 * @bug
3112 * Do NOT set indirect address register once and then
3113 * store data to indirect data register in the loop.
3114 * It seems very reasonable, but in this case DINO do not
3115 * accept ucode. It is essential to set address each time.
3116 */
3117 /* load new ipw uCode */
3118 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003119 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003120 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003121
James Ketrenos43f66a62005-03-25 12:31:53 -06003122 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003123 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3124 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003125
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003126 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003127
3128 /* wait for alive response */
3129 for (i = 0; i < 100; i++) {
3130 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003131 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003132 if (cr & DINO_RXFIFO_DATA)
3133 break;
3134 mdelay(1);
3135 }
3136
3137 if (cr & DINO_RXFIFO_DATA) {
3138 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003139 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003140
3141 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003143 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003144 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003145 memcpy(&priv->dino_alive, response_buffer,
3146 sizeof(priv->dino_alive));
3147 if (priv->dino_alive.alive_command == 1
3148 && priv->dino_alive.ucode_valid == 1) {
3149 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003150 IPW_DEBUG_INFO
3151 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3152 "of %02d/%02d/%02d %02d:%02d\n",
3153 priv->dino_alive.software_revision,
3154 priv->dino_alive.software_revision,
3155 priv->dino_alive.device_identifier,
3156 priv->dino_alive.device_identifier,
3157 priv->dino_alive.time_stamp[0],
3158 priv->dino_alive.time_stamp[1],
3159 priv->dino_alive.time_stamp[2],
3160 priv->dino_alive.time_stamp[3],
3161 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003162 } else {
3163 IPW_DEBUG_INFO("Microcode is not alive\n");
3164 rc = -EINVAL;
3165 }
3166 } else {
3167 IPW_DEBUG_INFO("No alive response from DINO\n");
3168 rc = -ETIME;
3169 }
3170
3171 /* disable DINO, otherwise for some reason
3172 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003173 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003174
James Ketrenos43f66a62005-03-25 12:31:53 -06003175 return rc;
3176}
3177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003178static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003179{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003180 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003181 int offset = 0;
3182 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003183 int total_nr = 0;
3184 int i;
3185 struct pci_pool *pool;
Zhu Yi41093162010-03-09 16:05:31 +08003186 void **virts;
3187 dma_addr_t *phys;
James Ketrenos43f66a62005-03-25 12:31:53 -06003188
Frans Pop9fd1ea42010-03-24 19:46:31 +01003189 IPW_DEBUG_TRACE("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003190
Zhu Yi41093162010-03-09 16:05:31 +08003191 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3192 GFP_KERNEL);
3193 if (!virts)
3194 return -ENOMEM;
3195
3196 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3197 GFP_KERNEL);
3198 if (!phys) {
3199 kfree(virts);
3200 return -ENOMEM;
3201 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003202 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3203 if (!pool) {
3204 IPW_ERROR("pci_pool_create failed\n");
Zhu Yi41093162010-03-09 16:05:31 +08003205 kfree(phys);
3206 kfree(virts);
James Ketrenos43f66a62005-03-25 12:31:53 -06003207 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003208 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003209
3210 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003211 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003212
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003213 /* the DMA is already ready this would be a bug. */
3214 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003215
3216 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003217 u32 chunk_len;
3218 u8 *start;
3219 int size;
3220 int nr = 0;
3221
James Ketrenos43f66a62005-03-25 12:31:53 -06003222 chunk = (struct fw_chunk *)(data + offset);
3223 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003224 chunk_len = le32_to_cpu(chunk->length);
3225 start = data + offset;
3226
3227 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3228 for (i = 0; i < nr; i++) {
3229 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3230 &phys[total_nr]);
3231 if (!virts[total_nr]) {
3232 ret = -ENOMEM;
3233 goto out;
3234 }
3235 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3236 CB_MAX_LENGTH);
3237 memcpy(virts[total_nr], start, size);
3238 start += size;
3239 total_nr++;
3240 /* We don't support fw chunk larger than 64*8K */
3241 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3242 }
3243
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003245 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003246 * offeset*/
3247 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003248 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3249 nr, le32_to_cpu(chunk->address),
3250 chunk_len);
3251 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3253 goto out;
3254 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003255
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003256 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003257 } while (offset < len);
3258
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003259 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003260 ret = ipw_fw_dma_kick(priv);
3261 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003262 IPW_ERROR("dmaKick Failed\n");
3263 goto out;
3264 }
3265
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003266 ret = ipw_fw_dma_wait(priv);
3267 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003268 IPW_ERROR("dmaWaitSync Failed\n");
3269 goto out;
3270 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003271 out:
3272 for (i = 0; i < total_nr; i++)
3273 pci_pool_free(pool, virts[i], phys[i]);
3274
3275 pci_pool_destroy(pool);
Zhu Yi41093162010-03-09 16:05:31 +08003276 kfree(phys);
3277 kfree(virts);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003278
3279 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003280}
3281
3282/* stop nic */
3283static int ipw_stop_nic(struct ipw_priv *priv)
3284{
3285 int rc = 0;
3286
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003287 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003288 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003289
James Ketrenosb095c382005-08-24 22:04:42 -05003290 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3291 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003292 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003293 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003294 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003295 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003296
James Ketrenosb095c382005-08-24 22:04:42 -05003297 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003298
James Ketrenos43f66a62005-03-25 12:31:53 -06003299 return rc;
3300}
3301
3302static void ipw_start_nic(struct ipw_priv *priv)
3303{
3304 IPW_DEBUG_TRACE(">>\n");
3305
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003306 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003307 ipw_clear_bit(priv, IPW_RESET_REG,
3308 IPW_RESET_REG_MASTER_DISABLED |
3309 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003310 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003311
James Ketrenos43f66a62005-03-25 12:31:53 -06003312 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003313 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3314 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003315
3316 IPW_DEBUG_TRACE("<<\n");
3317}
Jeff Garzikbf794512005-07-31 13:07:26 -04003318
James Ketrenos43f66a62005-03-25 12:31:53 -06003319static int ipw_init_nic(struct ipw_priv *priv)
3320{
3321 int rc;
3322
3323 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003324 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003325 /*prvHwInitNic */
3326 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003327 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003328
3329 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003330 ipw_write32(priv, IPW_READ_INT_REGISTER,
3331 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003332
3333 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003334 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3335 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003336 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003337 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3338
3339 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003340 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003341
3342 udelay(10);
3343
3344 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003345 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003346
3347 IPW_DEBUG_TRACE(">>\n");
3348 return 0;
3349}
3350
Jeff Garzikbf794512005-07-31 13:07:26 -04003351/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003352 * Probe is an ok place to call this from.
3353 */
3354static int ipw_reset_nic(struct ipw_priv *priv)
3355{
3356 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003357 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003358
3359 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003360
James Ketrenos43f66a62005-03-25 12:31:53 -06003361 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003362
James Ketrenosa613bff2005-08-24 21:43:11 -05003363 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003364 /* Clear the 'host command active' bit... */
3365 priv->status &= ~STATUS_HCMD_ACTIVE;
3366 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003367 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3368 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003369 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003370
3371 IPW_DEBUG_TRACE("<<\n");
3372 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003373}
James Ketrenos43f66a62005-03-25 12:31:53 -06003374
James Ketrenos9006ea72006-03-08 03:22:28 +08003375
3376struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003377 __le32 ver;
3378 __le32 boot_size;
3379 __le32 ucode_size;
3380 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003381 u8 data[0];
3382};
3383
Jeff Garzikbf794512005-07-31 13:07:26 -04003384static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003385 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003386{
James Ketrenos9006ea72006-03-08 03:22:28 +08003387 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003388 int rc;
3389
3390 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003391 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003392 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003393 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003394 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003395 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003396
James Ketrenos9006ea72006-03-08 03:22:28 +08003397 if ((*raw)->size < sizeof(*fw)) {
3398 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003399 return -EINVAL;
3400 }
3401
James Ketrenos9006ea72006-03-08 03:22:28 +08003402 fw = (void *)(*raw)->data;
3403
Zhu Yi0070f8c2006-04-13 17:20:12 +08003404 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3405 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003406 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3407 name, (*raw)->size);
3408 return -EINVAL;
3409 }
3410
3411 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003412 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003413 le32_to_cpu(fw->ver) >> 16,
3414 le32_to_cpu(fw->ver) & 0xff,
3415 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003416 return 0;
3417}
3418
James Ketrenosb095c382005-08-24 22:04:42 -05003419#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003420
Arjan van de Ven858119e2006-01-14 13:20:43 -08003421static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003422 struct ipw_rx_queue *rxq)
3423{
3424 unsigned long flags;
3425 int i;
3426
3427 spin_lock_irqsave(&rxq->lock, flags);
3428
3429 INIT_LIST_HEAD(&rxq->rx_free);
3430 INIT_LIST_HEAD(&rxq->rx_used);
3431
3432 /* Fill the rx_used queue with _all_ of the Rx buffers */
3433 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3434 /* In the reset function, these buffers may have been allocated
3435 * to an SKB, so we need to unmap and free potential storage */
3436 if (rxq->pool[i].skb != NULL) {
3437 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003438 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003439 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003440 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003441 }
3442 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3443 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003444
James Ketrenos43f66a62005-03-25 12:31:53 -06003445 /* Set us so that we have processed and used all buffers, but have
3446 * not restocked the Rx queue with fresh buffers */
3447 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003448 rxq->free_count = 0;
3449 spin_unlock_irqrestore(&rxq->lock, flags);
3450}
3451
3452#ifdef CONFIG_PM
3453static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003454static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003455
3456static void free_firmware(void)
3457{
3458 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003459 release_firmware(raw);
3460 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003461 fw_loaded = 0;
3462 }
3463}
3464#else
3465#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003466#endif
3467
3468static int ipw_load(struct ipw_priv *priv)
3469{
3470#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003471 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003472#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003473 struct ipw_fw *fw;
3474 u8 *boot_img, *ucode_img, *fw_img;
3475 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003476 int rc = 0, retries = 3;
3477
Zhu Yi397ae122006-01-24 16:37:22 +08003478 switch (priv->ieee->iw_mode) {
3479 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003480 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003481 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003482#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003483 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003484 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003485 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003486#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003487 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003488 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003489 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003490 }
Zhu Yi397ae122006-01-24 16:37:22 +08003491
James Ketrenos9006ea72006-03-08 03:22:28 +08003492 if (!name) {
3493 rc = -EINVAL;
3494 goto error;
3495 }
3496
3497#ifdef CONFIG_PM
3498 if (!fw_loaded) {
3499#endif
3500 rc = ipw_get_fw(priv, &raw, name);
3501 if (rc < 0)
3502 goto error;
3503#ifdef CONFIG_PM
3504 }
3505#endif
3506
3507 fw = (void *)raw->data;
3508 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003509 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3510 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3511 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003512
Zhu Yi397ae122006-01-24 16:37:22 +08003513 if (rc < 0)
3514 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003515
3516 if (!priv->rxq)
3517 priv->rxq = ipw_rx_queue_alloc(priv);
3518 else
3519 ipw_rx_queue_reset(priv, priv->rxq);
3520 if (!priv->rxq) {
3521 IPW_ERROR("Unable to initialize Rx queue\n");
3522 goto error;
3523 }
3524
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003525 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003526 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003527 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003528 priv->status &= ~STATUS_INT_ENABLED;
3529
3530 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003531 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003532
James Ketrenos43f66a62005-03-25 12:31:53 -06003533 ipw_stop_nic(priv);
3534
3535 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003536 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003537 IPW_ERROR("Unable to reset NIC\n");
3538 goto error;
3539 }
3540
James Ketrenosb095c382005-08-24 22:04:42 -05003541 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3542 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003543
3544 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003545 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003546 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003547 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003548 goto error;
3549 }
3550
3551 /* kick start the device */
3552 ipw_start_nic(priv);
3553
Zhu Yic7b6a672006-01-24 16:37:05 +08003554 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003555 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3556 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 if (rc < 0) {
3558 IPW_ERROR("device failed to boot initial fw image\n");
3559 goto error;
3560 }
3561 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3562
Jeff Garzikbf794512005-07-31 13:07:26 -04003563 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003564 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003565
3566 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003567 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003569 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003570 goto error;
3571 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003572
James Ketrenos43f66a62005-03-25 12:31:53 -06003573 /* stop nic */
3574 ipw_stop_nic(priv);
3575
3576 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003577 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003578 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003579 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003580 goto error;
3581 }
Zhu Yi397ae122006-01-24 16:37:22 +08003582#ifdef CONFIG_PM
3583 fw_loaded = 1;
3584#endif
3585
James Ketrenos43f66a62005-03-25 12:31:53 -06003586 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3587
3588 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003589 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003590 IPW_ERROR("Unable to initialize queues\n");
3591 goto error;
3592 }
3593
3594 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003595 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003596 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003597 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003598
James Ketrenos43f66a62005-03-25 12:31:53 -06003599 /* kick start the device */
3600 ipw_start_nic(priv);
3601
James Ketrenosb095c382005-08-24 22:04:42 -05003602 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003603 if (retries > 0) {
3604 IPW_WARNING("Parity error. Retrying init.\n");
3605 retries--;
3606 goto retry;
3607 }
3608
3609 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3610 rc = -EIO;
3611 goto error;
3612 }
3613
3614 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003615 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3616 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003617 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003618 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003619 goto error;
3620 }
3621 IPW_DEBUG_INFO("device response after %dms\n", rc);
3622
3623 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003624 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003625
3626 /* read eeprom data and initialize the eeprom region of sram */
3627 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003628 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003629
3630 /* enable interrupts */
3631 ipw_enable_interrupts(priv);
3632
3633 /* Ensure our queue has valid packets */
3634 ipw_rx_queue_replenish(priv);
3635
James Ketrenosb095c382005-08-24 22:04:42 -05003636 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003637
3638 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003639 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003640
3641#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003642 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003643#endif
3644 return 0;
3645
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003646 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003647 if (priv->rxq) {
3648 ipw_rx_queue_free(priv, priv->rxq);
3649 priv->rxq = NULL;
3650 }
3651 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003652 if (raw)
3653 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003654#ifdef CONFIG_PM
3655 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003656 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003657#endif
3658
3659 return rc;
3660}
3661
Jeff Garzikbf794512005-07-31 13:07:26 -04003662/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003663 * DMA services
3664 *
3665 * Theory of operation
3666 *
3667 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3668 * 2 empty entries always kept in the buffer to protect from overflow.
3669 *
3670 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003671 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3672 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003673 * Tx queue resumed.
3674 *
3675 * The IPW operates with six queues, one receive queue in the device's
3676 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003677 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003678 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003679 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003680 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003681 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003682 * we only utilize the first data transmit queue (queue1).
3683 */
3684
3685/**
3686 * Driver allocates buffers of this size for Rx
3687 */
3688
Dan Williams943dbef2008-02-14 17:49:41 -05003689/**
3690 * ipw_rx_queue_space - Return number of free slots available in queue.
3691 */
3692static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3693{
3694 int s = q->read - q->write;
3695 if (s <= 0)
3696 s += RX_QUEUE_SIZE;
3697 /* keep some buffer to not confuse full and empty queue */
3698 s -= 2;
3699 if (s < 0)
3700 s = 0;
3701 return s;
3702}
3703
3704static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003705{
3706 int s = q->last_used - q->first_empty;
3707 if (s <= 0)
3708 s += q->n_bd;
3709 s -= 2; /* keep some reserve to not confuse empty and full situations */
3710 if (s < 0)
3711 s = 0;
3712 return s;
3713}
3714
3715static inline int ipw_queue_inc_wrap(int index, int n_bd)
3716{
3717 return (++index == n_bd) ? 0 : index;
3718}
3719
3720/**
3721 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003722 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003723 * @param q queue to init
3724 * @param count Number of BD's to allocate. Should be power of 2
3725 * @param read_register Address for 'read' register
3726 * (not offset within BAR, full address)
3727 * @param write_register Address for 'write' register
3728 * (not offset within BAR, full address)
3729 * @param base_register Address for 'base' register
3730 * (not offset within BAR, full address)
3731 * @param size Address for 'size' register
3732 * (not offset within BAR, full address)
3733 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003734static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003735 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003736{
3737 q->n_bd = count;
3738
3739 q->low_mark = q->n_bd / 4;
3740 if (q->low_mark < 4)
3741 q->low_mark = 4;
3742
3743 q->high_mark = q->n_bd / 8;
3744 if (q->high_mark < 2)
3745 q->high_mark = 2;
3746
3747 q->first_empty = q->last_used = 0;
3748 q->reg_r = read;
3749 q->reg_w = write;
3750
3751 ipw_write32(priv, base, q->dma_addr);
3752 ipw_write32(priv, size, count);
3753 ipw_write32(priv, read, 0);
3754 ipw_write32(priv, write, 0);
3755
3756 _ipw_read32(priv, 0x90);
3757}
3758
Jeff Garzikbf794512005-07-31 13:07:26 -04003759static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003760 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003761 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003762{
3763 struct pci_dev *dev = priv->pci_dev;
3764
3765 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3766 if (!q->txb) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003767 IPW_ERROR("vmalloc for auxiliary BD structures failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003768 return -ENOMEM;
3769 }
3770
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003771 q->bd =
3772 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003773 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003774 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003775 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 kfree(q->txb);
3777 q->txb = NULL;
3778 return -ENOMEM;
3779 }
3780
3781 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3782 return 0;
3783}
3784
3785/**
3786 * Free one TFD, those at index [txq->q.last_used].
3787 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003788 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003789 * @param dev
3790 * @param txq
3791 */
3792static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3793 struct clx2_tx_queue *txq)
3794{
3795 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3796 struct pci_dev *dev = priv->pci_dev;
3797 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003798
James Ketrenos43f66a62005-03-25 12:31:53 -06003799 /* classify bd */
3800 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3801 /* nothing to cleanup after for host commands */
3802 return;
3803
3804 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003805 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3806 IPW_ERROR("Too many chunks: %i\n",
3807 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003808 /** @todo issue fatal error, it is quite serious situation */
3809 return;
3810 }
3811
3812 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003813 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3814 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3815 le16_to_cpu(bd->u.data.chunk_len[i]),
3816 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003817 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003818 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003819 txq->txb[txq->q.last_used] = NULL;
3820 }
3821 }
3822}
3823
3824/**
3825 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003826 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003827 * Empty queue by removing and destroying all BD's.
3828 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003829 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003830 * @param dev
3831 * @param q
3832 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003833static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003834{
3835 struct clx2_queue *q = &txq->q;
3836 struct pci_dev *dev = priv->pci_dev;
3837
Jeff Garzikbf794512005-07-31 13:07:26 -04003838 if (q->n_bd == 0)
3839 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003840
3841 /* first, empty all BD's */
3842 for (; q->first_empty != q->last_used;
3843 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3844 ipw_queue_tx_free_tfd(priv, txq);
3845 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003846
James Ketrenos43f66a62005-03-25 12:31:53 -06003847 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003848 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003849 q->dma_addr);
3850 kfree(txq->txb);
3851
3852 /* 0 fill whole structure */
3853 memset(txq, 0, sizeof(*txq));
3854}
3855
James Ketrenos43f66a62005-03-25 12:31:53 -06003856/**
3857 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003858 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003859 * @param priv
3860 */
3861static void ipw_tx_queue_free(struct ipw_priv *priv)
3862{
3863 /* Tx CMD queue */
3864 ipw_queue_tx_free(priv, &priv->txq_cmd);
3865
3866 /* Tx queues */
3867 ipw_queue_tx_free(priv, &priv->txq[0]);
3868 ipw_queue_tx_free(priv, &priv->txq[1]);
3869 ipw_queue_tx_free(priv, &priv->txq[2]);
3870 ipw_queue_tx_free(priv, &priv->txq[3]);
3871}
3872
Arjan van de Ven858119e2006-01-14 13:20:43 -08003873static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003874{
3875 /* First 3 bytes are manufacturer */
3876 bssid[0] = priv->mac_addr[0];
3877 bssid[1] = priv->mac_addr[1];
3878 bssid[2] = priv->mac_addr[2];
3879
3880 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003881 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003882
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003883 bssid[0] &= 0xfe; /* clear multicast bit */
3884 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003885}
3886
Arjan van de Ven858119e2006-01-14 13:20:43 -08003887static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003888{
3889 struct ipw_station_entry entry;
3890 int i;
3891
3892 for (i = 0; i < priv->num_stations; i++) {
3893 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3894 /* Another node is active in network */
3895 priv->missed_adhoc_beacons = 0;
3896 if (!(priv->config & CFG_STATIC_CHANNEL))
3897 /* when other nodes drop out, we drop out */
3898 priv->config &= ~CFG_ADHOC_PERSIST;
3899
3900 return i;
3901 }
3902 }
3903
3904 if (i == MAX_STATIONS)
3905 return IPW_INVALID_STATION;
3906
Johannes Berge1749612008-10-27 15:59:26 -07003907 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003908
3909 entry.reserved = 0;
3910 entry.support_mode = 0;
3911 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3912 memcpy(priv->stations[i], bssid, ETH_ALEN);
3913 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003914 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 priv->num_stations++;
3916
3917 return i;
3918}
3919
Arjan van de Ven858119e2006-01-14 13:20:43 -08003920static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003921{
3922 int i;
3923
Jeff Garzikbf794512005-07-31 13:07:26 -04003924 for (i = 0; i < priv->num_stations; i++)
3925 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003926 return i;
3927
3928 return IPW_INVALID_STATION;
3929}
3930
3931static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3932{
3933 int err;
3934
Hong Liu7b996592005-08-25 17:36:13 +08003935 if (priv->status & STATUS_ASSOCIATING) {
3936 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01003937 schedule_work(&priv->disassociate);
Hong Liu7b996592005-08-25 17:36:13 +08003938 return;
3939 }
3940
3941 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003942 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3943 return;
3944 }
3945
Johannes Berge1749612008-10-27 15:59:26 -07003946 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003947 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003948 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003949 priv->assoc_request.channel);
3950
3951 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3952 priv->status |= STATUS_DISASSOCIATING;
3953
3954 if (quiet)
3955 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3956 else
3957 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003958
James Ketrenos43f66a62005-03-25 12:31:53 -06003959 err = ipw_send_associate(priv, &priv->assoc_request);
3960 if (err) {
3961 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3962 "failed.\n");
3963 return;
3964 }
3965
3966}
3967
James Ketrenosc848d0a2005-08-24 21:56:24 -05003968static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003969{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003970 struct ipw_priv *priv = data;
3971 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3972 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003973 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003974 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003975 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003976}
3977
David Howellsc4028952006-11-22 14:57:56 +00003978static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003979{
David Howellsc4028952006-11-22 14:57:56 +00003980 struct ipw_priv *priv =
3981 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003982 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003983 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003984 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003985}
3986
David Howellsc4028952006-11-22 14:57:56 +00003987static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003988{
David Howellsc4028952006-11-22 14:57:56 +00003989 struct ipw_priv *priv =
3990 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003991
3992#ifdef CONFIG_IPW2200_PROMISCUOUS
3993 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3994 priv->sys_config.accept_all_data_frames = 1;
3995 priv->sys_config.accept_non_directed_frames = 1;
3996 priv->sys_config.accept_all_mgmt_bcpr = 1;
3997 priv->sys_config.accept_all_mgmt_frames = 1;
3998 }
3999#endif
4000
4001 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004002}
4003
4004struct ipw_status_code {
4005 u16 status;
4006 const char *reason;
4007};
4008
4009static const struct ipw_status_code ipw_status_codes[] = {
4010 {0x00, "Successful"},
4011 {0x01, "Unspecified failure"},
4012 {0x0A, "Cannot support all requested capabilities in the "
4013 "Capability information field"},
4014 {0x0B, "Reassociation denied due to inability to confirm that "
4015 "association exists"},
4016 {0x0C, "Association denied due to reason outside the scope of this "
4017 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004018 {0x0D,
4019 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004020 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004021 {0x0E,
4022 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004023 "transaction sequence number out of expected sequence"},
4024 {0x0F, "Authentication rejected because of challenge failure"},
4025 {0x10, "Authentication rejected due to timeout waiting for next "
4026 "frame in sequence"},
4027 {0x11, "Association denied because AP is unable to handle additional "
4028 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004029 {0x12,
4030 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004031 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004032 {0x13,
4033 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004034 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004035 {0x14,
4036 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004038 {0x15,
4039 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004040 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004041 {0x19,
4042 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004043 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004044 {0x1A,
4045 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004046 "DSSS-OFDM operation"},
4047 {0x28, "Invalid Information Element"},
4048 {0x29, "Group Cipher is not valid"},
4049 {0x2A, "Pairwise Cipher is not valid"},
4050 {0x2B, "AKMP is not valid"},
4051 {0x2C, "Unsupported RSN IE version"},
4052 {0x2D, "Invalid RSN IE Capabilities"},
4053 {0x2E, "Cipher suite is rejected per security policy"},
4054};
4055
Jeff Garzikbf794512005-07-31 13:07:26 -04004056static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004057{
4058 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004059 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004060 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004061 return ipw_status_codes[i].reason;
4062 return "Unknown status value.";
4063}
James Ketrenos43f66a62005-03-25 12:31:53 -06004064
4065static void inline average_init(struct average *avg)
4066{
4067 memset(avg, 0, sizeof(*avg));
4068}
4069
Zhu Yi00d21de2006-04-13 17:19:02 +08004070#define DEPTH_RSSI 8
4071#define DEPTH_NOISE 16
4072static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4073{
4074 return ((depth-1)*prev_avg + val)/depth;
4075}
4076
Arjan van de Ven858119e2006-01-14 13:20:43 -08004077static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004078{
4079 avg->sum -= avg->entries[avg->pos];
4080 avg->sum += val;
4081 avg->entries[avg->pos++] = val;
4082 if (unlikely(avg->pos == AVG_ENTRIES)) {
4083 avg->init = 1;
4084 avg->pos = 0;
4085 }
4086}
4087
Arjan van de Ven858119e2006-01-14 13:20:43 -08004088static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004089{
4090 if (!unlikely(avg->init)) {
4091 if (avg->pos)
4092 return avg->sum / avg->pos;
4093 return 0;
4094 }
4095
4096 return avg->sum / AVG_ENTRIES;
4097}
4098
4099static void ipw_reset_stats(struct ipw_priv *priv)
4100{
4101 u32 len = sizeof(u32);
4102
4103 priv->quality = 0;
4104
4105 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004106 priv->exp_avg_rssi = -60;
4107 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004108
4109 priv->last_rate = 0;
4110 priv->last_missed_beacons = 0;
4111 priv->last_rx_packets = 0;
4112 priv->last_tx_packets = 0;
4113 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004114
James Ketrenos43f66a62005-03-25 12:31:53 -06004115 /* Firmware managed, reset only when NIC is restarted, so we have to
4116 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004117 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004118 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004119 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004120 &priv->last_tx_failures, &len);
4121
4122 /* Driver managed, reset with each association */
4123 priv->missed_adhoc_beacons = 0;
4124 priv->missed_beacons = 0;
4125 priv->tx_packets = 0;
4126 priv->rx_packets = 0;
4127
4128}
4129
Arjan van de Ven858119e2006-01-14 13:20:43 -08004130static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004131{
4132 u32 i = 0x80000000;
4133 u32 mask = priv->rates_mask;
4134 /* If currently associated in B mode, restrict the maximum
4135 * rate match to B rates */
4136 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004137 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004138
4139 /* TODO: Verify that the rate is supported by the current rates
4140 * list. */
4141
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004142 while (i && !(mask & i))
4143 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004144 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004145 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004146 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004147 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004148 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004149 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004150 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004151 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004152 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004153 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004154 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004155 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004156 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004157 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004158 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004159 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004160 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004161 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004162 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004163 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004164 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004165 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004166 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004167 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004168 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004169 }
4170
Jeff Garzikbf794512005-07-31 13:07:26 -04004171 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004172 return 11000000;
4173 else
4174 return 54000000;
4175}
4176
4177static u32 ipw_get_current_rate(struct ipw_priv *priv)
4178{
4179 u32 rate, len = sizeof(rate);
4180 int err;
4181
Jeff Garzikbf794512005-07-31 13:07:26 -04004182 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004183 return 0;
4184
4185 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004186 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004187 &len);
4188 if (err) {
4189 IPW_DEBUG_INFO("failed querying ordinals.\n");
4190 return 0;
4191 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004192 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004193 return ipw_get_max_rate(priv);
4194
4195 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004196 case IPW_TX_RATE_1MB:
4197 return 1000000;
4198 case IPW_TX_RATE_2MB:
4199 return 2000000;
4200 case IPW_TX_RATE_5MB:
4201 return 5500000;
4202 case IPW_TX_RATE_6MB:
4203 return 6000000;
4204 case IPW_TX_RATE_9MB:
4205 return 9000000;
4206 case IPW_TX_RATE_11MB:
4207 return 11000000;
4208 case IPW_TX_RATE_12MB:
4209 return 12000000;
4210 case IPW_TX_RATE_18MB:
4211 return 18000000;
4212 case IPW_TX_RATE_24MB:
4213 return 24000000;
4214 case IPW_TX_RATE_36MB:
4215 return 36000000;
4216 case IPW_TX_RATE_48MB:
4217 return 48000000;
4218 case IPW_TX_RATE_54MB:
4219 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004220 }
4221
4222 return 0;
4223}
4224
James Ketrenos43f66a62005-03-25 12:31:53 -06004225#define IPW_STATS_INTERVAL (2 * HZ)
4226static void ipw_gather_stats(struct ipw_priv *priv)
4227{
4228 u32 rx_err, rx_err_delta, rx_packets_delta;
4229 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4230 u32 missed_beacons_percent, missed_beacons_delta;
4231 u32 quality = 0;
4232 u32 len = sizeof(u32);
4233 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004234 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004235 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004236 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004237
4238 if (!(priv->status & STATUS_ASSOCIATED)) {
4239 priv->quality = 0;
4240 return;
4241 }
4242
4243 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004244 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004245 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004246 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004247 priv->last_missed_beacons = priv->missed_beacons;
4248 if (priv->assoc_request.beacon_interval) {
4249 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004250 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004251 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004252 } else {
4253 missed_beacons_percent = 0;
4254 }
4255 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4256
4257 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4258 rx_err_delta = rx_err - priv->last_rx_err;
4259 priv->last_rx_err = rx_err;
4260
4261 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4262 tx_failures_delta = tx_failures - priv->last_tx_failures;
4263 priv->last_tx_failures = tx_failures;
4264
4265 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4266 priv->last_rx_packets = priv->rx_packets;
4267
4268 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4269 priv->last_tx_packets = priv->tx_packets;
4270
4271 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004272 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004273 * Missed beacon: 100% = 0, 0% = 70% missed
4274 * Rate: 60% = 1Mbs, 100% = Max
4275 * Rx and Tx errors represent a straight % of total Rx/Tx
4276 * RSSI: 100% = > -50, 0% = < -80
4277 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004278 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004279 * The lowest computed quality is used.
4280 *
4281 */
4282#define BEACON_THRESHOLD 5
4283 beacon_quality = 100 - missed_beacons_percent;
4284 if (beacon_quality < BEACON_THRESHOLD)
4285 beacon_quality = 0;
4286 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004287 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004288 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004289 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004290 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004291
James Ketrenos43f66a62005-03-25 12:31:53 -06004292 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004293 max_rate = ipw_get_max_rate(priv);
4294 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004295 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4296 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004297
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004298 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004299 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004300 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004301 else
4302 rx_quality = 100;
4303 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4304 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004305
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004306 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004307 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004308 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004309 else
4310 tx_quality = 100;
4311 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4312 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004313
Zhu Yi00d21de2006-04-13 17:19:02 +08004314 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004315 signal_quality =
4316 (100 *
4317 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4318 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4319 (priv->ieee->perfect_rssi - rssi) *
4320 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4321 62 * (priv->ieee->perfect_rssi - rssi))) /
4322 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4323 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4324 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004325 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004326 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004327 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004328
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004329 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004330 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004331
Reinette Chatre21f8a732009-08-18 10:25:05 -07004332 quality = min(rx_quality, signal_quality);
4333 quality = min(tx_quality, quality);
4334 quality = min(rate_quality, quality);
4335 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004336 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004337 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4338 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004339 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004340 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4341 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004342 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004343 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4344 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004345 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004346 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4347 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004348 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004349 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4350 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004351
4352 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004353
Tejun Heobcb6d912011-01-26 12:12:50 +01004354 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL);
James Ketrenos43f66a62005-03-25 12:31:53 -06004355}
4356
David Howellsc4028952006-11-22 14:57:56 +00004357static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004358{
David Howellsc4028952006-11-22 14:57:56 +00004359 struct ipw_priv *priv =
4360 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004361 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004362 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004363 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004364}
4365
Ben Cahille7582562005-10-06 15:34:41 -05004366/* Missed beacon behavior:
4367 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4368 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4369 * Above disassociate threshold, give up and stop scanning.
4370 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004371static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004372 int missed_count)
4373{
4374 priv->notif_missed_beacons = missed_count;
4375
James Ketrenosafbf30a2005-08-25 00:05:33 -05004376 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004377 priv->status & STATUS_ASSOCIATED) {
4378 /* If associated and we've hit the missed
4379 * beacon threshold, disassociate, turn
4380 * off roaming, and abort any active scans */
4381 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004382 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004383 "Missed beacon: %d - disassociate\n", missed_count);
4384 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004385 if (priv->status & STATUS_SCANNING) {
4386 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4387 IPW_DL_STATE,
4388 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004389 schedule_work(&priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004390 }
4391
Tejun Heobcb6d912011-01-26 12:12:50 +01004392 schedule_work(&priv->disassociate);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004393 return;
4394 }
4395
4396 if (priv->status & STATUS_ROAMING) {
4397 /* If we are currently roaming, then just
4398 * print a debug statement... */
4399 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4400 "Missed beacon: %d - roam in progress\n",
4401 missed_count);
4402 return;
4403 }
4404
Zhu Yi4bfdb912006-01-24 16:37:16 +08004405 if (roaming &&
4406 (missed_count > priv->roaming_threshold &&
4407 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004408 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004409 * bit in the status and kick off a scan.
4410 * This can happen several times before we reach
4411 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004412 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4413 "Missed beacon: %d - initiate "
4414 "roaming\n", missed_count);
4415 if (!(priv->status & STATUS_ROAMING)) {
4416 priv->status |= STATUS_ROAMING;
4417 if (!(priv->status & STATUS_SCANNING))
Tejun Heobcb6d912011-01-26 12:12:50 +01004418 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004419 }
4420 return;
4421 }
4422
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004423 if (priv->status & STATUS_SCANNING &&
4424 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004425 /* Stop scan to keep fw from getting
4426 * stuck (only if we aren't roaming --
4427 * otherwise we'll never scan more than 2 or 3
4428 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004429 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4430 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004431 schedule_work(&priv->abort_scan);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004432 }
4433
4434 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004435}
4436
Dan Williams0b531672007-10-09 13:55:24 -04004437static void ipw_scan_event(struct work_struct *work)
4438{
4439 union iwreq_data wrqu;
4440
4441 struct ipw_priv *priv =
4442 container_of(work, struct ipw_priv, scan_event.work);
4443
4444 wrqu.data.length = 0;
4445 wrqu.data.flags = 0;
4446 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4447}
4448
4449static void handle_scan_event(struct ipw_priv *priv)
4450{
4451 /* Only userspace-requested scan completion events go out immediately */
4452 if (!priv->user_requested_scan) {
4453 if (!delayed_work_pending(&priv->scan_event))
Tejun Heobcb6d912011-01-26 12:12:50 +01004454 schedule_delayed_work(&priv->scan_event,
4455 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004456 } else {
4457 union iwreq_data wrqu;
4458
4459 priv->user_requested_scan = 0;
4460 cancel_delayed_work(&priv->scan_event);
4461
4462 wrqu.data.length = 0;
4463 wrqu.data.flags = 0;
4464 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4465 }
4466}
4467
James Ketrenos43f66a62005-03-25 12:31:53 -06004468/**
4469 * Handle host notification packet.
4470 * Called from interrupt routine
4471 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004472static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004473 struct ipw_rx_notification *notif)
4474{
John W. Linville9387b7c2008-09-30 20:59:05 -04004475 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004476 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004477
Al Viroe62e1ee2007-12-27 01:36:46 -05004478 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004479
James Ketrenos43f66a62005-03-25 12:31:53 -06004480 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004481 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4482 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004483
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004484 switch (assoc->state) {
4485 case CMAS_ASSOCIATED:{
4486 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4487 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004488 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004489 print_ssid(ssid, priv->essid,
4490 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004491 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004492
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004493 switch (priv->ieee->iw_mode) {
4494 case IW_MODE_INFRA:
4495 memcpy(priv->ieee->bssid,
4496 priv->bssid, ETH_ALEN);
4497 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004498
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004499 case IW_MODE_ADHOC:
4500 memcpy(priv->ieee->bssid,
4501 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004502
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 /* clear out the station table */
4504 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004505
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004506 IPW_DEBUG_ASSOC
4507 ("queueing adhoc check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004508 schedule_delayed_work(
4509 &priv->adhoc_check,
4510 le16_to_cpu(priv->
4511 assoc_request.
4512 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004513 break;
4514 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004515
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004516 priv->status &= ~STATUS_ASSOCIATING;
4517 priv->status |= STATUS_ASSOCIATED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004518 schedule_work(&priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004519
Zhu Yie43e3c12006-04-13 17:20:45 +08004520#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004521#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004522 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004523 if ((priv->status & STATUS_AUTH) &&
4524 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4525 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004526 if ((sizeof
4527 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004528 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004529 <= size)
4530 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004531 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004532 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004533 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004534 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004535 };
4536
4537 IPW_DEBUG_QOS
4538 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004539 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004540 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004541 ieee,
4542 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004543 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004544 *)
4545 &notif->u.raw, &stats);
4546 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004547 }
James Ketrenosb095c382005-08-24 22:04:42 -05004548#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004549
James Ketrenosa613bff2005-08-24 21:43:11 -05004550 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 break;
4553 }
4554
4555 case CMAS_AUTHENTICATED:{
4556 if (priv->
4557 status & (STATUS_ASSOCIATED |
4558 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004559 struct notif_authenticate *auth
4560 = &notif->u.auth;
4561 IPW_DEBUG(IPW_DL_NOTIF |
4562 IPW_DL_STATE |
4563 IPW_DL_ASSOC,
4564 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004565 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004566 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004567 print_ssid(ssid,
4568 priv->
4569 essid,
4570 priv->
4571 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004572 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004573 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004574 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004575 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004576 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004577
4578 priv->status &=
4579 ~(STATUS_ASSOCIATING |
4580 STATUS_AUTH |
4581 STATUS_ASSOCIATED);
4582
James Ketrenosa613bff2005-08-24 21:43:11 -05004583 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584 break;
4585 }
4586
4587 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4588 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004589 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004590 print_ssid(ssid, priv->essid,
4591 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004592 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004593 break;
4594 }
4595
4596 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004597 if (priv->status & STATUS_AUTH) {
4598 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004599 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004600 *resp;
4601 resp =
4602 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004603 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004604 *)&notif->u.raw;
4605 IPW_DEBUG(IPW_DL_NOTIF |
4606 IPW_DL_STATE |
4607 IPW_DL_ASSOC,
4608 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004609 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004610 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004611 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004612 (resp->status)));
4613 }
4614
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4616 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004617 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004618 print_ssid(ssid, priv->essid,
4619 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004620 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004621
4622 priv->status &=
4623 ~(STATUS_DISASSOCIATING |
4624 STATUS_ASSOCIATING |
4625 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004626 if (priv->assoc_network
4627 && (priv->assoc_network->
4628 capability &
4629 WLAN_CAPABILITY_IBSS))
4630 ipw_remove_current_network
4631 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004632
James Ketrenosa613bff2005-08-24 21:43:11 -05004633 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004635 break;
4636 }
4637
James Ketrenosb095c382005-08-24 22:04:42 -05004638 case CMAS_RX_ASSOC_RESP:
4639 break;
4640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004641 default:
4642 IPW_ERROR("assoc: unknown (%d)\n",
4643 assoc->state);
4644 break;
4645 }
4646
James Ketrenos43f66a62005-03-25 12:31:53 -06004647 break;
4648 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004649
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004650 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4651 struct notif_authenticate *auth = &notif->u.auth;
4652 switch (auth->state) {
4653 case CMAS_AUTHENTICATED:
4654 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004655 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004656 print_ssid(ssid, priv->essid,
4657 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004658 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004659 priv->status |= STATUS_AUTH;
4660 break;
4661
4662 case CMAS_INIT:
4663 if (priv->status & STATUS_AUTH) {
4664 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4665 IPW_DL_ASSOC,
4666 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004667 le16_to_cpu(auth->status),
4668 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004669 (auth->
4670 status)));
4671 }
4672 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4673 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004674 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004675 print_ssid(ssid, priv->essid,
4676 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004677 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004678
4679 priv->status &= ~(STATUS_ASSOCIATING |
4680 STATUS_AUTH |
4681 STATUS_ASSOCIATED);
4682
James Ketrenosa613bff2005-08-24 21:43:11 -05004683 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004684 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004685
4686 case CMAS_TX_AUTH_SEQ_1:
4687 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4688 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4689 break;
4690 case CMAS_RX_AUTH_SEQ_2:
4691 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4692 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4693 break;
4694 case CMAS_AUTH_SEQ_1_PASS:
4695 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4696 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4697 break;
4698 case CMAS_AUTH_SEQ_1_FAIL:
4699 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4700 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4701 break;
4702 case CMAS_TX_AUTH_SEQ_3:
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4704 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4705 break;
4706 case CMAS_RX_AUTH_SEQ_4:
4707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4708 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4709 break;
4710 case CMAS_AUTH_SEQ_2_PASS:
4711 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4712 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4713 break;
4714 case CMAS_AUTH_SEQ_2_FAIL:
4715 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4716 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4717 break;
4718 case CMAS_TX_ASSOC:
4719 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4720 IPW_DL_ASSOC, "TX_ASSOC\n");
4721 break;
4722 case CMAS_RX_ASSOC_RESP:
4723 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4724 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004725
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004726 break;
4727 case CMAS_ASSOCIATED:
4728 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4729 IPW_DL_ASSOC, "ASSOCIATED\n");
4730 break;
4731 default:
4732 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4733 auth->state);
4734 break;
4735 }
4736 break;
4737 }
4738
4739 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4740 struct notif_channel_result *x =
4741 &notif->u.channel_result;
4742
Al Viroe62e1ee2007-12-27 01:36:46 -05004743 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004744 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4745 x->channel_num);
4746 } else {
4747 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4748 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004749 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004750 }
4751 break;
4752 }
4753
4754 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4755 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004756 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004757 IPW_DEBUG_SCAN
4758 ("Scan completed: type %d, %d channels, "
4759 "%d status\n", x->scan_type,
4760 x->num_channels, x->status);
4761 } else {
4762 IPW_ERROR("Scan completed of wrong size %d "
4763 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004764 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004765 }
4766
4767 priv->status &=
4768 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4769
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004770 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004771 cancel_delayed_work(&priv->scan_check);
4772
James Ketrenosb095c382005-08-24 22:04:42 -05004773 if (priv->status & STATUS_EXIT_PENDING)
4774 break;
4775
4776 priv->ieee->scans++;
4777
4778#ifdef CONFIG_IPW2200_MONITOR
4779 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004780 priv->status |= STATUS_SCAN_FORCED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004781 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004782 break;
4783 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004784 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004785#endif /* CONFIG_IPW2200_MONITOR */
4786
Dan Williamsea177302008-06-02 17:51:23 -04004787 /* Do queued direct scans first */
Tejun Heobcb6d912011-01-26 12:12:50 +01004788 if (priv->status & STATUS_DIRECT_SCAN_PENDING)
4789 schedule_delayed_work(&priv->request_direct_scan, 0);
Dan Williamsea177302008-06-02 17:51:23 -04004790
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004791 if (!(priv->status & (STATUS_ASSOCIATED |
4792 STATUS_ASSOCIATING |
4793 STATUS_ROAMING |
4794 STATUS_DISASSOCIATING)))
Tejun Heobcb6d912011-01-26 12:12:50 +01004795 schedule_work(&priv->associate);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004796 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004797 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4798 /* If a scan completed and we are in roam mode, then
4799 * the scan that completed was the one requested as a
4800 * result of entering roam... so, schedule the
4801 * roam work */
Tejun Heobcb6d912011-01-26 12:12:50 +01004802 schedule_work(&priv->roam);
Ben Cahille7582562005-10-06 15:34:41 -05004803 else
4804 /* Don't schedule if we aborted the scan */
4805 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004806 } else if (priv->status & STATUS_SCAN_PENDING)
Tejun Heobcb6d912011-01-26 12:12:50 +01004807 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004808 else if (priv->config & CFG_BACKGROUND_SCAN
4809 && priv->status & STATUS_ASSOCIATED)
Tejun Heobcb6d912011-01-26 12:12:50 +01004810 schedule_delayed_work(&priv->request_scan,
4811 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004812
4813 /* Send an empty event to user space.
4814 * We don't send the received data on the event because
4815 * it would require us to do complex transcoding, and
4816 * we want to minimise the work done in the irq handler
4817 * Use a request to extract the data.
4818 * Also, we generate this even for any scan, regardless
4819 * on how the scan was initiated. User space can just
4820 * sync on periodic scan to get fresh data...
4821 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004822 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4823 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004824 break;
4825 }
4826
4827 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4828 struct notif_frag_length *x = &notif->u.frag_len;
4829
Al Viroe62e1ee2007-12-27 01:36:46 -05004830 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004831 IPW_ERROR("Frag length: %d\n",
4832 le16_to_cpu(x->frag_length));
4833 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004834 IPW_ERROR("Frag length of wrong size %d "
4835 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004836 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004837 break;
4838 }
4839
4840 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4841 struct notif_link_deterioration *x =
4842 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004843
Al Viroe62e1ee2007-12-27 01:36:46 -05004844 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004845 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004846 "link deterioration: type %d, cnt %d\n",
4847 x->silence_notification_type,
4848 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004849 memcpy(&priv->last_link_deterioration, x,
4850 sizeof(*x));
4851 } else {
4852 IPW_ERROR("Link Deterioration of wrong size %d "
4853 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004854 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004855 }
4856 break;
4857 }
4858
4859 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4860 IPW_ERROR("Dino config\n");
4861 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004862 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004863 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004864
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004865 break;
4866 }
4867
4868 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4869 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004870 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004871 IPW_ERROR
4872 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004873 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004874 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004875 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004876
James Ketrenosa613bff2005-08-24 21:43:11 -05004877 if (le32_to_cpu(x->state) ==
4878 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4879 ipw_handle_missed_beacon(priv,
4880 le32_to_cpu(x->
4881 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004882
James Ketrenos43f66a62005-03-25 12:31:53 -06004883 break;
4884 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004885
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004886 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4887 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004888 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004889 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4890 "0x%02x station %d\n",
4891 x->key_state, x->security_type,
4892 x->station_index);
4893 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004894 }
4895
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004896 IPW_ERROR
4897 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004898 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004899 break;
4900 }
4901
4902 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4903 struct notif_calibration *x = &notif->u.calibration;
4904
Al Viroe62e1ee2007-12-27 01:36:46 -05004905 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004906 memcpy(&priv->calib, x, sizeof(*x));
4907 IPW_DEBUG_INFO("TODO: Calibration\n");
4908 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004909 }
4910
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004911 IPW_ERROR
4912 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004913 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004914 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004915 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004917 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004918 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004919 priv->exp_avg_noise =
4920 exponential_average(priv->exp_avg_noise,
4921 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4922 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004923 break;
4924 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004925
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004926 IPW_ERROR
4927 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004928 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004929 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004930 }
4931
James Ketrenos43f66a62005-03-25 12:31:53 -06004932 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004933 IPW_DEBUG_NOTIF("Unknown notification: "
4934 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004935 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 }
4937}
4938
4939/**
4940 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004941 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004942 * @param priv
4943 * @return error code
4944 */
4945static int ipw_queue_reset(struct ipw_priv *priv)
4946{
4947 int rc = 0;
4948 /** @todo customize queue sizes */
4949 int nTx = 64, nTxCmd = 8;
4950 ipw_tx_queue_free(priv);
4951 /* Tx CMD queue */
4952 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004953 IPW_TX_CMD_QUEUE_READ_INDEX,
4954 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4955 IPW_TX_CMD_QUEUE_BD_BASE,
4956 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004957 if (rc) {
4958 IPW_ERROR("Tx Cmd queue init failed\n");
4959 goto error;
4960 }
4961 /* Tx queue(s) */
4962 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004963 IPW_TX_QUEUE_0_READ_INDEX,
4964 IPW_TX_QUEUE_0_WRITE_INDEX,
4965 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004966 if (rc) {
4967 IPW_ERROR("Tx 0 queue init failed\n");
4968 goto error;
4969 }
4970 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004971 IPW_TX_QUEUE_1_READ_INDEX,
4972 IPW_TX_QUEUE_1_WRITE_INDEX,
4973 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004974 if (rc) {
4975 IPW_ERROR("Tx 1 queue init failed\n");
4976 goto error;
4977 }
4978 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004979 IPW_TX_QUEUE_2_READ_INDEX,
4980 IPW_TX_QUEUE_2_WRITE_INDEX,
4981 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004982 if (rc) {
4983 IPW_ERROR("Tx 2 queue init failed\n");
4984 goto error;
4985 }
4986 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004987 IPW_TX_QUEUE_3_READ_INDEX,
4988 IPW_TX_QUEUE_3_WRITE_INDEX,
4989 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004990 if (rc) {
4991 IPW_ERROR("Tx 3 queue init failed\n");
4992 goto error;
4993 }
4994 /* statistics */
4995 priv->rx_bufs_min = 0;
4996 priv->rx_pend_max = 0;
4997 return rc;
4998
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004999 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005000 ipw_tx_queue_free(priv);
5001 return rc;
5002}
5003
5004/**
5005 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005006 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005007 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005008 * new 'R' index need to be reclaimed. As result, some free space
5009 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005010 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005011 * @note Need to protect against garbage in 'R' index
5012 * @param priv
5013 * @param txq
5014 * @param qindex
5015 * @return Number of used entries remains in the queue
5016 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005017static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005018 struct clx2_tx_queue *txq, int qindex)
5019{
5020 u32 hw_tail;
5021 int used;
5022 struct clx2_queue *q = &txq->q;
5023
5024 hw_tail = ipw_read32(priv, q->reg_r);
5025 if (hw_tail >= q->n_bd) {
5026 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005027 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5028 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005029 goto done;
5030 }
5031 for (; q->last_used != hw_tail;
5032 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5033 ipw_queue_tx_free_tfd(priv, txq);
5034 priv->tx_packets++;
5035 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005036 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005037 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005038 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005039 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005040 used = q->first_empty - q->last_used;
5041 if (used < 0)
5042 used += q->n_bd;
5043
5044 return used;
5045}
5046
5047static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5048 int len, int sync)
5049{
5050 struct clx2_tx_queue *txq = &priv->txq_cmd;
5051 struct clx2_queue *q = &txq->q;
5052 struct tfd_frame *tfd;
5053
Dan Williams943dbef2008-02-14 17:49:41 -05005054 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005055 IPW_ERROR("No space for Tx\n");
5056 return -EBUSY;
5057 }
5058
5059 tfd = &txq->bd[q->first_empty];
5060 txq->txb[q->first_empty] = NULL;
5061
5062 memset(tfd, 0, sizeof(*tfd));
5063 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5064 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5065 priv->hcmd_seq++;
5066 tfd->u.cmd.index = hcmd;
5067 tfd->u.cmd.length = len;
5068 memcpy(tfd->u.cmd.payload, buf, len);
5069 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5070 ipw_write32(priv, q->reg_w, q->first_empty);
5071 _ipw_read32(priv, 0x90);
5072
5073 return 0;
5074}
5075
Jeff Garzikbf794512005-07-31 13:07:26 -04005076/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005077 * Rx theory of operation
5078 *
5079 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005080 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005081 * 0 to 31
5082 *
5083 * Rx Queue Indexes
5084 * The host/firmware share two index registers for managing the Rx buffers.
5085 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005086 * The READ index maps to the first position that the firmware may be writing
5087 * to -- the driver can read up to (but not including) this position and get
5088 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005089 * The READ index is managed by the firmware once the card is enabled.
5090 *
5091 * The WRITE index maps to the last position the driver has read from -- the
5092 * position preceding WRITE is the last slot the firmware can place a packet.
5093 *
5094 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005095 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005096 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005097 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005098 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5099 *
5100 * When the firmware places a packet in a buffer it will advance the READ index
5101 * and fire the RX interrupt. The driver can then query the READ index and
5102 * process as many packets as possible, moving the WRITE index forward as it
5103 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005104 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005105 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005106 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005107 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005108 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005109 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5110 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5111 * 'processed' and 'read' driver indexes as well)
5112 * + A received packet is processed and handed to the kernel network stack,
5113 * detached from the ipw->rxq. The driver 'processed' index is updated.
5114 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005115 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5116 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005117 * were enough free buffers and RX_STALLED is set it is cleared.
5118 *
5119 *
5120 * Driver sequence:
5121 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005122 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005123 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5124 * ipw_rx_queue_restock
5125 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5126 * queue, updates firmware pointers, and updates
5127 * the WRITE index. If insufficient rx_free buffers
5128 * are available, schedules ipw_rx_queue_replenish
5129 *
5130 * -- enable interrupts --
5131 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005132 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005133 * Moves the packet buffer from queue to rx_used.
5134 * Calls ipw_rx_queue_restock to refill any empty
5135 * slots.
5136 * ...
5137 *
5138 */
5139
Jeff Garzikbf794512005-07-31 13:07:26 -04005140/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005141 * If there are slots in the RX queue that need to be restocked,
5142 * and we have free pre-allocated buffers, fill the ranks as much
5143 * as we can pulling from rx_free.
5144 *
5145 * This moves the 'write' index forward to catch up with 'processed', and
5146 * also updates the memory address in the firmware to reference the new
5147 * target buffer.
5148 */
5149static void ipw_rx_queue_restock(struct ipw_priv *priv)
5150{
5151 struct ipw_rx_queue *rxq = priv->rxq;
5152 struct list_head *element;
5153 struct ipw_rx_mem_buffer *rxb;
5154 unsigned long flags;
5155 int write;
5156
5157 spin_lock_irqsave(&rxq->lock, flags);
5158 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005159 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005160 element = rxq->rx_free.next;
5161 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5162 list_del(element);
5163
James Ketrenosb095c382005-08-24 22:04:42 -05005164 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005165 rxb->dma_addr);
5166 rxq->queue[rxq->write] = rxb;
5167 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5168 rxq->free_count--;
5169 }
5170 spin_unlock_irqrestore(&rxq->lock, flags);
5171
Jeff Garzikbf794512005-07-31 13:07:26 -04005172 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005173 * refill it */
5174 if (rxq->free_count <= RX_LOW_WATERMARK)
Tejun Heobcb6d912011-01-26 12:12:50 +01005175 schedule_work(&priv->rx_replenish);
James Ketrenos43f66a62005-03-25 12:31:53 -06005176
5177 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005178 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005179 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005180}
5181
5182/*
5183 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005184 * Also restock the Rx queue via ipw_rx_queue_restock.
5185 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005186 * This is called as a scheduled work item (except for during intialization)
5187 */
5188static void ipw_rx_queue_replenish(void *data)
5189{
5190 struct ipw_priv *priv = data;
5191 struct ipw_rx_queue *rxq = priv->rxq;
5192 struct list_head *element;
5193 struct ipw_rx_mem_buffer *rxb;
5194 unsigned long flags;
5195
5196 spin_lock_irqsave(&rxq->lock, flags);
5197 while (!list_empty(&rxq->rx_used)) {
5198 element = rxq->rx_used.next;
5199 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005200 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005201 if (!rxb->skb) {
5202 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5203 priv->net_dev->name);
5204 /* We don't reschedule replenish work here -- we will
5205 * call the restock method and if it still needs
5206 * more buffers it will schedule replenish */
5207 break;
5208 }
5209 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005210
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005211 rxb->dma_addr =
5212 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005213 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005214
James Ketrenos43f66a62005-03-25 12:31:53 -06005215 list_add_tail(&rxb->list, &rxq->rx_free);
5216 rxq->free_count++;
5217 }
5218 spin_unlock_irqrestore(&rxq->lock, flags);
5219
5220 ipw_rx_queue_restock(priv);
5221}
5222
David Howellsc4028952006-11-22 14:57:56 +00005223static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005224{
David Howellsc4028952006-11-22 14:57:56 +00005225 struct ipw_priv *priv =
5226 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005227 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005228 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005229 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005230}
5231
James Ketrenos43f66a62005-03-25 12:31:53 -06005232/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005233 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005234 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005235 * non NULL it is unmapped and freed
5236 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005237static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005238{
5239 int i;
5240
5241 if (!rxq)
5242 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005243
James Ketrenos43f66a62005-03-25 12:31:53 -06005244 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5245 if (rxq->pool[i].skb != NULL) {
5246 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005247 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005248 dev_kfree_skb(rxq->pool[i].skb);
5249 }
5250 }
5251
5252 kfree(rxq);
5253}
5254
5255static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5256{
5257 struct ipw_rx_queue *rxq;
5258 int i;
5259
Takisc75f4742005-12-01 01:41:45 -08005260 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005261 if (unlikely(!rxq)) {
5262 IPW_ERROR("memory allocation failed\n");
5263 return NULL;
5264 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005265 spin_lock_init(&rxq->lock);
5266 INIT_LIST_HEAD(&rxq->rx_free);
5267 INIT_LIST_HEAD(&rxq->rx_used);
5268
5269 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005270 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005271 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5272
5273 /* Set us so that we have processed and used all buffers, but have
5274 * not restocked the Rx queue with fresh buffers */
5275 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005276 rxq->free_count = 0;
5277
5278 return rxq;
5279}
5280
5281static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5282{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005283 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005284 if (ieee_mode == IEEE_A) {
5285 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005286 case LIBIPW_OFDM_RATE_6MB:
5287 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005288 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005289 case LIBIPW_OFDM_RATE_9MB:
5290 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005291 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005292 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005293 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005294 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5295 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005296 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005297 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5298 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005299 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005300 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5301 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005302 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005303 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5304 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005305 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005306 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5307 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005308 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005309 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005310 default:
5311 return 0;
5312 }
5313 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005314
James Ketrenos43f66a62005-03-25 12:31:53 -06005315 /* B and G mixed */
5316 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005317 case LIBIPW_CCK_RATE_1MB:
5318 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5319 case LIBIPW_CCK_RATE_2MB:
5320 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5321 case LIBIPW_CCK_RATE_5MB:
5322 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5323 case LIBIPW_CCK_RATE_11MB:
5324 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005325 }
5326
5327 /* If we are limited to B modulations, bail at this point */
5328 if (ieee_mode == IEEE_B)
5329 return 0;
5330
5331 /* G */
5332 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005333 case LIBIPW_OFDM_RATE_6MB:
5334 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5335 case LIBIPW_OFDM_RATE_9MB:
5336 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5337 case LIBIPW_OFDM_RATE_12MB:
5338 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5339 case LIBIPW_OFDM_RATE_18MB:
5340 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5341 case LIBIPW_OFDM_RATE_24MB:
5342 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5343 case LIBIPW_OFDM_RATE_36MB:
5344 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5345 case LIBIPW_OFDM_RATE_48MB:
5346 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5347 case LIBIPW_OFDM_RATE_54MB:
5348 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005349 }
5350
5351 return 0;
5352}
5353
Jeff Garzikbf794512005-07-31 13:07:26 -04005354static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005355 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005356 struct ipw_supported_rates *rates)
5357{
5358 int num_rates, i;
5359
5360 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005361 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005362 rates->num_rates = 0;
5363 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005364 if (!ipw_is_rate_in_mask(priv, network->mode,
5365 network->rates[i])) {
5366
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005367 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005368 IPW_DEBUG_SCAN("Adding masked mandatory "
5369 "rate %02X\n",
5370 network->rates[i]);
5371 rates->supported_rates[rates->num_rates++] =
5372 network->rates[i];
5373 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005374 }
5375
James Ketrenos43f66a62005-03-25 12:31:53 -06005376 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5377 network->rates[i], priv->rates_mask);
5378 continue;
5379 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005380
James Ketrenos43f66a62005-03-25 12:31:53 -06005381 rates->supported_rates[rates->num_rates++] = network->rates[i];
5382 }
5383
James Ketrenosa613bff2005-08-24 21:43:11 -05005384 num_rates = min(network->rates_ex_len,
5385 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005386 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005387 if (!ipw_is_rate_in_mask(priv, network->mode,
5388 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005389 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005390 IPW_DEBUG_SCAN("Adding masked mandatory "
5391 "rate %02X\n",
5392 network->rates_ex[i]);
5393 rates->supported_rates[rates->num_rates++] =
5394 network->rates[i];
5395 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005396 }
5397
James Ketrenos43f66a62005-03-25 12:31:53 -06005398 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5399 network->rates_ex[i], priv->rates_mask);
5400 continue;
5401 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005402
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005403 rates->supported_rates[rates->num_rates++] =
5404 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005405 }
5406
James Ketrenosea2b26e2005-08-24 21:25:16 -05005407 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005408}
5409
Arjan van de Ven858119e2006-01-14 13:20:43 -08005410static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005411 const struct ipw_supported_rates *src)
5412{
5413 u8 i;
5414 for (i = 0; i < src->num_rates; i++)
5415 dest->supported_rates[i] = src->supported_rates[i];
5416 dest->num_rates = src->num_rates;
5417}
5418
5419/* TODO: Look at sniffed packets in the air to determine if the basic rate
5420 * mask should ever be used -- right now all callers to add the scan rates are
5421 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5422static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005423 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005424{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005425 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5426 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005427
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005428 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005429 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005430 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005431
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005432 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005433 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005434 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005435
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005436 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005437 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005438 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005439
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005440 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005441 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005442 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005443}
5444
5445static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005446 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005447{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5449 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005450
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005451 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005452 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005453 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005454
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005455 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005456 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005457 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005458
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005459 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005460 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005461 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005462
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005463 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005464 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005465 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005466
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005467 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005468 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005469 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005470
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005471 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005472 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005473 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005474
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005475 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005476 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005477 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005478
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005479 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005480 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005481 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005482}
5483
5484struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005485 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 struct ipw_supported_rates rates;
5487};
5488
James Ketrenosc848d0a2005-08-24 21:56:24 -05005489static int ipw_find_adhoc_network(struct ipw_priv *priv,
5490 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005491 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005492 int roaming)
5493{
5494 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005495 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005496
5497 /* Verify that this network's capability is compatible with the
5498 * current mode (AdHoc or Infrastructure) */
5499 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5500 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005501 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005502 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005503 print_ssid(ssid, network->ssid,
5504 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005505 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005506 return 0;
5507 }
5508
James Ketrenosc848d0a2005-08-24 21:56:24 -05005509 if (unlikely(roaming)) {
5510 /* If we are roaming, then ensure check if this is a valid
5511 * network to try and roam to */
5512 if ((network->ssid_len != match->network->ssid_len) ||
5513 memcmp(network->ssid, match->network->ssid,
5514 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005515 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005516 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005517 print_ssid(ssid, network->ssid,
5518 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005519 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005520 return 0;
5521 }
5522 } else {
5523 /* If an ESSID has been configured then compare the broadcast
5524 * ESSID to ours */
5525 if ((priv->config & CFG_STATIC_ESSID) &&
5526 ((network->ssid_len != priv->essid_len) ||
5527 memcmp(network->ssid, priv->essid,
5528 min(network->ssid_len, priv->essid_len)))) {
5529 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005530
James Ketrenosc848d0a2005-08-24 21:56:24 -05005531 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005532 print_ssid(ssid, network->ssid,
5533 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005534 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005535 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005536 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005537 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005538 print_ssid(ssid, priv->essid,
5539 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005540 return 0;
5541 }
5542 }
5543
5544 /* If the old network rate is better than this one, don't bother
5545 * testing everything else. */
5546
5547 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005548 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5549 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005550 print_ssid(ssid, match->network->ssid,
5551 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005552 return 0;
5553 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005554 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5555 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005556 print_ssid(ssid, match->network->ssid,
5557 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005558 return 0;
5559 }
5560
5561 /* Now go through and see if the requested network is valid... */
5562 if (priv->ieee->scan_age != 0 &&
5563 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005564 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005565 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005566 print_ssid(ssid, network->ssid,
5567 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005568 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005569 jiffies_to_msecs(jiffies -
5570 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005571 return 0;
5572 }
5573
5574 if ((priv->config & CFG_STATIC_CHANNEL) &&
5575 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005576 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005577 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005578 print_ssid(ssid, network->ssid,
5579 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005580 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005581 network->channel, priv->channel);
5582 return 0;
5583 }
5584
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005585 /* Verify privacy compatibility */
James Ketrenosc848d0a2005-08-24 21:56:24 -05005586 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5587 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005588 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005589 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005590 print_ssid(ssid, network->ssid,
5591 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005592 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005593 priv->
5594 capability & CAP_PRIVACY_ON ? "on" : "off",
5595 network->
5596 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5597 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005598 return 0;
5599 }
5600
5601 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005602 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5603 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005604 ".\n", print_ssid(ssid, network->ssid,
5605 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005606 network->bssid,
5607 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005608 return 0;
5609 }
5610
5611 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005612 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005613 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005614 "because of invalid frequency/mode "
5615 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005616 print_ssid(ssid, network->ssid,
5617 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005618 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005619 return 0;
5620 }
5621
5622 /* Ensure that the rates supported by the driver are compatible with
5623 * this AP, including verification of basic rates (mandatory) */
5624 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005625 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005626 "because configured rate mask excludes "
5627 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005628 print_ssid(ssid, network->ssid,
5629 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005630 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005631 return 0;
5632 }
5633
5634 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005635 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005636 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005637 print_ssid(ssid, network->ssid,
5638 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005639 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005640 return 0;
5641 }
5642
5643 /* TODO: Perform any further minimal comparititive tests. We do not
5644 * want to put too much policy logic here; intelligent scan selection
5645 * should occur within a generic IEEE 802.11 user space tool. */
5646
5647 /* Set up 'new' AP to this network */
5648 ipw_copy_rates(&match->rates, &rates);
5649 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005650 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005651 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005652 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005653
5654 return 1;
5655}
5656
David Howellsc4028952006-11-22 14:57:56 +00005657static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005658{
John W. Linville9387b7c2008-09-30 20:59:05 -04005659 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005660 struct ipw_priv *priv =
5661 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005662 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005663 struct ipw_network_match match = {
5664 .network = priv->assoc_network
5665 };
5666
James Ketrenosafbf30a2005-08-25 00:05:33 -05005667 if ((priv->status & STATUS_ASSOCIATED) &&
5668 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005669 /* First pass through ROAM process -- look for a better
5670 * network */
5671 unsigned long flags;
5672
5673 spin_lock_irqsave(&priv->ieee->lock, flags);
5674 list_for_each_entry(network, &priv->ieee->network_list, list) {
5675 if (network != priv->assoc_network)
5676 ipw_find_adhoc_network(priv, &match, network,
5677 1);
5678 }
5679 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5680
5681 if (match.network == priv->assoc_network) {
5682 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5683 "merge to.\n");
5684 return;
5685 }
5686
Zhu Yi46441512006-01-24 16:37:59 +08005687 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005688 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5689 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005690 print_ssid(ssid, priv->essid,
5691 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005692 ipw_remove_current_network(priv);
5693 }
5694
5695 ipw_disassociate(priv);
5696 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005697 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005698 return;
5699 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005700}
5701
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005702static int ipw_best_network(struct ipw_priv *priv,
5703 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005704 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005705{
5706 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005707 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005708
5709 /* Verify that this network's capability is compatible with the
5710 * current mode (AdHoc or Infrastructure) */
5711 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005712 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005713 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5714 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005715 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005716 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005717 print_ssid(ssid, network->ssid,
5718 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005719 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005720 return 0;
5721 }
5722
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 if (unlikely(roaming)) {
5724 /* If we are roaming, then ensure check if this is a valid
5725 * network to try and roam to */
5726 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005727 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005728 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005729 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005730 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005731 print_ssid(ssid, network->ssid,
5732 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005733 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005734 return 0;
5735 }
5736 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005737 /* If an ESSID has been configured then compare the broadcast
5738 * ESSID to ours */
5739 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005740 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005741 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005742 min(network->ssid_len, priv->essid_len)))) {
5743 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005744 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005745 print_ssid(ssid, network->ssid,
5746 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005748 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005749 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005750 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005751 print_ssid(ssid, priv->essid,
5752 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005753 return 0;
5754 }
5755 }
5756
5757 /* If the old network rate is better than this one, don't bother
5758 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005759 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005760 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005761 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005762 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005763 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005764 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5765 "'%s (%pM)' has a stronger signal.\n",
5766 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005767 print_ssid(ssid, match->network->ssid,
5768 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005769 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005770 return 0;
5771 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005772
James Ketrenos43f66a62005-03-25 12:31:53 -06005773 /* If this network has already had an association attempt within the
5774 * last 3 seconds, do not try and associate again... */
5775 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005776 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005777 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005778 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005779 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005780 print_ssid(ssid, network->ssid,
5781 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005782 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005783 jiffies_to_msecs(jiffies -
5784 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005785 return 0;
5786 }
5787
5788 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005789 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005790 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005791 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005792 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005793 print_ssid(ssid, network->ssid,
5794 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005795 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005796 jiffies_to_msecs(jiffies -
5797 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005798 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005799 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005800
Jeff Garzikbf794512005-07-31 13:07:26 -04005801 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005802 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005803 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005805 print_ssid(ssid, network->ssid,
5806 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005807 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005808 network->channel, priv->channel);
5809 return 0;
5810 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005811
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005812 /* Verify privacy compatibility */
Jeff Garzikbf794512005-07-31 13:07:26 -04005813 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005814 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005815 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005816 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005817 print_ssid(ssid, network->ssid,
5818 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005819 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005820 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005822 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005823 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005824 return 0;
5825 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005826
5827 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005828 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005829 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5830 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005831 print_ssid(ssid, network->ssid,
5832 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005833 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005834 return 0;
5835 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005836
James Ketrenos43f66a62005-03-25 12:31:53 -06005837 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005838 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005839 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005840 "because of invalid frequency/mode "
5841 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005842 print_ssid(ssid, network->ssid,
5843 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005844 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005845 return 0;
5846 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005847
Liu Hong1fe0adb2005-08-19 09:33:10 -05005848 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005849 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005850 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005851 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005852 print_ssid(ssid, network->ssid,
5853 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005854 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005855 return 0;
5856 }
5857
James Ketrenosea2b26e2005-08-24 21:25:16 -05005858 /* Ensure that the rates supported by the driver are compatible with
5859 * this AP, including verification of basic rates (mandatory) */
5860 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005861 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005862 "because configured rate mask excludes "
5863 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005864 print_ssid(ssid, network->ssid,
5865 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005866 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005867 return 0;
5868 }
5869
James Ketrenos43f66a62005-03-25 12:31:53 -06005870 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005871 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005872 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005873 print_ssid(ssid, network->ssid,
5874 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005875 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005876 return 0;
5877 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005878
James Ketrenos43f66a62005-03-25 12:31:53 -06005879 /* TODO: Perform any further minimal comparititive tests. We do not
5880 * want to put too much policy logic here; intelligent scan selection
5881 * should occur within a generic IEEE 802.11 user space tool. */
5882
5883 /* Set up 'new' AP to this network */
5884 ipw_copy_rates(&match->rates, &rates);
5885 match->network = network;
5886
Johannes Berge1749612008-10-27 15:59:26 -07005887 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005888 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005889 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005890
5891 return 1;
5892}
5893
Jeff Garzikbf794512005-07-31 13:07:26 -04005894static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005895 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005896{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005897 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005898 int i;
5899
James Ketrenos43f66a62005-03-25 12:31:53 -06005900 /*
5901 * For the purposes of scanning, we can set our wireless mode
5902 * to trigger scans across combinations of bands, but when it
5903 * comes to creating a new ad-hoc network, we have tell the FW
5904 * exactly which band to use.
5905 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005906 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005907 * chossen band. Attempting to create a new ad-hoc network
5908 * with an invalid channel for wireless mode will trigger a
5909 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005910 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005911 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005912 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5913 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005914 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005915 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005916 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005917 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005918 IPW_WARNING("Overriding invalid channel\n");
5919 priv->channel = geo->a[0].channel;
5920 }
5921 break;
5922
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005923 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005924 if (priv->ieee->mode & IEEE_G)
5925 network->mode = IEEE_G;
5926 else
5927 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005928 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005929 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005930 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005931 IPW_WARNING("Overriding invalid channel\n");
5932 priv->channel = geo->bg[0].channel;
5933 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005934 break;
5935
5936 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005937 IPW_WARNING("Overriding invalid channel\n");
5938 if (priv->ieee->mode & IEEE_A) {
5939 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005940 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005941 } else if (priv->ieee->mode & IEEE_G) {
5942 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005943 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005944 } else {
5945 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005946 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005947 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005948 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005949 }
5950
5951 network->channel = priv->channel;
5952 priv->config |= CFG_ADHOC_PERSIST;
5953 ipw_create_bssid(priv, network->bssid);
5954 network->ssid_len = priv->essid_len;
5955 memcpy(network->ssid, priv->essid, priv->essid_len);
5956 memset(&network->stats, 0, sizeof(network->stats));
5957 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005958 if (!(priv->config & CFG_PREAMBLE_LONG))
5959 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005960 if (priv->capability & CAP_PRIVACY_ON)
5961 network->capability |= WLAN_CAPABILITY_PRIVACY;
5962 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005963 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005964 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005965 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005966 &priv->rates.supported_rates[network->rates_len],
5967 network->rates_ex_len);
5968 network->last_scanned = 0;
5969 network->flags = 0;
5970 network->last_associate = 0;
5971 network->time_stamp[0] = 0;
5972 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005973 network->beacon_interval = 100; /* Default */
5974 network->listen_interval = 10; /* Default */
5975 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005976 network->wpa_ie_len = 0;
5977 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005978}
5979
James Ketrenosb095c382005-08-24 22:04:42 -05005980static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5981{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005982 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005983
5984 if (!(priv->ieee->sec.flags & (1 << index)))
5985 return;
5986
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005987 key.key_id = index;
5988 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5989 key.security_type = type;
5990 key.station_index = 0; /* always 0 for BSS */
5991 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005992 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005993 key.tx_counter[0] = cpu_to_le32(0);
5994 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005995
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005996 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005997}
5998
5999static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06006000{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006001 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006002 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006003
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006004 key.cmd_id = DINO_CMD_WEP_KEY;
6005 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006006
James Ketrenosb095c382005-08-24 22:04:42 -05006007 /* Note: AES keys cannot be set for multiple times.
6008 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006009 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006010 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006011 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006012 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006013 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006014 }
6015
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006016 key.key_size = priv->ieee->sec.key_sizes[i];
6017 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006018
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006019 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006020 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006021}
6022
Zhu Yi1fbfea52005-08-05 17:22:56 +08006023static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6024{
6025 if (priv->ieee->host_encrypt)
6026 return;
6027
6028 switch (level) {
6029 case SEC_LEVEL_3:
6030 priv->sys_config.disable_unicast_decryption = 0;
6031 priv->ieee->host_decrypt = 0;
6032 break;
6033 case SEC_LEVEL_2:
6034 priv->sys_config.disable_unicast_decryption = 1;
6035 priv->ieee->host_decrypt = 1;
6036 break;
6037 case SEC_LEVEL_1:
6038 priv->sys_config.disable_unicast_decryption = 0;
6039 priv->ieee->host_decrypt = 0;
6040 break;
6041 case SEC_LEVEL_0:
6042 priv->sys_config.disable_unicast_decryption = 1;
6043 break;
6044 default:
6045 break;
6046 }
6047}
6048
6049static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6050{
6051 if (priv->ieee->host_encrypt)
6052 return;
6053
6054 switch (level) {
6055 case SEC_LEVEL_3:
6056 priv->sys_config.disable_multicast_decryption = 0;
6057 break;
6058 case SEC_LEVEL_2:
6059 priv->sys_config.disable_multicast_decryption = 1;
6060 break;
6061 case SEC_LEVEL_1:
6062 priv->sys_config.disable_multicast_decryption = 0;
6063 break;
6064 case SEC_LEVEL_0:
6065 priv->sys_config.disable_multicast_decryption = 1;
6066 break;
6067 default:
6068 break;
6069 }
6070}
6071
James Ketrenosb095c382005-08-24 22:04:42 -05006072static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6073{
6074 switch (priv->ieee->sec.level) {
6075 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006076 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6077 ipw_send_tgi_tx_key(priv,
6078 DCT_FLAG_EXT_SECURITY_CCM,
6079 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006080
Hong Liu567deaf2005-08-31 18:07:22 +08006081 if (!priv->ieee->host_mc_decrypt)
6082 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006083 break;
6084 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006085 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6086 ipw_send_tgi_tx_key(priv,
6087 DCT_FLAG_EXT_SECURITY_TKIP,
6088 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006089 break;
6090 case SEC_LEVEL_1:
6091 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006092 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6093 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006094 break;
6095 case SEC_LEVEL_0:
6096 default:
6097 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006098 }
6099}
6100
6101static void ipw_adhoc_check(void *data)
6102{
6103 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006104
James Ketrenosafbf30a2005-08-25 00:05:33 -05006105 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006106 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006107 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6108 IPW_DL_STATE | IPW_DL_ASSOC,
6109 "Missed beacon: %d - disassociate\n",
6110 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006111 ipw_remove_current_network(priv);
6112 ipw_disassociate(priv);
6113 return;
6114 }
6115
Tejun Heobcb6d912011-01-26 12:12:50 +01006116 schedule_delayed_work(&priv->adhoc_check,
6117 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006118}
6119
David Howellsc4028952006-11-22 14:57:56 +00006120static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006121{
David Howellsc4028952006-11-22 14:57:56 +00006122 struct ipw_priv *priv =
6123 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006124 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006125 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006126 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006127}
6128
James Ketrenos43f66a62005-03-25 12:31:53 -06006129static void ipw_debug_config(struct ipw_priv *priv)
6130{
John W. Linville9387b7c2008-09-30 20:59:05 -04006131 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006132 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6133 "[CFG 0x%08X]\n", priv->config);
6134 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006135 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006136 else
6137 IPW_DEBUG_INFO("Channel unlocked.\n");
6138 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006139 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006140 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006141 else
6142 IPW_DEBUG_INFO("ESSID unlocked.\n");
6143 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006144 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006145 else
6146 IPW_DEBUG_INFO("BSSID unlocked.\n");
6147 if (priv->capability & CAP_PRIVACY_ON)
6148 IPW_DEBUG_INFO("PRIVACY on\n");
6149 else
6150 IPW_DEBUG_INFO("PRIVACY off\n");
6151 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6152}
James Ketrenos43f66a62005-03-25 12:31:53 -06006153
Arjan van de Ven858119e2006-01-14 13:20:43 -08006154static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006155{
6156 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006157 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006158 u32 reg;
6159 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006160 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006161
Jeff Garzikbf794512005-07-31 13:07:26 -04006162 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006163 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006164
James Ketrenos43f66a62005-03-25 12:31:53 -06006165 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006166 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006167 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006168 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006169 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006170 IPW_DEBUG_WX
6171 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006172 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006173 break;
6174 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006175
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006176 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006177 break;
6178
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006179 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006180 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006181 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006182 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006183 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006184 IPW_DEBUG_WX
6185 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006186 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006187 }
6188 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006189 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006190
6191 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006192 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6193 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006194 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195 IPW_DEBUG_WX
6196 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006197 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006198 break;
6199 }
6200
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006201 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6202 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6203 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006204 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006205
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006206 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6207 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6208 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006209 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006210
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006211 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6212 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6213 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006214 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006215
Reinette Chatre21f8a732009-08-18 10:25:05 -07006216 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006217 break;
6218 }
6219
Reinette Chatre21f8a732009-08-18 10:25:05 -07006220 fr.tx_rates = cpu_to_le16(new_tx_rates);
6221
James Ketrenos43f66a62005-03-25 12:31:53 -06006222 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006223 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006224}
6225
James Ketrenosea2b26e2005-08-24 21:25:16 -05006226static void ipw_abort_scan(struct ipw_priv *priv)
6227{
6228 int err;
6229
6230 if (priv->status & STATUS_SCAN_ABORTING) {
6231 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6232 return;
6233 }
6234 priv->status |= STATUS_SCAN_ABORTING;
6235
6236 err = ipw_send_scan_abort(priv);
6237 if (err)
6238 IPW_DEBUG_HC("Request to abort scan failed.\n");
6239}
6240
James Ketrenosafbf30a2005-08-25 00:05:33 -05006241static void ipw_add_scan_channels(struct ipw_priv *priv,
6242 struct ipw_scan_request_ext *scan,
6243 int scan_type)
6244{
6245 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006246 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006247 int i;
6248
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006249 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006250
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006251 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006252 int start = channel_index;
6253 for (i = 0; i < geo->a_channels; i++) {
6254 if ((priv->status & STATUS_ASSOCIATED) &&
6255 geo->a[i].channel == priv->channel)
6256 continue;
6257 channel_index++;
6258 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006259 ipw_set_scan_type(scan, channel_index,
6260 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006261 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006262 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6263 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006264 }
6265
6266 if (start != channel_index) {
6267 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6268 (channel_index - start);
6269 channel_index++;
6270 }
6271 }
6272
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006273 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006274 int start = channel_index;
6275 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006276 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006277 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006278 /* nop out the list */
6279 [0] = 0
6280 };
6281
6282 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006283 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006284 channel =
6285 priv->speed_scan[priv->speed_scan_pos];
6286 if (channel == 0) {
6287 priv->speed_scan_pos = 0;
6288 channel = priv->speed_scan[0];
6289 }
6290 if ((priv->status & STATUS_ASSOCIATED) &&
6291 channel == priv->channel) {
6292 priv->speed_scan_pos++;
6293 continue;
6294 }
6295
6296 /* If this channel has already been
6297 * added in scan, break from loop
6298 * and this will be the first channel
6299 * in the next scan.
6300 */
6301 if (channels[channel - 1] != 0)
6302 break;
6303
6304 channels[channel - 1] = 1;
6305 priv->speed_scan_pos++;
6306 channel_index++;
6307 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006308 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006309 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006310 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006311 geo->bg[index].
6312 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006313 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006314 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6315 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006316 }
6317 } else {
6318 for (i = 0; i < geo->bg_channels; i++) {
6319 if ((priv->status & STATUS_ASSOCIATED) &&
6320 geo->bg[i].channel == priv->channel)
6321 continue;
6322 channel_index++;
6323 scan->channels_list[channel_index] =
6324 geo->bg[i].channel;
6325 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006326 geo->bg[i].
6327 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006328 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006329 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6330 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006331 }
6332 }
6333
6334 if (start != channel_index) {
6335 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6336 (channel_index - start);
6337 }
6338 }
6339}
6340
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006341static int ipw_passive_dwell_time(struct ipw_priv *priv)
6342{
6343 /* staying on passive channels longer than the DTIM interval during a
6344 * scan, while associated, causes the firmware to cancel the scan
6345 * without notification. Hence, don't stay on passive channels longer
6346 * than the beacon interval.
6347 */
6348 if (priv->status & STATUS_ASSOCIATED
6349 && priv->assoc_network->beacon_interval > 10)
6350 return priv->assoc_network->beacon_interval - 10;
6351 else
6352 return 120;
6353}
6354
Dan Williamsea177302008-06-02 17:51:23 -04006355static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006356{
6357 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006358 int err = 0, scan_type;
6359
6360 if (!(priv->status & STATUS_INIT) ||
6361 (priv->status & STATUS_EXIT_PENDING))
6362 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006363
Zhu Yi46441512006-01-24 16:37:59 +08006364 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006365
Dan Williamsea177302008-06-02 17:51:23 -04006366 if (direct && (priv->direct_scan_ssid_len == 0)) {
6367 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6368 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6369 goto done;
6370 }
6371
James Ketrenosea2b26e2005-08-24 21:25:16 -05006372 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006373 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6374 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6375 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006376 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006377 }
6378
James Ketrenosafbf30a2005-08-25 00:05:33 -05006379 if (!(priv->status & STATUS_SCAN_FORCED) &&
6380 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006381 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006382 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6383 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006384 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006385 }
6386
6387 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006388 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6389 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6390 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006391 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006392 }
6393
6394 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006395 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006396
Zhu Yi094c4d22006-08-21 11:39:03 +08006397 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006398 IPW_DEBUG_WX("use passive scanning\n");
6399 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006400 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006401 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006402 ipw_add_scan_channels(priv, &scan, scan_type);
6403 goto send_request;
6404 }
6405
6406 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006407 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006408 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006409 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006410 else
6411 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006412 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006413
James Ketrenosa613bff2005-08-24 21:43:11 -05006414 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006415 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006416
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006417 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6418 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006419 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006420
James Ketrenosb095c382005-08-24 22:04:42 -05006421#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006422 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006423 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006424 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006425
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006426 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6427 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006428 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006429 channel = priv->channel;
6430 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006431
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006432 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006433 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006434 channel = priv->channel;
6435 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006436
James Ketrenosb095c382005-08-24 22:04:42 -05006437 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006438 band = (u8) (IPW_B_MODE << 6) | 1;
6439 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006440 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006441 }
6442
James Ketrenosb095c382005-08-24 22:04:42 -05006443 scan.channels_list[0] = band;
6444 scan.channels_list[1] = channel;
6445 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006446
James Ketrenosb095c382005-08-24 22:04:42 -05006447 /* NOTE: The card will sit on this channel for this time
6448 * period. Scan aborts are timing sensitive and frequently
6449 * result in firmware restarts. As such, it is best to
6450 * set a small dwell_time here and just keep re-issuing
6451 * scans. Otherwise fast channel hopping will not actually
6452 * hop channels.
6453 *
6454 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006455 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006456 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006457 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006458#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006459 /* Honor direct scans first, otherwise if we are roaming make
6460 * this a direct scan for the current network. Finally,
6461 * ensure that every other scan is a fast channel hop scan */
6462 if (direct) {
6463 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6464 priv->direct_scan_ssid_len);
6465 if (err) {
6466 IPW_DEBUG_HC("Attempt to send SSID command "
6467 "failed\n");
6468 goto done;
6469 }
6470
6471 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6472 } else if ((priv->status & STATUS_ROAMING)
6473 || (!(priv->status & STATUS_ASSOCIATED)
6474 && (priv->config & CFG_STATIC_ESSID)
6475 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006476 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6477 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006478 IPW_DEBUG_HC("Attempt to send SSID command "
6479 "failed.\n");
6480 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006481 }
6482
6483 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006484 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006485 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006486
James Ketrenosafbf30a2005-08-25 00:05:33 -05006487 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006488#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006489 }
6490#endif
6491
Zhu Yi094c4d22006-08-21 11:39:03 +08006492send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006493 err = ipw_send_scan_request_ext(priv, &scan);
6494 if (err) {
6495 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006496 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006497 }
6498
6499 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006500 if (direct) {
6501 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6502 priv->direct_scan_ssid_len = 0;
6503 } else
6504 priv->status &= ~STATUS_SCAN_PENDING;
6505
Tejun Heobcb6d912011-01-26 12:12:50 +01006506 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006507done:
Zhu Yi46441512006-01-24 16:37:59 +08006508 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006509 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006510}
6511
David Howellsc4028952006-11-22 14:57:56 +00006512static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006513{
David Howellsc4028952006-11-22 14:57:56 +00006514 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006515 container_of(work, struct ipw_priv, request_passive_scan.work);
6516 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006517}
6518
6519static void ipw_request_scan(struct work_struct *work)
6520{
6521 struct ipw_priv *priv =
6522 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006523 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6524}
6525
6526static void ipw_request_direct_scan(struct work_struct *work)
6527{
6528 struct ipw_priv *priv =
6529 container_of(work, struct ipw_priv, request_direct_scan.work);
6530 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006531}
6532
6533static void ipw_bg_abort_scan(struct work_struct *work)
6534{
6535 struct ipw_priv *priv =
6536 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006537 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006538 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006539 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006540}
6541
James Ketrenosea2b26e2005-08-24 21:25:16 -05006542static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6543{
James Ketrenosb095c382005-08-24 22:04:42 -05006544 /* This is called when wpa_supplicant loads and closes the driver
6545 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006546 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006547 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006548}
6549
James Ketrenosea2b26e2005-08-24 21:25:16 -05006550static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6551{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006552 struct libipw_device *ieee = priv->ieee;
6553 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006554 .flags = SEC_AUTH_MODE,
6555 };
6556 int ret = 0;
6557
James Ketrenosafbf30a2005-08-25 00:05:33 -05006558 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006559 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6560 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006561 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006562 sec.auth_mode = WLAN_AUTH_OPEN;
6563 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006564 } else if (value & IW_AUTH_ALG_LEAP) {
6565 sec.auth_mode = WLAN_AUTH_LEAP;
6566 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006567 } else
6568 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569
6570 if (ieee->set_security)
6571 ieee->set_security(ieee->dev, &sec);
6572 else
6573 ret = -EOPNOTSUPP;
6574
6575 return ret;
6576}
6577
Adrian Bunka73e22b2006-01-21 01:39:42 +01006578static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6579 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006580{
6581 /* make sure WPA is enabled */
6582 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006583}
6584
6585static int ipw_set_rsn_capa(struct ipw_priv *priv,
6586 char *capabilities, int length)
6587{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6589
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006590 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006591 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006592}
6593
James Ketrenosafbf30a2005-08-25 00:05:33 -05006594/*
6595 * WE-18 support
6596 */
6597
6598/* SIOCSIWGENIE */
6599static int ipw_wx_set_genie(struct net_device *dev,
6600 struct iw_request_info *info,
6601 union iwreq_data *wrqu, char *extra)
6602{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006603 struct ipw_priv *priv = libipw_priv(dev);
6604 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006605 u8 *buf;
6606 int err = 0;
6607
6608 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6609 (wrqu->data.length && extra == NULL))
6610 return -EINVAL;
6611
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 if (wrqu->data.length) {
Julia Lawalld3e50332010-05-15 23:21:01 +02006613 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006614 if (buf == NULL) {
6615 err = -ENOMEM;
6616 goto out;
6617 }
6618
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 kfree(ieee->wpa_ie);
6620 ieee->wpa_ie = buf;
6621 ieee->wpa_ie_len = wrqu->data.length;
6622 } else {
6623 kfree(ieee->wpa_ie);
6624 ieee->wpa_ie = NULL;
6625 ieee->wpa_ie_len = 0;
6626 }
6627
6628 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6629 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006630 return err;
6631}
6632
6633/* SIOCGIWGENIE */
6634static int ipw_wx_get_genie(struct net_device *dev,
6635 struct iw_request_info *info,
6636 union iwreq_data *wrqu, char *extra)
6637{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006638 struct ipw_priv *priv = libipw_priv(dev);
6639 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006640 int err = 0;
6641
James Ketrenosafbf30a2005-08-25 00:05:33 -05006642 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6643 wrqu->data.length = 0;
6644 goto out;
6645 }
6646
6647 if (wrqu->data.length < ieee->wpa_ie_len) {
6648 err = -E2BIG;
6649 goto out;
6650 }
6651
6652 wrqu->data.length = ieee->wpa_ie_len;
6653 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6654
6655 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006656 return err;
6657}
6658
Zhu Yi1fbfea52005-08-05 17:22:56 +08006659static int wext_cipher2level(int cipher)
6660{
6661 switch (cipher) {
6662 case IW_AUTH_CIPHER_NONE:
6663 return SEC_LEVEL_0;
6664 case IW_AUTH_CIPHER_WEP40:
6665 case IW_AUTH_CIPHER_WEP104:
6666 return SEC_LEVEL_1;
6667 case IW_AUTH_CIPHER_TKIP:
6668 return SEC_LEVEL_2;
6669 case IW_AUTH_CIPHER_CCMP:
6670 return SEC_LEVEL_3;
6671 default:
6672 return -1;
6673 }
6674}
6675
James Ketrenosafbf30a2005-08-25 00:05:33 -05006676/* SIOCSIWAUTH */
6677static int ipw_wx_set_auth(struct net_device *dev,
6678 struct iw_request_info *info,
6679 union iwreq_data *wrqu, char *extra)
6680{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006681 struct ipw_priv *priv = libipw_priv(dev);
6682 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006683 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006684 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006685 unsigned long flags;
6686 int ret = 0;
6687
6688 switch (param->flags & IW_AUTH_INDEX) {
6689 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006690 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006692 ipw_set_hw_decrypt_unicast(priv,
6693 wext_cipher2level(param->value));
6694 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006695 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006696 ipw_set_hw_decrypt_multicast(priv,
6697 wext_cipher2level(param->value));
6698 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006699 case IW_AUTH_KEY_MGMT:
6700 /*
6701 * ipw2200 does not use these parameters
6702 */
6703 break;
6704
6705 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006706 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006707 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006708 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006709
6710 flags = crypt->ops->get_flags(crypt->priv);
6711
6712 if (param->value)
6713 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6714 else
6715 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6716
6717 crypt->ops->set_flags(flags, crypt->priv);
6718
6719 break;
6720
6721 case IW_AUTH_DROP_UNENCRYPTED:{
6722 /* HACK:
6723 *
6724 * wpa_supplicant calls set_wpa_enabled when the driver
6725 * is loaded and unloaded, regardless of if WPA is being
6726 * used. No other calls are made which can be used to
6727 * determine if encryption will be used or not prior to
6728 * association being expected. If encryption is not being
6729 * used, drop_unencrypted is set to false, else true -- we
6730 * can use this to determine if the CAP_PRIVACY_ON bit should
6731 * be set.
6732 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006733 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006734 .flags = SEC_ENABLED,
6735 .enabled = param->value,
6736 };
6737 priv->ieee->drop_unencrypted = param->value;
6738 /* We only change SEC_LEVEL for open mode. Others
6739 * are set by ipw_wpa_set_encryption.
6740 */
6741 if (!param->value) {
6742 sec.flags |= SEC_LEVEL;
6743 sec.level = SEC_LEVEL_0;
6744 } else {
6745 sec.flags |= SEC_LEVEL;
6746 sec.level = SEC_LEVEL_1;
6747 }
6748 if (priv->ieee->set_security)
6749 priv->ieee->set_security(priv->ieee->dev, &sec);
6750 break;
6751 }
6752
6753 case IW_AUTH_80211_AUTH_ALG:
6754 ret = ipw_wpa_set_auth_algs(priv, param->value);
6755 break;
6756
6757 case IW_AUTH_WPA_ENABLED:
6758 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006759 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006760 break;
6761
6762 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6763 ieee->ieee802_1x = param->value;
6764 break;
6765
James Ketrenosafbf30a2005-08-25 00:05:33 -05006766 case IW_AUTH_PRIVACY_INVOKED:
6767 ieee->privacy_invoked = param->value;
6768 break;
6769
6770 default:
6771 return -EOPNOTSUPP;
6772 }
6773 return ret;
6774}
6775
6776/* SIOCGIWAUTH */
6777static int ipw_wx_get_auth(struct net_device *dev,
6778 struct iw_request_info *info,
6779 union iwreq_data *wrqu, char *extra)
6780{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006781 struct ipw_priv *priv = libipw_priv(dev);
6782 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006783 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006784 struct iw_param *param = &wrqu->param;
6785 int ret = 0;
6786
6787 switch (param->flags & IW_AUTH_INDEX) {
6788 case IW_AUTH_WPA_VERSION:
6789 case IW_AUTH_CIPHER_PAIRWISE:
6790 case IW_AUTH_CIPHER_GROUP:
6791 case IW_AUTH_KEY_MGMT:
6792 /*
6793 * wpa_supplicant will control these internally
6794 */
6795 ret = -EOPNOTSUPP;
6796 break;
6797
6798 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006799 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006800 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006801 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006802
6803 param->value = (crypt->ops->get_flags(crypt->priv) &
6804 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6805
6806 break;
6807
6808 case IW_AUTH_DROP_UNENCRYPTED:
6809 param->value = ieee->drop_unencrypted;
6810 break;
6811
6812 case IW_AUTH_80211_AUTH_ALG:
6813 param->value = ieee->sec.auth_mode;
6814 break;
6815
6816 case IW_AUTH_WPA_ENABLED:
6817 param->value = ieee->wpa_enabled;
6818 break;
6819
6820 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6821 param->value = ieee->ieee802_1x;
6822 break;
6823
6824 case IW_AUTH_ROAMING_CONTROL:
6825 case IW_AUTH_PRIVACY_INVOKED:
6826 param->value = ieee->privacy_invoked;
6827 break;
6828
6829 default:
6830 return -EOPNOTSUPP;
6831 }
6832 return 0;
6833}
6834
6835/* SIOCSIWENCODEEXT */
6836static int ipw_wx_set_encodeext(struct net_device *dev,
6837 struct iw_request_info *info,
6838 union iwreq_data *wrqu, char *extra)
6839{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006840 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006841 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6842
6843 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006844 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006845 /* IPW HW can't build TKIP MIC,
6846 host decryption still needed */
6847 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6848 priv->ieee->host_mc_decrypt = 1;
6849 else {
6850 priv->ieee->host_encrypt = 0;
6851 priv->ieee->host_encrypt_msdu = 1;
6852 priv->ieee->host_decrypt = 1;
6853 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006854 } else {
6855 priv->ieee->host_encrypt = 0;
6856 priv->ieee->host_encrypt_msdu = 0;
6857 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006858 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006859 }
6860 }
6861
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006862 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006863}
6864
6865/* SIOCGIWENCODEEXT */
6866static int ipw_wx_get_encodeext(struct net_device *dev,
6867 struct iw_request_info *info,
6868 union iwreq_data *wrqu, char *extra)
6869{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006870 struct ipw_priv *priv = libipw_priv(dev);
6871 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006872}
6873
6874/* SIOCSIWMLME */
6875static int ipw_wx_set_mlme(struct net_device *dev,
6876 struct iw_request_info *info,
6877 union iwreq_data *wrqu, char *extra)
6878{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006879 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006880 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006881 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006882
6883 reason = cpu_to_le16(mlme->reason_code);
6884
6885 switch (mlme->cmd) {
6886 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006887 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006888 break;
6889
6890 case IW_MLME_DISASSOC:
6891 ipw_disassociate(priv);
6892 break;
6893
6894 default:
6895 return -EOPNOTSUPP;
6896 }
6897 return 0;
6898}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006899
Zhu Yie43e3c12006-04-13 17:20:45 +08006900#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006901
6902/* QoS */
6903/*
6904* get the modulation type of the current network or
6905* the card current mode
6906*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006907static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006908{
6909 u8 mode = 0;
6910
6911 if (priv->status & STATUS_ASSOCIATED) {
6912 unsigned long flags;
6913
6914 spin_lock_irqsave(&priv->ieee->lock, flags);
6915 mode = priv->assoc_network->mode;
6916 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6917 } else {
6918 mode = priv->ieee->mode;
6919 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006920 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006921 return mode;
6922}
6923
6924/*
6925* Handle management frame beacon and probe response
6926*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006927static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6928 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006929 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006930{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006931 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006932
James Ketrenosafbf30a2005-08-25 00:05:33 -05006933 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006934 network->qos_data.active = network->qos_data.supported;
6935
6936 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006937 if (active_network &&
6938 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006939 network->qos_data.active = network->qos_data.supported;
6940
6941 if ((network->qos_data.active == 1) && (active_network == 1) &&
6942 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6943 (network->qos_data.old_param_count !=
6944 network->qos_data.param_count)) {
6945 network->qos_data.old_param_count =
6946 network->qos_data.param_count;
6947 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006948 IPW_DEBUG_QOS("QoS parameters change call "
6949 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006950 }
6951 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006952 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6953 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006954 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006955 else
6956 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006957 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006958
James Ketrenosb095c382005-08-24 22:04:42 -05006959 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006960 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006961 schedule_work(&priv->qos_activate);
6962 }
6963
6964 network->qos_data.active = 0;
6965 network->qos_data.supported = 0;
6966 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006967 if ((priv->status & STATUS_ASSOCIATED) &&
6968 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6969 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006970 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006971 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006972 priv->assoc_network->ssid_len) &&
6973 !memcmp(network->ssid,
6974 priv->assoc_network->ssid,
6975 network->ssid_len)) {
Tejun Heobcb6d912011-01-26 12:12:50 +01006976 schedule_work(&priv->merge_networks);
James Ketrenosb095c382005-08-24 22:04:42 -05006977 }
James Ketrenosb095c382005-08-24 22:04:42 -05006978 }
6979
6980 return 0;
6981}
6982
6983/*
6984* This function set up the firmware to support QoS. It sends
6985* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6986*/
6987static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006988 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006989{
6990 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006991 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6992 struct libipw_qos_parameters *active_one = NULL;
6993 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006994 u32 burst_duration;
6995 int i;
6996 u8 type;
6997
6998 type = ipw_qos_current_mode(priv);
6999
7000 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7001 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7002 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7003 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7004
7005 if (qos_network_data == NULL) {
7006 if (type == IEEE_B) {
7007 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7008 active_one = &def_parameters_CCK;
7009 } else
7010 active_one = &def_parameters_OFDM;
7011
James Ketrenosafbf30a2005-08-25 00:05:33 -05007012 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007013 burst_duration = ipw_qos_get_burst_duration(priv);
7014 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007015 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007016 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007017 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007018 if (type == IEEE_B) {
7019 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7020 type);
7021 if (priv->qos_data.qos_enable == 0)
7022 active_one = &def_parameters_CCK;
7023 else
7024 active_one = priv->qos_data.def_qos_parm_CCK;
7025 } else {
7026 if (priv->qos_data.qos_enable == 0)
7027 active_one = &def_parameters_OFDM;
7028 else
7029 active_one = priv->qos_data.def_qos_parm_OFDM;
7030 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007031 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007032 } else {
7033 unsigned long flags;
7034 int active;
7035
7036 spin_lock_irqsave(&priv->ieee->lock, flags);
7037 active_one = &(qos_network_data->parameters);
7038 qos_network_data->old_param_count =
7039 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007040 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007041 active = qos_network_data->supported;
7042 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7043
7044 if (active == 0) {
7045 burst_duration = ipw_qos_get_burst_duration(priv);
7046 for (i = 0; i < QOS_QUEUE_NUM; i++)
7047 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007048 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007049 }
7050 }
7051
7052 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007053 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007054 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007055 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007056 if (err)
7057 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7058
7059 return err;
7060}
7061
7062/*
7063* send IPW_CMD_WME_INFO to the firmware
7064*/
7065static int ipw_qos_set_info_element(struct ipw_priv *priv)
7066{
7067 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007068 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007069
7070 if (priv == NULL)
7071 return -1;
7072
7073 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007074 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007075
7076 qos_info.version = QOS_VERSION_1;
7077 qos_info.ac_info = 0;
7078
7079 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7080 qos_info.qui_type = QOS_OUI_TYPE;
7081 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7082
7083 ret = ipw_send_qos_info_command(priv, &qos_info);
7084 if (ret != 0) {
7085 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7086 }
7087 return ret;
7088}
7089
7090/*
7091* Set the QoS parameter with the association request structure
7092*/
7093static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007094 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007095{
7096 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007097 struct libipw_qos_data *qos_data = NULL;
7098 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007099 .supported = 1,
7100 .active = 1,
7101 };
7102
7103 switch (priv->ieee->iw_mode) {
7104 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007105 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007106
7107 qos_data = &ibss_data;
7108 break;
7109
7110 case IW_MODE_INFRA:
7111 qos_data = &network->qos_data;
7112 break;
7113
7114 default:
7115 BUG();
7116 break;
7117 }
7118
7119 err = ipw_qos_activate(priv, qos_data);
7120 if (err) {
7121 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7122 return err;
7123 }
7124
7125 if (priv->qos_data.qos_enable && qos_data->supported) {
7126 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7127 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7128 return ipw_qos_set_info_element(priv);
7129 }
7130
7131 return 0;
7132}
7133
7134/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007135* handling the beaconing responses. if we get different QoS setting
7136* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007137* setting
7138*/
7139static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007140 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007141{
7142 int ret = 0;
7143 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007144 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007145 int set_qos_param = 0;
7146
James Ketrenosafbf30a2005-08-25 00:05:33 -05007147 if ((priv == NULL) || (network == NULL) ||
7148 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007149 return ret;
7150
7151 if (!(priv->status & STATUS_ASSOCIATED))
7152 return ret;
7153
James Ketrenosafbf30a2005-08-25 00:05:33 -05007154 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007155 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007156
7157 spin_lock_irqsave(&priv->ieee->lock, flags);
7158 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007159 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007160 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007161 priv->assoc_network->qos_data.active = 1;
7162 if ((network->qos_data.old_param_count !=
7163 network->qos_data.param_count)) {
7164 set_qos_param = 1;
7165 network->qos_data.old_param_count =
7166 network->qos_data.param_count;
7167 }
7168
7169 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007170 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7171 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007172 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007173 else
7174 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007175 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007176 priv->assoc_network->qos_data.active = 0;
7177 priv->assoc_network->qos_data.supported = 0;
7178 set_qos_param = 1;
7179 }
7180
7181 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7182
7183 if (set_qos_param == 1)
7184 schedule_work(&priv->qos_activate);
7185
7186 return ret;
7187}
7188
7189static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7190{
7191 u32 ret = 0;
7192
7193 if ((priv == NULL))
7194 return 0;
7195
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007196 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007197 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007198 else
James Ketrenosb095c382005-08-24 22:04:42 -05007199 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007200
James Ketrenosb095c382005-08-24 22:04:42 -05007201 return ret;
7202}
7203
7204/*
7205* Initialize the setting of QoS global
7206*/
7207static void ipw_qos_init(struct ipw_priv *priv, int enable,
7208 int burst_enable, u32 burst_duration_CCK,
7209 u32 burst_duration_OFDM)
7210{
7211 priv->qos_data.qos_enable = enable;
7212
7213 if (priv->qos_data.qos_enable) {
7214 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7215 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7216 IPW_DEBUG_QOS("QoS is enabled\n");
7217 } else {
7218 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7219 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7220 IPW_DEBUG_QOS("QoS is not enabled\n");
7221 }
7222
7223 priv->qos_data.burst_enable = burst_enable;
7224
7225 if (burst_enable) {
7226 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7227 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7228 } else {
7229 priv->qos_data.burst_duration_CCK = 0;
7230 priv->qos_data.burst_duration_OFDM = 0;
7231 }
7232}
7233
7234/*
7235* map the packet priority to the right TX Queue
7236*/
7237static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7238{
7239 if (priority > 7 || !priv->qos_data.qos_enable)
7240 priority = 0;
7241
7242 return from_priority_to_tx_queue[priority] - 1;
7243}
7244
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007245static int ipw_is_qos_active(struct net_device *dev,
7246 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007247{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007248 struct ipw_priv *priv = libipw_priv(dev);
7249 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007250 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007251 u8 *daddr = skb->data + ETH_ALEN;
7252 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007253
7254 if (!(priv->status & STATUS_ASSOCIATED))
7255 return 0;
7256
7257 qos_data = &priv->assoc_network->qos_data;
7258
James Ketrenosb095c382005-08-24 22:04:42 -05007259 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7260 if (unicast == 0)
7261 qos_data->active = 0;
7262 else
7263 qos_data->active = qos_data->supported;
7264 }
James Ketrenosb095c382005-08-24 22:04:42 -05007265 active = qos_data->active;
7266 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007267 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7268 "unicast %d\n",
7269 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007270 if (active && priv->qos_data.qos_enable)
7271 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007272
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007273 return 0;
7274
7275}
7276/*
7277* add QoS parameter to the TX command
7278*/
7279static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7280 u16 priority,
7281 struct tfd_data *tfd)
7282{
7283 int tx_queue_id = 0;
7284
7285
7286 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7287 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7288
7289 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7290 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007291 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007292 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007293 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007294}
7295
7296/*
7297* background support to run QoS activate functionality
7298*/
David Howellsc4028952006-11-22 14:57:56 +00007299static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007300{
David Howellsc4028952006-11-22 14:57:56 +00007301 struct ipw_priv *priv =
7302 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007303
Zhu Yi46441512006-01-24 16:37:59 +08007304 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007305
7306 if (priv->status & STATUS_ASSOCIATED)
7307 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7308
Zhu Yi46441512006-01-24 16:37:59 +08007309 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007310}
7311
James Ketrenos3b9990c2005-08-19 13:18:55 -05007312static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007313 struct libipw_probe_response *resp,
7314 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007315{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007316 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007317 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7318 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007319
James Ketrenos3b9990c2005-08-19 13:18:55 -05007320 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007321
James Ketrenos3b9990c2005-08-19 13:18:55 -05007322 return 0;
7323}
James Ketrenosb095c382005-08-24 22:04:42 -05007324
James Ketrenos3b9990c2005-08-19 13:18:55 -05007325static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007326 struct libipw_beacon *resp,
7327 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007328{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007329 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007330 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7331 (network == priv->assoc_network));
7332
7333 ipw_qos_handle_probe_response(priv, active_network, network);
7334
7335 return 0;
7336}
7337
7338static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007339 struct libipw_assoc_response *resp,
7340 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007341{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007342 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007343 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007344 return 0;
7345}
7346
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007347static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007348 *qos_param)
7349{
Zhu Yi4e226992006-01-24 16:37:36 +08007350 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7351 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007352}
7353
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007354static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007355 *qos_param)
7356{
Zhu Yi4e226992006-01-24 16:37:36 +08007357 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7358 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007359}
7360
Zhu Yie43e3c12006-04-13 17:20:45 +08007361#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007362
James Ketrenos43f66a62005-03-25 12:31:53 -06007363static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007364 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007365 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007366{
7367 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007368 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007369
7370 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007371 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007372
7373 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007374 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007375 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007376 memcpy(priv->essid, network->ssid, priv->essid_len);
7377 }
7378
7379 network->last_associate = jiffies;
7380
7381 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7382 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007383 priv->assoc_request.auth_key = 0;
7384
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007386 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007387 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007388 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7389
Zhu Yi1ba61e02006-02-15 13:00:55 +08007390 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007391 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007392
7393 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7394 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7395 priv->assoc_request.auth_type = AUTH_LEAP;
7396 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007397 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007398
James Ketrenosa613bff2005-08-24 21:43:11 -05007399 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007400 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007401 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7402 priv->ieee->wpa_ie_len);
7403 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007404
Jeff Garzikbf794512005-07-31 13:07:26 -04007405 /*
7406 * It is valid for our ieee device to support multiple modes, but
7407 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007408 * just one mode.
7409 */
7410 if (network->mode & priv->ieee->mode & IEEE_A)
7411 priv->assoc_request.ieee_mode = IPW_A_MODE;
7412 else if (network->mode & priv->ieee->mode & IEEE_G)
7413 priv->assoc_request.ieee_mode = IPW_G_MODE;
7414 else if (network->mode & priv->ieee->mode & IEEE_B)
7415 priv->assoc_request.ieee_mode = IPW_B_MODE;
7416
Al Viro5b5e8072007-12-27 01:54:06 -05007417 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007418 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7419 && !(priv->config & CFG_PREAMBLE_LONG)) {
7420 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7421 } else {
7422 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7423
7424 /* Clear the short preamble if we won't be supporting it */
7425 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007426 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007427 }
7428
James Ketrenosafbf30a2005-08-25 00:05:33 -05007429 /* Clear capability bits that aren't used in Ad Hoc */
7430 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7431 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007432 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007433
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02007434 IPW_DEBUG_ASSOC("%ssociation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007435 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007437 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007438 network->channel,
7439 ipw_modes[priv->assoc_request.ieee_mode],
7440 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007441 (priv->assoc_request.preamble_length ==
7442 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7443 network->capability &
7444 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007445 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007446 priv->capability & CAP_PRIVACY_ON ?
7447 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007448 "(open)") : "",
7449 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007450 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007451 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007452 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007453
Al Viro5b5e8072007-12-27 01:54:06 -05007454 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007455 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007456 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007457 priv->assoc_request.assoc_type = HC_IBSS_START;
7458 priv->assoc_request.assoc_tsf_msw = 0;
7459 priv->assoc_request.assoc_tsf_lsw = 0;
7460 } else {
7461 if (unlikely(roaming))
7462 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7463 else
7464 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007465 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7466 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007467 }
7468
James Ketrenosafbf30a2005-08-25 00:05:33 -05007469 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007470
7471 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7472 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007473 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007474 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007475 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007476 priv->assoc_request.atim_window = 0;
7477 }
7478
Al Viro5b5e8072007-12-27 01:54:06 -05007479 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007480
James Ketrenos43f66a62005-03-25 12:31:53 -06007481 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7482 if (err) {
7483 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7484 return err;
7485 }
7486
7487 rates->ieee_mode = priv->assoc_request.ieee_mode;
7488 rates->purpose = IPW_RATE_CONNECT;
7489 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007490
James Ketrenos43f66a62005-03-25 12:31:53 -06007491 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7492 priv->sys_config.dot11g_auto_detection = 1;
7493 else
7494 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007495
7496 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7497 priv->sys_config.answer_broadcast_ssid_probe = 1;
7498 else
7499 priv->sys_config.answer_broadcast_ssid_probe = 0;
7500
Zhu Yid685b8c2006-04-13 17:20:27 +08007501 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007502 if (err) {
7503 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7504 return err;
7505 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007506
James Ketrenos43f66a62005-03-25 12:31:53 -06007507 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007508 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007509 if (err) {
7510 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7511 return err;
7512 }
7513
7514 /*
7515 * If preemption is enabled, it is possible for the association
7516 * to complete before we return from ipw_send_associate. Therefore
7517 * we have to be sure and update our priviate data first.
7518 */
7519 priv->channel = network->channel;
7520 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007521 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007522 priv->status &= ~STATUS_SECURITY_UPDATED;
7523
7524 priv->assoc_network = network;
7525
Zhu Yie43e3c12006-04-13 17:20:45 +08007526#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007527 ipw_qos_association(priv, network);
7528#endif
7529
James Ketrenos43f66a62005-03-25 12:31:53 -06007530 err = ipw_send_associate(priv, &priv->assoc_request);
7531 if (err) {
7532 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7533 return err;
7534 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007535
Frans Pop9fd1ea42010-03-24 19:46:31 +01007536 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007537 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007538 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007539
7540 return 0;
7541}
7542
7543static void ipw_roam(void *data)
7544{
7545 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007546 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007547 struct ipw_network_match match = {
7548 .network = priv->assoc_network
7549 };
7550
7551 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007552 *
7553 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007554 * setting the status ROAM bit and requesting a scan.
7555 * 2. When the scan completes, it schedules the ROAM work
7556 * 3. The ROAM work looks at all of the known networks for one that
7557 * is a better network than the currently associated. If none
7558 * found, the ROAM process is over (ROAM bit cleared)
7559 * 4. If a better network is found, a disassociation request is
7560 * sent.
7561 * 5. When the disassociation completes, the roam work is again
7562 * scheduled. The second time through, the driver is no longer
7563 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007564 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007565 * 6. At this point ,the roaming process is complete and the ROAM
7566 * status bit is cleared.
7567 */
7568
7569 /* If we are no longer associated, and the roaming bit is no longer
7570 * set, then we are not actively roaming, so just return */
7571 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7572 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007573
James Ketrenos43f66a62005-03-25 12:31:53 -06007574 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007575 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007576 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007577 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007578 u8 rssi = priv->assoc_network->stats.rssi;
7579 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007580 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007581 list_for_each_entry(network, &priv->ieee->network_list, list) {
7582 if (network != priv->assoc_network)
7583 ipw_best_network(priv, &match, network, 1);
7584 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007585 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007586 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007587
James Ketrenos43f66a62005-03-25 12:31:53 -06007588 if (match.network == priv->assoc_network) {
7589 IPW_DEBUG_ASSOC("No better APs in this network to "
7590 "roam to.\n");
7591 priv->status &= ~STATUS_ROAMING;
7592 ipw_debug_config(priv);
7593 return;
7594 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007595
James Ketrenos43f66a62005-03-25 12:31:53 -06007596 ipw_send_disassociate(priv, 1);
7597 priv->assoc_network = match.network;
7598
7599 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007600 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007601
7602 /* Second pass through ROAM process -- request association */
7603 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7604 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7605 priv->status &= ~STATUS_ROAMING;
7606}
7607
David Howellsc4028952006-11-22 14:57:56 +00007608static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007609{
David Howellsc4028952006-11-22 14:57:56 +00007610 struct ipw_priv *priv =
7611 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007612 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007613 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007614 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007615}
7616
7617static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007618{
7619 struct ipw_priv *priv = data;
7620
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007621 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007622 struct ipw_network_match match = {
7623 .network = NULL
7624 };
7625 struct ipw_supported_rates *rates;
7626 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007627 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007628 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007629
James Ketrenosb095c382005-08-24 22:04:42 -05007630 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7631 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7632 return 0;
7633 }
7634
James Ketrenosc848d0a2005-08-24 21:56:24 -05007635 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007636 IPW_DEBUG_ASSOC("Not attempting association (already in "
7637 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007638 return 0;
7639 }
7640
Hong Liue6324722005-09-14 21:04:15 -05007641 if (priv->status & STATUS_DISASSOCIATING) {
7642 IPW_DEBUG_ASSOC("Not attempting association (in "
7643 "disassociating)\n ");
Tejun Heobcb6d912011-01-26 12:12:50 +01007644 schedule_work(&priv->associate);
Hong Liue6324722005-09-14 21:04:15 -05007645 return 0;
7646 }
7647
James Ketrenosc848d0a2005-08-24 21:56:24 -05007648 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007649 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7650 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007651 return 0;
7652 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007653
7654 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007655 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007656 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007657 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007658 }
7659
James Ketrenosa613bff2005-08-24 21:43:11 -05007660 /* Protect our use of the network_list */
7661 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007662 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007663 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007664
7665 network = match.network;
7666 rates = &match.rates;
7667
7668 if (network == NULL &&
7669 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7670 priv->config & CFG_ADHOC_CREATE &&
7671 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007672 priv->config & CFG_STATIC_CHANNEL) {
7673 /* Use oldest network if the free list is empty */
7674 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007675 struct libipw_network *oldest = NULL;
7676 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007677
7678 list_for_each_entry(target, &priv->ieee->network_list, list) {
7679 if ((oldest == NULL) ||
7680 (target->last_scanned < oldest->last_scanned))
7681 oldest = target;
7682 }
7683
7684 /* If there are no more slots, expire the oldest */
7685 list_del(&oldest->list);
7686 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007687 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007688 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007689 print_ssid(ssid, target->ssid,
7690 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007691 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007692 list_add_tail(&target->list,
7693 &priv->ieee->network_free_list);
7694 }
7695
James Ketrenos43f66a62005-03-25 12:31:53 -06007696 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007697 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007698 ipw_adhoc_create(priv, network);
7699 rates = &priv->rates;
7700 list_del(element);
7701 list_add_tail(&network->list, &priv->ieee->network_list);
7702 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007703 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007704
James Ketrenos43f66a62005-03-25 12:31:53 -06007705 /* If we reached the end of the list, then we don't have any valid
7706 * matching APs */
7707 if (!network) {
7708 ipw_debug_config(priv);
7709
James Ketrenosb095c382005-08-24 22:04:42 -05007710 if (!(priv->status & STATUS_SCANNING)) {
7711 if (!(priv->config & CFG_SPEED_SCAN))
Tejun Heobcb6d912011-01-26 12:12:50 +01007712 schedule_delayed_work(&priv->request_scan,
7713 SCAN_INTERVAL);
James Ketrenosb095c382005-08-24 22:04:42 -05007714 else
Tejun Heobcb6d912011-01-26 12:12:50 +01007715 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007716 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007717
James Ketrenosc848d0a2005-08-24 21:56:24 -05007718 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007719 }
7720
7721 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007722
7723 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007724}
Jeff Garzikbf794512005-07-31 13:07:26 -04007725
David Howellsc4028952006-11-22 14:57:56 +00007726static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007727{
David Howellsc4028952006-11-22 14:57:56 +00007728 struct ipw_priv *priv =
7729 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007730 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007731 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007732 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007733}
7734
James Ketrenosb095c382005-08-24 22:04:42 -05007735static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7736 struct sk_buff *skb)
7737{
7738 struct ieee80211_hdr *hdr;
7739 u16 fc;
7740
7741 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007742 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007743 if (!(fc & IEEE80211_FCTL_PROTECTED))
7744 return;
7745
7746 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007747 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007748 switch (priv->ieee->sec.level) {
7749 case SEC_LEVEL_3:
7750 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007751 memmove(skb->data + LIBIPW_3ADDR_LEN,
7752 skb->data + LIBIPW_3ADDR_LEN + 8,
7753 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007754 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007755 break;
7756 case SEC_LEVEL_2:
7757 break;
7758 case SEC_LEVEL_1:
7759 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007760 memmove(skb->data + LIBIPW_3ADDR_LEN,
7761 skb->data + LIBIPW_3ADDR_LEN + 4,
7762 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007763 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007764 break;
7765 case SEC_LEVEL_0:
7766 break;
7767 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007768 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007769 priv->ieee->sec.level);
7770 break;
7771 }
7772}
7773
7774static void ipw_handle_data_packet(struct ipw_priv *priv,
7775 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007776 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007777{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007778 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007779 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007780 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7781
7782 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007783 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007784
Jeff Garzikbf794512005-07-31 13:07:26 -04007785 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007786 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007787 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007788 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007789 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007790 priv->wstats.discard.misc++;
7791 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7792 return;
7793 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007794 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007795 priv->wstats.discard.misc++;
7796 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7797 return;
7798 }
7799
7800 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007801 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007802
7803 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007804 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007805
7806 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7807
James Ketrenosb095c382005-08-24 22:04:42 -05007808 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007809 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007810 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007811 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007812 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007813 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7814
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007815 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007816 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007817 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007818 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007819 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007820 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007821}
7822
Zhu Yi459d4082006-04-13 17:21:00 +08007823#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007824static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7825 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007826 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007827{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007828 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007829 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7830 struct ipw_rx_frame *frame = &pkt->u.frame;
7831
7832 /* initial pull of some data */
7833 u16 received_channel = frame->received_channel;
7834 u8 antennaAndPhy = frame->antennaAndPhy;
7835 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7836 u16 pktrate = frame->rate;
7837
7838 /* Magic struct that slots into the radiotap header -- no reason
7839 * to build this manually element by element, we can write it much
7840 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007841 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007842
7843 short len = le16_to_cpu(pkt->u.frame.length);
7844
7845 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007846 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007847
7848 /* We only process data packets if the
7849 * interface is open */
7850 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7851 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007852 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007853 priv->wstats.discard.misc++;
7854 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7855 return;
7856 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007857 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007858 priv->wstats.discard.misc++;
7859 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7860 return;
7861 }
7862
7863 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7864 * that now */
7865 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7866 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007867 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007868 priv->wstats.discard.misc++;
7869 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7870 return;
7871 }
7872
7873 /* copy the frame itself */
7874 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7875 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7876
Mike Kershaw24a47db2005-08-26 00:41:54 -05007877 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7878
7879 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7880 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007881 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007882
7883 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007884 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7885 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007886 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007887 (1 << IEEE80211_RADIOTAP_RATE) |
7888 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7889 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007890 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007891 (1 << IEEE80211_RADIOTAP_ANTENNA));
7892
7893 /* Zero the flags, we'll add to them as we go */
7894 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007895 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7896 frame->parent_tsf[2] << 16 |
7897 frame->parent_tsf[1] << 8 |
7898 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007899
7900 /* Convert signal to DBM */
7901 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007902 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007903
7904 /* Convert the channel data and set the flags */
7905 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7906 if (received_channel > 14) { /* 802.11a */
7907 ipw_rt->rt_chbitmask =
7908 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7909 } else if (antennaAndPhy & 32) { /* 802.11b */
7910 ipw_rt->rt_chbitmask =
7911 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7912 } else { /* 802.11g */
7913 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007914 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007915 }
7916
7917 /* set the rate in multiples of 500k/s */
7918 switch (pktrate) {
7919 case IPW_TX_RATE_1MB:
7920 ipw_rt->rt_rate = 2;
7921 break;
7922 case IPW_TX_RATE_2MB:
7923 ipw_rt->rt_rate = 4;
7924 break;
7925 case IPW_TX_RATE_5MB:
7926 ipw_rt->rt_rate = 10;
7927 break;
7928 case IPW_TX_RATE_6MB:
7929 ipw_rt->rt_rate = 12;
7930 break;
7931 case IPW_TX_RATE_9MB:
7932 ipw_rt->rt_rate = 18;
7933 break;
7934 case IPW_TX_RATE_11MB:
7935 ipw_rt->rt_rate = 22;
7936 break;
7937 case IPW_TX_RATE_12MB:
7938 ipw_rt->rt_rate = 24;
7939 break;
7940 case IPW_TX_RATE_18MB:
7941 ipw_rt->rt_rate = 36;
7942 break;
7943 case IPW_TX_RATE_24MB:
7944 ipw_rt->rt_rate = 48;
7945 break;
7946 case IPW_TX_RATE_36MB:
7947 ipw_rt->rt_rate = 72;
7948 break;
7949 case IPW_TX_RATE_48MB:
7950 ipw_rt->rt_rate = 96;
7951 break;
7952 case IPW_TX_RATE_54MB:
7953 ipw_rt->rt_rate = 108;
7954 break;
7955 default:
7956 ipw_rt->rt_rate = 0;
7957 break;
7958 }
7959
7960 /* antenna number */
7961 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7962
7963 /* set the preamble flag if we have it */
7964 if ((antennaAndPhy & 64))
7965 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7966
7967 /* Set the size of the skb to the size of the frame */
7968 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007969
7970 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7971
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007972 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007973 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007974 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007975 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007976 /* no LED during capture */
7977 }
7978}
7979#endif
7980
Zhu Yid685b8c2006-04-13 17:20:27 +08007981#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007982#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007983 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7984 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7985
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007986#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007987 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7988
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007989#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007990 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7991
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007992#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007993 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7994
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007995#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007996 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7997
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007998#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007999 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8000
8001static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8002 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008003 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008004{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008005 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008006 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8007 struct ipw_rx_frame *frame = &pkt->u.frame;
8008 struct ipw_rt_hdr *ipw_rt;
8009
8010 /* First cache any information we need before we overwrite
8011 * the information provided in the skb from the hardware */
8012 struct ieee80211_hdr *hdr;
8013 u16 channel = frame->received_channel;
8014 u8 phy_flags = frame->antennaAndPhy;
8015 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008016 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008017 u8 rate = frame->rate;
8018 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008019 struct sk_buff *skb;
8020 int hdr_only = 0;
8021 u16 filter = priv->prom_priv->filter;
8022
8023 /* If the filter is set to not include Rx frames then return */
8024 if (filter & IPW_PROM_NO_RX)
8025 return;
8026
Zhu Yid685b8c2006-04-13 17:20:27 +08008027 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008028 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008029
8030 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008031 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008032 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8033 return;
8034 }
8035
8036 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008037 if (unlikely(!netif_running(dev))) {
8038 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008039 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8040 return;
8041 }
8042
8043 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8044 * that now */
8045 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8046 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008047 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008048 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8049 return;
8050 }
8051
8052 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008053 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008054 if (filter & IPW_PROM_NO_MGMT)
8055 return;
8056 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8057 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008058 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008059 if (filter & IPW_PROM_NO_CTL)
8060 return;
8061 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8062 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008063 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008064 if (filter & IPW_PROM_NO_DATA)
8065 return;
8066 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8067 hdr_only = 1;
8068 }
8069
8070 /* Copy the SKB since this is for the promiscuous side */
8071 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8072 if (skb == NULL) {
8073 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8074 return;
8075 }
8076
8077 /* copy the frame data to write after where the radiotap header goes */
8078 ipw_rt = (void *)skb->data;
8079
8080 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008081 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008082
8083 memcpy(ipw_rt->payload, hdr, len);
8084
Zhu Yid685b8c2006-04-13 17:20:27 +08008085 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8086 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008087 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008088
8089 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008090 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008091
8092 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008093 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8094 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008095 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008096 (1 << IEEE80211_RADIOTAP_RATE) |
8097 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8098 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8099 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8100 (1 << IEEE80211_RADIOTAP_ANTENNA));
8101
8102 /* Zero the flags, we'll add to them as we go */
8103 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008104 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8105 frame->parent_tsf[2] << 16 |
8106 frame->parent_tsf[1] << 8 |
8107 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008108
8109 /* Convert to DBM */
8110 ipw_rt->rt_dbmsignal = signal;
8111 ipw_rt->rt_dbmnoise = noise;
8112
8113 /* Convert the channel data and set the flags */
8114 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8115 if (channel > 14) { /* 802.11a */
8116 ipw_rt->rt_chbitmask =
8117 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8118 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8119 ipw_rt->rt_chbitmask =
8120 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8121 } else { /* 802.11g */
8122 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008123 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008124 }
8125
8126 /* set the rate in multiples of 500k/s */
8127 switch (rate) {
8128 case IPW_TX_RATE_1MB:
8129 ipw_rt->rt_rate = 2;
8130 break;
8131 case IPW_TX_RATE_2MB:
8132 ipw_rt->rt_rate = 4;
8133 break;
8134 case IPW_TX_RATE_5MB:
8135 ipw_rt->rt_rate = 10;
8136 break;
8137 case IPW_TX_RATE_6MB:
8138 ipw_rt->rt_rate = 12;
8139 break;
8140 case IPW_TX_RATE_9MB:
8141 ipw_rt->rt_rate = 18;
8142 break;
8143 case IPW_TX_RATE_11MB:
8144 ipw_rt->rt_rate = 22;
8145 break;
8146 case IPW_TX_RATE_12MB:
8147 ipw_rt->rt_rate = 24;
8148 break;
8149 case IPW_TX_RATE_18MB:
8150 ipw_rt->rt_rate = 36;
8151 break;
8152 case IPW_TX_RATE_24MB:
8153 ipw_rt->rt_rate = 48;
8154 break;
8155 case IPW_TX_RATE_36MB:
8156 ipw_rt->rt_rate = 72;
8157 break;
8158 case IPW_TX_RATE_48MB:
8159 ipw_rt->rt_rate = 96;
8160 break;
8161 case IPW_TX_RATE_54MB:
8162 ipw_rt->rt_rate = 108;
8163 break;
8164 default:
8165 ipw_rt->rt_rate = 0;
8166 break;
8167 }
8168
8169 /* antenna number */
8170 ipw_rt->rt_antenna = (phy_flags & 3);
8171
8172 /* set the preamble flag if we have it */
8173 if (phy_flags & (1 << 6))
8174 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8175
8176 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8177
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008178 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008179 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008180 dev_kfree_skb_any(skb);
8181 }
8182}
8183#endif
8184
Arjan van de Ven858119e2006-01-14 13:20:43 -08008185static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008186 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008187{
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008188 /* Filter incoming packets to determine if they are targeted toward
James Ketrenosea2b26e2005-08-24 21:25:16 -05008189 * this network, discarding packets coming from ourselves */
8190 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008191 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008192 /* packets from our adapter are dropped (echo) */
8193 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8194 return 0;
8195
Peter Jones90700fd2005-08-26 16:51:06 -05008196 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008197 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008198 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008199
8200 /* packets to our adapter go through */
8201 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8202 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008203
Peter Jones90700fd2005-08-26 16:51:06 -05008204 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008205 /* packets from our adapter are dropped (echo) */
8206 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8207 return 0;
8208
Peter Jones90700fd2005-08-26 16:51:06 -05008209 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008210 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008211 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8212
8213 /* packets to our adapter go through */
8214 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8215 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008216 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008217
James Ketrenosea2b26e2005-08-24 21:25:16 -05008218 return 1;
8219}
8220
James Ketrenosafbf30a2005-08-25 00:05:33 -05008221#define IPW_PACKET_RETRY_TIME HZ
8222
Arjan van de Ven858119e2006-01-14 13:20:43 -08008223static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008224 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008225{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008226 u16 sc = le16_to_cpu(header->seq_ctl);
8227 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8228 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8229 u16 *last_seq, *last_frag;
8230 unsigned long *last_time;
8231
8232 switch (priv->ieee->iw_mode) {
8233 case IW_MODE_ADHOC:
8234 {
8235 struct list_head *p;
8236 struct ipw_ibss_seq *entry = NULL;
8237 u8 *mac = header->addr2;
8238 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8239
8240 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8241 entry =
8242 list_entry(p, struct ipw_ibss_seq, list);
8243 if (!memcmp(entry->mac, mac, ETH_ALEN))
8244 break;
8245 }
8246 if (p == &priv->ibss_mac_hash[index]) {
8247 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8248 if (!entry) {
8249 IPW_ERROR
8250 ("Cannot malloc new mac entry\n");
8251 return 0;
8252 }
8253 memcpy(entry->mac, mac, ETH_ALEN);
8254 entry->seq_num = seq;
8255 entry->frag_num = frag;
8256 entry->packet_time = jiffies;
8257 list_add(&entry->list,
8258 &priv->ibss_mac_hash[index]);
8259 return 0;
8260 }
8261 last_seq = &entry->seq_num;
8262 last_frag = &entry->frag_num;
8263 last_time = &entry->packet_time;
8264 break;
8265 }
8266 case IW_MODE_INFRA:
8267 last_seq = &priv->last_seq_num;
8268 last_frag = &priv->last_frag_num;
8269 last_time = &priv->last_packet_time;
8270 break;
8271 default:
8272 return 0;
8273 }
8274 if ((*last_seq == seq) &&
8275 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8276 if (*last_frag == frag)
8277 goto drop;
8278 if (*last_frag + 1 != frag)
8279 /* out-of-order fragment */
8280 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008281 } else
8282 *last_seq = seq;
8283
Zhu Yif57ce7c2005-07-13 12:22:15 -05008284 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008285 *last_time = jiffies;
8286 return 0;
8287
8288 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008289 /* Comment this line now since we observed the card receives
8290 * duplicate packets but the FCTL_RETRY bit is not set in the
8291 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008292 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008293 return 1;
8294}
8295
James Ketrenosb095c382005-08-24 22:04:42 -05008296static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8297 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008298 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008299{
8300 struct sk_buff *skb = rxb->skb;
8301 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008302 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008303 (skb->data + IPW_RX_FRAME_SIZE);
8304
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008305 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008306
8307 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8308 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8309 IEEE80211_STYPE_PROBE_RESP) ||
8310 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8311 IEEE80211_STYPE_BEACON))) {
8312 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8313 ipw_add_station(priv, header->addr2);
8314 }
8315
8316 if (priv->config & CFG_NET_STATS) {
8317 IPW_DEBUG_HC("sending stat packet\n");
8318
8319 /* Set the size of the skb to the size of the full
8320 * ipw header and 802.11 frame */
8321 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8322 IPW_RX_FRAME_SIZE);
8323
8324 /* Advance past the ipw packet header to the 802.11 frame */
8325 skb_pull(skb, IPW_RX_FRAME_SIZE);
8326
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008327 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008328 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8329
8330 skb->dev = priv->ieee->dev;
8331
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008332 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008333 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008334
8335 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008336 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008337 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8338 netif_rx(skb);
8339 rxb->skb = NULL;
8340 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008341}
8342
James Ketrenos43f66a62005-03-25 12:31:53 -06008343/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008344 * Main entry function for receiving a packet with 80211 headers. This
James Ketrenos43f66a62005-03-25 12:31:53 -06008345 * should be called when ever the FW has notified us that there is a new
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008346 * skb in the receive queue.
James Ketrenos43f66a62005-03-25 12:31:53 -06008347 */
8348static void ipw_rx(struct ipw_priv *priv)
8349{
8350 struct ipw_rx_mem_buffer *rxb;
8351 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008352 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008353 u32 r, w, i;
8354 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008355 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008356
James Ketrenosb095c382005-08-24 22:04:42 -05008357 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8358 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008359 i = priv->rxq->read;
8360
8361 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8362 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008363
8364 while (i != r) {
8365 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008366 if (unlikely(rxb == NULL)) {
8367 printk(KERN_CRIT "Queue not allocated!\n");
8368 break;
8369 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008370 priv->rxq->queue[i] = NULL;
8371
8372 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008373 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008374 PCI_DMA_FROMDEVICE);
8375
8376 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8377 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8378 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008379 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008380
8381 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008382 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008383 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008384 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008385 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008386 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008387 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008388 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008389 .noise =
8390 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008391 .rate = pkt->u.frame.rate,
8392 .mac_time = jiffies,
8393 .received_channel =
8394 pkt->u.frame.received_channel,
8395 .freq =
8396 (pkt->u.frame.
8397 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008398 LIBIPW_24GHZ_BAND :
8399 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008400 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008401 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008402
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008403 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008404 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008405 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008406 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008407 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008408 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008409 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008410 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008411
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008412 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008413
Zhu Yid685b8c2006-04-13 17:20:27 +08008414#ifdef CONFIG_IPW2200_PROMISCUOUS
8415 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8416 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8417#endif
8418
James Ketrenosb095c382005-08-24 22:04:42 -05008419#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008420 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008421#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008422
8423 ipw_handle_data_packet_monitor(priv,
8424 rxb,
8425 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008426#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008427 ipw_handle_data_packet(priv, rxb,
8428 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008429#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008430 break;
8431 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008432#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008433
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008434 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008435 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008436 data +
8437 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008438 /* TODO: Check Ad-Hoc dest/source and make sure
8439 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008440 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008441 * frame control of the packet and disregard
8442 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008443
James Ketrenosea2b26e2005-08-24 21:25:16 -05008444 network_packet =
8445 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008446 if (network_packet && priv->assoc_network) {
8447 priv->assoc_network->stats.rssi =
8448 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008449 priv->exp_avg_rssi =
8450 exponential_average(priv->exp_avg_rssi,
8451 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008452 }
8453
8454 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008455 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008456
James Ketrenosa613bff2005-08-24 21:43:11 -05008457 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008458 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008459 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008460 IPW_DEBUG_DROP
8461 ("Received packet is too small. "
8462 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008463 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008464 priv->wstats.discard.misc++;
8465 break;
8466 }
8467
James Ketrenosa613bff2005-08-24 21:43:11 -05008468 switch (WLAN_FC_GET_TYPE
8469 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008470
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008471 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008472 ipw_handle_mgmt_packet(priv, rxb,
8473 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008474 break;
8475
8476 case IEEE80211_FTYPE_CTL:
8477 break;
8478
8479 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008480 if (unlikely(!network_packet ||
8481 is_duplicate_packet(priv,
8482 header)))
8483 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008484 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008485 "%pM, "
8486 "%pM, "
8487 "%pM\n",
8488 header->addr1,
8489 header->addr2,
8490 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008491 break;
8492 }
8493
8494 ipw_handle_data_packet(priv, rxb,
8495 &stats);
8496
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008497 break;
8498 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008499 break;
8500 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008501
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008502 case RX_HOST_NOTIFICATION_TYPE:{
8503 IPW_DEBUG_RX
8504 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 pkt->u.notification.subtype,
8506 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008507 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008508 ipw_rx_notification(priv, &pkt->u.notification);
8509 break;
8510 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008511
8512 default:
8513 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8514 pkt->header.message_type);
8515 break;
8516 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008517
8518 /* For now we just don't re-use anything. We can tweak this
8519 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008520 * fail to Rx correctly */
8521 if (rxb->skb != NULL) {
8522 dev_kfree_skb_any(rxb->skb);
8523 rxb->skb = NULL;
8524 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008525
James Ketrenos43f66a62005-03-25 12:31:53 -06008526 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008527 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008528 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008529
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008531
8532 /* If there are a lot of unsued frames, restock the Rx queue
8533 * so the ucode won't assert */
8534 if (fill_rx) {
8535 priv->rxq->read = i;
8536 ipw_rx_queue_replenish(priv);
8537 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008538 }
8539
8540 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008541 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 ipw_rx_queue_restock(priv);
8543}
8544
James Ketrenosafbf30a2005-08-25 00:05:33 -05008545#define DEFAULT_RTS_THRESHOLD 2304U
8546#define MIN_RTS_THRESHOLD 1U
8547#define MAX_RTS_THRESHOLD 2304U
8548#define DEFAULT_BEACON_INTERVAL 100U
8549#define DEFAULT_SHORT_RETRY_LIMIT 7U
8550#define DEFAULT_LONG_RETRY_LIMIT 4U
8551
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008552/**
8553 * ipw_sw_reset
8554 * @option: options to control different reset behaviour
8555 * 0 = reset everything except the 'disable' module_param
8556 * 1 = reset everything and print out driver info (for probe only)
8557 * 2 = reset everything
8558 */
8559static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008560{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008561 int band, modulation;
8562 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008563
James Ketrenosafbf30a2005-08-25 00:05:33 -05008564 /* Initialize module parameter values here */
8565 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008566
James Ketrenosafbf30a2005-08-25 00:05:33 -05008567 /* We default to disabling the LED code as right now it causes
8568 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008569 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008570 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008571
James Ketrenosafbf30a2005-08-25 00:05:33 -05008572 if (associate)
8573 priv->config |= CFG_ASSOCIATE;
8574 else
8575 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008576
James Ketrenosafbf30a2005-08-25 00:05:33 -05008577 if (auto_create)
8578 priv->config |= CFG_ADHOC_CREATE;
8579 else
8580 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8581
Zhu Yi17ed0812006-01-24 16:36:31 +08008582 priv->config &= ~CFG_STATIC_ESSID;
8583 priv->essid_len = 0;
8584 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8585
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008586 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008587 priv->status |= STATUS_RF_KILL_SW;
8588 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008589 }
8590
Reinette Chatre21f8a732009-08-18 10:25:05 -07008591 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008592 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008593 priv->channel = default_channel;
8594 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008595 /* TODO: Validate that provided channel is in range */
8596 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008597#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008598 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8599 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008600#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008601
Reinette Chatre21f8a732009-08-18 10:25:05 -07008602 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008603 case 1:
8604 priv->ieee->iw_mode = IW_MODE_ADHOC;
8605 priv->net_dev->type = ARPHRD_ETHER;
8606
8607 break;
8608#ifdef CONFIG_IPW2200_MONITOR
8609 case 2:
8610 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008611#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008612 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8613#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008614 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008615#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008616 break;
8617#endif
8618 default:
8619 case 0:
8620 priv->net_dev->type = ARPHRD_ETHER;
8621 priv->ieee->iw_mode = IW_MODE_INFRA;
8622 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008623 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008624
James Ketrenosafbf30a2005-08-25 00:05:33 -05008625 if (hwcrypto) {
8626 priv->ieee->host_encrypt = 0;
8627 priv->ieee->host_encrypt_msdu = 0;
8628 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008629 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008630 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008631 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008632
Zhu Yie402c932005-08-05 17:20:40 +08008633 /* IPW2200/2915 is abled to do hardware fragmentation. */
8634 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008635
James Ketrenosafbf30a2005-08-25 00:05:33 -05008636 if ((priv->pci_dev->device == 0x4223) ||
8637 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008638 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008639 printk(KERN_INFO DRV_NAME
8640 ": Detected Intel PRO/Wireless 2915ABG Network "
8641 "Connection\n");
8642 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008643 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8644 modulation = LIBIPW_OFDM_MODULATION |
8645 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008646 priv->adapter = IPW_2915ABG;
8647 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008648 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008649 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008650 printk(KERN_INFO DRV_NAME
8651 ": Detected Intel PRO/Wireless 2200BG Network "
8652 "Connection\n");
8653
8654 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008655 band = LIBIPW_24GHZ_BAND;
8656 modulation = LIBIPW_OFDM_MODULATION |
8657 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008658 priv->adapter = IPW_2200BG;
8659 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008660 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008661
James Ketrenosafbf30a2005-08-25 00:05:33 -05008662 priv->ieee->freq_band = band;
8663 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008664
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008665 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008666
James Ketrenosafbf30a2005-08-25 00:05:33 -05008667 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8668 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008669
James Ketrenosafbf30a2005-08-25 00:05:33 -05008670 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8671 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8672 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008673
James Ketrenosafbf30a2005-08-25 00:05:33 -05008674 /* If power management is turned on, default to AC mode */
8675 priv->power_mode = IPW_POWER_AC;
8676 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008677
Zhu Yi0ece35b2005-08-05 17:26:51 +08008678 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008679}
8680
8681/*
8682 * This file defines the Wireless Extension handlers. It does not
8683 * define any methods of hardware manipulation and relies on the
8684 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008685 *
8686 * The exception to this is the use of the ipw_get_ordinal()
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008687 * function used to poll the hardware vs. making unnecessary calls.
James Ketrenos43f66a62005-03-25 12:31:53 -06008688 *
8689 */
8690
James Ketrenos43f66a62005-03-25 12:31:53 -06008691static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8692{
8693 if (channel == 0) {
8694 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8695 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008696 IPW_DEBUG_ASSOC("Attempting to associate with new "
8697 "parameters.\n");
8698 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008699 return 0;
8700 }
8701
8702 priv->config |= CFG_STATIC_CHANNEL;
8703
8704 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008705 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8706 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008707 return 0;
8708 }
8709
8710 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8711 priv->channel = channel;
8712
James Ketrenosb095c382005-08-24 22:04:42 -05008713#ifdef CONFIG_IPW2200_MONITOR
8714 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008715 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008716 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008717 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008718 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008719 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008720 }
8721
8722 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8723 udelay(10);
8724
8725 if (priv->status & STATUS_SCANNING)
8726 IPW_DEBUG_SCAN("Still scanning...\n");
8727 else
8728 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8729 1000 - i);
8730
8731 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008732 }
James Ketrenosb095c382005-08-24 22:04:42 -05008733#endif /* CONFIG_IPW2200_MONITOR */
8734
James Ketrenosc848d0a2005-08-24 21:56:24 -05008735 /* Network configuration changed -- force [re]association */
8736 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8737 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008738 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008739
8740 return 0;
8741}
8742
Jeff Garzikbf794512005-07-31 13:07:26 -04008743static int ipw_wx_set_freq(struct net_device *dev,
8744 struct iw_request_info *info,
8745 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008746{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008747 struct ipw_priv *priv = libipw_priv(dev);
8748 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008749 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008750 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008751 u8 channel, flags;
8752 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008753
James Ketrenosb095c382005-08-24 22:04:42 -05008754 if (fwrq->m == 0) {
8755 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008756 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008757 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008758 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008759 return ret;
8760 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008761 /* if setting by freq convert to channel */
8762 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008763 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008764 if (channel == 0)
8765 return -EINVAL;
8766 } else
8767 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008768
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008769 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008770 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008771
Liu Hong1fe0adb2005-08-19 09:33:10 -05008772 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008773 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008774 if (i == -1)
8775 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008776
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008777 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008778 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008779 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008780 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8781 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008782 }
8783 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008784
Frans Pop9fd1ea42010-03-24 19:46:31 +01008785 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008786 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008787 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008788 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008789 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008790}
8791
Jeff Garzikbf794512005-07-31 13:07:26 -04008792static int ipw_wx_get_freq(struct net_device *dev,
8793 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008794 union iwreq_data *wrqu, char *extra)
8795{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008796 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008797
8798 wrqu->freq.e = 0;
8799
8800 /* If we are associated, trying to associate, or have a statically
8801 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008802 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008803 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008804 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8805 int i;
8806
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008807 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008808 BUG_ON(i == -1);
8809 wrqu->freq.e = 1;
8810
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008811 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8812 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008813 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8814 break;
8815
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008816 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008817 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8818 break;
8819
8820 default:
8821 BUG();
8822 }
8823 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008824 wrqu->freq.m = 0;
8825
Zhu Yi46441512006-01-24 16:37:59 +08008826 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008827 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 return 0;
8829}
8830
Jeff Garzikbf794512005-07-31 13:07:26 -04008831static int ipw_wx_set_mode(struct net_device *dev,
8832 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008833 union iwreq_data *wrqu, char *extra)
8834{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008835 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 int err = 0;
8837
8838 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8839
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008841#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 case IW_MODE_MONITOR:
8843#endif
8844 case IW_MODE_ADHOC:
8845 case IW_MODE_INFRA:
8846 break;
8847 case IW_MODE_AUTO:
8848 wrqu->mode = IW_MODE_INFRA;
8849 break;
8850 default:
8851 return -EINVAL;
8852 }
James Ketrenosb095c382005-08-24 22:04:42 -05008853 if (wrqu->mode == priv->ieee->iw_mode)
8854 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008855
Zhu Yi46441512006-01-24 16:37:59 +08008856 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008857
8858 ipw_sw_reset(priv, 0);
8859
James Ketrenosb095c382005-08-24 22:04:42 -05008860#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008861 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008862 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008863
8864 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008865#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008866 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8867#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008869#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008870#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008871
Jeff Garzikbf794512005-07-31 13:07:26 -04008872 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008873 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008874 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008875
8876 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008877
Tejun Heobcb6d912011-01-26 12:12:50 +01008878 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008879 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008880 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008881}
8882
Jeff Garzikbf794512005-07-31 13:07:26 -04008883static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008884 struct iw_request_info *info,
8885 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008886{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008887 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008888 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008889 wrqu->mode = priv->ieee->iw_mode;
8890 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008891 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008892 return 0;
8893}
8894
James Ketrenos43f66a62005-03-25 12:31:53 -06008895/* Values are in microsecond */
8896static const s32 timeout_duration[] = {
8897 350000,
8898 250000,
8899 75000,
8900 37000,
8901 25000,
8902};
8903
8904static const s32 period_duration[] = {
8905 400000,
8906 700000,
8907 1000000,
8908 1000000,
8909 1000000
8910};
8911
Jeff Garzikbf794512005-07-31 13:07:26 -04008912static int ipw_wx_get_range(struct net_device *dev,
8913 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008914 union iwreq_data *wrqu, char *extra)
8915{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008916 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008917 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008918 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008919 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008920
8921 wrqu->data.length = sizeof(*range);
8922 memset(range, 0, sizeof(*range));
8923
8924 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008925 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008926
8927 range->max_qual.qual = 100;
8928 /* TODO: Find real max RSSI and stick here */
8929 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008930 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008931 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008932
8933 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008934 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008935 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008936 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008937 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008938 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008939 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008940
Jeff Garzikbf794512005-07-31 13:07:26 -04008941 for (i = 0; i < range->num_bitrates; i++)
8942 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008943 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008944
James Ketrenos43f66a62005-03-25 12:31:53 -06008945 range->max_rts = DEFAULT_RTS_THRESHOLD;
8946 range->min_frag = MIN_FRAG_THRESHOLD;
8947 range->max_frag = MAX_FRAG_THRESHOLD;
8948
8949 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008950 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008951 range->num_encoding_sizes = 2;
8952 range->max_encoding_tokens = WEP_KEYS;
8953
8954 /* Set the Wireless Extension versions */
8955 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008956 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008957
James Ketrenosb095c382005-08-24 22:04:42 -05008958 i = 0;
8959 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008960 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8961 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008962 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008963 continue;
8964
James Ketrenosb095c382005-08-24 22:04:42 -05008965 range->freq[i].i = geo->bg[j].channel;
8966 range->freq[i].m = geo->bg[j].freq * 100000;
8967 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008968 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008969 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008970 }
James Ketrenosb095c382005-08-24 22:04:42 -05008971
8972 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008973 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8974 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008975 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008976 continue;
8977
James Ketrenosb095c382005-08-24 22:04:42 -05008978 range->freq[i].i = geo->a[j].channel;
8979 range->freq[i].m = geo->a[j].freq * 100000;
8980 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008981 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008982 }
8983 }
8984
8985 range->num_channels = i;
8986 range->num_frequency = i;
8987
Zhu Yi46441512006-01-24 16:37:59 +08008988 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008989
8990 /* Event capability (kernel + driver) */
8991 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8992 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008993 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8994 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008995 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008996
Dan Williamsf1b50862006-01-30 13:58:56 -05008997 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8998 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8999
Dan Williams374fdfb2007-12-12 10:25:07 -05009000 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9001
James Ketrenos43f66a62005-03-25 12:31:53 -06009002 IPW_DEBUG_WX("GET Range\n");
9003 return 0;
9004}
9005
Jeff Garzikbf794512005-07-31 13:07:26 -04009006static int ipw_wx_set_wap(struct net_device *dev,
9007 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009008 union iwreq_data *wrqu, char *extra)
9009{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009010 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009011
9012 static const unsigned char any[] = {
9013 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9014 };
9015 static const unsigned char off[] = {
9016 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9017 };
9018
Jeff Garzikbf794512005-07-31 13:07:26 -04009019 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009020 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009021 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009022 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9023 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9024 /* we disable mandatory BSSID association */
9025 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9026 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009027 IPW_DEBUG_ASSOC("Attempting to associate with new "
9028 "parameters.\n");
9029 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009030 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009031 return 0;
9032 }
9033
9034 priv->config |= CFG_STATIC_BSSID;
9035 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9036 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009037 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009038 return 0;
9039 }
9040
Johannes Berge1749612008-10-27 15:59:26 -07009041 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9042 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009043
9044 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9045
James Ketrenosc848d0a2005-08-24 21:56:24 -05009046 /* Network configuration changed -- force [re]association */
9047 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9048 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009049 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009050
Zhu Yi46441512006-01-24 16:37:59 +08009051 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009052 return 0;
9053}
9054
Jeff Garzikbf794512005-07-31 13:07:26 -04009055static int ipw_wx_get_wap(struct net_device *dev,
9056 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009057 union iwreq_data *wrqu, char *extra)
9058{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009059 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009060
James Ketrenos43f66a62005-03-25 12:31:53 -06009061 /* If we are associated, trying to associate, or have a statically
9062 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009063 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009064 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009065 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9066 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009067 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009068 } else
9069 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9070
Johannes Berge1749612008-10-27 15:59:26 -07009071 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9072 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009073 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009074 return 0;
9075}
9076
Jeff Garzikbf794512005-07-31 13:07:26 -04009077static int ipw_wx_set_essid(struct net_device *dev,
9078 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009079 union iwreq_data *wrqu, char *extra)
9080{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009081 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009082 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009083 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009084
Zhu Yiab644b02006-08-21 11:37:13 +08009085 mutex_lock(&priv->mutex);
9086
9087 if (!wrqu->essid.flags)
9088 {
9089 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9090 ipw_disassociate(priv);
9091 priv->config &= ~CFG_STATIC_ESSID;
9092 ipw_associate(priv);
9093 mutex_unlock(&priv->mutex);
9094 return 0;
9095 }
9096
Zhu Yia9f0d422006-08-21 11:37:26 +08009097 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009098
9099 priv->config |= CFG_STATIC_ESSID;
9100
Zhu Yia9f0d422006-08-21 11:37:26 +08009101 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9102 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009103 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009104 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009105 return 0;
9106 }
9107
John W. Linville9387b7c2008-09-30 20:59:05 -04009108 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9109 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009110
9111 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009112 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009113
James Ketrenosc848d0a2005-08-24 21:56:24 -05009114 /* Network configuration changed -- force [re]association */
9115 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9116 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009117 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009118
Zhu Yi46441512006-01-24 16:37:59 +08009119 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009120 return 0;
9121}
9122
Jeff Garzikbf794512005-07-31 13:07:26 -04009123static int ipw_wx_get_essid(struct net_device *dev,
9124 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 union iwreq_data *wrqu, char *extra)
9126{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009127 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009128 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009129
9130 /* If we are associated, trying to associate, or have a statically
9131 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009132 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009133 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009134 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9135 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009136 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009137 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009138 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009139 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 } else {
9141 IPW_DEBUG_WX("Getting essid: ANY\n");
9142 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009143 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 }
Zhu Yi46441512006-01-24 16:37:59 +08009145 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009146 return 0;
9147}
9148
Jeff Garzikbf794512005-07-31 13:07:26 -04009149static int ipw_wx_set_nick(struct net_device *dev,
9150 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009151 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009152{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009153 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009154
9155 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9156 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9157 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009158 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009159 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009160 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009161 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009162 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009163 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 return 0;
9165
9166}
9167
Jeff Garzikbf794512005-07-31 13:07:26 -04009168static int ipw_wx_get_nick(struct net_device *dev,
9169 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009170 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009171{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009172 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009173 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009174 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009175 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009176 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009177 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009178 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009179 return 0;
9180}
9181
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009182static int ipw_wx_set_sens(struct net_device *dev,
9183 struct iw_request_info *info,
9184 union iwreq_data *wrqu, char *extra)
9185{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009186 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009187 int err = 0;
9188
9189 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9190 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9191 mutex_lock(&priv->mutex);
9192
9193 if (wrqu->sens.fixed == 0)
9194 {
9195 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9196 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9197 goto out;
9198 }
9199 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9200 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9201 err = -EINVAL;
9202 goto out;
9203 }
9204
9205 priv->roaming_threshold = wrqu->sens.value;
9206 priv->disassociate_threshold = 3*wrqu->sens.value;
9207 out:
9208 mutex_unlock(&priv->mutex);
9209 return err;
9210}
9211
9212static int ipw_wx_get_sens(struct net_device *dev,
9213 struct iw_request_info *info,
9214 union iwreq_data *wrqu, char *extra)
9215{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009216 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009217 mutex_lock(&priv->mutex);
9218 wrqu->sens.fixed = 1;
9219 wrqu->sens.value = priv->roaming_threshold;
9220 mutex_unlock(&priv->mutex);
9221
Frans Pop9fd1ea42010-03-24 19:46:31 +01009222 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009223 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9224
9225 return 0;
9226}
9227
James Ketrenos43f66a62005-03-25 12:31:53 -06009228static int ipw_wx_set_rate(struct net_device *dev,
9229 struct iw_request_info *info,
9230 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009231{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009232 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009233 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009234 u32 target_rate = wrqu->bitrate.value;
9235 u32 fixed, mask;
9236
9237 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9238 /* value = X, fixed = 1 means only rate X */
9239 /* value = X, fixed = 0 means all rates lower equal X */
9240
9241 if (target_rate == -1) {
9242 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009243 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009244 /* Now we should reassociate */
9245 goto apply;
9246 }
9247
9248 mask = 0;
9249 fixed = wrqu->bitrate.fixed;
9250
9251 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009252 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009253 if (target_rate == 1000000)
9254 goto apply;
9255
9256 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009257 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009258 if (target_rate == 2000000)
9259 goto apply;
9260
9261 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009262 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009263 if (target_rate == 5500000)
9264 goto apply;
9265
9266 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009267 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009268 if (target_rate == 6000000)
9269 goto apply;
9270
9271 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009272 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009273 if (target_rate == 9000000)
9274 goto apply;
9275
9276 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009277 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009278 if (target_rate == 11000000)
9279 goto apply;
9280
9281 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009282 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009283 if (target_rate == 12000000)
9284 goto apply;
9285
9286 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009287 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009288 if (target_rate == 18000000)
9289 goto apply;
9290
9291 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009292 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009293 if (target_rate == 24000000)
9294 goto apply;
9295
9296 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009297 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009298 if (target_rate == 36000000)
9299 goto apply;
9300
9301 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009302 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009303 if (target_rate == 48000000)
9304 goto apply;
9305
9306 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009307 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009308 if (target_rate == 54000000)
9309 goto apply;
9310
9311 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9312 return -EINVAL;
9313
9314 apply:
9315 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9316 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009317 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009318 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009319 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009320 ipw_set_fixed_rate(priv, priv->ieee->mode);
9321 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009322 priv->config |= CFG_FIXED_RATE;
9323
James Ketrenosc848d0a2005-08-24 21:56:24 -05009324 if (priv->rates_mask == mask) {
9325 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009326 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009327 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009328 }
9329
James Ketrenosc848d0a2005-08-24 21:56:24 -05009330 priv->rates_mask = mask;
9331
9332 /* Network configuration changed -- force [re]association */
9333 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9334 if (!ipw_disassociate(priv))
9335 ipw_associate(priv);
9336
Zhu Yi46441512006-01-24 16:37:59 +08009337 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009338 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009339}
9340
Jeff Garzikbf794512005-07-31 13:07:26 -04009341static int ipw_wx_get_rate(struct net_device *dev,
9342 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009343 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009344{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009345 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009346 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009347 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009348 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009349 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009350 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 return 0;
9352}
9353
Jeff Garzikbf794512005-07-31 13:07:26 -04009354static int ipw_wx_set_rts(struct net_device *dev,
9355 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009356 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009357{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009358 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009359 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009360 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9362 else {
9363 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009364 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009365 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009366 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009367 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009368 priv->rts_threshold = wrqu->rts.value;
9369 }
9370
9371 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009372 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009373 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009374 return 0;
9375}
9376
Jeff Garzikbf794512005-07-31 13:07:26 -04009377static int ipw_wx_get_rts(struct net_device *dev,
9378 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009379 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009380{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009381 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009382 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009383 wrqu->rts.value = priv->rts_threshold;
9384 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009385 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009386 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009387 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009388 return 0;
9389}
9390
Jeff Garzikbf794512005-07-31 13:07:26 -04009391static int ipw_wx_set_txpow(struct net_device *dev,
9392 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009393 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009394{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009395 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009396 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009397
Zhu Yi46441512006-01-24 16:37:59 +08009398 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009399 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009400 err = -EINPROGRESS;
9401 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009402 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009403
James Ketrenosb095c382005-08-24 22:04:42 -05009404 if (!wrqu->power.fixed)
9405 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009406
James Ketrenosc848d0a2005-08-24 21:56:24 -05009407 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009408 err = -EINVAL;
9409 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009410 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009411
James Ketrenosb095c382005-08-24 22:04:42 -05009412 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009413 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009414 err = -EINVAL;
9415 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009416 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009417
9418 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009419 err = ipw_set_tx_power(priv);
9420 out:
Zhu Yi46441512006-01-24 16:37:59 +08009421 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009422 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009423}
9424
Jeff Garzikbf794512005-07-31 13:07:26 -04009425static int ipw_wx_get_txpow(struct net_device *dev,
9426 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009427 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009428{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009429 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009430 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009431 wrqu->power.value = priv->tx_power;
9432 wrqu->power.fixed = 1;
9433 wrqu->power.flags = IW_TXPOW_DBM;
9434 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009435 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009436
Frans Pop9fd1ea42010-03-24 19:46:31 +01009437 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009438 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009439
9440 return 0;
9441}
9442
Jeff Garzikbf794512005-07-31 13:07:26 -04009443static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009444 struct iw_request_info *info,
9445 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009446{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009447 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009448 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009449 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009450 priv->ieee->fts = DEFAULT_FTS;
9451 else {
9452 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009453 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009454 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009455 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009456 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009457
James Ketrenos43f66a62005-03-25 12:31:53 -06009458 priv->ieee->fts = wrqu->frag.value & ~0x1;
9459 }
9460
9461 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009462 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009463 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009464 return 0;
9465}
9466
Jeff Garzikbf794512005-07-31 13:07:26 -04009467static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009468 struct iw_request_info *info,
9469 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009470{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009471 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009472 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009473 wrqu->frag.value = priv->ieee->fts;
9474 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009475 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009476 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009477 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009478
9479 return 0;
9480}
9481
Jeff Garzikbf794512005-07-31 13:07:26 -04009482static int ipw_wx_set_retry(struct net_device *dev,
9483 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009484 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009485{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009486 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009487
9488 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9489 return -EINVAL;
9490
9491 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9492 return 0;
9493
Zhu Yid5f7ac22006-08-21 11:38:17 +08009494 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009495 return -EINVAL;
9496
Zhu Yi46441512006-01-24 16:37:59 +08009497 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009498 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009499 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009500 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009501 priv->long_retry_limit = (u8) wrqu->retry.value;
9502 else {
9503 priv->short_retry_limit = (u8) wrqu->retry.value;
9504 priv->long_retry_limit = (u8) wrqu->retry.value;
9505 }
9506
9507 ipw_send_retry_limit(priv, priv->short_retry_limit,
9508 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009509 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009510 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9511 priv->short_retry_limit, priv->long_retry_limit);
9512 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009513}
9514
Jeff Garzikbf794512005-07-31 13:07:26 -04009515static int ipw_wx_get_retry(struct net_device *dev,
9516 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009517 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009518{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009519 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009520
Zhu Yi46441512006-01-24 16:37:59 +08009521 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009522 wrqu->retry.disabled = 0;
9523
9524 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009525 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009526 return -EINVAL;
9527 }
9528
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009529 if (wrqu->retry.flags & IW_RETRY_LONG) {
9530 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009531 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009532 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9533 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009534 wrqu->retry.value = priv->short_retry_limit;
9535 } else {
9536 wrqu->retry.flags = IW_RETRY_LIMIT;
9537 wrqu->retry.value = priv->short_retry_limit;
9538 }
Zhu Yi46441512006-01-24 16:37:59 +08009539 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009540
Frans Pop9fd1ea42010-03-24 19:46:31 +01009541 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009542
9543 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009544}
9545
Jeff Garzikbf794512005-07-31 13:07:26 -04009546static int ipw_wx_set_scan(struct net_device *dev,
9547 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009548 union iwreq_data *wrqu, char *extra)
9549{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009550 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009551 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009552 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009553
Dan Williams0b531672007-10-09 13:55:24 -04009554 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009555
Dan Williams0b531672007-10-09 13:55:24 -04009556 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009557
Zhu Yi094c4d22006-08-21 11:39:03 +08009558 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009559 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009560 int len = min((int)req->essid_len,
9561 (int)sizeof(priv->direct_scan_ssid));
9562 memcpy(priv->direct_scan_ssid, req->essid, len);
9563 priv->direct_scan_ssid_len = len;
9564 work = &priv->request_direct_scan;
9565 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9566 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009567 }
Dan Williamsea177302008-06-02 17:51:23 -04009568 } else {
9569 /* Normal active broadcast scan */
9570 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009571 }
James Ketrenos8935f392005-10-05 15:59:08 -05009572
Dan Williamsea177302008-06-02 17:51:23 -04009573 mutex_unlock(&priv->mutex);
9574
James Ketrenos43f66a62005-03-25 12:31:53 -06009575 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009576
Tejun Heobcb6d912011-01-26 12:12:50 +01009577 schedule_delayed_work(work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009578
James Ketrenos43f66a62005-03-25 12:31:53 -06009579 return 0;
9580}
9581
Jeff Garzikbf794512005-07-31 13:07:26 -04009582static int ipw_wx_get_scan(struct net_device *dev,
9583 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009584 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009585{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009586 struct ipw_priv *priv = libipw_priv(dev);
9587 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009588}
9589
Jeff Garzikbf794512005-07-31 13:07:26 -04009590static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009591 struct iw_request_info *info,
9592 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009593{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009594 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009595 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009596 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009597
Zhu Yi46441512006-01-24 16:37:59 +08009598 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009599 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009600
Hong Liucaeff812005-08-05 17:25:50 +08009601 /* In IBSS mode, we need to notify the firmware to update
9602 * the beacon info after we changed the capability. */
9603 if (cap != priv->capability &&
9604 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9605 priv->status & STATUS_ASSOCIATED)
9606 ipw_disassociate(priv);
9607
Zhu Yi46441512006-01-24 16:37:59 +08009608 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009609 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009610}
9611
Jeff Garzikbf794512005-07-31 13:07:26 -04009612static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009613 struct iw_request_info *info,
9614 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009615{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009616 struct ipw_priv *priv = libipw_priv(dev);
9617 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009618}
9619
Jeff Garzikbf794512005-07-31 13:07:26 -04009620static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009621 struct iw_request_info *info,
9622 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009623{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009624 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009625 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009626 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009627 if (wrqu->power.disabled) {
9628 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9629 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9630 if (err) {
9631 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009632 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009633 return err;
9634 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009635 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009636 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009637 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009638 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009639
9640 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009641 case IW_POWER_ON: /* If not specified */
9642 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009643 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009645 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009646 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9647 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009648 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009649 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009650 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009651
James Ketrenos43f66a62005-03-25 12:31:53 -06009652 /* If the user hasn't specified a power management mode yet, default
9653 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009654 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009655 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009656 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009657 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009658
James Ketrenos43f66a62005-03-25 12:31:53 -06009659 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9660 if (err) {
9661 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009662 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 return err;
9664 }
9665
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009666 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009667 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 return 0;
9669}
9670
Jeff Garzikbf794512005-07-31 13:07:26 -04009671static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009672 struct iw_request_info *info,
9673 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009674{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009675 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009676 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009677 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009678 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009679 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009680 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009681
Zhu Yi46441512006-01-24 16:37:59 +08009682 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009684
James Ketrenos43f66a62005-03-25 12:31:53 -06009685 return 0;
9686}
9687
Jeff Garzikbf794512005-07-31 13:07:26 -04009688static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009689 struct iw_request_info *info,
9690 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009691{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009692 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009693 int mode = *(int *)extra;
9694 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009695
Zhu Yi46441512006-01-24 16:37:59 +08009696 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009697 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009698 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009699
Zhu Yi4e157f02007-07-12 16:09:32 +08009700 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009701 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009702 if (err) {
9703 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009704 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009705 return err;
9706 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009707 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009708 }
Zhu Yi46441512006-01-24 16:37:59 +08009709 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009710 return 0;
9711}
9712
9713#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009714static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009715 struct iw_request_info *info,
9716 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009717{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009718 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009719 int level = IPW_POWER_LEVEL(priv->power_mode);
9720 char *p = extra;
9721
9722 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9723
9724 switch (level) {
9725 case IPW_POWER_AC:
9726 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9727 break;
9728 case IPW_POWER_BATTERY:
9729 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9730 break;
9731 default:
9732 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009733 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009734 timeout_duration[level - 1] / 1000,
9735 period_duration[level - 1] / 1000);
9736 }
9737
9738 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009739 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009740
9741 wrqu->data.length = p - extra + 1;
9742
9743 return 0;
9744}
9745
9746static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009747 struct iw_request_info *info,
9748 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009749{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009750 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009751 int mode = *(int *)extra;
9752 u8 band = 0, modulation = 0;
9753
9754 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009755 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 return -EINVAL;
9757 }
Zhu Yi46441512006-01-24 16:37:59 +08009758 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009760 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009761 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009762 band |= LIBIPW_52GHZ_BAND;
9763 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009765 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009766 } else {
9767 if (mode & IEEE_A) {
9768 IPW_WARNING("Attempt to set 2200BG into "
9769 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009770 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009771 return -EINVAL;
9772 }
9773
James Ketrenosa33a1982005-09-14 14:28:59 -05009774 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 }
9776
9777 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009778 band |= LIBIPW_24GHZ_BAND;
9779 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009780 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009781 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009782
James Ketrenos43f66a62005-03-25 12:31:53 -06009783 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009784 band |= LIBIPW_24GHZ_BAND;
9785 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009786 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009787 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009788
9789 priv->ieee->mode = mode;
9790 priv->ieee->freq_band = band;
9791 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009792 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009793
James Ketrenosc848d0a2005-08-24 21:56:24 -05009794 /* Network configuration changed -- force [re]association */
9795 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9796 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009797 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009798 ipw_associate(priv);
9799 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009800
James Ketrenosa613bff2005-08-24 21:43:11 -05009801 /* Update the band LEDs */
9802 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009803
Jeff Garzikbf794512005-07-31 13:07:26 -04009804 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009805 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009806 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009807 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009808 return 0;
9809}
9810
9811static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009812 struct iw_request_info *info,
9813 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009814{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009815 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009816 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009817 switch (priv->ieee->mode) {
9818 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009819 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9820 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009821 case IEEE_B:
9822 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9823 break;
9824 case IEEE_A | IEEE_B:
9825 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9826 break;
9827 case IEEE_G:
9828 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9829 break;
9830 case IEEE_A | IEEE_G:
9831 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9832 break;
9833 case IEEE_B | IEEE_G:
9834 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9835 break;
9836 case IEEE_A | IEEE_B | IEEE_G:
9837 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9838 break;
9839 default:
9840 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009841 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009842 }
9843
James Ketrenos43f66a62005-03-25 12:31:53 -06009844 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9845
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009846 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009847 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009848
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009849 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009850}
9851
James Ketrenosea2b26e2005-08-24 21:25:16 -05009852static int ipw_wx_set_preamble(struct net_device *dev,
9853 struct iw_request_info *info,
9854 union iwreq_data *wrqu, char *extra)
9855{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009856 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009857 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009858 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009859 /* Switching from SHORT -> LONG requires a disassociation */
9860 if (mode == 1) {
9861 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9862 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009863
9864 /* Network configuration changed -- force [re]association */
9865 IPW_DEBUG_ASSOC
9866 ("[re]association triggered due to preamble change.\n");
9867 if (!ipw_disassociate(priv))
9868 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009869 }
9870 goto done;
9871 }
9872
9873 if (mode == 0) {
9874 priv->config &= ~CFG_PREAMBLE_LONG;
9875 goto done;
9876 }
Zhu Yi46441512006-01-24 16:37:59 +08009877 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009878 return -EINVAL;
9879
9880 done:
Zhu Yi46441512006-01-24 16:37:59 +08009881 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009882 return 0;
9883}
9884
9885static int ipw_wx_get_preamble(struct net_device *dev,
9886 struct iw_request_info *info,
9887 union iwreq_data *wrqu, char *extra)
9888{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009889 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009890 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009891 if (priv->config & CFG_PREAMBLE_LONG)
9892 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9893 else
9894 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009895 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009896 return 0;
9897}
9898
James Ketrenosb095c382005-08-24 22:04:42 -05009899#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009900static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009901 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009902 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009903{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009904 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009905 int *parms = (int *)extra;
9906 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009907 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009908 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 if (enable) {
9910 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009911#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009912 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9913#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009914 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009915#endif
Tejun Heobcb6d912011-01-26 12:12:50 +01009916 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009918
James Ketrenos43f66a62005-03-25 12:31:53 -06009919 ipw_set_channel(priv, parms[1]);
9920 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009921 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009922 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009923 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009924 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 priv->net_dev->type = ARPHRD_ETHER;
Tejun Heobcb6d912011-01-26 12:12:50 +01009926 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009927 }
Zhu Yi46441512006-01-24 16:37:59 +08009928 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009929 return 0;
9930}
9931
Pavel Machek67fd6b42006-07-11 15:34:05 +02009932#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009933
Jeff Garzikbf794512005-07-31 13:07:26 -04009934static int ipw_wx_reset(struct net_device *dev,
9935 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009936 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009937{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009938 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009939 IPW_DEBUG_WX("RESET\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01009940 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009941 return 0;
9942}
James Ketrenosb095c382005-08-24 22:04:42 -05009943
James Ketrenosb095c382005-08-24 22:04:42 -05009944static int ipw_wx_sw_reset(struct net_device *dev,
9945 struct iw_request_info *info,
9946 union iwreq_data *wrqu, char *extra)
9947{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009948 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009949 union iwreq_data wrqu_sec = {
9950 .encoding = {
9951 .flags = IW_ENCODE_DISABLED,
9952 },
9953 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009954 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009955
9956 IPW_DEBUG_WX("SW_RESET\n");
9957
Zhu Yi46441512006-01-24 16:37:59 +08009958 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009959
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009960 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009961 if (!ret) {
9962 free_firmware();
9963 ipw_adapter_restart(priv);
9964 }
James Ketrenosb095c382005-08-24 22:04:42 -05009965
9966 /* The SW reset bit might have been toggled on by the 'disable'
9967 * module parameter, so take appropriate action */
9968 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9969
Zhu Yi46441512006-01-24 16:37:59 +08009970 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009971 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009972 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009973
9974 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9975 /* Configuration likely changed -- force [re]association */
9976 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9977 "reset.\n");
9978 if (!ipw_disassociate(priv))
9979 ipw_associate(priv);
9980 }
9981
Zhu Yi46441512006-01-24 16:37:59 +08009982 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009983
9984 return 0;
9985}
James Ketrenos43f66a62005-03-25 12:31:53 -06009986
9987/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009988static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -07009989 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
9990 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9991 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
9992 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
9993 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
9994 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
9995 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
9996 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
9997 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
9998 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
9999 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
10000 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10001 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10002 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10003 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10004 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10005 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10006 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10007 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10008 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10009 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10010 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10011 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10012 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10013 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10014 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10015 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10016 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10017 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10018 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10019 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10020 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10021 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10022 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10023 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10024 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10025 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10026 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10027 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10028 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10029 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010030};
10031
James Ketrenosb095c382005-08-24 22:04:42 -050010032enum {
10033 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10034 IPW_PRIV_GET_POWER,
10035 IPW_PRIV_SET_MODE,
10036 IPW_PRIV_GET_MODE,
10037 IPW_PRIV_SET_PREAMBLE,
10038 IPW_PRIV_GET_PREAMBLE,
10039 IPW_PRIV_RESET,
10040 IPW_PRIV_SW_RESET,
10041#ifdef CONFIG_IPW2200_MONITOR
10042 IPW_PRIV_SET_MONITOR,
10043#endif
10044};
James Ketrenos43f66a62005-03-25 12:31:53 -060010045
Jeff Garzikbf794512005-07-31 13:07:26 -040010046static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010047 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010048 .cmd = IPW_PRIV_SET_POWER,
10049 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10050 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010051 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010052 .cmd = IPW_PRIV_GET_POWER,
10053 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10054 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010056 .cmd = IPW_PRIV_SET_MODE,
10057 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10058 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010060 .cmd = IPW_PRIV_GET_MODE,
10061 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10062 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010063 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010064 .cmd = IPW_PRIV_SET_PREAMBLE,
10065 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10066 .name = "set_preamble"},
10067 {
10068 .cmd = IPW_PRIV_GET_PREAMBLE,
10069 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10070 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010072 IPW_PRIV_RESET,
10073 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010074 {
10075 IPW_PRIV_SW_RESET,
10076 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10077#ifdef CONFIG_IPW2200_MONITOR
10078 {
10079 IPW_PRIV_SET_MONITOR,
10080 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10081#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010082};
10083
10084static iw_handler ipw_priv_handler[] = {
10085 ipw_wx_set_powermode,
10086 ipw_wx_get_powermode,
10087 ipw_wx_set_wireless_mode,
10088 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010089 ipw_wx_set_preamble,
10090 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010091 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010092 ipw_wx_sw_reset,
10093#ifdef CONFIG_IPW2200_MONITOR
10094 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010095#endif
10096};
10097
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010098static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010099 .standard = ipw_wx_handlers,
10100 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10101 .num_private = ARRAY_SIZE(ipw_priv_handler),
10102 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10103 .private = ipw_priv_handler,
10104 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010105 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010106};
10107
James Ketrenos43f66a62005-03-25 12:31:53 -060010108/*
10109 * Get wireless statistics.
10110 * Called by /proc/net/wireless
10111 * Also called by SIOCGIWSTATS
10112 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010113static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010114{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010115 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010116 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010117
James Ketrenos43f66a62005-03-25 12:31:53 -060010118 wstats = &priv->wstats;
10119
James Ketrenosea2b26e2005-08-24 21:25:16 -050010120 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010121 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010122 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10123 * and associated; if not associcated, the values are all meaningless
10124 * anyway, so set them all to NULL and INVALID */
10125 if (!(priv->status & STATUS_ASSOCIATED)) {
10126 wstats->miss.beacon = 0;
10127 wstats->discard.retries = 0;
10128 wstats->qual.qual = 0;
10129 wstats->qual.level = 0;
10130 wstats->qual.noise = 0;
10131 wstats->qual.updated = 7;
10132 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010133 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010134 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010135 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010136
10137 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010138 wstats->qual.level = priv->exp_avg_rssi;
10139 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010140 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010141 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010142
10143 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10144 wstats->discard.retries = priv->last_tx_failures;
10145 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010146
James Ketrenos43f66a62005-03-25 12:31:53 -060010147/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10148 goto fail_get_ordinal;
10149 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010150
James Ketrenos43f66a62005-03-25 12:31:53 -060010151 return wstats;
10152}
10153
James Ketrenos43f66a62005-03-25 12:31:53 -060010154/* net device stuff */
10155
Arjan van de Ven858119e2006-01-14 13:20:43 -080010156static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010157{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010158 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010159 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010160 sys_config->answer_broadcast_ssid_probe = 0;
10161 sys_config->accept_all_data_frames = 0;
10162 sys_config->accept_non_directed_frames = 1;
10163 sys_config->exclude_unicast_unencrypted = 0;
10164 sys_config->disable_unicast_decryption = 1;
10165 sys_config->exclude_multicast_unencrypted = 0;
10166 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010167 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10168 antenna = CFG_SYS_ANTENNA_BOTH;
10169 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010170 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010171 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010172 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010173 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010174 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010175 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010176}
10177
10178static int ipw_net_open(struct net_device *dev)
10179{
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010181 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010182 return 0;
10183}
10184
10185static int ipw_net_stop(struct net_device *dev)
10186{
10187 IPW_DEBUG_INFO("dev->close\n");
10188 netif_stop_queue(dev);
10189 return 0;
10190}
10191
10192/*
10193todo:
10194
10195modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010196we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010197*/
10198
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010199static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010200 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010201{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010202 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010203 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010204 int i = 0;
10205 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010206#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010207 int tx_id = ipw_get_tx_queue_number(priv, pri);
10208 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10209#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010210 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010211#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010212 struct clx2_queue *q = &txq->q;
10213 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010214 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010215
Zhu Yib8ddafd2008-11-27 13:42:20 +080010216 if (!(priv->status & STATUS_ASSOCIATED))
10217 goto drop;
10218
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010219 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010220 switch (priv->ieee->iw_mode) {
10221 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010222 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010223 id = ipw_find_station(priv, hdr->addr1);
10224 if (id == IPW_INVALID_STATION) {
10225 id = ipw_add_station(priv, hdr->addr1);
10226 if (id == IPW_INVALID_STATION) {
10227 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010228 "invalid cell: %pM\n",
10229 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010230 goto drop;
10231 }
10232 }
10233 break;
10234
10235 case IW_MODE_INFRA:
10236 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010237 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010238 id = 0;
10239 break;
10240 }
10241
10242 tfd = &txq->bd[q->first_empty];
10243 txq->txb[q->first_empty] = txb;
10244 memset(tfd, 0, sizeof(*tfd));
10245 tfd->u.data.station_number = id;
10246
10247 tfd->control_flags.message_type = TX_FRAME_TYPE;
10248 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10249
10250 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010251 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010252
James Ketrenos43f66a62005-03-25 12:31:53 -060010253 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010254 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010255 else
James Ketrenosb095c382005-08-24 22:04:42 -050010256 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010257
James Ketrenosea2b26e2005-08-24 21:25:16 -050010258 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10259 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010260
James Ketrenosc848d0a2005-08-24 21:56:24 -050010261 fc = le16_to_cpu(hdr->frame_ctl);
10262 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010263
10264 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10265
James Ketrenosb095c382005-08-24 22:04:42 -050010266 if (likely(unicast))
10267 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10268
10269 if (txb->encrypted && !priv->ieee->host_encrypt) {
10270 switch (priv->ieee->sec.level) {
10271 case SEC_LEVEL_3:
10272 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010273 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010274 /* XXX: ACK flag must be set for CCMP even if it
10275 * is a multicast/broadcast packet, because CCMP
10276 * group communication encrypted by GTK is
10277 * actually done by the AP. */
10278 if (!unicast)
10279 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10280
10281 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10282 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10283 tfd->u.data.key_index = 0;
10284 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10285 break;
10286 case SEC_LEVEL_2:
10287 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010288 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010289 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10290 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10291 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10292 break;
10293 case SEC_LEVEL_1:
10294 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010295 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010296 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10297 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010298 40)
10299 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10300 else
10301 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10302 break;
10303 case SEC_LEVEL_0:
10304 break;
10305 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010306 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010307 priv->ieee->sec.level);
10308 break;
10309 }
10310 } else
10311 /* No hardware encryption */
10312 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10313
Zhu Yie43e3c12006-04-13 17:20:45 +080010314#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010315 if (fc & IEEE80211_STYPE_QOS_DATA)
10316 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010317#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010318
James Ketrenos43f66a62005-03-25 12:31:53 -060010319 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010320 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10321 txb->nr_frags));
10322 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10323 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10324 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10325 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10326 i, le32_to_cpu(tfd->u.data.num_chunks),
10327 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010328 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010329 i, tfd->u.data.num_chunks,
10330 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010331 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010332 txb->fragments[i]->len - hdr_len);
10333
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010334 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010335 cpu_to_le32(pci_map_single
10336 (priv->pci_dev,
10337 txb->fragments[i]->data + hdr_len,
10338 txb->fragments[i]->len - hdr_len,
10339 PCI_DMA_TODEVICE));
10340 tfd->u.data.chunk_len[i] =
10341 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010342 }
10343
10344 if (i != txb->nr_frags) {
10345 struct sk_buff *skb;
10346 u16 remaining_bytes = 0;
10347 int j;
10348
10349 for (j = i; j < txb->nr_frags; j++)
10350 remaining_bytes += txb->fragments[j]->len - hdr_len;
10351
10352 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10353 remaining_bytes);
10354 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10355 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010356 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010357 for (j = i; j < txb->nr_frags; j++) {
10358 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010359
James Ketrenos43f66a62005-03-25 12:31:53 -060010360 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010361 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010362 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010363 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010364 }
10365 dev_kfree_skb_any(txb->fragments[i]);
10366 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010367 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010368 cpu_to_le32(pci_map_single
10369 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010370 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010371 PCI_DMA_TODEVICE));
10372
Marcin Slusarz5c058632008-02-13 00:06:12 +010010373 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010374 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010375 }
10376
10377 /* kick DMA */
10378 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10379 ipw_write32(priv, q->reg_w, q->first_empty);
10380
Dan Williams943dbef2008-02-14 17:49:41 -050010381 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010382 netif_stop_queue(priv->net_dev);
10383
James Ketrenos227d2dc2005-07-28 16:25:55 -050010384 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010385
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010386 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010387 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010388 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010389 return NETDEV_TX_OK;
10390}
10391
10392static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10393{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010394 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010395#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010396 int tx_id = ipw_get_tx_queue_number(priv, pri);
10397 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10398#else
10399 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010400#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010401
Dan Williams943dbef2008-02-14 17:49:41 -050010402 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010403 return 1;
10404
10405 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010406}
10407
Zhu Yid685b8c2006-04-13 17:20:27 +080010408#ifdef CONFIG_IPW2200_PROMISCUOUS
10409static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010410 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010411{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010412 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010413 struct ieee80211_hdr *hdr;
10414 u8 n;
10415 u16 filter = priv->prom_priv->filter;
10416 int hdr_only = 0;
10417
10418 if (filter & IPW_PROM_NO_TX)
10419 return;
10420
10421 memset(&dummystats, 0, sizeof(dummystats));
10422
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010423 /* Filtering of fragment chains is done against the first fragment */
Zhu Yid685b8c2006-04-13 17:20:27 +080010424 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010425 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010426 if (filter & IPW_PROM_NO_MGMT)
10427 return;
10428 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10429 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010430 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010431 if (filter & IPW_PROM_NO_CTL)
10432 return;
10433 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10434 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010435 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010436 if (filter & IPW_PROM_NO_DATA)
10437 return;
10438 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10439 hdr_only = 1;
10440 }
10441
10442 for(n=0; n<txb->nr_frags; ++n) {
10443 struct sk_buff *src = txb->fragments[n];
10444 struct sk_buff *dst;
10445 struct ieee80211_radiotap_header *rt_hdr;
10446 int len;
10447
10448 if (hdr_only) {
10449 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010450 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010451 } else
10452 len = src->len;
10453
Johannes Berg007e5dd2008-11-27 23:13:38 +010010454 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10455 if (!dst)
10456 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010457
10458 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10459
10460 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10461 rt_hdr->it_pad = 0;
10462 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010463 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010464
Al Viroe62e1ee2007-12-27 01:36:46 -050010465 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010466 ieee80211chan2mhz(priv->channel));
10467 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010468 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010469 cpu_to_le16(IEEE80211_CHAN_OFDM |
10470 IEEE80211_CHAN_5GHZ);
10471 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010472 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010473 cpu_to_le16(IEEE80211_CHAN_CCK |
10474 IEEE80211_CHAN_2GHZ);
10475 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010476 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010477 cpu_to_le16(IEEE80211_CHAN_OFDM |
10478 IEEE80211_CHAN_2GHZ);
10479
Al Viro743b84d2007-12-27 01:43:16 -050010480 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010481
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010482 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010483
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010484 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010485 dev_kfree_skb_any(dst);
10486 }
10487}
10488#endif
10489
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010490static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10491 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010492{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010493 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010494 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010495 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010496
10497 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010498 spin_lock_irqsave(&priv->lock, flags);
10499
Zhu Yid685b8c2006-04-13 17:20:27 +080010500#ifdef CONFIG_IPW2200_PROMISCUOUS
10501 if (rtap_iface && netif_running(priv->prom_net_dev))
10502 ipw_handle_promiscuous_tx(priv, txb);
10503#endif
10504
James Ketrenos227d2dc2005-07-28 16:25:55 -050010505 ret = ipw_tx_skb(priv, txb, pri);
10506 if (ret == NETDEV_TX_OK)
10507 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010508 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010509
James Ketrenos227d2dc2005-07-28 16:25:55 -050010510 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010511}
10512
James Ketrenos43f66a62005-03-25 12:31:53 -060010513static void ipw_net_set_multicast_list(struct net_device *dev)
10514{
10515
10516}
10517
10518static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10519{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010520 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010521 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010522
James Ketrenos43f66a62005-03-25 12:31:53 -060010523 if (!is_valid_ether_addr(addr->sa_data))
10524 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010525 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010526 priv->config |= CFG_CUSTOM_MAC;
10527 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010528 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10529 priv->net_dev->name, priv->mac_addr);
Tejun Heobcb6d912011-01-26 12:12:50 +010010530 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010531 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010532 return 0;
10533}
10534
Jeff Garzikbf794512005-07-31 13:07:26 -040010535static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010536 struct ethtool_drvinfo *info)
10537{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010538 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010539 char vers[64];
10540 char date[32];
10541 u32 len;
10542
10543 strcpy(info->driver, DRV_NAME);
10544 strcpy(info->version, DRV_VERSION);
10545
10546 len = sizeof(vers);
10547 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10548 len = sizeof(date);
10549 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10550
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010551 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010552 vers, date);
10553 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010554 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010555}
10556
10557static u32 ipw_ethtool_get_link(struct net_device *dev)
10558{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010559 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010560 return (priv->status & STATUS_ASSOCIATED) != 0;
10561}
10562
10563static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10564{
James Ketrenosb095c382005-08-24 22:04:42 -050010565 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010566}
10567
10568static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010569 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010570{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010571 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010572
James Ketrenosb095c382005-08-24 22:04:42 -050010573 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010574 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010575 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010576 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010577 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010578 return 0;
10579}
10580
10581static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010582 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010583{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010584 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010585 int i;
10586
James Ketrenosb095c382005-08-24 22:04:42 -050010587 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010588 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010589 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010590 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010591 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10592 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010593 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010594 return 0;
10595}
10596
Jeff Garzik7282d492006-09-13 14:30:00 -040010597static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010598 .get_link = ipw_ethtool_get_link,
10599 .get_drvinfo = ipw_ethtool_get_drvinfo,
10600 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10601 .get_eeprom = ipw_ethtool_get_eeprom,
10602 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010603};
10604
David Howells7d12e782006-10-05 14:55:46 +010010605static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010606{
10607 struct ipw_priv *priv = data;
10608 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010609
James Ketrenos43f66a62005-03-25 12:31:53 -060010610 if (!priv)
10611 return IRQ_NONE;
10612
Zhu Yi89c318e2006-06-08 22:19:49 -070010613 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010614
10615 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010616 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010617 goto none;
10618 }
10619
James Ketrenosb095c382005-08-24 22:04:42 -050010620 inta = ipw_read32(priv, IPW_INTA_RW);
10621 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010622
James Ketrenos43f66a62005-03-25 12:31:53 -060010623 if (inta == 0xFFFFFFFF) {
10624 /* Hardware disappeared */
10625 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10626 goto none;
10627 }
10628
James Ketrenosb095c382005-08-24 22:04:42 -050010629 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010630 /* Shared interrupt */
10631 goto none;
10632 }
10633
10634 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010635 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010636
James Ketrenos43f66a62005-03-25 12:31:53 -060010637 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010638 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10639 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010640
James Ketrenos43f66a62005-03-25 12:31:53 -060010641 /* Cache INTA value for our tasklet */
10642 priv->isr_inta = inta;
10643
10644 tasklet_schedule(&priv->irq_tasklet);
10645
Zhu Yi89c318e2006-06-08 22:19:49 -070010646 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010647
10648 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010649 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010650 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010651 return IRQ_NONE;
10652}
10653
10654static void ipw_rf_kill(void *adapter)
10655{
10656 struct ipw_priv *priv = adapter;
10657 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010658
James Ketrenos43f66a62005-03-25 12:31:53 -060010659 spin_lock_irqsave(&priv->lock, flags);
10660
10661 if (rf_kill_active(priv)) {
10662 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010010663 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010664 goto exit_unlock;
10665 }
10666
10667 /* RF Kill is now disabled, so bring the device back up */
10668
10669 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10670 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10671 "device\n");
10672
10673 /* we can not do an adapter restart while inside an irq lock */
Tejun Heobcb6d912011-01-26 12:12:50 +010010674 schedule_work(&priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010675 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010676 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10677 "enabled\n");
10678
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010679 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010680 spin_unlock_irqrestore(&priv->lock, flags);
10681}
10682
David Howellsc4028952006-11-22 14:57:56 +000010683static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010684{
David Howellsc4028952006-11-22 14:57:56 +000010685 struct ipw_priv *priv =
10686 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010687 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010688 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010689 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010690}
10691
Adrian Bunka73e22b2006-01-21 01:39:42 +010010692static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010693{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010694 priv->last_seq_num = -1;
10695 priv->last_frag_num = -1;
10696 priv->last_packet_time = 0;
10697
James Ketrenosa613bff2005-08-24 21:43:11 -050010698 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010699
James Ketrenosc848d0a2005-08-24 21:56:24 -050010700 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010701 cancel_delayed_work(&priv->request_direct_scan);
10702 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010703 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010704 ipw_reset_stats(priv);
10705 /* Ensure the rate is updated immediately */
10706 priv->last_rate = ipw_get_current_rate(priv);
10707 ipw_gather_stats(priv);
10708 ipw_led_link_up(priv);
10709 notify_wx_assoc_event(priv);
10710
10711 if (priv->config & CFG_BACKGROUND_SCAN)
Tejun Heobcb6d912011-01-26 12:12:50 +010010712 schedule_delayed_work(&priv->request_scan, HZ);
James Ketrenosa613bff2005-08-24 21:43:11 -050010713}
10714
David Howellsc4028952006-11-22 14:57:56 +000010715static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010716{
David Howellsc4028952006-11-22 14:57:56 +000010717 struct ipw_priv *priv =
10718 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010719 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010720 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010721 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010722}
10723
Adrian Bunka73e22b2006-01-21 01:39:42 +010010724static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010725{
10726 ipw_led_link_down(priv);
10727 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010728 notify_wx_assoc_event(priv);
10729
10730 /* Cancel any queued work ... */
10731 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010732 cancel_delayed_work(&priv->request_direct_scan);
10733 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010734 cancel_delayed_work(&priv->adhoc_check);
10735 cancel_delayed_work(&priv->gather_stats);
10736
10737 ipw_reset_stats(priv);
10738
James Ketrenosafbf30a2005-08-25 00:05:33 -050010739 if (!(priv->status & STATUS_EXIT_PENDING)) {
10740 /* Queue up another scan... */
Tejun Heobcb6d912011-01-26 12:12:50 +010010741 schedule_delayed_work(&priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010742 } else
10743 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010744}
10745
David Howellsc4028952006-11-22 14:57:56 +000010746static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010747{
David Howellsc4028952006-11-22 14:57:56 +000010748 struct ipw_priv *priv =
10749 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010750 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010751 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010752 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010753}
10754
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010755static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010756{
10757 int ret = 0;
10758
James Ketrenos43f66a62005-03-25 12:31:53 -060010759 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010760 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010761
David Howellsc4028952006-11-22 14:57:56 +000010762 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10763 INIT_WORK(&priv->associate, ipw_bg_associate);
10764 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10765 INIT_WORK(&priv->system_config, ipw_system_config);
10766 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10767 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10768 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10769 INIT_WORK(&priv->up, ipw_bg_up);
10770 INIT_WORK(&priv->down, ipw_bg_down);
10771 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010772 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10773 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010774 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010775 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10776 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10777 INIT_WORK(&priv->roam, ipw_bg_roam);
10778 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10779 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10780 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10781 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10782 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10783 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10784 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010785
Zhu Yie43e3c12006-04-13 17:20:45 +080010786#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010787 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010788#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010789
10790 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10791 ipw_irq_tasklet, (unsigned long)priv);
10792
10793 return ret;
10794}
10795
James Ketrenos43f66a62005-03-25 12:31:53 -060010796static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010797 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010798{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010799 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010800 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010801 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010802 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010803 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010804 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010805 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010806 priv->ieee->sec.flags &= ~(1 << i);
10807 else {
10808 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010810 priv->ieee->sec.flags |= (1 << i);
10811 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010812 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010813 } else if (sec->level != SEC_LEVEL_1)
10814 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010815 }
10816
James Ketrenosb095c382005-08-24 22:04:42 -050010817 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010818 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010819 priv->ieee->sec.active_key = sec->active_key;
10820 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010821 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010822 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010823 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010824 } else
10825 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010826
10827 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010828 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10829 priv->ieee->sec.auth_mode = sec->auth_mode;
10830 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010831 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10832 priv->capability |= CAP_SHARED_KEY;
10833 else
10834 priv->capability &= ~CAP_SHARED_KEY;
10835 priv->status |= STATUS_SECURITY_UPDATED;
10836 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010837
James Ketrenosb095c382005-08-24 22:04:42 -050010838 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10839 priv->ieee->sec.flags |= SEC_ENABLED;
10840 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010841 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010842 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010843 priv->capability |= CAP_PRIVACY_ON;
10844 else
10845 priv->capability &= ~CAP_PRIVACY_ON;
10846 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010847
James Ketrenosafbf30a2005-08-25 00:05:33 -050010848 if (sec->flags & SEC_ENCRYPT)
10849 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010850
James Ketrenosb095c382005-08-24 22:04:42 -050010851 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10852 priv->ieee->sec.level = sec->level;
10853 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010854 priv->status |= STATUS_SECURITY_UPDATED;
10855 }
10856
Zhu Yi1fbfea52005-08-05 17:22:56 +080010857 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10858 ipw_set_hwcrypto_keys(priv);
10859
Jeff Garzikbf794512005-07-31 13:07:26 -040010860 /* To match current functionality of ipw2100 (which works well w/
10861 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010862 * privacy capability changes ... */
10863#if 0
10864 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010865 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010866 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010867 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010868 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010869 IPW_DEBUG_ASSOC("Disassociating due to capability "
10870 "change.\n");
10871 ipw_disassociate(priv);
10872 }
10873#endif
10874}
10875
Jeff Garzikbf794512005-07-31 13:07:26 -040010876static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010877 struct ipw_supported_rates *rates)
10878{
10879 /* TODO: Mask out rates based on priv->rates_mask */
10880
10881 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010882 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010883 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010884 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010885 rates->ieee_mode = IPW_A_MODE;
10886 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010887 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10888 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010889 break;
10890
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010891 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 rates->ieee_mode = IPW_G_MODE;
10893 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010894 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10895 LIBIPW_CCK_DEFAULT_RATES_MASK);
10896 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10897 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10898 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010899 }
10900 break;
10901 }
10902
10903 return 0;
10904}
10905
Jeff Garzikbf794512005-07-31 13:07:26 -040010906static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010907{
James Ketrenos43f66a62005-03-25 12:31:53 -060010908 /* This is only called from ipw_up, which resets/reloads the firmware
10909 so, we don't need to first disable the card before we configure
10910 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010911 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010912 goto error;
10913
10914 /* initialize adapter address */
10915 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10916 goto error;
10917
10918 /* set basic system config settings */
10919 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010920
10921 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10922 * Does not support BT priority yet (don't abort or defer our Tx) */
10923 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010924 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010925
10926 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10927 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010928 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010929 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10930 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010931 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010932 }
10933
Zhu Yid685b8c2006-04-13 17:20:27 +080010934#ifdef CONFIG_IPW2200_PROMISCUOUS
10935 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10936 priv->sys_config.accept_all_data_frames = 1;
10937 priv->sys_config.accept_non_directed_frames = 1;
10938 priv->sys_config.accept_all_mgmt_bcpr = 1;
10939 priv->sys_config.accept_all_mgmt_frames = 1;
10940 }
10941#endif
10942
James Ketrenosc848d0a2005-08-24 21:56:24 -050010943 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10944 priv->sys_config.answer_broadcast_ssid_probe = 1;
10945 else
10946 priv->sys_config.answer_broadcast_ssid_probe = 0;
10947
Zhu Yid685b8c2006-04-13 17:20:27 +080010948 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010949 goto error;
10950
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010951 init_supported_rates(priv, &priv->rates);
10952 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010953 goto error;
10954
10955 /* Set request-to-send threshold */
10956 if (priv->rts_threshold) {
10957 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10958 goto error;
10959 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010960#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010961 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10962 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010963#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010964
10965 if (ipw_set_random_seed(priv))
10966 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010967
James Ketrenos43f66a62005-03-25 12:31:53 -060010968 /* final state transition to the RUN state */
10969 if (ipw_send_host_complete(priv))
10970 goto error;
10971
James Ketrenose6666192005-08-12 09:17:04 -050010972 priv->status |= STATUS_INIT;
10973
10974 ipw_led_init(priv);
10975 ipw_led_radio_on(priv);
10976 priv->notif_missed_beacons = 0;
10977
10978 /* Set hardware WEP key if it is configured. */
10979 if ((priv->capability & CAP_PRIVACY_ON) &&
10980 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10981 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10982 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010983
10984 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010985
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010986 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010987 return -EIO;
10988}
10989
James Ketrenos4f36f802005-08-03 20:36:56 -050010990/*
10991 * NOTE:
10992 *
10993 * These tables have been tested in conjunction with the
10994 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10995 *
10996 * Altering this values, using it on other hardware, or in geographies
10997 * not intended for resale of the above mentioned Intel adapters has
10998 * not been tested.
10999 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011000 * Remember to update the table in README.ipw2200 when changing this
11001 * table.
11002 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011003 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011004static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011005 { /* Restricted */
11006 "---",
11007 .bg_channels = 11,
11008 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11009 {2427, 4}, {2432, 5}, {2437, 6},
11010 {2442, 7}, {2447, 8}, {2452, 9},
11011 {2457, 10}, {2462, 11}},
11012 },
11013
11014 { /* Custom US/Canada */
11015 "ZZF",
11016 .bg_channels = 11,
11017 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11018 {2427, 4}, {2432, 5}, {2437, 6},
11019 {2442, 7}, {2447, 8}, {2452, 9},
11020 {2457, 10}, {2462, 11}},
11021 .a_channels = 8,
11022 .a = {{5180, 36},
11023 {5200, 40},
11024 {5220, 44},
11025 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011026 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11027 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11028 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11029 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011030 },
11031
11032 { /* Rest of World */
11033 "ZZD",
11034 .bg_channels = 13,
11035 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11036 {2427, 4}, {2432, 5}, {2437, 6},
11037 {2442, 7}, {2447, 8}, {2452, 9},
11038 {2457, 10}, {2462, 11}, {2467, 12},
11039 {2472, 13}},
11040 },
11041
11042 { /* Custom USA & Europe & High */
11043 "ZZA",
11044 .bg_channels = 11,
11045 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11046 {2427, 4}, {2432, 5}, {2437, 6},
11047 {2442, 7}, {2447, 8}, {2452, 9},
11048 {2457, 10}, {2462, 11}},
11049 .a_channels = 13,
11050 .a = {{5180, 36},
11051 {5200, 40},
11052 {5220, 44},
11053 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011054 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11055 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11056 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11057 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011058 {5745, 149},
11059 {5765, 153},
11060 {5785, 157},
11061 {5805, 161},
11062 {5825, 165}},
11063 },
11064
11065 { /* Custom NA & Europe */
11066 "ZZB",
11067 .bg_channels = 11,
11068 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11069 {2427, 4}, {2432, 5}, {2437, 6},
11070 {2442, 7}, {2447, 8}, {2452, 9},
11071 {2457, 10}, {2462, 11}},
11072 .a_channels = 13,
11073 .a = {{5180, 36},
11074 {5200, 40},
11075 {5220, 44},
11076 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011077 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11078 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11079 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11080 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11081 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11082 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11083 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11084 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11085 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011086 },
11087
11088 { /* Custom Japan */
11089 "ZZC",
11090 .bg_channels = 11,
11091 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11092 {2427, 4}, {2432, 5}, {2437, 6},
11093 {2442, 7}, {2447, 8}, {2452, 9},
11094 {2457, 10}, {2462, 11}},
11095 .a_channels = 4,
11096 .a = {{5170, 34}, {5190, 38},
11097 {5210, 42}, {5230, 46}},
11098 },
11099
11100 { /* Custom */
11101 "ZZM",
11102 .bg_channels = 11,
11103 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11104 {2427, 4}, {2432, 5}, {2437, 6},
11105 {2442, 7}, {2447, 8}, {2452, 9},
11106 {2457, 10}, {2462, 11}},
11107 },
11108
11109 { /* Europe */
11110 "ZZE",
11111 .bg_channels = 13,
11112 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11113 {2427, 4}, {2432, 5}, {2437, 6},
11114 {2442, 7}, {2447, 8}, {2452, 9},
11115 {2457, 10}, {2462, 11}, {2467, 12},
11116 {2472, 13}},
11117 .a_channels = 19,
11118 .a = {{5180, 36},
11119 {5200, 40},
11120 {5220, 44},
11121 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011122 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11123 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11124 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11125 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11126 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11127 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11128 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11129 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11130 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11131 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11132 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11133 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11134 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11135 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11136 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011137 },
11138
11139 { /* Custom Japan */
11140 "ZZJ",
11141 .bg_channels = 14,
11142 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11143 {2427, 4}, {2432, 5}, {2437, 6},
11144 {2442, 7}, {2447, 8}, {2452, 9},
11145 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011146 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011147 .a_channels = 4,
11148 .a = {{5170, 34}, {5190, 38},
11149 {5210, 42}, {5230, 46}},
11150 },
11151
James Ketrenos03520572005-10-19 16:12:31 -050011152 { /* Rest of World */
11153 "ZZR",
11154 .bg_channels = 14,
11155 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11156 {2427, 4}, {2432, 5}, {2437, 6},
11157 {2442, 7}, {2447, 8}, {2452, 9},
11158 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011159 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11160 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011161 },
11162
James Ketrenos4f36f802005-08-03 20:36:56 -050011163 { /* High Band */
11164 "ZZH",
11165 .bg_channels = 13,
11166 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11167 {2427, 4}, {2432, 5}, {2437, 6},
11168 {2442, 7}, {2447, 8}, {2452, 9},
11169 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011170 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11171 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011172 .a_channels = 4,
11173 .a = {{5745, 149}, {5765, 153},
11174 {5785, 157}, {5805, 161}},
11175 },
11176
11177 { /* Custom Europe */
11178 "ZZG",
11179 .bg_channels = 13,
11180 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11181 {2427, 4}, {2432, 5}, {2437, 6},
11182 {2442, 7}, {2447, 8}, {2452, 9},
11183 {2457, 10}, {2462, 11},
11184 {2467, 12}, {2472, 13}},
11185 .a_channels = 4,
11186 .a = {{5180, 36}, {5200, 40},
11187 {5220, 44}, {5240, 48}},
11188 },
11189
11190 { /* Europe */
11191 "ZZK",
11192 .bg_channels = 13,
11193 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11194 {2427, 4}, {2432, 5}, {2437, 6},
11195 {2442, 7}, {2447, 8}, {2452, 9},
11196 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011197 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11198 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011199 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011200 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11201 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11202 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11203 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11204 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11205 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11206 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11207 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11208 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11209 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11210 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11211 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11212 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11213 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11214 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11215 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11216 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11217 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11218 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11219 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11220 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11221 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11222 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11223 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011224 },
11225
11226 { /* Europe */
11227 "ZZL",
11228 .bg_channels = 11,
11229 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11230 {2427, 4}, {2432, 5}, {2437, 6},
11231 {2442, 7}, {2447, 8}, {2452, 9},
11232 {2457, 10}, {2462, 11}},
11233 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011234 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11235 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11236 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11237 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11238 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11239 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11240 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11241 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11242 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11243 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11244 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11245 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11246 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011247 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011248};
11249
James Ketrenos43f66a62005-03-25 12:31:53 -060011250#define MAX_HW_RESTARTS 5
11251static int ipw_up(struct ipw_priv *priv)
11252{
James Ketrenos4f36f802005-08-03 20:36:56 -050011253 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011254
Dan Williamsc3d72b92009-02-11 13:26:06 -050011255 /* Age scan list entries found before suspend */
11256 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011257 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011258 priv->suspend_time = 0;
11259 }
11260
James Ketrenos43f66a62005-03-25 12:31:53 -060011261 if (priv->status & STATUS_EXIT_PENDING)
11262 return -EIO;
11263
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011264 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011265 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011266 GFP_KERNEL);
11267 if (priv->cmdlog == NULL) {
11268 IPW_ERROR("Error allocating %d command log entries.\n",
11269 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011270 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011271 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011272 priv->cmdlog_len = cmdlog;
11273 }
11274 }
11275
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011276 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011277 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011278 * Also start the clocks. */
11279 rc = ipw_load(priv);
11280 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011281 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011282 return rc;
11283 }
11284
11285 ipw_init_ordinals(priv);
11286 if (!(priv->config & CFG_CUSTOM_MAC))
11287 eeprom_parse_mac(priv, priv->mac_addr);
11288 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011289 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011290
James Ketrenos4f36f802005-08-03 20:36:56 -050011291 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11292 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11293 ipw_geos[j].name, 3))
11294 break;
11295 }
James Ketrenos03520572005-10-19 16:12:31 -050011296 if (j == ARRAY_SIZE(ipw_geos)) {
11297 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11298 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11299 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11300 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011301 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011302 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011303 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011304 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011305 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011306 }
11307
James Ketrenosb095c382005-08-24 22:04:42 -050011308 if (priv->status & STATUS_RF_KILL_SW) {
11309 IPW_WARNING("Radio disabled by module parameter.\n");
11310 return 0;
11311 } else if (rf_kill_active(priv)) {
11312 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11313 "Kill switch must be turned off for "
11314 "wireless networking to work.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010011315 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011316 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011317 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011318
11319 rc = ipw_config(priv);
11320 if (!rc) {
11321 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011322
James Ketrenose6666192005-08-12 09:17:04 -050011323 /* If configure to try and auto-associate, kick
11324 * off a scan. */
Tejun Heobcb6d912011-01-26 12:12:50 +010011325 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011326
James Ketrenos43f66a62005-03-25 12:31:53 -060011327 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011328 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011329
James Ketrenosc848d0a2005-08-24 21:56:24 -050011330 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011331 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11332 i, MAX_HW_RESTARTS);
11333
11334 /* We had an error bringing up the hardware, so take it
11335 * all the way back down so we can try again */
11336 ipw_down(priv);
11337 }
11338
Jeff Garzikbf794512005-07-31 13:07:26 -040011339 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011340 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011341 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011342
James Ketrenos43f66a62005-03-25 12:31:53 -060011343 return -EIO;
11344}
11345
David Howellsc4028952006-11-22 14:57:56 +000011346static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011347{
David Howellsc4028952006-11-22 14:57:56 +000011348 struct ipw_priv *priv =
11349 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011350 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011351 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011352 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011353}
11354
James Ketrenosb095c382005-08-24 22:04:42 -050011355static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011356{
James Ketrenosb095c382005-08-24 22:04:42 -050011357 int i;
11358
11359 if (priv->status & STATUS_SCANNING) {
11360 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11361 ipw_abort_scan(priv);
11362 }
11363
11364 if (priv->status & STATUS_ASSOCIATED) {
11365 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11366 ipw_disassociate(priv);
11367 }
11368
11369 ipw_led_shutdown(priv);
11370
11371 /* Wait up to 1s for status to change to not scanning and not
11372 * associated (disassociation can take a while for a ful 802.11
11373 * exchange */
11374 for (i = 1000; i && (priv->status &
11375 (STATUS_DISASSOCIATING |
11376 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11377 udelay(10);
11378
11379 if (priv->status & (STATUS_DISASSOCIATING |
11380 STATUS_ASSOCIATED | STATUS_SCANNING))
11381 IPW_DEBUG_INFO("Still associated or scanning...\n");
11382 else
11383 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11384
James Ketrenosc848d0a2005-08-24 21:56:24 -050011385 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011386 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011387
11388 priv->status &= ~STATUS_INIT;
11389}
11390
James Ketrenos43f66a62005-03-25 12:31:53 -060011391static void ipw_down(struct ipw_priv *priv)
11392{
James Ketrenosb095c382005-08-24 22:04:42 -050011393 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11394
11395 priv->status |= STATUS_EXIT_PENDING;
11396
11397 if (ipw_is_init(priv))
11398 ipw_deinit(priv);
11399
11400 /* Wipe out the EXIT_PENDING status bit if we are not actually
11401 * exiting the module */
11402 if (!exit_pending)
11403 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011404
11405 /* tell the device to stop sending interrupts */
11406 ipw_disable_interrupts(priv);
11407
11408 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011409 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011410 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011411
11412 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011413
11414 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011415}
11416
David Howellsc4028952006-11-22 14:57:56 +000011417static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011418{
David Howellsc4028952006-11-22 14:57:56 +000011419 struct ipw_priv *priv =
11420 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011421 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011422 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011423 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011424}
11425
11426/* Called by register_netdev() */
11427static int ipw_net_init(struct net_device *dev)
11428{
John W. Linvillea3caa992009-08-25 14:12:25 -040011429 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011430 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011431 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11432 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011433 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011434
James Ketrenosc848d0a2005-08-24 21:56:24 -050011435 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011436 rc = -EIO;
11437 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011438 }
11439
John W. Linvillea3caa992009-08-25 14:12:25 -040011440 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11441
11442 /* fill-out priv->ieee->bg_band */
11443 if (geo->bg_channels) {
11444 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11445
11446 bg_band->band = IEEE80211_BAND_2GHZ;
11447 bg_band->n_channels = geo->bg_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011448 bg_band->channels = kcalloc(geo->bg_channels,
11449 sizeof(struct ieee80211_channel),
11450 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011451 if (!bg_band->channels) {
11452 rc = -ENOMEM;
11453 goto out;
11454 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011455 /* translate geo->bg to bg_band.channels */
11456 for (i = 0; i < geo->bg_channels; i++) {
11457 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11458 bg_band->channels[i].center_freq = geo->bg[i].freq;
11459 bg_band->channels[i].hw_value = geo->bg[i].channel;
11460 bg_band->channels[i].max_power = geo->bg[i].max_power;
11461 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11462 bg_band->channels[i].flags |=
11463 IEEE80211_CHAN_PASSIVE_SCAN;
11464 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11465 bg_band->channels[i].flags |=
11466 IEEE80211_CHAN_NO_IBSS;
11467 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11468 bg_band->channels[i].flags |=
11469 IEEE80211_CHAN_RADAR;
11470 /* No equivalent for LIBIPW_CH_80211H_RULES,
11471 LIBIPW_CH_UNIFORM_SPREADING, or
11472 LIBIPW_CH_B_ONLY... */
11473 }
11474 /* point at bitrate info */
11475 bg_band->bitrates = ipw2200_bg_rates;
11476 bg_band->n_bitrates = ipw2200_num_bg_rates;
11477
11478 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11479 }
11480
11481 /* fill-out priv->ieee->a_band */
11482 if (geo->a_channels) {
11483 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11484
11485 a_band->band = IEEE80211_BAND_5GHZ;
11486 a_band->n_channels = geo->a_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011487 a_band->channels = kcalloc(geo->a_channels,
11488 sizeof(struct ieee80211_channel),
11489 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011490 if (!a_band->channels) {
11491 rc = -ENOMEM;
11492 goto out;
11493 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011494 /* translate geo->bg to a_band.channels */
11495 for (i = 0; i < geo->a_channels; i++) {
11496 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11497 a_band->channels[i].center_freq = geo->a[i].freq;
11498 a_band->channels[i].hw_value = geo->a[i].channel;
11499 a_band->channels[i].max_power = geo->a[i].max_power;
11500 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11501 a_band->channels[i].flags |=
11502 IEEE80211_CHAN_PASSIVE_SCAN;
11503 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11504 a_band->channels[i].flags |=
11505 IEEE80211_CHAN_NO_IBSS;
11506 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11507 a_band->channels[i].flags |=
11508 IEEE80211_CHAN_RADAR;
11509 /* No equivalent for LIBIPW_CH_80211H_RULES,
11510 LIBIPW_CH_UNIFORM_SPREADING, or
11511 LIBIPW_CH_B_ONLY... */
11512 }
11513 /* point at bitrate info */
11514 a_band->bitrates = ipw2200_a_rates;
11515 a_band->n_bitrates = ipw2200_num_a_rates;
11516
11517 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11518 }
11519
11520 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11521
11522 /* With that information in place, we can now register the wiphy... */
11523 if (wiphy_register(wdev->wiphy)) {
11524 rc = -EIO;
11525 goto out;
11526 }
11527
11528out:
Zhu Yi46441512006-01-24 16:37:59 +080011529 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011530 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011531}
11532
11533/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011534static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011535 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11536 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11537 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11538 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11539 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11540 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11541 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11542 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11543 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11544 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11545 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011552 {PCI_VDEVICE(INTEL, 0x104f), 0},
11553 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11554 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11555 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11556 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011557
James Ketrenos43f66a62005-03-25 12:31:53 -060011558 /* required last entry */
11559 {0,}
11560};
11561
11562MODULE_DEVICE_TABLE(pci, card_ids);
11563
11564static struct attribute *ipw_sysfs_entries[] = {
11565 &dev_attr_rf_kill.attr,
11566 &dev_attr_direct_dword.attr,
11567 &dev_attr_indirect_byte.attr,
11568 &dev_attr_indirect_dword.attr,
11569 &dev_attr_mem_gpio_reg.attr,
11570 &dev_attr_command_event_reg.attr,
11571 &dev_attr_nic_type.attr,
11572 &dev_attr_status.attr,
11573 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011574 &dev_attr_error.attr,
11575 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011576 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011577 &dev_attr_eeprom_delay.attr,
11578 &dev_attr_ucode_version.attr,
11579 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011580 &dev_attr_scan_age.attr,
11581 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011582 &dev_attr_speed_scan.attr,
11583 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011584 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011585#ifdef CONFIG_IPW2200_PROMISCUOUS
11586 &dev_attr_rtap_iface.attr,
11587 &dev_attr_rtap_filter.attr,
11588#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011589 NULL
11590};
11591
11592static struct attribute_group ipw_attribute_group = {
11593 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011594 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011595};
11596
Zhu Yid685b8c2006-04-13 17:20:27 +080011597#ifdef CONFIG_IPW2200_PROMISCUOUS
11598static int ipw_prom_open(struct net_device *dev)
11599{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011600 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011601 struct ipw_priv *priv = prom_priv->priv;
11602
11603 IPW_DEBUG_INFO("prom dev->open\n");
11604 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011605
11606 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11607 priv->sys_config.accept_all_data_frames = 1;
11608 priv->sys_config.accept_non_directed_frames = 1;
11609 priv->sys_config.accept_all_mgmt_bcpr = 1;
11610 priv->sys_config.accept_all_mgmt_frames = 1;
11611
11612 ipw_send_system_config(priv);
11613 }
11614
11615 return 0;
11616}
11617
11618static int ipw_prom_stop(struct net_device *dev)
11619{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011620 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011621 struct ipw_priv *priv = prom_priv->priv;
11622
11623 IPW_DEBUG_INFO("prom dev->stop\n");
11624
11625 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11626 priv->sys_config.accept_all_data_frames = 0;
11627 priv->sys_config.accept_non_directed_frames = 0;
11628 priv->sys_config.accept_all_mgmt_bcpr = 0;
11629 priv->sys_config.accept_all_mgmt_frames = 0;
11630
11631 ipw_send_system_config(priv);
11632 }
11633
11634 return 0;
11635}
11636
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011637static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11638 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011639{
11640 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011641 dev_kfree_skb(skb);
11642 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011643}
11644
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011645static const struct net_device_ops ipw_prom_netdev_ops = {
11646 .ndo_open = ipw_prom_open,
11647 .ndo_stop = ipw_prom_stop,
11648 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011649 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011650 .ndo_set_mac_address = eth_mac_addr,
11651 .ndo_validate_addr = eth_validate_addr,
11652};
11653
Zhu Yid685b8c2006-04-13 17:20:27 +080011654static int ipw_prom_alloc(struct ipw_priv *priv)
11655{
11656 int rc = 0;
11657
11658 if (priv->prom_net_dev)
11659 return -EPERM;
11660
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011661 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011662 if (priv->prom_net_dev == NULL)
11663 return -ENOMEM;
11664
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011665 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011666 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11667 priv->prom_priv->priv = priv;
11668
11669 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011670 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011671
11672 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011673 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011674
11675 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011676 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011677
11678 rc = register_netdev(priv->prom_net_dev);
11679 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011680 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011681 priv->prom_net_dev = NULL;
11682 return rc;
11683 }
11684
11685 return 0;
11686}
11687
11688static void ipw_prom_free(struct ipw_priv *priv)
11689{
11690 if (!priv->prom_net_dev)
11691 return;
11692
11693 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011694 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011695
11696 priv->prom_net_dev = NULL;
11697}
11698
11699#endif
11700
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011701static const struct net_device_ops ipw_netdev_ops = {
11702 .ndo_init = ipw_net_init,
11703 .ndo_open = ipw_net_open,
11704 .ndo_stop = ipw_net_stop,
11705 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11706 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011707 .ndo_start_xmit = libipw_xmit,
11708 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011709 .ndo_validate_addr = eth_validate_addr,
11710};
Zhu Yid685b8c2006-04-13 17:20:27 +080011711
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011712static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11713 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011714{
11715 int err = 0;
11716 struct net_device *net_dev;
11717 void __iomem *base;
11718 u32 length, val;
11719 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011720 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011721
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011722 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011723 if (net_dev == NULL) {
11724 err = -ENOMEM;
11725 goto out;
11726 }
11727
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011728 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011729 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011730
James Ketrenos43f66a62005-03-25 12:31:53 -060011731 priv->net_dev = net_dev;
11732 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011733 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011734 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011735 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011736 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11737 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011738
Zhu Yi46441512006-01-24 16:37:59 +080011739 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011740 if (pci_enable_device(pdev)) {
11741 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011742 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011743 }
11744
11745 pci_set_master(pdev);
11746
Yang Hongyang284901a2009-04-06 19:01:15 -070011747 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011748 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011749 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011750 if (err) {
11751 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11752 goto out_pci_disable_device;
11753 }
11754
11755 pci_set_drvdata(pdev, priv);
11756
11757 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011758 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011759 goto out_pci_disable_device;
11760
Jeff Garzikbf794512005-07-31 13:07:26 -040011761 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011762 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011763 pci_read_config_dword(pdev, 0x40, &val);
11764 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011765 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011766
James Ketrenos43f66a62005-03-25 12:31:53 -060011767 length = pci_resource_len(pdev, 0);
11768 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011769
Arjan van de Ven275f1652008-10-20 21:42:39 -070011770 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011771 if (!base) {
11772 err = -ENODEV;
11773 goto out_pci_release_regions;
11774 }
11775
11776 priv->hw_base = base;
11777 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11778 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11779
11780 err = ipw_setup_deferred_work(priv);
11781 if (err) {
11782 IPW_ERROR("Unable to setup deferred work\n");
11783 goto out_iounmap;
11784 }
11785
James Ketrenosb095c382005-08-24 22:04:42 -050011786 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011787
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011788 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011789 if (err) {
11790 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
Tejun Heobcb6d912011-01-26 12:12:50 +010011791 goto out_iounmap;
James Ketrenos43f66a62005-03-25 12:31:53 -060011792 }
11793
James Ketrenos43f66a62005-03-25 12:31:53 -060011794 SET_NETDEV_DEV(net_dev, &pdev->dev);
11795
Zhu Yi46441512006-01-24 16:37:59 +080011796 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011797
James Ketrenos43f66a62005-03-25 12:31:53 -060011798 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11799 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011800 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011801
Zhu Yie43e3c12006-04-13 17:20:45 +080011802#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011803 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011804 priv->ieee->handle_probe_response = ipw_handle_beacon;
11805 priv->ieee->handle_beacon = ipw_handle_probe_response;
11806 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011807#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011808
James Ketrenosc848d0a2005-08-24 21:56:24 -050011809 priv->ieee->perfect_rssi = -20;
11810 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011811
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011812 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011813 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011814 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011815 net_dev->wireless_handlers = &ipw_wx_handler_def;
11816 net_dev->ethtool_ops = &ipw_ethtool_ops;
11817 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011818 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011819 net_dev->mem_start = pci_resource_start(pdev, 0);
11820 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11821
11822 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11823 if (err) {
11824 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011825 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011826 goto out_release_irq;
11827 }
11828
Zhu Yi46441512006-01-24 16:37:59 +080011829 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011830 err = register_netdev(net_dev);
11831 if (err) {
11832 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011833 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011834 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011835
Zhu Yid685b8c2006-04-13 17:20:27 +080011836#ifdef CONFIG_IPW2200_PROMISCUOUS
11837 if (rtap_iface) {
11838 err = ipw_prom_alloc(priv);
11839 if (err) {
11840 IPW_ERROR("Failed to register promiscuous network "
11841 "device (error %d).\n", err);
11842 unregister_netdev(priv->net_dev);
11843 goto out_remove_sysfs;
11844 }
11845 }
11846#endif
11847
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011848 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11849 "channels, %d 802.11a channels)\n",
11850 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11851 priv->ieee->geo.a_channels);
11852
James Ketrenos43f66a62005-03-25 12:31:53 -060011853 return 0;
11854
James Ketrenosa613bff2005-08-24 21:43:11 -050011855 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011856 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011857 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011858 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011859 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011860 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011861 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011862 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011863 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011864 pci_disable_device(pdev);
11865 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011866 out_free_libipw:
11867 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011868 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011869 return err;
11870}
11871
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011872static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011873{
11874 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011875 struct list_head *p, *q;
11876 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011877
James Ketrenos43f66a62005-03-25 12:31:53 -060011878 if (!priv)
11879 return;
11880
Zhu Yi46441512006-01-24 16:37:59 +080011881 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011882
James Ketrenosafbf30a2005-08-25 00:05:33 -050011883 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011884 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011885 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11886
Zhu Yi46441512006-01-24 16:37:59 +080011887 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011888
11889 unregister_netdev(priv->net_dev);
11890
11891 if (priv->rxq) {
11892 ipw_rx_queue_free(priv, priv->rxq);
11893 priv->rxq = NULL;
11894 }
11895 ipw_tx_queue_free(priv);
11896
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011897 if (priv->cmdlog) {
11898 kfree(priv->cmdlog);
11899 priv->cmdlog = NULL;
11900 }
Tejun Heobcb6d912011-01-26 12:12:50 +010011901
11902 /* make sure all works are inactive */
11903 cancel_delayed_work_sync(&priv->adhoc_check);
11904 cancel_work_sync(&priv->associate);
11905 cancel_work_sync(&priv->disassociate);
11906 cancel_work_sync(&priv->system_config);
11907 cancel_work_sync(&priv->rx_replenish);
11908 cancel_work_sync(&priv->adapter_restart);
11909 cancel_delayed_work_sync(&priv->rf_kill);
11910 cancel_work_sync(&priv->up);
11911 cancel_work_sync(&priv->down);
11912 cancel_delayed_work_sync(&priv->request_scan);
11913 cancel_delayed_work_sync(&priv->request_direct_scan);
11914 cancel_delayed_work_sync(&priv->request_passive_scan);
11915 cancel_delayed_work_sync(&priv->scan_event);
11916 cancel_delayed_work_sync(&priv->gather_stats);
11917 cancel_work_sync(&priv->abort_scan);
11918 cancel_work_sync(&priv->roam);
11919 cancel_delayed_work_sync(&priv->scan_check);
11920 cancel_work_sync(&priv->link_up);
11921 cancel_work_sync(&priv->link_down);
11922 cancel_delayed_work_sync(&priv->led_link_on);
11923 cancel_delayed_work_sync(&priv->led_link_off);
11924 cancel_delayed_work_sync(&priv->led_act_off);
11925 cancel_work_sync(&priv->merge_networks);
James Ketrenos43f66a62005-03-25 12:31:53 -060011926
James Ketrenosafbf30a2005-08-25 00:05:33 -050011927 /* Free MAC hash list for ADHOC */
11928 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11929 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011930 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011931 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011932 }
11933 }
11934
Jesper Juhl8f760782006-06-27 02:55:06 -070011935 kfree(priv->error);
11936 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011937
Zhu Yid685b8c2006-04-13 17:20:27 +080011938#ifdef CONFIG_IPW2200_PROMISCUOUS
11939 ipw_prom_free(priv);
11940#endif
11941
James Ketrenos43f66a62005-03-25 12:31:53 -060011942 free_irq(pdev->irq, priv);
11943 iounmap(priv->hw_base);
11944 pci_release_regions(pdev);
11945 pci_disable_device(pdev);
11946 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011947 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011948 wiphy_unregister(priv->ieee->wdev.wiphy);
11949 kfree(priv->ieee->a_band.channels);
11950 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011951 free_libipw(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011952 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011953}
11954
James Ketrenos43f66a62005-03-25 12:31:53 -060011955#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011956static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011957{
11958 struct ipw_priv *priv = pci_get_drvdata(pdev);
11959 struct net_device *dev = priv->net_dev;
11960
11961 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11962
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011963 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011964 ipw_down(priv);
11965
11966 /* Remove the PRESENT state of the device */
11967 netif_device_detach(dev);
11968
James Ketrenos43f66a62005-03-25 12:31:53 -060011969 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011970 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011971 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011972
Dan Williamsc3d72b92009-02-11 13:26:06 -050011973 priv->suspend_at = get_seconds();
11974
James Ketrenos43f66a62005-03-25 12:31:53 -060011975 return 0;
11976}
11977
11978static int ipw_pci_resume(struct pci_dev *pdev)
11979{
11980 struct ipw_priv *priv = pci_get_drvdata(pdev);
11981 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011982 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011983 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011984
James Ketrenos43f66a62005-03-25 12:31:53 -060011985 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11986
James Ketrenosea2b26e2005-08-24 21:25:16 -050011987 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011988 err = pci_enable_device(pdev);
11989 if (err) {
11990 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11991 dev->name);
11992 return err;
11993 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011994 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011995
James Ketrenos43f66a62005-03-25 12:31:53 -060011996 /*
11997 * Suspend/Resume resets the PCI configuration space, so we have to
11998 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11999 * from interfering with C3 CPU state. pci_restore_state won't help
12000 * here since it only restores the first 64 bytes pci config header.
12001 */
Jeff Garzikbf794512005-07-31 13:07:26 -040012002 pci_read_config_dword(pdev, 0x40, &val);
12003 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060012004 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12005
12006 /* Set the device back into the PRESENT state; this will also wake
12007 * the queue of needed */
12008 netif_device_attach(dev);
12009
Dan Williamsc3d72b92009-02-11 13:26:06 -050012010 priv->suspend_time = get_seconds() - priv->suspend_at;
12011
James Ketrenos43f66a62005-03-25 12:31:53 -060012012 /* Bring the device back up */
Tejun Heobcb6d912011-01-26 12:12:50 +010012013 schedule_work(&priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012014
James Ketrenos43f66a62005-03-25 12:31:53 -060012015 return 0;
12016}
12017#endif
12018
Zhu Yic8c22c92006-08-21 11:38:39 +080012019static void ipw_pci_shutdown(struct pci_dev *pdev)
12020{
12021 struct ipw_priv *priv = pci_get_drvdata(pdev);
12022
12023 /* Take down the device; powers it off, etc. */
12024 ipw_down(priv);
12025
12026 pci_disable_device(pdev);
12027}
12028
James Ketrenos43f66a62005-03-25 12:31:53 -060012029/* driver initialization stuff */
12030static struct pci_driver ipw_driver = {
12031 .name = DRV_NAME,
12032 .id_table = card_ids,
12033 .probe = ipw_pci_probe,
12034 .remove = __devexit_p(ipw_pci_remove),
12035#ifdef CONFIG_PM
12036 .suspend = ipw_pci_suspend,
12037 .resume = ipw_pci_resume,
12038#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012039 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012040};
12041
12042static int __init ipw_init(void)
12043{
12044 int ret;
12045
12046 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12047 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12048
Jeff Garzik29917622006-08-19 17:48:59 -040012049 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012050 if (ret) {
12051 IPW_ERROR("Unable to initialize PCI module\n");
12052 return ret;
12053 }
12054
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012055 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012056 if (ret) {
12057 IPW_ERROR("Unable to create driver sysfs file\n");
12058 pci_unregister_driver(&ipw_driver);
12059 return ret;
12060 }
12061
12062 return ret;
12063}
12064
12065static void __exit ipw_exit(void)
12066{
12067 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12068 pci_unregister_driver(&ipw_driver);
12069}
12070
12071module_param(disable, int, 0444);
12072MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12073
12074module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012075MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012076
12077module_param(auto_create, int, 0444);
12078MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12079
Reinette Chatre21f8a732009-08-18 10:25:05 -070012080module_param_named(led, led_support, int, 0444);
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000012081MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012082
James Ketrenos43f66a62005-03-25 12:31:53 -060012083module_param(debug, int, 0444);
12084MODULE_PARM_DESC(debug, "debug output mask");
12085
Reinette Chatre21f8a732009-08-18 10:25:05 -070012086module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012087MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012088
Zhu Yid685b8c2006-04-13 17:20:27 +080012089#ifdef CONFIG_IPW2200_PROMISCUOUS
12090module_param(rtap_iface, int, 0444);
12091MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12092#endif
12093
Zhu Yie43e3c12006-04-13 17:20:45 +080012094#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012095module_param(qos_enable, int, 0444);
12096MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012097
James Ketrenosb095c382005-08-24 22:04:42 -050012098module_param(qos_burst_enable, int, 0444);
12099MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12100
12101module_param(qos_no_ack_mask, int, 0444);
12102MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12103
12104module_param(burst_duration_CCK, int, 0444);
12105MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12106
12107module_param(burst_duration_OFDM, int, 0444);
12108MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012109#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012110
12111#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012112module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012113MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12114#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012115module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012116MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12117#endif
12118
Zhu Yi810dabd2006-01-24 16:36:59 +080012119module_param(bt_coexist, int, 0444);
12120MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12121
James Ketrenosb095c382005-08-24 22:04:42 -050012122module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012123MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012124
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012125module_param(cmdlog, int, 0444);
12126MODULE_PARM_DESC(cmdlog,
12127 "allocate a ring buffer for logging firmware commands");
12128
Zhu Yi4bfdb912006-01-24 16:37:16 +080012129module_param(roaming, int, 0444);
12130MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12131
Zhu Yid2b83e12006-04-13 17:19:36 +080012132module_param(antenna, int, 0444);
12133MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12134
James Ketrenos43f66a62005-03-25 12:31:53 -060012135module_exit(ipw_exit);
12136module_init(ipw_init);