blob: 2b022571a8595a5dd41c89bdd515d0f1fd0dc70b [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
Johannes Berg776d68f2011-11-09 21:33:45 +0100134/* Ugly macro to convert literal channel numbers into their mhz equivalents
135 * There are certianly some conditions that will break this (like feeding it '30')
136 * but they shouldn't arise since nothing talks on channel 30. */
137#define ieee80211chan2mhz(x) \
138 (((x) <= 14) ? \
139 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
140 ((x) + 1000) * 5)
141
Zhu Yie43e3c12006-04-13 17:20:45 +0800142#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500143static int qos_enable = 0;
144static int qos_burst_enable = 0;
145static int qos_no_ack_mask = 0;
146static int burst_duration_CCK = 0;
147static int burst_duration_OFDM = 0;
148
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400149static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500150 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
151 QOS_TX3_CW_MIN_OFDM},
152 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
153 QOS_TX3_CW_MAX_OFDM},
154 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
155 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
156 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
157 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
158};
159
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400160static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500161 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
162 QOS_TX3_CW_MIN_CCK},
163 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
164 QOS_TX3_CW_MAX_CCK},
165 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
166 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
167 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
168 QOS_TX3_TXOP_LIMIT_CCK}
169};
170
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400171static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500172 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
173 DEF_TX3_CW_MIN_OFDM},
174 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
175 DEF_TX3_CW_MAX_OFDM},
176 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
177 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
178 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
179 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
180};
181
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400182static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500183 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
184 DEF_TX3_CW_MIN_CCK},
185 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
186 DEF_TX3_CW_MAX_CCK},
187 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
188 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
189 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
190 DEF_TX3_TXOP_LIMIT_CCK}
191};
192
193static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
194
195static int from_priority_to_tx_queue[] = {
196 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
197 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
198};
199
200static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
201
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400202static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500203 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400204static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500205 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800206#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500207
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000208static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500209static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600210static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400211static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600212 struct clx2_tx_queue *txq, int qindex);
213static int ipw_queue_reset(struct ipw_priv *priv);
214
215static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
216 int len, int sync);
217
218static void ipw_tx_queue_free(struct ipw_priv *);
219
220static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
221static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
222static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600223static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000224static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600225static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000226static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600227static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400228static int init_supported_rates(struct ipw_priv *priv,
229 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500230static void ipw_set_hwcrypto_keys(struct ipw_priv *);
231static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600232
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500233static int snprint_line(char *buf, size_t count,
234 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600235{
236 int out, i, j, l;
237 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400238
James Ketrenos43f66a62005-03-25 12:31:53 -0600239 out = snprintf(buf, count, "%08X", ofs);
240
241 for (l = 0, i = 0; i < 2; i++) {
242 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400243 for (j = 0; j < 8 && l < len; j++, l++)
244 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600245 data[(i * 8 + j)]);
246 for (; j < 8; j++)
247 out += snprintf(buf + out, count - out, " ");
248 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400249
James Ketrenos43f66a62005-03-25 12:31:53 -0600250 out += snprintf(buf + out, count - out, " ");
251 for (l = 0, i = 0; i < 2; i++) {
252 out += snprintf(buf + out, count - out, " ");
253 for (j = 0; j < 8 && l < len; j++, l++) {
254 c = data[(i * 8 + j)];
255 if (!isascii(c) || !isprint(c))
256 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400257
James Ketrenos43f66a62005-03-25 12:31:53 -0600258 out += snprintf(buf + out, count - out, "%c", c);
259 }
260
261 for (; j < 8; j++)
262 out += snprintf(buf + out, count - out, " ");
263 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400264
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500265 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600266}
267
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400268static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600269{
270 char line[81];
271 u32 ofs = 0;
272 if (!(ipw_debug_level & level))
273 return;
274
275 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500276 snprint_line(line, sizeof(line), &data[ofs],
277 min(len, 16U), ofs);
278 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600279 ofs += 16;
280 len -= min(len, 16U);
281 }
282}
283
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500284static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
285{
286 size_t out = size;
287 u32 ofs = 0;
288 int total = 0;
289
290 while (size && len) {
291 out = snprint_line(output, size, &data[ofs],
292 min_t(size_t, len, 16U), ofs);
293
294 ofs += 16;
295 output += out;
296 size -= out;
297 len -= min_t(size_t, len, 16U);
298 total += out;
299 }
300 return total;
301}
302
Zhu Yic8fe6672006-01-24 16:36:36 +0800303/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600304static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
305#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
306
Zhu Yic8fe6672006-01-24 16:36:36 +0800307/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600308static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
309#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
310
Zhu Yic8fe6672006-01-24 16:36:36 +0800311/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600312static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
313static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
314{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
316 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600317 _ipw_write_reg8(a, b, c);
318}
319
Zhu Yic8fe6672006-01-24 16:36:36 +0800320/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600321static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
322static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
323{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400324 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
325 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 _ipw_write_reg16(a, b, c);
327}
328
Zhu Yic8fe6672006-01-24 16:36:36 +0800329/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600330static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
331static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
332{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400333 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
334 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600335 _ipw_write_reg32(a, b, c);
336}
337
Zhu Yic8fe6672006-01-24 16:36:36 +0800338/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100339static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
340 u8 val)
341{
342 writeb(val, ipw->hw_base + ofs);
343}
Zhu Yic8fe6672006-01-24 16:36:36 +0800344
345/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200346#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100347 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
348 __LINE__, (u32)(ofs), (u32)(val)); \
349 _ipw_write8(ipw, ofs, val); \
350} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600351
Zhu Yic8fe6672006-01-24 16:36:36 +0800352/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100353static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
354 u16 val)
355{
356 writew(val, ipw->hw_base + ofs);
357}
Zhu Yic8fe6672006-01-24 16:36:36 +0800358
359/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100360#define ipw_write16(ipw, ofs, val) do { \
361 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
362 __LINE__, (u32)(ofs), (u32)(val)); \
363 _ipw_write16(ipw, ofs, val); \
364} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600365
Zhu Yic8fe6672006-01-24 16:36:36 +0800366/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100367static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
368 u32 val)
369{
370 writel(val, ipw->hw_base + ofs);
371}
Zhu Yic8fe6672006-01-24 16:36:36 +0800372
373/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100374#define ipw_write32(ipw, ofs, val) do { \
375 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
376 __LINE__, (u32)(ofs), (u32)(val)); \
377 _ipw_write32(ipw, ofs, val); \
378} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600379
Zhu Yic8fe6672006-01-24 16:36:36 +0800380/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100381static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400382{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100383 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600384}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400385
Zhu Yic8fe6672006-01-24 16:36:36 +0800386/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100387#define ipw_read8(ipw, ofs) ({ \
388 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
389 (u32)(ofs)); \
390 _ipw_read8(ipw, ofs); \
391})
James Ketrenos43f66a62005-03-25 12:31:53 -0600392
Zhu Yic8fe6672006-01-24 16:36:36 +0800393/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100394static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400395{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100396 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600397}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400398
Zhu Yic8fe6672006-01-24 16:36:36 +0800399/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100400#define ipw_read16(ipw, ofs) ({ \
401 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
402 (u32)(ofs)); \
403 _ipw_read16(ipw, ofs); \
404})
James Ketrenos43f66a62005-03-25 12:31:53 -0600405
Zhu Yic8fe6672006-01-24 16:36:36 +0800406/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100407static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400408{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100409 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600410}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400411
Zhu Yic8fe6672006-01-24 16:36:36 +0800412/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100413#define ipw_read32(ipw, ofs) ({ \
414 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
415 (u32)(ofs)); \
416 _ipw_read32(ipw, ofs); \
417})
James Ketrenos43f66a62005-03-25 12:31:53 -0600418
419static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800420/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100421#define ipw_read_indirect(a, b, c, d) ({ \
422 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
423 __LINE__, (u32)(b), (u32)(d)); \
424 _ipw_read_indirect(a, b, c, d); \
425})
James Ketrenos43f66a62005-03-25 12:31:53 -0600426
Zhu Yic8fe6672006-01-24 16:36:36 +0800427/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400428static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
429 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100430#define ipw_write_indirect(a, b, c, d) do { \
431 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
432 __LINE__, (u32)(b), (u32)(d)); \
433 _ipw_write_indirect(a, b, c, d); \
434} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600435
Zhu Yic8fe6672006-01-24 16:36:36 +0800436/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400437static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600438{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400439 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500440 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
441 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600442}
443
Zhu Yic8fe6672006-01-24 16:36:36 +0800444/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600445static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
446{
Zhu Yi2638bc32006-01-24 16:37:52 +0800447 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800448 u32 dif_len = reg - aligned_addr;
449
James Ketrenos43f66a62005-03-25 12:31:53 -0600450 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800451 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
452 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600453}
454
Zhu Yic8fe6672006-01-24 16:36:36 +0800455/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400456static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600457{
Zhu Yi2638bc32006-01-24 16:37:52 +0800458 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800459 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
460
James Ketrenos43f66a62005-03-25 12:31:53 -0600461 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800462 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
463 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600464}
465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600467static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
468{
469 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500470 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100471 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500472 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400473 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600474}
475
Zhu Yic8fe6672006-01-24 16:36:36 +0800476/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600477static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
478{
479 u32 value;
480
481 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
482
James Ketrenosb095c382005-08-24 22:04:42 -0500483 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
484 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100485 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 return value;
487}
488
Zhu Yic8fe6672006-01-24 16:36:36 +0800489/* General purpose, no alignment requirement, iterative (multi-byte) read, */
490/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600491static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
492 int num)
493{
Zhu Yi2638bc32006-01-24 16:37:52 +0800494 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600496 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400497
James Ketrenos43f66a62005-03-25 12:31:53 -0600498 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
499
James Ketrenosea2b26e2005-08-24 21:25:16 -0500500 if (num <= 0) {
501 return;
502 }
503
Zhu Yic8fe6672006-01-24 16:36:36 +0800504 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600505 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500506 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600507 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500508 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500509 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600510 aligned_addr += 4;
511 }
512
Zhu Yic8fe6672006-01-24 16:36:36 +0800513 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500514 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500515 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500516 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400517
Zhu Yic8fe6672006-01-24 16:36:36 +0800518 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500519 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500520 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500521 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500522 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500523 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600524}
525
Zhu Yic8fe6672006-01-24 16:36:36 +0800526/* General purpose, no alignment requirement, iterative (multi-byte) write, */
527/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400528static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600529 int num)
530{
Zhu Yi2638bc32006-01-24 16:37:52 +0800531 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600532 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600533 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400534
James Ketrenos43f66a62005-03-25 12:31:53 -0600535 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400536
James Ketrenosea2b26e2005-08-24 21:25:16 -0500537 if (num <= 0) {
538 return;
539 }
540
Zhu Yic8fe6672006-01-24 16:36:36 +0800541 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600542 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500543 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800544 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500545 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500546 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600547 aligned_addr += 4;
548 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400549
Zhu Yic8fe6672006-01-24 16:36:36 +0800550 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500551 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500552 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500553 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400554
Zhu Yic8fe6672006-01-24 16:36:36 +0800555 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500556 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500557 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500558 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500559 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500560 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600561}
562
Zhu Yic8fe6672006-01-24 16:36:36 +0800563/* General purpose, no alignment requirement, iterative (multi-byte) write, */
564/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400565static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600566 int num)
567{
568 memcpy_toio((priv->hw_base + addr), buf, num);
569}
570
Zhu Yic8fe6672006-01-24 16:36:36 +0800571/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600572static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
573{
574 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
575}
576
Zhu Yic8fe6672006-01-24 16:36:36 +0800577/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600578static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
579{
580 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
581}
582
Zhu Yi89c318e2006-06-08 22:19:49 -0700583static inline void __ipw_enable_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_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600592{
593 if (!(priv->status & STATUS_INT_ENABLED))
594 return;
595 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500596 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600597}
598
Zhu Yi89c318e2006-06-08 22:19:49 -0700599static inline void ipw_enable_interrupts(struct ipw_priv *priv)
600{
601 unsigned long flags;
602
603 spin_lock_irqsave(&priv->irq_lock, flags);
604 __ipw_enable_interrupts(priv);
605 spin_unlock_irqrestore(&priv->irq_lock, flags);
606}
607
608static inline void ipw_disable_interrupts(struct ipw_priv *priv)
609{
610 unsigned long flags;
611
612 spin_lock_irqsave(&priv->irq_lock, flags);
613 __ipw_disable_interrupts(priv);
614 spin_unlock_irqrestore(&priv->irq_lock, flags);
615}
616
James Ketrenos43f66a62005-03-25 12:31:53 -0600617static char *ipw_error_desc(u32 val)
618{
619 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400620 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600621 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400622 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600623 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400624 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600625 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400626 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600627 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400628 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500629 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400630 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500631 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400632 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500633 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400634 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500635 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400636 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500637 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400638 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500639 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400640 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500641 return "DMA_STATUS";
642 case IPW_FW_ERROR_DINO_ERROR:
643 return "DINO_ERROR";
644 case IPW_FW_ERROR_EEPROM_ERROR:
645 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400646 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500647 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400648 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500649 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400650 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500651 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600652 }
653}
654
James Ketrenosb39860c2005-08-12 09:36:32 -0500655static void ipw_dump_error_log(struct ipw_priv *priv,
656 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600657{
James Ketrenosb39860c2005-08-12 09:36:32 -0500658 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600659
James Ketrenosb39860c2005-08-12 09:36:32 -0500660 if (!error) {
661 IPW_ERROR("Error allocating and capturing error log. "
662 "Nothing to dump.\n");
663 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600664 }
665
James Ketrenosb39860c2005-08-12 09:36:32 -0500666 IPW_ERROR("Start IPW Error Log Dump:\n");
667 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
668 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600669
James Ketrenosb39860c2005-08-12 09:36:32 -0500670 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400671 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500672 ipw_error_desc(error->elem[i].desc),
673 error->elem[i].time,
674 error->elem[i].blink1,
675 error->elem[i].blink2,
676 error->elem[i].link1,
677 error->elem[i].link2, error->elem[i].data);
678 for (i = 0; i < error->log_len; i++)
679 IPW_ERROR("%i\t0x%08x\t%i\n",
680 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500681 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600682}
James Ketrenos43f66a62005-03-25 12:31:53 -0600683
James Ketrenosc848d0a2005-08-24 21:56:24 -0500684static inline int ipw_is_init(struct ipw_priv *priv)
685{
686 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600687}
688
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400689static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600690{
691 u32 addr, field_info, field_len, field_count, total_len;
692
693 IPW_DEBUG_ORD("ordinal = %i\n", ord);
694
695 if (!priv || !val || !len) {
696 IPW_DEBUG_ORD("Invalid argument\n");
697 return -EINVAL;
698 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400699
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 /* verify device ordinal tables have been initialized */
701 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
702 IPW_DEBUG_ORD("Access ordinals before initialization\n");
703 return -EINVAL;
704 }
705
706 switch (IPW_ORD_TABLE_ID_MASK & ord) {
707 case IPW_ORD_TABLE_0_MASK:
708 /*
709 * TABLE 0: Direct access to a table of 32 bit values
710 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400711 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600712 * read from the table
713 */
714
715 /* remove the table id from the ordinal */
716 ord &= IPW_ORD_TABLE_VALUE_MASK;
717
718 /* boundary check */
719 if (ord > priv->table0_len) {
720 IPW_DEBUG_ORD("ordinal value (%i) longer then "
721 "max (%i)\n", ord, priv->table0_len);
722 return -EINVAL;
723 }
724
725 /* verify we have enough room to store the value */
726 if (*len < sizeof(u32)) {
727 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200728 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600729 return -EINVAL;
730 }
731
732 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400733 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600734
735 *len = sizeof(u32);
736 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400737 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600738 break;
739
740 case IPW_ORD_TABLE_1_MASK:
741 /*
742 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400743 *
744 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600745 * representing starting addr for the data (which is
746 * also a u32)
747 */
748
749 /* remove the table id from the ordinal */
750 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400751
James Ketrenos43f66a62005-03-25 12:31:53 -0600752 /* boundary check */
753 if (ord > priv->table1_len) {
754 IPW_DEBUG_ORD("ordinal value too long\n");
755 return -EINVAL;
756 }
757
758 /* verify we have enough room to store the value */
759 if (*len < sizeof(u32)) {
760 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200761 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600762 return -EINVAL;
763 }
764
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400765 *((u32 *) val) =
766 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600767 *len = sizeof(u32);
768 break;
769
770 case IPW_ORD_TABLE_2_MASK:
771 /*
772 * TABLE 2: Indirect access to a table of variable sized values
773 *
774 * This table consist of six values, each containing
775 * - dword containing the starting offset of the data
776 * - dword containing the lengh in the first 16bits
777 * and the count in the second 16bits
778 */
779
780 /* remove the table id from the ordinal */
781 ord &= IPW_ORD_TABLE_VALUE_MASK;
782
783 /* boundary check */
784 if (ord > priv->table2_len) {
785 IPW_DEBUG_ORD("ordinal value too long\n");
786 return -EINVAL;
787 }
788
789 /* get the address of statistic */
790 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400791
792 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600793 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400794 field_info =
795 ipw_read_reg32(priv,
796 priv->table2_addr + (ord << 3) +
797 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400798
James Ketrenos43f66a62005-03-25 12:31:53 -0600799 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400800 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400801
James Ketrenos43f66a62005-03-25 12:31:53 -0600802 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400803 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400804
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200805 /* abort if not enough memory */
James Ketrenos43f66a62005-03-25 12:31:53 -0600806 total_len = field_len * field_count;
807 if (total_len > *len) {
808 *len = total_len;
809 return -EINVAL;
810 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400811
James Ketrenos43f66a62005-03-25 12:31:53 -0600812 *len = total_len;
813 if (!total_len)
814 return 0;
815
816 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400817 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600818 addr, total_len, field_info);
819 ipw_read_indirect(priv, addr, val, total_len);
820 break;
821
822 default:
823 IPW_DEBUG_ORD("Invalid ordinal!\n");
824 return -EINVAL;
825
826 }
827
James Ketrenos43f66a62005-03-25 12:31:53 -0600828 return 0;
829}
830
831static void ipw_init_ordinals(struct ipw_priv *priv)
832{
833 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400834 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600835
836 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
837 priv->table0_addr, priv->table0_len);
838
839 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
840 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
841
842 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
843 priv->table1_addr, priv->table1_len);
844
845 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
846 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400847 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600848
849 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
850 priv->table2_addr, priv->table2_len);
851
852}
853
Adrian Bunka73e22b2006-01-21 01:39:42 +0100854static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500855{
James Ketrenosb095c382005-08-24 22:04:42 -0500856 reg &= ~IPW_START_STANDBY;
857 if (reg & IPW_GATE_ODMA)
858 reg &= ~IPW_GATE_ODMA;
859 if (reg & IPW_GATE_IDMA)
860 reg &= ~IPW_GATE_IDMA;
861 if (reg & IPW_GATE_ADMA)
862 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500863 return reg;
864}
865
866/*
867 * LED behavior:
868 * - On radio ON, turn on any LEDs that require to be on during start
869 * - On initialization, start unassociated blink
870 * - On association, disable unassociated blink
871 * - On disassociation, start unassociated blink
872 * - On radio OFF, turn off any LEDs started during radio on
873 *
874 */
Zhu Yiede61112006-01-24 16:37:10 +0800875#define LD_TIME_LINK_ON msecs_to_jiffies(300)
876#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
877#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500878
Adrian Bunka73e22b2006-01-21 01:39:42 +0100879static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500880{
881 unsigned long flags;
882 u32 led;
883
884 /* If configured to not use LEDs, or nic_type is 1,
885 * then we don't toggle a LINK led */
886 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
887 return;
888
889 spin_lock_irqsave(&priv->lock, flags);
890
891 if (!(priv->status & STATUS_RF_KILL_MASK) &&
892 !(priv->status & STATUS_LED_LINK_ON)) {
893 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500894 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500895 led |= priv->led_association_on;
896
897 led = ipw_register_toggle(led);
898
899 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500900 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500901
902 priv->status |= STATUS_LED_LINK_ON;
903
904 /* If we aren't associated, schedule turning the LED off */
905 if (!(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100906 schedule_delayed_work(&priv->led_link_off,
907 LD_TIME_LINK_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500908 }
909
910 spin_unlock_irqrestore(&priv->lock, flags);
911}
912
David Howellsc4028952006-11-22 14:57:56 +0000913static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500914{
David Howellsc4028952006-11-22 14:57:56 +0000915 struct ipw_priv *priv =
916 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800917 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000918 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800919 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500920}
921
Adrian Bunka73e22b2006-01-21 01:39:42 +0100922static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500923{
924 unsigned long flags;
925 u32 led;
926
927 /* If configured not to use LEDs, or nic type is 1,
928 * then we don't goggle the LINK led. */
929 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
930 return;
931
932 spin_lock_irqsave(&priv->lock, flags);
933
934 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500935 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500936 led &= priv->led_association_off;
937 led = ipw_register_toggle(led);
938
939 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500940 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500941
942 IPW_DEBUG_LED("Link LED Off\n");
943
944 priv->status &= ~STATUS_LED_LINK_ON;
945
946 /* If we aren't associated and the radio is on, schedule
947 * turning the LED on (blink while unassociated) */
948 if (!(priv->status & STATUS_RF_KILL_MASK) &&
949 !(priv->status & STATUS_ASSOCIATED))
Tejun Heobcb6d912011-01-26 12:12:50 +0100950 schedule_delayed_work(&priv->led_link_on,
951 LD_TIME_LINK_OFF);
James Ketrenosa613bff2005-08-24 21:43:11 -0500952
953 }
954
955 spin_unlock_irqrestore(&priv->lock, flags);
956}
957
David Howellsc4028952006-11-22 14:57:56 +0000958static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500959{
David Howellsc4028952006-11-22 14:57:56 +0000960 struct ipw_priv *priv =
961 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800962 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000963 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800964 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500965}
966
Arjan van de Ven858119e2006-01-14 13:20:43 -0800967static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500968{
James Ketrenosa613bff2005-08-24 21:43:11 -0500969 u32 led;
970
971 if (priv->config & CFG_NO_LED)
972 return;
973
James Ketrenosb095c382005-08-24 22:04:42 -0500974 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500975 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500976
977 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500978 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500979 led |= priv->led_activity_on;
980
981 led = ipw_register_toggle(led);
982
983 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500984 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500985
986 IPW_DEBUG_LED("Activity LED On\n");
987
988 priv->status |= STATUS_LED_ACT_ON;
989
James Ketrenosc848d0a2005-08-24 21:56:24 -0500990 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100991 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500992 } else {
993 /* Reschedule LED off for full time period */
994 cancel_delayed_work(&priv->led_act_off);
Tejun Heobcb6d912011-01-26 12:12:50 +0100995 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
James Ketrenosa613bff2005-08-24 21:43:11 -0500996 }
James Ketrenosb095c382005-08-24 22:04:42 -0500997}
James Ketrenosa613bff2005-08-24 21:43:11 -0500998
Adrian Bunka73e22b2006-01-21 01:39:42 +0100999#if 0
James Ketrenosb095c382005-08-24 22:04:42 -05001000void ipw_led_activity_on(struct ipw_priv *priv)
1001{
1002 unsigned long flags;
1003 spin_lock_irqsave(&priv->lock, flags);
1004 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05001005 spin_unlock_irqrestore(&priv->lock, flags);
1006}
Adrian Bunka73e22b2006-01-21 01:39:42 +01001007#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -05001008
Adrian Bunka73e22b2006-01-21 01:39:42 +01001009static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001010{
1011 unsigned long flags;
1012 u32 led;
1013
1014 if (priv->config & CFG_NO_LED)
1015 return;
1016
1017 spin_lock_irqsave(&priv->lock, flags);
1018
1019 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001020 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001021 led &= priv->led_activity_off;
1022
1023 led = ipw_register_toggle(led);
1024
1025 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001026 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001027
1028 IPW_DEBUG_LED("Activity LED Off\n");
1029
1030 priv->status &= ~STATUS_LED_ACT_ON;
1031 }
1032
1033 spin_unlock_irqrestore(&priv->lock, flags);
1034}
1035
David Howellsc4028952006-11-22 14:57:56 +00001036static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001037{
David Howellsc4028952006-11-22 14:57:56 +00001038 struct ipw_priv *priv =
1039 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001040 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001041 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001042 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001043}
1044
Adrian Bunka73e22b2006-01-21 01:39:42 +01001045static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001046{
1047 unsigned long flags;
1048 u32 led;
1049
1050 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001051 if (priv->config & CFG_NO_LED ||
1052 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001053 return;
1054
1055 spin_lock_irqsave(&priv->lock, flags);
1056
James Ketrenosb095c382005-08-24 22:04:42 -05001057 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001058 if (priv->assoc_network->mode == IEEE_A) {
1059 led |= priv->led_ofdm_on;
1060 led &= priv->led_association_off;
1061 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1062 } else if (priv->assoc_network->mode == IEEE_G) {
1063 led |= priv->led_ofdm_on;
1064 led |= priv->led_association_on;
1065 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1066 } else {
1067 led &= priv->led_ofdm_off;
1068 led |= priv->led_association_on;
1069 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1070 }
1071
1072 led = ipw_register_toggle(led);
1073
1074 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001075 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001076
1077 spin_unlock_irqrestore(&priv->lock, flags);
1078}
1079
Adrian Bunka73e22b2006-01-21 01:39:42 +01001080static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001081{
1082 unsigned long flags;
1083 u32 led;
1084
1085 /* Only nic type 1 supports mode LEDs */
1086 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1087 return;
1088
1089 spin_lock_irqsave(&priv->lock, flags);
1090
James Ketrenosb095c382005-08-24 22:04:42 -05001091 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001092 led &= priv->led_ofdm_off;
1093 led &= priv->led_association_off;
1094
1095 led = ipw_register_toggle(led);
1096
1097 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001098 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001099
1100 spin_unlock_irqrestore(&priv->lock, flags);
1101}
1102
Adrian Bunka73e22b2006-01-21 01:39:42 +01001103static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001104{
1105 ipw_led_link_on(priv);
1106}
1107
Adrian Bunka73e22b2006-01-21 01:39:42 +01001108static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001109{
1110 ipw_led_activity_off(priv);
1111 ipw_led_link_off(priv);
1112}
1113
Adrian Bunka73e22b2006-01-21 01:39:42 +01001114static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001115{
1116 /* Set the Link Led on for all nic types */
1117 ipw_led_link_on(priv);
1118}
1119
Adrian Bunka73e22b2006-01-21 01:39:42 +01001120static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001121{
1122 ipw_led_activity_off(priv);
1123 ipw_led_link_off(priv);
1124
1125 if (priv->status & STATUS_RF_KILL_MASK)
1126 ipw_led_radio_off(priv);
1127}
1128
Adrian Bunka73e22b2006-01-21 01:39:42 +01001129static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001130{
1131 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1132
1133 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001134 priv->led_activity_on = IPW_ACTIVITY_LED;
1135 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001136
James Ketrenosb095c382005-08-24 22:04:42 -05001137 priv->led_association_on = IPW_ASSOCIATED_LED;
1138 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001139
1140 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001141 priv->led_ofdm_on = IPW_OFDM_LED;
1142 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001143
1144 switch (priv->nic_type) {
1145 case EEPROM_NIC_TYPE_1:
1146 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001147 priv->led_activity_on = IPW_ASSOCIATED_LED;
1148 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1149 priv->led_association_on = IPW_ACTIVITY_LED;
1150 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001151
1152 if (!(priv->config & CFG_NO_LED))
1153 ipw_led_band_on(priv);
1154
1155 /* And we don't blink link LEDs for this nic, so
1156 * just return here */
1157 return;
1158
1159 case EEPROM_NIC_TYPE_3:
1160 case EEPROM_NIC_TYPE_2:
1161 case EEPROM_NIC_TYPE_4:
1162 case EEPROM_NIC_TYPE_0:
1163 break;
1164
1165 default:
1166 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1167 priv->nic_type);
1168 priv->nic_type = EEPROM_NIC_TYPE_0;
1169 break;
1170 }
1171
1172 if (!(priv->config & CFG_NO_LED)) {
1173 if (priv->status & STATUS_ASSOCIATED)
1174 ipw_led_link_on(priv);
1175 else
1176 ipw_led_link_off(priv);
1177 }
1178}
1179
Adrian Bunka73e22b2006-01-21 01:39:42 +01001180static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001181{
James Ketrenosa613bff2005-08-24 21:43:11 -05001182 ipw_led_activity_off(priv);
1183 ipw_led_link_off(priv);
1184 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001185 cancel_delayed_work(&priv->led_link_on);
1186 cancel_delayed_work(&priv->led_link_off);
1187 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001188}
1189
James Ketrenos43f66a62005-03-25 12:31:53 -06001190/*
1191 * The following adds a new attribute to the sysfs representation
1192 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001193 * used for controlling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001194 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001195 * See the level definitions in ipw for details.
1196 */
1197static ssize_t show_debug_level(struct device_driver *d, char *buf)
1198{
1199 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1200}
James Ketrenosa613bff2005-08-24 21:43:11 -05001201
1202static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1203 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001204{
1205 char *p = (char *)buf;
1206 u32 val;
1207
1208 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1209 p++;
1210 if (p[0] == 'x' || p[0] == 'X')
1211 p++;
1212 val = simple_strtoul(p, &p, 16);
1213 } else
1214 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001215 if (p == buf)
1216 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001217 ": %s is not in hex or decimal form.\n", buf);
1218 else
1219 ipw_debug_level = val;
1220
1221 return strnlen(buf, count);
1222}
1223
Jeff Garzikbf794512005-07-31 13:07:26 -04001224static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001225 show_debug_level, store_debug_level);
1226
James Ketrenosb39860c2005-08-12 09:36:32 -05001227static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1228{
Zhu Yic8fe6672006-01-24 16:36:36 +08001229 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001230 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1231}
1232
1233static void ipw_capture_event_log(struct ipw_priv *priv,
1234 u32 log_len, struct ipw_event *log)
1235{
1236 u32 base;
1237
1238 if (log_len) {
1239 base = ipw_read32(priv, IPW_EVENT_LOG);
1240 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1241 (u8 *) log, sizeof(*log) * log_len);
1242 }
1243}
1244
1245static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1246{
1247 struct ipw_fw_error *error;
1248 u32 log_len = ipw_get_event_log_len(priv);
1249 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1250 u32 elem_len = ipw_read_reg32(priv, base);
1251
1252 error = kmalloc(sizeof(*error) +
1253 sizeof(*error->elem) * elem_len +
1254 sizeof(*error->log) * log_len, GFP_ATOMIC);
1255 if (!error) {
1256 IPW_ERROR("Memory allocation for firmware error log "
1257 "failed.\n");
1258 return NULL;
1259 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001260 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001261 error->status = priv->status;
1262 error->config = priv->config;
1263 error->elem_len = elem_len;
1264 error->log_len = log_len;
1265 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001266 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001267
1268 ipw_capture_event_log(priv, log_len, error->log);
1269
1270 if (elem_len)
1271 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1272 sizeof(*error->elem) * elem_len);
1273
1274 return error;
1275}
1276
James Ketrenosb39860c2005-08-12 09:36:32 -05001277static ssize_t show_event_log(struct device *d,
1278 struct device_attribute *attr, char *buf)
1279{
1280 struct ipw_priv *priv = dev_get_drvdata(d);
1281 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001282 u32 log_size;
1283 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001284 u32 len = 0, i;
1285
Reinette Chatre412e9e72007-12-18 22:01:02 -08001286 /* not using min() because of its strict type checking */
1287 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1288 sizeof(*log) * log_len : PAGE_SIZE;
1289 log = kzalloc(log_size, GFP_KERNEL);
1290 if (!log) {
1291 IPW_ERROR("Unable to allocate memory for log\n");
1292 return 0;
1293 }
1294 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001295 ipw_capture_event_log(priv, log_len, log);
1296
1297 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1298 for (i = 0; i < log_len; i++)
1299 len += snprintf(buf + len, PAGE_SIZE - len,
1300 "\n%08X%08X%08X",
1301 log[i].time, log[i].event, log[i].data);
1302 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001303 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001304 return len;
1305}
1306
1307static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1308
1309static ssize_t show_error(struct device *d,
1310 struct device_attribute *attr, char *buf)
1311{
1312 struct ipw_priv *priv = dev_get_drvdata(d);
1313 u32 len = 0, i;
1314 if (!priv->error)
1315 return 0;
1316 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001317 "%08lX%08X%08X%08X",
1318 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001319 priv->error->status,
1320 priv->error->config, priv->error->elem_len);
1321 for (i = 0; i < priv->error->elem_len; i++)
1322 len += snprintf(buf + len, PAGE_SIZE - len,
1323 "\n%08X%08X%08X%08X%08X%08X%08X",
1324 priv->error->elem[i].time,
1325 priv->error->elem[i].desc,
1326 priv->error->elem[i].blink1,
1327 priv->error->elem[i].blink2,
1328 priv->error->elem[i].link1,
1329 priv->error->elem[i].link2,
1330 priv->error->elem[i].data);
1331
1332 len += snprintf(buf + len, PAGE_SIZE - len,
1333 "\n%08X", priv->error->log_len);
1334 for (i = 0; i < priv->error->log_len; i++)
1335 len += snprintf(buf + len, PAGE_SIZE - len,
1336 "\n%08X%08X%08X",
1337 priv->error->log[i].time,
1338 priv->error->log[i].event,
1339 priv->error->log[i].data);
1340 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1341 return len;
1342}
1343
1344static ssize_t clear_error(struct device *d,
1345 struct device_attribute *attr,
1346 const char *buf, size_t count)
1347{
1348 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001349
1350 kfree(priv->error);
1351 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001352 return count;
1353}
1354
1355static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1356
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001357static ssize_t show_cmd_log(struct device *d,
1358 struct device_attribute *attr, char *buf)
1359{
1360 struct ipw_priv *priv = dev_get_drvdata(d);
1361 u32 len = 0, i;
1362 if (!priv->cmdlog)
1363 return 0;
1364 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1365 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1366 i = (i + 1) % priv->cmdlog_len) {
1367 len +=
1368 snprintf(buf + len, PAGE_SIZE - len,
1369 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1370 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1371 priv->cmdlog[i].cmd.len);
1372 len +=
1373 snprintk_buf(buf + len, PAGE_SIZE - len,
1374 (u8 *) priv->cmdlog[i].cmd.param,
1375 priv->cmdlog[i].cmd.len);
1376 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1377 }
1378 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1379 return len;
1380}
1381
1382static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1383
Zhu Yid685b8c2006-04-13 17:20:27 +08001384#ifdef CONFIG_IPW2200_PROMISCUOUS
1385static void ipw_prom_free(struct ipw_priv *priv);
1386static int ipw_prom_alloc(struct ipw_priv *priv);
1387static ssize_t store_rtap_iface(struct device *d,
1388 struct device_attribute *attr,
1389 const char *buf, size_t count)
1390{
1391 struct ipw_priv *priv = dev_get_drvdata(d);
1392 int rc = 0;
1393
1394 if (count < 1)
1395 return -EINVAL;
1396
1397 switch (buf[0]) {
1398 case '0':
1399 if (!rtap_iface)
1400 return count;
1401
1402 if (netif_running(priv->prom_net_dev)) {
1403 IPW_WARNING("Interface is up. Cannot unregister.\n");
1404 return count;
1405 }
1406
1407 ipw_prom_free(priv);
1408 rtap_iface = 0;
1409 break;
1410
1411 case '1':
1412 if (rtap_iface)
1413 return count;
1414
1415 rc = ipw_prom_alloc(priv);
1416 if (!rc)
1417 rtap_iface = 1;
1418 break;
1419
1420 default:
1421 return -EINVAL;
1422 }
1423
1424 if (rc) {
1425 IPW_ERROR("Failed to register promiscuous network "
1426 "device (error %d).\n", rc);
1427 }
1428
1429 return count;
1430}
1431
1432static ssize_t show_rtap_iface(struct device *d,
1433 struct device_attribute *attr,
1434 char *buf)
1435{
1436 struct ipw_priv *priv = dev_get_drvdata(d);
1437 if (rtap_iface)
1438 return sprintf(buf, "%s", priv->prom_net_dev->name);
1439 else {
1440 buf[0] = '-';
1441 buf[1] = '1';
1442 buf[2] = '\0';
1443 return 3;
1444 }
1445}
1446
1447static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1448 store_rtap_iface);
1449
1450static ssize_t store_rtap_filter(struct device *d,
1451 struct device_attribute *attr,
1452 const char *buf, size_t count)
1453{
1454 struct ipw_priv *priv = dev_get_drvdata(d);
1455
1456 if (!priv->prom_priv) {
1457 IPW_ERROR("Attempting to set filter without "
1458 "rtap_iface enabled.\n");
1459 return -EPERM;
1460 }
1461
1462 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1463
1464 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1465 BIT_ARG16(priv->prom_priv->filter));
1466
1467 return count;
1468}
1469
1470static ssize_t show_rtap_filter(struct device *d,
1471 struct device_attribute *attr,
1472 char *buf)
1473{
1474 struct ipw_priv *priv = dev_get_drvdata(d);
1475 return sprintf(buf, "0x%04X",
1476 priv->prom_priv ? priv->prom_priv->filter : 0);
1477}
1478
1479static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1480 store_rtap_filter);
1481#endif
1482
James Ketrenosa613bff2005-08-24 21:43:11 -05001483static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1484 char *buf)
1485{
1486 struct ipw_priv *priv = dev_get_drvdata(d);
1487 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1488}
1489
1490static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1491 const char *buf, size_t count)
1492{
1493 struct ipw_priv *priv = dev_get_drvdata(d);
1494 struct net_device *dev = priv->net_dev;
1495 char buffer[] = "00000000";
1496 unsigned long len =
1497 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1498 unsigned long val;
1499 char *p = buffer;
1500
1501 IPW_DEBUG_INFO("enter\n");
1502
1503 strncpy(buffer, buf, len);
1504 buffer[len] = 0;
1505
1506 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1507 p++;
1508 if (p[0] == 'x' || p[0] == 'X')
1509 p++;
1510 val = simple_strtoul(p, &p, 16);
1511 } else
1512 val = simple_strtoul(p, &p, 10);
1513 if (p == buffer) {
1514 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1515 } else {
1516 priv->ieee->scan_age = val;
1517 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1518 }
1519
1520 IPW_DEBUG_INFO("exit\n");
1521 return len;
1522}
1523
1524static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1525
1526static ssize_t show_led(struct device *d, struct device_attribute *attr,
1527 char *buf)
1528{
1529 struct ipw_priv *priv = dev_get_drvdata(d);
1530 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1531}
1532
1533static ssize_t store_led(struct device *d, struct device_attribute *attr,
1534 const char *buf, size_t count)
1535{
1536 struct ipw_priv *priv = dev_get_drvdata(d);
1537
1538 IPW_DEBUG_INFO("enter\n");
1539
1540 if (count == 0)
1541 return 0;
1542
1543 if (*buf == 0) {
1544 IPW_DEBUG_LED("Disabling LED control.\n");
1545 priv->config |= CFG_NO_LED;
1546 ipw_led_shutdown(priv);
1547 } else {
1548 IPW_DEBUG_LED("Enabling LED control.\n");
1549 priv->config &= ~CFG_NO_LED;
1550 ipw_led_init(priv);
1551 }
1552
1553 IPW_DEBUG_INFO("exit\n");
1554 return count;
1555}
1556
1557static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1558
Andrew Mortonad3fee52005-06-20 14:30:36 -07001559static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001560 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001561{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001562 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001563 return sprintf(buf, "0x%08x\n", (int)p->status);
1564}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565
James Ketrenos43f66a62005-03-25 12:31:53 -06001566static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1567
Andrew Mortonad3fee52005-06-20 14:30:36 -07001568static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1569 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001570{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001571 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001572 return sprintf(buf, "0x%08x\n", (int)p->config);
1573}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001574
James Ketrenos43f66a62005-03-25 12:31:53 -06001575static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1576
Andrew Mortonad3fee52005-06-20 14:30:36 -07001577static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001579{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001580 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001581 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001582}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583
James Ketrenos43f66a62005-03-25 12:31:53 -06001584static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1585
Andrew Mortonad3fee52005-06-20 14:30:36 -07001586static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001587 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001588{
1589 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001590 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001591
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001592 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001593 return 0;
1594
1595 return sprintf(buf, "0x%08x\n", tmp);
1596}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001597
1598static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001599
Andrew Mortonad3fee52005-06-20 14:30:36 -07001600static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1601 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001602{
1603 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001604 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001606 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001607 return 0;
1608
1609 return sprintf(buf, "0x%08x\n", tmp);
1610}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001611
1612static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001613
1614/*
1615 * Add a device attribute to view/control the delay between eeprom
1616 * operations.
1617 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001618static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001619 struct device_attribute *attr, char *buf)
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);
1622 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001623 return sprintf(buf, "%i\n", n);
1624}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001625static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001626 struct device_attribute *attr,
1627 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001628{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001629 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001630 sscanf(buf, "%i", &p->eeprom_delay);
1631 return strnlen(buf, count);
1632}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001633
1634static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1635 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001636
Andrew Mortonad3fee52005-06-20 14:30:36 -07001637static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001638 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001639{
1640 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001641 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001642
James Ketrenosb095c382005-08-24 22:04:42 -05001643 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001644 return sprintf(buf, "0x%08x\n", reg);
1645}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001646static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001647 struct device_attribute *attr,
1648 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001649{
1650 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001651 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001652
1653 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001654 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001655 return strnlen(buf, count);
1656}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001657
1658static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1659 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001660
Andrew Mortonad3fee52005-06-20 14:30:36 -07001661static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001662 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001663{
1664 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001665 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001666
1667 reg = ipw_read_reg32(p, 0x301100);
1668 return sprintf(buf, "0x%08x\n", reg);
1669}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001670static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001671 struct device_attribute *attr,
1672 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001673{
1674 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001675 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001676
1677 sscanf(buf, "%x", &reg);
1678 ipw_write_reg32(p, 0x301100, reg);
1679 return strnlen(buf, count);
1680}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001681
1682static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1683 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001684
Andrew Mortonad3fee52005-06-20 14:30:36 -07001685static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001686 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001687{
1688 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001689 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001690
Jeff Garzikbf794512005-07-31 13:07:26 -04001691 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001692 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001693 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001694 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001695
James Ketrenos43f66a62005-03-25 12:31:53 -06001696 return sprintf(buf, "0x%08x\n", reg);
1697}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001698static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001699 struct device_attribute *attr,
1700 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001701{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001702 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001703
1704 sscanf(buf, "%x", &priv->indirect_dword);
1705 priv->status |= STATUS_INDIRECT_DWORD;
1706 return strnlen(buf, count);
1707}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001708
1709static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1710 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001711
Andrew Mortonad3fee52005-06-20 14:30:36 -07001712static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001713 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001714{
1715 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001716 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001717
Jeff Garzikbf794512005-07-31 13:07:26 -04001718 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001719 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001720 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001721 reg = 0;
1722
1723 return sprintf(buf, "0x%02x\n", reg);
1724}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001725static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001726 struct device_attribute *attr,
1727 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001728{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001729 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001730
1731 sscanf(buf, "%x", &priv->indirect_byte);
1732 priv->status |= STATUS_INDIRECT_BYTE;
1733 return strnlen(buf, count);
1734}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001735
1736static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001737 show_indirect_byte, store_indirect_byte);
1738
Andrew Mortonad3fee52005-06-20 14:30:36 -07001739static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001740 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001741{
1742 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001743 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001744
Jeff Garzikbf794512005-07-31 13:07:26 -04001745 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001746 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001747 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 reg = 0;
1749
1750 return sprintf(buf, "0x%08x\n", reg);
1751}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001752static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001753 struct device_attribute *attr,
1754 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001755{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001756 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001757
1758 sscanf(buf, "%x", &priv->direct_dword);
1759 priv->status |= STATUS_DIRECT_DWORD;
1760 return strnlen(buf, count);
1761}
James Ketrenos43f66a62005-03-25 12:31:53 -06001762
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001763static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1764 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001765
Arjan van de Ven858119e2006-01-14 13:20:43 -08001766static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001767{
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001768 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001769 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001770 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1771 } else {
James Ketrenos43f66a62005-03-25 12:31:53 -06001772 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001773 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1774 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001775
1776 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1777}
1778
Andrew Mortonad3fee52005-06-20 14:30:36 -07001779static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001780 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001781{
1782 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001783 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001784 2 - HW based RF kill active
1785 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001786 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001787 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001788 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001789 return sprintf(buf, "%i\n", val);
1790}
1791
1792static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1793{
Jeff Garzikbf794512005-07-31 13:07:26 -04001794 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001795 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001796 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001797
1798 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1799 disable_radio ? "OFF" : "ON");
1800
1801 if (disable_radio) {
1802 priv->status |= STATUS_RF_KILL_SW;
1803
Tejun Heobcb6d912011-01-26 12:12:50 +01001804 cancel_delayed_work(&priv->request_scan);
1805 cancel_delayed_work(&priv->request_direct_scan);
1806 cancel_delayed_work(&priv->request_passive_scan);
1807 cancel_delayed_work(&priv->scan_event);
1808 schedule_work(&priv->down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001809 } else {
1810 priv->status &= ~STATUS_RF_KILL_SW;
1811 if (rf_kill_active(priv)) {
1812 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1813 "disabled by HW switch\n");
1814 /* Make sure the RF_KILL check timer is running */
1815 cancel_delayed_work(&priv->rf_kill);
Tejun Heobcb6d912011-01-26 12:12:50 +01001816 schedule_delayed_work(&priv->rf_kill,
1817 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001818 } else
Tejun Heobcb6d912011-01-26 12:12:50 +01001819 schedule_work(&priv->up);
James Ketrenos43f66a62005-03-25 12:31:53 -06001820 }
1821
1822 return 1;
1823}
1824
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001825static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1826 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001827{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001828 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001829
James Ketrenos43f66a62005-03-25 12:31:53 -06001830 ipw_radio_kill_sw(priv, buf[0] == '1');
1831
1832 return count;
1833}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001834
1835static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001836
James Ketrenosb095c382005-08-24 22:04:42 -05001837static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1838 char *buf)
1839{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001840 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001841 int pos = 0, len = 0;
1842 if (priv->config & CFG_SPEED_SCAN) {
1843 while (priv->speed_scan[pos] != 0)
1844 len += sprintf(&buf[len], "%d ",
1845 priv->speed_scan[pos++]);
1846 return len + sprintf(&buf[len], "\n");
1847 }
1848
1849 return sprintf(buf, "0\n");
1850}
1851
1852static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1853 const char *buf, size_t count)
1854{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001855 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001856 int channel, pos = 0;
1857 const char *p = buf;
1858
1859 /* list of space separated channels to scan, optionally ending with 0 */
1860 while ((channel = simple_strtol(p, NULL, 0))) {
1861 if (pos == MAX_SPEED_SCAN - 1) {
1862 priv->speed_scan[pos] = 0;
1863 break;
1864 }
1865
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001866 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001867 priv->speed_scan[pos++] = channel;
1868 else
1869 IPW_WARNING("Skipping invalid channel request: %d\n",
1870 channel);
1871 p = strchr(p, ' ');
1872 if (!p)
1873 break;
1874 while (*p == ' ' || *p == '\t')
1875 p++;
1876 }
1877
1878 if (pos == 0)
1879 priv->config &= ~CFG_SPEED_SCAN;
1880 else {
1881 priv->speed_scan_pos = 0;
1882 priv->config |= CFG_SPEED_SCAN;
1883 }
1884
1885 return count;
1886}
1887
1888static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1889 store_speed_scan);
1890
1891static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1892 char *buf)
1893{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001894 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001895 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1896}
1897
1898static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1899 const char *buf, size_t count)
1900{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001901 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001902 if (buf[0] == '1')
1903 priv->config |= CFG_NET_STATS;
1904 else
1905 priv->config &= ~CFG_NET_STATS;
1906
1907 return count;
1908}
1909
James Ketrenosafbf30a2005-08-25 00:05:33 -05001910static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1911 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001912
Zhu Yi375dd242007-02-14 16:04:24 +08001913static ssize_t show_channels(struct device *d,
1914 struct device_attribute *attr,
1915 char *buf)
1916{
1917 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001918 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001919 int len = 0, i;
1920
1921 len = sprintf(&buf[len],
1922 "Displaying %d channels in 2.4Ghz band "
1923 "(802.11bg):\n", geo->bg_channels);
1924
1925 for (i = 0; i < geo->bg_channels; i++) {
1926 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1927 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001928 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001929 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001930 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1931 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001932 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001933 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001934 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001935 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001936 "B" : "B/G");
1937 }
1938
1939 len += sprintf(&buf[len],
1940 "Displaying %d channels in 5.2Ghz band "
1941 "(802.11a):\n", geo->a_channels);
1942 for (i = 0; i < geo->a_channels; i++) {
1943 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1944 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001945 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001946 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001947 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1948 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001949 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001950 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001951 "passive only" : "active/passive");
1952 }
1953
1954 return len;
1955}
1956
1957static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1958
James Ketrenosea2b26e2005-08-24 21:25:16 -05001959static void notify_wx_assoc_event(struct ipw_priv *priv)
1960{
1961 union iwreq_data wrqu;
1962 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1963 if (priv->status & STATUS_ASSOCIATED)
1964 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1965 else
1966 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1967 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1968}
1969
James Ketrenos43f66a62005-03-25 12:31:53 -06001970static void ipw_irq_tasklet(struct ipw_priv *priv)
1971{
1972 u32 inta, inta_mask, handled = 0;
1973 unsigned long flags;
1974 int rc = 0;
1975
Zhu Yi89c318e2006-06-08 22:19:49 -07001976 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001977
James Ketrenosb095c382005-08-24 22:04:42 -05001978 inta = ipw_read32(priv, IPW_INTA_RW);
1979 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Indan Zupancic3c4a8cc2011-01-08 12:17:27 +01001980
1981 if (inta == 0xFFFFFFFF) {
1982 /* Hardware disappeared */
1983 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1984 /* Only handle the cached INTA values */
1985 inta = 0;
1986 }
James Ketrenosb095c382005-08-24 22:04:42 -05001987 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001988
1989 /* Add any cached INTA values that need to be handled */
1990 inta |= priv->isr_inta;
1991
Zhu Yi89c318e2006-06-08 22:19:49 -07001992 spin_unlock_irqrestore(&priv->irq_lock, flags);
1993
1994 spin_lock_irqsave(&priv->lock, flags);
1995
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001997 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001998 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001999 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06002000 }
2001
James Ketrenosb095c382005-08-24 22:04:42 -05002002 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002003 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002004 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06002005 priv->status &= ~STATUS_HCMD_ACTIVE;
2006 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05002007 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
James Ketrenosb095c382005-08-24 22:04:42 -05002010 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002011 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002012 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002013 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002014 }
2015
James Ketrenosb095c382005-08-24 22:04:42 -05002016 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002017 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002018 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002019 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 }
2021
James Ketrenosb095c382005-08-24 22:04:42 -05002022 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002024 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002025 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 }
2027
James Ketrenosb095c382005-08-24 22:04:42 -05002028 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002029 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002030 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002031 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 }
2033
James Ketrenosb095c382005-08-24 22:04:42 -05002034 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002035 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002036 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002037 }
2038
James Ketrenosb095c382005-08-24 22:04:42 -05002039 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002040 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002041 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002042 }
2043
James Ketrenosb095c382005-08-24 22:04:42 -05002044 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002045 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002046 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002047 }
2048
James Ketrenosb095c382005-08-24 22:04:42 -05002049 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002050 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002051 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002052 }
2053
James Ketrenosb095c382005-08-24 22:04:42 -05002054 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002055 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002056 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002057 }
2058
James Ketrenosb095c382005-08-24 22:04:42 -05002059 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002060 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2061 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002062 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002063 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002064 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002065 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002066 cancel_delayed_work(&priv->request_direct_scan);
2067 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002068 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002069 schedule_work(&priv->link_down);
Tejun Heobcb6d912011-01-26 12:12:50 +01002070 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002071 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002072 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002073
James Ketrenosb095c382005-08-24 22:04:42 -05002074 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002075 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002076 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002077 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002078 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2079 struct ipw_fw_error *error =
2080 ipw_alloc_error_log(priv);
2081 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002082 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002083 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002084 } else {
2085 priv->error = ipw_alloc_error_log(priv);
2086 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002087 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002088 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002089 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2090 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002091 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2092 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002093 }
2094
James Ketrenosb095c382005-08-24 22:04:42 -05002095 /* XXX: If hardware encryption is for WPA/WPA2,
2096 * we have to notify the supplicant. */
2097 if (priv->ieee->sec.encrypt) {
2098 priv->status &= ~STATUS_ASSOCIATED;
2099 notify_wx_assoc_event(priv);
2100 }
2101
2102 /* Keep the restart process from trying to send host
2103 * commands by clearing the INIT status bit */
2104 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002105
2106 /* Cancel currently queued command. */
2107 priv->status &= ~STATUS_HCMD_ACTIVE;
2108 wake_up_interruptible(&priv->wait_command_queue);
2109
Tejun Heobcb6d912011-01-26 12:12:50 +01002110 schedule_work(&priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002111 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002112 }
2113
James Ketrenosb095c382005-08-24 22:04:42 -05002114 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002115 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002116 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002117 }
2118
2119 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002120 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121 }
2122
Zhu Yi89c318e2006-06-08 22:19:49 -07002123 spin_unlock_irqrestore(&priv->lock, flags);
2124
James Ketrenos43f66a62005-03-25 12:31:53 -06002125 /* enable all interrupts */
2126 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002127}
Jeff Garzikbf794512005-07-31 13:07:26 -04002128
James Ketrenos43f66a62005-03-25 12:31:53 -06002129#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2130static char *get_cmd_string(u8 cmd)
2131{
2132 switch (cmd) {
2133 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002134 IPW_CMD(POWER_DOWN);
2135 IPW_CMD(SYSTEM_CONFIG);
2136 IPW_CMD(MULTICAST_ADDRESS);
2137 IPW_CMD(SSID);
2138 IPW_CMD(ADAPTER_ADDRESS);
2139 IPW_CMD(PORT_TYPE);
2140 IPW_CMD(RTS_THRESHOLD);
2141 IPW_CMD(FRAG_THRESHOLD);
2142 IPW_CMD(POWER_MODE);
2143 IPW_CMD(WEP_KEY);
2144 IPW_CMD(TGI_TX_KEY);
2145 IPW_CMD(SCAN_REQUEST);
2146 IPW_CMD(SCAN_REQUEST_EXT);
2147 IPW_CMD(ASSOCIATE);
2148 IPW_CMD(SUPPORTED_RATES);
2149 IPW_CMD(SCAN_ABORT);
2150 IPW_CMD(TX_FLUSH);
2151 IPW_CMD(QOS_PARAMETERS);
2152 IPW_CMD(DINO_CONFIG);
2153 IPW_CMD(RSN_CAPABILITIES);
2154 IPW_CMD(RX_KEY);
2155 IPW_CMD(CARD_DISABLE);
2156 IPW_CMD(SEED_NUMBER);
2157 IPW_CMD(TX_POWER);
2158 IPW_CMD(COUNTRY_INFO);
2159 IPW_CMD(AIRONET_INFO);
2160 IPW_CMD(AP_TX_POWER);
2161 IPW_CMD(CCKM_INFO);
2162 IPW_CMD(CCX_VER_INFO);
2163 IPW_CMD(SET_CALIBRATION);
2164 IPW_CMD(SENSITIVITY_CALIB);
2165 IPW_CMD(RETRY_LIMIT);
2166 IPW_CMD(IPW_PRE_POWER_DOWN);
2167 IPW_CMD(VAP_BEACON_TEMPLATE);
2168 IPW_CMD(VAP_DTIM_PERIOD);
2169 IPW_CMD(EXT_SUPPORTED_RATES);
2170 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2171 IPW_CMD(VAP_QUIET_INTERVALS);
2172 IPW_CMD(VAP_CHANNEL_SWITCH);
2173 IPW_CMD(VAP_MANDATORY_CHANNELS);
2174 IPW_CMD(VAP_CELL_PWR_LIMIT);
2175 IPW_CMD(VAP_CF_PARAM_SET);
2176 IPW_CMD(VAP_SET_BEACONING_STATE);
2177 IPW_CMD(MEASUREMENT);
2178 IPW_CMD(POWER_CAPABILITY);
2179 IPW_CMD(SUPPORTED_CHANNELS);
2180 IPW_CMD(TPC_REPORT);
2181 IPW_CMD(WME_INFO);
2182 IPW_CMD(PRODUCTION_COMMAND);
2183 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002184 return "UNKNOWN";
2185 }
2186}
James Ketrenos43f66a62005-03-25 12:31:53 -06002187
2188#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002189
2190static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002191{
2192 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002193 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002194
James Ketrenosa613bff2005-08-24 21:43:11 -05002195 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002196 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002197 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2198 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002199 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002200 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002201 }
2202
2203 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002204
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002205 if (priv->cmdlog) {
2206 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2207 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2208 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2209 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2210 cmd->len);
2211 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2212 }
2213
James Ketrenosb095c382005-08-24 22:04:42 -05002214 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2215 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2216 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002217
2218#ifndef DEBUG_CMD_WEP_KEY
2219 if (cmd->cmd == IPW_CMD_WEP_KEY)
2220 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2221 else
2222#endif
2223 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2224
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002225 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002226 if (rc) {
2227 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002228 IPW_ERROR("Failed to send %s: Reason %d\n",
2229 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002230 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002231 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002232 }
2233 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002234
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002235 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2236 !(priv->
2237 status & STATUS_HCMD_ACTIVE),
2238 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002239 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002240 spin_lock_irqsave(&priv->lock, flags);
2241 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002242 IPW_ERROR("Failed to send %s: Command timed out.\n",
2243 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002244 priv->status &= ~STATUS_HCMD_ACTIVE;
2245 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002246 rc = -EIO;
2247 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002248 }
2249 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002250 } else
2251 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002252
James Ketrenosb095c382005-08-24 22:04:42 -05002253 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002254 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2255 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002256 rc = -EIO;
2257 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002258 }
2259
Zhu Yi2638bc32006-01-24 16:37:52 +08002260 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002261 if (priv->cmdlog) {
2262 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2263 priv->cmdlog_pos %= priv->cmdlog_len;
2264 }
2265 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002266}
2267
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002268static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002269{
2270 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002271 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002272 };
2273
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002274 return __ipw_send_cmd(priv, &cmd);
2275}
2276
2277static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2278 void *data)
2279{
2280 struct host_cmd cmd = {
2281 .cmd = command,
2282 .len = len,
2283 .param = data,
2284 };
2285
2286 return __ipw_send_cmd(priv, &cmd);
2287}
2288
2289static int ipw_send_host_complete(struct ipw_priv *priv)
2290{
James Ketrenos43f66a62005-03-25 12:31:53 -06002291 if (!priv) {
2292 IPW_ERROR("Invalid args\n");
2293 return -1;
2294 }
2295
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002296 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002297}
2298
Zhu Yid685b8c2006-04-13 17:20:27 +08002299static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002300{
Zhu Yid685b8c2006-04-13 17:20:27 +08002301 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2302 sizeof(priv->sys_config),
2303 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002304}
2305
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002306static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002307{
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 if (!priv || !ssid) {
2309 IPW_ERROR("Invalid args\n");
2310 return -1;
2311 }
2312
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002313 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002314 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002315}
2316
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002317static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002318{
James Ketrenos43f66a62005-03-25 12:31:53 -06002319 if (!priv || !mac) {
2320 IPW_ERROR("Invalid args\n");
2321 return -1;
2322 }
2323
Johannes Berge1749612008-10-27 15:59:26 -07002324 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2325 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002326
Zhu Yi2638bc32006-01-24 16:37:52 +08002327 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002328}
2329
2330static void ipw_adapter_restart(void *adapter)
2331{
2332 struct ipw_priv *priv = adapter;
2333
2334 if (priv->status & STATUS_RF_KILL_MASK)
2335 return;
2336
2337 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002338
2339 if (priv->assoc_network &&
2340 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2341 ipw_remove_current_network(priv);
2342
James Ketrenos43f66a62005-03-25 12:31:53 -06002343 if (ipw_up(priv)) {
2344 IPW_ERROR("Failed to up device\n");
2345 return;
2346 }
2347}
2348
David Howellsc4028952006-11-22 14:57:56 +00002349static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002350{
David Howellsc4028952006-11-22 14:57:56 +00002351 struct ipw_priv *priv =
2352 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002353 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002354 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002355 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002356}
2357
Zhu Yie65054b2010-03-30 09:36:16 +08002358static void ipw_abort_scan(struct ipw_priv *priv);
2359
2360#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
James Ketrenos43f66a62005-03-25 12:31:53 -06002361
2362static void ipw_scan_check(void *data)
2363{
2364 struct ipw_priv *priv = data;
Zhu Yie65054b2010-03-30 09:36:16 +08002365
2366 if (priv->status & STATUS_SCAN_ABORTING) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002367 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002368 "adapter after (%dms).\n",
2369 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
Tejun Heobcb6d912011-01-26 12:12:50 +01002370 schedule_work(&priv->adapter_restart);
Zhu Yie65054b2010-03-30 09:36:16 +08002371 } else if (priv->status & STATUS_SCANNING) {
2372 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2373 "after (%dms).\n",
2374 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2375 ipw_abort_scan(priv);
Tejun Heobcb6d912011-01-26 12:12:50 +01002376 schedule_delayed_work(&priv->scan_check, HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002377 }
2378}
2379
David Howellsc4028952006-11-22 14:57:56 +00002380static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002381{
David Howellsc4028952006-11-22 14:57:56 +00002382 struct ipw_priv *priv =
2383 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002384 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002385 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002386 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002387}
2388
James Ketrenos43f66a62005-03-25 12:31:53 -06002389static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2390 struct ipw_scan_request_ext *request)
2391{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002392 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002393 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002394}
2395
2396static int ipw_send_scan_abort(struct ipw_priv *priv)
2397{
James Ketrenos43f66a62005-03-25 12:31:53 -06002398 if (!priv) {
2399 IPW_ERROR("Invalid args\n");
2400 return -1;
2401 }
2402
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002403 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002404}
2405
2406static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2407{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002408 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002409 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002410 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002411
2412 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002413 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002414}
2415
2416static int ipw_send_associate(struct ipw_priv *priv,
2417 struct ipw_associate *associate)
2418{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002419 if (!priv || !associate) {
2420 IPW_ERROR("Invalid args\n");
2421 return -1;
2422 }
2423
Al Viro5b5e8072007-12-27 01:54:06 -05002424 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2425 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002426}
2427
2428static int ipw_send_supported_rates(struct ipw_priv *priv,
2429 struct ipw_supported_rates *rates)
2430{
James Ketrenos43f66a62005-03-25 12:31:53 -06002431 if (!priv || !rates) {
2432 IPW_ERROR("Invalid args\n");
2433 return -1;
2434 }
2435
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002436 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002437 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002438}
2439
2440static int ipw_set_random_seed(struct ipw_priv *priv)
2441{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002442 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002443
2444 if (!priv) {
2445 IPW_ERROR("Invalid args\n");
2446 return -1;
2447 }
2448
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002449 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002450
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002451 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002452}
2453
James Ketrenos43f66a62005-03-25 12:31:53 -06002454static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2455{
Al Viroe62e1ee2007-12-27 01:36:46 -05002456 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002457 if (!priv) {
2458 IPW_ERROR("Invalid args\n");
2459 return -1;
2460 }
2461
Al Viroe62e1ee2007-12-27 01:36:46 -05002462 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002463}
James Ketrenos43f66a62005-03-25 12:31:53 -06002464
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002465static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002466{
James Ketrenos43f66a62005-03-25 12:31:53 -06002467 if (!priv || !power) {
2468 IPW_ERROR("Invalid args\n");
2469 return -1;
2470 }
2471
Zhu Yi2638bc32006-01-24 16:37:52 +08002472 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002473}
James Ketrenos43f66a62005-03-25 12:31:53 -06002474
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002475static int ipw_set_tx_power(struct ipw_priv *priv)
2476{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002477 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002478 struct ipw_tx_power tx_power;
2479 s8 max_power;
2480 int i;
2481
2482 memset(&tx_power, 0, sizeof(tx_power));
2483
2484 /* configure device for 'G' band */
2485 tx_power.ieee_mode = IPW_G_MODE;
2486 tx_power.num_channels = geo->bg_channels;
2487 for (i = 0; i < geo->bg_channels; i++) {
2488 max_power = geo->bg[i].max_power;
2489 tx_power.channels_tx_power[i].channel_number =
2490 geo->bg[i].channel;
2491 tx_power.channels_tx_power[i].tx_power = max_power ?
2492 min(max_power, priv->tx_power) : priv->tx_power;
2493 }
2494 if (ipw_send_tx_power(priv, &tx_power))
2495 return -EIO;
2496
2497 /* configure device to also handle 'B' band */
2498 tx_power.ieee_mode = IPW_B_MODE;
2499 if (ipw_send_tx_power(priv, &tx_power))
2500 return -EIO;
2501
2502 /* configure device to also handle 'A' band */
2503 if (priv->ieee->abg_true) {
2504 tx_power.ieee_mode = IPW_A_MODE;
2505 tx_power.num_channels = geo->a_channels;
2506 for (i = 0; i < tx_power.num_channels; i++) {
2507 max_power = geo->a[i].max_power;
2508 tx_power.channels_tx_power[i].channel_number =
2509 geo->a[i].channel;
2510 tx_power.channels_tx_power[i].tx_power = max_power ?
2511 min(max_power, priv->tx_power) : priv->tx_power;
2512 }
2513 if (ipw_send_tx_power(priv, &tx_power))
2514 return -EIO;
2515 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002516 return 0;
2517}
2518
2519static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2520{
2521 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002522 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002524
2525 if (!priv) {
2526 IPW_ERROR("Invalid args\n");
2527 return -1;
2528 }
2529
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002530 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2531 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002532}
2533
2534static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2535{
2536 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002537 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002538 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002539
2540 if (!priv) {
2541 IPW_ERROR("Invalid args\n");
2542 return -1;
2543 }
2544
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002545 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2546 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002547}
2548
2549static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2550{
Al Viroe62e1ee2007-12-27 01:36:46 -05002551 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002552
2553 if (!priv) {
2554 IPW_ERROR("Invalid args\n");
2555 return -1;
2556 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002557
James Ketrenos43f66a62005-03-25 12:31:53 -06002558 /* If on battery, set to 3, if AC set to CAM, else user
2559 * level */
2560 switch (mode) {
2561 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002562 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002563 break;
2564 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002565 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002566 break;
2567 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002568 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002569 break;
2570 }
2571
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002572 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002573 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002574}
2575
James Ketrenosafbf30a2005-08-25 00:05:33 -05002576static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2577{
2578 struct ipw_retry_limit retry_limit = {
2579 .short_retry_limit = slimit,
2580 .long_retry_limit = llimit
2581 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002582
2583 if (!priv) {
2584 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002585 return -1;
2586 }
2587
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002588 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002589 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002590}
2591
2592/*
2593 * The IPW device contains a Microwire compatible EEPROM that stores
2594 * various data like the MAC address. Usually the firmware has exclusive
2595 * access to the eeprom, but during device initialization (before the
2596 * device driver has sent the HostComplete command to the firmware) the
2597 * device driver has read access to the EEPROM by way of indirect addressing
2598 * through a couple of memory mapped registers.
2599 *
2600 * The following is a simplified implementation for pulling data out of the
2601 * the eeprom, along with some helper functions to find information in
2602 * the per device private data's copy of the eeprom.
2603 *
2604 * NOTE: To better understand how these functions work (i.e what is a chip
2605 * select and why do have to keep driving the eeprom clock?), read
2606 * just about any data sheet for a Microwire compatible EEPROM.
2607 */
2608
2609/* write a 32 bit value into the indirect accessor register */
2610static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2611{
2612 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002613
James Ketrenos43f66a62005-03-25 12:31:53 -06002614 /* the eeprom requires some time to complete the operation */
2615 udelay(p->eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06002616}
2617
2618/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002619static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002620{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002621 eeprom_write_reg(priv, 0);
2622 eeprom_write_reg(priv, EEPROM_BIT_CS);
2623 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2624 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002625}
2626
2627/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002628static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002629{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 eeprom_write_reg(priv, EEPROM_BIT_CS);
2631 eeprom_write_reg(priv, 0);
2632 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002633}
2634
2635/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002636static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002637{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002638 int d = (bit ? EEPROM_BIT_DI : 0);
2639 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2640 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002641}
2642
2643/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002644static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002645{
2646 int i;
2647
2648 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002649 eeprom_write_bit(priv, 1);
2650 eeprom_write_bit(priv, op & 2);
2651 eeprom_write_bit(priv, op & 1);
2652 for (i = 7; i >= 0; i--) {
2653 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002654 }
2655}
2656
2657/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002659{
2660 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002661 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002662
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002664 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002665
2666 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002667 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002668
2669 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002670 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002672 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2673 eeprom_write_reg(priv, EEPROM_BIT_CS);
2674 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2675 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002676 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002677
James Ketrenos43f66a62005-03-25 12:31:53 -06002678 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002679 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002680 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002681
James Ketrenos43f66a62005-03-25 12:31:53 -06002682 return r;
2683}
2684
2685/* helper function for pulling the mac address out of the private */
2686/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002687static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002688{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002689 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002690}
2691
2692/*
2693 * Either the device driver (i.e. the host) or the firmware can
2694 * load eeprom data into the designated region in SRAM. If neither
2695 * happens then the FW will shutdown with a fatal error.
2696 *
2697 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2698 * bit needs region of shared SRAM needs to be non-zero.
2699 */
2700static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2701{
2702 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002703 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002704
James Ketrenos43f66a62005-03-25 12:31:53 -06002705 IPW_DEBUG_TRACE(">>\n");
2706
2707 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002708 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002709 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002710
Jeff Garzikbf794512005-07-31 13:07:26 -04002711 /*
2712 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002713 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002714 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002715 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002716 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002717 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2718
2719 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002720 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002721 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002722
2723 /* Do not load eeprom data on fatal error or suspend */
2724 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2725 } else {
2726 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2727
2728 /* Load eeprom data on fatal error or suspend */
2729 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2730 }
2731
2732 IPW_DEBUG_TRACE("<<\n");
2733}
2734
Arjan van de Ven858119e2006-01-14 13:20:43 -08002735static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002736{
2737 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002738 if (!count)
2739 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002740 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002741 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002742 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002743}
2744
2745static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2746{
James Ketrenosb095c382005-08-24 22:04:42 -05002747 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002748 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002749 sizeof(struct command_block));
2750}
2751
2752static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002753{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002754
Frans Pop9fd1ea42010-03-24 19:46:31 +01002755 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002756
James Ketrenos43f66a62005-03-25 12:31:53 -06002757 /* Start the dma */
2758 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002759
James Ketrenos43f66a62005-03-25 12:31:53 -06002760 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002761 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002762
Frans Pop9fd1ea42010-03-24 19:46:31 +01002763 IPW_DEBUG_FW("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002764 return 0;
2765}
2766
2767static void ipw_fw_dma_abort(struct ipw_priv *priv)
2768{
2769 u32 control = 0;
2770
2771 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002772
Pavel Machek67fd6b42006-07-11 15:34:05 +02002773 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002774 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002775 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002776 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002777
Frans Pop9fd1ea42010-03-24 19:46:31 +01002778 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002779}
2780
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002781static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2782 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002783{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002784 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002785 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002786 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 IPW_DEBUG_FW(">> :\n");
2788
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002789 ipw_write_indirect(priv, address, (u8 *) cb,
2790 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002791
2792 IPW_DEBUG_FW("<< :\n");
2793 return 0;
2794
2795}
2796
2797static int ipw_fw_dma_kick(struct ipw_priv *priv)
2798{
2799 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002801
2802 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002803
James Ketrenos43f66a62005-03-25 12:31:53 -06002804 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 ipw_fw_dma_write_command_block(priv, index,
2806 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002807
2808 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002809 ipw_clear_bit(priv, IPW_RESET_REG,
2810 IPW_RESET_REG_MASTER_DISABLED |
2811 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002812
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002813 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002814 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002815 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002816
2817 IPW_DEBUG_FW("<< :\n");
2818 return 0;
2819}
2820
2821static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2822{
2823 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002824 u32 register_value = 0;
2825 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002826
2827 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002828 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002829 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002830
2831 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002832 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002833 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002834
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002835 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002836 cb_fields_address = address;
2837 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002838 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002839
2840 cb_fields_address += sizeof(u32);
2841 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002842 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002843
2844 cb_fields_address += sizeof(u32);
2845 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002846 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002847 register_value);
2848
2849 cb_fields_address += sizeof(u32);
2850 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002851 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002852
2853 IPW_DEBUG_FW(">> :\n");
2854}
2855
2856static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2857{
2858 u32 current_cb_address = 0;
2859 u32 current_cb_index = 0;
2860
2861 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002862 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002863
James Ketrenosb095c382005-08-24 22:04:42 -05002864 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002865 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002866
Frans Pop9fd1ea42010-03-24 19:46:31 +01002867 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002868 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002869
2870 IPW_DEBUG_FW(">> :\n");
2871 return current_cb_index;
2872
2873}
2874
2875static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2876 u32 src_address,
2877 u32 dest_address,
2878 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002879 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002880{
2881
Jeff Garzikbf794512005-07-31 13:07:26 -04002882 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002883 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2884 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002885 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002886 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002887
2888 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2889 src_address, dest_address, length);
2890
2891 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2892 return -1;
2893
2894 last_cb_element = priv->sram_desc.last_cb_index;
2895 cb = &priv->sram_desc.cb_list[last_cb_element];
2896 priv->sram_desc.last_cb_index++;
2897
2898 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002899 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002900 control |= CB_INT_ENABLED;
2901
2902 if (is_last)
2903 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002904
James Ketrenos43f66a62005-03-25 12:31:53 -06002905 control |= length;
2906
2907 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002908 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002909
2910 /* Copy the Source and Destination addresses */
2911 cb->dest_addr = dest_address;
2912 cb->source_addr = src_address;
2913
2914 /* Copy the Control Word last */
2915 cb->control = control;
2916
2917 return 0;
2918}
2919
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002920static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2921 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002922{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002923 int ret, i;
2924 u32 size;
2925
Frans Pop9fd1ea42010-03-24 19:46:31 +01002926 IPW_DEBUG_FW(">>\n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002927 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2928 nr, dest_address, len);
2929
2930 for (i = 0; i < nr; i++) {
2931 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2932 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2933 dest_address +
2934 i * CB_MAX_LENGTH, size,
2935 0, 0);
2936 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002937 IPW_DEBUG_FW_INFO(": Failed\n");
2938 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002939 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002940 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002941 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002942
Frans Pop9fd1ea42010-03-24 19:46:31 +01002943 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002944 return 0;
2945}
2946
2947static int ipw_fw_dma_wait(struct ipw_priv *priv)
2948{
Zhu Yi397ae122006-01-24 16:37:22 +08002949 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002950 u32 watchdog = 0;
2951
Frans Pop9fd1ea42010-03-24 19:46:31 +01002952 IPW_DEBUG_FW(">> :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002953
2954 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002955 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002956 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002957
2958 while (current_index < priv->sram_desc.last_cb_index) {
2959 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002960 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002961 current_index = ipw_fw_dma_command_block_index(priv);
2962
Zhu Yi397ae122006-01-24 16:37:22 +08002963 if (previous_index < current_index) {
2964 watchdog = 0;
2965 continue;
2966 }
2967 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002968 IPW_DEBUG_FW_INFO("Timeout\n");
2969 ipw_fw_dma_dump_command_block(priv);
2970 ipw_fw_dma_abort(priv);
2971 return -1;
2972 }
2973 }
2974
2975 ipw_fw_dma_abort(priv);
2976
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002977 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002978 ipw_set_bit(priv, IPW_RESET_REG,
2979 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002980
Frans Pop9fd1ea42010-03-24 19:46:31 +01002981 IPW_DEBUG_FW("<< dmaWaitSync\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002982 return 0;
2983}
2984
Jeff Garzikbf794512005-07-31 13:07:26 -04002985static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002986{
2987 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002988 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002989 unsigned long flags;
2990
2991 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002992 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002993 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002994 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2995 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002996 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002997 &priv->ieee->network_free_list);
2998 }
2999 }
James Ketrenosa613bff2005-08-24 21:43:11 -05003000 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003001}
3002
3003/**
Jeff Garzikbf794512005-07-31 13:07:26 -04003004 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06003005 * Reads debug register from domain0.
3006 * If card is present, pre-defined value should
3007 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04003008 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 * @param priv
3010 * @return 1 if card is present, 0 otherwise
3011 */
3012static inline int ipw_alive(struct ipw_priv *priv)
3013{
3014 return ipw_read32(priv, 0x90) == 0xd55555d5;
3015}
3016
Zhu Yic7b6a672006-01-24 16:37:05 +08003017/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003018static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003019 int timeout)
3020{
3021 int i = 0;
3022
3023 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003024 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 return i;
3026 mdelay(10);
3027 i += 10;
3028 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003029
James Ketrenos43f66a62005-03-25 12:31:53 -06003030 return -ETIME;
3031}
3032
Jeff Garzikbf794512005-07-31 13:07:26 -04003033/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003034 * the ipw hardware. It assumes the buffer has all the bits for the
3035 * image and the caller is handling the memory allocation and clean up.
3036 */
3037
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003038static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003039{
3040 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003041
Frans Pop9fd1ea42010-03-24 19:46:31 +01003042 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003043 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003044 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003045
Zhu Yic7b6a672006-01-24 16:37:05 +08003046 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003047 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3048 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003049 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003050 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003051 return -1;
3052 }
3053
3054 IPW_DEBUG_INFO("stop master %dms\n", rc);
3055
3056 return rc;
3057}
3058
3059static void ipw_arc_release(struct ipw_priv *priv)
3060{
Frans Pop9fd1ea42010-03-24 19:46:31 +01003061 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003062 mdelay(5);
3063
James Ketrenosb095c382005-08-24 22:04:42 -05003064 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003065
3066 /* no one knows timing, for safety add some delay */
3067 mdelay(5);
3068}
3069
James Ketrenos43f66a62005-03-25 12:31:53 -06003070struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003071 __le32 address;
3072 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003073};
3074
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003075static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003076{
3077 int rc = 0, i, addr;
3078 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003079 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003080
Al Viroe62e1ee2007-12-27 01:36:46 -05003081 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003082
Frans Pop9fd1ea42010-03-24 19:46:31 +01003083 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003084
3085 rc = ipw_stop_master(priv);
3086
3087 if (rc < 0)
3088 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003089
James Ketrenosb095c382005-08-24 22:04:42 -05003090 for (addr = IPW_SHARED_LOWER_BOUND;
3091 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003092 ipw_write32(priv, addr, 0);
3093 }
3094
3095 /* no ucode (yet) */
3096 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3097 /* destroy DMA queues */
3098 /* reset sequence */
3099
James Ketrenosb095c382005-08-24 22:04:42 -05003100 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003101 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003102 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003103 mdelay(1);
3104
3105 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003106 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003107 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003108
James Ketrenosb095c382005-08-24 22:04:42 -05003109 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003110 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003111
James Ketrenos43f66a62005-03-25 12:31:53 -06003112 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003113 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3114 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003115 mdelay(1);
3116
3117 /* write ucode */
3118 /**
3119 * @bug
3120 * Do NOT set indirect address register once and then
3121 * store data to indirect data register in the loop.
3122 * It seems very reasonable, but in this case DINO do not
3123 * accept ucode. It is essential to set address each time.
3124 */
3125 /* load new ipw uCode */
3126 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003127 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003128 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003129
James Ketrenos43f66a62005-03-25 12:31:53 -06003130 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003131 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3132 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003133
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003134 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003135
3136 /* wait for alive response */
3137 for (i = 0; i < 100; i++) {
3138 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003139 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003140 if (cr & DINO_RXFIFO_DATA)
3141 break;
3142 mdelay(1);
3143 }
3144
3145 if (cr & DINO_RXFIFO_DATA) {
3146 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003147 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003148
3149 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003150 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003151 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003152 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003153 memcpy(&priv->dino_alive, response_buffer,
3154 sizeof(priv->dino_alive));
3155 if (priv->dino_alive.alive_command == 1
3156 && priv->dino_alive.ucode_valid == 1) {
3157 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003158 IPW_DEBUG_INFO
3159 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3160 "of %02d/%02d/%02d %02d:%02d\n",
3161 priv->dino_alive.software_revision,
3162 priv->dino_alive.software_revision,
3163 priv->dino_alive.device_identifier,
3164 priv->dino_alive.device_identifier,
3165 priv->dino_alive.time_stamp[0],
3166 priv->dino_alive.time_stamp[1],
3167 priv->dino_alive.time_stamp[2],
3168 priv->dino_alive.time_stamp[3],
3169 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 } else {
3171 IPW_DEBUG_INFO("Microcode is not alive\n");
3172 rc = -EINVAL;
3173 }
3174 } else {
3175 IPW_DEBUG_INFO("No alive response from DINO\n");
3176 rc = -ETIME;
3177 }
3178
3179 /* disable DINO, otherwise for some reason
3180 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003181 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003182
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 return rc;
3184}
3185
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003186static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003187{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003188 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003189 int offset = 0;
3190 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003191 int total_nr = 0;
3192 int i;
3193 struct pci_pool *pool;
Zhu Yi41093162010-03-09 16:05:31 +08003194 void **virts;
3195 dma_addr_t *phys;
James Ketrenos43f66a62005-03-25 12:31:53 -06003196
Frans Pop9fd1ea42010-03-24 19:46:31 +01003197 IPW_DEBUG_TRACE("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003198
Zhu Yi41093162010-03-09 16:05:31 +08003199 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3200 GFP_KERNEL);
3201 if (!virts)
3202 return -ENOMEM;
3203
3204 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3205 GFP_KERNEL);
3206 if (!phys) {
3207 kfree(virts);
3208 return -ENOMEM;
3209 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003210 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3211 if (!pool) {
3212 IPW_ERROR("pci_pool_create failed\n");
Zhu Yi41093162010-03-09 16:05:31 +08003213 kfree(phys);
3214 kfree(virts);
James Ketrenos43f66a62005-03-25 12:31:53 -06003215 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003216 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003217
3218 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003219 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003220
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003221 /* the DMA is already ready this would be a bug. */
3222 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003223
3224 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003225 u32 chunk_len;
3226 u8 *start;
3227 int size;
3228 int nr = 0;
3229
James Ketrenos43f66a62005-03-25 12:31:53 -06003230 chunk = (struct fw_chunk *)(data + offset);
3231 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003232 chunk_len = le32_to_cpu(chunk->length);
3233 start = data + offset;
3234
3235 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3236 for (i = 0; i < nr; i++) {
3237 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3238 &phys[total_nr]);
3239 if (!virts[total_nr]) {
3240 ret = -ENOMEM;
3241 goto out;
3242 }
3243 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3244 CB_MAX_LENGTH);
3245 memcpy(virts[total_nr], start, size);
3246 start += size;
3247 total_nr++;
3248 /* We don't support fw chunk larger than 64*8K */
3249 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3250 }
3251
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003253 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003254 * offeset*/
3255 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003256 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3257 nr, le32_to_cpu(chunk->address),
3258 chunk_len);
3259 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003260 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3261 goto out;
3262 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003263
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003264 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003265 } while (offset < len);
3266
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003267 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003268 ret = ipw_fw_dma_kick(priv);
3269 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003270 IPW_ERROR("dmaKick Failed\n");
3271 goto out;
3272 }
3273
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003274 ret = ipw_fw_dma_wait(priv);
3275 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003276 IPW_ERROR("dmaWaitSync Failed\n");
3277 goto out;
3278 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003279 out:
3280 for (i = 0; i < total_nr; i++)
3281 pci_pool_free(pool, virts[i], phys[i]);
3282
3283 pci_pool_destroy(pool);
Zhu Yi41093162010-03-09 16:05:31 +08003284 kfree(phys);
3285 kfree(virts);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003286
3287 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003288}
3289
3290/* stop nic */
3291static int ipw_stop_nic(struct ipw_priv *priv)
3292{
3293 int rc = 0;
3294
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003295 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003296 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003297
James Ketrenosb095c382005-08-24 22:04:42 -05003298 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3299 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003300 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003301 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003302 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003303 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003304
James Ketrenosb095c382005-08-24 22:04:42 -05003305 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003306
James Ketrenos43f66a62005-03-25 12:31:53 -06003307 return rc;
3308}
3309
3310static void ipw_start_nic(struct ipw_priv *priv)
3311{
3312 IPW_DEBUG_TRACE(">>\n");
3313
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003314 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003315 ipw_clear_bit(priv, IPW_RESET_REG,
3316 IPW_RESET_REG_MASTER_DISABLED |
3317 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003318 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003319
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003321 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3322 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003323
3324 IPW_DEBUG_TRACE("<<\n");
3325}
Jeff Garzikbf794512005-07-31 13:07:26 -04003326
James Ketrenos43f66a62005-03-25 12:31:53 -06003327static int ipw_init_nic(struct ipw_priv *priv)
3328{
3329 int rc;
3330
3331 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003332 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003333 /*prvHwInitNic */
3334 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003335 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003336
3337 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003338 ipw_write32(priv, IPW_READ_INT_REGISTER,
3339 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003340
3341 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003342 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3343 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003344 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003345 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3346
3347 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003348 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003349
3350 udelay(10);
3351
3352 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003353 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003354
3355 IPW_DEBUG_TRACE(">>\n");
3356 return 0;
3357}
3358
Jeff Garzikbf794512005-07-31 13:07:26 -04003359/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003360 * Probe is an ok place to call this from.
3361 */
3362static int ipw_reset_nic(struct ipw_priv *priv)
3363{
3364 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003365 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003366
3367 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003368
James Ketrenos43f66a62005-03-25 12:31:53 -06003369 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003370
James Ketrenosa613bff2005-08-24 21:43:11 -05003371 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003372 /* Clear the 'host command active' bit... */
3373 priv->status &= ~STATUS_HCMD_ACTIVE;
3374 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003375 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3376 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003377 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003378
3379 IPW_DEBUG_TRACE("<<\n");
3380 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003381}
James Ketrenos43f66a62005-03-25 12:31:53 -06003382
James Ketrenos9006ea72006-03-08 03:22:28 +08003383
3384struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003385 __le32 ver;
3386 __le32 boot_size;
3387 __le32 ucode_size;
3388 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003389 u8 data[0];
3390};
3391
Jeff Garzikbf794512005-07-31 13:07:26 -04003392static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003393 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003394{
James Ketrenos9006ea72006-03-08 03:22:28 +08003395 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 int rc;
3397
3398 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003399 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003400 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003401 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003402 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003403 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003404
James Ketrenos9006ea72006-03-08 03:22:28 +08003405 if ((*raw)->size < sizeof(*fw)) {
3406 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003407 return -EINVAL;
3408 }
3409
James Ketrenos9006ea72006-03-08 03:22:28 +08003410 fw = (void *)(*raw)->data;
3411
Zhu Yi0070f8c2006-04-13 17:20:12 +08003412 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3413 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003414 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3415 name, (*raw)->size);
3416 return -EINVAL;
3417 }
3418
3419 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003420 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003421 le32_to_cpu(fw->ver) >> 16,
3422 le32_to_cpu(fw->ver) & 0xff,
3423 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003424 return 0;
3425}
3426
James Ketrenosb095c382005-08-24 22:04:42 -05003427#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003428
Arjan van de Ven858119e2006-01-14 13:20:43 -08003429static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003430 struct ipw_rx_queue *rxq)
3431{
3432 unsigned long flags;
3433 int i;
3434
3435 spin_lock_irqsave(&rxq->lock, flags);
3436
3437 INIT_LIST_HEAD(&rxq->rx_free);
3438 INIT_LIST_HEAD(&rxq->rx_used);
3439
3440 /* Fill the rx_used queue with _all_ of the Rx buffers */
3441 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3442 /* In the reset function, these buffers may have been allocated
3443 * to an SKB, so we need to unmap and free potential storage */
3444 if (rxq->pool[i].skb != NULL) {
3445 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003446 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003447 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003448 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003449 }
3450 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3451 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003452
James Ketrenos43f66a62005-03-25 12:31:53 -06003453 /* Set us so that we have processed and used all buffers, but have
3454 * not restocked the Rx queue with fresh buffers */
3455 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003456 rxq->free_count = 0;
3457 spin_unlock_irqrestore(&rxq->lock, flags);
3458}
3459
3460#ifdef CONFIG_PM
3461static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003462static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003463
3464static void free_firmware(void)
3465{
3466 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003467 release_firmware(raw);
3468 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003469 fw_loaded = 0;
3470 }
3471}
3472#else
3473#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003474#endif
3475
3476static int ipw_load(struct ipw_priv *priv)
3477{
3478#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003479 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003480#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003481 struct ipw_fw *fw;
3482 u8 *boot_img, *ucode_img, *fw_img;
3483 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003484 int rc = 0, retries = 3;
3485
Zhu Yi397ae122006-01-24 16:37:22 +08003486 switch (priv->ieee->iw_mode) {
3487 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003488 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003489 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003490#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003491 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003492 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003493 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003494#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003495 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003496 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003497 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003498 }
Zhu Yi397ae122006-01-24 16:37:22 +08003499
James Ketrenos9006ea72006-03-08 03:22:28 +08003500 if (!name) {
3501 rc = -EINVAL;
3502 goto error;
3503 }
3504
3505#ifdef CONFIG_PM
3506 if (!fw_loaded) {
3507#endif
3508 rc = ipw_get_fw(priv, &raw, name);
3509 if (rc < 0)
3510 goto error;
3511#ifdef CONFIG_PM
3512 }
3513#endif
3514
3515 fw = (void *)raw->data;
3516 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003517 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3518 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3519 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003520
Zhu Yi397ae122006-01-24 16:37:22 +08003521 if (rc < 0)
3522 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003523
3524 if (!priv->rxq)
3525 priv->rxq = ipw_rx_queue_alloc(priv);
3526 else
3527 ipw_rx_queue_reset(priv, priv->rxq);
3528 if (!priv->rxq) {
3529 IPW_ERROR("Unable to initialize Rx queue\n");
3530 goto error;
3531 }
3532
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003533 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003534 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003535 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003536 priv->status &= ~STATUS_INT_ENABLED;
3537
3538 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003539 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003540
James Ketrenos43f66a62005-03-25 12:31:53 -06003541 ipw_stop_nic(priv);
3542
3543 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003544 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 IPW_ERROR("Unable to reset NIC\n");
3546 goto error;
3547 }
3548
James Ketrenosb095c382005-08-24 22:04:42 -05003549 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3550 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003551
3552 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003553 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003554 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003555 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003556 goto error;
3557 }
3558
3559 /* kick start the device */
3560 ipw_start_nic(priv);
3561
Zhu Yic7b6a672006-01-24 16:37:05 +08003562 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003563 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3564 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003565 if (rc < 0) {
3566 IPW_ERROR("device failed to boot initial fw image\n");
3567 goto error;
3568 }
3569 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3570
Jeff Garzikbf794512005-07-31 13:07:26 -04003571 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003572 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003573
3574 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003575 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003576 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003577 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003578 goto error;
3579 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003580
James Ketrenos43f66a62005-03-25 12:31:53 -06003581 /* stop nic */
3582 ipw_stop_nic(priv);
3583
3584 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003585 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003586 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003587 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003588 goto error;
3589 }
Zhu Yi397ae122006-01-24 16:37:22 +08003590#ifdef CONFIG_PM
3591 fw_loaded = 1;
3592#endif
3593
James Ketrenos43f66a62005-03-25 12:31:53 -06003594 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3595
3596 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003597 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003598 IPW_ERROR("Unable to initialize queues\n");
3599 goto error;
3600 }
3601
3602 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003603 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003604 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003605 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003606
James Ketrenos43f66a62005-03-25 12:31:53 -06003607 /* kick start the device */
3608 ipw_start_nic(priv);
3609
James Ketrenosb095c382005-08-24 22:04:42 -05003610 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003611 if (retries > 0) {
3612 IPW_WARNING("Parity error. Retrying init.\n");
3613 retries--;
3614 goto retry;
3615 }
3616
3617 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3618 rc = -EIO;
3619 goto error;
3620 }
3621
3622 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003623 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3624 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003625 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003626 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003627 goto error;
3628 }
3629 IPW_DEBUG_INFO("device response after %dms\n", rc);
3630
3631 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003632 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003633
3634 /* read eeprom data and initialize the eeprom region of sram */
3635 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003636 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003637
3638 /* enable interrupts */
3639 ipw_enable_interrupts(priv);
3640
3641 /* Ensure our queue has valid packets */
3642 ipw_rx_queue_replenish(priv);
3643
James Ketrenosb095c382005-08-24 22:04:42 -05003644 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003645
3646 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003647 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003648
3649#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003650 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003651#endif
3652 return 0;
3653
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003654 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003655 if (priv->rxq) {
3656 ipw_rx_queue_free(priv, priv->rxq);
3657 priv->rxq = NULL;
3658 }
3659 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003660 if (raw)
3661 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003662#ifdef CONFIG_PM
3663 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003664 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003665#endif
3666
3667 return rc;
3668}
3669
Jeff Garzikbf794512005-07-31 13:07:26 -04003670/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003671 * DMA services
3672 *
3673 * Theory of operation
3674 *
3675 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3676 * 2 empty entries always kept in the buffer to protect from overflow.
3677 *
3678 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003679 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3680 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003681 * Tx queue resumed.
3682 *
3683 * The IPW operates with six queues, one receive queue in the device's
3684 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003685 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003686 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003687 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003688 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003689 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003690 * we only utilize the first data transmit queue (queue1).
3691 */
3692
3693/**
3694 * Driver allocates buffers of this size for Rx
3695 */
3696
Dan Williams943dbef2008-02-14 17:49:41 -05003697/**
3698 * ipw_rx_queue_space - Return number of free slots available in queue.
3699 */
3700static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3701{
3702 int s = q->read - q->write;
3703 if (s <= 0)
3704 s += RX_QUEUE_SIZE;
3705 /* keep some buffer to not confuse full and empty queue */
3706 s -= 2;
3707 if (s < 0)
3708 s = 0;
3709 return s;
3710}
3711
3712static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003713{
3714 int s = q->last_used - q->first_empty;
3715 if (s <= 0)
3716 s += q->n_bd;
3717 s -= 2; /* keep some reserve to not confuse empty and full situations */
3718 if (s < 0)
3719 s = 0;
3720 return s;
3721}
3722
3723static inline int ipw_queue_inc_wrap(int index, int n_bd)
3724{
3725 return (++index == n_bd) ? 0 : index;
3726}
3727
3728/**
3729 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003730 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003731 * @param q queue to init
3732 * @param count Number of BD's to allocate. Should be power of 2
3733 * @param read_register Address for 'read' register
3734 * (not offset within BAR, full address)
3735 * @param write_register Address for 'write' register
3736 * (not offset within BAR, full address)
3737 * @param base_register Address for 'base' register
3738 * (not offset within BAR, full address)
3739 * @param size Address for 'size' register
3740 * (not offset within BAR, full address)
3741 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003742static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003743 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003744{
3745 q->n_bd = count;
3746
3747 q->low_mark = q->n_bd / 4;
3748 if (q->low_mark < 4)
3749 q->low_mark = 4;
3750
3751 q->high_mark = q->n_bd / 8;
3752 if (q->high_mark < 2)
3753 q->high_mark = 2;
3754
3755 q->first_empty = q->last_used = 0;
3756 q->reg_r = read;
3757 q->reg_w = write;
3758
3759 ipw_write32(priv, base, q->dma_addr);
3760 ipw_write32(priv, size, count);
3761 ipw_write32(priv, read, 0);
3762 ipw_write32(priv, write, 0);
3763
3764 _ipw_read32(priv, 0x90);
3765}
3766
Jeff Garzikbf794512005-07-31 13:07:26 -04003767static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003768 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003769 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003770{
3771 struct pci_dev *dev = priv->pci_dev;
3772
3773 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3774 if (!q->txb) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003775 IPW_ERROR("vmalloc for auxiliary BD structures failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 return -ENOMEM;
3777 }
3778
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003779 q->bd =
3780 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003781 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003782 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003783 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003784 kfree(q->txb);
3785 q->txb = NULL;
3786 return -ENOMEM;
3787 }
3788
3789 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3790 return 0;
3791}
3792
3793/**
3794 * Free one TFD, those at index [txq->q.last_used].
3795 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003796 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003797 * @param dev
3798 * @param txq
3799 */
3800static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3801 struct clx2_tx_queue *txq)
3802{
3803 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3804 struct pci_dev *dev = priv->pci_dev;
3805 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003806
James Ketrenos43f66a62005-03-25 12:31:53 -06003807 /* classify bd */
3808 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3809 /* nothing to cleanup after for host commands */
3810 return;
3811
3812 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003813 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3814 IPW_ERROR("Too many chunks: %i\n",
3815 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003816 /** @todo issue fatal error, it is quite serious situation */
3817 return;
3818 }
3819
3820 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003821 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3822 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3823 le16_to_cpu(bd->u.data.chunk_len[i]),
3824 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003825 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003826 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003827 txq->txb[txq->q.last_used] = NULL;
3828 }
3829 }
3830}
3831
3832/**
3833 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003834 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003835 * Empty queue by removing and destroying all BD's.
3836 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003837 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003838 * @param dev
3839 * @param q
3840 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003841static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003842{
3843 struct clx2_queue *q = &txq->q;
3844 struct pci_dev *dev = priv->pci_dev;
3845
Jeff Garzikbf794512005-07-31 13:07:26 -04003846 if (q->n_bd == 0)
3847 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003848
3849 /* first, empty all BD's */
3850 for (; q->first_empty != q->last_used;
3851 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3852 ipw_queue_tx_free_tfd(priv, txq);
3853 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003854
James Ketrenos43f66a62005-03-25 12:31:53 -06003855 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003856 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003857 q->dma_addr);
3858 kfree(txq->txb);
3859
3860 /* 0 fill whole structure */
3861 memset(txq, 0, sizeof(*txq));
3862}
3863
James Ketrenos43f66a62005-03-25 12:31:53 -06003864/**
3865 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003866 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003867 * @param priv
3868 */
3869static void ipw_tx_queue_free(struct ipw_priv *priv)
3870{
3871 /* Tx CMD queue */
3872 ipw_queue_tx_free(priv, &priv->txq_cmd);
3873
3874 /* Tx queues */
3875 ipw_queue_tx_free(priv, &priv->txq[0]);
3876 ipw_queue_tx_free(priv, &priv->txq[1]);
3877 ipw_queue_tx_free(priv, &priv->txq[2]);
3878 ipw_queue_tx_free(priv, &priv->txq[3]);
3879}
3880
Arjan van de Ven858119e2006-01-14 13:20:43 -08003881static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003882{
3883 /* First 3 bytes are manufacturer */
3884 bssid[0] = priv->mac_addr[0];
3885 bssid[1] = priv->mac_addr[1];
3886 bssid[2] = priv->mac_addr[2];
3887
3888 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003889 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003890
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003891 bssid[0] &= 0xfe; /* clear multicast bit */
3892 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003893}
3894
Arjan van de Ven858119e2006-01-14 13:20:43 -08003895static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003896{
3897 struct ipw_station_entry entry;
3898 int i;
3899
3900 for (i = 0; i < priv->num_stations; i++) {
3901 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3902 /* Another node is active in network */
3903 priv->missed_adhoc_beacons = 0;
3904 if (!(priv->config & CFG_STATIC_CHANNEL))
3905 /* when other nodes drop out, we drop out */
3906 priv->config &= ~CFG_ADHOC_PERSIST;
3907
3908 return i;
3909 }
3910 }
3911
3912 if (i == MAX_STATIONS)
3913 return IPW_INVALID_STATION;
3914
Johannes Berge1749612008-10-27 15:59:26 -07003915 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003916
3917 entry.reserved = 0;
3918 entry.support_mode = 0;
3919 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3920 memcpy(priv->stations[i], bssid, ETH_ALEN);
3921 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003922 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003923 priv->num_stations++;
3924
3925 return i;
3926}
3927
Arjan van de Ven858119e2006-01-14 13:20:43 -08003928static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003929{
3930 int i;
3931
Jeff Garzikbf794512005-07-31 13:07:26 -04003932 for (i = 0; i < priv->num_stations; i++)
3933 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003934 return i;
3935
3936 return IPW_INVALID_STATION;
3937}
3938
3939static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3940{
3941 int err;
3942
Hong Liu7b996592005-08-25 17:36:13 +08003943 if (priv->status & STATUS_ASSOCIATING) {
3944 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01003945 schedule_work(&priv->disassociate);
Hong Liu7b996592005-08-25 17:36:13 +08003946 return;
3947 }
3948
3949 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003950 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3951 return;
3952 }
3953
Johannes Berge1749612008-10-27 15:59:26 -07003954 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003955 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003956 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003957 priv->assoc_request.channel);
3958
3959 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3960 priv->status |= STATUS_DISASSOCIATING;
3961
3962 if (quiet)
3963 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3964 else
3965 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003966
James Ketrenos43f66a62005-03-25 12:31:53 -06003967 err = ipw_send_associate(priv, &priv->assoc_request);
3968 if (err) {
3969 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3970 "failed.\n");
3971 return;
3972 }
3973
3974}
3975
James Ketrenosc848d0a2005-08-24 21:56:24 -05003976static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003977{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003978 struct ipw_priv *priv = data;
3979 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3980 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003981 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003982 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003983 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003984}
3985
David Howellsc4028952006-11-22 14:57:56 +00003986static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003987{
David Howellsc4028952006-11-22 14:57:56 +00003988 struct ipw_priv *priv =
3989 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003990 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003991 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003992 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003993}
3994
David Howellsc4028952006-11-22 14:57:56 +00003995static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003996{
David Howellsc4028952006-11-22 14:57:56 +00003997 struct ipw_priv *priv =
3998 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003999
4000#ifdef CONFIG_IPW2200_PROMISCUOUS
4001 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
4002 priv->sys_config.accept_all_data_frames = 1;
4003 priv->sys_config.accept_non_directed_frames = 1;
4004 priv->sys_config.accept_all_mgmt_bcpr = 1;
4005 priv->sys_config.accept_all_mgmt_frames = 1;
4006 }
4007#endif
4008
4009 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004010}
4011
4012struct ipw_status_code {
4013 u16 status;
4014 const char *reason;
4015};
4016
4017static const struct ipw_status_code ipw_status_codes[] = {
4018 {0x00, "Successful"},
4019 {0x01, "Unspecified failure"},
4020 {0x0A, "Cannot support all requested capabilities in the "
4021 "Capability information field"},
4022 {0x0B, "Reassociation denied due to inability to confirm that "
4023 "association exists"},
4024 {0x0C, "Association denied due to reason outside the scope of this "
4025 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004026 {0x0D,
4027 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004028 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004029 {0x0E,
4030 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004031 "transaction sequence number out of expected sequence"},
4032 {0x0F, "Authentication rejected because of challenge failure"},
4033 {0x10, "Authentication rejected due to timeout waiting for next "
4034 "frame in sequence"},
4035 {0x11, "Association denied because AP is unable to handle additional "
4036 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004037 {0x12,
4038 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004039 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004040 {0x13,
4041 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004042 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004043 {0x14,
4044 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004045 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004046 {0x15,
4047 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004048 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004049 {0x19,
4050 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004051 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004052 {0x1A,
4053 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004054 "DSSS-OFDM operation"},
4055 {0x28, "Invalid Information Element"},
4056 {0x29, "Group Cipher is not valid"},
4057 {0x2A, "Pairwise Cipher is not valid"},
4058 {0x2B, "AKMP is not valid"},
4059 {0x2C, "Unsupported RSN IE version"},
4060 {0x2D, "Invalid RSN IE Capabilities"},
4061 {0x2E, "Cipher suite is rejected per security policy"},
4062};
4063
Jeff Garzikbf794512005-07-31 13:07:26 -04004064static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004065{
4066 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004067 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004068 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 return ipw_status_codes[i].reason;
4070 return "Unknown status value.";
4071}
James Ketrenos43f66a62005-03-25 12:31:53 -06004072
4073static void inline average_init(struct average *avg)
4074{
4075 memset(avg, 0, sizeof(*avg));
4076}
4077
Zhu Yi00d21de2006-04-13 17:19:02 +08004078#define DEPTH_RSSI 8
4079#define DEPTH_NOISE 16
4080static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4081{
4082 return ((depth-1)*prev_avg + val)/depth;
4083}
4084
Arjan van de Ven858119e2006-01-14 13:20:43 -08004085static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004086{
4087 avg->sum -= avg->entries[avg->pos];
4088 avg->sum += val;
4089 avg->entries[avg->pos++] = val;
4090 if (unlikely(avg->pos == AVG_ENTRIES)) {
4091 avg->init = 1;
4092 avg->pos = 0;
4093 }
4094}
4095
Arjan van de Ven858119e2006-01-14 13:20:43 -08004096static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004097{
4098 if (!unlikely(avg->init)) {
4099 if (avg->pos)
4100 return avg->sum / avg->pos;
4101 return 0;
4102 }
4103
4104 return avg->sum / AVG_ENTRIES;
4105}
4106
4107static void ipw_reset_stats(struct ipw_priv *priv)
4108{
4109 u32 len = sizeof(u32);
4110
4111 priv->quality = 0;
4112
4113 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004114 priv->exp_avg_rssi = -60;
4115 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004116
4117 priv->last_rate = 0;
4118 priv->last_missed_beacons = 0;
4119 priv->last_rx_packets = 0;
4120 priv->last_tx_packets = 0;
4121 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004122
James Ketrenos43f66a62005-03-25 12:31:53 -06004123 /* Firmware managed, reset only when NIC is restarted, so we have to
4124 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004125 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004126 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004127 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004128 &priv->last_tx_failures, &len);
4129
4130 /* Driver managed, reset with each association */
4131 priv->missed_adhoc_beacons = 0;
4132 priv->missed_beacons = 0;
4133 priv->tx_packets = 0;
4134 priv->rx_packets = 0;
4135
4136}
4137
Arjan van de Ven858119e2006-01-14 13:20:43 -08004138static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004139{
4140 u32 i = 0x80000000;
4141 u32 mask = priv->rates_mask;
4142 /* If currently associated in B mode, restrict the maximum
4143 * rate match to B rates */
4144 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004145 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004146
4147 /* TODO: Verify that the rate is supported by the current rates
4148 * list. */
4149
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004150 while (i && !(mask & i))
4151 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004152 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004153 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004154 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004155 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004156 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004157 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004158 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004159 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004160 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004161 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004162 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004163 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004164 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004165 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004166 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004167 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004168 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004169 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004170 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004171 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004172 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004173 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004174 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004175 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004176 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004177 }
4178
Jeff Garzikbf794512005-07-31 13:07:26 -04004179 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004180 return 11000000;
4181 else
4182 return 54000000;
4183}
4184
4185static u32 ipw_get_current_rate(struct ipw_priv *priv)
4186{
4187 u32 rate, len = sizeof(rate);
4188 int err;
4189
Jeff Garzikbf794512005-07-31 13:07:26 -04004190 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004191 return 0;
4192
4193 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004194 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004195 &len);
4196 if (err) {
4197 IPW_DEBUG_INFO("failed querying ordinals.\n");
4198 return 0;
4199 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004200 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004201 return ipw_get_max_rate(priv);
4202
4203 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004204 case IPW_TX_RATE_1MB:
4205 return 1000000;
4206 case IPW_TX_RATE_2MB:
4207 return 2000000;
4208 case IPW_TX_RATE_5MB:
4209 return 5500000;
4210 case IPW_TX_RATE_6MB:
4211 return 6000000;
4212 case IPW_TX_RATE_9MB:
4213 return 9000000;
4214 case IPW_TX_RATE_11MB:
4215 return 11000000;
4216 case IPW_TX_RATE_12MB:
4217 return 12000000;
4218 case IPW_TX_RATE_18MB:
4219 return 18000000;
4220 case IPW_TX_RATE_24MB:
4221 return 24000000;
4222 case IPW_TX_RATE_36MB:
4223 return 36000000;
4224 case IPW_TX_RATE_48MB:
4225 return 48000000;
4226 case IPW_TX_RATE_54MB:
4227 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004228 }
4229
4230 return 0;
4231}
4232
James Ketrenos43f66a62005-03-25 12:31:53 -06004233#define IPW_STATS_INTERVAL (2 * HZ)
4234static void ipw_gather_stats(struct ipw_priv *priv)
4235{
4236 u32 rx_err, rx_err_delta, rx_packets_delta;
4237 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4238 u32 missed_beacons_percent, missed_beacons_delta;
4239 u32 quality = 0;
4240 u32 len = sizeof(u32);
4241 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004242 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004243 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004244 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004245
4246 if (!(priv->status & STATUS_ASSOCIATED)) {
4247 priv->quality = 0;
4248 return;
4249 }
4250
4251 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004252 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004253 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004254 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004255 priv->last_missed_beacons = priv->missed_beacons;
4256 if (priv->assoc_request.beacon_interval) {
4257 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004258 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004259 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004260 } else {
4261 missed_beacons_percent = 0;
4262 }
4263 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4264
4265 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4266 rx_err_delta = rx_err - priv->last_rx_err;
4267 priv->last_rx_err = rx_err;
4268
4269 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4270 tx_failures_delta = tx_failures - priv->last_tx_failures;
4271 priv->last_tx_failures = tx_failures;
4272
4273 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4274 priv->last_rx_packets = priv->rx_packets;
4275
4276 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4277 priv->last_tx_packets = priv->tx_packets;
4278
4279 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004280 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004281 * Missed beacon: 100% = 0, 0% = 70% missed
4282 * Rate: 60% = 1Mbs, 100% = Max
4283 * Rx and Tx errors represent a straight % of total Rx/Tx
4284 * RSSI: 100% = > -50, 0% = < -80
4285 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004286 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004287 * The lowest computed quality is used.
4288 *
4289 */
4290#define BEACON_THRESHOLD 5
4291 beacon_quality = 100 - missed_beacons_percent;
4292 if (beacon_quality < BEACON_THRESHOLD)
4293 beacon_quality = 0;
4294 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004295 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004296 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004297 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004298 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004299
James Ketrenos43f66a62005-03-25 12:31:53 -06004300 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004301 max_rate = ipw_get_max_rate(priv);
4302 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004303 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4304 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004305
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004306 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004307 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004308 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004309 else
4310 rx_quality = 100;
4311 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4312 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004313
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004314 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004315 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004316 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004317 else
4318 tx_quality = 100;
4319 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4320 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004321
Zhu Yi00d21de2006-04-13 17:19:02 +08004322 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004323 signal_quality =
4324 (100 *
4325 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4326 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4327 (priv->ieee->perfect_rssi - rssi) *
4328 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4329 62 * (priv->ieee->perfect_rssi - rssi))) /
4330 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4331 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4332 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004333 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004334 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004335 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004336
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004337 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004338 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004339
Reinette Chatre21f8a732009-08-18 10:25:05 -07004340 quality = min(rx_quality, signal_quality);
4341 quality = min(tx_quality, quality);
4342 quality = min(rate_quality, quality);
4343 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004344 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004345 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4346 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004347 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004348 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4349 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004350 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004351 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4352 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004353 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004354 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4355 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004356 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004357 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4358 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004359
4360 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004361
Tejun Heobcb6d912011-01-26 12:12:50 +01004362 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL);
James Ketrenos43f66a62005-03-25 12:31:53 -06004363}
4364
David Howellsc4028952006-11-22 14:57:56 +00004365static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004366{
David Howellsc4028952006-11-22 14:57:56 +00004367 struct ipw_priv *priv =
4368 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004369 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004370 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004371 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004372}
4373
Ben Cahille7582562005-10-06 15:34:41 -05004374/* Missed beacon behavior:
4375 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4376 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4377 * Above disassociate threshold, give up and stop scanning.
4378 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004379static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004380 int missed_count)
4381{
4382 priv->notif_missed_beacons = missed_count;
4383
James Ketrenosafbf30a2005-08-25 00:05:33 -05004384 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004385 priv->status & STATUS_ASSOCIATED) {
4386 /* If associated and we've hit the missed
4387 * beacon threshold, disassociate, turn
4388 * off roaming, and abort any active scans */
4389 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004390 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004391 "Missed beacon: %d - disassociate\n", missed_count);
4392 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004393 if (priv->status & STATUS_SCANNING) {
4394 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4395 IPW_DL_STATE,
4396 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004397 schedule_work(&priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004398 }
4399
Tejun Heobcb6d912011-01-26 12:12:50 +01004400 schedule_work(&priv->disassociate);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004401 return;
4402 }
4403
4404 if (priv->status & STATUS_ROAMING) {
4405 /* If we are currently roaming, then just
4406 * print a debug statement... */
4407 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4408 "Missed beacon: %d - roam in progress\n",
4409 missed_count);
4410 return;
4411 }
4412
Zhu Yi4bfdb912006-01-24 16:37:16 +08004413 if (roaming &&
4414 (missed_count > priv->roaming_threshold &&
4415 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004416 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004417 * bit in the status and kick off a scan.
4418 * This can happen several times before we reach
4419 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004420 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4421 "Missed beacon: %d - initiate "
4422 "roaming\n", missed_count);
4423 if (!(priv->status & STATUS_ROAMING)) {
4424 priv->status |= STATUS_ROAMING;
4425 if (!(priv->status & STATUS_SCANNING))
Tejun Heobcb6d912011-01-26 12:12:50 +01004426 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004427 }
4428 return;
4429 }
4430
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004431 if (priv->status & STATUS_SCANNING &&
4432 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004433 /* Stop scan to keep fw from getting
4434 * stuck (only if we aren't roaming --
4435 * otherwise we'll never scan more than 2 or 3
4436 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004437 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4438 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004439 schedule_work(&priv->abort_scan);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004440 }
4441
4442 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004443}
4444
Dan Williams0b531672007-10-09 13:55:24 -04004445static void ipw_scan_event(struct work_struct *work)
4446{
4447 union iwreq_data wrqu;
4448
4449 struct ipw_priv *priv =
4450 container_of(work, struct ipw_priv, scan_event.work);
4451
4452 wrqu.data.length = 0;
4453 wrqu.data.flags = 0;
4454 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4455}
4456
4457static void handle_scan_event(struct ipw_priv *priv)
4458{
4459 /* Only userspace-requested scan completion events go out immediately */
4460 if (!priv->user_requested_scan) {
4461 if (!delayed_work_pending(&priv->scan_event))
Tejun Heobcb6d912011-01-26 12:12:50 +01004462 schedule_delayed_work(&priv->scan_event,
4463 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004464 } else {
4465 union iwreq_data wrqu;
4466
4467 priv->user_requested_scan = 0;
4468 cancel_delayed_work(&priv->scan_event);
4469
4470 wrqu.data.length = 0;
4471 wrqu.data.flags = 0;
4472 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4473 }
4474}
4475
James Ketrenos43f66a62005-03-25 12:31:53 -06004476/**
4477 * Handle host notification packet.
4478 * Called from interrupt routine
4479 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004480static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004481 struct ipw_rx_notification *notif)
4482{
John W. Linville9387b7c2008-09-30 20:59:05 -04004483 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004484 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004485
Al Viroe62e1ee2007-12-27 01:36:46 -05004486 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004487
James Ketrenos43f66a62005-03-25 12:31:53 -06004488 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004489 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4490 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004491
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004492 switch (assoc->state) {
4493 case CMAS_ASSOCIATED:{
4494 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4495 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004496 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004497 print_ssid(ssid, priv->essid,
4498 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004499 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004501 switch (priv->ieee->iw_mode) {
4502 case IW_MODE_INFRA:
4503 memcpy(priv->ieee->bssid,
4504 priv->bssid, ETH_ALEN);
4505 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004506
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004507 case IW_MODE_ADHOC:
4508 memcpy(priv->ieee->bssid,
4509 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004510
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004511 /* clear out the station table */
4512 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004513
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004514 IPW_DEBUG_ASSOC
4515 ("queueing adhoc check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004516 schedule_delayed_work(
4517 &priv->adhoc_check,
4518 le16_to_cpu(priv->
4519 assoc_request.
4520 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004521 break;
4522 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004523
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004524 priv->status &= ~STATUS_ASSOCIATING;
4525 priv->status |= STATUS_ASSOCIATED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004526 schedule_work(&priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004527
Zhu Yie43e3c12006-04-13 17:20:45 +08004528#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004529#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004530 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004531 if ((priv->status & STATUS_AUTH) &&
4532 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4533 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004534 if ((sizeof
4535 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004536 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004537 <= size)
4538 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004539 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004540 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004541 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004542 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004543 };
4544
4545 IPW_DEBUG_QOS
4546 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004547 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004548 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004549 ieee,
4550 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004551 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004552 *)
4553 &notif->u.raw, &stats);
4554 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004555 }
James Ketrenosb095c382005-08-24 22:04:42 -05004556#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004557
James Ketrenosa613bff2005-08-24 21:43:11 -05004558 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004559
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004560 break;
4561 }
4562
4563 case CMAS_AUTHENTICATED:{
4564 if (priv->
4565 status & (STATUS_ASSOCIATED |
4566 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004567 struct notif_authenticate *auth
4568 = &notif->u.auth;
4569 IPW_DEBUG(IPW_DL_NOTIF |
4570 IPW_DL_STATE |
4571 IPW_DL_ASSOC,
4572 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004573 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004574 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004575 print_ssid(ssid,
4576 priv->
4577 essid,
4578 priv->
4579 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004580 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004581 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004582 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004583 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004585
4586 priv->status &=
4587 ~(STATUS_ASSOCIATING |
4588 STATUS_AUTH |
4589 STATUS_ASSOCIATED);
4590
James Ketrenosa613bff2005-08-24 21:43:11 -05004591 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004592 break;
4593 }
4594
4595 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4596 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004597 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004598 print_ssid(ssid, priv->essid,
4599 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004600 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004601 break;
4602 }
4603
4604 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004605 if (priv->status & STATUS_AUTH) {
4606 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004607 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004608 *resp;
4609 resp =
4610 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004611 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004612 *)&notif->u.raw;
4613 IPW_DEBUG(IPW_DL_NOTIF |
4614 IPW_DL_STATE |
4615 IPW_DL_ASSOC,
4616 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004617 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004618 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004619 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004620 (resp->status)));
4621 }
4622
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004623 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4624 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004625 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004626 print_ssid(ssid, priv->essid,
4627 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004628 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004629
4630 priv->status &=
4631 ~(STATUS_DISASSOCIATING |
4632 STATUS_ASSOCIATING |
4633 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004634 if (priv->assoc_network
4635 && (priv->assoc_network->
4636 capability &
4637 WLAN_CAPABILITY_IBSS))
4638 ipw_remove_current_network
4639 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004640
James Ketrenosa613bff2005-08-24 21:43:11 -05004641 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004642
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004643 break;
4644 }
4645
James Ketrenosb095c382005-08-24 22:04:42 -05004646 case CMAS_RX_ASSOC_RESP:
4647 break;
4648
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004649 default:
4650 IPW_ERROR("assoc: unknown (%d)\n",
4651 assoc->state);
4652 break;
4653 }
4654
James Ketrenos43f66a62005-03-25 12:31:53 -06004655 break;
4656 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004657
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004658 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4659 struct notif_authenticate *auth = &notif->u.auth;
4660 switch (auth->state) {
4661 case CMAS_AUTHENTICATED:
4662 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004663 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004664 print_ssid(ssid, priv->essid,
4665 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004666 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004667 priv->status |= STATUS_AUTH;
4668 break;
4669
4670 case CMAS_INIT:
4671 if (priv->status & STATUS_AUTH) {
4672 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4673 IPW_DL_ASSOC,
4674 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004675 le16_to_cpu(auth->status),
4676 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004677 (auth->
4678 status)));
4679 }
4680 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4681 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004682 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004683 print_ssid(ssid, priv->essid,
4684 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004685 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004686
4687 priv->status &= ~(STATUS_ASSOCIATING |
4688 STATUS_AUTH |
4689 STATUS_ASSOCIATED);
4690
James Ketrenosa613bff2005-08-24 21:43:11 -05004691 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004692 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004693
4694 case CMAS_TX_AUTH_SEQ_1:
4695 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4696 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4697 break;
4698 case CMAS_RX_AUTH_SEQ_2:
4699 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4700 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4701 break;
4702 case CMAS_AUTH_SEQ_1_PASS:
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4704 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4705 break;
4706 case CMAS_AUTH_SEQ_1_FAIL:
4707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4708 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4709 break;
4710 case CMAS_TX_AUTH_SEQ_3:
4711 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4712 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4713 break;
4714 case CMAS_RX_AUTH_SEQ_4:
4715 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4716 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4717 break;
4718 case CMAS_AUTH_SEQ_2_PASS:
4719 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4720 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4721 break;
4722 case CMAS_AUTH_SEQ_2_FAIL:
4723 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4724 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4725 break;
4726 case CMAS_TX_ASSOC:
4727 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4728 IPW_DL_ASSOC, "TX_ASSOC\n");
4729 break;
4730 case CMAS_RX_ASSOC_RESP:
4731 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4732 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004733
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004734 break;
4735 case CMAS_ASSOCIATED:
4736 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4737 IPW_DL_ASSOC, "ASSOCIATED\n");
4738 break;
4739 default:
4740 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4741 auth->state);
4742 break;
4743 }
4744 break;
4745 }
4746
4747 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4748 struct notif_channel_result *x =
4749 &notif->u.channel_result;
4750
Al Viroe62e1ee2007-12-27 01:36:46 -05004751 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004752 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4753 x->channel_num);
4754 } else {
4755 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4756 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004757 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004758 }
4759 break;
4760 }
4761
4762 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4763 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004764 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004765 IPW_DEBUG_SCAN
4766 ("Scan completed: type %d, %d channels, "
4767 "%d status\n", x->scan_type,
4768 x->num_channels, x->status);
4769 } else {
4770 IPW_ERROR("Scan completed of wrong size %d "
4771 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004772 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004773 }
4774
4775 priv->status &=
4776 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4777
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004778 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004779 cancel_delayed_work(&priv->scan_check);
4780
James Ketrenosb095c382005-08-24 22:04:42 -05004781 if (priv->status & STATUS_EXIT_PENDING)
4782 break;
4783
4784 priv->ieee->scans++;
4785
4786#ifdef CONFIG_IPW2200_MONITOR
4787 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004788 priv->status |= STATUS_SCAN_FORCED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004789 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004790 break;
4791 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004792 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004793#endif /* CONFIG_IPW2200_MONITOR */
4794
Dan Williamsea177302008-06-02 17:51:23 -04004795 /* Do queued direct scans first */
Tejun Heobcb6d912011-01-26 12:12:50 +01004796 if (priv->status & STATUS_DIRECT_SCAN_PENDING)
4797 schedule_delayed_work(&priv->request_direct_scan, 0);
Dan Williamsea177302008-06-02 17:51:23 -04004798
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004799 if (!(priv->status & (STATUS_ASSOCIATED |
4800 STATUS_ASSOCIATING |
4801 STATUS_ROAMING |
4802 STATUS_DISASSOCIATING)))
Tejun Heobcb6d912011-01-26 12:12:50 +01004803 schedule_work(&priv->associate);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004804 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004805 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4806 /* If a scan completed and we are in roam mode, then
4807 * the scan that completed was the one requested as a
4808 * result of entering roam... so, schedule the
4809 * roam work */
Tejun Heobcb6d912011-01-26 12:12:50 +01004810 schedule_work(&priv->roam);
Ben Cahille7582562005-10-06 15:34:41 -05004811 else
4812 /* Don't schedule if we aborted the scan */
4813 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004814 } else if (priv->status & STATUS_SCAN_PENDING)
Tejun Heobcb6d912011-01-26 12:12:50 +01004815 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004816 else if (priv->config & CFG_BACKGROUND_SCAN
4817 && priv->status & STATUS_ASSOCIATED)
Tejun Heobcb6d912011-01-26 12:12:50 +01004818 schedule_delayed_work(&priv->request_scan,
4819 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004820
4821 /* Send an empty event to user space.
4822 * We don't send the received data on the event because
4823 * it would require us to do complex transcoding, and
4824 * we want to minimise the work done in the irq handler
4825 * Use a request to extract the data.
4826 * Also, we generate this even for any scan, regardless
4827 * on how the scan was initiated. User space can just
4828 * sync on periodic scan to get fresh data...
4829 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004830 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4831 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004832 break;
4833 }
4834
4835 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4836 struct notif_frag_length *x = &notif->u.frag_len;
4837
Al Viroe62e1ee2007-12-27 01:36:46 -05004838 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004839 IPW_ERROR("Frag length: %d\n",
4840 le16_to_cpu(x->frag_length));
4841 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004842 IPW_ERROR("Frag length of wrong size %d "
4843 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004844 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004845 break;
4846 }
4847
4848 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4849 struct notif_link_deterioration *x =
4850 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004851
Al Viroe62e1ee2007-12-27 01:36:46 -05004852 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004853 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004854 "link deterioration: type %d, cnt %d\n",
4855 x->silence_notification_type,
4856 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004857 memcpy(&priv->last_link_deterioration, x,
4858 sizeof(*x));
4859 } else {
4860 IPW_ERROR("Link Deterioration of wrong size %d "
4861 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004862 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004863 }
4864 break;
4865 }
4866
4867 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4868 IPW_ERROR("Dino config\n");
4869 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004870 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004871 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004872
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 break;
4874 }
4875
4876 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4877 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004878 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004879 IPW_ERROR
4880 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004881 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004882 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004883 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004884
James Ketrenosa613bff2005-08-24 21:43:11 -05004885 if (le32_to_cpu(x->state) ==
4886 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4887 ipw_handle_missed_beacon(priv,
4888 le32_to_cpu(x->
4889 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004890
James Ketrenos43f66a62005-03-25 12:31:53 -06004891 break;
4892 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004893
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004894 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4895 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004896 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004897 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4898 "0x%02x station %d\n",
4899 x->key_state, x->security_type,
4900 x->station_index);
4901 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004902 }
4903
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004904 IPW_ERROR
4905 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004906 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004907 break;
4908 }
4909
4910 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4911 struct notif_calibration *x = &notif->u.calibration;
4912
Al Viroe62e1ee2007-12-27 01:36:46 -05004913 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004914 memcpy(&priv->calib, x, sizeof(*x));
4915 IPW_DEBUG_INFO("TODO: Calibration\n");
4916 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004917 }
4918
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004919 IPW_ERROR
4920 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004921 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004922 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004923 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004924
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004925 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004926 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004927 priv->exp_avg_noise =
4928 exponential_average(priv->exp_avg_noise,
4929 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4930 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004931 break;
4932 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004933
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004934 IPW_ERROR
4935 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004936 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004937 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004938 }
4939
James Ketrenos43f66a62005-03-25 12:31:53 -06004940 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004941 IPW_DEBUG_NOTIF("Unknown notification: "
4942 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004943 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004944 }
4945}
4946
4947/**
4948 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004949 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004950 * @param priv
4951 * @return error code
4952 */
4953static int ipw_queue_reset(struct ipw_priv *priv)
4954{
4955 int rc = 0;
4956 /** @todo customize queue sizes */
4957 int nTx = 64, nTxCmd = 8;
4958 ipw_tx_queue_free(priv);
4959 /* Tx CMD queue */
4960 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004961 IPW_TX_CMD_QUEUE_READ_INDEX,
4962 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4963 IPW_TX_CMD_QUEUE_BD_BASE,
4964 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004965 if (rc) {
4966 IPW_ERROR("Tx Cmd queue init failed\n");
4967 goto error;
4968 }
4969 /* Tx queue(s) */
4970 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004971 IPW_TX_QUEUE_0_READ_INDEX,
4972 IPW_TX_QUEUE_0_WRITE_INDEX,
4973 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004974 if (rc) {
4975 IPW_ERROR("Tx 0 queue init failed\n");
4976 goto error;
4977 }
4978 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004979 IPW_TX_QUEUE_1_READ_INDEX,
4980 IPW_TX_QUEUE_1_WRITE_INDEX,
4981 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004982 if (rc) {
4983 IPW_ERROR("Tx 1 queue init failed\n");
4984 goto error;
4985 }
4986 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004987 IPW_TX_QUEUE_2_READ_INDEX,
4988 IPW_TX_QUEUE_2_WRITE_INDEX,
4989 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004990 if (rc) {
4991 IPW_ERROR("Tx 2 queue init failed\n");
4992 goto error;
4993 }
4994 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004995 IPW_TX_QUEUE_3_READ_INDEX,
4996 IPW_TX_QUEUE_3_WRITE_INDEX,
4997 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004998 if (rc) {
4999 IPW_ERROR("Tx 3 queue init failed\n");
5000 goto error;
5001 }
5002 /* statistics */
5003 priv->rx_bufs_min = 0;
5004 priv->rx_pend_max = 0;
5005 return rc;
5006
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005007 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005008 ipw_tx_queue_free(priv);
5009 return rc;
5010}
5011
5012/**
5013 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005014 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005015 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005016 * new 'R' index need to be reclaimed. As result, some free space
5017 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005018 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005019 * @note Need to protect against garbage in 'R' index
5020 * @param priv
5021 * @param txq
5022 * @param qindex
5023 * @return Number of used entries remains in the queue
5024 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005025static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005026 struct clx2_tx_queue *txq, int qindex)
5027{
5028 u32 hw_tail;
5029 int used;
5030 struct clx2_queue *q = &txq->q;
5031
5032 hw_tail = ipw_read32(priv, q->reg_r);
5033 if (hw_tail >= q->n_bd) {
5034 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005035 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5036 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005037 goto done;
5038 }
5039 for (; q->last_used != hw_tail;
5040 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5041 ipw_queue_tx_free_tfd(priv, txq);
5042 priv->tx_packets++;
5043 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005044 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005045 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005046 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005047 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 used = q->first_empty - q->last_used;
5049 if (used < 0)
5050 used += q->n_bd;
5051
5052 return used;
5053}
5054
5055static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5056 int len, int sync)
5057{
5058 struct clx2_tx_queue *txq = &priv->txq_cmd;
5059 struct clx2_queue *q = &txq->q;
5060 struct tfd_frame *tfd;
5061
Dan Williams943dbef2008-02-14 17:49:41 -05005062 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 IPW_ERROR("No space for Tx\n");
5064 return -EBUSY;
5065 }
5066
5067 tfd = &txq->bd[q->first_empty];
5068 txq->txb[q->first_empty] = NULL;
5069
5070 memset(tfd, 0, sizeof(*tfd));
5071 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5072 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5073 priv->hcmd_seq++;
5074 tfd->u.cmd.index = hcmd;
5075 tfd->u.cmd.length = len;
5076 memcpy(tfd->u.cmd.payload, buf, len);
5077 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5078 ipw_write32(priv, q->reg_w, q->first_empty);
5079 _ipw_read32(priv, 0x90);
5080
5081 return 0;
5082}
5083
Jeff Garzikbf794512005-07-31 13:07:26 -04005084/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005085 * Rx theory of operation
5086 *
5087 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005088 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005089 * 0 to 31
5090 *
5091 * Rx Queue Indexes
5092 * The host/firmware share two index registers for managing the Rx buffers.
5093 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005094 * The READ index maps to the first position that the firmware may be writing
5095 * to -- the driver can read up to (but not including) this position and get
5096 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005097 * The READ index is managed by the firmware once the card is enabled.
5098 *
5099 * The WRITE index maps to the last position the driver has read from -- the
5100 * position preceding WRITE is the last slot the firmware can place a packet.
5101 *
5102 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005103 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005104 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005105 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005106 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5107 *
5108 * When the firmware places a packet in a buffer it will advance the READ index
5109 * and fire the RX interrupt. The driver can then query the READ index and
5110 * process as many packets as possible, moving the WRITE index forward as it
5111 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005112 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005113 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005114 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005115 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005116 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005117 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5118 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5119 * 'processed' and 'read' driver indexes as well)
5120 * + A received packet is processed and handed to the kernel network stack,
5121 * detached from the ipw->rxq. The driver 'processed' index is updated.
5122 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005123 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5124 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005125 * were enough free buffers and RX_STALLED is set it is cleared.
5126 *
5127 *
5128 * Driver sequence:
5129 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005130 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005131 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5132 * ipw_rx_queue_restock
5133 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5134 * queue, updates firmware pointers, and updates
5135 * the WRITE index. If insufficient rx_free buffers
5136 * are available, schedules ipw_rx_queue_replenish
5137 *
5138 * -- enable interrupts --
5139 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005140 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005141 * Moves the packet buffer from queue to rx_used.
5142 * Calls ipw_rx_queue_restock to refill any empty
5143 * slots.
5144 * ...
5145 *
5146 */
5147
Jeff Garzikbf794512005-07-31 13:07:26 -04005148/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005149 * If there are slots in the RX queue that need to be restocked,
5150 * and we have free pre-allocated buffers, fill the ranks as much
5151 * as we can pulling from rx_free.
5152 *
5153 * This moves the 'write' index forward to catch up with 'processed', and
5154 * also updates the memory address in the firmware to reference the new
5155 * target buffer.
5156 */
5157static void ipw_rx_queue_restock(struct ipw_priv *priv)
5158{
5159 struct ipw_rx_queue *rxq = priv->rxq;
5160 struct list_head *element;
5161 struct ipw_rx_mem_buffer *rxb;
5162 unsigned long flags;
5163 int write;
5164
5165 spin_lock_irqsave(&rxq->lock, flags);
5166 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005167 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005168 element = rxq->rx_free.next;
5169 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5170 list_del(element);
5171
James Ketrenosb095c382005-08-24 22:04:42 -05005172 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005173 rxb->dma_addr);
5174 rxq->queue[rxq->write] = rxb;
5175 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5176 rxq->free_count--;
5177 }
5178 spin_unlock_irqrestore(&rxq->lock, flags);
5179
Jeff Garzikbf794512005-07-31 13:07:26 -04005180 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005181 * refill it */
5182 if (rxq->free_count <= RX_LOW_WATERMARK)
Tejun Heobcb6d912011-01-26 12:12:50 +01005183 schedule_work(&priv->rx_replenish);
James Ketrenos43f66a62005-03-25 12:31:53 -06005184
5185 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005186 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005187 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005188}
5189
5190/*
5191 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005192 * Also restock the Rx queue via ipw_rx_queue_restock.
5193 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005194 * This is called as a scheduled work item (except for during intialization)
5195 */
5196static void ipw_rx_queue_replenish(void *data)
5197{
5198 struct ipw_priv *priv = data;
5199 struct ipw_rx_queue *rxq = priv->rxq;
5200 struct list_head *element;
5201 struct ipw_rx_mem_buffer *rxb;
5202 unsigned long flags;
5203
5204 spin_lock_irqsave(&rxq->lock, flags);
5205 while (!list_empty(&rxq->rx_used)) {
5206 element = rxq->rx_used.next;
5207 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005208 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005209 if (!rxb->skb) {
5210 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5211 priv->net_dev->name);
5212 /* We don't reschedule replenish work here -- we will
5213 * call the restock method and if it still needs
5214 * more buffers it will schedule replenish */
5215 break;
5216 }
5217 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005218
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005219 rxb->dma_addr =
5220 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005221 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005222
James Ketrenos43f66a62005-03-25 12:31:53 -06005223 list_add_tail(&rxb->list, &rxq->rx_free);
5224 rxq->free_count++;
5225 }
5226 spin_unlock_irqrestore(&rxq->lock, flags);
5227
5228 ipw_rx_queue_restock(priv);
5229}
5230
David Howellsc4028952006-11-22 14:57:56 +00005231static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005232{
David Howellsc4028952006-11-22 14:57:56 +00005233 struct ipw_priv *priv =
5234 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005235 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005236 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005237 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005238}
5239
James Ketrenos43f66a62005-03-25 12:31:53 -06005240/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005241 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005242 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005243 * non NULL it is unmapped and freed
5244 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005245static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005246{
5247 int i;
5248
5249 if (!rxq)
5250 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005251
James Ketrenos43f66a62005-03-25 12:31:53 -06005252 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5253 if (rxq->pool[i].skb != NULL) {
5254 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005255 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005256 dev_kfree_skb(rxq->pool[i].skb);
5257 }
5258 }
5259
5260 kfree(rxq);
5261}
5262
5263static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5264{
5265 struct ipw_rx_queue *rxq;
5266 int i;
5267
Takisc75f4742005-12-01 01:41:45 -08005268 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005269 if (unlikely(!rxq)) {
5270 IPW_ERROR("memory allocation failed\n");
5271 return NULL;
5272 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005273 spin_lock_init(&rxq->lock);
5274 INIT_LIST_HEAD(&rxq->rx_free);
5275 INIT_LIST_HEAD(&rxq->rx_used);
5276
5277 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005278 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005279 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5280
5281 /* Set us so that we have processed and used all buffers, but have
5282 * not restocked the Rx queue with fresh buffers */
5283 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005284 rxq->free_count = 0;
5285
5286 return rxq;
5287}
5288
5289static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5290{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005291 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005292 if (ieee_mode == IEEE_A) {
5293 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005294 case LIBIPW_OFDM_RATE_6MB:
5295 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005296 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005297 case LIBIPW_OFDM_RATE_9MB:
5298 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005299 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005300 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005301 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005302 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5303 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005304 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005305 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5306 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005307 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005308 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5309 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005310 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005311 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5312 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005313 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005314 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5315 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005316 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005317 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005318 default:
5319 return 0;
5320 }
5321 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005322
James Ketrenos43f66a62005-03-25 12:31:53 -06005323 /* B and G mixed */
5324 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005325 case LIBIPW_CCK_RATE_1MB:
5326 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5327 case LIBIPW_CCK_RATE_2MB:
5328 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5329 case LIBIPW_CCK_RATE_5MB:
5330 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5331 case LIBIPW_CCK_RATE_11MB:
5332 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005333 }
5334
5335 /* If we are limited to B modulations, bail at this point */
5336 if (ieee_mode == IEEE_B)
5337 return 0;
5338
5339 /* G */
5340 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005341 case LIBIPW_OFDM_RATE_6MB:
5342 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5343 case LIBIPW_OFDM_RATE_9MB:
5344 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5345 case LIBIPW_OFDM_RATE_12MB:
5346 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5347 case LIBIPW_OFDM_RATE_18MB:
5348 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5349 case LIBIPW_OFDM_RATE_24MB:
5350 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5351 case LIBIPW_OFDM_RATE_36MB:
5352 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5353 case LIBIPW_OFDM_RATE_48MB:
5354 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5355 case LIBIPW_OFDM_RATE_54MB:
5356 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005357 }
5358
5359 return 0;
5360}
5361
Jeff Garzikbf794512005-07-31 13:07:26 -04005362static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005363 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005364 struct ipw_supported_rates *rates)
5365{
5366 int num_rates, i;
5367
5368 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005369 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005370 rates->num_rates = 0;
5371 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005372 if (!ipw_is_rate_in_mask(priv, network->mode,
5373 network->rates[i])) {
5374
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005375 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005376 IPW_DEBUG_SCAN("Adding masked mandatory "
5377 "rate %02X\n",
5378 network->rates[i]);
5379 rates->supported_rates[rates->num_rates++] =
5380 network->rates[i];
5381 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005382 }
5383
James Ketrenos43f66a62005-03-25 12:31:53 -06005384 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5385 network->rates[i], priv->rates_mask);
5386 continue;
5387 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005388
James Ketrenos43f66a62005-03-25 12:31:53 -06005389 rates->supported_rates[rates->num_rates++] = network->rates[i];
5390 }
5391
James Ketrenosa613bff2005-08-24 21:43:11 -05005392 num_rates = min(network->rates_ex_len,
5393 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005394 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005395 if (!ipw_is_rate_in_mask(priv, network->mode,
5396 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005397 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005398 IPW_DEBUG_SCAN("Adding masked mandatory "
5399 "rate %02X\n",
5400 network->rates_ex[i]);
5401 rates->supported_rates[rates->num_rates++] =
5402 network->rates[i];
5403 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005404 }
5405
James Ketrenos43f66a62005-03-25 12:31:53 -06005406 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5407 network->rates_ex[i], priv->rates_mask);
5408 continue;
5409 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005410
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005411 rates->supported_rates[rates->num_rates++] =
5412 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005413 }
5414
James Ketrenosea2b26e2005-08-24 21:25:16 -05005415 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005416}
5417
Arjan van de Ven858119e2006-01-14 13:20:43 -08005418static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005419 const struct ipw_supported_rates *src)
5420{
5421 u8 i;
5422 for (i = 0; i < src->num_rates; i++)
5423 dest->supported_rates[i] = src->supported_rates[i];
5424 dest->num_rates = src->num_rates;
5425}
5426
5427/* TODO: Look at sniffed packets in the air to determine if the basic rate
5428 * mask should ever be used -- right now all callers to add the scan rates are
5429 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5430static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005431 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005432{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005433 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5434 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005435
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005436 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005437 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005438 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005439
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005440 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005441 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005442 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005443
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005444 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005446 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005447
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005449 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005450 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005451}
5452
5453static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005454 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005455{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005456 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5457 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005458
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005459 if (rate_mask & LIBIPW_OFDM_RATE_6MB_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_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005462
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005463 if (rate_mask & LIBIPW_OFDM_RATE_9MB_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_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005466
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005467 if (rate_mask & LIBIPW_OFDM_RATE_12MB_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_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005470
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005471 if (rate_mask & LIBIPW_OFDM_RATE_18MB_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_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005474
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005475 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005476 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005477 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005478
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005479 if (rate_mask & LIBIPW_OFDM_RATE_36MB_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_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005482
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005483 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005484 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005485 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005486
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005487 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005488 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005489 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005490}
5491
5492struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005493 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005494 struct ipw_supported_rates rates;
5495};
5496
James Ketrenosc848d0a2005-08-24 21:56:24 -05005497static int ipw_find_adhoc_network(struct ipw_priv *priv,
5498 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005499 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005500 int roaming)
5501{
5502 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005503 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005504
5505 /* Verify that this network's capability is compatible with the
5506 * current mode (AdHoc or Infrastructure) */
5507 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5508 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005509 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005510 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005511 print_ssid(ssid, network->ssid,
5512 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005513 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005514 return 0;
5515 }
5516
James Ketrenosc848d0a2005-08-24 21:56:24 -05005517 if (unlikely(roaming)) {
5518 /* If we are roaming, then ensure check if this is a valid
5519 * network to try and roam to */
5520 if ((network->ssid_len != match->network->ssid_len) ||
5521 memcmp(network->ssid, match->network->ssid,
5522 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005523 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005524 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005525 print_ssid(ssid, network->ssid,
5526 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005527 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005528 return 0;
5529 }
5530 } else {
5531 /* If an ESSID has been configured then compare the broadcast
5532 * ESSID to ours */
5533 if ((priv->config & CFG_STATIC_ESSID) &&
5534 ((network->ssid_len != priv->essid_len) ||
5535 memcmp(network->ssid, priv->essid,
5536 min(network->ssid_len, priv->essid_len)))) {
5537 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005538
James Ketrenosc848d0a2005-08-24 21:56:24 -05005539 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005540 print_ssid(ssid, network->ssid,
5541 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005542 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005543 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005544 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005545 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005546 print_ssid(ssid, priv->essid,
5547 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005548 return 0;
5549 }
5550 }
5551
5552 /* If the old network rate is better than this one, don't bother
5553 * testing everything else. */
5554
5555 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005556 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5557 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005558 print_ssid(ssid, match->network->ssid,
5559 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005560 return 0;
5561 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005562 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5563 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005564 print_ssid(ssid, match->network->ssid,
5565 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005566 return 0;
5567 }
5568
5569 /* Now go through and see if the requested network is valid... */
5570 if (priv->ieee->scan_age != 0 &&
5571 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005572 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005573 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005574 print_ssid(ssid, network->ssid,
5575 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005576 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005577 jiffies_to_msecs(jiffies -
5578 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005579 return 0;
5580 }
5581
5582 if ((priv->config & CFG_STATIC_CHANNEL) &&
5583 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005584 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005585 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005586 print_ssid(ssid, network->ssid,
5587 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005588 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005589 network->channel, priv->channel);
5590 return 0;
5591 }
5592
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005593 /* Verify privacy compatibility */
James Ketrenosc848d0a2005-08-24 21:56:24 -05005594 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5595 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005596 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005597 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005598 print_ssid(ssid, network->ssid,
5599 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005600 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005601 priv->
5602 capability & CAP_PRIVACY_ON ? "on" : "off",
5603 network->
5604 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5605 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005606 return 0;
5607 }
5608
5609 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005610 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5611 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005612 ".\n", print_ssid(ssid, network->ssid,
5613 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005614 network->bssid,
5615 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005616 return 0;
5617 }
5618
5619 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005620 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005621 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005622 "because of invalid frequency/mode "
5623 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005624 print_ssid(ssid, network->ssid,
5625 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005626 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005627 return 0;
5628 }
5629
5630 /* Ensure that the rates supported by the driver are compatible with
5631 * this AP, including verification of basic rates (mandatory) */
5632 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005633 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005634 "because configured rate mask excludes "
5635 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005636 print_ssid(ssid, network->ssid,
5637 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005638 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005639 return 0;
5640 }
5641
5642 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005643 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005644 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005645 print_ssid(ssid, network->ssid,
5646 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005647 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005648 return 0;
5649 }
5650
5651 /* TODO: Perform any further minimal comparititive tests. We do not
5652 * want to put too much policy logic here; intelligent scan selection
5653 * should occur within a generic IEEE 802.11 user space tool. */
5654
5655 /* Set up 'new' AP to this network */
5656 ipw_copy_rates(&match->rates, &rates);
5657 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005658 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005659 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005660 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005661
5662 return 1;
5663}
5664
David Howellsc4028952006-11-22 14:57:56 +00005665static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005666{
John W. Linville9387b7c2008-09-30 20:59:05 -04005667 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005668 struct ipw_priv *priv =
5669 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005670 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005671 struct ipw_network_match match = {
5672 .network = priv->assoc_network
5673 };
5674
James Ketrenosafbf30a2005-08-25 00:05:33 -05005675 if ((priv->status & STATUS_ASSOCIATED) &&
5676 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005677 /* First pass through ROAM process -- look for a better
5678 * network */
5679 unsigned long flags;
5680
5681 spin_lock_irqsave(&priv->ieee->lock, flags);
5682 list_for_each_entry(network, &priv->ieee->network_list, list) {
5683 if (network != priv->assoc_network)
5684 ipw_find_adhoc_network(priv, &match, network,
5685 1);
5686 }
5687 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5688
5689 if (match.network == priv->assoc_network) {
5690 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5691 "merge to.\n");
5692 return;
5693 }
5694
Zhu Yi46441512006-01-24 16:37:59 +08005695 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005696 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5697 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005698 print_ssid(ssid, priv->essid,
5699 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005700 ipw_remove_current_network(priv);
5701 }
5702
5703 ipw_disassociate(priv);
5704 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005705 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005706 return;
5707 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005708}
5709
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005710static int ipw_best_network(struct ipw_priv *priv,
5711 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005712 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005713{
5714 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005715 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005716
5717 /* Verify that this network's capability is compatible with the
5718 * current mode (AdHoc or Infrastructure) */
5719 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005720 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005721 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5722 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005723 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005724 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005725 print_ssid(ssid, network->ssid,
5726 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005727 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005728 return 0;
5729 }
5730
James Ketrenos43f66a62005-03-25 12:31:53 -06005731 if (unlikely(roaming)) {
5732 /* If we are roaming, then ensure check if this is a valid
5733 * network to try and roam to */
5734 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005735 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005736 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005737 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005738 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005739 print_ssid(ssid, network->ssid,
5740 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005741 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005742 return 0;
5743 }
5744 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005745 /* If an ESSID has been configured then compare the broadcast
5746 * ESSID to ours */
5747 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005749 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005750 min(network->ssid_len, priv->essid_len)))) {
5751 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005752 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005753 print_ssid(ssid, network->ssid,
5754 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005755 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005756 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005757 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005758 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005759 print_ssid(ssid, priv->essid,
5760 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005761 return 0;
5762 }
5763 }
5764
5765 /* If the old network rate is better than this one, don't bother
5766 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005767 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005768 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005769 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005770 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005771 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005772 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5773 "'%s (%pM)' has a stronger signal.\n",
5774 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005775 print_ssid(ssid, match->network->ssid,
5776 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005777 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 return 0;
5779 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005780
James Ketrenos43f66a62005-03-25 12:31:53 -06005781 /* If this network has already had an association attempt within the
5782 * last 3 seconds, do not try and associate again... */
5783 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005784 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005785 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005786 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005787 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005788 print_ssid(ssid, network->ssid,
5789 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005790 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005791 jiffies_to_msecs(jiffies -
5792 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 return 0;
5794 }
5795
5796 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005797 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005798 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005799 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005800 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005801 print_ssid(ssid, network->ssid,
5802 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005803 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005804 jiffies_to_msecs(jiffies -
5805 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005806 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005807 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005808
Jeff Garzikbf794512005-07-31 13:07:26 -04005809 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005810 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005811 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005812 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005813 print_ssid(ssid, network->ssid,
5814 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005815 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005816 network->channel, priv->channel);
5817 return 0;
5818 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005819
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005820 /* Verify privacy compatibility */
Jeff Garzikbf794512005-07-31 13:07:26 -04005821 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005823 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005824 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005825 print_ssid(ssid, network->ssid,
5826 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005827 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005828 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005829 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005830 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005831 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 return 0;
5833 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005834
5835 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005836 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005837 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5838 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005839 print_ssid(ssid, network->ssid,
5840 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005841 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005842 return 0;
5843 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005844
James Ketrenos43f66a62005-03-25 12:31:53 -06005845 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005846 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005847 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005848 "because of invalid frequency/mode "
5849 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005850 print_ssid(ssid, network->ssid,
5851 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005852 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005853 return 0;
5854 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005855
Liu Hong1fe0adb2005-08-19 09:33:10 -05005856 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005857 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005858 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005859 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005860 print_ssid(ssid, network->ssid,
5861 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005862 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005863 return 0;
5864 }
5865
James Ketrenosea2b26e2005-08-24 21:25:16 -05005866 /* Ensure that the rates supported by the driver are compatible with
5867 * this AP, including verification of basic rates (mandatory) */
5868 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005869 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005870 "because configured rate mask excludes "
5871 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005872 print_ssid(ssid, network->ssid,
5873 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005874 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005875 return 0;
5876 }
5877
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005879 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005880 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005881 print_ssid(ssid, network->ssid,
5882 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005883 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005884 return 0;
5885 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005886
James Ketrenos43f66a62005-03-25 12:31:53 -06005887 /* TODO: Perform any further minimal comparititive tests. We do not
5888 * want to put too much policy logic here; intelligent scan selection
5889 * should occur within a generic IEEE 802.11 user space tool. */
5890
5891 /* Set up 'new' AP to this network */
5892 ipw_copy_rates(&match->rates, &rates);
5893 match->network = network;
5894
Johannes Berge1749612008-10-27 15:59:26 -07005895 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005896 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005897 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005898
5899 return 1;
5900}
5901
Jeff Garzikbf794512005-07-31 13:07:26 -04005902static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005903 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005904{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005905 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005906 int i;
5907
James Ketrenos43f66a62005-03-25 12:31:53 -06005908 /*
5909 * For the purposes of scanning, we can set our wireless mode
5910 * to trigger scans across combinations of bands, but when it
5911 * comes to creating a new ad-hoc network, we have tell the FW
5912 * exactly which band to use.
5913 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005914 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005915 * chossen band. Attempting to create a new ad-hoc network
5916 * with an invalid channel for wireless mode will trigger a
5917 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005918 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005919 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005920 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5921 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005922 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005923 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005924 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005925 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005926 IPW_WARNING("Overriding invalid channel\n");
5927 priv->channel = geo->a[0].channel;
5928 }
5929 break;
5930
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005931 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005932 if (priv->ieee->mode & IEEE_G)
5933 network->mode = IEEE_G;
5934 else
5935 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005936 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005937 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005938 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005939 IPW_WARNING("Overriding invalid channel\n");
5940 priv->channel = geo->bg[0].channel;
5941 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005942 break;
5943
5944 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005945 IPW_WARNING("Overriding invalid channel\n");
5946 if (priv->ieee->mode & IEEE_A) {
5947 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005948 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005949 } else if (priv->ieee->mode & IEEE_G) {
5950 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005951 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005952 } else {
5953 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005954 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005955 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005956 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005957 }
5958
5959 network->channel = priv->channel;
5960 priv->config |= CFG_ADHOC_PERSIST;
5961 ipw_create_bssid(priv, network->bssid);
5962 network->ssid_len = priv->essid_len;
5963 memcpy(network->ssid, priv->essid, priv->essid_len);
5964 memset(&network->stats, 0, sizeof(network->stats));
5965 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005966 if (!(priv->config & CFG_PREAMBLE_LONG))
5967 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005968 if (priv->capability & CAP_PRIVACY_ON)
5969 network->capability |= WLAN_CAPABILITY_PRIVACY;
5970 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005971 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005972 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005973 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005974 &priv->rates.supported_rates[network->rates_len],
5975 network->rates_ex_len);
5976 network->last_scanned = 0;
5977 network->flags = 0;
5978 network->last_associate = 0;
5979 network->time_stamp[0] = 0;
5980 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005981 network->beacon_interval = 100; /* Default */
5982 network->listen_interval = 10; /* Default */
5983 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005984 network->wpa_ie_len = 0;
5985 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005986}
5987
James Ketrenosb095c382005-08-24 22:04:42 -05005988static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5989{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005990 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005991
5992 if (!(priv->ieee->sec.flags & (1 << index)))
5993 return;
5994
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005995 key.key_id = index;
5996 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5997 key.security_type = type;
5998 key.station_index = 0; /* always 0 for BSS */
5999 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006000 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08006001 key.tx_counter[0] = cpu_to_le32(0);
6002 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05006003
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006004 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05006005}
6006
6007static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06006008{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006009 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006010 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006011
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006012 key.cmd_id = DINO_CMD_WEP_KEY;
6013 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006014
James Ketrenosb095c382005-08-24 22:04:42 -05006015 /* Note: AES keys cannot be set for multiple times.
6016 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006017 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006018 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006019 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006020 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006021 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006022 }
6023
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006024 key.key_size = priv->ieee->sec.key_sizes[i];
6025 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006026
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006027 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006028 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006029}
6030
Zhu Yi1fbfea52005-08-05 17:22:56 +08006031static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6032{
6033 if (priv->ieee->host_encrypt)
6034 return;
6035
6036 switch (level) {
6037 case SEC_LEVEL_3:
6038 priv->sys_config.disable_unicast_decryption = 0;
6039 priv->ieee->host_decrypt = 0;
6040 break;
6041 case SEC_LEVEL_2:
6042 priv->sys_config.disable_unicast_decryption = 1;
6043 priv->ieee->host_decrypt = 1;
6044 break;
6045 case SEC_LEVEL_1:
6046 priv->sys_config.disable_unicast_decryption = 0;
6047 priv->ieee->host_decrypt = 0;
6048 break;
6049 case SEC_LEVEL_0:
6050 priv->sys_config.disable_unicast_decryption = 1;
6051 break;
6052 default:
6053 break;
6054 }
6055}
6056
6057static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6058{
6059 if (priv->ieee->host_encrypt)
6060 return;
6061
6062 switch (level) {
6063 case SEC_LEVEL_3:
6064 priv->sys_config.disable_multicast_decryption = 0;
6065 break;
6066 case SEC_LEVEL_2:
6067 priv->sys_config.disable_multicast_decryption = 1;
6068 break;
6069 case SEC_LEVEL_1:
6070 priv->sys_config.disable_multicast_decryption = 0;
6071 break;
6072 case SEC_LEVEL_0:
6073 priv->sys_config.disable_multicast_decryption = 1;
6074 break;
6075 default:
6076 break;
6077 }
6078}
6079
James Ketrenosb095c382005-08-24 22:04:42 -05006080static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6081{
6082 switch (priv->ieee->sec.level) {
6083 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006084 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6085 ipw_send_tgi_tx_key(priv,
6086 DCT_FLAG_EXT_SECURITY_CCM,
6087 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006088
Hong Liu567deaf2005-08-31 18:07:22 +08006089 if (!priv->ieee->host_mc_decrypt)
6090 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006091 break;
6092 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006093 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6094 ipw_send_tgi_tx_key(priv,
6095 DCT_FLAG_EXT_SECURITY_TKIP,
6096 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006097 break;
6098 case SEC_LEVEL_1:
6099 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006100 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6101 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006102 break;
6103 case SEC_LEVEL_0:
6104 default:
6105 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006106 }
6107}
6108
6109static void ipw_adhoc_check(void *data)
6110{
6111 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006112
James Ketrenosafbf30a2005-08-25 00:05:33 -05006113 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006114 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006115 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6116 IPW_DL_STATE | IPW_DL_ASSOC,
6117 "Missed beacon: %d - disassociate\n",
6118 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006119 ipw_remove_current_network(priv);
6120 ipw_disassociate(priv);
6121 return;
6122 }
6123
Tejun Heobcb6d912011-01-26 12:12:50 +01006124 schedule_delayed_work(&priv->adhoc_check,
6125 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006126}
6127
David Howellsc4028952006-11-22 14:57:56 +00006128static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006129{
David Howellsc4028952006-11-22 14:57:56 +00006130 struct ipw_priv *priv =
6131 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006132 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006133 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006134 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006135}
6136
James Ketrenos43f66a62005-03-25 12:31:53 -06006137static void ipw_debug_config(struct ipw_priv *priv)
6138{
John W. Linville9387b7c2008-09-30 20:59:05 -04006139 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006140 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6141 "[CFG 0x%08X]\n", priv->config);
6142 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006143 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006144 else
6145 IPW_DEBUG_INFO("Channel unlocked.\n");
6146 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006147 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006148 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006149 else
6150 IPW_DEBUG_INFO("ESSID unlocked.\n");
6151 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006152 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006153 else
6154 IPW_DEBUG_INFO("BSSID unlocked.\n");
6155 if (priv->capability & CAP_PRIVACY_ON)
6156 IPW_DEBUG_INFO("PRIVACY on\n");
6157 else
6158 IPW_DEBUG_INFO("PRIVACY off\n");
6159 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6160}
James Ketrenos43f66a62005-03-25 12:31:53 -06006161
Arjan van de Ven858119e2006-01-14 13:20:43 -08006162static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006163{
6164 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006165 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006166 u32 reg;
6167 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006168 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006169
Jeff Garzikbf794512005-07-31 13:07:26 -04006170 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006171 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006172
James Ketrenos43f66a62005-03-25 12:31:53 -06006173 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006174 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006175 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006176 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006177 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006178 IPW_DEBUG_WX
6179 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006180 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006181 break;
6182 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006183
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006184 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006185 break;
6186
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006187 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006188 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006189 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006190 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006191 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006192 IPW_DEBUG_WX
6193 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006194 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006195 }
6196 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006197 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006198
6199 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006200 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6201 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006202 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006203 IPW_DEBUG_WX
6204 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006205 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006206 break;
6207 }
6208
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006209 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6210 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6211 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006212 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006213
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006214 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6215 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6216 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006217 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006218
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006219 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6220 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6221 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006222 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006223
Reinette Chatre21f8a732009-08-18 10:25:05 -07006224 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006225 break;
6226 }
6227
Reinette Chatre21f8a732009-08-18 10:25:05 -07006228 fr.tx_rates = cpu_to_le16(new_tx_rates);
6229
James Ketrenos43f66a62005-03-25 12:31:53 -06006230 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006231 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006232}
6233
James Ketrenosea2b26e2005-08-24 21:25:16 -05006234static void ipw_abort_scan(struct ipw_priv *priv)
6235{
6236 int err;
6237
6238 if (priv->status & STATUS_SCAN_ABORTING) {
6239 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6240 return;
6241 }
6242 priv->status |= STATUS_SCAN_ABORTING;
6243
6244 err = ipw_send_scan_abort(priv);
6245 if (err)
6246 IPW_DEBUG_HC("Request to abort scan failed.\n");
6247}
6248
James Ketrenosafbf30a2005-08-25 00:05:33 -05006249static void ipw_add_scan_channels(struct ipw_priv *priv,
6250 struct ipw_scan_request_ext *scan,
6251 int scan_type)
6252{
6253 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006254 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006255 int i;
6256
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006257 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006258
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006259 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006260 int start = channel_index;
6261 for (i = 0; i < geo->a_channels; i++) {
6262 if ((priv->status & STATUS_ASSOCIATED) &&
6263 geo->a[i].channel == priv->channel)
6264 continue;
6265 channel_index++;
6266 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006267 ipw_set_scan_type(scan, channel_index,
6268 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006269 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006270 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6271 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006272 }
6273
6274 if (start != channel_index) {
6275 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6276 (channel_index - start);
6277 channel_index++;
6278 }
6279 }
6280
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006281 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006282 int start = channel_index;
6283 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006284 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006285 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006286 /* nop out the list */
6287 [0] = 0
6288 };
6289
6290 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006291 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006292 channel =
6293 priv->speed_scan[priv->speed_scan_pos];
6294 if (channel == 0) {
6295 priv->speed_scan_pos = 0;
6296 channel = priv->speed_scan[0];
6297 }
6298 if ((priv->status & STATUS_ASSOCIATED) &&
6299 channel == priv->channel) {
6300 priv->speed_scan_pos++;
6301 continue;
6302 }
6303
6304 /* If this channel has already been
6305 * added in scan, break from loop
6306 * and this will be the first channel
6307 * in the next scan.
6308 */
6309 if (channels[channel - 1] != 0)
6310 break;
6311
6312 channels[channel - 1] = 1;
6313 priv->speed_scan_pos++;
6314 channel_index++;
6315 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006316 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006317 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006318 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006319 geo->bg[index].
6320 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006321 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006322 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6323 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006324 }
6325 } else {
6326 for (i = 0; i < geo->bg_channels; i++) {
6327 if ((priv->status & STATUS_ASSOCIATED) &&
6328 geo->bg[i].channel == priv->channel)
6329 continue;
6330 channel_index++;
6331 scan->channels_list[channel_index] =
6332 geo->bg[i].channel;
6333 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006334 geo->bg[i].
6335 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006336 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006337 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6338 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006339 }
6340 }
6341
6342 if (start != channel_index) {
6343 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6344 (channel_index - start);
6345 }
6346 }
6347}
6348
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006349static int ipw_passive_dwell_time(struct ipw_priv *priv)
6350{
6351 /* staying on passive channels longer than the DTIM interval during a
6352 * scan, while associated, causes the firmware to cancel the scan
6353 * without notification. Hence, don't stay on passive channels longer
6354 * than the beacon interval.
6355 */
6356 if (priv->status & STATUS_ASSOCIATED
6357 && priv->assoc_network->beacon_interval > 10)
6358 return priv->assoc_network->beacon_interval - 10;
6359 else
6360 return 120;
6361}
6362
Dan Williamsea177302008-06-02 17:51:23 -04006363static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006364{
6365 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006366 int err = 0, scan_type;
6367
6368 if (!(priv->status & STATUS_INIT) ||
6369 (priv->status & STATUS_EXIT_PENDING))
6370 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006371
Zhu Yi46441512006-01-24 16:37:59 +08006372 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006373
Dan Williamsea177302008-06-02 17:51:23 -04006374 if (direct && (priv->direct_scan_ssid_len == 0)) {
6375 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6376 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6377 goto done;
6378 }
6379
James Ketrenosea2b26e2005-08-24 21:25:16 -05006380 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006381 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6382 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
James Ketrenosafbf30a2005-08-25 00:05:33 -05006387 if (!(priv->status & STATUS_SCAN_FORCED) &&
6388 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006389 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006390 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6391 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006392 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006393 }
6394
6395 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006396 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6397 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6398 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006399 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006400 }
6401
6402 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006403 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006404
Zhu Yi094c4d22006-08-21 11:39:03 +08006405 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006406 IPW_DEBUG_WX("use passive scanning\n");
6407 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006408 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006409 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006410 ipw_add_scan_channels(priv, &scan, scan_type);
6411 goto send_request;
6412 }
6413
6414 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006415 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006416 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006417 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006418 else
6419 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006420 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006421
James Ketrenosa613bff2005-08-24 21:43:11 -05006422 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006423 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006424
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006425 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6426 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006427 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006428
James Ketrenosb095c382005-08-24 22:04:42 -05006429#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006430 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006431 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006432 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006433
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006434 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6435 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006436 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006437 channel = priv->channel;
6438 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006439
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006440 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006441 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006442 channel = priv->channel;
6443 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006444
James Ketrenosb095c382005-08-24 22:04:42 -05006445 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006446 band = (u8) (IPW_B_MODE << 6) | 1;
6447 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006448 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006449 }
6450
James Ketrenosb095c382005-08-24 22:04:42 -05006451 scan.channels_list[0] = band;
6452 scan.channels_list[1] = channel;
6453 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006454
James Ketrenosb095c382005-08-24 22:04:42 -05006455 /* NOTE: The card will sit on this channel for this time
6456 * period. Scan aborts are timing sensitive and frequently
6457 * result in firmware restarts. As such, it is best to
6458 * set a small dwell_time here and just keep re-issuing
6459 * scans. Otherwise fast channel hopping will not actually
6460 * hop channels.
6461 *
6462 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006463 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006464 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006465 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006466#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006467 /* Honor direct scans first, otherwise if we are roaming make
6468 * this a direct scan for the current network. Finally,
6469 * ensure that every other scan is a fast channel hop scan */
6470 if (direct) {
6471 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6472 priv->direct_scan_ssid_len);
6473 if (err) {
6474 IPW_DEBUG_HC("Attempt to send SSID command "
6475 "failed\n");
6476 goto done;
6477 }
6478
6479 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6480 } else if ((priv->status & STATUS_ROAMING)
6481 || (!(priv->status & STATUS_ASSOCIATED)
6482 && (priv->config & CFG_STATIC_ESSID)
6483 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006484 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6485 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006486 IPW_DEBUG_HC("Attempt to send SSID command "
6487 "failed.\n");
6488 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006489 }
6490
6491 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006492 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006493 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006494
James Ketrenosafbf30a2005-08-25 00:05:33 -05006495 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006496#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006497 }
6498#endif
6499
Zhu Yi094c4d22006-08-21 11:39:03 +08006500send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006501 err = ipw_send_scan_request_ext(priv, &scan);
6502 if (err) {
6503 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006504 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006505 }
6506
6507 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006508 if (direct) {
6509 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6510 priv->direct_scan_ssid_len = 0;
6511 } else
6512 priv->status &= ~STATUS_SCAN_PENDING;
6513
Tejun Heobcb6d912011-01-26 12:12:50 +01006514 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006515done:
Zhu Yi46441512006-01-24 16:37:59 +08006516 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006517 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006518}
6519
David Howellsc4028952006-11-22 14:57:56 +00006520static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006521{
David Howellsc4028952006-11-22 14:57:56 +00006522 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006523 container_of(work, struct ipw_priv, request_passive_scan.work);
6524 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006525}
6526
6527static void ipw_request_scan(struct work_struct *work)
6528{
6529 struct ipw_priv *priv =
6530 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006531 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6532}
6533
6534static void ipw_request_direct_scan(struct work_struct *work)
6535{
6536 struct ipw_priv *priv =
6537 container_of(work, struct ipw_priv, request_direct_scan.work);
6538 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006539}
6540
6541static void ipw_bg_abort_scan(struct work_struct *work)
6542{
6543 struct ipw_priv *priv =
6544 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006545 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006546 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006547 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006548}
6549
James Ketrenosea2b26e2005-08-24 21:25:16 -05006550static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6551{
James Ketrenosb095c382005-08-24 22:04:42 -05006552 /* This is called when wpa_supplicant loads and closes the driver
6553 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006554 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006555 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006556}
6557
James Ketrenosea2b26e2005-08-24 21:25:16 -05006558static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6559{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006560 struct libipw_device *ieee = priv->ieee;
6561 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006562 .flags = SEC_AUTH_MODE,
6563 };
6564 int ret = 0;
6565
James Ketrenosafbf30a2005-08-25 00:05:33 -05006566 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006567 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6568 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006569 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006570 sec.auth_mode = WLAN_AUTH_OPEN;
6571 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006572 } else if (value & IW_AUTH_ALG_LEAP) {
6573 sec.auth_mode = WLAN_AUTH_LEAP;
6574 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006575 } else
6576 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006577
6578 if (ieee->set_security)
6579 ieee->set_security(ieee->dev, &sec);
6580 else
6581 ret = -EOPNOTSUPP;
6582
6583 return ret;
6584}
6585
Adrian Bunka73e22b2006-01-21 01:39:42 +01006586static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6587 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588{
6589 /* make sure WPA is enabled */
6590 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006591}
6592
6593static int ipw_set_rsn_capa(struct ipw_priv *priv,
6594 char *capabilities, int length)
6595{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006596 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6597
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006598 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006599 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006600}
6601
James Ketrenosafbf30a2005-08-25 00:05:33 -05006602/*
6603 * WE-18 support
6604 */
6605
6606/* SIOCSIWGENIE */
6607static int ipw_wx_set_genie(struct net_device *dev,
6608 struct iw_request_info *info,
6609 union iwreq_data *wrqu, char *extra)
6610{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006611 struct ipw_priv *priv = libipw_priv(dev);
6612 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006613 u8 *buf;
6614 int err = 0;
6615
6616 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6617 (wrqu->data.length && extra == NULL))
6618 return -EINVAL;
6619
James Ketrenosafbf30a2005-08-25 00:05:33 -05006620 if (wrqu->data.length) {
Julia Lawalld3e50332010-05-15 23:21:01 +02006621 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006622 if (buf == NULL) {
6623 err = -ENOMEM;
6624 goto out;
6625 }
6626
James Ketrenosafbf30a2005-08-25 00:05:33 -05006627 kfree(ieee->wpa_ie);
6628 ieee->wpa_ie = buf;
6629 ieee->wpa_ie_len = wrqu->data.length;
6630 } else {
6631 kfree(ieee->wpa_ie);
6632 ieee->wpa_ie = NULL;
6633 ieee->wpa_ie_len = 0;
6634 }
6635
6636 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6637 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006638 return err;
6639}
6640
6641/* SIOCGIWGENIE */
6642static int ipw_wx_get_genie(struct net_device *dev,
6643 struct iw_request_info *info,
6644 union iwreq_data *wrqu, char *extra)
6645{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006646 struct ipw_priv *priv = libipw_priv(dev);
6647 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006648 int err = 0;
6649
James Ketrenosafbf30a2005-08-25 00:05:33 -05006650 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6651 wrqu->data.length = 0;
6652 goto out;
6653 }
6654
6655 if (wrqu->data.length < ieee->wpa_ie_len) {
6656 err = -E2BIG;
6657 goto out;
6658 }
6659
6660 wrqu->data.length = ieee->wpa_ie_len;
6661 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6662
6663 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006664 return err;
6665}
6666
Zhu Yi1fbfea52005-08-05 17:22:56 +08006667static int wext_cipher2level(int cipher)
6668{
6669 switch (cipher) {
6670 case IW_AUTH_CIPHER_NONE:
6671 return SEC_LEVEL_0;
6672 case IW_AUTH_CIPHER_WEP40:
6673 case IW_AUTH_CIPHER_WEP104:
6674 return SEC_LEVEL_1;
6675 case IW_AUTH_CIPHER_TKIP:
6676 return SEC_LEVEL_2;
6677 case IW_AUTH_CIPHER_CCMP:
6678 return SEC_LEVEL_3;
6679 default:
6680 return -1;
6681 }
6682}
6683
James Ketrenosafbf30a2005-08-25 00:05:33 -05006684/* SIOCSIWAUTH */
6685static int ipw_wx_set_auth(struct net_device *dev,
6686 struct iw_request_info *info,
6687 union iwreq_data *wrqu, char *extra)
6688{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006689 struct ipw_priv *priv = libipw_priv(dev);
6690 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006692 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006693 unsigned long flags;
6694 int ret = 0;
6695
6696 switch (param->flags & IW_AUTH_INDEX) {
6697 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006698 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006699 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006700 ipw_set_hw_decrypt_unicast(priv,
6701 wext_cipher2level(param->value));
6702 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006703 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006704 ipw_set_hw_decrypt_multicast(priv,
6705 wext_cipher2level(param->value));
6706 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006707 case IW_AUTH_KEY_MGMT:
6708 /*
6709 * ipw2200 does not use these parameters
6710 */
6711 break;
6712
6713 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006714 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006715 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006716 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006717
6718 flags = crypt->ops->get_flags(crypt->priv);
6719
6720 if (param->value)
6721 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6722 else
6723 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6724
6725 crypt->ops->set_flags(flags, crypt->priv);
6726
6727 break;
6728
6729 case IW_AUTH_DROP_UNENCRYPTED:{
6730 /* HACK:
6731 *
6732 * wpa_supplicant calls set_wpa_enabled when the driver
6733 * is loaded and unloaded, regardless of if WPA is being
6734 * used. No other calls are made which can be used to
6735 * determine if encryption will be used or not prior to
6736 * association being expected. If encryption is not being
6737 * used, drop_unencrypted is set to false, else true -- we
6738 * can use this to determine if the CAP_PRIVACY_ON bit should
6739 * be set.
6740 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006741 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006742 .flags = SEC_ENABLED,
6743 .enabled = param->value,
6744 };
6745 priv->ieee->drop_unencrypted = param->value;
6746 /* We only change SEC_LEVEL for open mode. Others
6747 * are set by ipw_wpa_set_encryption.
6748 */
6749 if (!param->value) {
6750 sec.flags |= SEC_LEVEL;
6751 sec.level = SEC_LEVEL_0;
6752 } else {
6753 sec.flags |= SEC_LEVEL;
6754 sec.level = SEC_LEVEL_1;
6755 }
6756 if (priv->ieee->set_security)
6757 priv->ieee->set_security(priv->ieee->dev, &sec);
6758 break;
6759 }
6760
6761 case IW_AUTH_80211_AUTH_ALG:
6762 ret = ipw_wpa_set_auth_algs(priv, param->value);
6763 break;
6764
6765 case IW_AUTH_WPA_ENABLED:
6766 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006767 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006768 break;
6769
6770 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6771 ieee->ieee802_1x = param->value;
6772 break;
6773
James Ketrenosafbf30a2005-08-25 00:05:33 -05006774 case IW_AUTH_PRIVACY_INVOKED:
6775 ieee->privacy_invoked = param->value;
6776 break;
6777
6778 default:
6779 return -EOPNOTSUPP;
6780 }
6781 return ret;
6782}
6783
6784/* SIOCGIWAUTH */
6785static int ipw_wx_get_auth(struct net_device *dev,
6786 struct iw_request_info *info,
6787 union iwreq_data *wrqu, char *extra)
6788{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006789 struct ipw_priv *priv = libipw_priv(dev);
6790 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006791 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006792 struct iw_param *param = &wrqu->param;
6793 int ret = 0;
6794
6795 switch (param->flags & IW_AUTH_INDEX) {
6796 case IW_AUTH_WPA_VERSION:
6797 case IW_AUTH_CIPHER_PAIRWISE:
6798 case IW_AUTH_CIPHER_GROUP:
6799 case IW_AUTH_KEY_MGMT:
6800 /*
6801 * wpa_supplicant will control these internally
6802 */
6803 ret = -EOPNOTSUPP;
6804 break;
6805
6806 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006807 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006808 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006809 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006810
6811 param->value = (crypt->ops->get_flags(crypt->priv) &
6812 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6813
6814 break;
6815
6816 case IW_AUTH_DROP_UNENCRYPTED:
6817 param->value = ieee->drop_unencrypted;
6818 break;
6819
6820 case IW_AUTH_80211_AUTH_ALG:
6821 param->value = ieee->sec.auth_mode;
6822 break;
6823
6824 case IW_AUTH_WPA_ENABLED:
6825 param->value = ieee->wpa_enabled;
6826 break;
6827
6828 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6829 param->value = ieee->ieee802_1x;
6830 break;
6831
6832 case IW_AUTH_ROAMING_CONTROL:
6833 case IW_AUTH_PRIVACY_INVOKED:
6834 param->value = ieee->privacy_invoked;
6835 break;
6836
6837 default:
6838 return -EOPNOTSUPP;
6839 }
6840 return 0;
6841}
6842
6843/* SIOCSIWENCODEEXT */
6844static int ipw_wx_set_encodeext(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6847{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006848 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006849 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6850
6851 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006852 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006853 /* IPW HW can't build TKIP MIC,
6854 host decryption still needed */
6855 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6856 priv->ieee->host_mc_decrypt = 1;
6857 else {
6858 priv->ieee->host_encrypt = 0;
6859 priv->ieee->host_encrypt_msdu = 1;
6860 priv->ieee->host_decrypt = 1;
6861 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006862 } else {
6863 priv->ieee->host_encrypt = 0;
6864 priv->ieee->host_encrypt_msdu = 0;
6865 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006866 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006867 }
6868 }
6869
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006870 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006871}
6872
6873/* SIOCGIWENCODEEXT */
6874static int ipw_wx_get_encodeext(struct net_device *dev,
6875 struct iw_request_info *info,
6876 union iwreq_data *wrqu, char *extra)
6877{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006878 struct ipw_priv *priv = libipw_priv(dev);
6879 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006880}
6881
6882/* SIOCSIWMLME */
6883static int ipw_wx_set_mlme(struct net_device *dev,
6884 struct iw_request_info *info,
6885 union iwreq_data *wrqu, char *extra)
6886{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006887 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006888 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006889 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006890
6891 reason = cpu_to_le16(mlme->reason_code);
6892
6893 switch (mlme->cmd) {
6894 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006895 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006896 break;
6897
6898 case IW_MLME_DISASSOC:
6899 ipw_disassociate(priv);
6900 break;
6901
6902 default:
6903 return -EOPNOTSUPP;
6904 }
6905 return 0;
6906}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006907
Zhu Yie43e3c12006-04-13 17:20:45 +08006908#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006909
6910/* QoS */
6911/*
6912* get the modulation type of the current network or
6913* the card current mode
6914*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006915static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006916{
6917 u8 mode = 0;
6918
6919 if (priv->status & STATUS_ASSOCIATED) {
6920 unsigned long flags;
6921
6922 spin_lock_irqsave(&priv->ieee->lock, flags);
6923 mode = priv->assoc_network->mode;
6924 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6925 } else {
6926 mode = priv->ieee->mode;
6927 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006928 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006929 return mode;
6930}
6931
6932/*
6933* Handle management frame beacon and probe response
6934*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006935static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6936 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006937 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006938{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006939 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006940
James Ketrenosafbf30a2005-08-25 00:05:33 -05006941 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006942 network->qos_data.active = network->qos_data.supported;
6943
6944 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006945 if (active_network &&
6946 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006947 network->qos_data.active = network->qos_data.supported;
6948
6949 if ((network->qos_data.active == 1) && (active_network == 1) &&
6950 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6951 (network->qos_data.old_param_count !=
6952 network->qos_data.param_count)) {
6953 network->qos_data.old_param_count =
6954 network->qos_data.param_count;
6955 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006956 IPW_DEBUG_QOS("QoS parameters change call "
6957 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006958 }
6959 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006960 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6961 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006962 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006963 else
6964 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006965 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006966
James Ketrenosb095c382005-08-24 22:04:42 -05006967 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006968 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006969 schedule_work(&priv->qos_activate);
6970 }
6971
6972 network->qos_data.active = 0;
6973 network->qos_data.supported = 0;
6974 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006975 if ((priv->status & STATUS_ASSOCIATED) &&
6976 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6977 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006978 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006979 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006980 priv->assoc_network->ssid_len) &&
6981 !memcmp(network->ssid,
6982 priv->assoc_network->ssid,
6983 network->ssid_len)) {
Tejun Heobcb6d912011-01-26 12:12:50 +01006984 schedule_work(&priv->merge_networks);
James Ketrenosb095c382005-08-24 22:04:42 -05006985 }
James Ketrenosb095c382005-08-24 22:04:42 -05006986 }
6987
6988 return 0;
6989}
6990
6991/*
6992* This function set up the firmware to support QoS. It sends
6993* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6994*/
6995static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006996 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006997{
6998 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006999 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
7000 struct libipw_qos_parameters *active_one = NULL;
7001 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007002 u32 burst_duration;
7003 int i;
7004 u8 type;
7005
7006 type = ipw_qos_current_mode(priv);
7007
7008 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7009 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7010 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7011 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7012
7013 if (qos_network_data == NULL) {
7014 if (type == IEEE_B) {
7015 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7016 active_one = &def_parameters_CCK;
7017 } else
7018 active_one = &def_parameters_OFDM;
7019
James Ketrenosafbf30a2005-08-25 00:05:33 -05007020 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007021 burst_duration = ipw_qos_get_burst_duration(priv);
7022 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007023 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007024 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007025 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007026 if (type == IEEE_B) {
7027 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7028 type);
7029 if (priv->qos_data.qos_enable == 0)
7030 active_one = &def_parameters_CCK;
7031 else
7032 active_one = priv->qos_data.def_qos_parm_CCK;
7033 } else {
7034 if (priv->qos_data.qos_enable == 0)
7035 active_one = &def_parameters_OFDM;
7036 else
7037 active_one = priv->qos_data.def_qos_parm_OFDM;
7038 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007039 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007040 } else {
7041 unsigned long flags;
7042 int active;
7043
7044 spin_lock_irqsave(&priv->ieee->lock, flags);
7045 active_one = &(qos_network_data->parameters);
7046 qos_network_data->old_param_count =
7047 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007048 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007049 active = qos_network_data->supported;
7050 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7051
7052 if (active == 0) {
7053 burst_duration = ipw_qos_get_burst_duration(priv);
7054 for (i = 0; i < QOS_QUEUE_NUM; i++)
7055 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007056 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007057 }
7058 }
7059
7060 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007061 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007062 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007063 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007064 if (err)
7065 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7066
7067 return err;
7068}
7069
7070/*
7071* send IPW_CMD_WME_INFO to the firmware
7072*/
7073static int ipw_qos_set_info_element(struct ipw_priv *priv)
7074{
7075 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007076 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007077
7078 if (priv == NULL)
7079 return -1;
7080
7081 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007082 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007083
7084 qos_info.version = QOS_VERSION_1;
7085 qos_info.ac_info = 0;
7086
7087 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7088 qos_info.qui_type = QOS_OUI_TYPE;
7089 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7090
7091 ret = ipw_send_qos_info_command(priv, &qos_info);
7092 if (ret != 0) {
7093 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7094 }
7095 return ret;
7096}
7097
7098/*
7099* Set the QoS parameter with the association request structure
7100*/
7101static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007102 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007103{
7104 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007105 struct libipw_qos_data *qos_data = NULL;
7106 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007107 .supported = 1,
7108 .active = 1,
7109 };
7110
7111 switch (priv->ieee->iw_mode) {
7112 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007113 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007114
7115 qos_data = &ibss_data;
7116 break;
7117
7118 case IW_MODE_INFRA:
7119 qos_data = &network->qos_data;
7120 break;
7121
7122 default:
7123 BUG();
7124 break;
7125 }
7126
7127 err = ipw_qos_activate(priv, qos_data);
7128 if (err) {
7129 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7130 return err;
7131 }
7132
7133 if (priv->qos_data.qos_enable && qos_data->supported) {
7134 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7135 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7136 return ipw_qos_set_info_element(priv);
7137 }
7138
7139 return 0;
7140}
7141
7142/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007143* handling the beaconing responses. if we get different QoS setting
7144* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007145* setting
7146*/
7147static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007148 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007149{
7150 int ret = 0;
7151 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007152 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007153 int set_qos_param = 0;
7154
James Ketrenosafbf30a2005-08-25 00:05:33 -05007155 if ((priv == NULL) || (network == NULL) ||
7156 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007157 return ret;
7158
7159 if (!(priv->status & STATUS_ASSOCIATED))
7160 return ret;
7161
James Ketrenosafbf30a2005-08-25 00:05:33 -05007162 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007163 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007164
7165 spin_lock_irqsave(&priv->ieee->lock, flags);
7166 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007167 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007168 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007169 priv->assoc_network->qos_data.active = 1;
7170 if ((network->qos_data.old_param_count !=
7171 network->qos_data.param_count)) {
7172 set_qos_param = 1;
7173 network->qos_data.old_param_count =
7174 network->qos_data.param_count;
7175 }
7176
7177 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007178 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7179 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007180 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007181 else
7182 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007183 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007184 priv->assoc_network->qos_data.active = 0;
7185 priv->assoc_network->qos_data.supported = 0;
7186 set_qos_param = 1;
7187 }
7188
7189 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7190
7191 if (set_qos_param == 1)
7192 schedule_work(&priv->qos_activate);
7193
7194 return ret;
7195}
7196
7197static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7198{
7199 u32 ret = 0;
7200
7201 if ((priv == NULL))
7202 return 0;
7203
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007204 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007205 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007206 else
James Ketrenosb095c382005-08-24 22:04:42 -05007207 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007208
James Ketrenosb095c382005-08-24 22:04:42 -05007209 return ret;
7210}
7211
7212/*
7213* Initialize the setting of QoS global
7214*/
7215static void ipw_qos_init(struct ipw_priv *priv, int enable,
7216 int burst_enable, u32 burst_duration_CCK,
7217 u32 burst_duration_OFDM)
7218{
7219 priv->qos_data.qos_enable = enable;
7220
7221 if (priv->qos_data.qos_enable) {
7222 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7223 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7224 IPW_DEBUG_QOS("QoS is enabled\n");
7225 } else {
7226 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7227 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7228 IPW_DEBUG_QOS("QoS is not enabled\n");
7229 }
7230
7231 priv->qos_data.burst_enable = burst_enable;
7232
7233 if (burst_enable) {
7234 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7235 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7236 } else {
7237 priv->qos_data.burst_duration_CCK = 0;
7238 priv->qos_data.burst_duration_OFDM = 0;
7239 }
7240}
7241
7242/*
7243* map the packet priority to the right TX Queue
7244*/
7245static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7246{
7247 if (priority > 7 || !priv->qos_data.qos_enable)
7248 priority = 0;
7249
7250 return from_priority_to_tx_queue[priority] - 1;
7251}
7252
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007253static int ipw_is_qos_active(struct net_device *dev,
7254 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007255{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007256 struct ipw_priv *priv = libipw_priv(dev);
7257 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007258 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007259 u8 *daddr = skb->data + ETH_ALEN;
7260 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007261
7262 if (!(priv->status & STATUS_ASSOCIATED))
7263 return 0;
7264
7265 qos_data = &priv->assoc_network->qos_data;
7266
James Ketrenosb095c382005-08-24 22:04:42 -05007267 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7268 if (unicast == 0)
7269 qos_data->active = 0;
7270 else
7271 qos_data->active = qos_data->supported;
7272 }
James Ketrenosb095c382005-08-24 22:04:42 -05007273 active = qos_data->active;
7274 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007275 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7276 "unicast %d\n",
7277 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007278 if (active && priv->qos_data.qos_enable)
7279 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007280
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007281 return 0;
7282
7283}
7284/*
7285* add QoS parameter to the TX command
7286*/
7287static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7288 u16 priority,
7289 struct tfd_data *tfd)
7290{
7291 int tx_queue_id = 0;
7292
7293
7294 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7295 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7296
7297 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7298 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007299 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007300 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007301 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007302}
7303
7304/*
7305* background support to run QoS activate functionality
7306*/
David Howellsc4028952006-11-22 14:57:56 +00007307static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007308{
David Howellsc4028952006-11-22 14:57:56 +00007309 struct ipw_priv *priv =
7310 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007311
Zhu Yi46441512006-01-24 16:37:59 +08007312 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007313
7314 if (priv->status & STATUS_ASSOCIATED)
7315 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7316
Zhu Yi46441512006-01-24 16:37:59 +08007317 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007318}
7319
James Ketrenos3b9990c2005-08-19 13:18:55 -05007320static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007321 struct libipw_probe_response *resp,
7322 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007323{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007324 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007325 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7326 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007327
James Ketrenos3b9990c2005-08-19 13:18:55 -05007328 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007329
James Ketrenos3b9990c2005-08-19 13:18:55 -05007330 return 0;
7331}
James Ketrenosb095c382005-08-24 22:04:42 -05007332
James Ketrenos3b9990c2005-08-19 13:18:55 -05007333static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007334 struct libipw_beacon *resp,
7335 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007336{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007337 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007338 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7339 (network == priv->assoc_network));
7340
7341 ipw_qos_handle_probe_response(priv, active_network, network);
7342
7343 return 0;
7344}
7345
7346static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007347 struct libipw_assoc_response *resp,
7348 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007349{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007350 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007351 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007352 return 0;
7353}
7354
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007355static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007356 *qos_param)
7357{
Zhu Yi4e226992006-01-24 16:37:36 +08007358 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7359 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007360}
7361
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007362static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007363 *qos_param)
7364{
Zhu Yi4e226992006-01-24 16:37:36 +08007365 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7366 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007367}
7368
Zhu Yie43e3c12006-04-13 17:20:45 +08007369#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007370
James Ketrenos43f66a62005-03-25 12:31:53 -06007371static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007372 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007373 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007374{
7375 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007376 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007377
7378 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007379 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007380
7381 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007382 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007383 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007384 memcpy(priv->essid, network->ssid, priv->essid_len);
7385 }
7386
7387 network->last_associate = jiffies;
7388
7389 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7390 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007391 priv->assoc_request.auth_key = 0;
7392
James Ketrenos43f66a62005-03-25 12:31:53 -06007393 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007394 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007395 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007396 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7397
Zhu Yi1ba61e02006-02-15 13:00:55 +08007398 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007399 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007400
7401 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7402 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7403 priv->assoc_request.auth_type = AUTH_LEAP;
7404 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007405 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007406
James Ketrenosa613bff2005-08-24 21:43:11 -05007407 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007408 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007409 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7410 priv->ieee->wpa_ie_len);
7411 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007412
Jeff Garzikbf794512005-07-31 13:07:26 -04007413 /*
7414 * It is valid for our ieee device to support multiple modes, but
7415 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007416 * just one mode.
7417 */
7418 if (network->mode & priv->ieee->mode & IEEE_A)
7419 priv->assoc_request.ieee_mode = IPW_A_MODE;
7420 else if (network->mode & priv->ieee->mode & IEEE_G)
7421 priv->assoc_request.ieee_mode = IPW_G_MODE;
7422 else if (network->mode & priv->ieee->mode & IEEE_B)
7423 priv->assoc_request.ieee_mode = IPW_B_MODE;
7424
Al Viro5b5e8072007-12-27 01:54:06 -05007425 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007426 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7427 && !(priv->config & CFG_PREAMBLE_LONG)) {
7428 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7429 } else {
7430 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7431
7432 /* Clear the short preamble if we won't be supporting it */
7433 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007434 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007435 }
7436
James Ketrenosafbf30a2005-08-25 00:05:33 -05007437 /* Clear capability bits that aren't used in Ad Hoc */
7438 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7439 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007440 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007441
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02007442 IPW_DEBUG_ASSOC("%ssociation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007443 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007444 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007445 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007446 network->channel,
7447 ipw_modes[priv->assoc_request.ieee_mode],
7448 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007449 (priv->assoc_request.preamble_length ==
7450 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7451 network->capability &
7452 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007453 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007454 priv->capability & CAP_PRIVACY_ON ?
7455 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007456 "(open)") : "",
7457 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007458 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007459 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007460 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007461
Al Viro5b5e8072007-12-27 01:54:06 -05007462 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007463 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007464 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007465 priv->assoc_request.assoc_type = HC_IBSS_START;
7466 priv->assoc_request.assoc_tsf_msw = 0;
7467 priv->assoc_request.assoc_tsf_lsw = 0;
7468 } else {
7469 if (unlikely(roaming))
7470 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7471 else
7472 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007473 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7474 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007475 }
7476
James Ketrenosafbf30a2005-08-25 00:05:33 -05007477 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007478
7479 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7480 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007481 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007482 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007483 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007484 priv->assoc_request.atim_window = 0;
7485 }
7486
Al Viro5b5e8072007-12-27 01:54:06 -05007487 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007488
James Ketrenos43f66a62005-03-25 12:31:53 -06007489 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7490 if (err) {
7491 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7492 return err;
7493 }
7494
7495 rates->ieee_mode = priv->assoc_request.ieee_mode;
7496 rates->purpose = IPW_RATE_CONNECT;
7497 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007498
James Ketrenos43f66a62005-03-25 12:31:53 -06007499 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7500 priv->sys_config.dot11g_auto_detection = 1;
7501 else
7502 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007503
7504 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7505 priv->sys_config.answer_broadcast_ssid_probe = 1;
7506 else
7507 priv->sys_config.answer_broadcast_ssid_probe = 0;
7508
Zhu Yid685b8c2006-04-13 17:20:27 +08007509 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007510 if (err) {
7511 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7512 return err;
7513 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007514
James Ketrenos43f66a62005-03-25 12:31:53 -06007515 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007516 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007517 if (err) {
7518 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7519 return err;
7520 }
7521
7522 /*
7523 * If preemption is enabled, it is possible for the association
7524 * to complete before we return from ipw_send_associate. Therefore
7525 * we have to be sure and update our priviate data first.
7526 */
7527 priv->channel = network->channel;
7528 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007529 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007530 priv->status &= ~STATUS_SECURITY_UPDATED;
7531
7532 priv->assoc_network = network;
7533
Zhu Yie43e3c12006-04-13 17:20:45 +08007534#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007535 ipw_qos_association(priv, network);
7536#endif
7537
James Ketrenos43f66a62005-03-25 12:31:53 -06007538 err = ipw_send_associate(priv, &priv->assoc_request);
7539 if (err) {
7540 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7541 return err;
7542 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007543
Frans Pop9fd1ea42010-03-24 19:46:31 +01007544 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007545 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007546 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007547
7548 return 0;
7549}
7550
7551static void ipw_roam(void *data)
7552{
7553 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007554 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007555 struct ipw_network_match match = {
7556 .network = priv->assoc_network
7557 };
7558
7559 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007560 *
7561 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007562 * setting the status ROAM bit and requesting a scan.
7563 * 2. When the scan completes, it schedules the ROAM work
7564 * 3. The ROAM work looks at all of the known networks for one that
7565 * is a better network than the currently associated. If none
7566 * found, the ROAM process is over (ROAM bit cleared)
7567 * 4. If a better network is found, a disassociation request is
7568 * sent.
7569 * 5. When the disassociation completes, the roam work is again
7570 * scheduled. The second time through, the driver is no longer
7571 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007572 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007573 * 6. At this point ,the roaming process is complete and the ROAM
7574 * status bit is cleared.
7575 */
7576
7577 /* If we are no longer associated, and the roaming bit is no longer
7578 * set, then we are not actively roaming, so just return */
7579 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7580 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007581
James Ketrenos43f66a62005-03-25 12:31:53 -06007582 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007583 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007584 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007585 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007586 u8 rssi = priv->assoc_network->stats.rssi;
7587 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007588 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007589 list_for_each_entry(network, &priv->ieee->network_list, list) {
7590 if (network != priv->assoc_network)
7591 ipw_best_network(priv, &match, network, 1);
7592 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007593 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007594 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007595
James Ketrenos43f66a62005-03-25 12:31:53 -06007596 if (match.network == priv->assoc_network) {
7597 IPW_DEBUG_ASSOC("No better APs in this network to "
7598 "roam to.\n");
7599 priv->status &= ~STATUS_ROAMING;
7600 ipw_debug_config(priv);
7601 return;
7602 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007603
James Ketrenos43f66a62005-03-25 12:31:53 -06007604 ipw_send_disassociate(priv, 1);
7605 priv->assoc_network = match.network;
7606
7607 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007608 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007609
7610 /* Second pass through ROAM process -- request association */
7611 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7612 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7613 priv->status &= ~STATUS_ROAMING;
7614}
7615
David Howellsc4028952006-11-22 14:57:56 +00007616static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007617{
David Howellsc4028952006-11-22 14:57:56 +00007618 struct ipw_priv *priv =
7619 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007620 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007621 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007622 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007623}
7624
7625static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007626{
7627 struct ipw_priv *priv = data;
7628
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007629 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007630 struct ipw_network_match match = {
7631 .network = NULL
7632 };
7633 struct ipw_supported_rates *rates;
7634 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007635 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007636 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007637
James Ketrenosb095c382005-08-24 22:04:42 -05007638 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7639 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7640 return 0;
7641 }
7642
James Ketrenosc848d0a2005-08-24 21:56:24 -05007643 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007644 IPW_DEBUG_ASSOC("Not attempting association (already in "
7645 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007646 return 0;
7647 }
7648
Hong Liue6324722005-09-14 21:04:15 -05007649 if (priv->status & STATUS_DISASSOCIATING) {
7650 IPW_DEBUG_ASSOC("Not attempting association (in "
7651 "disassociating)\n ");
Tejun Heobcb6d912011-01-26 12:12:50 +01007652 schedule_work(&priv->associate);
Hong Liue6324722005-09-14 21:04:15 -05007653 return 0;
7654 }
7655
James Ketrenosc848d0a2005-08-24 21:56:24 -05007656 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007657 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7658 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007659 return 0;
7660 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007661
7662 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007663 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007664 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007665 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007666 }
7667
James Ketrenosa613bff2005-08-24 21:43:11 -05007668 /* Protect our use of the network_list */
7669 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007670 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007671 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007672
7673 network = match.network;
7674 rates = &match.rates;
7675
7676 if (network == NULL &&
7677 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7678 priv->config & CFG_ADHOC_CREATE &&
7679 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007680 priv->config & CFG_STATIC_CHANNEL) {
7681 /* Use oldest network if the free list is empty */
7682 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007683 struct libipw_network *oldest = NULL;
7684 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007685
7686 list_for_each_entry(target, &priv->ieee->network_list, list) {
7687 if ((oldest == NULL) ||
7688 (target->last_scanned < oldest->last_scanned))
7689 oldest = target;
7690 }
7691
7692 /* If there are no more slots, expire the oldest */
7693 list_del(&oldest->list);
7694 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007695 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007696 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007697 print_ssid(ssid, target->ssid,
7698 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007699 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007700 list_add_tail(&target->list,
7701 &priv->ieee->network_free_list);
7702 }
7703
James Ketrenos43f66a62005-03-25 12:31:53 -06007704 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007705 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007706 ipw_adhoc_create(priv, network);
7707 rates = &priv->rates;
7708 list_del(element);
7709 list_add_tail(&network->list, &priv->ieee->network_list);
7710 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007711 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007712
James Ketrenos43f66a62005-03-25 12:31:53 -06007713 /* If we reached the end of the list, then we don't have any valid
7714 * matching APs */
7715 if (!network) {
7716 ipw_debug_config(priv);
7717
James Ketrenosb095c382005-08-24 22:04:42 -05007718 if (!(priv->status & STATUS_SCANNING)) {
7719 if (!(priv->config & CFG_SPEED_SCAN))
Tejun Heobcb6d912011-01-26 12:12:50 +01007720 schedule_delayed_work(&priv->request_scan,
7721 SCAN_INTERVAL);
James Ketrenosb095c382005-08-24 22:04:42 -05007722 else
Tejun Heobcb6d912011-01-26 12:12:50 +01007723 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007724 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007725
James Ketrenosc848d0a2005-08-24 21:56:24 -05007726 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007727 }
7728
7729 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007730
7731 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007732}
Jeff Garzikbf794512005-07-31 13:07:26 -04007733
David Howellsc4028952006-11-22 14:57:56 +00007734static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007735{
David Howellsc4028952006-11-22 14:57:56 +00007736 struct ipw_priv *priv =
7737 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007738 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007739 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007740 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007741}
7742
James Ketrenosb095c382005-08-24 22:04:42 -05007743static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7744 struct sk_buff *skb)
7745{
7746 struct ieee80211_hdr *hdr;
7747 u16 fc;
7748
7749 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007750 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007751 if (!(fc & IEEE80211_FCTL_PROTECTED))
7752 return;
7753
7754 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007755 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007756 switch (priv->ieee->sec.level) {
7757 case SEC_LEVEL_3:
7758 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007759 memmove(skb->data + LIBIPW_3ADDR_LEN,
7760 skb->data + LIBIPW_3ADDR_LEN + 8,
7761 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007762 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007763 break;
7764 case SEC_LEVEL_2:
7765 break;
7766 case SEC_LEVEL_1:
7767 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007768 memmove(skb->data + LIBIPW_3ADDR_LEN,
7769 skb->data + LIBIPW_3ADDR_LEN + 4,
7770 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007771 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007772 break;
7773 case SEC_LEVEL_0:
7774 break;
7775 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007776 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007777 priv->ieee->sec.level);
7778 break;
7779 }
7780}
7781
7782static void ipw_handle_data_packet(struct ipw_priv *priv,
7783 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007784 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007785{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007786 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007787 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007788 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7789
7790 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007791 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007792
Jeff Garzikbf794512005-07-31 13:07:26 -04007793 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007794 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007795 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007796 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007797 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007798 priv->wstats.discard.misc++;
7799 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7800 return;
7801 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007802 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007803 priv->wstats.discard.misc++;
7804 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7805 return;
7806 }
7807
7808 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007809 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007810
7811 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007812 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007813
7814 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7815
James Ketrenosb095c382005-08-24 22:04:42 -05007816 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007817 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007818 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007819 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007820 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007821 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7822
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007823 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007824 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007825 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007826 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007827 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007828 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007829}
7830
Zhu Yi459d4082006-04-13 17:21:00 +08007831#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007832static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7833 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007834 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007835{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007836 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007837 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7838 struct ipw_rx_frame *frame = &pkt->u.frame;
7839
7840 /* initial pull of some data */
7841 u16 received_channel = frame->received_channel;
7842 u8 antennaAndPhy = frame->antennaAndPhy;
7843 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7844 u16 pktrate = frame->rate;
7845
7846 /* Magic struct that slots into the radiotap header -- no reason
7847 * to build this manually element by element, we can write it much
7848 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007849 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007850
Dan Carpenter92c1ff12012-01-12 09:34:50 +03007851 unsigned short len = le16_to_cpu(pkt->u.frame.length);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007852
7853 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007854 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007855
7856 /* We only process data packets if the
7857 * interface is open */
7858 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7859 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007860 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007861 priv->wstats.discard.misc++;
7862 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7863 return;
7864 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007865 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007866 priv->wstats.discard.misc++;
7867 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7868 return;
7869 }
7870
7871 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7872 * that now */
7873 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7874 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007875 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007876 priv->wstats.discard.misc++;
7877 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7878 return;
7879 }
7880
7881 /* copy the frame itself */
7882 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7883 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7884
Mike Kershaw24a47db2005-08-26 00:41:54 -05007885 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7886
7887 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7888 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007889 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007890
7891 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007892 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7893 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007894 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007895 (1 << IEEE80211_RADIOTAP_RATE) |
7896 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7897 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007898 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007899 (1 << IEEE80211_RADIOTAP_ANTENNA));
7900
7901 /* Zero the flags, we'll add to them as we go */
7902 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007903 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7904 frame->parent_tsf[2] << 16 |
7905 frame->parent_tsf[1] << 8 |
7906 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007907
7908 /* Convert signal to DBM */
7909 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007910 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007911
7912 /* Convert the channel data and set the flags */
7913 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7914 if (received_channel > 14) { /* 802.11a */
7915 ipw_rt->rt_chbitmask =
7916 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7917 } else if (antennaAndPhy & 32) { /* 802.11b */
7918 ipw_rt->rt_chbitmask =
7919 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7920 } else { /* 802.11g */
7921 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007922 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007923 }
7924
7925 /* set the rate in multiples of 500k/s */
7926 switch (pktrate) {
7927 case IPW_TX_RATE_1MB:
7928 ipw_rt->rt_rate = 2;
7929 break;
7930 case IPW_TX_RATE_2MB:
7931 ipw_rt->rt_rate = 4;
7932 break;
7933 case IPW_TX_RATE_5MB:
7934 ipw_rt->rt_rate = 10;
7935 break;
7936 case IPW_TX_RATE_6MB:
7937 ipw_rt->rt_rate = 12;
7938 break;
7939 case IPW_TX_RATE_9MB:
7940 ipw_rt->rt_rate = 18;
7941 break;
7942 case IPW_TX_RATE_11MB:
7943 ipw_rt->rt_rate = 22;
7944 break;
7945 case IPW_TX_RATE_12MB:
7946 ipw_rt->rt_rate = 24;
7947 break;
7948 case IPW_TX_RATE_18MB:
7949 ipw_rt->rt_rate = 36;
7950 break;
7951 case IPW_TX_RATE_24MB:
7952 ipw_rt->rt_rate = 48;
7953 break;
7954 case IPW_TX_RATE_36MB:
7955 ipw_rt->rt_rate = 72;
7956 break;
7957 case IPW_TX_RATE_48MB:
7958 ipw_rt->rt_rate = 96;
7959 break;
7960 case IPW_TX_RATE_54MB:
7961 ipw_rt->rt_rate = 108;
7962 break;
7963 default:
7964 ipw_rt->rt_rate = 0;
7965 break;
7966 }
7967
7968 /* antenna number */
7969 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7970
7971 /* set the preamble flag if we have it */
7972 if ((antennaAndPhy & 64))
7973 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7974
7975 /* Set the size of the skb to the size of the frame */
7976 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007977
7978 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7979
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007980 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007981 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007982 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007983 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007984 /* no LED during capture */
7985 }
7986}
7987#endif
7988
Zhu Yid685b8c2006-04-13 17:20:27 +08007989#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007990#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007991 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7992 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7993
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007994#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007995 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7996
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007997#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007998 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7999
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008000#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008001 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8002
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008003#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008004 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8005
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008006#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008007 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8008
8009static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8010 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008011 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008012{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008013 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008014 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8015 struct ipw_rx_frame *frame = &pkt->u.frame;
8016 struct ipw_rt_hdr *ipw_rt;
8017
8018 /* First cache any information we need before we overwrite
8019 * the information provided in the skb from the hardware */
8020 struct ieee80211_hdr *hdr;
8021 u16 channel = frame->received_channel;
8022 u8 phy_flags = frame->antennaAndPhy;
8023 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008024 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008025 u8 rate = frame->rate;
Dan Carpenter92c1ff12012-01-12 09:34:50 +03008026 unsigned short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008027 struct sk_buff *skb;
8028 int hdr_only = 0;
8029 u16 filter = priv->prom_priv->filter;
8030
8031 /* If the filter is set to not include Rx frames then return */
8032 if (filter & IPW_PROM_NO_RX)
8033 return;
8034
Zhu Yid685b8c2006-04-13 17:20:27 +08008035 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008036 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008037
8038 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008039 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008040 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8041 return;
8042 }
8043
8044 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008045 if (unlikely(!netif_running(dev))) {
8046 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008047 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8048 return;
8049 }
8050
8051 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8052 * that now */
8053 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8054 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008055 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008056 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8057 return;
8058 }
8059
8060 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008061 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008062 if (filter & IPW_PROM_NO_MGMT)
8063 return;
8064 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8065 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008066 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008067 if (filter & IPW_PROM_NO_CTL)
8068 return;
8069 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8070 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008071 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008072 if (filter & IPW_PROM_NO_DATA)
8073 return;
8074 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8075 hdr_only = 1;
8076 }
8077
8078 /* Copy the SKB since this is for the promiscuous side */
8079 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8080 if (skb == NULL) {
8081 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8082 return;
8083 }
8084
8085 /* copy the frame data to write after where the radiotap header goes */
8086 ipw_rt = (void *)skb->data;
8087
8088 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008089 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008090
8091 memcpy(ipw_rt->payload, hdr, len);
8092
Zhu Yid685b8c2006-04-13 17:20:27 +08008093 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8094 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008095 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008096
8097 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008098 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008099
8100 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008101 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8102 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008103 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008104 (1 << IEEE80211_RADIOTAP_RATE) |
8105 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8106 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8107 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8108 (1 << IEEE80211_RADIOTAP_ANTENNA));
8109
8110 /* Zero the flags, we'll add to them as we go */
8111 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008112 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8113 frame->parent_tsf[2] << 16 |
8114 frame->parent_tsf[1] << 8 |
8115 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008116
8117 /* Convert to DBM */
8118 ipw_rt->rt_dbmsignal = signal;
8119 ipw_rt->rt_dbmnoise = noise;
8120
8121 /* Convert the channel data and set the flags */
8122 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8123 if (channel > 14) { /* 802.11a */
8124 ipw_rt->rt_chbitmask =
8125 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8126 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8127 ipw_rt->rt_chbitmask =
8128 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8129 } else { /* 802.11g */
8130 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008131 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008132 }
8133
8134 /* set the rate in multiples of 500k/s */
8135 switch (rate) {
8136 case IPW_TX_RATE_1MB:
8137 ipw_rt->rt_rate = 2;
8138 break;
8139 case IPW_TX_RATE_2MB:
8140 ipw_rt->rt_rate = 4;
8141 break;
8142 case IPW_TX_RATE_5MB:
8143 ipw_rt->rt_rate = 10;
8144 break;
8145 case IPW_TX_RATE_6MB:
8146 ipw_rt->rt_rate = 12;
8147 break;
8148 case IPW_TX_RATE_9MB:
8149 ipw_rt->rt_rate = 18;
8150 break;
8151 case IPW_TX_RATE_11MB:
8152 ipw_rt->rt_rate = 22;
8153 break;
8154 case IPW_TX_RATE_12MB:
8155 ipw_rt->rt_rate = 24;
8156 break;
8157 case IPW_TX_RATE_18MB:
8158 ipw_rt->rt_rate = 36;
8159 break;
8160 case IPW_TX_RATE_24MB:
8161 ipw_rt->rt_rate = 48;
8162 break;
8163 case IPW_TX_RATE_36MB:
8164 ipw_rt->rt_rate = 72;
8165 break;
8166 case IPW_TX_RATE_48MB:
8167 ipw_rt->rt_rate = 96;
8168 break;
8169 case IPW_TX_RATE_54MB:
8170 ipw_rt->rt_rate = 108;
8171 break;
8172 default:
8173 ipw_rt->rt_rate = 0;
8174 break;
8175 }
8176
8177 /* antenna number */
8178 ipw_rt->rt_antenna = (phy_flags & 3);
8179
8180 /* set the preamble flag if we have it */
8181 if (phy_flags & (1 << 6))
8182 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8183
8184 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8185
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008186 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008187 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008188 dev_kfree_skb_any(skb);
8189 }
8190}
8191#endif
8192
Arjan van de Ven858119e2006-01-14 13:20:43 -08008193static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008194 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008195{
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008196 /* Filter incoming packets to determine if they are targeted toward
James Ketrenosea2b26e2005-08-24 21:25:16 -05008197 * this network, discarding packets coming from ourselves */
8198 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008199 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008200 /* packets from our adapter are dropped (echo) */
8201 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8202 return 0;
8203
Peter Jones90700fd2005-08-26 16:51:06 -05008204 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008205 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008206 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008207
8208 /* packets to our adapter go through */
8209 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8210 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008211
Peter Jones90700fd2005-08-26 16:51:06 -05008212 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008213 /* packets from our adapter are dropped (echo) */
8214 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8215 return 0;
8216
Peter Jones90700fd2005-08-26 16:51:06 -05008217 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008218 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008219 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8220
8221 /* packets to our adapter go through */
8222 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8223 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008224 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008225
James Ketrenosea2b26e2005-08-24 21:25:16 -05008226 return 1;
8227}
8228
James Ketrenosafbf30a2005-08-25 00:05:33 -05008229#define IPW_PACKET_RETRY_TIME HZ
8230
Arjan van de Ven858119e2006-01-14 13:20:43 -08008231static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008232 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008233{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008234 u16 sc = le16_to_cpu(header->seq_ctl);
8235 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8236 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8237 u16 *last_seq, *last_frag;
8238 unsigned long *last_time;
8239
8240 switch (priv->ieee->iw_mode) {
8241 case IW_MODE_ADHOC:
8242 {
8243 struct list_head *p;
8244 struct ipw_ibss_seq *entry = NULL;
8245 u8 *mac = header->addr2;
8246 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8247
8248 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8249 entry =
8250 list_entry(p, struct ipw_ibss_seq, list);
8251 if (!memcmp(entry->mac, mac, ETH_ALEN))
8252 break;
8253 }
8254 if (p == &priv->ibss_mac_hash[index]) {
8255 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8256 if (!entry) {
8257 IPW_ERROR
8258 ("Cannot malloc new mac entry\n");
8259 return 0;
8260 }
8261 memcpy(entry->mac, mac, ETH_ALEN);
8262 entry->seq_num = seq;
8263 entry->frag_num = frag;
8264 entry->packet_time = jiffies;
8265 list_add(&entry->list,
8266 &priv->ibss_mac_hash[index]);
8267 return 0;
8268 }
8269 last_seq = &entry->seq_num;
8270 last_frag = &entry->frag_num;
8271 last_time = &entry->packet_time;
8272 break;
8273 }
8274 case IW_MODE_INFRA:
8275 last_seq = &priv->last_seq_num;
8276 last_frag = &priv->last_frag_num;
8277 last_time = &priv->last_packet_time;
8278 break;
8279 default:
8280 return 0;
8281 }
8282 if ((*last_seq == seq) &&
8283 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8284 if (*last_frag == frag)
8285 goto drop;
8286 if (*last_frag + 1 != frag)
8287 /* out-of-order fragment */
8288 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008289 } else
8290 *last_seq = seq;
8291
Zhu Yif57ce7c2005-07-13 12:22:15 -05008292 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008293 *last_time = jiffies;
8294 return 0;
8295
8296 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008297 /* Comment this line now since we observed the card receives
8298 * duplicate packets but the FCTL_RETRY bit is not set in the
8299 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008300 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008301 return 1;
8302}
8303
James Ketrenosb095c382005-08-24 22:04:42 -05008304static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8305 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008306 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008307{
8308 struct sk_buff *skb = rxb->skb;
8309 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008310 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008311 (skb->data + IPW_RX_FRAME_SIZE);
8312
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008313 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008314
8315 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8316 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8317 IEEE80211_STYPE_PROBE_RESP) ||
8318 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8319 IEEE80211_STYPE_BEACON))) {
8320 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8321 ipw_add_station(priv, header->addr2);
8322 }
8323
8324 if (priv->config & CFG_NET_STATS) {
8325 IPW_DEBUG_HC("sending stat packet\n");
8326
8327 /* Set the size of the skb to the size of the full
8328 * ipw header and 802.11 frame */
8329 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8330 IPW_RX_FRAME_SIZE);
8331
8332 /* Advance past the ipw packet header to the 802.11 frame */
8333 skb_pull(skb, IPW_RX_FRAME_SIZE);
8334
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008335 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008336 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8337
8338 skb->dev = priv->ieee->dev;
8339
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008340 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008341 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008342
8343 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008344 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008345 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8346 netif_rx(skb);
8347 rxb->skb = NULL;
8348 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008349}
8350
James Ketrenos43f66a62005-03-25 12:31:53 -06008351/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008352 * Main entry function for receiving a packet with 80211 headers. This
James Ketrenos43f66a62005-03-25 12:31:53 -06008353 * should be called when ever the FW has notified us that there is a new
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008354 * skb in the receive queue.
James Ketrenos43f66a62005-03-25 12:31:53 -06008355 */
8356static void ipw_rx(struct ipw_priv *priv)
8357{
8358 struct ipw_rx_mem_buffer *rxb;
8359 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008360 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008361 u32 r, w, i;
8362 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008363 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008364
James Ketrenosb095c382005-08-24 22:04:42 -05008365 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8366 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008367 i = priv->rxq->read;
8368
8369 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8370 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008371
8372 while (i != r) {
8373 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008374 if (unlikely(rxb == NULL)) {
8375 printk(KERN_CRIT "Queue not allocated!\n");
8376 break;
8377 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008378 priv->rxq->queue[i] = NULL;
8379
8380 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008381 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008382 PCI_DMA_FROMDEVICE);
8383
8384 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8385 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8386 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008387 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008388
8389 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008390 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008391 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008392 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008393 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008394 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008395 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008396 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008397 .noise =
8398 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008399 .rate = pkt->u.frame.rate,
8400 .mac_time = jiffies,
8401 .received_channel =
8402 pkt->u.frame.received_channel,
8403 .freq =
8404 (pkt->u.frame.
8405 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008406 LIBIPW_24GHZ_BAND :
8407 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008408 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008409 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008410
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008411 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008412 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008413 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008414 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008415 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008416 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008417 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008418 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008419
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008420 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008421
Zhu Yid685b8c2006-04-13 17:20:27 +08008422#ifdef CONFIG_IPW2200_PROMISCUOUS
8423 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8424 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8425#endif
8426
James Ketrenosb095c382005-08-24 22:04:42 -05008427#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008428 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008429#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008430
8431 ipw_handle_data_packet_monitor(priv,
8432 rxb,
8433 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008434#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008435 ipw_handle_data_packet(priv, rxb,
8436 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008437#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008438 break;
8439 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008440#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008441
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008442 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008443 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008444 data +
8445 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008446 /* TODO: Check Ad-Hoc dest/source and make sure
8447 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008448 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008449 * frame control of the packet and disregard
8450 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008451
James Ketrenosea2b26e2005-08-24 21:25:16 -05008452 network_packet =
8453 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008454 if (network_packet && priv->assoc_network) {
8455 priv->assoc_network->stats.rssi =
8456 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008457 priv->exp_avg_rssi =
8458 exponential_average(priv->exp_avg_rssi,
8459 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008460 }
8461
8462 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008463 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008464
James Ketrenosa613bff2005-08-24 21:43:11 -05008465 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008466 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008467 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008468 IPW_DEBUG_DROP
8469 ("Received packet is too small. "
8470 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008471 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008472 priv->wstats.discard.misc++;
8473 break;
8474 }
8475
James Ketrenosa613bff2005-08-24 21:43:11 -05008476 switch (WLAN_FC_GET_TYPE
8477 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008479 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008480 ipw_handle_mgmt_packet(priv, rxb,
8481 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008482 break;
8483
8484 case IEEE80211_FTYPE_CTL:
8485 break;
8486
8487 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008488 if (unlikely(!network_packet ||
8489 is_duplicate_packet(priv,
8490 header)))
8491 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008492 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008493 "%pM, "
8494 "%pM, "
8495 "%pM\n",
8496 header->addr1,
8497 header->addr2,
8498 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008499 break;
8500 }
8501
8502 ipw_handle_data_packet(priv, rxb,
8503 &stats);
8504
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008505 break;
8506 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008507 break;
8508 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008509
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008510 case RX_HOST_NOTIFICATION_TYPE:{
8511 IPW_DEBUG_RX
8512 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008513 pkt->u.notification.subtype,
8514 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008515 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008516 ipw_rx_notification(priv, &pkt->u.notification);
8517 break;
8518 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008519
8520 default:
8521 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8522 pkt->header.message_type);
8523 break;
8524 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008525
8526 /* For now we just don't re-use anything. We can tweak this
8527 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008528 * fail to Rx correctly */
8529 if (rxb->skb != NULL) {
8530 dev_kfree_skb_any(rxb->skb);
8531 rxb->skb = NULL;
8532 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008533
James Ketrenos43f66a62005-03-25 12:31:53 -06008534 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008535 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008536 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008537
James Ketrenos43f66a62005-03-25 12:31:53 -06008538 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008539
8540 /* If there are a lot of unsued frames, restock the Rx queue
8541 * so the ucode won't assert */
8542 if (fill_rx) {
8543 priv->rxq->read = i;
8544 ipw_rx_queue_replenish(priv);
8545 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008546 }
8547
8548 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008549 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008550 ipw_rx_queue_restock(priv);
8551}
8552
James Ketrenosafbf30a2005-08-25 00:05:33 -05008553#define DEFAULT_RTS_THRESHOLD 2304U
8554#define MIN_RTS_THRESHOLD 1U
8555#define MAX_RTS_THRESHOLD 2304U
8556#define DEFAULT_BEACON_INTERVAL 100U
8557#define DEFAULT_SHORT_RETRY_LIMIT 7U
8558#define DEFAULT_LONG_RETRY_LIMIT 4U
8559
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008560/**
8561 * ipw_sw_reset
8562 * @option: options to control different reset behaviour
8563 * 0 = reset everything except the 'disable' module_param
8564 * 1 = reset everything and print out driver info (for probe only)
8565 * 2 = reset everything
8566 */
8567static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008568{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008569 int band, modulation;
8570 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008571
James Ketrenosafbf30a2005-08-25 00:05:33 -05008572 /* Initialize module parameter values here */
8573 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008574
James Ketrenosafbf30a2005-08-25 00:05:33 -05008575 /* We default to disabling the LED code as right now it causes
8576 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008577 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008578 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008579
James Ketrenosafbf30a2005-08-25 00:05:33 -05008580 if (associate)
8581 priv->config |= CFG_ASSOCIATE;
8582 else
8583 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008584
James Ketrenosafbf30a2005-08-25 00:05:33 -05008585 if (auto_create)
8586 priv->config |= CFG_ADHOC_CREATE;
8587 else
8588 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8589
Zhu Yi17ed0812006-01-24 16:36:31 +08008590 priv->config &= ~CFG_STATIC_ESSID;
8591 priv->essid_len = 0;
8592 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8593
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008594 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008595 priv->status |= STATUS_RF_KILL_SW;
8596 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008597 }
8598
Reinette Chatre21f8a732009-08-18 10:25:05 -07008599 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008600 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008601 priv->channel = default_channel;
8602 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008603 /* TODO: Validate that provided channel is in range */
8604 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008605#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008606 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8607 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008608#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008609
Reinette Chatre21f8a732009-08-18 10:25:05 -07008610 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008611 case 1:
8612 priv->ieee->iw_mode = IW_MODE_ADHOC;
8613 priv->net_dev->type = ARPHRD_ETHER;
8614
8615 break;
8616#ifdef CONFIG_IPW2200_MONITOR
8617 case 2:
8618 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008619#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008620 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8621#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008622 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008623#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008624 break;
8625#endif
8626 default:
8627 case 0:
8628 priv->net_dev->type = ARPHRD_ETHER;
8629 priv->ieee->iw_mode = IW_MODE_INFRA;
8630 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008631 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008632
James Ketrenosafbf30a2005-08-25 00:05:33 -05008633 if (hwcrypto) {
8634 priv->ieee->host_encrypt = 0;
8635 priv->ieee->host_encrypt_msdu = 0;
8636 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008637 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008638 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008639 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008640
Zhu Yie402c932005-08-05 17:20:40 +08008641 /* IPW2200/2915 is abled to do hardware fragmentation. */
8642 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008643
James Ketrenosafbf30a2005-08-25 00:05:33 -05008644 if ((priv->pci_dev->device == 0x4223) ||
8645 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008646 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008647 printk(KERN_INFO DRV_NAME
8648 ": Detected Intel PRO/Wireless 2915ABG Network "
8649 "Connection\n");
8650 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008651 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8652 modulation = LIBIPW_OFDM_MODULATION |
8653 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008654 priv->adapter = IPW_2915ABG;
8655 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008656 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008657 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008658 printk(KERN_INFO DRV_NAME
8659 ": Detected Intel PRO/Wireless 2200BG Network "
8660 "Connection\n");
8661
8662 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008663 band = LIBIPW_24GHZ_BAND;
8664 modulation = LIBIPW_OFDM_MODULATION |
8665 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008666 priv->adapter = IPW_2200BG;
8667 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008668 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008669
James Ketrenosafbf30a2005-08-25 00:05:33 -05008670 priv->ieee->freq_band = band;
8671 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008672
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008673 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008674
James Ketrenosafbf30a2005-08-25 00:05:33 -05008675 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8676 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008677
James Ketrenosafbf30a2005-08-25 00:05:33 -05008678 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8679 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8680 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008681
James Ketrenosafbf30a2005-08-25 00:05:33 -05008682 /* If power management is turned on, default to AC mode */
8683 priv->power_mode = IPW_POWER_AC;
8684 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008685
Zhu Yi0ece35b2005-08-05 17:26:51 +08008686 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008687}
8688
8689/*
8690 * This file defines the Wireless Extension handlers. It does not
8691 * define any methods of hardware manipulation and relies on the
8692 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008693 *
8694 * The exception to this is the use of the ipw_get_ordinal()
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008695 * function used to poll the hardware vs. making unnecessary calls.
James Ketrenos43f66a62005-03-25 12:31:53 -06008696 *
8697 */
8698
James Ketrenos43f66a62005-03-25 12:31:53 -06008699static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8700{
8701 if (channel == 0) {
8702 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8703 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008704 IPW_DEBUG_ASSOC("Attempting to associate with new "
8705 "parameters.\n");
8706 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008707 return 0;
8708 }
8709
8710 priv->config |= CFG_STATIC_CHANNEL;
8711
8712 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008713 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8714 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008715 return 0;
8716 }
8717
8718 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8719 priv->channel = channel;
8720
James Ketrenosb095c382005-08-24 22:04:42 -05008721#ifdef CONFIG_IPW2200_MONITOR
8722 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008723 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008724 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008725 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008726 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008727 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008728 }
8729
8730 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8731 udelay(10);
8732
8733 if (priv->status & STATUS_SCANNING)
8734 IPW_DEBUG_SCAN("Still scanning...\n");
8735 else
8736 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8737 1000 - i);
8738
8739 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008740 }
James Ketrenosb095c382005-08-24 22:04:42 -05008741#endif /* CONFIG_IPW2200_MONITOR */
8742
James Ketrenosc848d0a2005-08-24 21:56:24 -05008743 /* Network configuration changed -- force [re]association */
8744 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8745 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008746 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008747
8748 return 0;
8749}
8750
Jeff Garzikbf794512005-07-31 13:07:26 -04008751static int ipw_wx_set_freq(struct net_device *dev,
8752 struct iw_request_info *info,
8753 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008754{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008755 struct ipw_priv *priv = libipw_priv(dev);
8756 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008757 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008758 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008759 u8 channel, flags;
8760 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008761
James Ketrenosb095c382005-08-24 22:04:42 -05008762 if (fwrq->m == 0) {
8763 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008764 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008765 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008766 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008767 return ret;
8768 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008769 /* if setting by freq convert to channel */
8770 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008771 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008772 if (channel == 0)
8773 return -EINVAL;
8774 } else
8775 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008776
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008777 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008778 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008779
Liu Hong1fe0adb2005-08-19 09:33:10 -05008780 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008781 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008782 if (i == -1)
8783 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008784
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008785 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008786 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008787 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008788 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8789 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008790 }
8791 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008792
Frans Pop9fd1ea42010-03-24 19:46:31 +01008793 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008794 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008795 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008796 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008797 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008798}
8799
Jeff Garzikbf794512005-07-31 13:07:26 -04008800static int ipw_wx_get_freq(struct net_device *dev,
8801 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008802 union iwreq_data *wrqu, char *extra)
8803{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008804 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008805
8806 wrqu->freq.e = 0;
8807
8808 /* If we are associated, trying to associate, or have a statically
8809 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008810 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008811 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008812 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8813 int i;
8814
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008815 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008816 BUG_ON(i == -1);
8817 wrqu->freq.e = 1;
8818
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008819 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8820 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008821 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8822 break;
8823
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008824 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008825 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8826 break;
8827
8828 default:
8829 BUG();
8830 }
8831 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 wrqu->freq.m = 0;
8833
Zhu Yi46441512006-01-24 16:37:59 +08008834 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008835 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 return 0;
8837}
8838
Jeff Garzikbf794512005-07-31 13:07:26 -04008839static int ipw_wx_set_mode(struct net_device *dev,
8840 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008841 union iwreq_data *wrqu, char *extra)
8842{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008843 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 int err = 0;
8845
8846 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8847
James Ketrenos43f66a62005-03-25 12:31:53 -06008848 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008849#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008850 case IW_MODE_MONITOR:
8851#endif
8852 case IW_MODE_ADHOC:
8853 case IW_MODE_INFRA:
8854 break;
8855 case IW_MODE_AUTO:
8856 wrqu->mode = IW_MODE_INFRA;
8857 break;
8858 default:
8859 return -EINVAL;
8860 }
James Ketrenosb095c382005-08-24 22:04:42 -05008861 if (wrqu->mode == priv->ieee->iw_mode)
8862 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008863
Zhu Yi46441512006-01-24 16:37:59 +08008864 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008865
8866 ipw_sw_reset(priv, 0);
8867
James Ketrenosb095c382005-08-24 22:04:42 -05008868#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008869 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008870 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008871
8872 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008873#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008874 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8875#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008876 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008877#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008878#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008879
Jeff Garzikbf794512005-07-31 13:07:26 -04008880 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008881 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008882 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008883
8884 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008885
Tejun Heobcb6d912011-01-26 12:12:50 +01008886 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008887 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008888 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008889}
8890
Jeff Garzikbf794512005-07-31 13:07:26 -04008891static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008892 struct iw_request_info *info,
8893 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008894{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008895 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008896 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008897 wrqu->mode = priv->ieee->iw_mode;
8898 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008899 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008900 return 0;
8901}
8902
James Ketrenos43f66a62005-03-25 12:31:53 -06008903/* Values are in microsecond */
8904static const s32 timeout_duration[] = {
8905 350000,
8906 250000,
8907 75000,
8908 37000,
8909 25000,
8910};
8911
8912static const s32 period_duration[] = {
8913 400000,
8914 700000,
8915 1000000,
8916 1000000,
8917 1000000
8918};
8919
Jeff Garzikbf794512005-07-31 13:07:26 -04008920static int ipw_wx_get_range(struct net_device *dev,
8921 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008922 union iwreq_data *wrqu, char *extra)
8923{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008924 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008925 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008926 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008927 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008928
8929 wrqu->data.length = sizeof(*range);
8930 memset(range, 0, sizeof(*range));
8931
8932 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008933 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008934
8935 range->max_qual.qual = 100;
8936 /* TODO: Find real max RSSI and stick here */
8937 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008938 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008939 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008940
8941 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008942 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008943 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008944 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008945 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008946 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008947 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008948
Jeff Garzikbf794512005-07-31 13:07:26 -04008949 for (i = 0; i < range->num_bitrates; i++)
8950 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008951 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008952
James Ketrenos43f66a62005-03-25 12:31:53 -06008953 range->max_rts = DEFAULT_RTS_THRESHOLD;
8954 range->min_frag = MIN_FRAG_THRESHOLD;
8955 range->max_frag = MAX_FRAG_THRESHOLD;
8956
8957 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008958 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008959 range->num_encoding_sizes = 2;
8960 range->max_encoding_tokens = WEP_KEYS;
8961
8962 /* Set the Wireless Extension versions */
8963 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008964 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008965
James Ketrenosb095c382005-08-24 22:04:42 -05008966 i = 0;
8967 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008968 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8969 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008970 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008971 continue;
8972
James Ketrenosb095c382005-08-24 22:04:42 -05008973 range->freq[i].i = geo->bg[j].channel;
8974 range->freq[i].m = geo->bg[j].freq * 100000;
8975 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008976 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008977 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008978 }
James Ketrenosb095c382005-08-24 22:04:42 -05008979
8980 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008981 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8982 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008983 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008984 continue;
8985
James Ketrenosb095c382005-08-24 22:04:42 -05008986 range->freq[i].i = geo->a[j].channel;
8987 range->freq[i].m = geo->a[j].freq * 100000;
8988 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008989 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008990 }
8991 }
8992
8993 range->num_channels = i;
8994 range->num_frequency = i;
8995
Zhu Yi46441512006-01-24 16:37:59 +08008996 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008997
8998 /* Event capability (kernel + driver) */
8999 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
9000 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08009001 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9002 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009003 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009004
Dan Williamsf1b50862006-01-30 13:58:56 -05009005 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9006 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9007
Dan Williams374fdfb2007-12-12 10:25:07 -05009008 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9009
James Ketrenos43f66a62005-03-25 12:31:53 -06009010 IPW_DEBUG_WX("GET Range\n");
9011 return 0;
9012}
9013
Jeff Garzikbf794512005-07-31 13:07:26 -04009014static int ipw_wx_set_wap(struct net_device *dev,
9015 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009016 union iwreq_data *wrqu, char *extra)
9017{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009018 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009019
9020 static const unsigned char any[] = {
9021 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9022 };
9023 static const unsigned char off[] = {
9024 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9025 };
9026
Jeff Garzikbf794512005-07-31 13:07:26 -04009027 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009028 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009029 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009030 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9031 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9032 /* we disable mandatory BSSID association */
9033 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9034 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009035 IPW_DEBUG_ASSOC("Attempting to associate with new "
9036 "parameters.\n");
9037 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009038 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009039 return 0;
9040 }
9041
9042 priv->config |= CFG_STATIC_BSSID;
9043 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9044 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009045 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009046 return 0;
9047 }
9048
Johannes Berge1749612008-10-27 15:59:26 -07009049 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9050 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009051
9052 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9053
James Ketrenosc848d0a2005-08-24 21:56:24 -05009054 /* Network configuration changed -- force [re]association */
9055 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9056 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009057 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009058
Zhu Yi46441512006-01-24 16:37:59 +08009059 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009060 return 0;
9061}
9062
Jeff Garzikbf794512005-07-31 13:07:26 -04009063static int ipw_wx_get_wap(struct net_device *dev,
9064 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009065 union iwreq_data *wrqu, char *extra)
9066{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009067 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009068
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 /* If we are associated, trying to associate, or have a statically
9070 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009071 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009072 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009073 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9074 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009075 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009076 } else
9077 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9078
Johannes Berge1749612008-10-27 15:59:26 -07009079 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9080 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009081 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009082 return 0;
9083}
9084
Jeff Garzikbf794512005-07-31 13:07:26 -04009085static int ipw_wx_set_essid(struct net_device *dev,
9086 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009087 union iwreq_data *wrqu, char *extra)
9088{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009089 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009090 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009091 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009092
Zhu Yiab644b02006-08-21 11:37:13 +08009093 mutex_lock(&priv->mutex);
9094
9095 if (!wrqu->essid.flags)
9096 {
9097 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9098 ipw_disassociate(priv);
9099 priv->config &= ~CFG_STATIC_ESSID;
9100 ipw_associate(priv);
9101 mutex_unlock(&priv->mutex);
9102 return 0;
9103 }
9104
Zhu Yia9f0d422006-08-21 11:37:26 +08009105 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009106
9107 priv->config |= CFG_STATIC_ESSID;
9108
Zhu Yia9f0d422006-08-21 11:37:26 +08009109 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9110 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009111 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009112 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009113 return 0;
9114 }
9115
John W. Linville9387b7c2008-09-30 20:59:05 -04009116 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9117 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009118
9119 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009120 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009121
James Ketrenosc848d0a2005-08-24 21:56:24 -05009122 /* Network configuration changed -- force [re]association */
9123 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9124 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009126
Zhu Yi46441512006-01-24 16:37:59 +08009127 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 return 0;
9129}
9130
Jeff Garzikbf794512005-07-31 13:07:26 -04009131static int ipw_wx_get_essid(struct net_device *dev,
9132 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009133 union iwreq_data *wrqu, char *extra)
9134{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009135 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009136 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009137
9138 /* If we are associated, trying to associate, or have a statically
9139 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009140 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009141 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009142 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9143 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009144 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009145 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009146 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009147 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 } else {
9149 IPW_DEBUG_WX("Getting essid: ANY\n");
9150 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009151 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009152 }
Zhu Yi46441512006-01-24 16:37:59 +08009153 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 return 0;
9155}
9156
Jeff Garzikbf794512005-07-31 13:07:26 -04009157static int ipw_wx_set_nick(struct net_device *dev,
9158 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009159 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009160{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009161 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009162
9163 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9164 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9165 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009166 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009168 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009169 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009170 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009171 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009172 return 0;
9173
9174}
9175
Jeff Garzikbf794512005-07-31 13:07:26 -04009176static int ipw_wx_get_nick(struct net_device *dev,
9177 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009178 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009179{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009180 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009181 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009182 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009183 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009185 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009186 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009187 return 0;
9188}
9189
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009190static int ipw_wx_set_sens(struct net_device *dev,
9191 struct iw_request_info *info,
9192 union iwreq_data *wrqu, char *extra)
9193{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009194 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009195 int err = 0;
9196
9197 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9198 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9199 mutex_lock(&priv->mutex);
9200
9201 if (wrqu->sens.fixed == 0)
9202 {
9203 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9204 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9205 goto out;
9206 }
9207 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9208 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9209 err = -EINVAL;
9210 goto out;
9211 }
9212
9213 priv->roaming_threshold = wrqu->sens.value;
9214 priv->disassociate_threshold = 3*wrqu->sens.value;
9215 out:
9216 mutex_unlock(&priv->mutex);
9217 return err;
9218}
9219
9220static int ipw_wx_get_sens(struct net_device *dev,
9221 struct iw_request_info *info,
9222 union iwreq_data *wrqu, char *extra)
9223{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009224 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009225 mutex_lock(&priv->mutex);
9226 wrqu->sens.fixed = 1;
9227 wrqu->sens.value = priv->roaming_threshold;
9228 mutex_unlock(&priv->mutex);
9229
Frans Pop9fd1ea42010-03-24 19:46:31 +01009230 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009231 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9232
9233 return 0;
9234}
9235
James Ketrenos43f66a62005-03-25 12:31:53 -06009236static int ipw_wx_set_rate(struct net_device *dev,
9237 struct iw_request_info *info,
9238 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009239{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009240 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009241 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009242 u32 target_rate = wrqu->bitrate.value;
9243 u32 fixed, mask;
9244
9245 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9246 /* value = X, fixed = 1 means only rate X */
9247 /* value = X, fixed = 0 means all rates lower equal X */
9248
9249 if (target_rate == -1) {
9250 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009251 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009252 /* Now we should reassociate */
9253 goto apply;
9254 }
9255
9256 mask = 0;
9257 fixed = wrqu->bitrate.fixed;
9258
9259 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009260 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009261 if (target_rate == 1000000)
9262 goto apply;
9263
9264 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009265 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009266 if (target_rate == 2000000)
9267 goto apply;
9268
9269 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009270 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009271 if (target_rate == 5500000)
9272 goto apply;
9273
9274 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009275 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009276 if (target_rate == 6000000)
9277 goto apply;
9278
9279 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009280 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009281 if (target_rate == 9000000)
9282 goto apply;
9283
9284 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009285 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009286 if (target_rate == 11000000)
9287 goto apply;
9288
9289 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009290 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009291 if (target_rate == 12000000)
9292 goto apply;
9293
9294 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009295 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009296 if (target_rate == 18000000)
9297 goto apply;
9298
9299 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009300 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009301 if (target_rate == 24000000)
9302 goto apply;
9303
9304 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009305 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009306 if (target_rate == 36000000)
9307 goto apply;
9308
9309 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009310 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009311 if (target_rate == 48000000)
9312 goto apply;
9313
9314 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009315 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009316 if (target_rate == 54000000)
9317 goto apply;
9318
9319 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9320 return -EINVAL;
9321
9322 apply:
9323 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9324 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009325 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009326 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009327 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009328 ipw_set_fixed_rate(priv, priv->ieee->mode);
9329 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009330 priv->config |= CFG_FIXED_RATE;
9331
James Ketrenosc848d0a2005-08-24 21:56:24 -05009332 if (priv->rates_mask == mask) {
9333 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009334 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009335 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009336 }
9337
James Ketrenosc848d0a2005-08-24 21:56:24 -05009338 priv->rates_mask = mask;
9339
9340 /* Network configuration changed -- force [re]association */
9341 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9342 if (!ipw_disassociate(priv))
9343 ipw_associate(priv);
9344
Zhu Yi46441512006-01-24 16:37:59 +08009345 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009346 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009347}
9348
Jeff Garzikbf794512005-07-31 13:07:26 -04009349static int ipw_wx_get_rate(struct net_device *dev,
9350 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009352{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009353 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009354 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009355 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009356 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009357 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009358 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009359 return 0;
9360}
9361
Jeff Garzikbf794512005-07-31 13:07:26 -04009362static int ipw_wx_set_rts(struct net_device *dev,
9363 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009364 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009365{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009366 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009367 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009368 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009369 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9370 else {
9371 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009372 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009373 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009374 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009375 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009376 priv->rts_threshold = wrqu->rts.value;
9377 }
9378
9379 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009380 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009381 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009382 return 0;
9383}
9384
Jeff Garzikbf794512005-07-31 13:07:26 -04009385static int ipw_wx_get_rts(struct net_device *dev,
9386 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009387 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009388{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009389 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009390 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009391 wrqu->rts.value = priv->rts_threshold;
9392 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009393 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009394 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009395 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009396 return 0;
9397}
9398
Jeff Garzikbf794512005-07-31 13:07:26 -04009399static int ipw_wx_set_txpow(struct net_device *dev,
9400 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009401 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009402{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009403 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009404 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009405
Zhu Yi46441512006-01-24 16:37:59 +08009406 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009407 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009408 err = -EINPROGRESS;
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.fixed)
9413 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009414
James Ketrenosc848d0a2005-08-24 21:56:24 -05009415 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009416 err = -EINVAL;
9417 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009418 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009419
James Ketrenosb095c382005-08-24 22:04:42 -05009420 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009421 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009422 err = -EINVAL;
9423 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009424 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009425
9426 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009427 err = ipw_set_tx_power(priv);
9428 out:
Zhu Yi46441512006-01-24 16:37:59 +08009429 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009430 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009431}
9432
Jeff Garzikbf794512005-07-31 13:07:26 -04009433static int ipw_wx_get_txpow(struct net_device *dev,
9434 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009435 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009436{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009437 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009438 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009439 wrqu->power.value = priv->tx_power;
9440 wrqu->power.fixed = 1;
9441 wrqu->power.flags = IW_TXPOW_DBM;
9442 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009443 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009444
Frans Pop9fd1ea42010-03-24 19:46:31 +01009445 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009446 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009447
9448 return 0;
9449}
9450
Jeff Garzikbf794512005-07-31 13:07:26 -04009451static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009452 struct iw_request_info *info,
9453 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009454{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009455 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009456 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009457 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009458 priv->ieee->fts = DEFAULT_FTS;
9459 else {
9460 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009461 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009462 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009464 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009465
James Ketrenos43f66a62005-03-25 12:31:53 -06009466 priv->ieee->fts = wrqu->frag.value & ~0x1;
9467 }
9468
9469 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009470 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009471 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 return 0;
9473}
9474
Jeff Garzikbf794512005-07-31 13:07:26 -04009475static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009476 struct iw_request_info *info,
9477 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009478{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009479 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009480 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009481 wrqu->frag.value = priv->ieee->fts;
9482 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009483 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009484 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009485 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009486
9487 return 0;
9488}
9489
Jeff Garzikbf794512005-07-31 13:07:26 -04009490static int ipw_wx_set_retry(struct net_device *dev,
9491 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009492 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009493{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009494 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009495
9496 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9497 return -EINVAL;
9498
9499 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9500 return 0;
9501
Zhu Yid5f7ac22006-08-21 11:38:17 +08009502 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009503 return -EINVAL;
9504
Zhu Yi46441512006-01-24 16:37:59 +08009505 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009506 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009507 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009508 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009509 priv->long_retry_limit = (u8) wrqu->retry.value;
9510 else {
9511 priv->short_retry_limit = (u8) wrqu->retry.value;
9512 priv->long_retry_limit = (u8) wrqu->retry.value;
9513 }
9514
9515 ipw_send_retry_limit(priv, priv->short_retry_limit,
9516 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009517 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009518 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9519 priv->short_retry_limit, priv->long_retry_limit);
9520 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009521}
9522
Jeff Garzikbf794512005-07-31 13:07:26 -04009523static int ipw_wx_get_retry(struct net_device *dev,
9524 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009525 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009526{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009527 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009528
Zhu Yi46441512006-01-24 16:37:59 +08009529 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009530 wrqu->retry.disabled = 0;
9531
9532 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009533 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009534 return -EINVAL;
9535 }
9536
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009537 if (wrqu->retry.flags & IW_RETRY_LONG) {
9538 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009539 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009540 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9541 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009542 wrqu->retry.value = priv->short_retry_limit;
9543 } else {
9544 wrqu->retry.flags = IW_RETRY_LIMIT;
9545 wrqu->retry.value = priv->short_retry_limit;
9546 }
Zhu Yi46441512006-01-24 16:37:59 +08009547 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009548
Frans Pop9fd1ea42010-03-24 19:46:31 +01009549 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009550
9551 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009552}
9553
Jeff Garzikbf794512005-07-31 13:07:26 -04009554static int ipw_wx_set_scan(struct net_device *dev,
9555 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009556 union iwreq_data *wrqu, char *extra)
9557{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009558 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009559 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009560 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009561
Dan Williams0b531672007-10-09 13:55:24 -04009562 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009563
Dan Williams0b531672007-10-09 13:55:24 -04009564 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009565
Zhu Yi094c4d22006-08-21 11:39:03 +08009566 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009567 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009568 int len = min((int)req->essid_len,
9569 (int)sizeof(priv->direct_scan_ssid));
9570 memcpy(priv->direct_scan_ssid, req->essid, len);
9571 priv->direct_scan_ssid_len = len;
9572 work = &priv->request_direct_scan;
9573 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9574 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009575 }
Dan Williamsea177302008-06-02 17:51:23 -04009576 } else {
9577 /* Normal active broadcast scan */
9578 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009579 }
James Ketrenos8935f392005-10-05 15:59:08 -05009580
Dan Williamsea177302008-06-02 17:51:23 -04009581 mutex_unlock(&priv->mutex);
9582
James Ketrenos43f66a62005-03-25 12:31:53 -06009583 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009584
Tejun Heobcb6d912011-01-26 12:12:50 +01009585 schedule_delayed_work(work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009586
James Ketrenos43f66a62005-03-25 12:31:53 -06009587 return 0;
9588}
9589
Jeff Garzikbf794512005-07-31 13:07:26 -04009590static int ipw_wx_get_scan(struct net_device *dev,
9591 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009592 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009593{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009594 struct ipw_priv *priv = libipw_priv(dev);
9595 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009596}
9597
Jeff Garzikbf794512005-07-31 13:07:26 -04009598static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009599 struct iw_request_info *info,
9600 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009601{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009602 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009603 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009604 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009605
Zhu Yi46441512006-01-24 16:37:59 +08009606 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009607 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009608
Hong Liucaeff812005-08-05 17:25:50 +08009609 /* In IBSS mode, we need to notify the firmware to update
9610 * the beacon info after we changed the capability. */
9611 if (cap != priv->capability &&
9612 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9613 priv->status & STATUS_ASSOCIATED)
9614 ipw_disassociate(priv);
9615
Zhu Yi46441512006-01-24 16:37:59 +08009616 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009617 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009618}
9619
Jeff Garzikbf794512005-07-31 13:07:26 -04009620static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009621 struct iw_request_info *info,
9622 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009623{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009624 struct ipw_priv *priv = libipw_priv(dev);
9625 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009626}
9627
Jeff Garzikbf794512005-07-31 13:07:26 -04009628static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009629 struct iw_request_info *info,
9630 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009631{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009632 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009633 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009634 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009635 if (wrqu->power.disabled) {
9636 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9637 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9638 if (err) {
9639 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009640 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009641 return err;
9642 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009643 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009644 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009646 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009647
9648 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009649 case IW_POWER_ON: /* If not specified */
9650 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009651 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009652 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009653 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009654 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9655 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009656 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009657 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009658 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009659
James Ketrenos43f66a62005-03-25 12:31:53 -06009660 /* If the user hasn't specified a power management mode yet, default
9661 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009662 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009664 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009665 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009666
James Ketrenos43f66a62005-03-25 12:31:53 -06009667 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9668 if (err) {
9669 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009670 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009671 return err;
9672 }
9673
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009674 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009675 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009676 return 0;
9677}
9678
Jeff Garzikbf794512005-07-31 13:07:26 -04009679static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009680 struct iw_request_info *info,
9681 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009682{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009683 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009684 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009685 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009686 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009687 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009688 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009689
Zhu Yi46441512006-01-24 16:37:59 +08009690 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009691 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009692
James Ketrenos43f66a62005-03-25 12:31:53 -06009693 return 0;
9694}
9695
Jeff Garzikbf794512005-07-31 13:07:26 -04009696static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009697 struct iw_request_info *info,
9698 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009699{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009700 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009701 int mode = *(int *)extra;
9702 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009703
Zhu Yi46441512006-01-24 16:37:59 +08009704 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009705 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009706 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009707
Zhu Yi4e157f02007-07-12 16:09:32 +08009708 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009710 if (err) {
9711 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009712 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009713 return err;
9714 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009715 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009716 }
Zhu Yi46441512006-01-24 16:37:59 +08009717 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 return 0;
9719}
9720
9721#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009722static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009723 struct iw_request_info *info,
9724 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009725{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009726 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009727 int level = IPW_POWER_LEVEL(priv->power_mode);
9728 char *p = extra;
9729
9730 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9731
9732 switch (level) {
9733 case IPW_POWER_AC:
9734 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9735 break;
9736 case IPW_POWER_BATTERY:
9737 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9738 break;
9739 default:
9740 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009741 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009742 timeout_duration[level - 1] / 1000,
9743 period_duration[level - 1] / 1000);
9744 }
9745
9746 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009747 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009748
9749 wrqu->data.length = p - extra + 1;
9750
9751 return 0;
9752}
9753
9754static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009755 struct iw_request_info *info,
9756 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009757{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009758 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 int mode = *(int *)extra;
9760 u8 band = 0, modulation = 0;
9761
9762 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009763 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 return -EINVAL;
9765 }
Zhu Yi46441512006-01-24 16:37:59 +08009766 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009767 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009768 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009769 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009770 band |= LIBIPW_52GHZ_BAND;
9771 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009772 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009773 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009774 } else {
9775 if (mode & IEEE_A) {
9776 IPW_WARNING("Attempt to set 2200BG into "
9777 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009778 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009779 return -EINVAL;
9780 }
9781
James Ketrenosa33a1982005-09-14 14:28:59 -05009782 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009783 }
9784
9785 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009786 band |= LIBIPW_24GHZ_BAND;
9787 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009788 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009789 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009790
James Ketrenos43f66a62005-03-25 12:31:53 -06009791 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009792 band |= LIBIPW_24GHZ_BAND;
9793 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009794 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009795 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009796
9797 priv->ieee->mode = mode;
9798 priv->ieee->freq_band = band;
9799 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009800 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009801
James Ketrenosc848d0a2005-08-24 21:56:24 -05009802 /* Network configuration changed -- force [re]association */
9803 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9804 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009805 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009806 ipw_associate(priv);
9807 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009808
James Ketrenosa613bff2005-08-24 21:43:11 -05009809 /* Update the band LEDs */
9810 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009811
Jeff Garzikbf794512005-07-31 13:07:26 -04009812 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009813 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009814 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009815 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009816 return 0;
9817}
9818
9819static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009820 struct iw_request_info *info,
9821 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009822{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009823 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009824 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009825 switch (priv->ieee->mode) {
9826 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009827 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9828 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009829 case IEEE_B:
9830 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9831 break;
9832 case IEEE_A | IEEE_B:
9833 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9834 break;
9835 case IEEE_G:
9836 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9837 break;
9838 case IEEE_A | IEEE_G:
9839 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9840 break;
9841 case IEEE_B | IEEE_G:
9842 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9843 break;
9844 case IEEE_A | IEEE_B | IEEE_G:
9845 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9846 break;
9847 default:
9848 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009849 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009850 }
9851
James Ketrenos43f66a62005-03-25 12:31:53 -06009852 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9853
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009854 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009855 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009856
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009857 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009858}
9859
James Ketrenosea2b26e2005-08-24 21:25:16 -05009860static int ipw_wx_set_preamble(struct net_device *dev,
9861 struct iw_request_info *info,
9862 union iwreq_data *wrqu, char *extra)
9863{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009864 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009865 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009866 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009867 /* Switching from SHORT -> LONG requires a disassociation */
9868 if (mode == 1) {
9869 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9870 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009871
9872 /* Network configuration changed -- force [re]association */
9873 IPW_DEBUG_ASSOC
9874 ("[re]association triggered due to preamble change.\n");
9875 if (!ipw_disassociate(priv))
9876 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009877 }
9878 goto done;
9879 }
9880
9881 if (mode == 0) {
9882 priv->config &= ~CFG_PREAMBLE_LONG;
9883 goto done;
9884 }
Zhu Yi46441512006-01-24 16:37:59 +08009885 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009886 return -EINVAL;
9887
9888 done:
Zhu Yi46441512006-01-24 16:37:59 +08009889 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009890 return 0;
9891}
9892
9893static int ipw_wx_get_preamble(struct net_device *dev,
9894 struct iw_request_info *info,
9895 union iwreq_data *wrqu, char *extra)
9896{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009897 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009898 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009899 if (priv->config & CFG_PREAMBLE_LONG)
9900 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9901 else
9902 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009903 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009904 return 0;
9905}
9906
James Ketrenosb095c382005-08-24 22:04:42 -05009907#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009908static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009909 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009910 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009911{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009912 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 int *parms = (int *)extra;
9914 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009915 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009916 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 if (enable) {
9918 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009919#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009920 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9921#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009922 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009923#endif
Tejun Heobcb6d912011-01-26 12:12:50 +01009924 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009926
James Ketrenos43f66a62005-03-25 12:31:53 -06009927 ipw_set_channel(priv, parms[1]);
9928 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009929 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009930 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009932 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009933 priv->net_dev->type = ARPHRD_ETHER;
Tejun Heobcb6d912011-01-26 12:12:50 +01009934 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009935 }
Zhu Yi46441512006-01-24 16:37:59 +08009936 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009937 return 0;
9938}
9939
Pavel Machek67fd6b42006-07-11 15:34:05 +02009940#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009941
Jeff Garzikbf794512005-07-31 13:07:26 -04009942static int ipw_wx_reset(struct net_device *dev,
9943 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009944 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009945{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009946 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009947 IPW_DEBUG_WX("RESET\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01009948 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009949 return 0;
9950}
James Ketrenosb095c382005-08-24 22:04:42 -05009951
James Ketrenosb095c382005-08-24 22:04:42 -05009952static int ipw_wx_sw_reset(struct net_device *dev,
9953 struct iw_request_info *info,
9954 union iwreq_data *wrqu, char *extra)
9955{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009956 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009957 union iwreq_data wrqu_sec = {
9958 .encoding = {
9959 .flags = IW_ENCODE_DISABLED,
9960 },
9961 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009962 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009963
9964 IPW_DEBUG_WX("SW_RESET\n");
9965
Zhu Yi46441512006-01-24 16:37:59 +08009966 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009967
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009968 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009969 if (!ret) {
9970 free_firmware();
9971 ipw_adapter_restart(priv);
9972 }
James Ketrenosb095c382005-08-24 22:04:42 -05009973
9974 /* The SW reset bit might have been toggled on by the 'disable'
9975 * module parameter, so take appropriate action */
9976 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9977
Zhu Yi46441512006-01-24 16:37:59 +08009978 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009979 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009980 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009981
9982 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9983 /* Configuration likely changed -- force [re]association */
9984 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9985 "reset.\n");
9986 if (!ipw_disassociate(priv))
9987 ipw_associate(priv);
9988 }
9989
Zhu Yi46441512006-01-24 16:37:59 +08009990 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009991
9992 return 0;
9993}
James Ketrenos43f66a62005-03-25 12:31:53 -06009994
9995/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009996static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -07009997 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
9998 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9999 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
10000 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
10001 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
10002 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
10003 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
10004 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
10005 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
10006 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
10007 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
10008 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10009 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10010 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10011 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10012 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10013 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10014 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10015 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10016 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10017 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10018 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10019 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10020 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10021 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10022 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10023 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10024 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10025 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10026 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10027 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10028 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10029 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10030 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10031 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10032 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10033 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10034 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10035 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10036 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10037 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010038};
10039
James Ketrenosb095c382005-08-24 22:04:42 -050010040enum {
10041 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10042 IPW_PRIV_GET_POWER,
10043 IPW_PRIV_SET_MODE,
10044 IPW_PRIV_GET_MODE,
10045 IPW_PRIV_SET_PREAMBLE,
10046 IPW_PRIV_GET_PREAMBLE,
10047 IPW_PRIV_RESET,
10048 IPW_PRIV_SW_RESET,
10049#ifdef CONFIG_IPW2200_MONITOR
10050 IPW_PRIV_SET_MONITOR,
10051#endif
10052};
James Ketrenos43f66a62005-03-25 12:31:53 -060010053
Jeff Garzikbf794512005-07-31 13:07:26 -040010054static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010056 .cmd = IPW_PRIV_SET_POWER,
10057 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10058 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010060 .cmd = IPW_PRIV_GET_POWER,
10061 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10062 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010063 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010064 .cmd = IPW_PRIV_SET_MODE,
10065 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10066 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010067 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010068 .cmd = IPW_PRIV_GET_MODE,
10069 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10070 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010072 .cmd = IPW_PRIV_SET_PREAMBLE,
10073 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10074 .name = "set_preamble"},
10075 {
10076 .cmd = IPW_PRIV_GET_PREAMBLE,
10077 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10078 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010079 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010080 IPW_PRIV_RESET,
10081 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010082 {
10083 IPW_PRIV_SW_RESET,
10084 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10085#ifdef CONFIG_IPW2200_MONITOR
10086 {
10087 IPW_PRIV_SET_MONITOR,
10088 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10089#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010090};
10091
10092static iw_handler ipw_priv_handler[] = {
10093 ipw_wx_set_powermode,
10094 ipw_wx_get_powermode,
10095 ipw_wx_set_wireless_mode,
10096 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010097 ipw_wx_set_preamble,
10098 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010099 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010100 ipw_wx_sw_reset,
10101#ifdef CONFIG_IPW2200_MONITOR
10102 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010103#endif
10104};
10105
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010106static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010107 .standard = ipw_wx_handlers,
10108 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10109 .num_private = ARRAY_SIZE(ipw_priv_handler),
10110 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10111 .private = ipw_priv_handler,
10112 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010113 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010114};
10115
James Ketrenos43f66a62005-03-25 12:31:53 -060010116/*
10117 * Get wireless statistics.
10118 * Called by /proc/net/wireless
10119 * Also called by SIOCGIWSTATS
10120 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010121static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010122{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010123 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010124 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010125
James Ketrenos43f66a62005-03-25 12:31:53 -060010126 wstats = &priv->wstats;
10127
James Ketrenosea2b26e2005-08-24 21:25:16 -050010128 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010129 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010130 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10131 * and associated; if not associcated, the values are all meaningless
10132 * anyway, so set them all to NULL and INVALID */
10133 if (!(priv->status & STATUS_ASSOCIATED)) {
10134 wstats->miss.beacon = 0;
10135 wstats->discard.retries = 0;
10136 wstats->qual.qual = 0;
10137 wstats->qual.level = 0;
10138 wstats->qual.noise = 0;
10139 wstats->qual.updated = 7;
10140 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010141 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010143 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010144
10145 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010146 wstats->qual.level = priv->exp_avg_rssi;
10147 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010148 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010149 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010150
10151 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10152 wstats->discard.retries = priv->last_tx_failures;
10153 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010154
James Ketrenos43f66a62005-03-25 12:31:53 -060010155/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10156 goto fail_get_ordinal;
10157 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010158
James Ketrenos43f66a62005-03-25 12:31:53 -060010159 return wstats;
10160}
10161
James Ketrenos43f66a62005-03-25 12:31:53 -060010162/* net device stuff */
10163
Arjan van de Ven858119e2006-01-14 13:20:43 -080010164static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010165{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010166 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010167 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010168 sys_config->answer_broadcast_ssid_probe = 0;
10169 sys_config->accept_all_data_frames = 0;
10170 sys_config->accept_non_directed_frames = 1;
10171 sys_config->exclude_unicast_unencrypted = 0;
10172 sys_config->disable_unicast_decryption = 1;
10173 sys_config->exclude_multicast_unencrypted = 0;
10174 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010175 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10176 antenna = CFG_SYS_ANTENNA_BOTH;
10177 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010178 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010179 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010180 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010181 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010182 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010183 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010184}
10185
10186static int ipw_net_open(struct net_device *dev)
10187{
James Ketrenos43f66a62005-03-25 12:31:53 -060010188 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010189 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010190 return 0;
10191}
10192
10193static int ipw_net_stop(struct net_device *dev)
10194{
10195 IPW_DEBUG_INFO("dev->close\n");
10196 netif_stop_queue(dev);
10197 return 0;
10198}
10199
10200/*
10201todo:
10202
10203modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010204we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010205*/
10206
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010207static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010208 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010209{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010210 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010211 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010212 int i = 0;
10213 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010214#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010215 int tx_id = ipw_get_tx_queue_number(priv, pri);
10216 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10217#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010218 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010219#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010220 struct clx2_queue *q = &txq->q;
10221 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010222 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010223
Zhu Yib8ddafd2008-11-27 13:42:20 +080010224 if (!(priv->status & STATUS_ASSOCIATED))
10225 goto drop;
10226
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010227 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010228 switch (priv->ieee->iw_mode) {
10229 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010230 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010231 id = ipw_find_station(priv, hdr->addr1);
10232 if (id == IPW_INVALID_STATION) {
10233 id = ipw_add_station(priv, hdr->addr1);
10234 if (id == IPW_INVALID_STATION) {
10235 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010236 "invalid cell: %pM\n",
10237 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010238 goto drop;
10239 }
10240 }
10241 break;
10242
10243 case IW_MODE_INFRA:
10244 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010245 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010246 id = 0;
10247 break;
10248 }
10249
10250 tfd = &txq->bd[q->first_empty];
10251 txq->txb[q->first_empty] = txb;
10252 memset(tfd, 0, sizeof(*tfd));
10253 tfd->u.data.station_number = id;
10254
10255 tfd->control_flags.message_type = TX_FRAME_TYPE;
10256 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10257
10258 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010259 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010260
James Ketrenos43f66a62005-03-25 12:31:53 -060010261 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010262 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010263 else
James Ketrenosb095c382005-08-24 22:04:42 -050010264 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010265
James Ketrenosea2b26e2005-08-24 21:25:16 -050010266 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10267 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010268
James Ketrenosc848d0a2005-08-24 21:56:24 -050010269 fc = le16_to_cpu(hdr->frame_ctl);
10270 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010271
10272 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10273
James Ketrenosb095c382005-08-24 22:04:42 -050010274 if (likely(unicast))
10275 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10276
10277 if (txb->encrypted && !priv->ieee->host_encrypt) {
10278 switch (priv->ieee->sec.level) {
10279 case SEC_LEVEL_3:
10280 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010281 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010282 /* XXX: ACK flag must be set for CCMP even if it
10283 * is a multicast/broadcast packet, because CCMP
10284 * group communication encrypted by GTK is
10285 * actually done by the AP. */
10286 if (!unicast)
10287 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10288
10289 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10290 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10291 tfd->u.data.key_index = 0;
10292 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10293 break;
10294 case SEC_LEVEL_2:
10295 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010296 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010297 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10298 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10299 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10300 break;
10301 case SEC_LEVEL_1:
10302 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010303 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010304 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10305 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010306 40)
10307 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10308 else
10309 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10310 break;
10311 case SEC_LEVEL_0:
10312 break;
10313 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010314 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010315 priv->ieee->sec.level);
10316 break;
10317 }
10318 } else
10319 /* No hardware encryption */
10320 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10321
Zhu Yie43e3c12006-04-13 17:20:45 +080010322#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010323 if (fc & IEEE80211_STYPE_QOS_DATA)
10324 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010325#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010326
James Ketrenos43f66a62005-03-25 12:31:53 -060010327 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010328 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10329 txb->nr_frags));
10330 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10331 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10332 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10333 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10334 i, le32_to_cpu(tfd->u.data.num_chunks),
10335 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010336 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010337 i, tfd->u.data.num_chunks,
10338 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010339 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010340 txb->fragments[i]->len - hdr_len);
10341
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010342 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010343 cpu_to_le32(pci_map_single
10344 (priv->pci_dev,
10345 txb->fragments[i]->data + hdr_len,
10346 txb->fragments[i]->len - hdr_len,
10347 PCI_DMA_TODEVICE));
10348 tfd->u.data.chunk_len[i] =
10349 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010350 }
10351
10352 if (i != txb->nr_frags) {
10353 struct sk_buff *skb;
10354 u16 remaining_bytes = 0;
10355 int j;
10356
10357 for (j = i; j < txb->nr_frags; j++)
10358 remaining_bytes += txb->fragments[j]->len - hdr_len;
10359
10360 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10361 remaining_bytes);
10362 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10363 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010364 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010365 for (j = i; j < txb->nr_frags; j++) {
10366 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010367
James Ketrenos43f66a62005-03-25 12:31:53 -060010368 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010369 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010370 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010371 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010372 }
10373 dev_kfree_skb_any(txb->fragments[i]);
10374 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010375 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010376 cpu_to_le32(pci_map_single
10377 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010378 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010379 PCI_DMA_TODEVICE));
10380
Marcin Slusarz5c058632008-02-13 00:06:12 +010010381 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010382 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010383 }
10384
10385 /* kick DMA */
10386 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10387 ipw_write32(priv, q->reg_w, q->first_empty);
10388
Dan Williams943dbef2008-02-14 17:49:41 -050010389 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010390 netif_stop_queue(priv->net_dev);
10391
James Ketrenos227d2dc2005-07-28 16:25:55 -050010392 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010393
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010394 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010395 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010396 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010397 return NETDEV_TX_OK;
10398}
10399
10400static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10401{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010402 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010403#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010404 int tx_id = ipw_get_tx_queue_number(priv, pri);
10405 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10406#else
10407 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010408#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010409
Dan Williams943dbef2008-02-14 17:49:41 -050010410 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010411 return 1;
10412
10413 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010414}
10415
Zhu Yid685b8c2006-04-13 17:20:27 +080010416#ifdef CONFIG_IPW2200_PROMISCUOUS
10417static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010418 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010419{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010420 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010421 struct ieee80211_hdr *hdr;
10422 u8 n;
10423 u16 filter = priv->prom_priv->filter;
10424 int hdr_only = 0;
10425
10426 if (filter & IPW_PROM_NO_TX)
10427 return;
10428
10429 memset(&dummystats, 0, sizeof(dummystats));
10430
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010431 /* Filtering of fragment chains is done against the first fragment */
Zhu Yid685b8c2006-04-13 17:20:27 +080010432 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010433 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010434 if (filter & IPW_PROM_NO_MGMT)
10435 return;
10436 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10437 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010438 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010439 if (filter & IPW_PROM_NO_CTL)
10440 return;
10441 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10442 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010443 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010444 if (filter & IPW_PROM_NO_DATA)
10445 return;
10446 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10447 hdr_only = 1;
10448 }
10449
10450 for(n=0; n<txb->nr_frags; ++n) {
10451 struct sk_buff *src = txb->fragments[n];
10452 struct sk_buff *dst;
10453 struct ieee80211_radiotap_header *rt_hdr;
10454 int len;
10455
10456 if (hdr_only) {
10457 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010458 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010459 } else
10460 len = src->len;
10461
Johannes Berg007e5dd2008-11-27 23:13:38 +010010462 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10463 if (!dst)
10464 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010465
10466 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10467
10468 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10469 rt_hdr->it_pad = 0;
10470 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010471 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010472
Al Viroe62e1ee2007-12-27 01:36:46 -050010473 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010474 ieee80211chan2mhz(priv->channel));
10475 if (priv->channel > 14) /* 802.11a */
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_5GHZ);
10479 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010480 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010481 cpu_to_le16(IEEE80211_CHAN_CCK |
10482 IEEE80211_CHAN_2GHZ);
10483 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010484 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010485 cpu_to_le16(IEEE80211_CHAN_OFDM |
10486 IEEE80211_CHAN_2GHZ);
10487
Al Viro743b84d2007-12-27 01:43:16 -050010488 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010489
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010490 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010491
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010492 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010493 dev_kfree_skb_any(dst);
10494 }
10495}
10496#endif
10497
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010498static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10499 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010500{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010501 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010502 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010503 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010504
10505 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010506 spin_lock_irqsave(&priv->lock, flags);
10507
Zhu Yid685b8c2006-04-13 17:20:27 +080010508#ifdef CONFIG_IPW2200_PROMISCUOUS
10509 if (rtap_iface && netif_running(priv->prom_net_dev))
10510 ipw_handle_promiscuous_tx(priv, txb);
10511#endif
10512
James Ketrenos227d2dc2005-07-28 16:25:55 -050010513 ret = ipw_tx_skb(priv, txb, pri);
10514 if (ret == NETDEV_TX_OK)
10515 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010516 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010517
James Ketrenos227d2dc2005-07-28 16:25:55 -050010518 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010519}
10520
James Ketrenos43f66a62005-03-25 12:31:53 -060010521static void ipw_net_set_multicast_list(struct net_device *dev)
10522{
10523
10524}
10525
10526static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10527{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010528 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010529 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010530
James Ketrenos43f66a62005-03-25 12:31:53 -060010531 if (!is_valid_ether_addr(addr->sa_data))
10532 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010533 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010534 priv->config |= CFG_CUSTOM_MAC;
10535 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010536 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10537 priv->net_dev->name, priv->mac_addr);
Tejun Heobcb6d912011-01-26 12:12:50 +010010538 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010539 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010540 return 0;
10541}
10542
Jeff Garzikbf794512005-07-31 13:07:26 -040010543static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010544 struct ethtool_drvinfo *info)
10545{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010546 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010547 char vers[64];
10548 char date[32];
10549 u32 len;
10550
Rick Jones1f80c232011-11-15 10:40:49 -080010551 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
10552 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
James Ketrenos43f66a62005-03-25 12:31:53 -060010553
10554 len = sizeof(vers);
10555 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10556 len = sizeof(date);
10557 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10558
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010559 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010560 vers, date);
Rick Jones1f80c232011-11-15 10:40:49 -080010561 strlcpy(info->bus_info, pci_name(p->pci_dev),
10562 sizeof(info->bus_info));
James Ketrenosb095c382005-08-24 22:04:42 -050010563 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010564}
10565
10566static u32 ipw_ethtool_get_link(struct net_device *dev)
10567{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010568 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010569 return (priv->status & STATUS_ASSOCIATED) != 0;
10570}
10571
10572static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10573{
James Ketrenosb095c382005-08-24 22:04:42 -050010574 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010575}
10576
10577static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010578 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010579{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010580 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010581
James Ketrenosb095c382005-08-24 22:04:42 -050010582 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010583 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010584 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010585 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010586 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010587 return 0;
10588}
10589
10590static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010591 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010592{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010593 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010594 int i;
10595
James Ketrenosb095c382005-08-24 22:04:42 -050010596 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010597 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010598 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010599 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010600 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10601 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010602 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010603 return 0;
10604}
10605
Jeff Garzik7282d492006-09-13 14:30:00 -040010606static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010607 .get_link = ipw_ethtool_get_link,
10608 .get_drvinfo = ipw_ethtool_get_drvinfo,
10609 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10610 .get_eeprom = ipw_ethtool_get_eeprom,
10611 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010612};
10613
David Howells7d12e782006-10-05 14:55:46 +010010614static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010615{
10616 struct ipw_priv *priv = data;
10617 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010618
James Ketrenos43f66a62005-03-25 12:31:53 -060010619 if (!priv)
10620 return IRQ_NONE;
10621
Zhu Yi89c318e2006-06-08 22:19:49 -070010622 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010623
10624 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010625 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010626 goto none;
10627 }
10628
James Ketrenosb095c382005-08-24 22:04:42 -050010629 inta = ipw_read32(priv, IPW_INTA_RW);
10630 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010631
James Ketrenos43f66a62005-03-25 12:31:53 -060010632 if (inta == 0xFFFFFFFF) {
10633 /* Hardware disappeared */
10634 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10635 goto none;
10636 }
10637
James Ketrenosb095c382005-08-24 22:04:42 -050010638 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010639 /* Shared interrupt */
10640 goto none;
10641 }
10642
10643 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010644 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010645
James Ketrenos43f66a62005-03-25 12:31:53 -060010646 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010647 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10648 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010649
James Ketrenos43f66a62005-03-25 12:31:53 -060010650 /* Cache INTA value for our tasklet */
10651 priv->isr_inta = inta;
10652
10653 tasklet_schedule(&priv->irq_tasklet);
10654
Zhu Yi89c318e2006-06-08 22:19:49 -070010655 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010656
10657 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010658 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010659 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010660 return IRQ_NONE;
10661}
10662
10663static void ipw_rf_kill(void *adapter)
10664{
10665 struct ipw_priv *priv = adapter;
10666 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010667
James Ketrenos43f66a62005-03-25 12:31:53 -060010668 spin_lock_irqsave(&priv->lock, flags);
10669
10670 if (rf_kill_active(priv)) {
10671 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010010672 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010673 goto exit_unlock;
10674 }
10675
10676 /* RF Kill is now disabled, so bring the device back up */
10677
10678 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10679 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10680 "device\n");
10681
10682 /* we can not do an adapter restart while inside an irq lock */
Tejun Heobcb6d912011-01-26 12:12:50 +010010683 schedule_work(&priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010684 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010685 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10686 "enabled\n");
10687
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010688 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010689 spin_unlock_irqrestore(&priv->lock, flags);
10690}
10691
David Howellsc4028952006-11-22 14:57:56 +000010692static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010693{
David Howellsc4028952006-11-22 14:57:56 +000010694 struct ipw_priv *priv =
10695 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010696 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010697 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010698 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010699}
10700
Adrian Bunka73e22b2006-01-21 01:39:42 +010010701static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010702{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010703 priv->last_seq_num = -1;
10704 priv->last_frag_num = -1;
10705 priv->last_packet_time = 0;
10706
James Ketrenosa613bff2005-08-24 21:43:11 -050010707 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010708
James Ketrenosc848d0a2005-08-24 21:56:24 -050010709 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010710 cancel_delayed_work(&priv->request_direct_scan);
10711 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010712 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010713 ipw_reset_stats(priv);
10714 /* Ensure the rate is updated immediately */
10715 priv->last_rate = ipw_get_current_rate(priv);
10716 ipw_gather_stats(priv);
10717 ipw_led_link_up(priv);
10718 notify_wx_assoc_event(priv);
10719
10720 if (priv->config & CFG_BACKGROUND_SCAN)
Tejun Heobcb6d912011-01-26 12:12:50 +010010721 schedule_delayed_work(&priv->request_scan, HZ);
James Ketrenosa613bff2005-08-24 21:43:11 -050010722}
10723
David Howellsc4028952006-11-22 14:57:56 +000010724static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010725{
David Howellsc4028952006-11-22 14:57:56 +000010726 struct ipw_priv *priv =
10727 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010728 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010729 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010730 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010731}
10732
Adrian Bunka73e22b2006-01-21 01:39:42 +010010733static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010734{
10735 ipw_led_link_down(priv);
10736 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010737 notify_wx_assoc_event(priv);
10738
10739 /* Cancel any queued work ... */
10740 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010741 cancel_delayed_work(&priv->request_direct_scan);
10742 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010743 cancel_delayed_work(&priv->adhoc_check);
10744 cancel_delayed_work(&priv->gather_stats);
10745
10746 ipw_reset_stats(priv);
10747
James Ketrenosafbf30a2005-08-25 00:05:33 -050010748 if (!(priv->status & STATUS_EXIT_PENDING)) {
10749 /* Queue up another scan... */
Tejun Heobcb6d912011-01-26 12:12:50 +010010750 schedule_delayed_work(&priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010751 } else
10752 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010753}
10754
David Howellsc4028952006-11-22 14:57:56 +000010755static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010756{
David Howellsc4028952006-11-22 14:57:56 +000010757 struct ipw_priv *priv =
10758 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010759 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010760 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010761 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010762}
10763
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010764static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010765{
10766 int ret = 0;
10767
James Ketrenos43f66a62005-03-25 12:31:53 -060010768 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010769 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010770
David Howellsc4028952006-11-22 14:57:56 +000010771 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10772 INIT_WORK(&priv->associate, ipw_bg_associate);
10773 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10774 INIT_WORK(&priv->system_config, ipw_system_config);
10775 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10776 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10777 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10778 INIT_WORK(&priv->up, ipw_bg_up);
10779 INIT_WORK(&priv->down, ipw_bg_down);
10780 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010781 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10782 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010783 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010784 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10785 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10786 INIT_WORK(&priv->roam, ipw_bg_roam);
10787 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10788 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10789 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10790 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10791 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10792 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10793 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010794
Zhu Yie43e3c12006-04-13 17:20:45 +080010795#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010796 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010797#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010798
10799 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10800 ipw_irq_tasklet, (unsigned long)priv);
10801
10802 return ret;
10803}
10804
James Ketrenos43f66a62005-03-25 12:31:53 -060010805static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010806 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010807{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010808 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010810 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010811 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010812 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010813 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010814 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010815 priv->ieee->sec.flags &= ~(1 << i);
10816 else {
10817 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010818 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010819 priv->ieee->sec.flags |= (1 << i);
10820 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010821 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010822 } else if (sec->level != SEC_LEVEL_1)
10823 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010824 }
10825
James Ketrenosb095c382005-08-24 22:04:42 -050010826 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010827 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010828 priv->ieee->sec.active_key = sec->active_key;
10829 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010830 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010831 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010832 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010833 } else
10834 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010835
10836 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010837 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10838 priv->ieee->sec.auth_mode = sec->auth_mode;
10839 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010840 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10841 priv->capability |= CAP_SHARED_KEY;
10842 else
10843 priv->capability &= ~CAP_SHARED_KEY;
10844 priv->status |= STATUS_SECURITY_UPDATED;
10845 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010846
James Ketrenosb095c382005-08-24 22:04:42 -050010847 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10848 priv->ieee->sec.flags |= SEC_ENABLED;
10849 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010850 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010851 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010852 priv->capability |= CAP_PRIVACY_ON;
10853 else
10854 priv->capability &= ~CAP_PRIVACY_ON;
10855 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010856
James Ketrenosafbf30a2005-08-25 00:05:33 -050010857 if (sec->flags & SEC_ENCRYPT)
10858 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010859
James Ketrenosb095c382005-08-24 22:04:42 -050010860 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10861 priv->ieee->sec.level = sec->level;
10862 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010863 priv->status |= STATUS_SECURITY_UPDATED;
10864 }
10865
Zhu Yi1fbfea52005-08-05 17:22:56 +080010866 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10867 ipw_set_hwcrypto_keys(priv);
10868
Jeff Garzikbf794512005-07-31 13:07:26 -040010869 /* To match current functionality of ipw2100 (which works well w/
10870 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010871 * privacy capability changes ... */
10872#if 0
10873 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010874 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010875 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010876 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010877 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010878 IPW_DEBUG_ASSOC("Disassociating due to capability "
10879 "change.\n");
10880 ipw_disassociate(priv);
10881 }
10882#endif
10883}
10884
Jeff Garzikbf794512005-07-31 13:07:26 -040010885static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010886 struct ipw_supported_rates *rates)
10887{
10888 /* TODO: Mask out rates based on priv->rates_mask */
10889
10890 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010891 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010893 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010894 rates->ieee_mode = IPW_A_MODE;
10895 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010896 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10897 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010898 break;
10899
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010900 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010901 rates->ieee_mode = IPW_G_MODE;
10902 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010903 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10904 LIBIPW_CCK_DEFAULT_RATES_MASK);
10905 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10906 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10907 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010908 }
10909 break;
10910 }
10911
10912 return 0;
10913}
10914
Jeff Garzikbf794512005-07-31 13:07:26 -040010915static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010916{
James Ketrenos43f66a62005-03-25 12:31:53 -060010917 /* This is only called from ipw_up, which resets/reloads the firmware
10918 so, we don't need to first disable the card before we configure
10919 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010920 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010921 goto error;
10922
10923 /* initialize adapter address */
10924 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10925 goto error;
10926
10927 /* set basic system config settings */
10928 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010929
10930 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10931 * Does not support BT priority yet (don't abort or defer our Tx) */
10932 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010933 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010934
10935 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10936 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010937 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010938 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10939 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010940 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010941 }
10942
Zhu Yid685b8c2006-04-13 17:20:27 +080010943#ifdef CONFIG_IPW2200_PROMISCUOUS
10944 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10945 priv->sys_config.accept_all_data_frames = 1;
10946 priv->sys_config.accept_non_directed_frames = 1;
10947 priv->sys_config.accept_all_mgmt_bcpr = 1;
10948 priv->sys_config.accept_all_mgmt_frames = 1;
10949 }
10950#endif
10951
James Ketrenosc848d0a2005-08-24 21:56:24 -050010952 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10953 priv->sys_config.answer_broadcast_ssid_probe = 1;
10954 else
10955 priv->sys_config.answer_broadcast_ssid_probe = 0;
10956
Zhu Yid685b8c2006-04-13 17:20:27 +080010957 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010958 goto error;
10959
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010960 init_supported_rates(priv, &priv->rates);
10961 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010962 goto error;
10963
10964 /* Set request-to-send threshold */
10965 if (priv->rts_threshold) {
10966 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10967 goto error;
10968 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010969#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010970 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10971 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010972#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010973
10974 if (ipw_set_random_seed(priv))
10975 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010976
James Ketrenos43f66a62005-03-25 12:31:53 -060010977 /* final state transition to the RUN state */
10978 if (ipw_send_host_complete(priv))
10979 goto error;
10980
James Ketrenose6666192005-08-12 09:17:04 -050010981 priv->status |= STATUS_INIT;
10982
10983 ipw_led_init(priv);
10984 ipw_led_radio_on(priv);
10985 priv->notif_missed_beacons = 0;
10986
10987 /* Set hardware WEP key if it is configured. */
10988 if ((priv->capability & CAP_PRIVACY_ON) &&
10989 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10990 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10991 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010992
10993 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010994
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010995 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010996 return -EIO;
10997}
10998
James Ketrenos4f36f802005-08-03 20:36:56 -050010999/*
11000 * NOTE:
11001 *
11002 * These tables have been tested in conjunction with the
11003 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11004 *
11005 * Altering this values, using it on other hardware, or in geographies
11006 * not intended for resale of the above mentioned Intel adapters has
11007 * not been tested.
11008 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011009 * Remember to update the table in README.ipw2200 when changing this
11010 * table.
11011 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011012 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011013static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011014 { /* Restricted */
11015 "---",
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 },
11022
11023 { /* Custom US/Canada */
11024 "ZZF",
11025 .bg_channels = 11,
11026 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11027 {2427, 4}, {2432, 5}, {2437, 6},
11028 {2442, 7}, {2447, 8}, {2452, 9},
11029 {2457, 10}, {2462, 11}},
11030 .a_channels = 8,
11031 .a = {{5180, 36},
11032 {5200, 40},
11033 {5220, 44},
11034 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011035 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11036 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11037 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11038 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011039 },
11040
11041 { /* Rest of World */
11042 "ZZD",
11043 .bg_channels = 13,
11044 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11}, {2467, 12},
11048 {2472, 13}},
11049 },
11050
11051 { /* Custom USA & Europe & High */
11052 "ZZA",
11053 .bg_channels = 11,
11054 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11055 {2427, 4}, {2432, 5}, {2437, 6},
11056 {2442, 7}, {2447, 8}, {2452, 9},
11057 {2457, 10}, {2462, 11}},
11058 .a_channels = 13,
11059 .a = {{5180, 36},
11060 {5200, 40},
11061 {5220, 44},
11062 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011063 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11064 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11065 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11066 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011067 {5745, 149},
11068 {5765, 153},
11069 {5785, 157},
11070 {5805, 161},
11071 {5825, 165}},
11072 },
11073
11074 { /* Custom NA & Europe */
11075 "ZZB",
11076 .bg_channels = 11,
11077 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11078 {2427, 4}, {2432, 5}, {2437, 6},
11079 {2442, 7}, {2447, 8}, {2452, 9},
11080 {2457, 10}, {2462, 11}},
11081 .a_channels = 13,
11082 .a = {{5180, 36},
11083 {5200, 40},
11084 {5220, 44},
11085 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011086 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11087 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11088 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11089 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11090 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11091 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11092 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11093 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11094 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011095 },
11096
11097 { /* Custom Japan */
11098 "ZZC",
11099 .bg_channels = 11,
11100 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11101 {2427, 4}, {2432, 5}, {2437, 6},
11102 {2442, 7}, {2447, 8}, {2452, 9},
11103 {2457, 10}, {2462, 11}},
11104 .a_channels = 4,
11105 .a = {{5170, 34}, {5190, 38},
11106 {5210, 42}, {5230, 46}},
11107 },
11108
11109 { /* Custom */
11110 "ZZM",
11111 .bg_channels = 11,
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}},
11116 },
11117
11118 { /* Europe */
11119 "ZZE",
11120 .bg_channels = 13,
11121 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11122 {2427, 4}, {2432, 5}, {2437, 6},
11123 {2442, 7}, {2447, 8}, {2452, 9},
11124 {2457, 10}, {2462, 11}, {2467, 12},
11125 {2472, 13}},
11126 .a_channels = 19,
11127 .a = {{5180, 36},
11128 {5200, 40},
11129 {5220, 44},
11130 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011131 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11132 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11133 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11134 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11135 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11136 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11137 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11138 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11139 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11140 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11141 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11142 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11143 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11144 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11145 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011146 },
11147
11148 { /* Custom Japan */
11149 "ZZJ",
11150 .bg_channels = 14,
11151 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11152 {2427, 4}, {2432, 5}, {2437, 6},
11153 {2442, 7}, {2447, 8}, {2452, 9},
11154 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011155 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011156 .a_channels = 4,
11157 .a = {{5170, 34}, {5190, 38},
11158 {5210, 42}, {5230, 46}},
11159 },
11160
James Ketrenos03520572005-10-19 16:12:31 -050011161 { /* Rest of World */
11162 "ZZR",
11163 .bg_channels = 14,
11164 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11165 {2427, 4}, {2432, 5}, {2437, 6},
11166 {2442, 7}, {2447, 8}, {2452, 9},
11167 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011168 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11169 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011170 },
11171
James Ketrenos4f36f802005-08-03 20:36:56 -050011172 { /* High Band */
11173 "ZZH",
11174 .bg_channels = 13,
11175 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11176 {2427, 4}, {2432, 5}, {2437, 6},
11177 {2442, 7}, {2447, 8}, {2452, 9},
11178 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011179 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11180 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011181 .a_channels = 4,
11182 .a = {{5745, 149}, {5765, 153},
11183 {5785, 157}, {5805, 161}},
11184 },
11185
11186 { /* Custom Europe */
11187 "ZZG",
11188 .bg_channels = 13,
11189 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11190 {2427, 4}, {2432, 5}, {2437, 6},
11191 {2442, 7}, {2447, 8}, {2452, 9},
11192 {2457, 10}, {2462, 11},
11193 {2467, 12}, {2472, 13}},
11194 .a_channels = 4,
11195 .a = {{5180, 36}, {5200, 40},
11196 {5220, 44}, {5240, 48}},
11197 },
11198
11199 { /* Europe */
11200 "ZZK",
11201 .bg_channels = 13,
11202 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11203 {2427, 4}, {2432, 5}, {2437, 6},
11204 {2442, 7}, {2447, 8}, {2452, 9},
11205 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011206 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11207 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011208 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011209 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11210 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11211 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11212 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11213 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11214 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11215 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11216 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11217 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11218 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11219 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11220 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11221 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11222 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11223 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11224 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11225 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11226 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11227 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11228 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11229 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11230 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11231 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11232 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011233 },
11234
11235 { /* Europe */
11236 "ZZL",
11237 .bg_channels = 11,
11238 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11239 {2427, 4}, {2432, 5}, {2437, 6},
11240 {2442, 7}, {2447, 8}, {2452, 9},
11241 {2457, 10}, {2462, 11}},
11242 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011243 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11244 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11245 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11246 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11247 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11248 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11249 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11250 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11251 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11252 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11253 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11254 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11255 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011256 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011257};
11258
James Ketrenos43f66a62005-03-25 12:31:53 -060011259#define MAX_HW_RESTARTS 5
11260static int ipw_up(struct ipw_priv *priv)
11261{
James Ketrenos4f36f802005-08-03 20:36:56 -050011262 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011263
Dan Williamsc3d72b92009-02-11 13:26:06 -050011264 /* Age scan list entries found before suspend */
11265 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011266 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011267 priv->suspend_time = 0;
11268 }
11269
James Ketrenos43f66a62005-03-25 12:31:53 -060011270 if (priv->status & STATUS_EXIT_PENDING)
11271 return -EIO;
11272
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011273 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011274 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011275 GFP_KERNEL);
11276 if (priv->cmdlog == NULL) {
11277 IPW_ERROR("Error allocating %d command log entries.\n",
11278 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011279 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011280 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011281 priv->cmdlog_len = cmdlog;
11282 }
11283 }
11284
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011285 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011286 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011287 * Also start the clocks. */
11288 rc = ipw_load(priv);
11289 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011290 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011291 return rc;
11292 }
11293
11294 ipw_init_ordinals(priv);
11295 if (!(priv->config & CFG_CUSTOM_MAC))
11296 eeprom_parse_mac(priv, priv->mac_addr);
11297 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011298 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011299
James Ketrenos4f36f802005-08-03 20:36:56 -050011300 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11301 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11302 ipw_geos[j].name, 3))
11303 break;
11304 }
James Ketrenos03520572005-10-19 16:12:31 -050011305 if (j == ARRAY_SIZE(ipw_geos)) {
11306 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11307 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11308 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11309 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011310 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011311 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011312 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011313 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011314 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011315 }
11316
James Ketrenosb095c382005-08-24 22:04:42 -050011317 if (priv->status & STATUS_RF_KILL_SW) {
11318 IPW_WARNING("Radio disabled by module parameter.\n");
11319 return 0;
11320 } else if (rf_kill_active(priv)) {
11321 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11322 "Kill switch must be turned off for "
11323 "wireless networking to work.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010011324 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011325 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011326 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011327
11328 rc = ipw_config(priv);
11329 if (!rc) {
11330 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011331
James Ketrenose6666192005-08-12 09:17:04 -050011332 /* If configure to try and auto-associate, kick
11333 * off a scan. */
Tejun Heobcb6d912011-01-26 12:12:50 +010011334 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011335
James Ketrenos43f66a62005-03-25 12:31:53 -060011336 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011337 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011338
James Ketrenosc848d0a2005-08-24 21:56:24 -050011339 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011340 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11341 i, MAX_HW_RESTARTS);
11342
11343 /* We had an error bringing up the hardware, so take it
11344 * all the way back down so we can try again */
11345 ipw_down(priv);
11346 }
11347
Jeff Garzikbf794512005-07-31 13:07:26 -040011348 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011349 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011350 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011351
James Ketrenos43f66a62005-03-25 12:31:53 -060011352 return -EIO;
11353}
11354
David Howellsc4028952006-11-22 14:57:56 +000011355static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011356{
David Howellsc4028952006-11-22 14:57:56 +000011357 struct ipw_priv *priv =
11358 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011359 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011360 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011361 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011362}
11363
James Ketrenosb095c382005-08-24 22:04:42 -050011364static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011365{
James Ketrenosb095c382005-08-24 22:04:42 -050011366 int i;
11367
11368 if (priv->status & STATUS_SCANNING) {
11369 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11370 ipw_abort_scan(priv);
11371 }
11372
11373 if (priv->status & STATUS_ASSOCIATED) {
11374 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11375 ipw_disassociate(priv);
11376 }
11377
11378 ipw_led_shutdown(priv);
11379
11380 /* Wait up to 1s for status to change to not scanning and not
11381 * associated (disassociation can take a while for a ful 802.11
11382 * exchange */
11383 for (i = 1000; i && (priv->status &
11384 (STATUS_DISASSOCIATING |
11385 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11386 udelay(10);
11387
11388 if (priv->status & (STATUS_DISASSOCIATING |
11389 STATUS_ASSOCIATED | STATUS_SCANNING))
11390 IPW_DEBUG_INFO("Still associated or scanning...\n");
11391 else
11392 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11393
James Ketrenosc848d0a2005-08-24 21:56:24 -050011394 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011395 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011396
11397 priv->status &= ~STATUS_INIT;
11398}
11399
James Ketrenos43f66a62005-03-25 12:31:53 -060011400static void ipw_down(struct ipw_priv *priv)
11401{
James Ketrenosb095c382005-08-24 22:04:42 -050011402 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11403
11404 priv->status |= STATUS_EXIT_PENDING;
11405
11406 if (ipw_is_init(priv))
11407 ipw_deinit(priv);
11408
11409 /* Wipe out the EXIT_PENDING status bit if we are not actually
11410 * exiting the module */
11411 if (!exit_pending)
11412 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011413
11414 /* tell the device to stop sending interrupts */
11415 ipw_disable_interrupts(priv);
11416
11417 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011418 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011419 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011420
11421 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011422
11423 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011424}
11425
David Howellsc4028952006-11-22 14:57:56 +000011426static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011427{
David Howellsc4028952006-11-22 14:57:56 +000011428 struct ipw_priv *priv =
11429 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011430 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011431 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011432 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011433}
11434
11435/* Called by register_netdev() */
11436static int ipw_net_init(struct net_device *dev)
11437{
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011438 int rc = 0;
11439 struct ipw_priv *priv = libipw_priv(dev);
11440
11441 mutex_lock(&priv->mutex);
11442 if (ipw_up(priv))
11443 rc = -EIO;
11444 mutex_unlock(&priv->mutex);
11445
11446 return rc;
11447}
11448
11449static int ipw_wdev_init(struct net_device *dev)
11450{
John W. Linvillea3caa992009-08-25 14:12:25 -040011451 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011452 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011453 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11454 struct wireless_dev *wdev = &priv->ieee->wdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011455
John W. Linvillea3caa992009-08-25 14:12:25 -040011456 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11457
11458 /* fill-out priv->ieee->bg_band */
11459 if (geo->bg_channels) {
11460 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11461
11462 bg_band->band = IEEE80211_BAND_2GHZ;
11463 bg_band->n_channels = geo->bg_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011464 bg_band->channels = kcalloc(geo->bg_channels,
11465 sizeof(struct ieee80211_channel),
11466 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011467 if (!bg_band->channels) {
11468 rc = -ENOMEM;
11469 goto out;
11470 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011471 /* translate geo->bg to bg_band.channels */
11472 for (i = 0; i < geo->bg_channels; i++) {
11473 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11474 bg_band->channels[i].center_freq = geo->bg[i].freq;
11475 bg_band->channels[i].hw_value = geo->bg[i].channel;
11476 bg_band->channels[i].max_power = geo->bg[i].max_power;
11477 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11478 bg_band->channels[i].flags |=
11479 IEEE80211_CHAN_PASSIVE_SCAN;
11480 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11481 bg_band->channels[i].flags |=
11482 IEEE80211_CHAN_NO_IBSS;
11483 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11484 bg_band->channels[i].flags |=
11485 IEEE80211_CHAN_RADAR;
11486 /* No equivalent for LIBIPW_CH_80211H_RULES,
11487 LIBIPW_CH_UNIFORM_SPREADING, or
11488 LIBIPW_CH_B_ONLY... */
11489 }
11490 /* point at bitrate info */
11491 bg_band->bitrates = ipw2200_bg_rates;
11492 bg_band->n_bitrates = ipw2200_num_bg_rates;
11493
11494 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11495 }
11496
11497 /* fill-out priv->ieee->a_band */
11498 if (geo->a_channels) {
11499 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11500
11501 a_band->band = IEEE80211_BAND_5GHZ;
11502 a_band->n_channels = geo->a_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011503 a_band->channels = kcalloc(geo->a_channels,
11504 sizeof(struct ieee80211_channel),
11505 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011506 if (!a_band->channels) {
11507 rc = -ENOMEM;
11508 goto out;
11509 }
Stanislav Yakovlev75836b82012-03-20 17:52:57 -040011510 /* translate geo->a to a_band.channels */
John W. Linvillea3caa992009-08-25 14:12:25 -040011511 for (i = 0; i < geo->a_channels; i++) {
Stanislav Yakovlev75836b82012-03-20 17:52:57 -040011512 a_band->channels[i].band = IEEE80211_BAND_5GHZ;
John W. Linvillea3caa992009-08-25 14:12:25 -040011513 a_band->channels[i].center_freq = geo->a[i].freq;
11514 a_band->channels[i].hw_value = geo->a[i].channel;
11515 a_band->channels[i].max_power = geo->a[i].max_power;
11516 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11517 a_band->channels[i].flags |=
11518 IEEE80211_CHAN_PASSIVE_SCAN;
11519 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11520 a_band->channels[i].flags |=
11521 IEEE80211_CHAN_NO_IBSS;
11522 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11523 a_band->channels[i].flags |=
11524 IEEE80211_CHAN_RADAR;
11525 /* No equivalent for LIBIPW_CH_80211H_RULES,
11526 LIBIPW_CH_UNIFORM_SPREADING, or
11527 LIBIPW_CH_B_ONLY... */
11528 }
11529 /* point at bitrate info */
11530 a_band->bitrates = ipw2200_a_rates;
11531 a_band->n_bitrates = ipw2200_num_a_rates;
11532
11533 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11534 }
11535
11536 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11537
11538 /* With that information in place, we can now register the wiphy... */
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011539 if (wiphy_register(wdev->wiphy))
John W. Linvillea3caa992009-08-25 14:12:25 -040011540 rc = -EIO;
John W. Linvillea3caa992009-08-25 14:12:25 -040011541out:
John W. Linvillea3caa992009-08-25 14:12:25 -040011542 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011543}
11544
11545/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011546static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11552 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11553 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11554 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11555 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11556 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11557 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11558 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11559 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11560 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11561 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11562 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11563 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011564 {PCI_VDEVICE(INTEL, 0x104f), 0},
11565 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11566 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11567 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11568 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011569
James Ketrenos43f66a62005-03-25 12:31:53 -060011570 /* required last entry */
11571 {0,}
11572};
11573
11574MODULE_DEVICE_TABLE(pci, card_ids);
11575
11576static struct attribute *ipw_sysfs_entries[] = {
11577 &dev_attr_rf_kill.attr,
11578 &dev_attr_direct_dword.attr,
11579 &dev_attr_indirect_byte.attr,
11580 &dev_attr_indirect_dword.attr,
11581 &dev_attr_mem_gpio_reg.attr,
11582 &dev_attr_command_event_reg.attr,
11583 &dev_attr_nic_type.attr,
11584 &dev_attr_status.attr,
11585 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011586 &dev_attr_error.attr,
11587 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011588 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011589 &dev_attr_eeprom_delay.attr,
11590 &dev_attr_ucode_version.attr,
11591 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011592 &dev_attr_scan_age.attr,
11593 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011594 &dev_attr_speed_scan.attr,
11595 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011596 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011597#ifdef CONFIG_IPW2200_PROMISCUOUS
11598 &dev_attr_rtap_iface.attr,
11599 &dev_attr_rtap_filter.attr,
11600#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011601 NULL
11602};
11603
11604static struct attribute_group ipw_attribute_group = {
11605 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011606 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011607};
11608
Zhu Yid685b8c2006-04-13 17:20:27 +080011609#ifdef CONFIG_IPW2200_PROMISCUOUS
11610static int ipw_prom_open(struct net_device *dev)
11611{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011612 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011613 struct ipw_priv *priv = prom_priv->priv;
11614
11615 IPW_DEBUG_INFO("prom dev->open\n");
11616 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011617
11618 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11619 priv->sys_config.accept_all_data_frames = 1;
11620 priv->sys_config.accept_non_directed_frames = 1;
11621 priv->sys_config.accept_all_mgmt_bcpr = 1;
11622 priv->sys_config.accept_all_mgmt_frames = 1;
11623
11624 ipw_send_system_config(priv);
11625 }
11626
11627 return 0;
11628}
11629
11630static int ipw_prom_stop(struct net_device *dev)
11631{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011632 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011633 struct ipw_priv *priv = prom_priv->priv;
11634
11635 IPW_DEBUG_INFO("prom dev->stop\n");
11636
11637 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11638 priv->sys_config.accept_all_data_frames = 0;
11639 priv->sys_config.accept_non_directed_frames = 0;
11640 priv->sys_config.accept_all_mgmt_bcpr = 0;
11641 priv->sys_config.accept_all_mgmt_frames = 0;
11642
11643 ipw_send_system_config(priv);
11644 }
11645
11646 return 0;
11647}
11648
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011649static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11650 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011651{
11652 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011653 dev_kfree_skb(skb);
11654 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011655}
11656
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011657static const struct net_device_ops ipw_prom_netdev_ops = {
11658 .ndo_open = ipw_prom_open,
11659 .ndo_stop = ipw_prom_stop,
11660 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011661 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011662 .ndo_set_mac_address = eth_mac_addr,
11663 .ndo_validate_addr = eth_validate_addr,
11664};
11665
Zhu Yid685b8c2006-04-13 17:20:27 +080011666static int ipw_prom_alloc(struct ipw_priv *priv)
11667{
11668 int rc = 0;
11669
11670 if (priv->prom_net_dev)
11671 return -EPERM;
11672
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011673 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011674 if (priv->prom_net_dev == NULL)
11675 return -ENOMEM;
11676
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011677 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011678 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11679 priv->prom_priv->priv = priv;
11680
11681 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011682 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011683
11684 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011685 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011686
11687 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011688 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011689
11690 rc = register_netdev(priv->prom_net_dev);
11691 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011692 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011693 priv->prom_net_dev = NULL;
11694 return rc;
11695 }
11696
11697 return 0;
11698}
11699
11700static void ipw_prom_free(struct ipw_priv *priv)
11701{
11702 if (!priv->prom_net_dev)
11703 return;
11704
11705 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011706 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011707
11708 priv->prom_net_dev = NULL;
11709}
11710
11711#endif
11712
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011713static const struct net_device_ops ipw_netdev_ops = {
11714 .ndo_init = ipw_net_init,
11715 .ndo_open = ipw_net_open,
11716 .ndo_stop = ipw_net_stop,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000011717 .ndo_set_rx_mode = ipw_net_set_multicast_list,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011718 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011719 .ndo_start_xmit = libipw_xmit,
11720 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011721 .ndo_validate_addr = eth_validate_addr,
11722};
Zhu Yid685b8c2006-04-13 17:20:27 +080011723
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011724static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11725 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011726{
11727 int err = 0;
11728 struct net_device *net_dev;
11729 void __iomem *base;
11730 u32 length, val;
11731 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011732 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011733
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011734 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011735 if (net_dev == NULL) {
11736 err = -ENOMEM;
11737 goto out;
11738 }
11739
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011740 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011741 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011742
James Ketrenos43f66a62005-03-25 12:31:53 -060011743 priv->net_dev = net_dev;
11744 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011745 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011746 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011747 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011748 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11749 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011750
Zhu Yi46441512006-01-24 16:37:59 +080011751 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011752 if (pci_enable_device(pdev)) {
11753 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011754 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011755 }
11756
11757 pci_set_master(pdev);
11758
Yang Hongyang284901a2009-04-06 19:01:15 -070011759 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011760 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011761 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011762 if (err) {
11763 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11764 goto out_pci_disable_device;
11765 }
11766
11767 pci_set_drvdata(pdev, priv);
11768
11769 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011770 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011771 goto out_pci_disable_device;
11772
Jeff Garzikbf794512005-07-31 13:07:26 -040011773 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011774 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011775 pci_read_config_dword(pdev, 0x40, &val);
11776 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011777 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011778
James Ketrenos43f66a62005-03-25 12:31:53 -060011779 length = pci_resource_len(pdev, 0);
11780 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011781
Arjan van de Ven275f1652008-10-20 21:42:39 -070011782 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011783 if (!base) {
11784 err = -ENODEV;
11785 goto out_pci_release_regions;
11786 }
11787
11788 priv->hw_base = base;
11789 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11790 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11791
11792 err = ipw_setup_deferred_work(priv);
11793 if (err) {
11794 IPW_ERROR("Unable to setup deferred work\n");
11795 goto out_iounmap;
11796 }
11797
James Ketrenosb095c382005-08-24 22:04:42 -050011798 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011799
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011800 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011801 if (err) {
11802 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
Tejun Heobcb6d912011-01-26 12:12:50 +010011803 goto out_iounmap;
James Ketrenos43f66a62005-03-25 12:31:53 -060011804 }
11805
James Ketrenos43f66a62005-03-25 12:31:53 -060011806 SET_NETDEV_DEV(net_dev, &pdev->dev);
11807
Zhu Yi46441512006-01-24 16:37:59 +080011808 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011809
James Ketrenos43f66a62005-03-25 12:31:53 -060011810 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11811 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011812 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011813
Zhu Yie43e3c12006-04-13 17:20:45 +080011814#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011815 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011816 priv->ieee->handle_probe_response = ipw_handle_beacon;
11817 priv->ieee->handle_beacon = ipw_handle_probe_response;
11818 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011819#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011820
James Ketrenosc848d0a2005-08-24 21:56:24 -050011821 priv->ieee->perfect_rssi = -20;
11822 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011823
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011824 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011825 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011826 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011827 net_dev->wireless_handlers = &ipw_wx_handler_def;
11828 net_dev->ethtool_ops = &ipw_ethtool_ops;
11829 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011830 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011831 net_dev->mem_start = pci_resource_start(pdev, 0);
11832 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11833
11834 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11835 if (err) {
11836 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011837 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011838 goto out_release_irq;
11839 }
11840
Zhu Yi46441512006-01-24 16:37:59 +080011841 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011842 err = register_netdev(net_dev);
11843 if (err) {
11844 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011845 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011846 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011847
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011848 err = ipw_wdev_init(net_dev);
11849 if (err) {
11850 IPW_ERROR("failed to register wireless device\n");
11851 goto out_unregister_netdev;
11852 }
11853
Zhu Yid685b8c2006-04-13 17:20:27 +080011854#ifdef CONFIG_IPW2200_PROMISCUOUS
11855 if (rtap_iface) {
11856 err = ipw_prom_alloc(priv);
11857 if (err) {
11858 IPW_ERROR("Failed to register promiscuous network "
11859 "device (error %d).\n", err);
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011860 wiphy_unregister(priv->ieee->wdev.wiphy);
11861 kfree(priv->ieee->a_band.channels);
11862 kfree(priv->ieee->bg_band.channels);
11863 goto out_unregister_netdev;
Zhu Yid685b8c2006-04-13 17:20:27 +080011864 }
11865 }
11866#endif
11867
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011868 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11869 "channels, %d 802.11a channels)\n",
11870 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11871 priv->ieee->geo.a_channels);
11872
James Ketrenos43f66a62005-03-25 12:31:53 -060011873 return 0;
11874
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011875 out_unregister_netdev:
11876 unregister_netdev(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011877 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011878 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011879 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011880 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011881 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011882 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011883 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011884 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011885 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011886 pci_disable_device(pdev);
11887 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011888 out_free_libipw:
11889 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011890 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011891 return err;
11892}
11893
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011894static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011895{
11896 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011897 struct list_head *p, *q;
11898 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011899
James Ketrenos43f66a62005-03-25 12:31:53 -060011900 if (!priv)
11901 return;
11902
Zhu Yi46441512006-01-24 16:37:59 +080011903 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011904
James Ketrenosafbf30a2005-08-25 00:05:33 -050011905 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011906 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011907 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11908
Zhu Yi46441512006-01-24 16:37:59 +080011909 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011910
11911 unregister_netdev(priv->net_dev);
11912
11913 if (priv->rxq) {
11914 ipw_rx_queue_free(priv, priv->rxq);
11915 priv->rxq = NULL;
11916 }
11917 ipw_tx_queue_free(priv);
11918
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011919 if (priv->cmdlog) {
11920 kfree(priv->cmdlog);
11921 priv->cmdlog = NULL;
11922 }
Tejun Heobcb6d912011-01-26 12:12:50 +010011923
11924 /* make sure all works are inactive */
11925 cancel_delayed_work_sync(&priv->adhoc_check);
11926 cancel_work_sync(&priv->associate);
11927 cancel_work_sync(&priv->disassociate);
11928 cancel_work_sync(&priv->system_config);
11929 cancel_work_sync(&priv->rx_replenish);
11930 cancel_work_sync(&priv->adapter_restart);
11931 cancel_delayed_work_sync(&priv->rf_kill);
11932 cancel_work_sync(&priv->up);
11933 cancel_work_sync(&priv->down);
11934 cancel_delayed_work_sync(&priv->request_scan);
11935 cancel_delayed_work_sync(&priv->request_direct_scan);
11936 cancel_delayed_work_sync(&priv->request_passive_scan);
11937 cancel_delayed_work_sync(&priv->scan_event);
11938 cancel_delayed_work_sync(&priv->gather_stats);
11939 cancel_work_sync(&priv->abort_scan);
11940 cancel_work_sync(&priv->roam);
11941 cancel_delayed_work_sync(&priv->scan_check);
11942 cancel_work_sync(&priv->link_up);
11943 cancel_work_sync(&priv->link_down);
11944 cancel_delayed_work_sync(&priv->led_link_on);
11945 cancel_delayed_work_sync(&priv->led_link_off);
11946 cancel_delayed_work_sync(&priv->led_act_off);
11947 cancel_work_sync(&priv->merge_networks);
James Ketrenos43f66a62005-03-25 12:31:53 -060011948
James Ketrenosafbf30a2005-08-25 00:05:33 -050011949 /* Free MAC hash list for ADHOC */
11950 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11951 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011952 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011953 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011954 }
11955 }
11956
Jesper Juhl8f760782006-06-27 02:55:06 -070011957 kfree(priv->error);
11958 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011959
Zhu Yid685b8c2006-04-13 17:20:27 +080011960#ifdef CONFIG_IPW2200_PROMISCUOUS
11961 ipw_prom_free(priv);
11962#endif
11963
James Ketrenos43f66a62005-03-25 12:31:53 -060011964 free_irq(pdev->irq, priv);
11965 iounmap(priv->hw_base);
11966 pci_release_regions(pdev);
11967 pci_disable_device(pdev);
11968 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011969 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011970 wiphy_unregister(priv->ieee->wdev.wiphy);
11971 kfree(priv->ieee->a_band.channels);
11972 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011973 free_libipw(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011974 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011975}
11976
James Ketrenos43f66a62005-03-25 12:31:53 -060011977#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011978static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011979{
11980 struct ipw_priv *priv = pci_get_drvdata(pdev);
11981 struct net_device *dev = priv->net_dev;
11982
11983 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11984
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011985 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011986 ipw_down(priv);
11987
11988 /* Remove the PRESENT state of the device */
11989 netif_device_detach(dev);
11990
James Ketrenos43f66a62005-03-25 12:31:53 -060011991 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011992 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011993 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011994
Dan Williamsc3d72b92009-02-11 13:26:06 -050011995 priv->suspend_at = get_seconds();
11996
James Ketrenos43f66a62005-03-25 12:31:53 -060011997 return 0;
11998}
11999
12000static int ipw_pci_resume(struct pci_dev *pdev)
12001{
12002 struct ipw_priv *priv = pci_get_drvdata(pdev);
12003 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050012004 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060012005 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040012006
James Ketrenos43f66a62005-03-25 12:31:53 -060012007 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
12008
James Ketrenosea2b26e2005-08-24 21:25:16 -050012009 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050012010 err = pci_enable_device(pdev);
12011 if (err) {
12012 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
12013 dev->name);
12014 return err;
12015 }
James Ketrenos43f66a62005-03-25 12:31:53 -060012016 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050012017
James Ketrenos43f66a62005-03-25 12:31:53 -060012018 /*
12019 * Suspend/Resume resets the PCI configuration space, so we have to
12020 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
12021 * from interfering with C3 CPU state. pci_restore_state won't help
12022 * here since it only restores the first 64 bytes pci config header.
12023 */
Jeff Garzikbf794512005-07-31 13:07:26 -040012024 pci_read_config_dword(pdev, 0x40, &val);
12025 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060012026 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12027
12028 /* Set the device back into the PRESENT state; this will also wake
12029 * the queue of needed */
12030 netif_device_attach(dev);
12031
Dan Williamsc3d72b92009-02-11 13:26:06 -050012032 priv->suspend_time = get_seconds() - priv->suspend_at;
12033
James Ketrenos43f66a62005-03-25 12:31:53 -060012034 /* Bring the device back up */
Tejun Heobcb6d912011-01-26 12:12:50 +010012035 schedule_work(&priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012036
James Ketrenos43f66a62005-03-25 12:31:53 -060012037 return 0;
12038}
12039#endif
12040
Zhu Yic8c22c92006-08-21 11:38:39 +080012041static void ipw_pci_shutdown(struct pci_dev *pdev)
12042{
12043 struct ipw_priv *priv = pci_get_drvdata(pdev);
12044
12045 /* Take down the device; powers it off, etc. */
12046 ipw_down(priv);
12047
12048 pci_disable_device(pdev);
12049}
12050
James Ketrenos43f66a62005-03-25 12:31:53 -060012051/* driver initialization stuff */
12052static struct pci_driver ipw_driver = {
12053 .name = DRV_NAME,
12054 .id_table = card_ids,
12055 .probe = ipw_pci_probe,
12056 .remove = __devexit_p(ipw_pci_remove),
12057#ifdef CONFIG_PM
12058 .suspend = ipw_pci_suspend,
12059 .resume = ipw_pci_resume,
12060#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012061 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012062};
12063
12064static int __init ipw_init(void)
12065{
12066 int ret;
12067
12068 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12069 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12070
Jeff Garzik29917622006-08-19 17:48:59 -040012071 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012072 if (ret) {
12073 IPW_ERROR("Unable to initialize PCI module\n");
12074 return ret;
12075 }
12076
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012077 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012078 if (ret) {
12079 IPW_ERROR("Unable to create driver sysfs file\n");
12080 pci_unregister_driver(&ipw_driver);
12081 return ret;
12082 }
12083
12084 return ret;
12085}
12086
12087static void __exit ipw_exit(void)
12088{
12089 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12090 pci_unregister_driver(&ipw_driver);
12091}
12092
12093module_param(disable, int, 0444);
12094MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12095
12096module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012097MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012098
12099module_param(auto_create, int, 0444);
12100MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12101
Reinette Chatre21f8a732009-08-18 10:25:05 -070012102module_param_named(led, led_support, int, 0444);
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000012103MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012104
James Ketrenos43f66a62005-03-25 12:31:53 -060012105module_param(debug, int, 0444);
12106MODULE_PARM_DESC(debug, "debug output mask");
12107
Reinette Chatre21f8a732009-08-18 10:25:05 -070012108module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012109MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012110
Zhu Yid685b8c2006-04-13 17:20:27 +080012111#ifdef CONFIG_IPW2200_PROMISCUOUS
12112module_param(rtap_iface, int, 0444);
12113MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12114#endif
12115
Zhu Yie43e3c12006-04-13 17:20:45 +080012116#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012117module_param(qos_enable, int, 0444);
12118MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012119
James Ketrenosb095c382005-08-24 22:04:42 -050012120module_param(qos_burst_enable, int, 0444);
12121MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12122
12123module_param(qos_no_ack_mask, int, 0444);
12124MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12125
12126module_param(burst_duration_CCK, int, 0444);
12127MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12128
12129module_param(burst_duration_OFDM, int, 0444);
12130MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012131#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012132
12133#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012134module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012135MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12136#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012137module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012138MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12139#endif
12140
Zhu Yi810dabd2006-01-24 16:36:59 +080012141module_param(bt_coexist, int, 0444);
12142MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12143
James Ketrenosb095c382005-08-24 22:04:42 -050012144module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012145MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012146
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012147module_param(cmdlog, int, 0444);
12148MODULE_PARM_DESC(cmdlog,
12149 "allocate a ring buffer for logging firmware commands");
12150
Zhu Yi4bfdb912006-01-24 16:37:16 +080012151module_param(roaming, int, 0444);
12152MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12153
Zhu Yid2b83e12006-04-13 17:19:36 +080012154module_param(antenna, int, 0444);
12155MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12156
James Ketrenos43f66a62005-03-25 12:31:53 -060012157module_exit(ipw_exit);
12158module_init(ipw_init);