blob: 77c5d2f5115a7373d76eb6a190faeaa4c0465749 [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);
Jesper Juhld144f532012-04-09 22:51:01 +02003660 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003661#ifdef CONFIG_PM
3662 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003663 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003664#endif
3665
3666 return rc;
3667}
3668
Jeff Garzikbf794512005-07-31 13:07:26 -04003669/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003670 * DMA services
3671 *
3672 * Theory of operation
3673 *
3674 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3675 * 2 empty entries always kept in the buffer to protect from overflow.
3676 *
3677 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003678 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3679 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003680 * Tx queue resumed.
3681 *
3682 * The IPW operates with six queues, one receive queue in the device's
3683 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003684 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003685 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003686 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003687 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003688 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003689 * we only utilize the first data transmit queue (queue1).
3690 */
3691
3692/**
3693 * Driver allocates buffers of this size for Rx
3694 */
3695
Dan Williams943dbef2008-02-14 17:49:41 -05003696/**
3697 * ipw_rx_queue_space - Return number of free slots available in queue.
3698 */
3699static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3700{
3701 int s = q->read - q->write;
3702 if (s <= 0)
3703 s += RX_QUEUE_SIZE;
3704 /* keep some buffer to not confuse full and empty queue */
3705 s -= 2;
3706 if (s < 0)
3707 s = 0;
3708 return s;
3709}
3710
3711static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003712{
3713 int s = q->last_used - q->first_empty;
3714 if (s <= 0)
3715 s += q->n_bd;
3716 s -= 2; /* keep some reserve to not confuse empty and full situations */
3717 if (s < 0)
3718 s = 0;
3719 return s;
3720}
3721
3722static inline int ipw_queue_inc_wrap(int index, int n_bd)
3723{
3724 return (++index == n_bd) ? 0 : index;
3725}
3726
3727/**
3728 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003729 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003730 * @param q queue to init
3731 * @param count Number of BD's to allocate. Should be power of 2
3732 * @param read_register Address for 'read' register
3733 * (not offset within BAR, full address)
3734 * @param write_register Address for 'write' register
3735 * (not offset within BAR, full address)
3736 * @param base_register Address for 'base' register
3737 * (not offset within BAR, full address)
3738 * @param size Address for 'size' register
3739 * (not offset within BAR, full address)
3740 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003741static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003742 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003743{
3744 q->n_bd = count;
3745
3746 q->low_mark = q->n_bd / 4;
3747 if (q->low_mark < 4)
3748 q->low_mark = 4;
3749
3750 q->high_mark = q->n_bd / 8;
3751 if (q->high_mark < 2)
3752 q->high_mark = 2;
3753
3754 q->first_empty = q->last_used = 0;
3755 q->reg_r = read;
3756 q->reg_w = write;
3757
3758 ipw_write32(priv, base, q->dma_addr);
3759 ipw_write32(priv, size, count);
3760 ipw_write32(priv, read, 0);
3761 ipw_write32(priv, write, 0);
3762
3763 _ipw_read32(priv, 0x90);
3764}
3765
Jeff Garzikbf794512005-07-31 13:07:26 -04003766static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003767 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003768 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003769{
3770 struct pci_dev *dev = priv->pci_dev;
3771
3772 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3773 if (!q->txb) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003774 IPW_ERROR("vmalloc for auxiliary BD structures failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003775 return -ENOMEM;
3776 }
3777
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003778 q->bd =
3779 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003780 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003781 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003782 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003783 kfree(q->txb);
3784 q->txb = NULL;
3785 return -ENOMEM;
3786 }
3787
3788 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3789 return 0;
3790}
3791
3792/**
3793 * Free one TFD, those at index [txq->q.last_used].
3794 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003795 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003796 * @param dev
3797 * @param txq
3798 */
3799static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3800 struct clx2_tx_queue *txq)
3801{
3802 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3803 struct pci_dev *dev = priv->pci_dev;
3804 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003805
James Ketrenos43f66a62005-03-25 12:31:53 -06003806 /* classify bd */
3807 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3808 /* nothing to cleanup after for host commands */
3809 return;
3810
3811 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003812 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3813 IPW_ERROR("Too many chunks: %i\n",
3814 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003815 /** @todo issue fatal error, it is quite serious situation */
3816 return;
3817 }
3818
3819 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003820 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3821 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3822 le16_to_cpu(bd->u.data.chunk_len[i]),
3823 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003824 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003825 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003826 txq->txb[txq->q.last_used] = NULL;
3827 }
3828 }
3829}
3830
3831/**
3832 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003833 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003834 * Empty queue by removing and destroying all BD's.
3835 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003836 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003837 * @param dev
3838 * @param q
3839 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003840static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003841{
3842 struct clx2_queue *q = &txq->q;
3843 struct pci_dev *dev = priv->pci_dev;
3844
Jeff Garzikbf794512005-07-31 13:07:26 -04003845 if (q->n_bd == 0)
3846 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003847
3848 /* first, empty all BD's */
3849 for (; q->first_empty != q->last_used;
3850 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3851 ipw_queue_tx_free_tfd(priv, txq);
3852 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003853
James Ketrenos43f66a62005-03-25 12:31:53 -06003854 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003855 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003856 q->dma_addr);
3857 kfree(txq->txb);
3858
3859 /* 0 fill whole structure */
3860 memset(txq, 0, sizeof(*txq));
3861}
3862
James Ketrenos43f66a62005-03-25 12:31:53 -06003863/**
3864 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003865 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003866 * @param priv
3867 */
3868static void ipw_tx_queue_free(struct ipw_priv *priv)
3869{
3870 /* Tx CMD queue */
3871 ipw_queue_tx_free(priv, &priv->txq_cmd);
3872
3873 /* Tx queues */
3874 ipw_queue_tx_free(priv, &priv->txq[0]);
3875 ipw_queue_tx_free(priv, &priv->txq[1]);
3876 ipw_queue_tx_free(priv, &priv->txq[2]);
3877 ipw_queue_tx_free(priv, &priv->txq[3]);
3878}
3879
Arjan van de Ven858119e2006-01-14 13:20:43 -08003880static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003881{
3882 /* First 3 bytes are manufacturer */
3883 bssid[0] = priv->mac_addr[0];
3884 bssid[1] = priv->mac_addr[1];
3885 bssid[2] = priv->mac_addr[2];
3886
3887 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003888 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003889
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003890 bssid[0] &= 0xfe; /* clear multicast bit */
3891 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003892}
3893
Arjan van de Ven858119e2006-01-14 13:20:43 -08003894static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003895{
3896 struct ipw_station_entry entry;
3897 int i;
3898
3899 for (i = 0; i < priv->num_stations; i++) {
3900 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3901 /* Another node is active in network */
3902 priv->missed_adhoc_beacons = 0;
3903 if (!(priv->config & CFG_STATIC_CHANNEL))
3904 /* when other nodes drop out, we drop out */
3905 priv->config &= ~CFG_ADHOC_PERSIST;
3906
3907 return i;
3908 }
3909 }
3910
3911 if (i == MAX_STATIONS)
3912 return IPW_INVALID_STATION;
3913
Johannes Berge1749612008-10-27 15:59:26 -07003914 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003915
3916 entry.reserved = 0;
3917 entry.support_mode = 0;
3918 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3919 memcpy(priv->stations[i], bssid, ETH_ALEN);
3920 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003921 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003922 priv->num_stations++;
3923
3924 return i;
3925}
3926
Arjan van de Ven858119e2006-01-14 13:20:43 -08003927static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003928{
3929 int i;
3930
Jeff Garzikbf794512005-07-31 13:07:26 -04003931 for (i = 0; i < priv->num_stations; i++)
3932 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003933 return i;
3934
3935 return IPW_INVALID_STATION;
3936}
3937
3938static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3939{
3940 int err;
3941
Hong Liu7b996592005-08-25 17:36:13 +08003942 if (priv->status & STATUS_ASSOCIATING) {
3943 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01003944 schedule_work(&priv->disassociate);
Hong Liu7b996592005-08-25 17:36:13 +08003945 return;
3946 }
3947
3948 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003949 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3950 return;
3951 }
3952
Johannes Berge1749612008-10-27 15:59:26 -07003953 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003954 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003955 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003956 priv->assoc_request.channel);
3957
3958 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3959 priv->status |= STATUS_DISASSOCIATING;
3960
3961 if (quiet)
3962 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3963 else
3964 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003965
James Ketrenos43f66a62005-03-25 12:31:53 -06003966 err = ipw_send_associate(priv, &priv->assoc_request);
3967 if (err) {
3968 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3969 "failed.\n");
3970 return;
3971 }
3972
3973}
3974
James Ketrenosc848d0a2005-08-24 21:56:24 -05003975static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003976{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003977 struct ipw_priv *priv = data;
3978 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3979 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003980 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003981 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003982 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003983}
3984
David Howellsc4028952006-11-22 14:57:56 +00003985static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003986{
David Howellsc4028952006-11-22 14:57:56 +00003987 struct ipw_priv *priv =
3988 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003989 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003990 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003991 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003992}
3993
David Howellsc4028952006-11-22 14:57:56 +00003994static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003995{
David Howellsc4028952006-11-22 14:57:56 +00003996 struct ipw_priv *priv =
3997 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003998
3999#ifdef CONFIG_IPW2200_PROMISCUOUS
4000 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
4001 priv->sys_config.accept_all_data_frames = 1;
4002 priv->sys_config.accept_non_directed_frames = 1;
4003 priv->sys_config.accept_all_mgmt_bcpr = 1;
4004 priv->sys_config.accept_all_mgmt_frames = 1;
4005 }
4006#endif
4007
4008 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004009}
4010
4011struct ipw_status_code {
4012 u16 status;
4013 const char *reason;
4014};
4015
4016static const struct ipw_status_code ipw_status_codes[] = {
4017 {0x00, "Successful"},
4018 {0x01, "Unspecified failure"},
4019 {0x0A, "Cannot support all requested capabilities in the "
4020 "Capability information field"},
4021 {0x0B, "Reassociation denied due to inability to confirm that "
4022 "association exists"},
4023 {0x0C, "Association denied due to reason outside the scope of this "
4024 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004025 {0x0D,
4026 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004027 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004028 {0x0E,
4029 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004030 "transaction sequence number out of expected sequence"},
4031 {0x0F, "Authentication rejected because of challenge failure"},
4032 {0x10, "Authentication rejected due to timeout waiting for next "
4033 "frame in sequence"},
4034 {0x11, "Association denied because AP is unable to handle additional "
4035 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004036 {0x12,
4037 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004038 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004039 {0x13,
4040 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004042 {0x14,
4043 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004044 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004045 {0x15,
4046 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004047 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004048 {0x19,
4049 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004050 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004051 {0x1A,
4052 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004053 "DSSS-OFDM operation"},
4054 {0x28, "Invalid Information Element"},
4055 {0x29, "Group Cipher is not valid"},
4056 {0x2A, "Pairwise Cipher is not valid"},
4057 {0x2B, "AKMP is not valid"},
4058 {0x2C, "Unsupported RSN IE version"},
4059 {0x2D, "Invalid RSN IE Capabilities"},
4060 {0x2E, "Cipher suite is rejected per security policy"},
4061};
4062
Jeff Garzikbf794512005-07-31 13:07:26 -04004063static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004064{
4065 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004066 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004067 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004068 return ipw_status_codes[i].reason;
4069 return "Unknown status value.";
4070}
James Ketrenos43f66a62005-03-25 12:31:53 -06004071
4072static void inline average_init(struct average *avg)
4073{
4074 memset(avg, 0, sizeof(*avg));
4075}
4076
Zhu Yi00d21de2006-04-13 17:19:02 +08004077#define DEPTH_RSSI 8
4078#define DEPTH_NOISE 16
4079static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4080{
4081 return ((depth-1)*prev_avg + val)/depth;
4082}
4083
Arjan van de Ven858119e2006-01-14 13:20:43 -08004084static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004085{
4086 avg->sum -= avg->entries[avg->pos];
4087 avg->sum += val;
4088 avg->entries[avg->pos++] = val;
4089 if (unlikely(avg->pos == AVG_ENTRIES)) {
4090 avg->init = 1;
4091 avg->pos = 0;
4092 }
4093}
4094
Arjan van de Ven858119e2006-01-14 13:20:43 -08004095static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004096{
4097 if (!unlikely(avg->init)) {
4098 if (avg->pos)
4099 return avg->sum / avg->pos;
4100 return 0;
4101 }
4102
4103 return avg->sum / AVG_ENTRIES;
4104}
4105
4106static void ipw_reset_stats(struct ipw_priv *priv)
4107{
4108 u32 len = sizeof(u32);
4109
4110 priv->quality = 0;
4111
4112 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004113 priv->exp_avg_rssi = -60;
4114 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004115
4116 priv->last_rate = 0;
4117 priv->last_missed_beacons = 0;
4118 priv->last_rx_packets = 0;
4119 priv->last_tx_packets = 0;
4120 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004121
James Ketrenos43f66a62005-03-25 12:31:53 -06004122 /* Firmware managed, reset only when NIC is restarted, so we have to
4123 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004124 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004125 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004126 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004127 &priv->last_tx_failures, &len);
4128
4129 /* Driver managed, reset with each association */
4130 priv->missed_adhoc_beacons = 0;
4131 priv->missed_beacons = 0;
4132 priv->tx_packets = 0;
4133 priv->rx_packets = 0;
4134
4135}
4136
Arjan van de Ven858119e2006-01-14 13:20:43 -08004137static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004138{
4139 u32 i = 0x80000000;
4140 u32 mask = priv->rates_mask;
4141 /* If currently associated in B mode, restrict the maximum
4142 * rate match to B rates */
4143 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004144 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004145
4146 /* TODO: Verify that the rate is supported by the current rates
4147 * list. */
4148
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004149 while (i && !(mask & i))
4150 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004151 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004152 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004153 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004154 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004155 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004156 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004158 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004159 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004160 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004161 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004162 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004163 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004164 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004165 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004166 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004167 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004168 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004169 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004170 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004171 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004172 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004173 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004174 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004175 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004176 }
4177
Jeff Garzikbf794512005-07-31 13:07:26 -04004178 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004179 return 11000000;
4180 else
4181 return 54000000;
4182}
4183
4184static u32 ipw_get_current_rate(struct ipw_priv *priv)
4185{
4186 u32 rate, len = sizeof(rate);
4187 int err;
4188
Jeff Garzikbf794512005-07-31 13:07:26 -04004189 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004190 return 0;
4191
4192 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004193 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004194 &len);
4195 if (err) {
4196 IPW_DEBUG_INFO("failed querying ordinals.\n");
4197 return 0;
4198 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004199 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004200 return ipw_get_max_rate(priv);
4201
4202 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004203 case IPW_TX_RATE_1MB:
4204 return 1000000;
4205 case IPW_TX_RATE_2MB:
4206 return 2000000;
4207 case IPW_TX_RATE_5MB:
4208 return 5500000;
4209 case IPW_TX_RATE_6MB:
4210 return 6000000;
4211 case IPW_TX_RATE_9MB:
4212 return 9000000;
4213 case IPW_TX_RATE_11MB:
4214 return 11000000;
4215 case IPW_TX_RATE_12MB:
4216 return 12000000;
4217 case IPW_TX_RATE_18MB:
4218 return 18000000;
4219 case IPW_TX_RATE_24MB:
4220 return 24000000;
4221 case IPW_TX_RATE_36MB:
4222 return 36000000;
4223 case IPW_TX_RATE_48MB:
4224 return 48000000;
4225 case IPW_TX_RATE_54MB:
4226 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004227 }
4228
4229 return 0;
4230}
4231
James Ketrenos43f66a62005-03-25 12:31:53 -06004232#define IPW_STATS_INTERVAL (2 * HZ)
4233static void ipw_gather_stats(struct ipw_priv *priv)
4234{
4235 u32 rx_err, rx_err_delta, rx_packets_delta;
4236 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4237 u32 missed_beacons_percent, missed_beacons_delta;
4238 u32 quality = 0;
4239 u32 len = sizeof(u32);
4240 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004241 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004242 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004243 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004244
4245 if (!(priv->status & STATUS_ASSOCIATED)) {
4246 priv->quality = 0;
4247 return;
4248 }
4249
4250 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004251 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004252 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004253 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004254 priv->last_missed_beacons = priv->missed_beacons;
4255 if (priv->assoc_request.beacon_interval) {
4256 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004257 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004258 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004259 } else {
4260 missed_beacons_percent = 0;
4261 }
4262 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4263
4264 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4265 rx_err_delta = rx_err - priv->last_rx_err;
4266 priv->last_rx_err = rx_err;
4267
4268 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4269 tx_failures_delta = tx_failures - priv->last_tx_failures;
4270 priv->last_tx_failures = tx_failures;
4271
4272 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4273 priv->last_rx_packets = priv->rx_packets;
4274
4275 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4276 priv->last_tx_packets = priv->tx_packets;
4277
4278 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004279 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004280 * Missed beacon: 100% = 0, 0% = 70% missed
4281 * Rate: 60% = 1Mbs, 100% = Max
4282 * Rx and Tx errors represent a straight % of total Rx/Tx
4283 * RSSI: 100% = > -50, 0% = < -80
4284 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004285 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004286 * The lowest computed quality is used.
4287 *
4288 */
4289#define BEACON_THRESHOLD 5
4290 beacon_quality = 100 - missed_beacons_percent;
4291 if (beacon_quality < BEACON_THRESHOLD)
4292 beacon_quality = 0;
4293 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004294 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004295 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004296 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004297 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004298
James Ketrenos43f66a62005-03-25 12:31:53 -06004299 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004300 max_rate = ipw_get_max_rate(priv);
4301 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004302 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4303 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004304
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004305 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004306 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004307 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004308 else
4309 rx_quality = 100;
4310 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4311 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004312
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004313 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004314 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004315 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004316 else
4317 tx_quality = 100;
4318 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4319 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004320
Zhu Yi00d21de2006-04-13 17:19:02 +08004321 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004322 signal_quality =
4323 (100 *
4324 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4325 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4326 (priv->ieee->perfect_rssi - rssi) *
4327 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4328 62 * (priv->ieee->perfect_rssi - rssi))) /
4329 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4330 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4331 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004332 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004333 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004334 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004335
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004336 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004337 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004338
Reinette Chatre21f8a732009-08-18 10:25:05 -07004339 quality = min(rx_quality, signal_quality);
4340 quality = min(tx_quality, quality);
4341 quality = min(rate_quality, quality);
4342 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004343 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004344 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4345 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004346 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004347 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4348 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004349 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004350 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4351 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004352 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004353 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4354 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004355 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004356 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4357 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004358
4359 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004360
Tejun Heobcb6d912011-01-26 12:12:50 +01004361 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL);
James Ketrenos43f66a62005-03-25 12:31:53 -06004362}
4363
David Howellsc4028952006-11-22 14:57:56 +00004364static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004365{
David Howellsc4028952006-11-22 14:57:56 +00004366 struct ipw_priv *priv =
4367 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004368 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004369 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004370 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004371}
4372
Ben Cahille7582562005-10-06 15:34:41 -05004373/* Missed beacon behavior:
4374 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4375 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4376 * Above disassociate threshold, give up and stop scanning.
4377 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004378static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004379 int missed_count)
4380{
4381 priv->notif_missed_beacons = missed_count;
4382
James Ketrenosafbf30a2005-08-25 00:05:33 -05004383 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004384 priv->status & STATUS_ASSOCIATED) {
4385 /* If associated and we've hit the missed
4386 * beacon threshold, disassociate, turn
4387 * off roaming, and abort any active scans */
4388 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004389 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004390 "Missed beacon: %d - disassociate\n", missed_count);
4391 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004392 if (priv->status & STATUS_SCANNING) {
4393 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4394 IPW_DL_STATE,
4395 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004396 schedule_work(&priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004397 }
4398
Tejun Heobcb6d912011-01-26 12:12:50 +01004399 schedule_work(&priv->disassociate);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004400 return;
4401 }
4402
4403 if (priv->status & STATUS_ROAMING) {
4404 /* If we are currently roaming, then just
4405 * print a debug statement... */
4406 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4407 "Missed beacon: %d - roam in progress\n",
4408 missed_count);
4409 return;
4410 }
4411
Zhu Yi4bfdb912006-01-24 16:37:16 +08004412 if (roaming &&
4413 (missed_count > priv->roaming_threshold &&
4414 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004415 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004416 * bit in the status and kick off a scan.
4417 * This can happen several times before we reach
4418 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004419 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4420 "Missed beacon: %d - initiate "
4421 "roaming\n", missed_count);
4422 if (!(priv->status & STATUS_ROAMING)) {
4423 priv->status |= STATUS_ROAMING;
4424 if (!(priv->status & STATUS_SCANNING))
Tejun Heobcb6d912011-01-26 12:12:50 +01004425 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004426 }
4427 return;
4428 }
4429
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004430 if (priv->status & STATUS_SCANNING &&
4431 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004432 /* Stop scan to keep fw from getting
4433 * stuck (only if we aren't roaming --
4434 * otherwise we'll never scan more than 2 or 3
4435 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004436 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4437 "Aborting scan with missed beacon.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004438 schedule_work(&priv->abort_scan);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004439 }
4440
4441 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004442}
4443
Dan Williams0b531672007-10-09 13:55:24 -04004444static void ipw_scan_event(struct work_struct *work)
4445{
4446 union iwreq_data wrqu;
4447
4448 struct ipw_priv *priv =
4449 container_of(work, struct ipw_priv, scan_event.work);
4450
4451 wrqu.data.length = 0;
4452 wrqu.data.flags = 0;
4453 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4454}
4455
4456static void handle_scan_event(struct ipw_priv *priv)
4457{
4458 /* Only userspace-requested scan completion events go out immediately */
4459 if (!priv->user_requested_scan) {
4460 if (!delayed_work_pending(&priv->scan_event))
Tejun Heobcb6d912011-01-26 12:12:50 +01004461 schedule_delayed_work(&priv->scan_event,
4462 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004463 } else {
4464 union iwreq_data wrqu;
4465
4466 priv->user_requested_scan = 0;
4467 cancel_delayed_work(&priv->scan_event);
4468
4469 wrqu.data.length = 0;
4470 wrqu.data.flags = 0;
4471 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4472 }
4473}
4474
James Ketrenos43f66a62005-03-25 12:31:53 -06004475/**
4476 * Handle host notification packet.
4477 * Called from interrupt routine
4478 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004479static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004480 struct ipw_rx_notification *notif)
4481{
John W. Linville9387b7c2008-09-30 20:59:05 -04004482 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004483 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004484
Al Viroe62e1ee2007-12-27 01:36:46 -05004485 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004486
James Ketrenos43f66a62005-03-25 12:31:53 -06004487 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004488 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4489 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004490
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004491 switch (assoc->state) {
4492 case CMAS_ASSOCIATED:{
4493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4494 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004495 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004496 print_ssid(ssid, priv->essid,
4497 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004498 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004499
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004500 switch (priv->ieee->iw_mode) {
4501 case IW_MODE_INFRA:
4502 memcpy(priv->ieee->bssid,
4503 priv->bssid, ETH_ALEN);
4504 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004505
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004506 case IW_MODE_ADHOC:
4507 memcpy(priv->ieee->bssid,
4508 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004509
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004510 /* clear out the station table */
4511 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004512
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004513 IPW_DEBUG_ASSOC
4514 ("queueing adhoc check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01004515 schedule_delayed_work(
4516 &priv->adhoc_check,
4517 le16_to_cpu(priv->
4518 assoc_request.
4519 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 break;
4521 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004522
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004523 priv->status &= ~STATUS_ASSOCIATING;
4524 priv->status |= STATUS_ASSOCIATED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004525 schedule_work(&priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004526
Zhu Yie43e3c12006-04-13 17:20:45 +08004527#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004528#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004529 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004530 if ((priv->status & STATUS_AUTH) &&
4531 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4532 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004533 if ((sizeof
4534 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004535 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004536 <= size)
4537 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004538 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004539 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004540 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004541 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004542 };
4543
4544 IPW_DEBUG_QOS
4545 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004546 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004547 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004548 ieee,
4549 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004550 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004551 *)
4552 &notif->u.raw, &stats);
4553 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004554 }
James Ketrenosb095c382005-08-24 22:04:42 -05004555#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004556
James Ketrenosa613bff2005-08-24 21:43:11 -05004557 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004558
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004559 break;
4560 }
4561
4562 case CMAS_AUTHENTICATED:{
4563 if (priv->
4564 status & (STATUS_ASSOCIATED |
4565 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004566 struct notif_authenticate *auth
4567 = &notif->u.auth;
4568 IPW_DEBUG(IPW_DL_NOTIF |
4569 IPW_DL_STATE |
4570 IPW_DL_ASSOC,
4571 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004572 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004573 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004574 print_ssid(ssid,
4575 priv->
4576 essid,
4577 priv->
4578 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004579 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004580 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004581 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004582 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004583 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584
4585 priv->status &=
4586 ~(STATUS_ASSOCIATING |
4587 STATUS_AUTH |
4588 STATUS_ASSOCIATED);
4589
James Ketrenosa613bff2005-08-24 21:43:11 -05004590 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004591 break;
4592 }
4593
4594 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4595 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004596 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004597 print_ssid(ssid, priv->essid,
4598 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004599 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004600 break;
4601 }
4602
4603 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004604 if (priv->status & STATUS_AUTH) {
4605 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004606 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004607 *resp;
4608 resp =
4609 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004610 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004611 *)&notif->u.raw;
4612 IPW_DEBUG(IPW_DL_NOTIF |
4613 IPW_DL_STATE |
4614 IPW_DL_ASSOC,
4615 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004616 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004617 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004618 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004619 (resp->status)));
4620 }
4621
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004622 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4623 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004624 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004625 print_ssid(ssid, priv->essid,
4626 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004627 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004628
4629 priv->status &=
4630 ~(STATUS_DISASSOCIATING |
4631 STATUS_ASSOCIATING |
4632 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004633 if (priv->assoc_network
4634 && (priv->assoc_network->
4635 capability &
4636 WLAN_CAPABILITY_IBSS))
4637 ipw_remove_current_network
4638 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004639
James Ketrenosa613bff2005-08-24 21:43:11 -05004640 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004641
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004642 break;
4643 }
4644
James Ketrenosb095c382005-08-24 22:04:42 -05004645 case CMAS_RX_ASSOC_RESP:
4646 break;
4647
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004648 default:
4649 IPW_ERROR("assoc: unknown (%d)\n",
4650 assoc->state);
4651 break;
4652 }
4653
James Ketrenos43f66a62005-03-25 12:31:53 -06004654 break;
4655 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004656
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004657 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4658 struct notif_authenticate *auth = &notif->u.auth;
4659 switch (auth->state) {
4660 case CMAS_AUTHENTICATED:
4661 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004662 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004663 print_ssid(ssid, priv->essid,
4664 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004665 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004666 priv->status |= STATUS_AUTH;
4667 break;
4668
4669 case CMAS_INIT:
4670 if (priv->status & STATUS_AUTH) {
4671 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4672 IPW_DL_ASSOC,
4673 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004674 le16_to_cpu(auth->status),
4675 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004676 (auth->
4677 status)));
4678 }
4679 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4680 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004681 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004682 print_ssid(ssid, priv->essid,
4683 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004684 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004685
4686 priv->status &= ~(STATUS_ASSOCIATING |
4687 STATUS_AUTH |
4688 STATUS_ASSOCIATED);
4689
James Ketrenosa613bff2005-08-24 21:43:11 -05004690 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004691 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004692
4693 case CMAS_TX_AUTH_SEQ_1:
4694 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4695 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4696 break;
4697 case CMAS_RX_AUTH_SEQ_2:
4698 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4699 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4700 break;
4701 case CMAS_AUTH_SEQ_1_PASS:
4702 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4703 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4704 break;
4705 case CMAS_AUTH_SEQ_1_FAIL:
4706 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4707 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4708 break;
4709 case CMAS_TX_AUTH_SEQ_3:
4710 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4711 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4712 break;
4713 case CMAS_RX_AUTH_SEQ_4:
4714 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4715 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4716 break;
4717 case CMAS_AUTH_SEQ_2_PASS:
4718 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4719 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4720 break;
4721 case CMAS_AUTH_SEQ_2_FAIL:
4722 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4723 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4724 break;
4725 case CMAS_TX_ASSOC:
4726 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4727 IPW_DL_ASSOC, "TX_ASSOC\n");
4728 break;
4729 case CMAS_RX_ASSOC_RESP:
4730 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4731 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004732
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004733 break;
4734 case CMAS_ASSOCIATED:
4735 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4736 IPW_DL_ASSOC, "ASSOCIATED\n");
4737 break;
4738 default:
4739 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4740 auth->state);
4741 break;
4742 }
4743 break;
4744 }
4745
4746 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4747 struct notif_channel_result *x =
4748 &notif->u.channel_result;
4749
Al Viroe62e1ee2007-12-27 01:36:46 -05004750 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004751 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4752 x->channel_num);
4753 } else {
4754 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4755 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004756 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004757 }
4758 break;
4759 }
4760
4761 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4762 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004763 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004764 IPW_DEBUG_SCAN
4765 ("Scan completed: type %d, %d channels, "
4766 "%d status\n", x->scan_type,
4767 x->num_channels, x->status);
4768 } else {
4769 IPW_ERROR("Scan completed of wrong size %d "
4770 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004771 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004772 }
4773
4774 priv->status &=
4775 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4776
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004777 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004778 cancel_delayed_work(&priv->scan_check);
4779
James Ketrenosb095c382005-08-24 22:04:42 -05004780 if (priv->status & STATUS_EXIT_PENDING)
4781 break;
4782
4783 priv->ieee->scans++;
4784
4785#ifdef CONFIG_IPW2200_MONITOR
4786 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004787 priv->status |= STATUS_SCAN_FORCED;
Tejun Heobcb6d912011-01-26 12:12:50 +01004788 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004789 break;
4790 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004791 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004792#endif /* CONFIG_IPW2200_MONITOR */
4793
Dan Williamsea177302008-06-02 17:51:23 -04004794 /* Do queued direct scans first */
Tejun Heobcb6d912011-01-26 12:12:50 +01004795 if (priv->status & STATUS_DIRECT_SCAN_PENDING)
4796 schedule_delayed_work(&priv->request_direct_scan, 0);
Dan Williamsea177302008-06-02 17:51:23 -04004797
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004798 if (!(priv->status & (STATUS_ASSOCIATED |
4799 STATUS_ASSOCIATING |
4800 STATUS_ROAMING |
4801 STATUS_DISASSOCIATING)))
Tejun Heobcb6d912011-01-26 12:12:50 +01004802 schedule_work(&priv->associate);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004803 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004804 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4805 /* If a scan completed and we are in roam mode, then
4806 * the scan that completed was the one requested as a
4807 * result of entering roam... so, schedule the
4808 * roam work */
Tejun Heobcb6d912011-01-26 12:12:50 +01004809 schedule_work(&priv->roam);
Ben Cahille7582562005-10-06 15:34:41 -05004810 else
4811 /* Don't schedule if we aborted the scan */
4812 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004813 } else if (priv->status & STATUS_SCAN_PENDING)
Tejun Heobcb6d912011-01-26 12:12:50 +01004814 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004815 else if (priv->config & CFG_BACKGROUND_SCAN
4816 && priv->status & STATUS_ASSOCIATED)
Tejun Heobcb6d912011-01-26 12:12:50 +01004817 schedule_delayed_work(&priv->request_scan,
4818 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004819
4820 /* Send an empty event to user space.
4821 * We don't send the received data on the event because
4822 * it would require us to do complex transcoding, and
4823 * we want to minimise the work done in the irq handler
4824 * Use a request to extract the data.
4825 * Also, we generate this even for any scan, regardless
4826 * on how the scan was initiated. User space can just
4827 * sync on periodic scan to get fresh data...
4828 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004829 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4830 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004831 break;
4832 }
4833
4834 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4835 struct notif_frag_length *x = &notif->u.frag_len;
4836
Al Viroe62e1ee2007-12-27 01:36:46 -05004837 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004838 IPW_ERROR("Frag length: %d\n",
4839 le16_to_cpu(x->frag_length));
4840 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004841 IPW_ERROR("Frag length of wrong size %d "
4842 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004843 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004844 break;
4845 }
4846
4847 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4848 struct notif_link_deterioration *x =
4849 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004850
Al Viroe62e1ee2007-12-27 01:36:46 -05004851 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004852 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004853 "link deterioration: type %d, cnt %d\n",
4854 x->silence_notification_type,
4855 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004856 memcpy(&priv->last_link_deterioration, x,
4857 sizeof(*x));
4858 } else {
4859 IPW_ERROR("Link Deterioration of wrong size %d "
4860 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004861 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004862 }
4863 break;
4864 }
4865
4866 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4867 IPW_ERROR("Dino config\n");
4868 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004869 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004870 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004871
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004872 break;
4873 }
4874
4875 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4876 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004877 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004878 IPW_ERROR
4879 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004880 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004881 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004882 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004883
James Ketrenosa613bff2005-08-24 21:43:11 -05004884 if (le32_to_cpu(x->state) ==
4885 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4886 ipw_handle_missed_beacon(priv,
4887 le32_to_cpu(x->
4888 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004889
James Ketrenos43f66a62005-03-25 12:31:53 -06004890 break;
4891 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004892
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004893 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4894 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004895 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004896 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4897 "0x%02x station %d\n",
4898 x->key_state, x->security_type,
4899 x->station_index);
4900 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004901 }
4902
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004903 IPW_ERROR
4904 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004905 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004906 break;
4907 }
4908
4909 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4910 struct notif_calibration *x = &notif->u.calibration;
4911
Al Viroe62e1ee2007-12-27 01:36:46 -05004912 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004913 memcpy(&priv->calib, x, sizeof(*x));
4914 IPW_DEBUG_INFO("TODO: Calibration\n");
4915 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004916 }
4917
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004918 IPW_ERROR
4919 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004920 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004921 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004922 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004923
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004924 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004925 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004926 priv->exp_avg_noise =
4927 exponential_average(priv->exp_avg_noise,
4928 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4929 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004930 break;
4931 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004932
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004933 IPW_ERROR
4934 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004935 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004937 }
4938
James Ketrenos43f66a62005-03-25 12:31:53 -06004939 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004940 IPW_DEBUG_NOTIF("Unknown notification: "
4941 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004942 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004943 }
4944}
4945
4946/**
4947 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004948 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004949 * @param priv
4950 * @return error code
4951 */
4952static int ipw_queue_reset(struct ipw_priv *priv)
4953{
4954 int rc = 0;
4955 /** @todo customize queue sizes */
4956 int nTx = 64, nTxCmd = 8;
4957 ipw_tx_queue_free(priv);
4958 /* Tx CMD queue */
4959 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004960 IPW_TX_CMD_QUEUE_READ_INDEX,
4961 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4962 IPW_TX_CMD_QUEUE_BD_BASE,
4963 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004964 if (rc) {
4965 IPW_ERROR("Tx Cmd queue init failed\n");
4966 goto error;
4967 }
4968 /* Tx queue(s) */
4969 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004970 IPW_TX_QUEUE_0_READ_INDEX,
4971 IPW_TX_QUEUE_0_WRITE_INDEX,
4972 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 if (rc) {
4974 IPW_ERROR("Tx 0 queue init failed\n");
4975 goto error;
4976 }
4977 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004978 IPW_TX_QUEUE_1_READ_INDEX,
4979 IPW_TX_QUEUE_1_WRITE_INDEX,
4980 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004981 if (rc) {
4982 IPW_ERROR("Tx 1 queue init failed\n");
4983 goto error;
4984 }
4985 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004986 IPW_TX_QUEUE_2_READ_INDEX,
4987 IPW_TX_QUEUE_2_WRITE_INDEX,
4988 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004989 if (rc) {
4990 IPW_ERROR("Tx 2 queue init failed\n");
4991 goto error;
4992 }
4993 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004994 IPW_TX_QUEUE_3_READ_INDEX,
4995 IPW_TX_QUEUE_3_WRITE_INDEX,
4996 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004997 if (rc) {
4998 IPW_ERROR("Tx 3 queue init failed\n");
4999 goto error;
5000 }
5001 /* statistics */
5002 priv->rx_bufs_min = 0;
5003 priv->rx_pend_max = 0;
5004 return rc;
5005
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005006 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005007 ipw_tx_queue_free(priv);
5008 return rc;
5009}
5010
5011/**
5012 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005013 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005014 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005015 * new 'R' index need to be reclaimed. As result, some free space
5016 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005017 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005018 * @note Need to protect against garbage in 'R' index
5019 * @param priv
5020 * @param txq
5021 * @param qindex
5022 * @return Number of used entries remains in the queue
5023 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005024static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005025 struct clx2_tx_queue *txq, int qindex)
5026{
5027 u32 hw_tail;
5028 int used;
5029 struct clx2_queue *q = &txq->q;
5030
5031 hw_tail = ipw_read32(priv, q->reg_r);
5032 if (hw_tail >= q->n_bd) {
5033 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005034 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5035 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005036 goto done;
5037 }
5038 for (; q->last_used != hw_tail;
5039 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5040 ipw_queue_tx_free_tfd(priv, txq);
5041 priv->tx_packets++;
5042 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005043 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005044 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005045 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005046 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005047 used = q->first_empty - q->last_used;
5048 if (used < 0)
5049 used += q->n_bd;
5050
5051 return used;
5052}
5053
5054static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5055 int len, int sync)
5056{
5057 struct clx2_tx_queue *txq = &priv->txq_cmd;
5058 struct clx2_queue *q = &txq->q;
5059 struct tfd_frame *tfd;
5060
Dan Williams943dbef2008-02-14 17:49:41 -05005061 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005062 IPW_ERROR("No space for Tx\n");
5063 return -EBUSY;
5064 }
5065
5066 tfd = &txq->bd[q->first_empty];
5067 txq->txb[q->first_empty] = NULL;
5068
5069 memset(tfd, 0, sizeof(*tfd));
5070 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5071 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5072 priv->hcmd_seq++;
5073 tfd->u.cmd.index = hcmd;
5074 tfd->u.cmd.length = len;
5075 memcpy(tfd->u.cmd.payload, buf, len);
5076 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5077 ipw_write32(priv, q->reg_w, q->first_empty);
5078 _ipw_read32(priv, 0x90);
5079
5080 return 0;
5081}
5082
Jeff Garzikbf794512005-07-31 13:07:26 -04005083/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005084 * Rx theory of operation
5085 *
5086 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005087 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 * 0 to 31
5089 *
5090 * Rx Queue Indexes
5091 * The host/firmware share two index registers for managing the Rx buffers.
5092 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005093 * The READ index maps to the first position that the firmware may be writing
5094 * to -- the driver can read up to (but not including) this position and get
5095 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005096 * The READ index is managed by the firmware once the card is enabled.
5097 *
5098 * The WRITE index maps to the last position the driver has read from -- the
5099 * position preceding WRITE is the last slot the firmware can place a packet.
5100 *
5101 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005102 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005103 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005104 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005105 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5106 *
5107 * When the firmware places a packet in a buffer it will advance the READ index
5108 * and fire the RX interrupt. The driver can then query the READ index and
5109 * process as many packets as possible, moving the WRITE index forward as it
5110 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005111 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005112 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005113 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005114 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005115 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5117 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5118 * 'processed' and 'read' driver indexes as well)
5119 * + A received packet is processed and handed to the kernel network stack,
5120 * detached from the ipw->rxq. The driver 'processed' index is updated.
5121 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005122 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5123 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005124 * were enough free buffers and RX_STALLED is set it is cleared.
5125 *
5126 *
5127 * Driver sequence:
5128 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005129 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005130 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5131 * ipw_rx_queue_restock
5132 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5133 * queue, updates firmware pointers, and updates
5134 * the WRITE index. If insufficient rx_free buffers
5135 * are available, schedules ipw_rx_queue_replenish
5136 *
5137 * -- enable interrupts --
5138 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005139 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005140 * Moves the packet buffer from queue to rx_used.
5141 * Calls ipw_rx_queue_restock to refill any empty
5142 * slots.
5143 * ...
5144 *
5145 */
5146
Jeff Garzikbf794512005-07-31 13:07:26 -04005147/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005148 * If there are slots in the RX queue that need to be restocked,
5149 * and we have free pre-allocated buffers, fill the ranks as much
5150 * as we can pulling from rx_free.
5151 *
5152 * This moves the 'write' index forward to catch up with 'processed', and
5153 * also updates the memory address in the firmware to reference the new
5154 * target buffer.
5155 */
5156static void ipw_rx_queue_restock(struct ipw_priv *priv)
5157{
5158 struct ipw_rx_queue *rxq = priv->rxq;
5159 struct list_head *element;
5160 struct ipw_rx_mem_buffer *rxb;
5161 unsigned long flags;
5162 int write;
5163
5164 spin_lock_irqsave(&rxq->lock, flags);
5165 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005166 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005167 element = rxq->rx_free.next;
5168 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5169 list_del(element);
5170
James Ketrenosb095c382005-08-24 22:04:42 -05005171 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005172 rxb->dma_addr);
5173 rxq->queue[rxq->write] = rxb;
5174 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5175 rxq->free_count--;
5176 }
5177 spin_unlock_irqrestore(&rxq->lock, flags);
5178
Jeff Garzikbf794512005-07-31 13:07:26 -04005179 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005180 * refill it */
5181 if (rxq->free_count <= RX_LOW_WATERMARK)
Tejun Heobcb6d912011-01-26 12:12:50 +01005182 schedule_work(&priv->rx_replenish);
James Ketrenos43f66a62005-03-25 12:31:53 -06005183
5184 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005185 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005186 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005187}
5188
5189/*
5190 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 * Also restock the Rx queue via ipw_rx_queue_restock.
5192 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005193 * This is called as a scheduled work item (except for during intialization)
5194 */
5195static void ipw_rx_queue_replenish(void *data)
5196{
5197 struct ipw_priv *priv = data;
5198 struct ipw_rx_queue *rxq = priv->rxq;
5199 struct list_head *element;
5200 struct ipw_rx_mem_buffer *rxb;
5201 unsigned long flags;
5202
5203 spin_lock_irqsave(&rxq->lock, flags);
5204 while (!list_empty(&rxq->rx_used)) {
5205 element = rxq->rx_used.next;
5206 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005207 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005208 if (!rxb->skb) {
5209 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5210 priv->net_dev->name);
5211 /* We don't reschedule replenish work here -- we will
5212 * call the restock method and if it still needs
5213 * more buffers it will schedule replenish */
5214 break;
5215 }
5216 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005217
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005218 rxb->dma_addr =
5219 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005220 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005221
James Ketrenos43f66a62005-03-25 12:31:53 -06005222 list_add_tail(&rxb->list, &rxq->rx_free);
5223 rxq->free_count++;
5224 }
5225 spin_unlock_irqrestore(&rxq->lock, flags);
5226
5227 ipw_rx_queue_restock(priv);
5228}
5229
David Howellsc4028952006-11-22 14:57:56 +00005230static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005231{
David Howellsc4028952006-11-22 14:57:56 +00005232 struct ipw_priv *priv =
5233 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005234 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005235 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005236 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005237}
5238
James Ketrenos43f66a62005-03-25 12:31:53 -06005239/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005240 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005241 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005242 * non NULL it is unmapped and freed
5243 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005244static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005245{
5246 int i;
5247
5248 if (!rxq)
5249 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005250
James Ketrenos43f66a62005-03-25 12:31:53 -06005251 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5252 if (rxq->pool[i].skb != NULL) {
5253 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005254 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005255 dev_kfree_skb(rxq->pool[i].skb);
5256 }
5257 }
5258
5259 kfree(rxq);
5260}
5261
5262static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5263{
5264 struct ipw_rx_queue *rxq;
5265 int i;
5266
Takisc75f4742005-12-01 01:41:45 -08005267 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005268 if (unlikely(!rxq)) {
5269 IPW_ERROR("memory allocation failed\n");
5270 return NULL;
5271 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005272 spin_lock_init(&rxq->lock);
5273 INIT_LIST_HEAD(&rxq->rx_free);
5274 INIT_LIST_HEAD(&rxq->rx_used);
5275
5276 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005277 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005278 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5279
5280 /* Set us so that we have processed and used all buffers, but have
5281 * not restocked the Rx queue with fresh buffers */
5282 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283 rxq->free_count = 0;
5284
5285 return rxq;
5286}
5287
5288static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5289{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005290 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005291 if (ieee_mode == IEEE_A) {
5292 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005293 case LIBIPW_OFDM_RATE_6MB:
5294 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005295 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005296 case LIBIPW_OFDM_RATE_9MB:
5297 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005298 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005299 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005300 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005301 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5302 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005303 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005304 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5305 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005306 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005307 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5308 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005309 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005310 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5311 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005312 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005313 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5314 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005315 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005316 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005317 default:
5318 return 0;
5319 }
5320 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005321
James Ketrenos43f66a62005-03-25 12:31:53 -06005322 /* B and G mixed */
5323 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005324 case LIBIPW_CCK_RATE_1MB:
5325 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5326 case LIBIPW_CCK_RATE_2MB:
5327 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5328 case LIBIPW_CCK_RATE_5MB:
5329 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5330 case LIBIPW_CCK_RATE_11MB:
5331 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005332 }
5333
5334 /* If we are limited to B modulations, bail at this point */
5335 if (ieee_mode == IEEE_B)
5336 return 0;
5337
5338 /* G */
5339 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005340 case LIBIPW_OFDM_RATE_6MB:
5341 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5342 case LIBIPW_OFDM_RATE_9MB:
5343 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5344 case LIBIPW_OFDM_RATE_12MB:
5345 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5346 case LIBIPW_OFDM_RATE_18MB:
5347 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5348 case LIBIPW_OFDM_RATE_24MB:
5349 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5350 case LIBIPW_OFDM_RATE_36MB:
5351 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5352 case LIBIPW_OFDM_RATE_48MB:
5353 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5354 case LIBIPW_OFDM_RATE_54MB:
5355 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005356 }
5357
5358 return 0;
5359}
5360
Jeff Garzikbf794512005-07-31 13:07:26 -04005361static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005362 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005363 struct ipw_supported_rates *rates)
5364{
5365 int num_rates, i;
5366
5367 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005368 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005369 rates->num_rates = 0;
5370 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005371 if (!ipw_is_rate_in_mask(priv, network->mode,
5372 network->rates[i])) {
5373
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005374 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005375 IPW_DEBUG_SCAN("Adding masked mandatory "
5376 "rate %02X\n",
5377 network->rates[i]);
5378 rates->supported_rates[rates->num_rates++] =
5379 network->rates[i];
5380 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005381 }
5382
James Ketrenos43f66a62005-03-25 12:31:53 -06005383 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5384 network->rates[i], priv->rates_mask);
5385 continue;
5386 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005387
James Ketrenos43f66a62005-03-25 12:31:53 -06005388 rates->supported_rates[rates->num_rates++] = network->rates[i];
5389 }
5390
James Ketrenosa613bff2005-08-24 21:43:11 -05005391 num_rates = min(network->rates_ex_len,
5392 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005393 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005394 if (!ipw_is_rate_in_mask(priv, network->mode,
5395 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005396 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005397 IPW_DEBUG_SCAN("Adding masked mandatory "
5398 "rate %02X\n",
5399 network->rates_ex[i]);
5400 rates->supported_rates[rates->num_rates++] =
5401 network->rates[i];
5402 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005403 }
5404
James Ketrenos43f66a62005-03-25 12:31:53 -06005405 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5406 network->rates_ex[i], priv->rates_mask);
5407 continue;
5408 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005409
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005410 rates->supported_rates[rates->num_rates++] =
5411 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005412 }
5413
James Ketrenosea2b26e2005-08-24 21:25:16 -05005414 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005415}
5416
Arjan van de Ven858119e2006-01-14 13:20:43 -08005417static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005418 const struct ipw_supported_rates *src)
5419{
5420 u8 i;
5421 for (i = 0; i < src->num_rates; i++)
5422 dest->supported_rates[i] = src->supported_rates[i];
5423 dest->num_rates = src->num_rates;
5424}
5425
5426/* TODO: Look at sniffed packets in the air to determine if the basic rate
5427 * mask should ever be used -- right now all callers to add the scan rates are
5428 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5429static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005430 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005431{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005432 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5433 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005434
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005435 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005436 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005437 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005438
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005439 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005440 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005441 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005442
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005443 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005444 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005445 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005446
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005447 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005448 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005449 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005450}
5451
5452static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005453 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005454{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005455 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5456 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005457
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005459 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005460 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005461
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005462 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005463 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005464 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005465
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005466 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005467 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005468 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005469
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005470 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005471 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005472 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005473
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005474 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005475 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005476 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005477
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005478 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005479 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005480 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005481
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005482 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005483 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005484 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005485
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005486 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005487 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005488 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005489}
5490
5491struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005492 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005493 struct ipw_supported_rates rates;
5494};
5495
James Ketrenosc848d0a2005-08-24 21:56:24 -05005496static int ipw_find_adhoc_network(struct ipw_priv *priv,
5497 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005498 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005499 int roaming)
5500{
5501 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005502 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005503
5504 /* Verify that this network's capability is compatible with the
5505 * current mode (AdHoc or Infrastructure) */
5506 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5507 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005508 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005509 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005510 print_ssid(ssid, network->ssid,
5511 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005512 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005513 return 0;
5514 }
5515
James Ketrenosc848d0a2005-08-24 21:56:24 -05005516 if (unlikely(roaming)) {
5517 /* If we are roaming, then ensure check if this is a valid
5518 * network to try and roam to */
5519 if ((network->ssid_len != match->network->ssid_len) ||
5520 memcmp(network->ssid, match->network->ssid,
5521 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005522 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005523 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005524 print_ssid(ssid, network->ssid,
5525 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005526 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005527 return 0;
5528 }
5529 } else {
5530 /* If an ESSID has been configured then compare the broadcast
5531 * ESSID to ours */
5532 if ((priv->config & CFG_STATIC_ESSID) &&
5533 ((network->ssid_len != priv->essid_len) ||
5534 memcmp(network->ssid, priv->essid,
5535 min(network->ssid_len, priv->essid_len)))) {
5536 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005537
James Ketrenosc848d0a2005-08-24 21:56:24 -05005538 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005539 print_ssid(ssid, network->ssid,
5540 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005541 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005542 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005543 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005544 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005545 print_ssid(ssid, priv->essid,
5546 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005547 return 0;
5548 }
5549 }
5550
5551 /* If the old network rate is better than this one, don't bother
5552 * testing everything else. */
5553
5554 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005555 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5556 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005557 print_ssid(ssid, match->network->ssid,
5558 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005559 return 0;
5560 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005561 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5562 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005563 print_ssid(ssid, match->network->ssid,
5564 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005565 return 0;
5566 }
5567
5568 /* Now go through and see if the requested network is valid... */
5569 if (priv->ieee->scan_age != 0 &&
5570 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005571 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005572 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005573 print_ssid(ssid, network->ssid,
5574 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005575 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005576 jiffies_to_msecs(jiffies -
5577 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005578 return 0;
5579 }
5580
5581 if ((priv->config & CFG_STATIC_CHANNEL) &&
5582 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005583 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005584 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005585 print_ssid(ssid, network->ssid,
5586 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005587 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005588 network->channel, priv->channel);
5589 return 0;
5590 }
5591
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005592 /* Verify privacy compatibility */
James Ketrenosc848d0a2005-08-24 21:56:24 -05005593 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5594 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005595 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005596 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005597 print_ssid(ssid, network->ssid,
5598 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005599 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005600 priv->
5601 capability & CAP_PRIVACY_ON ? "on" : "off",
5602 network->
5603 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5604 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005605 return 0;
5606 }
5607
5608 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005609 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5610 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005611 ".\n", print_ssid(ssid, network->ssid,
5612 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005613 network->bssid,
5614 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005615 return 0;
5616 }
5617
5618 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005619 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005620 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005621 "because of invalid frequency/mode "
5622 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005623 print_ssid(ssid, network->ssid,
5624 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005625 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005626 return 0;
5627 }
5628
5629 /* Ensure that the rates supported by the driver are compatible with
5630 * this AP, including verification of basic rates (mandatory) */
5631 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005632 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005633 "because configured rate mask excludes "
5634 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005635 print_ssid(ssid, network->ssid,
5636 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005637 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005638 return 0;
5639 }
5640
5641 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005642 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005643 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005644 print_ssid(ssid, network->ssid,
5645 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005646 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005647 return 0;
5648 }
5649
5650 /* TODO: Perform any further minimal comparititive tests. We do not
5651 * want to put too much policy logic here; intelligent scan selection
5652 * should occur within a generic IEEE 802.11 user space tool. */
5653
5654 /* Set up 'new' AP to this network */
5655 ipw_copy_rates(&match->rates, &rates);
5656 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005657 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005658 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005659 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005660
5661 return 1;
5662}
5663
David Howellsc4028952006-11-22 14:57:56 +00005664static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005665{
John W. Linville9387b7c2008-09-30 20:59:05 -04005666 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005667 struct ipw_priv *priv =
5668 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005669 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005670 struct ipw_network_match match = {
5671 .network = priv->assoc_network
5672 };
5673
James Ketrenosafbf30a2005-08-25 00:05:33 -05005674 if ((priv->status & STATUS_ASSOCIATED) &&
5675 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005676 /* First pass through ROAM process -- look for a better
5677 * network */
5678 unsigned long flags;
5679
5680 spin_lock_irqsave(&priv->ieee->lock, flags);
5681 list_for_each_entry(network, &priv->ieee->network_list, list) {
5682 if (network != priv->assoc_network)
5683 ipw_find_adhoc_network(priv, &match, network,
5684 1);
5685 }
5686 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5687
5688 if (match.network == priv->assoc_network) {
5689 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5690 "merge to.\n");
5691 return;
5692 }
5693
Zhu Yi46441512006-01-24 16:37:59 +08005694 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005695 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5696 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005697 print_ssid(ssid, priv->essid,
5698 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005699 ipw_remove_current_network(priv);
5700 }
5701
5702 ipw_disassociate(priv);
5703 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005704 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005705 return;
5706 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005707}
5708
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005709static int ipw_best_network(struct ipw_priv *priv,
5710 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005711 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005712{
5713 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005714 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005715
5716 /* Verify that this network's capability is compatible with the
5717 * current mode (AdHoc or Infrastructure) */
5718 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005719 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005720 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5721 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005722 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005723 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005724 print_ssid(ssid, network->ssid,
5725 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005726 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 return 0;
5728 }
5729
James Ketrenos43f66a62005-03-25 12:31:53 -06005730 if (unlikely(roaming)) {
5731 /* If we are roaming, then ensure check if this is a valid
5732 * network to try and roam to */
5733 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005734 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005735 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005736 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005737 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005738 print_ssid(ssid, network->ssid,
5739 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005740 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005741 return 0;
5742 }
5743 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005744 /* If an ESSID has been configured then compare the broadcast
5745 * ESSID to ours */
5746 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005748 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005749 min(network->ssid_len, priv->essid_len)))) {
5750 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005751 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005752 print_ssid(ssid, network->ssid,
5753 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005754 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005755 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005756 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005757 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005758 print_ssid(ssid, priv->essid,
5759 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005760 return 0;
5761 }
5762 }
5763
5764 /* If the old network rate is better than this one, don't bother
5765 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005766 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005767 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005768 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005769 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005770 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005771 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5772 "'%s (%pM)' has a stronger signal.\n",
5773 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005774 print_ssid(ssid, match->network->ssid,
5775 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005776 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005777 return 0;
5778 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005779
James Ketrenos43f66a62005-03-25 12:31:53 -06005780 /* If this network has already had an association attempt within the
5781 * last 3 seconds, do not try and associate again... */
5782 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005783 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005784 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005785 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005786 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005787 print_ssid(ssid, network->ssid,
5788 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005789 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005790 jiffies_to_msecs(jiffies -
5791 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005792 return 0;
5793 }
5794
5795 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005796 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005797 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005798 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005799 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005800 print_ssid(ssid, network->ssid,
5801 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005802 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005803 jiffies_to_msecs(jiffies -
5804 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005805 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005806 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005807
Jeff Garzikbf794512005-07-31 13:07:26 -04005808 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005809 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005810 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005811 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005812 print_ssid(ssid, network->ssid,
5813 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005814 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 network->channel, priv->channel);
5816 return 0;
5817 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005818
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005819 /* Verify privacy compatibility */
Jeff Garzikbf794512005-07-31 13:07:26 -04005820 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005822 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005823 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005824 print_ssid(ssid, network->ssid,
5825 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005826 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005827 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005828 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005829 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005830 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005831 return 0;
5832 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005833
5834 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005835 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005836 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5837 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005838 print_ssid(ssid, network->ssid,
5839 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005840 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005841 return 0;
5842 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005843
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005845 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005846 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005847 "because of invalid frequency/mode "
5848 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005849 print_ssid(ssid, network->ssid,
5850 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005851 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005852 return 0;
5853 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005854
Liu Hong1fe0adb2005-08-19 09:33:10 -05005855 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005856 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005857 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005858 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005859 print_ssid(ssid, network->ssid,
5860 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005861 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005862 return 0;
5863 }
5864
James Ketrenosea2b26e2005-08-24 21:25:16 -05005865 /* Ensure that the rates supported by the driver are compatible with
5866 * this AP, including verification of basic rates (mandatory) */
5867 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005868 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005869 "because configured rate mask excludes "
5870 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005871 print_ssid(ssid, network->ssid,
5872 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005873 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005874 return 0;
5875 }
5876
James Ketrenos43f66a62005-03-25 12:31:53 -06005877 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005878 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005879 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005880 print_ssid(ssid, network->ssid,
5881 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005882 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005883 return 0;
5884 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005885
James Ketrenos43f66a62005-03-25 12:31:53 -06005886 /* TODO: Perform any further minimal comparititive tests. We do not
5887 * want to put too much policy logic here; intelligent scan selection
5888 * should occur within a generic IEEE 802.11 user space tool. */
5889
5890 /* Set up 'new' AP to this network */
5891 ipw_copy_rates(&match->rates, &rates);
5892 match->network = network;
5893
Johannes Berge1749612008-10-27 15:59:26 -07005894 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005895 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005896 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005897
5898 return 1;
5899}
5900
Jeff Garzikbf794512005-07-31 13:07:26 -04005901static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005902 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005903{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005904 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005905 int i;
5906
James Ketrenos43f66a62005-03-25 12:31:53 -06005907 /*
5908 * For the purposes of scanning, we can set our wireless mode
5909 * to trigger scans across combinations of bands, but when it
5910 * comes to creating a new ad-hoc network, we have tell the FW
5911 * exactly which band to use.
5912 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005913 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005914 * chossen band. Attempting to create a new ad-hoc network
5915 * with an invalid channel for wireless mode will trigger a
5916 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005917 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005918 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005919 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5920 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005921 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005922 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005923 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005924 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005925 IPW_WARNING("Overriding invalid channel\n");
5926 priv->channel = geo->a[0].channel;
5927 }
5928 break;
5929
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005930 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005931 if (priv->ieee->mode & IEEE_G)
5932 network->mode = IEEE_G;
5933 else
5934 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005935 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005936 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005937 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005938 IPW_WARNING("Overriding invalid channel\n");
5939 priv->channel = geo->bg[0].channel;
5940 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005941 break;
5942
5943 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005944 IPW_WARNING("Overriding invalid channel\n");
5945 if (priv->ieee->mode & IEEE_A) {
5946 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005947 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005948 } else if (priv->ieee->mode & IEEE_G) {
5949 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005950 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005951 } else {
5952 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005953 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005954 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005955 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005956 }
5957
5958 network->channel = priv->channel;
5959 priv->config |= CFG_ADHOC_PERSIST;
5960 ipw_create_bssid(priv, network->bssid);
5961 network->ssid_len = priv->essid_len;
5962 memcpy(network->ssid, priv->essid, priv->essid_len);
5963 memset(&network->stats, 0, sizeof(network->stats));
5964 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005965 if (!(priv->config & CFG_PREAMBLE_LONG))
5966 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005967 if (priv->capability & CAP_PRIVACY_ON)
5968 network->capability |= WLAN_CAPABILITY_PRIVACY;
5969 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005970 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005971 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005972 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005973 &priv->rates.supported_rates[network->rates_len],
5974 network->rates_ex_len);
5975 network->last_scanned = 0;
5976 network->flags = 0;
5977 network->last_associate = 0;
5978 network->time_stamp[0] = 0;
5979 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005980 network->beacon_interval = 100; /* Default */
5981 network->listen_interval = 10; /* Default */
5982 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005983 network->wpa_ie_len = 0;
5984 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005985}
5986
James Ketrenosb095c382005-08-24 22:04:42 -05005987static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5988{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005989 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005990
5991 if (!(priv->ieee->sec.flags & (1 << index)))
5992 return;
5993
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005994 key.key_id = index;
5995 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5996 key.security_type = type;
5997 key.station_index = 0; /* always 0 for BSS */
5998 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005999 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08006000 key.tx_counter[0] = cpu_to_le32(0);
6001 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05006002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006003 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05006004}
6005
6006static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06006007{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006008 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006009 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006010
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006011 key.cmd_id = DINO_CMD_WEP_KEY;
6012 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006013
James Ketrenosb095c382005-08-24 22:04:42 -05006014 /* Note: AES keys cannot be set for multiple times.
6015 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006016 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006017 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006018 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006019 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006020 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006021 }
6022
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006023 key.key_size = priv->ieee->sec.key_sizes[i];
6024 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006025
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006026 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006027 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006028}
6029
Zhu Yi1fbfea52005-08-05 17:22:56 +08006030static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6031{
6032 if (priv->ieee->host_encrypt)
6033 return;
6034
6035 switch (level) {
6036 case SEC_LEVEL_3:
6037 priv->sys_config.disable_unicast_decryption = 0;
6038 priv->ieee->host_decrypt = 0;
6039 break;
6040 case SEC_LEVEL_2:
6041 priv->sys_config.disable_unicast_decryption = 1;
6042 priv->ieee->host_decrypt = 1;
6043 break;
6044 case SEC_LEVEL_1:
6045 priv->sys_config.disable_unicast_decryption = 0;
6046 priv->ieee->host_decrypt = 0;
6047 break;
6048 case SEC_LEVEL_0:
6049 priv->sys_config.disable_unicast_decryption = 1;
6050 break;
6051 default:
6052 break;
6053 }
6054}
6055
6056static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6057{
6058 if (priv->ieee->host_encrypt)
6059 return;
6060
6061 switch (level) {
6062 case SEC_LEVEL_3:
6063 priv->sys_config.disable_multicast_decryption = 0;
6064 break;
6065 case SEC_LEVEL_2:
6066 priv->sys_config.disable_multicast_decryption = 1;
6067 break;
6068 case SEC_LEVEL_1:
6069 priv->sys_config.disable_multicast_decryption = 0;
6070 break;
6071 case SEC_LEVEL_0:
6072 priv->sys_config.disable_multicast_decryption = 1;
6073 break;
6074 default:
6075 break;
6076 }
6077}
6078
James Ketrenosb095c382005-08-24 22:04:42 -05006079static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6080{
6081 switch (priv->ieee->sec.level) {
6082 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006083 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6084 ipw_send_tgi_tx_key(priv,
6085 DCT_FLAG_EXT_SECURITY_CCM,
6086 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006087
Hong Liu567deaf2005-08-31 18:07:22 +08006088 if (!priv->ieee->host_mc_decrypt)
6089 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006090 break;
6091 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006092 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6093 ipw_send_tgi_tx_key(priv,
6094 DCT_FLAG_EXT_SECURITY_TKIP,
6095 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006096 break;
6097 case SEC_LEVEL_1:
6098 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006099 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6100 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006101 break;
6102 case SEC_LEVEL_0:
6103 default:
6104 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006105 }
6106}
6107
6108static void ipw_adhoc_check(void *data)
6109{
6110 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006111
James Ketrenosafbf30a2005-08-25 00:05:33 -05006112 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006113 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006114 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6115 IPW_DL_STATE | IPW_DL_ASSOC,
6116 "Missed beacon: %d - disassociate\n",
6117 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006118 ipw_remove_current_network(priv);
6119 ipw_disassociate(priv);
6120 return;
6121 }
6122
Tejun Heobcb6d912011-01-26 12:12:50 +01006123 schedule_delayed_work(&priv->adhoc_check,
6124 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006125}
6126
David Howellsc4028952006-11-22 14:57:56 +00006127static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006128{
David Howellsc4028952006-11-22 14:57:56 +00006129 struct ipw_priv *priv =
6130 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006131 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006132 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006133 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006134}
6135
James Ketrenos43f66a62005-03-25 12:31:53 -06006136static void ipw_debug_config(struct ipw_priv *priv)
6137{
John W. Linville9387b7c2008-09-30 20:59:05 -04006138 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006139 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6140 "[CFG 0x%08X]\n", priv->config);
6141 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006142 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006143 else
6144 IPW_DEBUG_INFO("Channel unlocked.\n");
6145 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006146 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006147 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006148 else
6149 IPW_DEBUG_INFO("ESSID unlocked.\n");
6150 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006151 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006152 else
6153 IPW_DEBUG_INFO("BSSID unlocked.\n");
6154 if (priv->capability & CAP_PRIVACY_ON)
6155 IPW_DEBUG_INFO("PRIVACY on\n");
6156 else
6157 IPW_DEBUG_INFO("PRIVACY off\n");
6158 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6159}
James Ketrenos43f66a62005-03-25 12:31:53 -06006160
Arjan van de Ven858119e2006-01-14 13:20:43 -08006161static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006162{
6163 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006164 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006165 u32 reg;
6166 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006167 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006168
Jeff Garzikbf794512005-07-31 13:07:26 -04006169 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006170 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006171
James Ketrenos43f66a62005-03-25 12:31:53 -06006172 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006173 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006174 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006175 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006176 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006177 IPW_DEBUG_WX
6178 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006179 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006180 break;
6181 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006182
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006183 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006184 break;
6185
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006186 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006187 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006188 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006189 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006190 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006191 IPW_DEBUG_WX
6192 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006193 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006194 }
6195 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006196 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006197
6198 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006199 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6200 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006201 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006202 IPW_DEBUG_WX
6203 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006204 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006205 break;
6206 }
6207
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006208 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6209 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6210 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006211 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006212
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006213 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6214 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6215 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006216 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006217
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006218 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6219 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6220 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006221 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006222
Reinette Chatre21f8a732009-08-18 10:25:05 -07006223 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006224 break;
6225 }
6226
Reinette Chatre21f8a732009-08-18 10:25:05 -07006227 fr.tx_rates = cpu_to_le16(new_tx_rates);
6228
James Ketrenos43f66a62005-03-25 12:31:53 -06006229 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006230 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006231}
6232
James Ketrenosea2b26e2005-08-24 21:25:16 -05006233static void ipw_abort_scan(struct ipw_priv *priv)
6234{
6235 int err;
6236
6237 if (priv->status & STATUS_SCAN_ABORTING) {
6238 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6239 return;
6240 }
6241 priv->status |= STATUS_SCAN_ABORTING;
6242
6243 err = ipw_send_scan_abort(priv);
6244 if (err)
6245 IPW_DEBUG_HC("Request to abort scan failed.\n");
6246}
6247
James Ketrenosafbf30a2005-08-25 00:05:33 -05006248static void ipw_add_scan_channels(struct ipw_priv *priv,
6249 struct ipw_scan_request_ext *scan,
6250 int scan_type)
6251{
6252 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006253 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006254 int i;
6255
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006256 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006257
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006258 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006259 int start = channel_index;
6260 for (i = 0; i < geo->a_channels; i++) {
6261 if ((priv->status & STATUS_ASSOCIATED) &&
6262 geo->a[i].channel == priv->channel)
6263 continue;
6264 channel_index++;
6265 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006266 ipw_set_scan_type(scan, channel_index,
6267 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006268 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006269 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6270 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006271 }
6272
6273 if (start != channel_index) {
6274 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6275 (channel_index - start);
6276 channel_index++;
6277 }
6278 }
6279
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006280 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006281 int start = channel_index;
6282 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006283 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006284 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006285 /* nop out the list */
6286 [0] = 0
6287 };
6288
6289 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006290 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006291 channel =
6292 priv->speed_scan[priv->speed_scan_pos];
6293 if (channel == 0) {
6294 priv->speed_scan_pos = 0;
6295 channel = priv->speed_scan[0];
6296 }
6297 if ((priv->status & STATUS_ASSOCIATED) &&
6298 channel == priv->channel) {
6299 priv->speed_scan_pos++;
6300 continue;
6301 }
6302
6303 /* If this channel has already been
6304 * added in scan, break from loop
6305 * and this will be the first channel
6306 * in the next scan.
6307 */
6308 if (channels[channel - 1] != 0)
6309 break;
6310
6311 channels[channel - 1] = 1;
6312 priv->speed_scan_pos++;
6313 channel_index++;
6314 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006315 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006316 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006317 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006318 geo->bg[index].
6319 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006320 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006321 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6322 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006323 }
6324 } else {
6325 for (i = 0; i < geo->bg_channels; i++) {
6326 if ((priv->status & STATUS_ASSOCIATED) &&
6327 geo->bg[i].channel == priv->channel)
6328 continue;
6329 channel_index++;
6330 scan->channels_list[channel_index] =
6331 geo->bg[i].channel;
6332 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006333 geo->bg[i].
6334 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006335 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006336 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6337 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006338 }
6339 }
6340
6341 if (start != channel_index) {
6342 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6343 (channel_index - start);
6344 }
6345 }
6346}
6347
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006348static int ipw_passive_dwell_time(struct ipw_priv *priv)
6349{
6350 /* staying on passive channels longer than the DTIM interval during a
6351 * scan, while associated, causes the firmware to cancel the scan
6352 * without notification. Hence, don't stay on passive channels longer
6353 * than the beacon interval.
6354 */
6355 if (priv->status & STATUS_ASSOCIATED
6356 && priv->assoc_network->beacon_interval > 10)
6357 return priv->assoc_network->beacon_interval - 10;
6358 else
6359 return 120;
6360}
6361
Dan Williamsea177302008-06-02 17:51:23 -04006362static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006363{
6364 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006365 int err = 0, scan_type;
6366
6367 if (!(priv->status & STATUS_INIT) ||
6368 (priv->status & STATUS_EXIT_PENDING))
6369 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006370
Zhu Yi46441512006-01-24 16:37:59 +08006371 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006372
Dan Williamsea177302008-06-02 17:51:23 -04006373 if (direct && (priv->direct_scan_ssid_len == 0)) {
6374 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6375 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6376 goto done;
6377 }
6378
James Ketrenosea2b26e2005-08-24 21:25:16 -05006379 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006380 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6381 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6382 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006383 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006384 }
6385
James Ketrenosafbf30a2005-08-25 00:05:33 -05006386 if (!(priv->status & STATUS_SCAN_FORCED) &&
6387 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006388 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006389 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6390 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006391 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006392 }
6393
6394 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006395 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6396 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6397 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006398 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006399 }
6400
6401 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006402 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006403
Zhu Yi094c4d22006-08-21 11:39:03 +08006404 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006405 IPW_DEBUG_WX("use passive scanning\n");
6406 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006407 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006408 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006409 ipw_add_scan_channels(priv, &scan, scan_type);
6410 goto send_request;
6411 }
6412
6413 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006414 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006415 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006416 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006417 else
6418 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006419 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006420
James Ketrenosa613bff2005-08-24 21:43:11 -05006421 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006422 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006423
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006424 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6425 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006426 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006427
James Ketrenosb095c382005-08-24 22:04:42 -05006428#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006429 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006430 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006431 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006432
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006433 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6434 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006435 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006436 channel = priv->channel;
6437 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006438
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006439 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006440 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006441 channel = priv->channel;
6442 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006443
James Ketrenosb095c382005-08-24 22:04:42 -05006444 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006445 band = (u8) (IPW_B_MODE << 6) | 1;
6446 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006447 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006448 }
6449
James Ketrenosb095c382005-08-24 22:04:42 -05006450 scan.channels_list[0] = band;
6451 scan.channels_list[1] = channel;
6452 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006453
James Ketrenosb095c382005-08-24 22:04:42 -05006454 /* NOTE: The card will sit on this channel for this time
6455 * period. Scan aborts are timing sensitive and frequently
6456 * result in firmware restarts. As such, it is best to
6457 * set a small dwell_time here and just keep re-issuing
6458 * scans. Otherwise fast channel hopping will not actually
6459 * hop channels.
6460 *
6461 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006462 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006463 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006464 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006465#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006466 /* Honor direct scans first, otherwise if we are roaming make
6467 * this a direct scan for the current network. Finally,
6468 * ensure that every other scan is a fast channel hop scan */
6469 if (direct) {
6470 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6471 priv->direct_scan_ssid_len);
6472 if (err) {
6473 IPW_DEBUG_HC("Attempt to send SSID command "
6474 "failed\n");
6475 goto done;
6476 }
6477
6478 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6479 } else if ((priv->status & STATUS_ROAMING)
6480 || (!(priv->status & STATUS_ASSOCIATED)
6481 && (priv->config & CFG_STATIC_ESSID)
6482 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006483 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6484 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006485 IPW_DEBUG_HC("Attempt to send SSID command "
6486 "failed.\n");
6487 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006488 }
6489
6490 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006491 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006492 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006493
James Ketrenosafbf30a2005-08-25 00:05:33 -05006494 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006495#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006496 }
6497#endif
6498
Zhu Yi094c4d22006-08-21 11:39:03 +08006499send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006500 err = ipw_send_scan_request_ext(priv, &scan);
6501 if (err) {
6502 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006503 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006504 }
6505
6506 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006507 if (direct) {
6508 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6509 priv->direct_scan_ssid_len = 0;
6510 } else
6511 priv->status &= ~STATUS_SCAN_PENDING;
6512
Tejun Heobcb6d912011-01-26 12:12:50 +01006513 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006514done:
Zhu Yi46441512006-01-24 16:37:59 +08006515 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006516 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006517}
6518
David Howellsc4028952006-11-22 14:57:56 +00006519static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006520{
David Howellsc4028952006-11-22 14:57:56 +00006521 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006522 container_of(work, struct ipw_priv, request_passive_scan.work);
6523 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006524}
6525
6526static void ipw_request_scan(struct work_struct *work)
6527{
6528 struct ipw_priv *priv =
6529 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006530 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6531}
6532
6533static void ipw_request_direct_scan(struct work_struct *work)
6534{
6535 struct ipw_priv *priv =
6536 container_of(work, struct ipw_priv, request_direct_scan.work);
6537 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006538}
6539
6540static void ipw_bg_abort_scan(struct work_struct *work)
6541{
6542 struct ipw_priv *priv =
6543 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006544 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006545 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006546 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006547}
6548
James Ketrenosea2b26e2005-08-24 21:25:16 -05006549static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6550{
James Ketrenosb095c382005-08-24 22:04:42 -05006551 /* This is called when wpa_supplicant loads and closes the driver
6552 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006553 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006554 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006555}
6556
James Ketrenosea2b26e2005-08-24 21:25:16 -05006557static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6558{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006559 struct libipw_device *ieee = priv->ieee;
6560 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006561 .flags = SEC_AUTH_MODE,
6562 };
6563 int ret = 0;
6564
James Ketrenosafbf30a2005-08-25 00:05:33 -05006565 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006566 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6567 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006568 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569 sec.auth_mode = WLAN_AUTH_OPEN;
6570 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006571 } else if (value & IW_AUTH_ALG_LEAP) {
6572 sec.auth_mode = WLAN_AUTH_LEAP;
6573 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006574 } else
6575 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006576
6577 if (ieee->set_security)
6578 ieee->set_security(ieee->dev, &sec);
6579 else
6580 ret = -EOPNOTSUPP;
6581
6582 return ret;
6583}
6584
Adrian Bunka73e22b2006-01-21 01:39:42 +01006585static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6586 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006587{
6588 /* make sure WPA is enabled */
6589 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006590}
6591
6592static int ipw_set_rsn_capa(struct ipw_priv *priv,
6593 char *capabilities, int length)
6594{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006595 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6596
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006597 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006598 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006599}
6600
James Ketrenosafbf30a2005-08-25 00:05:33 -05006601/*
6602 * WE-18 support
6603 */
6604
6605/* SIOCSIWGENIE */
6606static int ipw_wx_set_genie(struct net_device *dev,
6607 struct iw_request_info *info,
6608 union iwreq_data *wrqu, char *extra)
6609{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006610 struct ipw_priv *priv = libipw_priv(dev);
6611 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 u8 *buf;
6613 int err = 0;
6614
6615 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6616 (wrqu->data.length && extra == NULL))
6617 return -EINVAL;
6618
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 if (wrqu->data.length) {
Julia Lawalld3e50332010-05-15 23:21:01 +02006620 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006621 if (buf == NULL) {
6622 err = -ENOMEM;
6623 goto out;
6624 }
6625
James Ketrenosafbf30a2005-08-25 00:05:33 -05006626 kfree(ieee->wpa_ie);
6627 ieee->wpa_ie = buf;
6628 ieee->wpa_ie_len = wrqu->data.length;
6629 } else {
6630 kfree(ieee->wpa_ie);
6631 ieee->wpa_ie = NULL;
6632 ieee->wpa_ie_len = 0;
6633 }
6634
6635 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6636 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006637 return err;
6638}
6639
6640/* SIOCGIWGENIE */
6641static int ipw_wx_get_genie(struct net_device *dev,
6642 struct iw_request_info *info,
6643 union iwreq_data *wrqu, char *extra)
6644{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006645 struct ipw_priv *priv = libipw_priv(dev);
6646 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006647 int err = 0;
6648
James Ketrenosafbf30a2005-08-25 00:05:33 -05006649 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6650 wrqu->data.length = 0;
6651 goto out;
6652 }
6653
6654 if (wrqu->data.length < ieee->wpa_ie_len) {
6655 err = -E2BIG;
6656 goto out;
6657 }
6658
6659 wrqu->data.length = ieee->wpa_ie_len;
6660 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6661
6662 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663 return err;
6664}
6665
Zhu Yi1fbfea52005-08-05 17:22:56 +08006666static int wext_cipher2level(int cipher)
6667{
6668 switch (cipher) {
6669 case IW_AUTH_CIPHER_NONE:
6670 return SEC_LEVEL_0;
6671 case IW_AUTH_CIPHER_WEP40:
6672 case IW_AUTH_CIPHER_WEP104:
6673 return SEC_LEVEL_1;
6674 case IW_AUTH_CIPHER_TKIP:
6675 return SEC_LEVEL_2;
6676 case IW_AUTH_CIPHER_CCMP:
6677 return SEC_LEVEL_3;
6678 default:
6679 return -1;
6680 }
6681}
6682
James Ketrenosafbf30a2005-08-25 00:05:33 -05006683/* SIOCSIWAUTH */
6684static int ipw_wx_set_auth(struct net_device *dev,
6685 struct iw_request_info *info,
6686 union iwreq_data *wrqu, char *extra)
6687{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006688 struct ipw_priv *priv = libipw_priv(dev);
6689 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006690 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006691 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006692 unsigned long flags;
6693 int ret = 0;
6694
6695 switch (param->flags & IW_AUTH_INDEX) {
6696 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006697 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006698 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006699 ipw_set_hw_decrypt_unicast(priv,
6700 wext_cipher2level(param->value));
6701 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006702 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006703 ipw_set_hw_decrypt_multicast(priv,
6704 wext_cipher2level(param->value));
6705 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006706 case IW_AUTH_KEY_MGMT:
6707 /*
6708 * ipw2200 does not use these parameters
6709 */
6710 break;
6711
6712 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006713 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006714 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006715 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006716
6717 flags = crypt->ops->get_flags(crypt->priv);
6718
6719 if (param->value)
6720 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6721 else
6722 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6723
6724 crypt->ops->set_flags(flags, crypt->priv);
6725
6726 break;
6727
6728 case IW_AUTH_DROP_UNENCRYPTED:{
6729 /* HACK:
6730 *
6731 * wpa_supplicant calls set_wpa_enabled when the driver
6732 * is loaded and unloaded, regardless of if WPA is being
6733 * used. No other calls are made which can be used to
6734 * determine if encryption will be used or not prior to
6735 * association being expected. If encryption is not being
6736 * used, drop_unencrypted is set to false, else true -- we
6737 * can use this to determine if the CAP_PRIVACY_ON bit should
6738 * be set.
6739 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006740 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006741 .flags = SEC_ENABLED,
6742 .enabled = param->value,
6743 };
6744 priv->ieee->drop_unencrypted = param->value;
6745 /* We only change SEC_LEVEL for open mode. Others
6746 * are set by ipw_wpa_set_encryption.
6747 */
6748 if (!param->value) {
6749 sec.flags |= SEC_LEVEL;
6750 sec.level = SEC_LEVEL_0;
6751 } else {
6752 sec.flags |= SEC_LEVEL;
6753 sec.level = SEC_LEVEL_1;
6754 }
6755 if (priv->ieee->set_security)
6756 priv->ieee->set_security(priv->ieee->dev, &sec);
6757 break;
6758 }
6759
6760 case IW_AUTH_80211_AUTH_ALG:
6761 ret = ipw_wpa_set_auth_algs(priv, param->value);
6762 break;
6763
6764 case IW_AUTH_WPA_ENABLED:
6765 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006766 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006767 break;
6768
6769 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6770 ieee->ieee802_1x = param->value;
6771 break;
6772
James Ketrenosafbf30a2005-08-25 00:05:33 -05006773 case IW_AUTH_PRIVACY_INVOKED:
6774 ieee->privacy_invoked = param->value;
6775 break;
6776
6777 default:
6778 return -EOPNOTSUPP;
6779 }
6780 return ret;
6781}
6782
6783/* SIOCGIWAUTH */
6784static int ipw_wx_get_auth(struct net_device *dev,
6785 struct iw_request_info *info,
6786 union iwreq_data *wrqu, char *extra)
6787{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006788 struct ipw_priv *priv = libipw_priv(dev);
6789 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006790 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006791 struct iw_param *param = &wrqu->param;
6792 int ret = 0;
6793
6794 switch (param->flags & IW_AUTH_INDEX) {
6795 case IW_AUTH_WPA_VERSION:
6796 case IW_AUTH_CIPHER_PAIRWISE:
6797 case IW_AUTH_CIPHER_GROUP:
6798 case IW_AUTH_KEY_MGMT:
6799 /*
6800 * wpa_supplicant will control these internally
6801 */
6802 ret = -EOPNOTSUPP;
6803 break;
6804
6805 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006806 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006807 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006808 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006809
6810 param->value = (crypt->ops->get_flags(crypt->priv) &
6811 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6812
6813 break;
6814
6815 case IW_AUTH_DROP_UNENCRYPTED:
6816 param->value = ieee->drop_unencrypted;
6817 break;
6818
6819 case IW_AUTH_80211_AUTH_ALG:
6820 param->value = ieee->sec.auth_mode;
6821 break;
6822
6823 case IW_AUTH_WPA_ENABLED:
6824 param->value = ieee->wpa_enabled;
6825 break;
6826
6827 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6828 param->value = ieee->ieee802_1x;
6829 break;
6830
6831 case IW_AUTH_ROAMING_CONTROL:
6832 case IW_AUTH_PRIVACY_INVOKED:
6833 param->value = ieee->privacy_invoked;
6834 break;
6835
6836 default:
6837 return -EOPNOTSUPP;
6838 }
6839 return 0;
6840}
6841
6842/* SIOCSIWENCODEEXT */
6843static int ipw_wx_set_encodeext(struct net_device *dev,
6844 struct iw_request_info *info,
6845 union iwreq_data *wrqu, char *extra)
6846{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006847 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006848 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6849
6850 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006851 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006852 /* IPW HW can't build TKIP MIC,
6853 host decryption still needed */
6854 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6855 priv->ieee->host_mc_decrypt = 1;
6856 else {
6857 priv->ieee->host_encrypt = 0;
6858 priv->ieee->host_encrypt_msdu = 1;
6859 priv->ieee->host_decrypt = 1;
6860 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006861 } else {
6862 priv->ieee->host_encrypt = 0;
6863 priv->ieee->host_encrypt_msdu = 0;
6864 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006865 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006866 }
6867 }
6868
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006869 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006870}
6871
6872/* SIOCGIWENCODEEXT */
6873static int ipw_wx_get_encodeext(struct net_device *dev,
6874 struct iw_request_info *info,
6875 union iwreq_data *wrqu, char *extra)
6876{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006877 struct ipw_priv *priv = libipw_priv(dev);
6878 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006879}
6880
6881/* SIOCSIWMLME */
6882static int ipw_wx_set_mlme(struct net_device *dev,
6883 struct iw_request_info *info,
6884 union iwreq_data *wrqu, char *extra)
6885{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006886 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006887 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006888 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006889
6890 reason = cpu_to_le16(mlme->reason_code);
6891
6892 switch (mlme->cmd) {
6893 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006894 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006895 break;
6896
6897 case IW_MLME_DISASSOC:
6898 ipw_disassociate(priv);
6899 break;
6900
6901 default:
6902 return -EOPNOTSUPP;
6903 }
6904 return 0;
6905}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006906
Zhu Yie43e3c12006-04-13 17:20:45 +08006907#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006908
6909/* QoS */
6910/*
6911* get the modulation type of the current network or
6912* the card current mode
6913*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006914static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006915{
6916 u8 mode = 0;
6917
6918 if (priv->status & STATUS_ASSOCIATED) {
6919 unsigned long flags;
6920
6921 spin_lock_irqsave(&priv->ieee->lock, flags);
6922 mode = priv->assoc_network->mode;
6923 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6924 } else {
6925 mode = priv->ieee->mode;
6926 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006927 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006928 return mode;
6929}
6930
6931/*
6932* Handle management frame beacon and probe response
6933*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006934static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6935 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006936 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006937{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006938 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006939
James Ketrenosafbf30a2005-08-25 00:05:33 -05006940 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006941 network->qos_data.active = network->qos_data.supported;
6942
6943 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006944 if (active_network &&
6945 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006946 network->qos_data.active = network->qos_data.supported;
6947
6948 if ((network->qos_data.active == 1) && (active_network == 1) &&
6949 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6950 (network->qos_data.old_param_count !=
6951 network->qos_data.param_count)) {
6952 network->qos_data.old_param_count =
6953 network->qos_data.param_count;
6954 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006955 IPW_DEBUG_QOS("QoS parameters change call "
6956 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006957 }
6958 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006959 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6960 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006961 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006962 else
6963 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006964 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006965
James Ketrenosb095c382005-08-24 22:04:42 -05006966 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006967 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006968 schedule_work(&priv->qos_activate);
6969 }
6970
6971 network->qos_data.active = 0;
6972 network->qos_data.supported = 0;
6973 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006974 if ((priv->status & STATUS_ASSOCIATED) &&
6975 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6976 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006977 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006978 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006979 priv->assoc_network->ssid_len) &&
6980 !memcmp(network->ssid,
6981 priv->assoc_network->ssid,
6982 network->ssid_len)) {
Tejun Heobcb6d912011-01-26 12:12:50 +01006983 schedule_work(&priv->merge_networks);
James Ketrenosb095c382005-08-24 22:04:42 -05006984 }
James Ketrenosb095c382005-08-24 22:04:42 -05006985 }
6986
6987 return 0;
6988}
6989
6990/*
6991* This function set up the firmware to support QoS. It sends
6992* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6993*/
6994static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006995 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006996{
6997 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006998 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6999 struct libipw_qos_parameters *active_one = NULL;
7000 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007001 u32 burst_duration;
7002 int i;
7003 u8 type;
7004
7005 type = ipw_qos_current_mode(priv);
7006
7007 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7008 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7009 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7010 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7011
7012 if (qos_network_data == NULL) {
7013 if (type == IEEE_B) {
7014 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7015 active_one = &def_parameters_CCK;
7016 } else
7017 active_one = &def_parameters_OFDM;
7018
James Ketrenosafbf30a2005-08-25 00:05:33 -05007019 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007020 burst_duration = ipw_qos_get_burst_duration(priv);
7021 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007022 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007023 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007024 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007025 if (type == IEEE_B) {
7026 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7027 type);
7028 if (priv->qos_data.qos_enable == 0)
7029 active_one = &def_parameters_CCK;
7030 else
7031 active_one = priv->qos_data.def_qos_parm_CCK;
7032 } else {
7033 if (priv->qos_data.qos_enable == 0)
7034 active_one = &def_parameters_OFDM;
7035 else
7036 active_one = priv->qos_data.def_qos_parm_OFDM;
7037 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007038 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007039 } else {
7040 unsigned long flags;
7041 int active;
7042
7043 spin_lock_irqsave(&priv->ieee->lock, flags);
7044 active_one = &(qos_network_data->parameters);
7045 qos_network_data->old_param_count =
7046 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007047 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007048 active = qos_network_data->supported;
7049 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7050
7051 if (active == 0) {
7052 burst_duration = ipw_qos_get_burst_duration(priv);
7053 for (i = 0; i < QOS_QUEUE_NUM; i++)
7054 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007055 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007056 }
7057 }
7058
7059 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007060 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007061 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007062 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007063 if (err)
7064 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7065
7066 return err;
7067}
7068
7069/*
7070* send IPW_CMD_WME_INFO to the firmware
7071*/
7072static int ipw_qos_set_info_element(struct ipw_priv *priv)
7073{
7074 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007075 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007076
7077 if (priv == NULL)
7078 return -1;
7079
7080 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007081 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007082
7083 qos_info.version = QOS_VERSION_1;
7084 qos_info.ac_info = 0;
7085
7086 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7087 qos_info.qui_type = QOS_OUI_TYPE;
7088 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7089
7090 ret = ipw_send_qos_info_command(priv, &qos_info);
7091 if (ret != 0) {
7092 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7093 }
7094 return ret;
7095}
7096
7097/*
7098* Set the QoS parameter with the association request structure
7099*/
7100static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007101 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007102{
7103 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007104 struct libipw_qos_data *qos_data = NULL;
7105 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007106 .supported = 1,
7107 .active = 1,
7108 };
7109
7110 switch (priv->ieee->iw_mode) {
7111 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007112 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007113
7114 qos_data = &ibss_data;
7115 break;
7116
7117 case IW_MODE_INFRA:
7118 qos_data = &network->qos_data;
7119 break;
7120
7121 default:
7122 BUG();
7123 break;
7124 }
7125
7126 err = ipw_qos_activate(priv, qos_data);
7127 if (err) {
7128 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7129 return err;
7130 }
7131
7132 if (priv->qos_data.qos_enable && qos_data->supported) {
7133 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7134 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7135 return ipw_qos_set_info_element(priv);
7136 }
7137
7138 return 0;
7139}
7140
7141/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007142* handling the beaconing responses. if we get different QoS setting
7143* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007144* setting
7145*/
7146static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007147 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007148{
7149 int ret = 0;
7150 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007151 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007152 int set_qos_param = 0;
7153
James Ketrenosafbf30a2005-08-25 00:05:33 -05007154 if ((priv == NULL) || (network == NULL) ||
7155 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007156 return ret;
7157
7158 if (!(priv->status & STATUS_ASSOCIATED))
7159 return ret;
7160
James Ketrenosafbf30a2005-08-25 00:05:33 -05007161 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007162 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007163
7164 spin_lock_irqsave(&priv->ieee->lock, flags);
7165 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007166 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007167 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007168 priv->assoc_network->qos_data.active = 1;
7169 if ((network->qos_data.old_param_count !=
7170 network->qos_data.param_count)) {
7171 set_qos_param = 1;
7172 network->qos_data.old_param_count =
7173 network->qos_data.param_count;
7174 }
7175
7176 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007177 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7178 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007179 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007180 else
7181 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007182 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007183 priv->assoc_network->qos_data.active = 0;
7184 priv->assoc_network->qos_data.supported = 0;
7185 set_qos_param = 1;
7186 }
7187
7188 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7189
7190 if (set_qos_param == 1)
7191 schedule_work(&priv->qos_activate);
7192
7193 return ret;
7194}
7195
7196static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7197{
7198 u32 ret = 0;
7199
7200 if ((priv == NULL))
7201 return 0;
7202
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007203 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007204 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007205 else
James Ketrenosb095c382005-08-24 22:04:42 -05007206 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007207
James Ketrenosb095c382005-08-24 22:04:42 -05007208 return ret;
7209}
7210
7211/*
7212* Initialize the setting of QoS global
7213*/
7214static void ipw_qos_init(struct ipw_priv *priv, int enable,
7215 int burst_enable, u32 burst_duration_CCK,
7216 u32 burst_duration_OFDM)
7217{
7218 priv->qos_data.qos_enable = enable;
7219
7220 if (priv->qos_data.qos_enable) {
7221 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7222 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7223 IPW_DEBUG_QOS("QoS is enabled\n");
7224 } else {
7225 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7226 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7227 IPW_DEBUG_QOS("QoS is not enabled\n");
7228 }
7229
7230 priv->qos_data.burst_enable = burst_enable;
7231
7232 if (burst_enable) {
7233 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7234 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7235 } else {
7236 priv->qos_data.burst_duration_CCK = 0;
7237 priv->qos_data.burst_duration_OFDM = 0;
7238 }
7239}
7240
7241/*
7242* map the packet priority to the right TX Queue
7243*/
7244static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7245{
7246 if (priority > 7 || !priv->qos_data.qos_enable)
7247 priority = 0;
7248
7249 return from_priority_to_tx_queue[priority] - 1;
7250}
7251
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007252static int ipw_is_qos_active(struct net_device *dev,
7253 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007254{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007255 struct ipw_priv *priv = libipw_priv(dev);
7256 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007257 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007258 u8 *daddr = skb->data + ETH_ALEN;
7259 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007260
7261 if (!(priv->status & STATUS_ASSOCIATED))
7262 return 0;
7263
7264 qos_data = &priv->assoc_network->qos_data;
7265
James Ketrenosb095c382005-08-24 22:04:42 -05007266 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7267 if (unicast == 0)
7268 qos_data->active = 0;
7269 else
7270 qos_data->active = qos_data->supported;
7271 }
James Ketrenosb095c382005-08-24 22:04:42 -05007272 active = qos_data->active;
7273 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007274 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7275 "unicast %d\n",
7276 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007277 if (active && priv->qos_data.qos_enable)
7278 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007279
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007280 return 0;
7281
7282}
7283/*
7284* add QoS parameter to the TX command
7285*/
7286static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7287 u16 priority,
7288 struct tfd_data *tfd)
7289{
7290 int tx_queue_id = 0;
7291
7292
7293 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7294 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7295
7296 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7297 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007298 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007299 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007300 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007301}
7302
7303/*
7304* background support to run QoS activate functionality
7305*/
David Howellsc4028952006-11-22 14:57:56 +00007306static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007307{
David Howellsc4028952006-11-22 14:57:56 +00007308 struct ipw_priv *priv =
7309 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007310
Zhu Yi46441512006-01-24 16:37:59 +08007311 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007312
7313 if (priv->status & STATUS_ASSOCIATED)
7314 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7315
Zhu Yi46441512006-01-24 16:37:59 +08007316 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007317}
7318
James Ketrenos3b9990c2005-08-19 13:18:55 -05007319static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007320 struct libipw_probe_response *resp,
7321 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007322{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007323 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007324 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7325 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007326
James Ketrenos3b9990c2005-08-19 13:18:55 -05007327 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007328
James Ketrenos3b9990c2005-08-19 13:18:55 -05007329 return 0;
7330}
James Ketrenosb095c382005-08-24 22:04:42 -05007331
James Ketrenos3b9990c2005-08-19 13:18:55 -05007332static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007333 struct libipw_beacon *resp,
7334 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007335{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007336 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007337 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7338 (network == priv->assoc_network));
7339
7340 ipw_qos_handle_probe_response(priv, active_network, network);
7341
7342 return 0;
7343}
7344
7345static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007346 struct libipw_assoc_response *resp,
7347 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007348{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007349 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007350 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007351 return 0;
7352}
7353
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007354static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007355 *qos_param)
7356{
Zhu Yi4e226992006-01-24 16:37:36 +08007357 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7358 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007359}
7360
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007361static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007362 *qos_param)
7363{
Zhu Yi4e226992006-01-24 16:37:36 +08007364 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7365 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007366}
7367
Zhu Yie43e3c12006-04-13 17:20:45 +08007368#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007369
James Ketrenos43f66a62005-03-25 12:31:53 -06007370static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007371 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007372 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007373{
7374 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007375 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007376
7377 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007378 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007379
7380 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007381 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007382 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007383 memcpy(priv->essid, network->ssid, priv->essid_len);
7384 }
7385
7386 network->last_associate = jiffies;
7387
7388 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7389 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007390 priv->assoc_request.auth_key = 0;
7391
James Ketrenos43f66a62005-03-25 12:31:53 -06007392 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007393 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007394 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007395 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7396
Zhu Yi1ba61e02006-02-15 13:00:55 +08007397 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007398 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007399
7400 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7401 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7402 priv->assoc_request.auth_type = AUTH_LEAP;
7403 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007404 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007405
James Ketrenosa613bff2005-08-24 21:43:11 -05007406 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007407 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007408 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7409 priv->ieee->wpa_ie_len);
7410 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007411
Jeff Garzikbf794512005-07-31 13:07:26 -04007412 /*
7413 * It is valid for our ieee device to support multiple modes, but
7414 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007415 * just one mode.
7416 */
7417 if (network->mode & priv->ieee->mode & IEEE_A)
7418 priv->assoc_request.ieee_mode = IPW_A_MODE;
7419 else if (network->mode & priv->ieee->mode & IEEE_G)
7420 priv->assoc_request.ieee_mode = IPW_G_MODE;
7421 else if (network->mode & priv->ieee->mode & IEEE_B)
7422 priv->assoc_request.ieee_mode = IPW_B_MODE;
7423
Al Viro5b5e8072007-12-27 01:54:06 -05007424 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007425 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7426 && !(priv->config & CFG_PREAMBLE_LONG)) {
7427 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7428 } else {
7429 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7430
7431 /* Clear the short preamble if we won't be supporting it */
7432 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007433 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007434 }
7435
James Ketrenosafbf30a2005-08-25 00:05:33 -05007436 /* Clear capability bits that aren't used in Ad Hoc */
7437 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7438 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007439 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007440
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02007441 IPW_DEBUG_ASSOC("%ssociation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007442 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007443 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007444 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007445 network->channel,
7446 ipw_modes[priv->assoc_request.ieee_mode],
7447 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007448 (priv->assoc_request.preamble_length ==
7449 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7450 network->capability &
7451 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007452 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007453 priv->capability & CAP_PRIVACY_ON ?
7454 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007455 "(open)") : "",
7456 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007457 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007458 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007459 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007460
Al Viro5b5e8072007-12-27 01:54:06 -05007461 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007462 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007463 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 priv->assoc_request.assoc_type = HC_IBSS_START;
7465 priv->assoc_request.assoc_tsf_msw = 0;
7466 priv->assoc_request.assoc_tsf_lsw = 0;
7467 } else {
7468 if (unlikely(roaming))
7469 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7470 else
7471 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007472 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7473 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007474 }
7475
James Ketrenosafbf30a2005-08-25 00:05:33 -05007476 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007477
7478 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7479 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007480 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007481 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007482 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007483 priv->assoc_request.atim_window = 0;
7484 }
7485
Al Viro5b5e8072007-12-27 01:54:06 -05007486 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007487
James Ketrenos43f66a62005-03-25 12:31:53 -06007488 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7489 if (err) {
7490 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7491 return err;
7492 }
7493
7494 rates->ieee_mode = priv->assoc_request.ieee_mode;
7495 rates->purpose = IPW_RATE_CONNECT;
7496 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007497
James Ketrenos43f66a62005-03-25 12:31:53 -06007498 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7499 priv->sys_config.dot11g_auto_detection = 1;
7500 else
7501 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007502
7503 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7504 priv->sys_config.answer_broadcast_ssid_probe = 1;
7505 else
7506 priv->sys_config.answer_broadcast_ssid_probe = 0;
7507
Zhu Yid685b8c2006-04-13 17:20:27 +08007508 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007509 if (err) {
7510 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7511 return err;
7512 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007513
James Ketrenos43f66a62005-03-25 12:31:53 -06007514 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007515 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007516 if (err) {
7517 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7518 return err;
7519 }
7520
7521 /*
7522 * If preemption is enabled, it is possible for the association
7523 * to complete before we return from ipw_send_associate. Therefore
7524 * we have to be sure and update our priviate data first.
7525 */
7526 priv->channel = network->channel;
7527 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007528 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007529 priv->status &= ~STATUS_SECURITY_UPDATED;
7530
7531 priv->assoc_network = network;
7532
Zhu Yie43e3c12006-04-13 17:20:45 +08007533#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007534 ipw_qos_association(priv, network);
7535#endif
7536
James Ketrenos43f66a62005-03-25 12:31:53 -06007537 err = ipw_send_associate(priv, &priv->assoc_request);
7538 if (err) {
7539 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7540 return err;
7541 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007542
Frans Pop9fd1ea42010-03-24 19:46:31 +01007543 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007544 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007545 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007546
7547 return 0;
7548}
7549
7550static void ipw_roam(void *data)
7551{
7552 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007553 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007554 struct ipw_network_match match = {
7555 .network = priv->assoc_network
7556 };
7557
7558 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007559 *
7560 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007561 * setting the status ROAM bit and requesting a scan.
7562 * 2. When the scan completes, it schedules the ROAM work
7563 * 3. The ROAM work looks at all of the known networks for one that
7564 * is a better network than the currently associated. If none
7565 * found, the ROAM process is over (ROAM bit cleared)
7566 * 4. If a better network is found, a disassociation request is
7567 * sent.
7568 * 5. When the disassociation completes, the roam work is again
7569 * scheduled. The second time through, the driver is no longer
7570 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007571 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007572 * 6. At this point ,the roaming process is complete and the ROAM
7573 * status bit is cleared.
7574 */
7575
7576 /* If we are no longer associated, and the roaming bit is no longer
7577 * set, then we are not actively roaming, so just return */
7578 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7579 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007580
James Ketrenos43f66a62005-03-25 12:31:53 -06007581 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007582 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007583 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007584 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007585 u8 rssi = priv->assoc_network->stats.rssi;
7586 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007587 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007588 list_for_each_entry(network, &priv->ieee->network_list, list) {
7589 if (network != priv->assoc_network)
7590 ipw_best_network(priv, &match, network, 1);
7591 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007592 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007593 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007594
James Ketrenos43f66a62005-03-25 12:31:53 -06007595 if (match.network == priv->assoc_network) {
7596 IPW_DEBUG_ASSOC("No better APs in this network to "
7597 "roam to.\n");
7598 priv->status &= ~STATUS_ROAMING;
7599 ipw_debug_config(priv);
7600 return;
7601 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007602
James Ketrenos43f66a62005-03-25 12:31:53 -06007603 ipw_send_disassociate(priv, 1);
7604 priv->assoc_network = match.network;
7605
7606 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007607 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007608
7609 /* Second pass through ROAM process -- request association */
7610 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7611 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7612 priv->status &= ~STATUS_ROAMING;
7613}
7614
David Howellsc4028952006-11-22 14:57:56 +00007615static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007616{
David Howellsc4028952006-11-22 14:57:56 +00007617 struct ipw_priv *priv =
7618 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007619 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007620 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007621 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007622}
7623
7624static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007625{
7626 struct ipw_priv *priv = data;
7627
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007628 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007629 struct ipw_network_match match = {
7630 .network = NULL
7631 };
7632 struct ipw_supported_rates *rates;
7633 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007634 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007635 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007636
James Ketrenosb095c382005-08-24 22:04:42 -05007637 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7638 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7639 return 0;
7640 }
7641
James Ketrenosc848d0a2005-08-24 21:56:24 -05007642 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007643 IPW_DEBUG_ASSOC("Not attempting association (already in "
7644 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007645 return 0;
7646 }
7647
Hong Liue6324722005-09-14 21:04:15 -05007648 if (priv->status & STATUS_DISASSOCIATING) {
7649 IPW_DEBUG_ASSOC("Not attempting association (in "
7650 "disassociating)\n ");
Tejun Heobcb6d912011-01-26 12:12:50 +01007651 schedule_work(&priv->associate);
Hong Liue6324722005-09-14 21:04:15 -05007652 return 0;
7653 }
7654
James Ketrenosc848d0a2005-08-24 21:56:24 -05007655 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007656 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7657 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007658 return 0;
7659 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007660
7661 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007662 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007663 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007664 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007665 }
7666
James Ketrenosa613bff2005-08-24 21:43:11 -05007667 /* Protect our use of the network_list */
7668 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007669 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007670 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007671
7672 network = match.network;
7673 rates = &match.rates;
7674
7675 if (network == NULL &&
7676 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7677 priv->config & CFG_ADHOC_CREATE &&
7678 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007679 priv->config & CFG_STATIC_CHANNEL) {
7680 /* Use oldest network if the free list is empty */
7681 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007682 struct libipw_network *oldest = NULL;
7683 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007684
7685 list_for_each_entry(target, &priv->ieee->network_list, list) {
7686 if ((oldest == NULL) ||
7687 (target->last_scanned < oldest->last_scanned))
7688 oldest = target;
7689 }
7690
7691 /* If there are no more slots, expire the oldest */
7692 list_del(&oldest->list);
7693 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007694 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007695 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007696 print_ssid(ssid, target->ssid,
7697 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007698 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007699 list_add_tail(&target->list,
7700 &priv->ieee->network_free_list);
7701 }
7702
James Ketrenos43f66a62005-03-25 12:31:53 -06007703 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007704 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007705 ipw_adhoc_create(priv, network);
7706 rates = &priv->rates;
7707 list_del(element);
7708 list_add_tail(&network->list, &priv->ieee->network_list);
7709 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007710 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007711
James Ketrenos43f66a62005-03-25 12:31:53 -06007712 /* If we reached the end of the list, then we don't have any valid
7713 * matching APs */
7714 if (!network) {
7715 ipw_debug_config(priv);
7716
James Ketrenosb095c382005-08-24 22:04:42 -05007717 if (!(priv->status & STATUS_SCANNING)) {
7718 if (!(priv->config & CFG_SPEED_SCAN))
Tejun Heobcb6d912011-01-26 12:12:50 +01007719 schedule_delayed_work(&priv->request_scan,
7720 SCAN_INTERVAL);
James Ketrenosb095c382005-08-24 22:04:42 -05007721 else
Tejun Heobcb6d912011-01-26 12:12:50 +01007722 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007723 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007724
James Ketrenosc848d0a2005-08-24 21:56:24 -05007725 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007726 }
7727
7728 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007729
7730 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007731}
Jeff Garzikbf794512005-07-31 13:07:26 -04007732
David Howellsc4028952006-11-22 14:57:56 +00007733static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007734{
David Howellsc4028952006-11-22 14:57:56 +00007735 struct ipw_priv *priv =
7736 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007737 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007738 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007739 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007740}
7741
James Ketrenosb095c382005-08-24 22:04:42 -05007742static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7743 struct sk_buff *skb)
7744{
7745 struct ieee80211_hdr *hdr;
7746 u16 fc;
7747
7748 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007749 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007750 if (!(fc & IEEE80211_FCTL_PROTECTED))
7751 return;
7752
7753 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007754 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007755 switch (priv->ieee->sec.level) {
7756 case SEC_LEVEL_3:
7757 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007758 memmove(skb->data + LIBIPW_3ADDR_LEN,
7759 skb->data + LIBIPW_3ADDR_LEN + 8,
7760 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007761 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007762 break;
7763 case SEC_LEVEL_2:
7764 break;
7765 case SEC_LEVEL_1:
7766 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007767 memmove(skb->data + LIBIPW_3ADDR_LEN,
7768 skb->data + LIBIPW_3ADDR_LEN + 4,
7769 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007770 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007771 break;
7772 case SEC_LEVEL_0:
7773 break;
7774 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007775 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007776 priv->ieee->sec.level);
7777 break;
7778 }
7779}
7780
7781static void ipw_handle_data_packet(struct ipw_priv *priv,
7782 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007783 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007784{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007785 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007786 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007787 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7788
7789 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007790 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007791
Jeff Garzikbf794512005-07-31 13:07:26 -04007792 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007793 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007794 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007795 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007796 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007797 priv->wstats.discard.misc++;
7798 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7799 return;
7800 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007801 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007802 priv->wstats.discard.misc++;
7803 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7804 return;
7805 }
7806
7807 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007808 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007809
7810 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007811 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007812
7813 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7814
James Ketrenosb095c382005-08-24 22:04:42 -05007815 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007816 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007817 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007818 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007819 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007820 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7821
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007822 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007823 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007824 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007825 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007826 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007827 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007828}
7829
Zhu Yi459d4082006-04-13 17:21:00 +08007830#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007831static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7832 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007833 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007834{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007835 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007836 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7837 struct ipw_rx_frame *frame = &pkt->u.frame;
7838
7839 /* initial pull of some data */
7840 u16 received_channel = frame->received_channel;
7841 u8 antennaAndPhy = frame->antennaAndPhy;
7842 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7843 u16 pktrate = frame->rate;
7844
7845 /* Magic struct that slots into the radiotap header -- no reason
7846 * to build this manually element by element, we can write it much
7847 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007848 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007849
Dan Carpenter92c1ff12012-01-12 09:34:50 +03007850 unsigned short len = le16_to_cpu(pkt->u.frame.length);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007851
7852 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007853 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007854
7855 /* We only process data packets if the
7856 * interface is open */
7857 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7858 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007859 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007860 priv->wstats.discard.misc++;
7861 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7862 return;
7863 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007864 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007865 priv->wstats.discard.misc++;
7866 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7867 return;
7868 }
7869
7870 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7871 * that now */
7872 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7873 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007874 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007875 priv->wstats.discard.misc++;
7876 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7877 return;
7878 }
7879
7880 /* copy the frame itself */
7881 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7882 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7883
Mike Kershaw24a47db2005-08-26 00:41:54 -05007884 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7885
7886 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7887 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007888 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007889
7890 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007891 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7892 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007893 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007894 (1 << IEEE80211_RADIOTAP_RATE) |
7895 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7896 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007897 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007898 (1 << IEEE80211_RADIOTAP_ANTENNA));
7899
7900 /* Zero the flags, we'll add to them as we go */
7901 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007902 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7903 frame->parent_tsf[2] << 16 |
7904 frame->parent_tsf[1] << 8 |
7905 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007906
7907 /* Convert signal to DBM */
7908 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007909 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007910
7911 /* Convert the channel data and set the flags */
7912 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7913 if (received_channel > 14) { /* 802.11a */
7914 ipw_rt->rt_chbitmask =
7915 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7916 } else if (antennaAndPhy & 32) { /* 802.11b */
7917 ipw_rt->rt_chbitmask =
7918 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7919 } else { /* 802.11g */
7920 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007921 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007922 }
7923
7924 /* set the rate in multiples of 500k/s */
7925 switch (pktrate) {
7926 case IPW_TX_RATE_1MB:
7927 ipw_rt->rt_rate = 2;
7928 break;
7929 case IPW_TX_RATE_2MB:
7930 ipw_rt->rt_rate = 4;
7931 break;
7932 case IPW_TX_RATE_5MB:
7933 ipw_rt->rt_rate = 10;
7934 break;
7935 case IPW_TX_RATE_6MB:
7936 ipw_rt->rt_rate = 12;
7937 break;
7938 case IPW_TX_RATE_9MB:
7939 ipw_rt->rt_rate = 18;
7940 break;
7941 case IPW_TX_RATE_11MB:
7942 ipw_rt->rt_rate = 22;
7943 break;
7944 case IPW_TX_RATE_12MB:
7945 ipw_rt->rt_rate = 24;
7946 break;
7947 case IPW_TX_RATE_18MB:
7948 ipw_rt->rt_rate = 36;
7949 break;
7950 case IPW_TX_RATE_24MB:
7951 ipw_rt->rt_rate = 48;
7952 break;
7953 case IPW_TX_RATE_36MB:
7954 ipw_rt->rt_rate = 72;
7955 break;
7956 case IPW_TX_RATE_48MB:
7957 ipw_rt->rt_rate = 96;
7958 break;
7959 case IPW_TX_RATE_54MB:
7960 ipw_rt->rt_rate = 108;
7961 break;
7962 default:
7963 ipw_rt->rt_rate = 0;
7964 break;
7965 }
7966
7967 /* antenna number */
7968 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7969
7970 /* set the preamble flag if we have it */
7971 if ((antennaAndPhy & 64))
7972 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7973
7974 /* Set the size of the skb to the size of the frame */
7975 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007976
7977 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7978
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007979 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007980 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007981 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007982 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007983 /* no LED during capture */
7984 }
7985}
7986#endif
7987
Zhu Yid685b8c2006-04-13 17:20:27 +08007988#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007989#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007990 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7991 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7992
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007993#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007994 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7995
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007996#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007997 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7998
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007999#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008000 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8001
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008002#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008003 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8004
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008005#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008006 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8007
8008static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8009 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008010 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008011{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008012 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008013 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8014 struct ipw_rx_frame *frame = &pkt->u.frame;
8015 struct ipw_rt_hdr *ipw_rt;
8016
8017 /* First cache any information we need before we overwrite
8018 * the information provided in the skb from the hardware */
8019 struct ieee80211_hdr *hdr;
8020 u16 channel = frame->received_channel;
8021 u8 phy_flags = frame->antennaAndPhy;
8022 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008023 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008024 u8 rate = frame->rate;
Dan Carpenter92c1ff12012-01-12 09:34:50 +03008025 unsigned short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008026 struct sk_buff *skb;
8027 int hdr_only = 0;
8028 u16 filter = priv->prom_priv->filter;
8029
8030 /* If the filter is set to not include Rx frames then return */
8031 if (filter & IPW_PROM_NO_RX)
8032 return;
8033
Zhu Yid685b8c2006-04-13 17:20:27 +08008034 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008035 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008036
8037 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008038 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008039 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8040 return;
8041 }
8042
8043 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008044 if (unlikely(!netif_running(dev))) {
8045 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008046 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8047 return;
8048 }
8049
8050 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8051 * that now */
8052 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8053 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008054 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008055 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8056 return;
8057 }
8058
8059 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008060 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008061 if (filter & IPW_PROM_NO_MGMT)
8062 return;
8063 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8064 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008065 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008066 if (filter & IPW_PROM_NO_CTL)
8067 return;
8068 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8069 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008070 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008071 if (filter & IPW_PROM_NO_DATA)
8072 return;
8073 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8074 hdr_only = 1;
8075 }
8076
8077 /* Copy the SKB since this is for the promiscuous side */
8078 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8079 if (skb == NULL) {
8080 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8081 return;
8082 }
8083
8084 /* copy the frame data to write after where the radiotap header goes */
8085 ipw_rt = (void *)skb->data;
8086
8087 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008088 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008089
8090 memcpy(ipw_rt->payload, hdr, len);
8091
Zhu Yid685b8c2006-04-13 17:20:27 +08008092 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8093 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008094 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008095
8096 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008097 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008098
8099 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008100 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8101 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008102 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008103 (1 << IEEE80211_RADIOTAP_RATE) |
8104 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8105 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8106 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8107 (1 << IEEE80211_RADIOTAP_ANTENNA));
8108
8109 /* Zero the flags, we'll add to them as we go */
8110 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008111 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8112 frame->parent_tsf[2] << 16 |
8113 frame->parent_tsf[1] << 8 |
8114 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008115
8116 /* Convert to DBM */
8117 ipw_rt->rt_dbmsignal = signal;
8118 ipw_rt->rt_dbmnoise = noise;
8119
8120 /* Convert the channel data and set the flags */
8121 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8122 if (channel > 14) { /* 802.11a */
8123 ipw_rt->rt_chbitmask =
8124 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8125 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8126 ipw_rt->rt_chbitmask =
8127 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8128 } else { /* 802.11g */
8129 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008130 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008131 }
8132
8133 /* set the rate in multiples of 500k/s */
8134 switch (rate) {
8135 case IPW_TX_RATE_1MB:
8136 ipw_rt->rt_rate = 2;
8137 break;
8138 case IPW_TX_RATE_2MB:
8139 ipw_rt->rt_rate = 4;
8140 break;
8141 case IPW_TX_RATE_5MB:
8142 ipw_rt->rt_rate = 10;
8143 break;
8144 case IPW_TX_RATE_6MB:
8145 ipw_rt->rt_rate = 12;
8146 break;
8147 case IPW_TX_RATE_9MB:
8148 ipw_rt->rt_rate = 18;
8149 break;
8150 case IPW_TX_RATE_11MB:
8151 ipw_rt->rt_rate = 22;
8152 break;
8153 case IPW_TX_RATE_12MB:
8154 ipw_rt->rt_rate = 24;
8155 break;
8156 case IPW_TX_RATE_18MB:
8157 ipw_rt->rt_rate = 36;
8158 break;
8159 case IPW_TX_RATE_24MB:
8160 ipw_rt->rt_rate = 48;
8161 break;
8162 case IPW_TX_RATE_36MB:
8163 ipw_rt->rt_rate = 72;
8164 break;
8165 case IPW_TX_RATE_48MB:
8166 ipw_rt->rt_rate = 96;
8167 break;
8168 case IPW_TX_RATE_54MB:
8169 ipw_rt->rt_rate = 108;
8170 break;
8171 default:
8172 ipw_rt->rt_rate = 0;
8173 break;
8174 }
8175
8176 /* antenna number */
8177 ipw_rt->rt_antenna = (phy_flags & 3);
8178
8179 /* set the preamble flag if we have it */
8180 if (phy_flags & (1 << 6))
8181 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8182
8183 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8184
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008185 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008186 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008187 dev_kfree_skb_any(skb);
8188 }
8189}
8190#endif
8191
Arjan van de Ven858119e2006-01-14 13:20:43 -08008192static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008193 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008194{
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008195 /* Filter incoming packets to determine if they are targeted toward
James Ketrenosea2b26e2005-08-24 21:25:16 -05008196 * this network, discarding packets coming from ourselves */
8197 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008198 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008199 /* packets from our adapter are dropped (echo) */
8200 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8201 return 0;
8202
Peter Jones90700fd2005-08-26 16:51:06 -05008203 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008204 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008205 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008206
8207 /* packets to our adapter go through */
8208 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8209 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008210
Peter Jones90700fd2005-08-26 16:51:06 -05008211 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008212 /* packets from our adapter are dropped (echo) */
8213 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8214 return 0;
8215
Peter Jones90700fd2005-08-26 16:51:06 -05008216 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008217 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008218 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8219
8220 /* packets to our adapter go through */
8221 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8222 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008223 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008224
James Ketrenosea2b26e2005-08-24 21:25:16 -05008225 return 1;
8226}
8227
James Ketrenosafbf30a2005-08-25 00:05:33 -05008228#define IPW_PACKET_RETRY_TIME HZ
8229
Arjan van de Ven858119e2006-01-14 13:20:43 -08008230static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008231 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008232{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008233 u16 sc = le16_to_cpu(header->seq_ctl);
8234 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8235 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8236 u16 *last_seq, *last_frag;
8237 unsigned long *last_time;
8238
8239 switch (priv->ieee->iw_mode) {
8240 case IW_MODE_ADHOC:
8241 {
8242 struct list_head *p;
8243 struct ipw_ibss_seq *entry = NULL;
8244 u8 *mac = header->addr2;
8245 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8246
8247 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8248 entry =
8249 list_entry(p, struct ipw_ibss_seq, list);
8250 if (!memcmp(entry->mac, mac, ETH_ALEN))
8251 break;
8252 }
8253 if (p == &priv->ibss_mac_hash[index]) {
8254 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8255 if (!entry) {
8256 IPW_ERROR
8257 ("Cannot malloc new mac entry\n");
8258 return 0;
8259 }
8260 memcpy(entry->mac, mac, ETH_ALEN);
8261 entry->seq_num = seq;
8262 entry->frag_num = frag;
8263 entry->packet_time = jiffies;
8264 list_add(&entry->list,
8265 &priv->ibss_mac_hash[index]);
8266 return 0;
8267 }
8268 last_seq = &entry->seq_num;
8269 last_frag = &entry->frag_num;
8270 last_time = &entry->packet_time;
8271 break;
8272 }
8273 case IW_MODE_INFRA:
8274 last_seq = &priv->last_seq_num;
8275 last_frag = &priv->last_frag_num;
8276 last_time = &priv->last_packet_time;
8277 break;
8278 default:
8279 return 0;
8280 }
8281 if ((*last_seq == seq) &&
8282 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8283 if (*last_frag == frag)
8284 goto drop;
8285 if (*last_frag + 1 != frag)
8286 /* out-of-order fragment */
8287 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008288 } else
8289 *last_seq = seq;
8290
Zhu Yif57ce7c2005-07-13 12:22:15 -05008291 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008292 *last_time = jiffies;
8293 return 0;
8294
8295 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008296 /* Comment this line now since we observed the card receives
8297 * duplicate packets but the FCTL_RETRY bit is not set in the
8298 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008299 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008300 return 1;
8301}
8302
James Ketrenosb095c382005-08-24 22:04:42 -05008303static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8304 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008305 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008306{
8307 struct sk_buff *skb = rxb->skb;
8308 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008309 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008310 (skb->data + IPW_RX_FRAME_SIZE);
8311
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008312 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008313
8314 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8315 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8316 IEEE80211_STYPE_PROBE_RESP) ||
8317 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8318 IEEE80211_STYPE_BEACON))) {
8319 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8320 ipw_add_station(priv, header->addr2);
8321 }
8322
8323 if (priv->config & CFG_NET_STATS) {
8324 IPW_DEBUG_HC("sending stat packet\n");
8325
8326 /* Set the size of the skb to the size of the full
8327 * ipw header and 802.11 frame */
8328 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8329 IPW_RX_FRAME_SIZE);
8330
8331 /* Advance past the ipw packet header to the 802.11 frame */
8332 skb_pull(skb, IPW_RX_FRAME_SIZE);
8333
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008334 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008335 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8336
8337 skb->dev = priv->ieee->dev;
8338
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008339 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008340 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008341
8342 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008343 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008344 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8345 netif_rx(skb);
8346 rxb->skb = NULL;
8347 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008348}
8349
James Ketrenos43f66a62005-03-25 12:31:53 -06008350/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008351 * Main entry function for receiving a packet with 80211 headers. This
James Ketrenos43f66a62005-03-25 12:31:53 -06008352 * should be called when ever the FW has notified us that there is a new
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008353 * skb in the receive queue.
James Ketrenos43f66a62005-03-25 12:31:53 -06008354 */
8355static void ipw_rx(struct ipw_priv *priv)
8356{
8357 struct ipw_rx_mem_buffer *rxb;
8358 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008359 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008360 u32 r, w, i;
8361 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008362 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008363
James Ketrenosb095c382005-08-24 22:04:42 -05008364 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8365 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008366 i = priv->rxq->read;
8367
8368 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8369 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008370
8371 while (i != r) {
8372 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008373 if (unlikely(rxb == NULL)) {
8374 printk(KERN_CRIT "Queue not allocated!\n");
8375 break;
8376 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008377 priv->rxq->queue[i] = NULL;
8378
8379 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008380 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008381 PCI_DMA_FROMDEVICE);
8382
8383 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8384 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8385 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008386 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008387
8388 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008389 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008390 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008391 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008392 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008393 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008394 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008395 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008396 .noise =
8397 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008398 .rate = pkt->u.frame.rate,
8399 .mac_time = jiffies,
8400 .received_channel =
8401 pkt->u.frame.received_channel,
8402 .freq =
8403 (pkt->u.frame.
8404 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008405 LIBIPW_24GHZ_BAND :
8406 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008407 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008408 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008409
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008410 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008411 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008412 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008413 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008414 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008415 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008416 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008417 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008418
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008419 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008420
Zhu Yid685b8c2006-04-13 17:20:27 +08008421#ifdef CONFIG_IPW2200_PROMISCUOUS
8422 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8423 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8424#endif
8425
James Ketrenosb095c382005-08-24 22:04:42 -05008426#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008427 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008428#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008429
8430 ipw_handle_data_packet_monitor(priv,
8431 rxb,
8432 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008433#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008434 ipw_handle_data_packet(priv, rxb,
8435 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008436#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008437 break;
8438 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008439#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008440
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008441 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008442 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008443 data +
8444 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008445 /* TODO: Check Ad-Hoc dest/source and make sure
8446 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008447 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008448 * frame control of the packet and disregard
8449 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008450
James Ketrenosea2b26e2005-08-24 21:25:16 -05008451 network_packet =
8452 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008453 if (network_packet && priv->assoc_network) {
8454 priv->assoc_network->stats.rssi =
8455 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008456 priv->exp_avg_rssi =
8457 exponential_average(priv->exp_avg_rssi,
8458 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008459 }
8460
8461 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008462 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008463
James Ketrenosa613bff2005-08-24 21:43:11 -05008464 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008465 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008466 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008467 IPW_DEBUG_DROP
8468 ("Received packet is too small. "
8469 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008470 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008471 priv->wstats.discard.misc++;
8472 break;
8473 }
8474
James Ketrenosa613bff2005-08-24 21:43:11 -05008475 switch (WLAN_FC_GET_TYPE
8476 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008477
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008478 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008479 ipw_handle_mgmt_packet(priv, rxb,
8480 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008481 break;
8482
8483 case IEEE80211_FTYPE_CTL:
8484 break;
8485
8486 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008487 if (unlikely(!network_packet ||
8488 is_duplicate_packet(priv,
8489 header)))
8490 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008491 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008492 "%pM, "
8493 "%pM, "
8494 "%pM\n",
8495 header->addr1,
8496 header->addr2,
8497 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008498 break;
8499 }
8500
8501 ipw_handle_data_packet(priv, rxb,
8502 &stats);
8503
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008504 break;
8505 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008506 break;
8507 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008508
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008509 case RX_HOST_NOTIFICATION_TYPE:{
8510 IPW_DEBUG_RX
8511 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008512 pkt->u.notification.subtype,
8513 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008514 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008515 ipw_rx_notification(priv, &pkt->u.notification);
8516 break;
8517 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008518
8519 default:
8520 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8521 pkt->header.message_type);
8522 break;
8523 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008524
8525 /* For now we just don't re-use anything. We can tweak this
8526 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008527 * fail to Rx correctly */
8528 if (rxb->skb != NULL) {
8529 dev_kfree_skb_any(rxb->skb);
8530 rxb->skb = NULL;
8531 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008532
James Ketrenos43f66a62005-03-25 12:31:53 -06008533 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008534 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008535 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008536
James Ketrenos43f66a62005-03-25 12:31:53 -06008537 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008538
8539 /* If there are a lot of unsued frames, restock the Rx queue
8540 * so the ucode won't assert */
8541 if (fill_rx) {
8542 priv->rxq->read = i;
8543 ipw_rx_queue_replenish(priv);
8544 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 }
8546
8547 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008548 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008549 ipw_rx_queue_restock(priv);
8550}
8551
James Ketrenosafbf30a2005-08-25 00:05:33 -05008552#define DEFAULT_RTS_THRESHOLD 2304U
8553#define MIN_RTS_THRESHOLD 1U
8554#define MAX_RTS_THRESHOLD 2304U
8555#define DEFAULT_BEACON_INTERVAL 100U
8556#define DEFAULT_SHORT_RETRY_LIMIT 7U
8557#define DEFAULT_LONG_RETRY_LIMIT 4U
8558
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008559/**
8560 * ipw_sw_reset
8561 * @option: options to control different reset behaviour
8562 * 0 = reset everything except the 'disable' module_param
8563 * 1 = reset everything and print out driver info (for probe only)
8564 * 2 = reset everything
8565 */
8566static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008567{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008568 int band, modulation;
8569 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008570
James Ketrenosafbf30a2005-08-25 00:05:33 -05008571 /* Initialize module parameter values here */
8572 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008573
James Ketrenosafbf30a2005-08-25 00:05:33 -05008574 /* We default to disabling the LED code as right now it causes
8575 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008576 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008577 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008578
James Ketrenosafbf30a2005-08-25 00:05:33 -05008579 if (associate)
8580 priv->config |= CFG_ASSOCIATE;
8581 else
8582 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008583
James Ketrenosafbf30a2005-08-25 00:05:33 -05008584 if (auto_create)
8585 priv->config |= CFG_ADHOC_CREATE;
8586 else
8587 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8588
Zhu Yi17ed0812006-01-24 16:36:31 +08008589 priv->config &= ~CFG_STATIC_ESSID;
8590 priv->essid_len = 0;
8591 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8592
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008593 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008594 priv->status |= STATUS_RF_KILL_SW;
8595 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 }
8597
Reinette Chatre21f8a732009-08-18 10:25:05 -07008598 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008599 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008600 priv->channel = default_channel;
8601 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008602 /* TODO: Validate that provided channel is in range */
8603 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008604#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008605 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8606 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008607#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008608
Reinette Chatre21f8a732009-08-18 10:25:05 -07008609 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008610 case 1:
8611 priv->ieee->iw_mode = IW_MODE_ADHOC;
8612 priv->net_dev->type = ARPHRD_ETHER;
8613
8614 break;
8615#ifdef CONFIG_IPW2200_MONITOR
8616 case 2:
8617 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008618#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008619 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8620#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008621 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008622#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008623 break;
8624#endif
8625 default:
8626 case 0:
8627 priv->net_dev->type = ARPHRD_ETHER;
8628 priv->ieee->iw_mode = IW_MODE_INFRA;
8629 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008630 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008631
James Ketrenosafbf30a2005-08-25 00:05:33 -05008632 if (hwcrypto) {
8633 priv->ieee->host_encrypt = 0;
8634 priv->ieee->host_encrypt_msdu = 0;
8635 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008636 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008637 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008638 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008639
Zhu Yie402c932005-08-05 17:20:40 +08008640 /* IPW2200/2915 is abled to do hardware fragmentation. */
8641 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008642
James Ketrenosafbf30a2005-08-25 00:05:33 -05008643 if ((priv->pci_dev->device == 0x4223) ||
8644 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008645 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008646 printk(KERN_INFO DRV_NAME
8647 ": Detected Intel PRO/Wireless 2915ABG Network "
8648 "Connection\n");
8649 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008650 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8651 modulation = LIBIPW_OFDM_MODULATION |
8652 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008653 priv->adapter = IPW_2915ABG;
8654 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008655 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008656 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008657 printk(KERN_INFO DRV_NAME
8658 ": Detected Intel PRO/Wireless 2200BG Network "
8659 "Connection\n");
8660
8661 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008662 band = LIBIPW_24GHZ_BAND;
8663 modulation = LIBIPW_OFDM_MODULATION |
8664 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008665 priv->adapter = IPW_2200BG;
8666 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008667 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008668
James Ketrenosafbf30a2005-08-25 00:05:33 -05008669 priv->ieee->freq_band = band;
8670 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008671
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008672 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008673
James Ketrenosafbf30a2005-08-25 00:05:33 -05008674 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8675 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008676
James Ketrenosafbf30a2005-08-25 00:05:33 -05008677 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8678 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8679 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008680
James Ketrenosafbf30a2005-08-25 00:05:33 -05008681 /* If power management is turned on, default to AC mode */
8682 priv->power_mode = IPW_POWER_AC;
8683 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008684
Zhu Yi0ece35b2005-08-05 17:26:51 +08008685 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008686}
8687
8688/*
8689 * This file defines the Wireless Extension handlers. It does not
8690 * define any methods of hardware manipulation and relies on the
8691 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008692 *
8693 * The exception to this is the use of the ipw_get_ordinal()
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008694 * function used to poll the hardware vs. making unnecessary calls.
James Ketrenos43f66a62005-03-25 12:31:53 -06008695 *
8696 */
8697
James Ketrenos43f66a62005-03-25 12:31:53 -06008698static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8699{
8700 if (channel == 0) {
8701 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8702 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008703 IPW_DEBUG_ASSOC("Attempting to associate with new "
8704 "parameters.\n");
8705 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008706 return 0;
8707 }
8708
8709 priv->config |= CFG_STATIC_CHANNEL;
8710
8711 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008712 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8713 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008714 return 0;
8715 }
8716
8717 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8718 priv->channel = channel;
8719
James Ketrenosb095c382005-08-24 22:04:42 -05008720#ifdef CONFIG_IPW2200_MONITOR
8721 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008722 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008723 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008724 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008725 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008726 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008727 }
8728
8729 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8730 udelay(10);
8731
8732 if (priv->status & STATUS_SCANNING)
8733 IPW_DEBUG_SCAN("Still scanning...\n");
8734 else
8735 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8736 1000 - i);
8737
8738 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 }
James Ketrenosb095c382005-08-24 22:04:42 -05008740#endif /* CONFIG_IPW2200_MONITOR */
8741
James Ketrenosc848d0a2005-08-24 21:56:24 -05008742 /* Network configuration changed -- force [re]association */
8743 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8744 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008745 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008746
8747 return 0;
8748}
8749
Jeff Garzikbf794512005-07-31 13:07:26 -04008750static int ipw_wx_set_freq(struct net_device *dev,
8751 struct iw_request_info *info,
8752 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008753{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008754 struct ipw_priv *priv = libipw_priv(dev);
8755 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008756 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008757 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008758 u8 channel, flags;
8759 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008760
James Ketrenosb095c382005-08-24 22:04:42 -05008761 if (fwrq->m == 0) {
8762 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008763 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008764 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008765 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008766 return ret;
8767 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008768 /* if setting by freq convert to channel */
8769 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008770 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008771 if (channel == 0)
8772 return -EINVAL;
8773 } else
8774 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008775
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008776 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008777 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008778
Liu Hong1fe0adb2005-08-19 09:33:10 -05008779 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008780 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008781 if (i == -1)
8782 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008783
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008784 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008785 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008786 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008787 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8788 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 }
8790 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008791
Frans Pop9fd1ea42010-03-24 19:46:31 +01008792 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008793 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008794 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008795 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008796 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008797}
8798
Jeff Garzikbf794512005-07-31 13:07:26 -04008799static int ipw_wx_get_freq(struct net_device *dev,
8800 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008801 union iwreq_data *wrqu, char *extra)
8802{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008803 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008804
8805 wrqu->freq.e = 0;
8806
8807 /* If we are associated, trying to associate, or have a statically
8808 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008809 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008811 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8812 int i;
8813
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008814 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008815 BUG_ON(i == -1);
8816 wrqu->freq.e = 1;
8817
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008818 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8819 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008820 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8821 break;
8822
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008823 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008824 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8825 break;
8826
8827 default:
8828 BUG();
8829 }
8830 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 wrqu->freq.m = 0;
8832
Zhu Yi46441512006-01-24 16:37:59 +08008833 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008834 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008835 return 0;
8836}
8837
Jeff Garzikbf794512005-07-31 13:07:26 -04008838static int ipw_wx_set_mode(struct net_device *dev,
8839 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 union iwreq_data *wrqu, char *extra)
8841{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008842 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008843 int err = 0;
8844
8845 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8846
James Ketrenos43f66a62005-03-25 12:31:53 -06008847 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008848#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008849 case IW_MODE_MONITOR:
8850#endif
8851 case IW_MODE_ADHOC:
8852 case IW_MODE_INFRA:
8853 break;
8854 case IW_MODE_AUTO:
8855 wrqu->mode = IW_MODE_INFRA;
8856 break;
8857 default:
8858 return -EINVAL;
8859 }
James Ketrenosb095c382005-08-24 22:04:42 -05008860 if (wrqu->mode == priv->ieee->iw_mode)
8861 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008862
Zhu Yi46441512006-01-24 16:37:59 +08008863 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008864
8865 ipw_sw_reset(priv, 0);
8866
James Ketrenosb095c382005-08-24 22:04:42 -05008867#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008868 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008869 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008870
8871 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008872#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008873 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8874#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008875 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008876#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008877#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008878
Jeff Garzikbf794512005-07-31 13:07:26 -04008879 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008880 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008881 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008882
8883 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008884
Tejun Heobcb6d912011-01-26 12:12:50 +01008885 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008886 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008887 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008888}
8889
Jeff Garzikbf794512005-07-31 13:07:26 -04008890static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008891 struct iw_request_info *info,
8892 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008893{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008894 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008895 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008896 wrqu->mode = priv->ieee->iw_mode;
8897 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008898 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008899 return 0;
8900}
8901
James Ketrenos43f66a62005-03-25 12:31:53 -06008902/* Values are in microsecond */
8903static const s32 timeout_duration[] = {
8904 350000,
8905 250000,
8906 75000,
8907 37000,
8908 25000,
8909};
8910
8911static const s32 period_duration[] = {
8912 400000,
8913 700000,
8914 1000000,
8915 1000000,
8916 1000000
8917};
8918
Jeff Garzikbf794512005-07-31 13:07:26 -04008919static int ipw_wx_get_range(struct net_device *dev,
8920 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008921 union iwreq_data *wrqu, char *extra)
8922{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008923 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008924 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008925 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008926 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008927
8928 wrqu->data.length = sizeof(*range);
8929 memset(range, 0, sizeof(*range));
8930
8931 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008932 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008933
8934 range->max_qual.qual = 100;
8935 /* TODO: Find real max RSSI and stick here */
8936 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008937 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008938 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008939
8940 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008941 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008942 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008943 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008944 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008945 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008946 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008947
Jeff Garzikbf794512005-07-31 13:07:26 -04008948 for (i = 0; i < range->num_bitrates; i++)
8949 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008950 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008951
James Ketrenos43f66a62005-03-25 12:31:53 -06008952 range->max_rts = DEFAULT_RTS_THRESHOLD;
8953 range->min_frag = MIN_FRAG_THRESHOLD;
8954 range->max_frag = MAX_FRAG_THRESHOLD;
8955
8956 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008957 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008958 range->num_encoding_sizes = 2;
8959 range->max_encoding_tokens = WEP_KEYS;
8960
8961 /* Set the Wireless Extension versions */
8962 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008963 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008964
James Ketrenosb095c382005-08-24 22:04:42 -05008965 i = 0;
8966 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008967 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8968 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008969 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008970 continue;
8971
James Ketrenosb095c382005-08-24 22:04:42 -05008972 range->freq[i].i = geo->bg[j].channel;
8973 range->freq[i].m = geo->bg[j].freq * 100000;
8974 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008975 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008976 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008977 }
James Ketrenosb095c382005-08-24 22:04:42 -05008978
8979 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008980 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8981 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008982 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008983 continue;
8984
James Ketrenosb095c382005-08-24 22:04:42 -05008985 range->freq[i].i = geo->a[j].channel;
8986 range->freq[i].m = geo->a[j].freq * 100000;
8987 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008988 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008989 }
8990 }
8991
8992 range->num_channels = i;
8993 range->num_frequency = i;
8994
Zhu Yi46441512006-01-24 16:37:59 +08008995 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008996
8997 /* Event capability (kernel + driver) */
8998 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8999 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08009000 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9001 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009002 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009003
Dan Williamsf1b50862006-01-30 13:58:56 -05009004 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9005 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9006
Dan Williams374fdfb2007-12-12 10:25:07 -05009007 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9008
James Ketrenos43f66a62005-03-25 12:31:53 -06009009 IPW_DEBUG_WX("GET Range\n");
9010 return 0;
9011}
9012
Jeff Garzikbf794512005-07-31 13:07:26 -04009013static int ipw_wx_set_wap(struct net_device *dev,
9014 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009015 union iwreq_data *wrqu, char *extra)
9016{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009017 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009018
9019 static const unsigned char any[] = {
9020 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9021 };
9022 static const unsigned char off[] = {
9023 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9024 };
9025
Jeff Garzikbf794512005-07-31 13:07:26 -04009026 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009027 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009028 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009029 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9030 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9031 /* we disable mandatory BSSID association */
9032 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9033 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009034 IPW_DEBUG_ASSOC("Attempting to associate with new "
9035 "parameters.\n");
9036 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009037 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009038 return 0;
9039 }
9040
9041 priv->config |= CFG_STATIC_BSSID;
9042 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9043 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009044 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009045 return 0;
9046 }
9047
Johannes Berge1749612008-10-27 15:59:26 -07009048 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9049 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009050
9051 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9052
James Ketrenosc848d0a2005-08-24 21:56:24 -05009053 /* Network configuration changed -- force [re]association */
9054 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9055 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009056 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009057
Zhu Yi46441512006-01-24 16:37:59 +08009058 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009059 return 0;
9060}
9061
Jeff Garzikbf794512005-07-31 13:07:26 -04009062static int ipw_wx_get_wap(struct net_device *dev,
9063 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 union iwreq_data *wrqu, char *extra)
9065{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009066 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009067
James Ketrenos43f66a62005-03-25 12:31:53 -06009068 /* If we are associated, trying to associate, or have a statically
9069 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009070 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009071 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009072 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9073 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009074 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009075 } else
9076 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9077
Johannes Berge1749612008-10-27 15:59:26 -07009078 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9079 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009080 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009081 return 0;
9082}
9083
Jeff Garzikbf794512005-07-31 13:07:26 -04009084static int ipw_wx_set_essid(struct net_device *dev,
9085 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009086 union iwreq_data *wrqu, char *extra)
9087{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009088 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009089 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009090 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009091
Zhu Yiab644b02006-08-21 11:37:13 +08009092 mutex_lock(&priv->mutex);
9093
9094 if (!wrqu->essid.flags)
9095 {
9096 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9097 ipw_disassociate(priv);
9098 priv->config &= ~CFG_STATIC_ESSID;
9099 ipw_associate(priv);
9100 mutex_unlock(&priv->mutex);
9101 return 0;
9102 }
9103
Zhu Yia9f0d422006-08-21 11:37:26 +08009104 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009105
9106 priv->config |= CFG_STATIC_ESSID;
9107
Zhu Yia9f0d422006-08-21 11:37:26 +08009108 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9109 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009110 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009111 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009112 return 0;
9113 }
9114
John W. Linville9387b7c2008-09-30 20:59:05 -04009115 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9116 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009117
9118 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009119 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009120
James Ketrenosc848d0a2005-08-24 21:56:24 -05009121 /* Network configuration changed -- force [re]association */
9122 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9123 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009124 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009125
Zhu Yi46441512006-01-24 16:37:59 +08009126 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009127 return 0;
9128}
9129
Jeff Garzikbf794512005-07-31 13:07:26 -04009130static int ipw_wx_get_essid(struct net_device *dev,
9131 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009132 union iwreq_data *wrqu, char *extra)
9133{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009134 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009135 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009136
9137 /* If we are associated, trying to associate, or have a statically
9138 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009139 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009141 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9142 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009143 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009144 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009145 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009146 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009147 } else {
9148 IPW_DEBUG_WX("Getting essid: ANY\n");
9149 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009150 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009151 }
Zhu Yi46441512006-01-24 16:37:59 +08009152 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009153 return 0;
9154}
9155
Jeff Garzikbf794512005-07-31 13:07:26 -04009156static int ipw_wx_set_nick(struct net_device *dev,
9157 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009158 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009159{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009160 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009161
9162 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9163 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9164 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009165 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009166 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009167 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009168 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009170 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009171 return 0;
9172
9173}
9174
Jeff Garzikbf794512005-07-31 13:07:26 -04009175static int ipw_wx_get_nick(struct net_device *dev,
9176 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009177 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009178{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009179 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009180 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009181 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009182 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009183 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009184 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009185 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009186 return 0;
9187}
9188
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009189static int ipw_wx_set_sens(struct net_device *dev,
9190 struct iw_request_info *info,
9191 union iwreq_data *wrqu, char *extra)
9192{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009193 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009194 int err = 0;
9195
9196 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9197 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9198 mutex_lock(&priv->mutex);
9199
9200 if (wrqu->sens.fixed == 0)
9201 {
9202 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9203 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9204 goto out;
9205 }
9206 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9207 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9208 err = -EINVAL;
9209 goto out;
9210 }
9211
9212 priv->roaming_threshold = wrqu->sens.value;
9213 priv->disassociate_threshold = 3*wrqu->sens.value;
9214 out:
9215 mutex_unlock(&priv->mutex);
9216 return err;
9217}
9218
9219static int ipw_wx_get_sens(struct net_device *dev,
9220 struct iw_request_info *info,
9221 union iwreq_data *wrqu, char *extra)
9222{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009223 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009224 mutex_lock(&priv->mutex);
9225 wrqu->sens.fixed = 1;
9226 wrqu->sens.value = priv->roaming_threshold;
9227 mutex_unlock(&priv->mutex);
9228
Frans Pop9fd1ea42010-03-24 19:46:31 +01009229 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009230 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9231
9232 return 0;
9233}
9234
James Ketrenos43f66a62005-03-25 12:31:53 -06009235static int ipw_wx_set_rate(struct net_device *dev,
9236 struct iw_request_info *info,
9237 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009238{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009239 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009240 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009241 u32 target_rate = wrqu->bitrate.value;
9242 u32 fixed, mask;
9243
9244 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9245 /* value = X, fixed = 1 means only rate X */
9246 /* value = X, fixed = 0 means all rates lower equal X */
9247
9248 if (target_rate == -1) {
9249 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009250 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009251 /* Now we should reassociate */
9252 goto apply;
9253 }
9254
9255 mask = 0;
9256 fixed = wrqu->bitrate.fixed;
9257
9258 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009259 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009260 if (target_rate == 1000000)
9261 goto apply;
9262
9263 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009264 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009265 if (target_rate == 2000000)
9266 goto apply;
9267
9268 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009269 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009270 if (target_rate == 5500000)
9271 goto apply;
9272
9273 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009274 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009275 if (target_rate == 6000000)
9276 goto apply;
9277
9278 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009279 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009280 if (target_rate == 9000000)
9281 goto apply;
9282
9283 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009284 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009285 if (target_rate == 11000000)
9286 goto apply;
9287
9288 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009289 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009290 if (target_rate == 12000000)
9291 goto apply;
9292
9293 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009294 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009295 if (target_rate == 18000000)
9296 goto apply;
9297
9298 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009299 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009300 if (target_rate == 24000000)
9301 goto apply;
9302
9303 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009304 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009305 if (target_rate == 36000000)
9306 goto apply;
9307
9308 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009309 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009310 if (target_rate == 48000000)
9311 goto apply;
9312
9313 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009314 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009315 if (target_rate == 54000000)
9316 goto apply;
9317
9318 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9319 return -EINVAL;
9320
9321 apply:
9322 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9323 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009324 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009325 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009326 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009327 ipw_set_fixed_rate(priv, priv->ieee->mode);
9328 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009329 priv->config |= CFG_FIXED_RATE;
9330
James Ketrenosc848d0a2005-08-24 21:56:24 -05009331 if (priv->rates_mask == mask) {
9332 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009333 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009334 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009335 }
9336
James Ketrenosc848d0a2005-08-24 21:56:24 -05009337 priv->rates_mask = mask;
9338
9339 /* Network configuration changed -- force [re]association */
9340 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9341 if (!ipw_disassociate(priv))
9342 ipw_associate(priv);
9343
Zhu Yi46441512006-01-24 16:37:59 +08009344 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009345 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009346}
9347
Jeff Garzikbf794512005-07-31 13:07:26 -04009348static int ipw_wx_get_rate(struct net_device *dev,
9349 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009350 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009351{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009352 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009353 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009354 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009355 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009356 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009357 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 return 0;
9359}
9360
Jeff Garzikbf794512005-07-31 13:07:26 -04009361static int ipw_wx_set_rts(struct net_device *dev,
9362 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009364{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009365 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009366 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009367 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009368 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9369 else {
9370 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009371 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009372 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009374 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 priv->rts_threshold = wrqu->rts.value;
9376 }
9377
9378 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009379 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009380 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009381 return 0;
9382}
9383
Jeff Garzikbf794512005-07-31 13:07:26 -04009384static int ipw_wx_get_rts(struct net_device *dev,
9385 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009386 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009387{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009388 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009389 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009390 wrqu->rts.value = priv->rts_threshold;
9391 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009392 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009393 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009394 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009395 return 0;
9396}
9397
Jeff Garzikbf794512005-07-31 13:07:26 -04009398static int ipw_wx_set_txpow(struct net_device *dev,
9399 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009400 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009401{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009402 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009403 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009404
Zhu Yi46441512006-01-24 16:37:59 +08009405 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009406 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009407 err = -EINPROGRESS;
9408 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009409 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009410
James Ketrenosb095c382005-08-24 22:04:42 -05009411 if (!wrqu->power.fixed)
9412 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009413
James Ketrenosc848d0a2005-08-24 21:56:24 -05009414 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009415 err = -EINVAL;
9416 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009417 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009418
James Ketrenosb095c382005-08-24 22:04:42 -05009419 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009420 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009421 err = -EINVAL;
9422 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009423 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009424
9425 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009426 err = ipw_set_tx_power(priv);
9427 out:
Zhu Yi46441512006-01-24 16:37:59 +08009428 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009429 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009430}
9431
Jeff Garzikbf794512005-07-31 13:07:26 -04009432static int ipw_wx_get_txpow(struct net_device *dev,
9433 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009434 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009435{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009436 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009437 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009438 wrqu->power.value = priv->tx_power;
9439 wrqu->power.fixed = 1;
9440 wrqu->power.flags = IW_TXPOW_DBM;
9441 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009442 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009443
Frans Pop9fd1ea42010-03-24 19:46:31 +01009444 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009445 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009446
9447 return 0;
9448}
9449
Jeff Garzikbf794512005-07-31 13:07:26 -04009450static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009451 struct iw_request_info *info,
9452 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009453{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009454 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009455 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009456 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009457 priv->ieee->fts = DEFAULT_FTS;
9458 else {
9459 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009460 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009461 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009462 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009463 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009464
James Ketrenos43f66a62005-03-25 12:31:53 -06009465 priv->ieee->fts = wrqu->frag.value & ~0x1;
9466 }
9467
9468 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009469 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009470 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009471 return 0;
9472}
9473
Jeff Garzikbf794512005-07-31 13:07:26 -04009474static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009475 struct iw_request_info *info,
9476 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009477{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009478 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009479 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009480 wrqu->frag.value = priv->ieee->fts;
9481 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009482 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009483 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009484 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009485
9486 return 0;
9487}
9488
Jeff Garzikbf794512005-07-31 13:07:26 -04009489static int ipw_wx_set_retry(struct net_device *dev,
9490 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009491 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009492{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009493 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009494
9495 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9496 return -EINVAL;
9497
9498 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9499 return 0;
9500
Zhu Yid5f7ac22006-08-21 11:38:17 +08009501 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009502 return -EINVAL;
9503
Zhu Yi46441512006-01-24 16:37:59 +08009504 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009505 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009506 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009507 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009508 priv->long_retry_limit = (u8) wrqu->retry.value;
9509 else {
9510 priv->short_retry_limit = (u8) wrqu->retry.value;
9511 priv->long_retry_limit = (u8) wrqu->retry.value;
9512 }
9513
9514 ipw_send_retry_limit(priv, priv->short_retry_limit,
9515 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009516 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009517 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9518 priv->short_retry_limit, priv->long_retry_limit);
9519 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009520}
9521
Jeff Garzikbf794512005-07-31 13:07:26 -04009522static int ipw_wx_get_retry(struct net_device *dev,
9523 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009524 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009525{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009526 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009527
Zhu Yi46441512006-01-24 16:37:59 +08009528 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009529 wrqu->retry.disabled = 0;
9530
9531 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009532 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009533 return -EINVAL;
9534 }
9535
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009536 if (wrqu->retry.flags & IW_RETRY_LONG) {
9537 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009538 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009539 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9540 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009541 wrqu->retry.value = priv->short_retry_limit;
9542 } else {
9543 wrqu->retry.flags = IW_RETRY_LIMIT;
9544 wrqu->retry.value = priv->short_retry_limit;
9545 }
Zhu Yi46441512006-01-24 16:37:59 +08009546 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009547
Frans Pop9fd1ea42010-03-24 19:46:31 +01009548 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009549
9550 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009551}
9552
Jeff Garzikbf794512005-07-31 13:07:26 -04009553static int ipw_wx_set_scan(struct net_device *dev,
9554 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009555 union iwreq_data *wrqu, char *extra)
9556{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009557 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009558 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009559 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009560
Dan Williams0b531672007-10-09 13:55:24 -04009561 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009562
Dan Williams0b531672007-10-09 13:55:24 -04009563 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009564
Zhu Yi094c4d22006-08-21 11:39:03 +08009565 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009566 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009567 int len = min((int)req->essid_len,
9568 (int)sizeof(priv->direct_scan_ssid));
9569 memcpy(priv->direct_scan_ssid, req->essid, len);
9570 priv->direct_scan_ssid_len = len;
9571 work = &priv->request_direct_scan;
9572 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9573 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009574 }
Dan Williamsea177302008-06-02 17:51:23 -04009575 } else {
9576 /* Normal active broadcast scan */
9577 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009578 }
James Ketrenos8935f392005-10-05 15:59:08 -05009579
Dan Williamsea177302008-06-02 17:51:23 -04009580 mutex_unlock(&priv->mutex);
9581
James Ketrenos43f66a62005-03-25 12:31:53 -06009582 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009583
Tejun Heobcb6d912011-01-26 12:12:50 +01009584 schedule_delayed_work(work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009585
James Ketrenos43f66a62005-03-25 12:31:53 -06009586 return 0;
9587}
9588
Jeff Garzikbf794512005-07-31 13:07:26 -04009589static int ipw_wx_get_scan(struct net_device *dev,
9590 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009591 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009592{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009593 struct ipw_priv *priv = libipw_priv(dev);
9594 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009595}
9596
Jeff Garzikbf794512005-07-31 13:07:26 -04009597static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009598 struct iw_request_info *info,
9599 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009600{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009601 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009602 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009603 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009604
Zhu Yi46441512006-01-24 16:37:59 +08009605 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009606 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009607
Hong Liucaeff812005-08-05 17:25:50 +08009608 /* In IBSS mode, we need to notify the firmware to update
9609 * the beacon info after we changed the capability. */
9610 if (cap != priv->capability &&
9611 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9612 priv->status & STATUS_ASSOCIATED)
9613 ipw_disassociate(priv);
9614
Zhu Yi46441512006-01-24 16:37:59 +08009615 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009616 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009617}
9618
Jeff Garzikbf794512005-07-31 13:07:26 -04009619static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009620 struct iw_request_info *info,
9621 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009622{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009623 struct ipw_priv *priv = libipw_priv(dev);
9624 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009625}
9626
Jeff Garzikbf794512005-07-31 13:07:26 -04009627static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009628 struct iw_request_info *info,
9629 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009630{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009631 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009632 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009633 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 if (wrqu->power.disabled) {
9635 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9636 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9637 if (err) {
9638 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009639 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009640 return err;
9641 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009643 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009645 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009646
9647 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009648 case IW_POWER_ON: /* If not specified */
9649 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009650 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009651 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009652 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9654 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009655 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009656 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009657 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009658
James Ketrenos43f66a62005-03-25 12:31:53 -06009659 /* If the user hasn't specified a power management mode yet, default
9660 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009661 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009662 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009663 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009664 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009665
James Ketrenos43f66a62005-03-25 12:31:53 -06009666 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9667 if (err) {
9668 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009669 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 return err;
9671 }
9672
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009673 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009674 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009675 return 0;
9676}
9677
Jeff Garzikbf794512005-07-31 13:07:26 -04009678static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009679 struct iw_request_info *info,
9680 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009681{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009682 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009683 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009684 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009685 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009686 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009688
Zhu Yi46441512006-01-24 16:37:59 +08009689 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009690 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009691
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 return 0;
9693}
9694
Jeff Garzikbf794512005-07-31 13:07:26 -04009695static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009696 struct iw_request_info *info,
9697 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009698{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009699 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009700 int mode = *(int *)extra;
9701 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009702
Zhu Yi46441512006-01-24 16:37:59 +08009703 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009704 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009705 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009706
Zhu Yi4e157f02007-07-12 16:09:32 +08009707 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009708 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 if (err) {
9710 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009711 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009712 return err;
9713 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009714 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009715 }
Zhu Yi46441512006-01-24 16:37:59 +08009716 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009717 return 0;
9718}
9719
9720#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009721static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009722 struct iw_request_info *info,
9723 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009724{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009725 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 int level = IPW_POWER_LEVEL(priv->power_mode);
9727 char *p = extra;
9728
9729 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9730
9731 switch (level) {
9732 case IPW_POWER_AC:
9733 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9734 break;
9735 case IPW_POWER_BATTERY:
9736 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9737 break;
9738 default:
9739 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009740 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 timeout_duration[level - 1] / 1000,
9742 period_duration[level - 1] / 1000);
9743 }
9744
9745 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009746 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009747
9748 wrqu->data.length = p - extra + 1;
9749
9750 return 0;
9751}
9752
9753static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009754 struct iw_request_info *info,
9755 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009756{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009757 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009758 int mode = *(int *)extra;
9759 u8 band = 0, modulation = 0;
9760
9761 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009762 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009763 return -EINVAL;
9764 }
Zhu Yi46441512006-01-24 16:37:59 +08009765 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009766 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009767 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009768 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009769 band |= LIBIPW_52GHZ_BAND;
9770 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009771 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009772 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009773 } else {
9774 if (mode & IEEE_A) {
9775 IPW_WARNING("Attempt to set 2200BG into "
9776 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009777 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009778 return -EINVAL;
9779 }
9780
James Ketrenosa33a1982005-09-14 14:28:59 -05009781 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009782 }
9783
9784 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009785 band |= LIBIPW_24GHZ_BAND;
9786 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009788 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009789
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009791 band |= LIBIPW_24GHZ_BAND;
9792 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009793 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009794 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009795
9796 priv->ieee->mode = mode;
9797 priv->ieee->freq_band = band;
9798 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009799 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009800
James Ketrenosc848d0a2005-08-24 21:56:24 -05009801 /* Network configuration changed -- force [re]association */
9802 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9803 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009804 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009805 ipw_associate(priv);
9806 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009807
James Ketrenosa613bff2005-08-24 21:43:11 -05009808 /* Update the band LEDs */
9809 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009810
Jeff Garzikbf794512005-07-31 13:07:26 -04009811 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009812 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009813 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009814 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009815 return 0;
9816}
9817
9818static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009819 struct iw_request_info *info,
9820 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009821{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009822 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009823 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009824 switch (priv->ieee->mode) {
9825 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009826 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9827 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009828 case IEEE_B:
9829 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9830 break;
9831 case IEEE_A | IEEE_B:
9832 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9833 break;
9834 case IEEE_G:
9835 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9836 break;
9837 case IEEE_A | IEEE_G:
9838 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9839 break;
9840 case IEEE_B | IEEE_G:
9841 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9842 break;
9843 case IEEE_A | IEEE_B | IEEE_G:
9844 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9845 break;
9846 default:
9847 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009848 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009849 }
9850
James Ketrenos43f66a62005-03-25 12:31:53 -06009851 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009853 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009854 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009855
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009856 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009857}
9858
James Ketrenosea2b26e2005-08-24 21:25:16 -05009859static int ipw_wx_set_preamble(struct net_device *dev,
9860 struct iw_request_info *info,
9861 union iwreq_data *wrqu, char *extra)
9862{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009863 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009864 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009865 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009866 /* Switching from SHORT -> LONG requires a disassociation */
9867 if (mode == 1) {
9868 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9869 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009870
9871 /* Network configuration changed -- force [re]association */
9872 IPW_DEBUG_ASSOC
9873 ("[re]association triggered due to preamble change.\n");
9874 if (!ipw_disassociate(priv))
9875 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009876 }
9877 goto done;
9878 }
9879
9880 if (mode == 0) {
9881 priv->config &= ~CFG_PREAMBLE_LONG;
9882 goto done;
9883 }
Zhu Yi46441512006-01-24 16:37:59 +08009884 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009885 return -EINVAL;
9886
9887 done:
Zhu Yi46441512006-01-24 16:37:59 +08009888 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009889 return 0;
9890}
9891
9892static int ipw_wx_get_preamble(struct net_device *dev,
9893 struct iw_request_info *info,
9894 union iwreq_data *wrqu, char *extra)
9895{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009896 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009897 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009898 if (priv->config & CFG_PREAMBLE_LONG)
9899 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9900 else
9901 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009902 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009903 return 0;
9904}
9905
James Ketrenosb095c382005-08-24 22:04:42 -05009906#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009907static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009908 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009910{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009911 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009912 int *parms = (int *)extra;
9913 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009914 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009915 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009916 if (enable) {
9917 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009918#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009919 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9920#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009921 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009922#endif
Tejun Heobcb6d912011-01-26 12:12:50 +01009923 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009924 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009925
James Ketrenos43f66a62005-03-25 12:31:53 -06009926 ipw_set_channel(priv, parms[1]);
9927 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009928 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009929 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009930 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009931 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009932 priv->net_dev->type = ARPHRD_ETHER;
Tejun Heobcb6d912011-01-26 12:12:50 +01009933 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009934 }
Zhu Yi46441512006-01-24 16:37:59 +08009935 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009936 return 0;
9937}
9938
Pavel Machek67fd6b42006-07-11 15:34:05 +02009939#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009940
Jeff Garzikbf794512005-07-31 13:07:26 -04009941static int ipw_wx_reset(struct net_device *dev,
9942 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009943 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009944{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009945 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009946 IPW_DEBUG_WX("RESET\n");
Tejun Heobcb6d912011-01-26 12:12:50 +01009947 schedule_work(&priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009948 return 0;
9949}
James Ketrenosb095c382005-08-24 22:04:42 -05009950
James Ketrenosb095c382005-08-24 22:04:42 -05009951static int ipw_wx_sw_reset(struct net_device *dev,
9952 struct iw_request_info *info,
9953 union iwreq_data *wrqu, char *extra)
9954{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009955 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009956 union iwreq_data wrqu_sec = {
9957 .encoding = {
9958 .flags = IW_ENCODE_DISABLED,
9959 },
9960 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009961 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009962
9963 IPW_DEBUG_WX("SW_RESET\n");
9964
Zhu Yi46441512006-01-24 16:37:59 +08009965 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009966
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009967 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009968 if (!ret) {
9969 free_firmware();
9970 ipw_adapter_restart(priv);
9971 }
James Ketrenosb095c382005-08-24 22:04:42 -05009972
9973 /* The SW reset bit might have been toggled on by the 'disable'
9974 * module parameter, so take appropriate action */
9975 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9976
Zhu Yi46441512006-01-24 16:37:59 +08009977 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009978 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009979 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009980
9981 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9982 /* Configuration likely changed -- force [re]association */
9983 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9984 "reset.\n");
9985 if (!ipw_disassociate(priv))
9986 ipw_associate(priv);
9987 }
9988
Zhu Yi46441512006-01-24 16:37:59 +08009989 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009990
9991 return 0;
9992}
James Ketrenos43f66a62005-03-25 12:31:53 -06009993
9994/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009995static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -07009996 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
9997 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9998 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
9999 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
10000 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
10001 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
10002 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
10003 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
10004 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
10005 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
10006 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
10007 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10008 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10009 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10010 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10011 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10012 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10013 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10014 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10015 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10016 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10017 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10018 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10019 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10020 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10021 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10022 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10023 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10024 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10025 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10026 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10027 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10028 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10029 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10030 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10031 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10032 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10033 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10034 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10035 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10036 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010037};
10038
James Ketrenosb095c382005-08-24 22:04:42 -050010039enum {
10040 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10041 IPW_PRIV_GET_POWER,
10042 IPW_PRIV_SET_MODE,
10043 IPW_PRIV_GET_MODE,
10044 IPW_PRIV_SET_PREAMBLE,
10045 IPW_PRIV_GET_PREAMBLE,
10046 IPW_PRIV_RESET,
10047 IPW_PRIV_SW_RESET,
10048#ifdef CONFIG_IPW2200_MONITOR
10049 IPW_PRIV_SET_MONITOR,
10050#endif
10051};
James Ketrenos43f66a62005-03-25 12:31:53 -060010052
Jeff Garzikbf794512005-07-31 13:07:26 -040010053static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010055 .cmd = IPW_PRIV_SET_POWER,
10056 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10057 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010058 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010059 .cmd = IPW_PRIV_GET_POWER,
10060 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10061 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010063 .cmd = IPW_PRIV_SET_MODE,
10064 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10065 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010066 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010067 .cmd = IPW_PRIV_GET_MODE,
10068 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10069 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010070 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010071 .cmd = IPW_PRIV_SET_PREAMBLE,
10072 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10073 .name = "set_preamble"},
10074 {
10075 .cmd = IPW_PRIV_GET_PREAMBLE,
10076 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10077 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010078 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010079 IPW_PRIV_RESET,
10080 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010081 {
10082 IPW_PRIV_SW_RESET,
10083 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10084#ifdef CONFIG_IPW2200_MONITOR
10085 {
10086 IPW_PRIV_SET_MONITOR,
10087 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10088#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010089};
10090
10091static iw_handler ipw_priv_handler[] = {
10092 ipw_wx_set_powermode,
10093 ipw_wx_get_powermode,
10094 ipw_wx_set_wireless_mode,
10095 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010096 ipw_wx_set_preamble,
10097 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010098 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010099 ipw_wx_sw_reset,
10100#ifdef CONFIG_IPW2200_MONITOR
10101 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010102#endif
10103};
10104
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010105static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010106 .standard = ipw_wx_handlers,
10107 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10108 .num_private = ARRAY_SIZE(ipw_priv_handler),
10109 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10110 .private = ipw_priv_handler,
10111 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010112 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010113};
10114
James Ketrenos43f66a62005-03-25 12:31:53 -060010115/*
10116 * Get wireless statistics.
10117 * Called by /proc/net/wireless
10118 * Also called by SIOCGIWSTATS
10119 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010120static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010121{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010122 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010123 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010124
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 wstats = &priv->wstats;
10126
James Ketrenosea2b26e2005-08-24 21:25:16 -050010127 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010128 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010129 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10130 * and associated; if not associcated, the values are all meaningless
10131 * anyway, so set them all to NULL and INVALID */
10132 if (!(priv->status & STATUS_ASSOCIATED)) {
10133 wstats->miss.beacon = 0;
10134 wstats->discard.retries = 0;
10135 wstats->qual.qual = 0;
10136 wstats->qual.level = 0;
10137 wstats->qual.noise = 0;
10138 wstats->qual.updated = 7;
10139 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010140 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010141 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010142 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010143
10144 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010145 wstats->qual.level = priv->exp_avg_rssi;
10146 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010147 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010148 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010149
10150 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10151 wstats->discard.retries = priv->last_tx_failures;
10152 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010153
James Ketrenos43f66a62005-03-25 12:31:53 -060010154/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10155 goto fail_get_ordinal;
10156 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010157
James Ketrenos43f66a62005-03-25 12:31:53 -060010158 return wstats;
10159}
10160
James Ketrenos43f66a62005-03-25 12:31:53 -060010161/* net device stuff */
10162
Arjan van de Ven858119e2006-01-14 13:20:43 -080010163static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010164{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010165 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010166 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010167 sys_config->answer_broadcast_ssid_probe = 0;
10168 sys_config->accept_all_data_frames = 0;
10169 sys_config->accept_non_directed_frames = 1;
10170 sys_config->exclude_unicast_unencrypted = 0;
10171 sys_config->disable_unicast_decryption = 1;
10172 sys_config->exclude_multicast_unencrypted = 0;
10173 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010174 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10175 antenna = CFG_SYS_ANTENNA_BOTH;
10176 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010177 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010178 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010179 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010181 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010182 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010183}
10184
10185static int ipw_net_open(struct net_device *dev)
10186{
James Ketrenos43f66a62005-03-25 12:31:53 -060010187 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010188 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010189 return 0;
10190}
10191
10192static int ipw_net_stop(struct net_device *dev)
10193{
10194 IPW_DEBUG_INFO("dev->close\n");
10195 netif_stop_queue(dev);
10196 return 0;
10197}
10198
10199/*
10200todo:
10201
10202modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010203we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010204*/
10205
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010206static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010207 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010208{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010209 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010210 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 int i = 0;
10212 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010213#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010214 int tx_id = ipw_get_tx_queue_number(priv, pri);
10215 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10216#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010217 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010218#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010219 struct clx2_queue *q = &txq->q;
10220 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010221 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010222
Zhu Yib8ddafd2008-11-27 13:42:20 +080010223 if (!(priv->status & STATUS_ASSOCIATED))
10224 goto drop;
10225
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010226 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010227 switch (priv->ieee->iw_mode) {
10228 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010229 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010230 id = ipw_find_station(priv, hdr->addr1);
10231 if (id == IPW_INVALID_STATION) {
10232 id = ipw_add_station(priv, hdr->addr1);
10233 if (id == IPW_INVALID_STATION) {
10234 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010235 "invalid cell: %pM\n",
10236 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010237 goto drop;
10238 }
10239 }
10240 break;
10241
10242 case IW_MODE_INFRA:
10243 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010244 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010245 id = 0;
10246 break;
10247 }
10248
10249 tfd = &txq->bd[q->first_empty];
10250 txq->txb[q->first_empty] = txb;
10251 memset(tfd, 0, sizeof(*tfd));
10252 tfd->u.data.station_number = id;
10253
10254 tfd->control_flags.message_type = TX_FRAME_TYPE;
10255 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10256
10257 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010258 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010259
James Ketrenos43f66a62005-03-25 12:31:53 -060010260 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010261 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010262 else
James Ketrenosb095c382005-08-24 22:04:42 -050010263 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010264
James Ketrenosea2b26e2005-08-24 21:25:16 -050010265 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10266 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010267
James Ketrenosc848d0a2005-08-24 21:56:24 -050010268 fc = le16_to_cpu(hdr->frame_ctl);
10269 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010270
10271 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10272
James Ketrenosb095c382005-08-24 22:04:42 -050010273 if (likely(unicast))
10274 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10275
10276 if (txb->encrypted && !priv->ieee->host_encrypt) {
10277 switch (priv->ieee->sec.level) {
10278 case SEC_LEVEL_3:
10279 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010280 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010281 /* XXX: ACK flag must be set for CCMP even if it
10282 * is a multicast/broadcast packet, because CCMP
10283 * group communication encrypted by GTK is
10284 * actually done by the AP. */
10285 if (!unicast)
10286 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10287
10288 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10289 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10290 tfd->u.data.key_index = 0;
10291 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10292 break;
10293 case SEC_LEVEL_2:
10294 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010295 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010296 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10297 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10298 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10299 break;
10300 case SEC_LEVEL_1:
10301 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010302 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010303 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10304 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010305 40)
10306 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10307 else
10308 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10309 break;
10310 case SEC_LEVEL_0:
10311 break;
10312 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010313 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010314 priv->ieee->sec.level);
10315 break;
10316 }
10317 } else
10318 /* No hardware encryption */
10319 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10320
Zhu Yie43e3c12006-04-13 17:20:45 +080010321#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010322 if (fc & IEEE80211_STYPE_QOS_DATA)
10323 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010324#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010325
James Ketrenos43f66a62005-03-25 12:31:53 -060010326 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010327 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10328 txb->nr_frags));
10329 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10330 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10331 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10332 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10333 i, le32_to_cpu(tfd->u.data.num_chunks),
10334 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010335 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010336 i, tfd->u.data.num_chunks,
10337 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010338 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010339 txb->fragments[i]->len - hdr_len);
10340
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010341 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010342 cpu_to_le32(pci_map_single
10343 (priv->pci_dev,
10344 txb->fragments[i]->data + hdr_len,
10345 txb->fragments[i]->len - hdr_len,
10346 PCI_DMA_TODEVICE));
10347 tfd->u.data.chunk_len[i] =
10348 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010349 }
10350
10351 if (i != txb->nr_frags) {
10352 struct sk_buff *skb;
10353 u16 remaining_bytes = 0;
10354 int j;
10355
10356 for (j = i; j < txb->nr_frags; j++)
10357 remaining_bytes += txb->fragments[j]->len - hdr_len;
10358
10359 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10360 remaining_bytes);
10361 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10362 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010363 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010364 for (j = i; j < txb->nr_frags; j++) {
10365 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010366
James Ketrenos43f66a62005-03-25 12:31:53 -060010367 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010368 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010369 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010370 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010371 }
10372 dev_kfree_skb_any(txb->fragments[i]);
10373 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010374 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010375 cpu_to_le32(pci_map_single
10376 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010377 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010378 PCI_DMA_TODEVICE));
10379
Marcin Slusarz5c058632008-02-13 00:06:12 +010010380 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010381 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010382 }
10383
10384 /* kick DMA */
10385 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10386 ipw_write32(priv, q->reg_w, q->first_empty);
10387
Dan Williams943dbef2008-02-14 17:49:41 -050010388 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010389 netif_stop_queue(priv->net_dev);
10390
James Ketrenos227d2dc2005-07-28 16:25:55 -050010391 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010392
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010393 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010394 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010395 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010396 return NETDEV_TX_OK;
10397}
10398
10399static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10400{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010401 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010402#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010403 int tx_id = ipw_get_tx_queue_number(priv, pri);
10404 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10405#else
10406 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010407#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010408
Dan Williams943dbef2008-02-14 17:49:41 -050010409 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010410 return 1;
10411
10412 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010413}
10414
Zhu Yid685b8c2006-04-13 17:20:27 +080010415#ifdef CONFIG_IPW2200_PROMISCUOUS
10416static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010417 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010418{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010419 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010420 struct ieee80211_hdr *hdr;
10421 u8 n;
10422 u16 filter = priv->prom_priv->filter;
10423 int hdr_only = 0;
10424
10425 if (filter & IPW_PROM_NO_TX)
10426 return;
10427
10428 memset(&dummystats, 0, sizeof(dummystats));
10429
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010430 /* Filtering of fragment chains is done against the first fragment */
Zhu Yid685b8c2006-04-13 17:20:27 +080010431 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010432 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010433 if (filter & IPW_PROM_NO_MGMT)
10434 return;
10435 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10436 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010437 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010438 if (filter & IPW_PROM_NO_CTL)
10439 return;
10440 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10441 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010442 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010443 if (filter & IPW_PROM_NO_DATA)
10444 return;
10445 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10446 hdr_only = 1;
10447 }
10448
10449 for(n=0; n<txb->nr_frags; ++n) {
10450 struct sk_buff *src = txb->fragments[n];
10451 struct sk_buff *dst;
10452 struct ieee80211_radiotap_header *rt_hdr;
10453 int len;
10454
10455 if (hdr_only) {
10456 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010457 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010458 } else
10459 len = src->len;
10460
Johannes Berg007e5dd2008-11-27 23:13:38 +010010461 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10462 if (!dst)
10463 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010464
10465 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10466
10467 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10468 rt_hdr->it_pad = 0;
10469 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010470 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010471
Al Viroe62e1ee2007-12-27 01:36:46 -050010472 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010473 ieee80211chan2mhz(priv->channel));
10474 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010475 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010476 cpu_to_le16(IEEE80211_CHAN_OFDM |
10477 IEEE80211_CHAN_5GHZ);
10478 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010479 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010480 cpu_to_le16(IEEE80211_CHAN_CCK |
10481 IEEE80211_CHAN_2GHZ);
10482 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010483 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010484 cpu_to_le16(IEEE80211_CHAN_OFDM |
10485 IEEE80211_CHAN_2GHZ);
10486
Al Viro743b84d2007-12-27 01:43:16 -050010487 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010488
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010489 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010490
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010491 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010492 dev_kfree_skb_any(dst);
10493 }
10494}
10495#endif
10496
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010497static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10498 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010499{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010500 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010501 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010502 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010503
10504 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010505 spin_lock_irqsave(&priv->lock, flags);
10506
Zhu Yid685b8c2006-04-13 17:20:27 +080010507#ifdef CONFIG_IPW2200_PROMISCUOUS
10508 if (rtap_iface && netif_running(priv->prom_net_dev))
10509 ipw_handle_promiscuous_tx(priv, txb);
10510#endif
10511
James Ketrenos227d2dc2005-07-28 16:25:55 -050010512 ret = ipw_tx_skb(priv, txb, pri);
10513 if (ret == NETDEV_TX_OK)
10514 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010515 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010516
James Ketrenos227d2dc2005-07-28 16:25:55 -050010517 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010518}
10519
James Ketrenos43f66a62005-03-25 12:31:53 -060010520static void ipw_net_set_multicast_list(struct net_device *dev)
10521{
10522
10523}
10524
10525static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10526{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010527 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010528 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010529
James Ketrenos43f66a62005-03-25 12:31:53 -060010530 if (!is_valid_ether_addr(addr->sa_data))
10531 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010532 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010533 priv->config |= CFG_CUSTOM_MAC;
10534 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010535 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10536 priv->net_dev->name, priv->mac_addr);
Tejun Heobcb6d912011-01-26 12:12:50 +010010537 schedule_work(&priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010538 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010539 return 0;
10540}
10541
Jeff Garzikbf794512005-07-31 13:07:26 -040010542static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010543 struct ethtool_drvinfo *info)
10544{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010545 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010546 char vers[64];
10547 char date[32];
10548 u32 len;
10549
Rick Jones1f80c232011-11-15 10:40:49 -080010550 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
10551 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
James Ketrenos43f66a62005-03-25 12:31:53 -060010552
10553 len = sizeof(vers);
10554 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10555 len = sizeof(date);
10556 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10557
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010558 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010559 vers, date);
Rick Jones1f80c232011-11-15 10:40:49 -080010560 strlcpy(info->bus_info, pci_name(p->pci_dev),
10561 sizeof(info->bus_info));
James Ketrenosb095c382005-08-24 22:04:42 -050010562 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010563}
10564
10565static u32 ipw_ethtool_get_link(struct net_device *dev)
10566{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010567 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010568 return (priv->status & STATUS_ASSOCIATED) != 0;
10569}
10570
10571static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10572{
James Ketrenosb095c382005-08-24 22:04:42 -050010573 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010574}
10575
10576static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010577 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010578{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010579 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010580
James Ketrenosb095c382005-08-24 22:04:42 -050010581 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010582 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010583 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010584 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010585 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010586 return 0;
10587}
10588
10589static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010590 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010591{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010592 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010593 int i;
10594
James Ketrenosb095c382005-08-24 22:04:42 -050010595 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010596 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010597 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010598 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010599 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10600 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010601 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010602 return 0;
10603}
10604
Jeff Garzik7282d492006-09-13 14:30:00 -040010605static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010606 .get_link = ipw_ethtool_get_link,
10607 .get_drvinfo = ipw_ethtool_get_drvinfo,
10608 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10609 .get_eeprom = ipw_ethtool_get_eeprom,
10610 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010611};
10612
David Howells7d12e782006-10-05 14:55:46 +010010613static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010614{
10615 struct ipw_priv *priv = data;
10616 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010617
James Ketrenos43f66a62005-03-25 12:31:53 -060010618 if (!priv)
10619 return IRQ_NONE;
10620
Zhu Yi89c318e2006-06-08 22:19:49 -070010621 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010622
10623 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010624 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010625 goto none;
10626 }
10627
James Ketrenosb095c382005-08-24 22:04:42 -050010628 inta = ipw_read32(priv, IPW_INTA_RW);
10629 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010630
James Ketrenos43f66a62005-03-25 12:31:53 -060010631 if (inta == 0xFFFFFFFF) {
10632 /* Hardware disappeared */
10633 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10634 goto none;
10635 }
10636
James Ketrenosb095c382005-08-24 22:04:42 -050010637 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010638 /* Shared interrupt */
10639 goto none;
10640 }
10641
10642 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010643 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010644
James Ketrenos43f66a62005-03-25 12:31:53 -060010645 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010646 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10647 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010648
James Ketrenos43f66a62005-03-25 12:31:53 -060010649 /* Cache INTA value for our tasklet */
10650 priv->isr_inta = inta;
10651
10652 tasklet_schedule(&priv->irq_tasklet);
10653
Zhu Yi89c318e2006-06-08 22:19:49 -070010654 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010655
10656 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010657 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010658 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010659 return IRQ_NONE;
10660}
10661
10662static void ipw_rf_kill(void *adapter)
10663{
10664 struct ipw_priv *priv = adapter;
10665 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010666
James Ketrenos43f66a62005-03-25 12:31:53 -060010667 spin_lock_irqsave(&priv->lock, flags);
10668
10669 if (rf_kill_active(priv)) {
10670 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010010671 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010672 goto exit_unlock;
10673 }
10674
10675 /* RF Kill is now disabled, so bring the device back up */
10676
10677 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10678 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10679 "device\n");
10680
10681 /* we can not do an adapter restart while inside an irq lock */
Tejun Heobcb6d912011-01-26 12:12:50 +010010682 schedule_work(&priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010683 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010684 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10685 "enabled\n");
10686
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010687 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010688 spin_unlock_irqrestore(&priv->lock, flags);
10689}
10690
David Howellsc4028952006-11-22 14:57:56 +000010691static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010692{
David Howellsc4028952006-11-22 14:57:56 +000010693 struct ipw_priv *priv =
10694 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010695 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010696 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010697 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010698}
10699
Adrian Bunka73e22b2006-01-21 01:39:42 +010010700static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010701{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010702 priv->last_seq_num = -1;
10703 priv->last_frag_num = -1;
10704 priv->last_packet_time = 0;
10705
James Ketrenosa613bff2005-08-24 21:43:11 -050010706 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010707
James Ketrenosc848d0a2005-08-24 21:56:24 -050010708 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010709 cancel_delayed_work(&priv->request_direct_scan);
10710 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010711 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010712 ipw_reset_stats(priv);
10713 /* Ensure the rate is updated immediately */
10714 priv->last_rate = ipw_get_current_rate(priv);
10715 ipw_gather_stats(priv);
10716 ipw_led_link_up(priv);
10717 notify_wx_assoc_event(priv);
10718
10719 if (priv->config & CFG_BACKGROUND_SCAN)
Tejun Heobcb6d912011-01-26 12:12:50 +010010720 schedule_delayed_work(&priv->request_scan, HZ);
James Ketrenosa613bff2005-08-24 21:43:11 -050010721}
10722
David Howellsc4028952006-11-22 14:57:56 +000010723static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010724{
David Howellsc4028952006-11-22 14:57:56 +000010725 struct ipw_priv *priv =
10726 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010727 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010728 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010729 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010730}
10731
Adrian Bunka73e22b2006-01-21 01:39:42 +010010732static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010733{
10734 ipw_led_link_down(priv);
10735 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010736 notify_wx_assoc_event(priv);
10737
10738 /* Cancel any queued work ... */
10739 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010740 cancel_delayed_work(&priv->request_direct_scan);
10741 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010742 cancel_delayed_work(&priv->adhoc_check);
10743 cancel_delayed_work(&priv->gather_stats);
10744
10745 ipw_reset_stats(priv);
10746
James Ketrenosafbf30a2005-08-25 00:05:33 -050010747 if (!(priv->status & STATUS_EXIT_PENDING)) {
10748 /* Queue up another scan... */
Tejun Heobcb6d912011-01-26 12:12:50 +010010749 schedule_delayed_work(&priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010750 } else
10751 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010752}
10753
David Howellsc4028952006-11-22 14:57:56 +000010754static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010755{
David Howellsc4028952006-11-22 14:57:56 +000010756 struct ipw_priv *priv =
10757 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010758 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010759 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010760 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010761}
10762
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010763static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010764{
10765 int ret = 0;
10766
James Ketrenos43f66a62005-03-25 12:31:53 -060010767 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010768 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010769
David Howellsc4028952006-11-22 14:57:56 +000010770 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10771 INIT_WORK(&priv->associate, ipw_bg_associate);
10772 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10773 INIT_WORK(&priv->system_config, ipw_system_config);
10774 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10775 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10776 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10777 INIT_WORK(&priv->up, ipw_bg_up);
10778 INIT_WORK(&priv->down, ipw_bg_down);
10779 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010780 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10781 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010782 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010783 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10784 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10785 INIT_WORK(&priv->roam, ipw_bg_roam);
10786 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10787 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10788 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10789 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10790 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10791 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10792 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010793
Zhu Yie43e3c12006-04-13 17:20:45 +080010794#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010795 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010796#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010797
10798 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10799 ipw_irq_tasklet, (unsigned long)priv);
10800
10801 return ret;
10802}
10803
James Ketrenos43f66a62005-03-25 12:31:53 -060010804static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010805 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010806{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010807 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010808 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010809 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010810 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010811 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010812 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010813 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010814 priv->ieee->sec.flags &= ~(1 << i);
10815 else {
10816 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010818 priv->ieee->sec.flags |= (1 << i);
10819 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010820 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010821 } else if (sec->level != SEC_LEVEL_1)
10822 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010823 }
10824
James Ketrenosb095c382005-08-24 22:04:42 -050010825 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010826 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010827 priv->ieee->sec.active_key = sec->active_key;
10828 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010829 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010830 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010831 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010832 } else
10833 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010834
10835 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010836 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10837 priv->ieee->sec.auth_mode = sec->auth_mode;
10838 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010839 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10840 priv->capability |= CAP_SHARED_KEY;
10841 else
10842 priv->capability &= ~CAP_SHARED_KEY;
10843 priv->status |= STATUS_SECURITY_UPDATED;
10844 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010845
James Ketrenosb095c382005-08-24 22:04:42 -050010846 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10847 priv->ieee->sec.flags |= SEC_ENABLED;
10848 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010849 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010850 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010851 priv->capability |= CAP_PRIVACY_ON;
10852 else
10853 priv->capability &= ~CAP_PRIVACY_ON;
10854 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010855
James Ketrenosafbf30a2005-08-25 00:05:33 -050010856 if (sec->flags & SEC_ENCRYPT)
10857 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010858
James Ketrenosb095c382005-08-24 22:04:42 -050010859 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10860 priv->ieee->sec.level = sec->level;
10861 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010862 priv->status |= STATUS_SECURITY_UPDATED;
10863 }
10864
Zhu Yi1fbfea52005-08-05 17:22:56 +080010865 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10866 ipw_set_hwcrypto_keys(priv);
10867
Jeff Garzikbf794512005-07-31 13:07:26 -040010868 /* To match current functionality of ipw2100 (which works well w/
10869 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010870 * privacy capability changes ... */
10871#if 0
10872 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010873 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010874 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010875 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010876 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010877 IPW_DEBUG_ASSOC("Disassociating due to capability "
10878 "change.\n");
10879 ipw_disassociate(priv);
10880 }
10881#endif
10882}
10883
Jeff Garzikbf794512005-07-31 13:07:26 -040010884static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010885 struct ipw_supported_rates *rates)
10886{
10887 /* TODO: Mask out rates based on priv->rates_mask */
10888
10889 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010890 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010891 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010892 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010893 rates->ieee_mode = IPW_A_MODE;
10894 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010895 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10896 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010897 break;
10898
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010899 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010900 rates->ieee_mode = IPW_G_MODE;
10901 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010902 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10903 LIBIPW_CCK_DEFAULT_RATES_MASK);
10904 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10905 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10906 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010907 }
10908 break;
10909 }
10910
10911 return 0;
10912}
10913
Jeff Garzikbf794512005-07-31 13:07:26 -040010914static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010915{
James Ketrenos43f66a62005-03-25 12:31:53 -060010916 /* This is only called from ipw_up, which resets/reloads the firmware
10917 so, we don't need to first disable the card before we configure
10918 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010919 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010920 goto error;
10921
10922 /* initialize adapter address */
10923 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10924 goto error;
10925
10926 /* set basic system config settings */
10927 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010928
10929 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10930 * Does not support BT priority yet (don't abort or defer our Tx) */
10931 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010932 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010933
10934 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10935 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010936 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010937 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10938 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010939 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010940 }
10941
Zhu Yid685b8c2006-04-13 17:20:27 +080010942#ifdef CONFIG_IPW2200_PROMISCUOUS
10943 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10944 priv->sys_config.accept_all_data_frames = 1;
10945 priv->sys_config.accept_non_directed_frames = 1;
10946 priv->sys_config.accept_all_mgmt_bcpr = 1;
10947 priv->sys_config.accept_all_mgmt_frames = 1;
10948 }
10949#endif
10950
James Ketrenosc848d0a2005-08-24 21:56:24 -050010951 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10952 priv->sys_config.answer_broadcast_ssid_probe = 1;
10953 else
10954 priv->sys_config.answer_broadcast_ssid_probe = 0;
10955
Zhu Yid685b8c2006-04-13 17:20:27 +080010956 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010957 goto error;
10958
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010959 init_supported_rates(priv, &priv->rates);
10960 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010961 goto error;
10962
10963 /* Set request-to-send threshold */
10964 if (priv->rts_threshold) {
10965 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10966 goto error;
10967 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010968#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010969 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10970 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010971#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010972
10973 if (ipw_set_random_seed(priv))
10974 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010975
James Ketrenos43f66a62005-03-25 12:31:53 -060010976 /* final state transition to the RUN state */
10977 if (ipw_send_host_complete(priv))
10978 goto error;
10979
James Ketrenose6666192005-08-12 09:17:04 -050010980 priv->status |= STATUS_INIT;
10981
10982 ipw_led_init(priv);
10983 ipw_led_radio_on(priv);
10984 priv->notif_missed_beacons = 0;
10985
10986 /* Set hardware WEP key if it is configured. */
10987 if ((priv->capability & CAP_PRIVACY_ON) &&
10988 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10989 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10990 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010991
10992 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010993
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010994 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010995 return -EIO;
10996}
10997
James Ketrenos4f36f802005-08-03 20:36:56 -050010998/*
10999 * NOTE:
11000 *
11001 * These tables have been tested in conjunction with the
11002 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11003 *
11004 * Altering this values, using it on other hardware, or in geographies
11005 * not intended for resale of the above mentioned Intel adapters has
11006 * not been tested.
11007 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011008 * Remember to update the table in README.ipw2200 when changing this
11009 * table.
11010 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011011 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011012static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011013 { /* Restricted */
11014 "---",
11015 .bg_channels = 11,
11016 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11017 {2427, 4}, {2432, 5}, {2437, 6},
11018 {2442, 7}, {2447, 8}, {2452, 9},
11019 {2457, 10}, {2462, 11}},
11020 },
11021
11022 { /* Custom US/Canada */
11023 "ZZF",
11024 .bg_channels = 11,
11025 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11026 {2427, 4}, {2432, 5}, {2437, 6},
11027 {2442, 7}, {2447, 8}, {2452, 9},
11028 {2457, 10}, {2462, 11}},
11029 .a_channels = 8,
11030 .a = {{5180, 36},
11031 {5200, 40},
11032 {5220, 44},
11033 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011034 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11035 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11036 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11037 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011038 },
11039
11040 { /* Rest of World */
11041 "ZZD",
11042 .bg_channels = 13,
11043 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11044 {2427, 4}, {2432, 5}, {2437, 6},
11045 {2442, 7}, {2447, 8}, {2452, 9},
11046 {2457, 10}, {2462, 11}, {2467, 12},
11047 {2472, 13}},
11048 },
11049
11050 { /* Custom USA & Europe & High */
11051 "ZZA",
11052 .bg_channels = 11,
11053 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11054 {2427, 4}, {2432, 5}, {2437, 6},
11055 {2442, 7}, {2447, 8}, {2452, 9},
11056 {2457, 10}, {2462, 11}},
11057 .a_channels = 13,
11058 .a = {{5180, 36},
11059 {5200, 40},
11060 {5220, 44},
11061 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011062 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11063 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11064 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11065 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011066 {5745, 149},
11067 {5765, 153},
11068 {5785, 157},
11069 {5805, 161},
11070 {5825, 165}},
11071 },
11072
11073 { /* Custom NA & Europe */
11074 "ZZB",
11075 .bg_channels = 11,
11076 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11077 {2427, 4}, {2432, 5}, {2437, 6},
11078 {2442, 7}, {2447, 8}, {2452, 9},
11079 {2457, 10}, {2462, 11}},
11080 .a_channels = 13,
11081 .a = {{5180, 36},
11082 {5200, 40},
11083 {5220, 44},
11084 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011085 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11086 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11087 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11088 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11089 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11090 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11091 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11092 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11093 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011094 },
11095
11096 { /* Custom Japan */
11097 "ZZC",
11098 .bg_channels = 11,
11099 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11100 {2427, 4}, {2432, 5}, {2437, 6},
11101 {2442, 7}, {2447, 8}, {2452, 9},
11102 {2457, 10}, {2462, 11}},
11103 .a_channels = 4,
11104 .a = {{5170, 34}, {5190, 38},
11105 {5210, 42}, {5230, 46}},
11106 },
11107
11108 { /* Custom */
11109 "ZZM",
11110 .bg_channels = 11,
11111 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11112 {2427, 4}, {2432, 5}, {2437, 6},
11113 {2442, 7}, {2447, 8}, {2452, 9},
11114 {2457, 10}, {2462, 11}},
11115 },
11116
11117 { /* Europe */
11118 "ZZE",
11119 .bg_channels = 13,
11120 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11121 {2427, 4}, {2432, 5}, {2437, 6},
11122 {2442, 7}, {2447, 8}, {2452, 9},
11123 {2457, 10}, {2462, 11}, {2467, 12},
11124 {2472, 13}},
11125 .a_channels = 19,
11126 .a = {{5180, 36},
11127 {5200, 40},
11128 {5220, 44},
11129 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011130 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11131 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11132 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11133 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11134 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11135 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11136 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11137 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11138 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11139 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11140 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11141 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11142 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11143 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11144 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011145 },
11146
11147 { /* Custom Japan */
11148 "ZZJ",
11149 .bg_channels = 14,
11150 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11151 {2427, 4}, {2432, 5}, {2437, 6},
11152 {2442, 7}, {2447, 8}, {2452, 9},
11153 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011154 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011155 .a_channels = 4,
11156 .a = {{5170, 34}, {5190, 38},
11157 {5210, 42}, {5230, 46}},
11158 },
11159
James Ketrenos03520572005-10-19 16:12:31 -050011160 { /* Rest of World */
11161 "ZZR",
11162 .bg_channels = 14,
11163 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11164 {2427, 4}, {2432, 5}, {2437, 6},
11165 {2442, 7}, {2447, 8}, {2452, 9},
11166 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011167 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11168 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011169 },
11170
James Ketrenos4f36f802005-08-03 20:36:56 -050011171 { /* High Band */
11172 "ZZH",
11173 .bg_channels = 13,
11174 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11175 {2427, 4}, {2432, 5}, {2437, 6},
11176 {2442, 7}, {2447, 8}, {2452, 9},
11177 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011178 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11179 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011180 .a_channels = 4,
11181 .a = {{5745, 149}, {5765, 153},
11182 {5785, 157}, {5805, 161}},
11183 },
11184
11185 { /* Custom Europe */
11186 "ZZG",
11187 .bg_channels = 13,
11188 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11189 {2427, 4}, {2432, 5}, {2437, 6},
11190 {2442, 7}, {2447, 8}, {2452, 9},
11191 {2457, 10}, {2462, 11},
11192 {2467, 12}, {2472, 13}},
11193 .a_channels = 4,
11194 .a = {{5180, 36}, {5200, 40},
11195 {5220, 44}, {5240, 48}},
11196 },
11197
11198 { /* Europe */
11199 "ZZK",
11200 .bg_channels = 13,
11201 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11202 {2427, 4}, {2432, 5}, {2437, 6},
11203 {2442, 7}, {2447, 8}, {2452, 9},
11204 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011205 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11206 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011207 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011208 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11209 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11210 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11211 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11212 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11213 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11214 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11215 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11216 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11217 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11218 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11219 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11220 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11221 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11222 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11223 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11224 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11225 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11226 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11227 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11228 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11229 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11230 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11231 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011232 },
11233
11234 { /* Europe */
11235 "ZZL",
11236 .bg_channels = 11,
11237 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11238 {2427, 4}, {2432, 5}, {2437, 6},
11239 {2442, 7}, {2447, 8}, {2452, 9},
11240 {2457, 10}, {2462, 11}},
11241 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011242 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11243 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11244 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11245 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11246 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11247 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11248 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11249 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11250 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11251 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11252 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11253 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11254 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011255 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011256};
11257
James Ketrenos43f66a62005-03-25 12:31:53 -060011258#define MAX_HW_RESTARTS 5
11259static int ipw_up(struct ipw_priv *priv)
11260{
James Ketrenos4f36f802005-08-03 20:36:56 -050011261 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011262
Dan Williamsc3d72b92009-02-11 13:26:06 -050011263 /* Age scan list entries found before suspend */
11264 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011265 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011266 priv->suspend_time = 0;
11267 }
11268
James Ketrenos43f66a62005-03-25 12:31:53 -060011269 if (priv->status & STATUS_EXIT_PENDING)
11270 return -EIO;
11271
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011272 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011273 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011274 GFP_KERNEL);
11275 if (priv->cmdlog == NULL) {
11276 IPW_ERROR("Error allocating %d command log entries.\n",
11277 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011278 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011279 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011280 priv->cmdlog_len = cmdlog;
11281 }
11282 }
11283
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011284 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011285 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011286 * Also start the clocks. */
11287 rc = ipw_load(priv);
11288 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011289 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011290 return rc;
11291 }
11292
11293 ipw_init_ordinals(priv);
11294 if (!(priv->config & CFG_CUSTOM_MAC))
11295 eeprom_parse_mac(priv, priv->mac_addr);
11296 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011297 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011298
James Ketrenos4f36f802005-08-03 20:36:56 -050011299 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11300 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11301 ipw_geos[j].name, 3))
11302 break;
11303 }
James Ketrenos03520572005-10-19 16:12:31 -050011304 if (j == ARRAY_SIZE(ipw_geos)) {
11305 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11306 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11307 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11308 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011309 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011310 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011311 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011312 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011313 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011314 }
11315
James Ketrenosb095c382005-08-24 22:04:42 -050011316 if (priv->status & STATUS_RF_KILL_SW) {
11317 IPW_WARNING("Radio disabled by module parameter.\n");
11318 return 0;
11319 } else if (rf_kill_active(priv)) {
11320 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11321 "Kill switch must be turned off for "
11322 "wireless networking to work.\n");
Tejun Heobcb6d912011-01-26 12:12:50 +010011323 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011324 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011325 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011326
11327 rc = ipw_config(priv);
11328 if (!rc) {
11329 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011330
James Ketrenose6666192005-08-12 09:17:04 -050011331 /* If configure to try and auto-associate, kick
11332 * off a scan. */
Tejun Heobcb6d912011-01-26 12:12:50 +010011333 schedule_delayed_work(&priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011334
James Ketrenos43f66a62005-03-25 12:31:53 -060011335 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011336 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011337
James Ketrenosc848d0a2005-08-24 21:56:24 -050011338 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011339 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11340 i, MAX_HW_RESTARTS);
11341
11342 /* We had an error bringing up the hardware, so take it
11343 * all the way back down so we can try again */
11344 ipw_down(priv);
11345 }
11346
Jeff Garzikbf794512005-07-31 13:07:26 -040011347 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011348 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011349 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011350
James Ketrenos43f66a62005-03-25 12:31:53 -060011351 return -EIO;
11352}
11353
David Howellsc4028952006-11-22 14:57:56 +000011354static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011355{
David Howellsc4028952006-11-22 14:57:56 +000011356 struct ipw_priv *priv =
11357 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011358 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011359 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011360 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011361}
11362
James Ketrenosb095c382005-08-24 22:04:42 -050011363static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011364{
James Ketrenosb095c382005-08-24 22:04:42 -050011365 int i;
11366
11367 if (priv->status & STATUS_SCANNING) {
11368 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11369 ipw_abort_scan(priv);
11370 }
11371
11372 if (priv->status & STATUS_ASSOCIATED) {
11373 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11374 ipw_disassociate(priv);
11375 }
11376
11377 ipw_led_shutdown(priv);
11378
11379 /* Wait up to 1s for status to change to not scanning and not
11380 * associated (disassociation can take a while for a ful 802.11
11381 * exchange */
11382 for (i = 1000; i && (priv->status &
11383 (STATUS_DISASSOCIATING |
11384 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11385 udelay(10);
11386
11387 if (priv->status & (STATUS_DISASSOCIATING |
11388 STATUS_ASSOCIATED | STATUS_SCANNING))
11389 IPW_DEBUG_INFO("Still associated or scanning...\n");
11390 else
11391 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11392
James Ketrenosc848d0a2005-08-24 21:56:24 -050011393 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011394 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011395
11396 priv->status &= ~STATUS_INIT;
11397}
11398
James Ketrenos43f66a62005-03-25 12:31:53 -060011399static void ipw_down(struct ipw_priv *priv)
11400{
James Ketrenosb095c382005-08-24 22:04:42 -050011401 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11402
11403 priv->status |= STATUS_EXIT_PENDING;
11404
11405 if (ipw_is_init(priv))
11406 ipw_deinit(priv);
11407
11408 /* Wipe out the EXIT_PENDING status bit if we are not actually
11409 * exiting the module */
11410 if (!exit_pending)
11411 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011412
11413 /* tell the device to stop sending interrupts */
11414 ipw_disable_interrupts(priv);
11415
11416 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011417 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011418 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011419
11420 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011421
11422 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011423}
11424
David Howellsc4028952006-11-22 14:57:56 +000011425static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011426{
David Howellsc4028952006-11-22 14:57:56 +000011427 struct ipw_priv *priv =
11428 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011429 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011430 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011431 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011432}
11433
11434/* Called by register_netdev() */
11435static int ipw_net_init(struct net_device *dev)
11436{
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011437 int rc = 0;
11438 struct ipw_priv *priv = libipw_priv(dev);
11439
11440 mutex_lock(&priv->mutex);
11441 if (ipw_up(priv))
11442 rc = -EIO;
11443 mutex_unlock(&priv->mutex);
11444
11445 return rc;
11446}
11447
11448static int ipw_wdev_init(struct net_device *dev)
11449{
John W. Linvillea3caa992009-08-25 14:12:25 -040011450 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011451 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011452 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11453 struct wireless_dev *wdev = &priv->ieee->wdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011454
John W. Linvillea3caa992009-08-25 14:12:25 -040011455 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11456
11457 /* fill-out priv->ieee->bg_band */
11458 if (geo->bg_channels) {
11459 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11460
11461 bg_band->band = IEEE80211_BAND_2GHZ;
11462 bg_band->n_channels = geo->bg_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011463 bg_band->channels = kcalloc(geo->bg_channels,
11464 sizeof(struct ieee80211_channel),
11465 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011466 if (!bg_band->channels) {
11467 rc = -ENOMEM;
11468 goto out;
11469 }
John W. Linvillea3caa992009-08-25 14:12:25 -040011470 /* translate geo->bg to bg_band.channels */
11471 for (i = 0; i < geo->bg_channels; i++) {
11472 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11473 bg_band->channels[i].center_freq = geo->bg[i].freq;
11474 bg_band->channels[i].hw_value = geo->bg[i].channel;
11475 bg_band->channels[i].max_power = geo->bg[i].max_power;
11476 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11477 bg_band->channels[i].flags |=
11478 IEEE80211_CHAN_PASSIVE_SCAN;
11479 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11480 bg_band->channels[i].flags |=
11481 IEEE80211_CHAN_NO_IBSS;
11482 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11483 bg_band->channels[i].flags |=
11484 IEEE80211_CHAN_RADAR;
11485 /* No equivalent for LIBIPW_CH_80211H_RULES,
11486 LIBIPW_CH_UNIFORM_SPREADING, or
11487 LIBIPW_CH_B_ONLY... */
11488 }
11489 /* point at bitrate info */
11490 bg_band->bitrates = ipw2200_bg_rates;
11491 bg_band->n_bitrates = ipw2200_num_bg_rates;
11492
11493 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11494 }
11495
11496 /* fill-out priv->ieee->a_band */
11497 if (geo->a_channels) {
11498 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11499
11500 a_band->band = IEEE80211_BAND_5GHZ;
11501 a_band->n_channels = geo->a_channels;
Joe Perchesbaeb2ff2010-08-11 07:02:48 +000011502 a_band->channels = kcalloc(geo->a_channels,
11503 sizeof(struct ieee80211_channel),
11504 GFP_KERNEL);
Dan Carpenter2ee4e272010-10-04 14:31:46 +020011505 if (!a_band->channels) {
11506 rc = -ENOMEM;
11507 goto out;
11508 }
Stanislav Yakovlev75836b82012-03-20 17:52:57 -040011509 /* translate geo->a to a_band.channels */
John W. Linvillea3caa992009-08-25 14:12:25 -040011510 for (i = 0; i < geo->a_channels; i++) {
Stanislav Yakovlev75836b82012-03-20 17:52:57 -040011511 a_band->channels[i].band = IEEE80211_BAND_5GHZ;
John W. Linvillea3caa992009-08-25 14:12:25 -040011512 a_band->channels[i].center_freq = geo->a[i].freq;
11513 a_band->channels[i].hw_value = geo->a[i].channel;
11514 a_band->channels[i].max_power = geo->a[i].max_power;
11515 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11516 a_band->channels[i].flags |=
11517 IEEE80211_CHAN_PASSIVE_SCAN;
11518 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11519 a_band->channels[i].flags |=
11520 IEEE80211_CHAN_NO_IBSS;
11521 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11522 a_band->channels[i].flags |=
11523 IEEE80211_CHAN_RADAR;
11524 /* No equivalent for LIBIPW_CH_80211H_RULES,
11525 LIBIPW_CH_UNIFORM_SPREADING, or
11526 LIBIPW_CH_B_ONLY... */
11527 }
11528 /* point at bitrate info */
11529 a_band->bitrates = ipw2200_a_rates;
11530 a_band->n_bitrates = ipw2200_num_a_rates;
11531
11532 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11533 }
11534
11535 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11536
11537 /* With that information in place, we can now register the wiphy... */
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011538 if (wiphy_register(wdev->wiphy))
John W. Linvillea3caa992009-08-25 14:12:25 -040011539 rc = -EIO;
John W. Linvillea3caa992009-08-25 14:12:25 -040011540out:
John W. Linvillea3caa992009-08-25 14:12:25 -040011541 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011542}
11543
11544/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011545static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11552 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11553 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11554 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11555 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11556 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11557 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11558 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11559 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11560 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11561 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11562 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011563 {PCI_VDEVICE(INTEL, 0x104f), 0},
11564 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11565 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11566 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11567 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011568
James Ketrenos43f66a62005-03-25 12:31:53 -060011569 /* required last entry */
11570 {0,}
11571};
11572
11573MODULE_DEVICE_TABLE(pci, card_ids);
11574
11575static struct attribute *ipw_sysfs_entries[] = {
11576 &dev_attr_rf_kill.attr,
11577 &dev_attr_direct_dword.attr,
11578 &dev_attr_indirect_byte.attr,
11579 &dev_attr_indirect_dword.attr,
11580 &dev_attr_mem_gpio_reg.attr,
11581 &dev_attr_command_event_reg.attr,
11582 &dev_attr_nic_type.attr,
11583 &dev_attr_status.attr,
11584 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011585 &dev_attr_error.attr,
11586 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011587 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011588 &dev_attr_eeprom_delay.attr,
11589 &dev_attr_ucode_version.attr,
11590 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011591 &dev_attr_scan_age.attr,
11592 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011593 &dev_attr_speed_scan.attr,
11594 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011595 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011596#ifdef CONFIG_IPW2200_PROMISCUOUS
11597 &dev_attr_rtap_iface.attr,
11598 &dev_attr_rtap_filter.attr,
11599#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011600 NULL
11601};
11602
11603static struct attribute_group ipw_attribute_group = {
11604 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011605 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011606};
11607
Zhu Yid685b8c2006-04-13 17:20:27 +080011608#ifdef CONFIG_IPW2200_PROMISCUOUS
11609static int ipw_prom_open(struct net_device *dev)
11610{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011611 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011612 struct ipw_priv *priv = prom_priv->priv;
11613
11614 IPW_DEBUG_INFO("prom dev->open\n");
11615 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011616
11617 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11618 priv->sys_config.accept_all_data_frames = 1;
11619 priv->sys_config.accept_non_directed_frames = 1;
11620 priv->sys_config.accept_all_mgmt_bcpr = 1;
11621 priv->sys_config.accept_all_mgmt_frames = 1;
11622
11623 ipw_send_system_config(priv);
11624 }
11625
11626 return 0;
11627}
11628
11629static int ipw_prom_stop(struct net_device *dev)
11630{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011631 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011632 struct ipw_priv *priv = prom_priv->priv;
11633
11634 IPW_DEBUG_INFO("prom dev->stop\n");
11635
11636 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11637 priv->sys_config.accept_all_data_frames = 0;
11638 priv->sys_config.accept_non_directed_frames = 0;
11639 priv->sys_config.accept_all_mgmt_bcpr = 0;
11640 priv->sys_config.accept_all_mgmt_frames = 0;
11641
11642 ipw_send_system_config(priv);
11643 }
11644
11645 return 0;
11646}
11647
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011648static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11649 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011650{
11651 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011652 dev_kfree_skb(skb);
11653 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011654}
11655
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011656static const struct net_device_ops ipw_prom_netdev_ops = {
11657 .ndo_open = ipw_prom_open,
11658 .ndo_stop = ipw_prom_stop,
11659 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011660 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011661 .ndo_set_mac_address = eth_mac_addr,
11662 .ndo_validate_addr = eth_validate_addr,
11663};
11664
Zhu Yid685b8c2006-04-13 17:20:27 +080011665static int ipw_prom_alloc(struct ipw_priv *priv)
11666{
11667 int rc = 0;
11668
11669 if (priv->prom_net_dev)
11670 return -EPERM;
11671
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011672 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011673 if (priv->prom_net_dev == NULL)
11674 return -ENOMEM;
11675
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011676 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011677 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11678 priv->prom_priv->priv = priv;
11679
11680 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011681 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011682
11683 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011684 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011685
11686 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011687 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011688
11689 rc = register_netdev(priv->prom_net_dev);
11690 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011691 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011692 priv->prom_net_dev = NULL;
11693 return rc;
11694 }
11695
11696 return 0;
11697}
11698
11699static void ipw_prom_free(struct ipw_priv *priv)
11700{
11701 if (!priv->prom_net_dev)
11702 return;
11703
11704 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011705 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011706
11707 priv->prom_net_dev = NULL;
11708}
11709
11710#endif
11711
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011712static const struct net_device_ops ipw_netdev_ops = {
11713 .ndo_init = ipw_net_init,
11714 .ndo_open = ipw_net_open,
11715 .ndo_stop = ipw_net_stop,
Jiri Pirkoafc4b132011-08-16 06:29:01 +000011716 .ndo_set_rx_mode = ipw_net_set_multicast_list,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011717 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011718 .ndo_start_xmit = libipw_xmit,
11719 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011720 .ndo_validate_addr = eth_validate_addr,
11721};
Zhu Yid685b8c2006-04-13 17:20:27 +080011722
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011723static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11724 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011725{
11726 int err = 0;
11727 struct net_device *net_dev;
11728 void __iomem *base;
11729 u32 length, val;
11730 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011731 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011732
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011733 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011734 if (net_dev == NULL) {
11735 err = -ENOMEM;
11736 goto out;
11737 }
11738
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011739 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011740 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011741
James Ketrenos43f66a62005-03-25 12:31:53 -060011742 priv->net_dev = net_dev;
11743 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011744 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011745 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011746 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011747 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11748 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011749
Zhu Yi46441512006-01-24 16:37:59 +080011750 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011751 if (pci_enable_device(pdev)) {
11752 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011753 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011754 }
11755
11756 pci_set_master(pdev);
11757
Yang Hongyang284901a2009-04-06 19:01:15 -070011758 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011759 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011760 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011761 if (err) {
11762 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11763 goto out_pci_disable_device;
11764 }
11765
11766 pci_set_drvdata(pdev, priv);
11767
11768 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011769 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011770 goto out_pci_disable_device;
11771
Jeff Garzikbf794512005-07-31 13:07:26 -040011772 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011773 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011774 pci_read_config_dword(pdev, 0x40, &val);
11775 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011776 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011777
James Ketrenos43f66a62005-03-25 12:31:53 -060011778 length = pci_resource_len(pdev, 0);
11779 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011780
Arjan van de Ven275f1652008-10-20 21:42:39 -070011781 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011782 if (!base) {
11783 err = -ENODEV;
11784 goto out_pci_release_regions;
11785 }
11786
11787 priv->hw_base = base;
11788 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11789 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11790
11791 err = ipw_setup_deferred_work(priv);
11792 if (err) {
11793 IPW_ERROR("Unable to setup deferred work\n");
11794 goto out_iounmap;
11795 }
11796
James Ketrenosb095c382005-08-24 22:04:42 -050011797 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011798
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011799 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011800 if (err) {
11801 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
Tejun Heobcb6d912011-01-26 12:12:50 +010011802 goto out_iounmap;
James Ketrenos43f66a62005-03-25 12:31:53 -060011803 }
11804
James Ketrenos43f66a62005-03-25 12:31:53 -060011805 SET_NETDEV_DEV(net_dev, &pdev->dev);
11806
Zhu Yi46441512006-01-24 16:37:59 +080011807 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011808
James Ketrenos43f66a62005-03-25 12:31:53 -060011809 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11810 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011811 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011812
Zhu Yie43e3c12006-04-13 17:20:45 +080011813#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011814 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011815 priv->ieee->handle_probe_response = ipw_handle_beacon;
11816 priv->ieee->handle_beacon = ipw_handle_probe_response;
11817 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011818#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011819
James Ketrenosc848d0a2005-08-24 21:56:24 -050011820 priv->ieee->perfect_rssi = -20;
11821 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011822
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011823 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011824 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011825 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011826 net_dev->wireless_handlers = &ipw_wx_handler_def;
11827 net_dev->ethtool_ops = &ipw_ethtool_ops;
11828 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011829 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011830 net_dev->mem_start = pci_resource_start(pdev, 0);
11831 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11832
11833 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11834 if (err) {
11835 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011836 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011837 goto out_release_irq;
11838 }
11839
Zhu Yi46441512006-01-24 16:37:59 +080011840 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011841 err = register_netdev(net_dev);
11842 if (err) {
11843 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011844 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011845 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011846
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011847 err = ipw_wdev_init(net_dev);
11848 if (err) {
11849 IPW_ERROR("failed to register wireless device\n");
11850 goto out_unregister_netdev;
11851 }
11852
Zhu Yid685b8c2006-04-13 17:20:27 +080011853#ifdef CONFIG_IPW2200_PROMISCUOUS
11854 if (rtap_iface) {
11855 err = ipw_prom_alloc(priv);
11856 if (err) {
11857 IPW_ERROR("Failed to register promiscuous network "
11858 "device (error %d).\n", err);
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011859 wiphy_unregister(priv->ieee->wdev.wiphy);
11860 kfree(priv->ieee->a_band.channels);
11861 kfree(priv->ieee->bg_band.channels);
11862 goto out_unregister_netdev;
Zhu Yid685b8c2006-04-13 17:20:27 +080011863 }
11864 }
11865#endif
11866
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011867 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11868 "channels, %d 802.11a channels)\n",
11869 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11870 priv->ieee->geo.a_channels);
11871
James Ketrenos43f66a62005-03-25 12:31:53 -060011872 return 0;
11873
Stanislaw Gruszka7cabafc2011-09-14 16:47:50 +020011874 out_unregister_netdev:
11875 unregister_netdev(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011876 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011877 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011878 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011879 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011880 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011881 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011882 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011883 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011884 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011885 pci_disable_device(pdev);
11886 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011887 out_free_libipw:
11888 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011889 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011890 return err;
11891}
11892
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011893static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011894{
11895 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011896 struct list_head *p, *q;
11897 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011898
James Ketrenos43f66a62005-03-25 12:31:53 -060011899 if (!priv)
11900 return;
11901
Zhu Yi46441512006-01-24 16:37:59 +080011902 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011903
James Ketrenosafbf30a2005-08-25 00:05:33 -050011904 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011905 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011906 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11907
Zhu Yi46441512006-01-24 16:37:59 +080011908 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011909
11910 unregister_netdev(priv->net_dev);
11911
11912 if (priv->rxq) {
11913 ipw_rx_queue_free(priv, priv->rxq);
11914 priv->rxq = NULL;
11915 }
11916 ipw_tx_queue_free(priv);
11917
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011918 if (priv->cmdlog) {
11919 kfree(priv->cmdlog);
11920 priv->cmdlog = NULL;
11921 }
Tejun Heobcb6d912011-01-26 12:12:50 +010011922
11923 /* make sure all works are inactive */
11924 cancel_delayed_work_sync(&priv->adhoc_check);
11925 cancel_work_sync(&priv->associate);
11926 cancel_work_sync(&priv->disassociate);
11927 cancel_work_sync(&priv->system_config);
11928 cancel_work_sync(&priv->rx_replenish);
11929 cancel_work_sync(&priv->adapter_restart);
11930 cancel_delayed_work_sync(&priv->rf_kill);
11931 cancel_work_sync(&priv->up);
11932 cancel_work_sync(&priv->down);
11933 cancel_delayed_work_sync(&priv->request_scan);
11934 cancel_delayed_work_sync(&priv->request_direct_scan);
11935 cancel_delayed_work_sync(&priv->request_passive_scan);
11936 cancel_delayed_work_sync(&priv->scan_event);
11937 cancel_delayed_work_sync(&priv->gather_stats);
11938 cancel_work_sync(&priv->abort_scan);
11939 cancel_work_sync(&priv->roam);
11940 cancel_delayed_work_sync(&priv->scan_check);
11941 cancel_work_sync(&priv->link_up);
11942 cancel_work_sync(&priv->link_down);
11943 cancel_delayed_work_sync(&priv->led_link_on);
11944 cancel_delayed_work_sync(&priv->led_link_off);
11945 cancel_delayed_work_sync(&priv->led_act_off);
11946 cancel_work_sync(&priv->merge_networks);
James Ketrenos43f66a62005-03-25 12:31:53 -060011947
James Ketrenosafbf30a2005-08-25 00:05:33 -050011948 /* Free MAC hash list for ADHOC */
11949 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11950 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011951 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011952 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011953 }
11954 }
11955
Jesper Juhl8f760782006-06-27 02:55:06 -070011956 kfree(priv->error);
11957 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011958
Zhu Yid685b8c2006-04-13 17:20:27 +080011959#ifdef CONFIG_IPW2200_PROMISCUOUS
11960 ipw_prom_free(priv);
11961#endif
11962
James Ketrenos43f66a62005-03-25 12:31:53 -060011963 free_irq(pdev->irq, priv);
11964 iounmap(priv->hw_base);
11965 pci_release_regions(pdev);
11966 pci_disable_device(pdev);
11967 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011968 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011969 wiphy_unregister(priv->ieee->wdev.wiphy);
11970 kfree(priv->ieee->a_band.channels);
11971 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011972 free_libipw(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011973 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011974}
11975
James Ketrenos43f66a62005-03-25 12:31:53 -060011976#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011977static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011978{
11979 struct ipw_priv *priv = pci_get_drvdata(pdev);
11980 struct net_device *dev = priv->net_dev;
11981
11982 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11983
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011984 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011985 ipw_down(priv);
11986
11987 /* Remove the PRESENT state of the device */
11988 netif_device_detach(dev);
11989
James Ketrenos43f66a62005-03-25 12:31:53 -060011990 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011991 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011992 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011993
Dan Williamsc3d72b92009-02-11 13:26:06 -050011994 priv->suspend_at = get_seconds();
11995
James Ketrenos43f66a62005-03-25 12:31:53 -060011996 return 0;
11997}
11998
11999static int ipw_pci_resume(struct pci_dev *pdev)
12000{
12001 struct ipw_priv *priv = pci_get_drvdata(pdev);
12002 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050012003 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060012004 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040012005
James Ketrenos43f66a62005-03-25 12:31:53 -060012006 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
12007
James Ketrenosea2b26e2005-08-24 21:25:16 -050012008 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050012009 err = pci_enable_device(pdev);
12010 if (err) {
12011 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
12012 dev->name);
12013 return err;
12014 }
James Ketrenos43f66a62005-03-25 12:31:53 -060012015 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050012016
James Ketrenos43f66a62005-03-25 12:31:53 -060012017 /*
12018 * Suspend/Resume resets the PCI configuration space, so we have to
12019 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
12020 * from interfering with C3 CPU state. pci_restore_state won't help
12021 * here since it only restores the first 64 bytes pci config header.
12022 */
Jeff Garzikbf794512005-07-31 13:07:26 -040012023 pci_read_config_dword(pdev, 0x40, &val);
12024 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060012025 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12026
12027 /* Set the device back into the PRESENT state; this will also wake
12028 * the queue of needed */
12029 netif_device_attach(dev);
12030
Dan Williamsc3d72b92009-02-11 13:26:06 -050012031 priv->suspend_time = get_seconds() - priv->suspend_at;
12032
James Ketrenos43f66a62005-03-25 12:31:53 -060012033 /* Bring the device back up */
Tejun Heobcb6d912011-01-26 12:12:50 +010012034 schedule_work(&priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012035
James Ketrenos43f66a62005-03-25 12:31:53 -060012036 return 0;
12037}
12038#endif
12039
Zhu Yic8c22c92006-08-21 11:38:39 +080012040static void ipw_pci_shutdown(struct pci_dev *pdev)
12041{
12042 struct ipw_priv *priv = pci_get_drvdata(pdev);
12043
12044 /* Take down the device; powers it off, etc. */
12045 ipw_down(priv);
12046
12047 pci_disable_device(pdev);
12048}
12049
James Ketrenos43f66a62005-03-25 12:31:53 -060012050/* driver initialization stuff */
12051static struct pci_driver ipw_driver = {
12052 .name = DRV_NAME,
12053 .id_table = card_ids,
12054 .probe = ipw_pci_probe,
12055 .remove = __devexit_p(ipw_pci_remove),
12056#ifdef CONFIG_PM
12057 .suspend = ipw_pci_suspend,
12058 .resume = ipw_pci_resume,
12059#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012060 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012061};
12062
12063static int __init ipw_init(void)
12064{
12065 int ret;
12066
12067 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12068 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12069
Jeff Garzik29917622006-08-19 17:48:59 -040012070 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012071 if (ret) {
12072 IPW_ERROR("Unable to initialize PCI module\n");
12073 return ret;
12074 }
12075
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012076 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012077 if (ret) {
12078 IPW_ERROR("Unable to create driver sysfs file\n");
12079 pci_unregister_driver(&ipw_driver);
12080 return ret;
12081 }
12082
12083 return ret;
12084}
12085
12086static void __exit ipw_exit(void)
12087{
12088 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12089 pci_unregister_driver(&ipw_driver);
12090}
12091
12092module_param(disable, int, 0444);
12093MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12094
12095module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012096MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012097
12098module_param(auto_create, int, 0444);
12099MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12100
Reinette Chatre21f8a732009-08-18 10:25:05 -070012101module_param_named(led, led_support, int, 0444);
ubuntu@tjworld.netc086aba2009-03-23 20:29:28 +000012102MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012103
James Ketrenos43f66a62005-03-25 12:31:53 -060012104module_param(debug, int, 0444);
12105MODULE_PARM_DESC(debug, "debug output mask");
12106
Reinette Chatre21f8a732009-08-18 10:25:05 -070012107module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012108MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012109
Zhu Yid685b8c2006-04-13 17:20:27 +080012110#ifdef CONFIG_IPW2200_PROMISCUOUS
12111module_param(rtap_iface, int, 0444);
12112MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12113#endif
12114
Zhu Yie43e3c12006-04-13 17:20:45 +080012115#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012116module_param(qos_enable, int, 0444);
12117MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012118
James Ketrenosb095c382005-08-24 22:04:42 -050012119module_param(qos_burst_enable, int, 0444);
12120MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12121
12122module_param(qos_no_ack_mask, int, 0444);
12123MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12124
12125module_param(burst_duration_CCK, int, 0444);
12126MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12127
12128module_param(burst_duration_OFDM, int, 0444);
12129MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012130#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012131
12132#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012133module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012134MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12135#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012136module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012137MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12138#endif
12139
Zhu Yi810dabd2006-01-24 16:36:59 +080012140module_param(bt_coexist, int, 0444);
12141MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12142
James Ketrenosb095c382005-08-24 22:04:42 -050012143module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012144MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012145
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012146module_param(cmdlog, int, 0444);
12147MODULE_PARM_DESC(cmdlog,
12148 "allocate a ring buffer for logging firmware commands");
12149
Zhu Yi4bfdb912006-01-24 16:37:16 +080012150module_param(roaming, int, 0444);
12151MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12152
Zhu Yid2b83e12006-04-13 17:19:36 +080012153module_param(antenna, int, 0444);
12154MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12155
James Ketrenos43f66a62005-03-25 12:31:53 -060012156module_exit(ipw_exit);
12157module_init(ipw_init);