blob: 192abfdc5039bd23b88885699b05c01ae6b759b8 [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>
James Ketrenos43f66a62005-03-25 12:31:53 -060034#include "ipw2200.h"
35
Zhu Yiae4af612006-04-13 17:20:34 +080036
37#ifndef KBUILD_EXTMOD
38#define VK "k"
39#else
40#define VK
41#endif
42
43#ifdef CONFIG_IPW2200_DEBUG
44#define VD "d"
45#else
46#define VD
47#endif
48
49#ifdef CONFIG_IPW2200_MONITOR
50#define VM "m"
51#else
52#define VM
53#endif
54
55#ifdef CONFIG_IPW2200_PROMISCUOUS
56#define VP "p"
57#else
58#define VP
59#endif
60
Zhu Yi459d4082006-04-13 17:21:00 +080061#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080062#define VR "r"
63#else
64#define VR
65#endif
66
67#ifdef CONFIG_IPW2200_QOS
68#define VQ "q"
69#else
70#define VQ
71#endif
72
Zhu Yiee2c4ad2007-07-12 16:09:47 +080073#define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060074#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080075#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060076#define DRV_VERSION IPW2200_VERSION
77
James Ketrenosb095c382005-08-24 22:04:42 -050078#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
79
James Ketrenos43f66a62005-03-25 12:31:53 -060080MODULE_DESCRIPTION(DRV_DESCRIPTION);
81MODULE_VERSION(DRV_VERSION);
82MODULE_AUTHOR(DRV_COPYRIGHT);
83MODULE_LICENSE("GPL");
Ben Hutchings873395a2009-11-07 21:59:10 +000084MODULE_FIRMWARE("ipw2200-ibss.fw");
85#ifdef CONFIG_IPW2200_MONITOR
86MODULE_FIRMWARE("ipw2200-sniffer.fw");
87#endif
88MODULE_FIRMWARE("ipw2200-bss.fw");
James Ketrenos43f66a62005-03-25 12:31:53 -060089
James Ketrenosf6c5cb72005-08-25 00:39:09 -050090static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060091static int debug = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -070092static int default_channel = 0;
93static int network_mode = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060094
95static u32 ipw_debug_level;
Tim Gardner5c7f9b72008-10-14 10:38:03 -060096static int associate;
James Ketrenos43f66a62005-03-25 12:31:53 -060097static int auto_create = 1;
Reinette Chatre21f8a732009-08-18 10:25:05 -070098static int led_support = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060099static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +0800100static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +0800101static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +0800102static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600103static const char ipw_modes[] = {
104 'a', 'b', 'g', '?'
105};
Zhu Yid2b83e12006-04-13 17:19:36 +0800106static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600107
Zhu Yid685b8c2006-04-13 17:20:27 +0800108#ifdef CONFIG_IPW2200_PROMISCUOUS
109static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
110#endif
111
John W. Linvillea3caa992009-08-25 14:12:25 -0400112static struct ieee80211_rate ipw2200_rates[] = {
113 { .bitrate = 10 },
114 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
115 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
116 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
117 { .bitrate = 60 },
118 { .bitrate = 90 },
119 { .bitrate = 120 },
120 { .bitrate = 180 },
121 { .bitrate = 240 },
122 { .bitrate = 360 },
123 { .bitrate = 480 },
124 { .bitrate = 540 }
125};
126
127#define ipw2200_a_rates (ipw2200_rates + 4)
128#define ipw2200_num_a_rates 8
129#define ipw2200_bg_rates (ipw2200_rates + 0)
130#define ipw2200_num_bg_rates 12
Zhu Yid685b8c2006-04-13 17:20:27 +0800131
Zhu Yie43e3c12006-04-13 17:20:45 +0800132#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500133static int qos_enable = 0;
134static int qos_burst_enable = 0;
135static int qos_no_ack_mask = 0;
136static int burst_duration_CCK = 0;
137static int burst_duration_OFDM = 0;
138
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400139static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500140 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
141 QOS_TX3_CW_MIN_OFDM},
142 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
143 QOS_TX3_CW_MAX_OFDM},
144 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
145 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
146 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
147 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
148};
149
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400150static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500151 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
152 QOS_TX3_CW_MIN_CCK},
153 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
154 QOS_TX3_CW_MAX_CCK},
155 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
156 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
157 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
158 QOS_TX3_TXOP_LIMIT_CCK}
159};
160
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400161static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500162 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
163 DEF_TX3_CW_MIN_OFDM},
164 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
165 DEF_TX3_CW_MAX_OFDM},
166 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
167 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
168 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
169 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
170};
171
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400172static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500173 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
174 DEF_TX3_CW_MIN_CCK},
175 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
176 DEF_TX3_CW_MAX_CCK},
177 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
178 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
179 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
180 DEF_TX3_TXOP_LIMIT_CCK}
181};
182
183static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
184
185static int from_priority_to_tx_queue[] = {
186 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
187 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
188};
189
190static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
191
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400192static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500193 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400194static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500195 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800196#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500197
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000198static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500199static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600200static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400201static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600202 struct clx2_tx_queue *txq, int qindex);
203static int ipw_queue_reset(struct ipw_priv *priv);
204
205static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
206 int len, int sync);
207
208static void ipw_tx_queue_free(struct ipw_priv *);
209
210static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
211static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
212static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600213static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000214static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600215static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000216static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600217static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400218static int init_supported_rates(struct ipw_priv *priv,
219 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500220static void ipw_set_hwcrypto_keys(struct ipw_priv *);
221static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600222
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500223static int snprint_line(char *buf, size_t count,
224 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600225{
226 int out, i, j, l;
227 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400228
James Ketrenos43f66a62005-03-25 12:31:53 -0600229 out = snprintf(buf, count, "%08X", ofs);
230
231 for (l = 0, i = 0; i < 2; i++) {
232 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400233 for (j = 0; j < 8 && l < len; j++, l++)
234 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600235 data[(i * 8 + j)]);
236 for (; j < 8; j++)
237 out += snprintf(buf + out, count - out, " ");
238 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400239
James Ketrenos43f66a62005-03-25 12:31:53 -0600240 out += snprintf(buf + out, count - out, " ");
241 for (l = 0, i = 0; i < 2; i++) {
242 out += snprintf(buf + out, count - out, " ");
243 for (j = 0; j < 8 && l < len; j++, l++) {
244 c = data[(i * 8 + j)];
245 if (!isascii(c) || !isprint(c))
246 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400247
James Ketrenos43f66a62005-03-25 12:31:53 -0600248 out += snprintf(buf + out, count - out, "%c", c);
249 }
250
251 for (; j < 8; j++)
252 out += snprintf(buf + out, count - out, " ");
253 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400254
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500255 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600256}
257
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400258static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600259{
260 char line[81];
261 u32 ofs = 0;
262 if (!(ipw_debug_level & level))
263 return;
264
265 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500266 snprint_line(line, sizeof(line), &data[ofs],
267 min(len, 16U), ofs);
268 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600269 ofs += 16;
270 len -= min(len, 16U);
271 }
272}
273
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500274static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
275{
276 size_t out = size;
277 u32 ofs = 0;
278 int total = 0;
279
280 while (size && len) {
281 out = snprint_line(output, size, &data[ofs],
282 min_t(size_t, len, 16U), ofs);
283
284 ofs += 16;
285 output += out;
286 size -= out;
287 len -= min_t(size_t, len, 16U);
288 total += out;
289 }
290 return total;
291}
292
Zhu Yic8fe6672006-01-24 16:36:36 +0800293/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600294static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
295#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
296
Zhu Yic8fe6672006-01-24 16:36:36 +0800297/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600298static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
299#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
300
Zhu Yic8fe6672006-01-24 16:36:36 +0800301/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600302static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
303static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
304{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400305 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
306 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600307 _ipw_write_reg8(a, b, c);
308}
309
Zhu Yic8fe6672006-01-24 16:36:36 +0800310/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600311static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
312static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
313{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400314 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
315 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600316 _ipw_write_reg16(a, b, c);
317}
318
Zhu Yic8fe6672006-01-24 16:36:36 +0800319/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600320static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
321static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
322{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400323 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
324 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600325 _ipw_write_reg32(a, b, c);
326}
327
Zhu Yic8fe6672006-01-24 16:36:36 +0800328/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100329static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
330 u8 val)
331{
332 writeb(val, ipw->hw_base + ofs);
333}
Zhu Yic8fe6672006-01-24 16:36:36 +0800334
335/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200336#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100337 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
338 __LINE__, (u32)(ofs), (u32)(val)); \
339 _ipw_write8(ipw, ofs, val); \
340} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600341
Zhu Yic8fe6672006-01-24 16:36:36 +0800342/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100343static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
344 u16 val)
345{
346 writew(val, ipw->hw_base + ofs);
347}
Zhu Yic8fe6672006-01-24 16:36:36 +0800348
349/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100350#define ipw_write16(ipw, ofs, val) do { \
351 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
352 __LINE__, (u32)(ofs), (u32)(val)); \
353 _ipw_write16(ipw, ofs, val); \
354} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600355
Zhu Yic8fe6672006-01-24 16:36:36 +0800356/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100357static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
358 u32 val)
359{
360 writel(val, ipw->hw_base + ofs);
361}
Zhu Yic8fe6672006-01-24 16:36:36 +0800362
363/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100364#define ipw_write32(ipw, ofs, val) do { \
365 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
366 __LINE__, (u32)(ofs), (u32)(val)); \
367 _ipw_write32(ipw, ofs, val); \
368} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600369
Zhu Yic8fe6672006-01-24 16:36:36 +0800370/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100371static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400372{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100373 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600374}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400375
Zhu Yic8fe6672006-01-24 16:36:36 +0800376/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100377#define ipw_read8(ipw, ofs) ({ \
378 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
379 (u32)(ofs)); \
380 _ipw_read8(ipw, ofs); \
381})
James Ketrenos43f66a62005-03-25 12:31:53 -0600382
Zhu Yic8fe6672006-01-24 16:36:36 +0800383/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100384static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400385{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100386 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600387}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400388
Zhu Yic8fe6672006-01-24 16:36:36 +0800389/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100390#define ipw_read16(ipw, ofs) ({ \
391 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
392 (u32)(ofs)); \
393 _ipw_read16(ipw, ofs); \
394})
James Ketrenos43f66a62005-03-25 12:31:53 -0600395
Zhu Yic8fe6672006-01-24 16:36:36 +0800396/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100397static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400398{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100399 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600400}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400401
Zhu Yic8fe6672006-01-24 16:36:36 +0800402/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100403#define ipw_read32(ipw, ofs) ({ \
404 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
405 (u32)(ofs)); \
406 _ipw_read32(ipw, ofs); \
407})
James Ketrenos43f66a62005-03-25 12:31:53 -0600408
409static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800410/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100411#define ipw_read_indirect(a, b, c, d) ({ \
412 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
413 __LINE__, (u32)(b), (u32)(d)); \
414 _ipw_read_indirect(a, b, c, d); \
415})
James Ketrenos43f66a62005-03-25 12:31:53 -0600416
Zhu Yic8fe6672006-01-24 16:36:36 +0800417/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400418static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
419 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100420#define ipw_write_indirect(a, b, c, d) do { \
421 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
422 __LINE__, (u32)(b), (u32)(d)); \
423 _ipw_write_indirect(a, b, c, d); \
424} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600425
Zhu Yic8fe6672006-01-24 16:36:36 +0800426/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400427static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600428{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400429 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500430 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
431 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600432}
433
Zhu Yic8fe6672006-01-24 16:36:36 +0800434/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600435static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
436{
Zhu Yi2638bc32006-01-24 16:37:52 +0800437 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800438 u32 dif_len = reg - aligned_addr;
439
James Ketrenos43f66a62005-03-25 12:31:53 -0600440 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800441 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
442 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600443}
444
Zhu Yic8fe6672006-01-24 16:36:36 +0800445/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400446static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600447{
Zhu Yi2638bc32006-01-24 16:37:52 +0800448 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800449 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
450
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800452 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
453 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600454}
455
Zhu Yic8fe6672006-01-24 16:36:36 +0800456/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600457static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
458{
459 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500460 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100461 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500462 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400463 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600464}
465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600467static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
468{
469 u32 value;
470
471 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
472
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
474 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
Frans Pop9fd1ea42010-03-24 19:46:31 +0100475 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 return value;
477}
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479/* General purpose, no alignment requirement, iterative (multi-byte) read, */
480/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600481static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
482 int num)
483{
Zhu Yi2638bc32006-01-24 16:37:52 +0800484 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600485 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400487
James Ketrenos43f66a62005-03-25 12:31:53 -0600488 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
489
James Ketrenosea2b26e2005-08-24 21:25:16 -0500490 if (num <= 0) {
491 return;
492 }
493
Zhu Yic8fe6672006-01-24 16:36:36 +0800494 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500496 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600497 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500498 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500499 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600500 aligned_addr += 4;
501 }
502
Zhu Yic8fe6672006-01-24 16:36:36 +0800503 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500504 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500505 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500506 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400507
Zhu Yic8fe6672006-01-24 16:36:36 +0800508 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500509 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500510 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500511 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500512 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500513 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600514}
515
Zhu Yic8fe6672006-01-24 16:36:36 +0800516/* General purpose, no alignment requirement, iterative (multi-byte) write, */
517/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400518static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600519 int num)
520{
Zhu Yi2638bc32006-01-24 16:37:52 +0800521 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600522 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600523 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400524
James Ketrenos43f66a62005-03-25 12:31:53 -0600525 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400526
James Ketrenosea2b26e2005-08-24 21:25:16 -0500527 if (num <= 0) {
528 return;
529 }
530
Zhu Yic8fe6672006-01-24 16:36:36 +0800531 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600532 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500533 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800534 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500535 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500536 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600537 aligned_addr += 4;
538 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400539
Zhu Yic8fe6672006-01-24 16:36:36 +0800540 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500541 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500542 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500543 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400544
Zhu Yic8fe6672006-01-24 16:36:36 +0800545 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500546 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500547 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500548 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500549 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500550 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600551}
552
Zhu Yic8fe6672006-01-24 16:36:36 +0800553/* General purpose, no alignment requirement, iterative (multi-byte) write, */
554/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400555static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600556 int num)
557{
558 memcpy_toio((priv->hw_base + addr), buf, num);
559}
560
Zhu Yic8fe6672006-01-24 16:36:36 +0800561/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600562static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
563{
564 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
565}
566
Zhu Yic8fe6672006-01-24 16:36:36 +0800567/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600568static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
569{
570 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
571}
572
Zhu Yi89c318e2006-06-08 22:19:49 -0700573static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600574{
575 if (priv->status & STATUS_INT_ENABLED)
576 return;
577 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500578 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600579}
580
Zhu Yi89c318e2006-06-08 22:19:49 -0700581static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600582{
583 if (!(priv->status & STATUS_INT_ENABLED))
584 return;
585 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500586 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600587}
588
Zhu Yi89c318e2006-06-08 22:19:49 -0700589static inline void ipw_enable_interrupts(struct ipw_priv *priv)
590{
591 unsigned long flags;
592
593 spin_lock_irqsave(&priv->irq_lock, flags);
594 __ipw_enable_interrupts(priv);
595 spin_unlock_irqrestore(&priv->irq_lock, flags);
596}
597
598static inline void ipw_disable_interrupts(struct ipw_priv *priv)
599{
600 unsigned long flags;
601
602 spin_lock_irqsave(&priv->irq_lock, flags);
603 __ipw_disable_interrupts(priv);
604 spin_unlock_irqrestore(&priv->irq_lock, flags);
605}
606
James Ketrenos43f66a62005-03-25 12:31:53 -0600607static char *ipw_error_desc(u32 val)
608{
609 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400610 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600611 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400612 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600613 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400614 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600615 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400616 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600617 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400618 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500619 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400620 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500621 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400622 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500623 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400624 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500625 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400626 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500627 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400628 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500629 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400630 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500631 return "DMA_STATUS";
632 case IPW_FW_ERROR_DINO_ERROR:
633 return "DINO_ERROR";
634 case IPW_FW_ERROR_EEPROM_ERROR:
635 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400636 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500637 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400638 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500639 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400640 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500641 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600642 }
643}
644
James Ketrenosb39860c2005-08-12 09:36:32 -0500645static void ipw_dump_error_log(struct ipw_priv *priv,
646 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600647{
James Ketrenosb39860c2005-08-12 09:36:32 -0500648 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600649
James Ketrenosb39860c2005-08-12 09:36:32 -0500650 if (!error) {
651 IPW_ERROR("Error allocating and capturing error log. "
652 "Nothing to dump.\n");
653 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600654 }
655
James Ketrenosb39860c2005-08-12 09:36:32 -0500656 IPW_ERROR("Start IPW Error Log Dump:\n");
657 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
658 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600659
James Ketrenosb39860c2005-08-12 09:36:32 -0500660 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400661 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500662 ipw_error_desc(error->elem[i].desc),
663 error->elem[i].time,
664 error->elem[i].blink1,
665 error->elem[i].blink2,
666 error->elem[i].link1,
667 error->elem[i].link2, error->elem[i].data);
668 for (i = 0; i < error->log_len; i++)
669 IPW_ERROR("%i\t0x%08x\t%i\n",
670 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500671 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600672}
James Ketrenos43f66a62005-03-25 12:31:53 -0600673
James Ketrenosc848d0a2005-08-24 21:56:24 -0500674static inline int ipw_is_init(struct ipw_priv *priv)
675{
676 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600677}
678
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400679static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600680{
681 u32 addr, field_info, field_len, field_count, total_len;
682
683 IPW_DEBUG_ORD("ordinal = %i\n", ord);
684
685 if (!priv || !val || !len) {
686 IPW_DEBUG_ORD("Invalid argument\n");
687 return -EINVAL;
688 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400689
James Ketrenos43f66a62005-03-25 12:31:53 -0600690 /* verify device ordinal tables have been initialized */
691 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
692 IPW_DEBUG_ORD("Access ordinals before initialization\n");
693 return -EINVAL;
694 }
695
696 switch (IPW_ORD_TABLE_ID_MASK & ord) {
697 case IPW_ORD_TABLE_0_MASK:
698 /*
699 * TABLE 0: Direct access to a table of 32 bit values
700 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400701 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600702 * read from the table
703 */
704
705 /* remove the table id from the ordinal */
706 ord &= IPW_ORD_TABLE_VALUE_MASK;
707
708 /* boundary check */
709 if (ord > priv->table0_len) {
710 IPW_DEBUG_ORD("ordinal value (%i) longer then "
711 "max (%i)\n", ord, priv->table0_len);
712 return -EINVAL;
713 }
714
715 /* verify we have enough room to store the value */
716 if (*len < sizeof(u32)) {
717 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200718 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600719 return -EINVAL;
720 }
721
722 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400723 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600724
725 *len = sizeof(u32);
726 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400727 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600728 break;
729
730 case IPW_ORD_TABLE_1_MASK:
731 /*
732 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400733 *
734 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600735 * representing starting addr for the data (which is
736 * also a u32)
737 */
738
739 /* remove the table id from the ordinal */
740 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400741
James Ketrenos43f66a62005-03-25 12:31:53 -0600742 /* boundary check */
743 if (ord > priv->table1_len) {
744 IPW_DEBUG_ORD("ordinal value too long\n");
745 return -EINVAL;
746 }
747
748 /* verify we have enough room to store the value */
749 if (*len < sizeof(u32)) {
750 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200751 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600752 return -EINVAL;
753 }
754
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400755 *((u32 *) val) =
756 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600757 *len = sizeof(u32);
758 break;
759
760 case IPW_ORD_TABLE_2_MASK:
761 /*
762 * TABLE 2: Indirect access to a table of variable sized values
763 *
764 * This table consist of six values, each containing
765 * - dword containing the starting offset of the data
766 * - dword containing the lengh in the first 16bits
767 * and the count in the second 16bits
768 */
769
770 /* remove the table id from the ordinal */
771 ord &= IPW_ORD_TABLE_VALUE_MASK;
772
773 /* boundary check */
774 if (ord > priv->table2_len) {
775 IPW_DEBUG_ORD("ordinal value too long\n");
776 return -EINVAL;
777 }
778
779 /* get the address of statistic */
780 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400781
782 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600783 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400784 field_info =
785 ipw_read_reg32(priv,
786 priv->table2_addr + (ord << 3) +
787 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400788
James Ketrenos43f66a62005-03-25 12:31:53 -0600789 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400790 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400791
James Ketrenos43f66a62005-03-25 12:31:53 -0600792 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400793 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400794
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200795 /* abort if not enough memory */
James Ketrenos43f66a62005-03-25 12:31:53 -0600796 total_len = field_len * field_count;
797 if (total_len > *len) {
798 *len = total_len;
799 return -EINVAL;
800 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400801
James Ketrenos43f66a62005-03-25 12:31:53 -0600802 *len = total_len;
803 if (!total_len)
804 return 0;
805
806 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400807 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600808 addr, total_len, field_info);
809 ipw_read_indirect(priv, addr, val, total_len);
810 break;
811
812 default:
813 IPW_DEBUG_ORD("Invalid ordinal!\n");
814 return -EINVAL;
815
816 }
817
James Ketrenos43f66a62005-03-25 12:31:53 -0600818 return 0;
819}
820
821static void ipw_init_ordinals(struct ipw_priv *priv)
822{
823 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400824 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600825
826 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
827 priv->table0_addr, priv->table0_len);
828
829 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
830 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
831
832 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
833 priv->table1_addr, priv->table1_len);
834
835 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
836 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400837 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600838
839 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
840 priv->table2_addr, priv->table2_len);
841
842}
843
Adrian Bunka73e22b2006-01-21 01:39:42 +0100844static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500845{
James Ketrenosb095c382005-08-24 22:04:42 -0500846 reg &= ~IPW_START_STANDBY;
847 if (reg & IPW_GATE_ODMA)
848 reg &= ~IPW_GATE_ODMA;
849 if (reg & IPW_GATE_IDMA)
850 reg &= ~IPW_GATE_IDMA;
851 if (reg & IPW_GATE_ADMA)
852 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500853 return reg;
854}
855
856/*
857 * LED behavior:
858 * - On radio ON, turn on any LEDs that require to be on during start
859 * - On initialization, start unassociated blink
860 * - On association, disable unassociated blink
861 * - On disassociation, start unassociated blink
862 * - On radio OFF, turn off any LEDs started during radio on
863 *
864 */
Zhu Yiede61112006-01-24 16:37:10 +0800865#define LD_TIME_LINK_ON msecs_to_jiffies(300)
866#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
867#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500868
Adrian Bunka73e22b2006-01-21 01:39:42 +0100869static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500870{
871 unsigned long flags;
872 u32 led;
873
874 /* If configured to not use LEDs, or nic_type is 1,
875 * then we don't toggle a LINK led */
876 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
877 return;
878
879 spin_lock_irqsave(&priv->lock, flags);
880
881 if (!(priv->status & STATUS_RF_KILL_MASK) &&
882 !(priv->status & STATUS_LED_LINK_ON)) {
883 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500884 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500885 led |= priv->led_association_on;
886
887 led = ipw_register_toggle(led);
888
889 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500890 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500891
892 priv->status |= STATUS_LED_LINK_ON;
893
894 /* If we aren't associated, schedule turning the LED off */
895 if (!(priv->status & STATUS_ASSOCIATED))
896 queue_delayed_work(priv->workqueue,
897 &priv->led_link_off,
898 LD_TIME_LINK_ON);
899 }
900
901 spin_unlock_irqrestore(&priv->lock, flags);
902}
903
David Howellsc4028952006-11-22 14:57:56 +0000904static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500905{
David Howellsc4028952006-11-22 14:57:56 +0000906 struct ipw_priv *priv =
907 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800908 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000909 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800910 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500911}
912
Adrian Bunka73e22b2006-01-21 01:39:42 +0100913static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500914{
915 unsigned long flags;
916 u32 led;
917
918 /* If configured not to use LEDs, or nic type is 1,
919 * then we don't goggle the LINK led. */
920 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
921 return;
922
923 spin_lock_irqsave(&priv->lock, flags);
924
925 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500926 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500927 led &= priv->led_association_off;
928 led = ipw_register_toggle(led);
929
930 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500931 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500932
933 IPW_DEBUG_LED("Link LED Off\n");
934
935 priv->status &= ~STATUS_LED_LINK_ON;
936
937 /* If we aren't associated and the radio is on, schedule
938 * turning the LED on (blink while unassociated) */
939 if (!(priv->status & STATUS_RF_KILL_MASK) &&
940 !(priv->status & STATUS_ASSOCIATED))
941 queue_delayed_work(priv->workqueue, &priv->led_link_on,
942 LD_TIME_LINK_OFF);
943
944 }
945
946 spin_unlock_irqrestore(&priv->lock, flags);
947}
948
David Howellsc4028952006-11-22 14:57:56 +0000949static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500950{
David Howellsc4028952006-11-22 14:57:56 +0000951 struct ipw_priv *priv =
952 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800953 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000954 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800955 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500956}
957
Arjan van de Ven858119e2006-01-14 13:20:43 -0800958static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500959{
James Ketrenosa613bff2005-08-24 21:43:11 -0500960 u32 led;
961
962 if (priv->config & CFG_NO_LED)
963 return;
964
James Ketrenosb095c382005-08-24 22:04:42 -0500965 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500966 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500967
968 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500969 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500970 led |= priv->led_activity_on;
971
972 led = ipw_register_toggle(led);
973
974 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500975 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500976
977 IPW_DEBUG_LED("Activity LED On\n");
978
979 priv->status |= STATUS_LED_ACT_ON;
980
James Ketrenosc848d0a2005-08-24 21:56:24 -0500981 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500982 queue_delayed_work(priv->workqueue, &priv->led_act_off,
983 LD_TIME_ACT_ON);
984 } else {
985 /* Reschedule LED off for full time period */
986 cancel_delayed_work(&priv->led_act_off);
987 queue_delayed_work(priv->workqueue, &priv->led_act_off,
988 LD_TIME_ACT_ON);
989 }
James Ketrenosb095c382005-08-24 22:04:42 -0500990}
James Ketrenosa613bff2005-08-24 21:43:11 -0500991
Adrian Bunka73e22b2006-01-21 01:39:42 +0100992#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500993void ipw_led_activity_on(struct ipw_priv *priv)
994{
995 unsigned long flags;
996 spin_lock_irqsave(&priv->lock, flags);
997 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500998 spin_unlock_irqrestore(&priv->lock, flags);
999}
Adrian Bunka73e22b2006-01-21 01:39:42 +01001000#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -05001001
Adrian Bunka73e22b2006-01-21 01:39:42 +01001002static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001003{
1004 unsigned long flags;
1005 u32 led;
1006
1007 if (priv->config & CFG_NO_LED)
1008 return;
1009
1010 spin_lock_irqsave(&priv->lock, flags);
1011
1012 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -05001013 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001014 led &= priv->led_activity_off;
1015
1016 led = ipw_register_toggle(led);
1017
1018 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001019 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001020
1021 IPW_DEBUG_LED("Activity LED Off\n");
1022
1023 priv->status &= ~STATUS_LED_ACT_ON;
1024 }
1025
1026 spin_unlock_irqrestore(&priv->lock, flags);
1027}
1028
David Howellsc4028952006-11-22 14:57:56 +00001029static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001030{
David Howellsc4028952006-11-22 14:57:56 +00001031 struct ipw_priv *priv =
1032 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001033 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001034 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001035 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001036}
1037
Adrian Bunka73e22b2006-01-21 01:39:42 +01001038static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001039{
1040 unsigned long flags;
1041 u32 led;
1042
1043 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001044 if (priv->config & CFG_NO_LED ||
1045 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001046 return;
1047
1048 spin_lock_irqsave(&priv->lock, flags);
1049
James Ketrenosb095c382005-08-24 22:04:42 -05001050 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001051 if (priv->assoc_network->mode == IEEE_A) {
1052 led |= priv->led_ofdm_on;
1053 led &= priv->led_association_off;
1054 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1055 } else if (priv->assoc_network->mode == IEEE_G) {
1056 led |= priv->led_ofdm_on;
1057 led |= priv->led_association_on;
1058 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1059 } else {
1060 led &= priv->led_ofdm_off;
1061 led |= priv->led_association_on;
1062 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1063 }
1064
1065 led = ipw_register_toggle(led);
1066
1067 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001068 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001069
1070 spin_unlock_irqrestore(&priv->lock, flags);
1071}
1072
Adrian Bunka73e22b2006-01-21 01:39:42 +01001073static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001074{
1075 unsigned long flags;
1076 u32 led;
1077
1078 /* Only nic type 1 supports mode LEDs */
1079 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1080 return;
1081
1082 spin_lock_irqsave(&priv->lock, flags);
1083
James Ketrenosb095c382005-08-24 22:04:42 -05001084 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001085 led &= priv->led_ofdm_off;
1086 led &= priv->led_association_off;
1087
1088 led = ipw_register_toggle(led);
1089
1090 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001091 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001092
1093 spin_unlock_irqrestore(&priv->lock, flags);
1094}
1095
Adrian Bunka73e22b2006-01-21 01:39:42 +01001096static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001097{
1098 ipw_led_link_on(priv);
1099}
1100
Adrian Bunka73e22b2006-01-21 01:39:42 +01001101static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001102{
1103 ipw_led_activity_off(priv);
1104 ipw_led_link_off(priv);
1105}
1106
Adrian Bunka73e22b2006-01-21 01:39:42 +01001107static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001108{
1109 /* Set the Link Led on for all nic types */
1110 ipw_led_link_on(priv);
1111}
1112
Adrian Bunka73e22b2006-01-21 01:39:42 +01001113static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001114{
1115 ipw_led_activity_off(priv);
1116 ipw_led_link_off(priv);
1117
1118 if (priv->status & STATUS_RF_KILL_MASK)
1119 ipw_led_radio_off(priv);
1120}
1121
Adrian Bunka73e22b2006-01-21 01:39:42 +01001122static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001123{
1124 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1125
1126 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001127 priv->led_activity_on = IPW_ACTIVITY_LED;
1128 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001129
James Ketrenosb095c382005-08-24 22:04:42 -05001130 priv->led_association_on = IPW_ASSOCIATED_LED;
1131 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001132
1133 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001134 priv->led_ofdm_on = IPW_OFDM_LED;
1135 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001136
1137 switch (priv->nic_type) {
1138 case EEPROM_NIC_TYPE_1:
1139 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001140 priv->led_activity_on = IPW_ASSOCIATED_LED;
1141 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1142 priv->led_association_on = IPW_ACTIVITY_LED;
1143 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001144
1145 if (!(priv->config & CFG_NO_LED))
1146 ipw_led_band_on(priv);
1147
1148 /* And we don't blink link LEDs for this nic, so
1149 * just return here */
1150 return;
1151
1152 case EEPROM_NIC_TYPE_3:
1153 case EEPROM_NIC_TYPE_2:
1154 case EEPROM_NIC_TYPE_4:
1155 case EEPROM_NIC_TYPE_0:
1156 break;
1157
1158 default:
1159 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1160 priv->nic_type);
1161 priv->nic_type = EEPROM_NIC_TYPE_0;
1162 break;
1163 }
1164
1165 if (!(priv->config & CFG_NO_LED)) {
1166 if (priv->status & STATUS_ASSOCIATED)
1167 ipw_led_link_on(priv);
1168 else
1169 ipw_led_link_off(priv);
1170 }
1171}
1172
Adrian Bunka73e22b2006-01-21 01:39:42 +01001173static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001174{
James Ketrenosa613bff2005-08-24 21:43:11 -05001175 ipw_led_activity_off(priv);
1176 ipw_led_link_off(priv);
1177 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001178 cancel_delayed_work(&priv->led_link_on);
1179 cancel_delayed_work(&priv->led_link_off);
1180 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001181}
1182
James Ketrenos43f66a62005-03-25 12:31:53 -06001183/*
1184 * The following adds a new attribute to the sysfs representation
1185 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1186 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001187 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001188 * See the level definitions in ipw for details.
1189 */
1190static ssize_t show_debug_level(struct device_driver *d, char *buf)
1191{
1192 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1193}
James Ketrenosa613bff2005-08-24 21:43:11 -05001194
1195static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1196 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001197{
1198 char *p = (char *)buf;
1199 u32 val;
1200
1201 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1202 p++;
1203 if (p[0] == 'x' || p[0] == 'X')
1204 p++;
1205 val = simple_strtoul(p, &p, 16);
1206 } else
1207 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001208 if (p == buf)
1209 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001210 ": %s is not in hex or decimal form.\n", buf);
1211 else
1212 ipw_debug_level = val;
1213
1214 return strnlen(buf, count);
1215}
1216
Jeff Garzikbf794512005-07-31 13:07:26 -04001217static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001218 show_debug_level, store_debug_level);
1219
James Ketrenosb39860c2005-08-12 09:36:32 -05001220static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1221{
Zhu Yic8fe6672006-01-24 16:36:36 +08001222 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001223 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1224}
1225
1226static void ipw_capture_event_log(struct ipw_priv *priv,
1227 u32 log_len, struct ipw_event *log)
1228{
1229 u32 base;
1230
1231 if (log_len) {
1232 base = ipw_read32(priv, IPW_EVENT_LOG);
1233 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1234 (u8 *) log, sizeof(*log) * log_len);
1235 }
1236}
1237
1238static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1239{
1240 struct ipw_fw_error *error;
1241 u32 log_len = ipw_get_event_log_len(priv);
1242 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1243 u32 elem_len = ipw_read_reg32(priv, base);
1244
1245 error = kmalloc(sizeof(*error) +
1246 sizeof(*error->elem) * elem_len +
1247 sizeof(*error->log) * log_len, GFP_ATOMIC);
1248 if (!error) {
1249 IPW_ERROR("Memory allocation for firmware error log "
1250 "failed.\n");
1251 return NULL;
1252 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001253 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001254 error->status = priv->status;
1255 error->config = priv->config;
1256 error->elem_len = elem_len;
1257 error->log_len = log_len;
1258 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001259 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001260
1261 ipw_capture_event_log(priv, log_len, error->log);
1262
1263 if (elem_len)
1264 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1265 sizeof(*error->elem) * elem_len);
1266
1267 return error;
1268}
1269
James Ketrenosb39860c2005-08-12 09:36:32 -05001270static ssize_t show_event_log(struct device *d,
1271 struct device_attribute *attr, char *buf)
1272{
1273 struct ipw_priv *priv = dev_get_drvdata(d);
1274 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001275 u32 log_size;
1276 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001277 u32 len = 0, i;
1278
Reinette Chatre412e9e72007-12-18 22:01:02 -08001279 /* not using min() because of its strict type checking */
1280 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1281 sizeof(*log) * log_len : PAGE_SIZE;
1282 log = kzalloc(log_size, GFP_KERNEL);
1283 if (!log) {
1284 IPW_ERROR("Unable to allocate memory for log\n");
1285 return 0;
1286 }
1287 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001288 ipw_capture_event_log(priv, log_len, log);
1289
1290 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1291 for (i = 0; i < log_len; i++)
1292 len += snprintf(buf + len, PAGE_SIZE - len,
1293 "\n%08X%08X%08X",
1294 log[i].time, log[i].event, log[i].data);
1295 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001296 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001297 return len;
1298}
1299
1300static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1301
1302static ssize_t show_error(struct device *d,
1303 struct device_attribute *attr, char *buf)
1304{
1305 struct ipw_priv *priv = dev_get_drvdata(d);
1306 u32 len = 0, i;
1307 if (!priv->error)
1308 return 0;
1309 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001310 "%08lX%08X%08X%08X",
1311 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001312 priv->error->status,
1313 priv->error->config, priv->error->elem_len);
1314 for (i = 0; i < priv->error->elem_len; i++)
1315 len += snprintf(buf + len, PAGE_SIZE - len,
1316 "\n%08X%08X%08X%08X%08X%08X%08X",
1317 priv->error->elem[i].time,
1318 priv->error->elem[i].desc,
1319 priv->error->elem[i].blink1,
1320 priv->error->elem[i].blink2,
1321 priv->error->elem[i].link1,
1322 priv->error->elem[i].link2,
1323 priv->error->elem[i].data);
1324
1325 len += snprintf(buf + len, PAGE_SIZE - len,
1326 "\n%08X", priv->error->log_len);
1327 for (i = 0; i < priv->error->log_len; i++)
1328 len += snprintf(buf + len, PAGE_SIZE - len,
1329 "\n%08X%08X%08X",
1330 priv->error->log[i].time,
1331 priv->error->log[i].event,
1332 priv->error->log[i].data);
1333 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1334 return len;
1335}
1336
1337static ssize_t clear_error(struct device *d,
1338 struct device_attribute *attr,
1339 const char *buf, size_t count)
1340{
1341 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001342
1343 kfree(priv->error);
1344 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001345 return count;
1346}
1347
1348static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1349
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001350static ssize_t show_cmd_log(struct device *d,
1351 struct device_attribute *attr, char *buf)
1352{
1353 struct ipw_priv *priv = dev_get_drvdata(d);
1354 u32 len = 0, i;
1355 if (!priv->cmdlog)
1356 return 0;
1357 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1358 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1359 i = (i + 1) % priv->cmdlog_len) {
1360 len +=
1361 snprintf(buf + len, PAGE_SIZE - len,
1362 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1363 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1364 priv->cmdlog[i].cmd.len);
1365 len +=
1366 snprintk_buf(buf + len, PAGE_SIZE - len,
1367 (u8 *) priv->cmdlog[i].cmd.param,
1368 priv->cmdlog[i].cmd.len);
1369 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1370 }
1371 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1372 return len;
1373}
1374
1375static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1376
Zhu Yid685b8c2006-04-13 17:20:27 +08001377#ifdef CONFIG_IPW2200_PROMISCUOUS
1378static void ipw_prom_free(struct ipw_priv *priv);
1379static int ipw_prom_alloc(struct ipw_priv *priv);
1380static ssize_t store_rtap_iface(struct device *d,
1381 struct device_attribute *attr,
1382 const char *buf, size_t count)
1383{
1384 struct ipw_priv *priv = dev_get_drvdata(d);
1385 int rc = 0;
1386
1387 if (count < 1)
1388 return -EINVAL;
1389
1390 switch (buf[0]) {
1391 case '0':
1392 if (!rtap_iface)
1393 return count;
1394
1395 if (netif_running(priv->prom_net_dev)) {
1396 IPW_WARNING("Interface is up. Cannot unregister.\n");
1397 return count;
1398 }
1399
1400 ipw_prom_free(priv);
1401 rtap_iface = 0;
1402 break;
1403
1404 case '1':
1405 if (rtap_iface)
1406 return count;
1407
1408 rc = ipw_prom_alloc(priv);
1409 if (!rc)
1410 rtap_iface = 1;
1411 break;
1412
1413 default:
1414 return -EINVAL;
1415 }
1416
1417 if (rc) {
1418 IPW_ERROR("Failed to register promiscuous network "
1419 "device (error %d).\n", rc);
1420 }
1421
1422 return count;
1423}
1424
1425static ssize_t show_rtap_iface(struct device *d,
1426 struct device_attribute *attr,
1427 char *buf)
1428{
1429 struct ipw_priv *priv = dev_get_drvdata(d);
1430 if (rtap_iface)
1431 return sprintf(buf, "%s", priv->prom_net_dev->name);
1432 else {
1433 buf[0] = '-';
1434 buf[1] = '1';
1435 buf[2] = '\0';
1436 return 3;
1437 }
1438}
1439
1440static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1441 store_rtap_iface);
1442
1443static ssize_t store_rtap_filter(struct device *d,
1444 struct device_attribute *attr,
1445 const char *buf, size_t count)
1446{
1447 struct ipw_priv *priv = dev_get_drvdata(d);
1448
1449 if (!priv->prom_priv) {
1450 IPW_ERROR("Attempting to set filter without "
1451 "rtap_iface enabled.\n");
1452 return -EPERM;
1453 }
1454
1455 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1456
1457 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1458 BIT_ARG16(priv->prom_priv->filter));
1459
1460 return count;
1461}
1462
1463static ssize_t show_rtap_filter(struct device *d,
1464 struct device_attribute *attr,
1465 char *buf)
1466{
1467 struct ipw_priv *priv = dev_get_drvdata(d);
1468 return sprintf(buf, "0x%04X",
1469 priv->prom_priv ? priv->prom_priv->filter : 0);
1470}
1471
1472static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1473 store_rtap_filter);
1474#endif
1475
James Ketrenosa613bff2005-08-24 21:43:11 -05001476static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1477 char *buf)
1478{
1479 struct ipw_priv *priv = dev_get_drvdata(d);
1480 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1481}
1482
1483static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1484 const char *buf, size_t count)
1485{
1486 struct ipw_priv *priv = dev_get_drvdata(d);
1487 struct net_device *dev = priv->net_dev;
1488 char buffer[] = "00000000";
1489 unsigned long len =
1490 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1491 unsigned long val;
1492 char *p = buffer;
1493
1494 IPW_DEBUG_INFO("enter\n");
1495
1496 strncpy(buffer, buf, len);
1497 buffer[len] = 0;
1498
1499 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1500 p++;
1501 if (p[0] == 'x' || p[0] == 'X')
1502 p++;
1503 val = simple_strtoul(p, &p, 16);
1504 } else
1505 val = simple_strtoul(p, &p, 10);
1506 if (p == buffer) {
1507 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1508 } else {
1509 priv->ieee->scan_age = val;
1510 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1511 }
1512
1513 IPW_DEBUG_INFO("exit\n");
1514 return len;
1515}
1516
1517static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1518
1519static ssize_t show_led(struct device *d, struct device_attribute *attr,
1520 char *buf)
1521{
1522 struct ipw_priv *priv = dev_get_drvdata(d);
1523 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1524}
1525
1526static ssize_t store_led(struct device *d, struct device_attribute *attr,
1527 const char *buf, size_t count)
1528{
1529 struct ipw_priv *priv = dev_get_drvdata(d);
1530
1531 IPW_DEBUG_INFO("enter\n");
1532
1533 if (count == 0)
1534 return 0;
1535
1536 if (*buf == 0) {
1537 IPW_DEBUG_LED("Disabling LED control.\n");
1538 priv->config |= CFG_NO_LED;
1539 ipw_led_shutdown(priv);
1540 } else {
1541 IPW_DEBUG_LED("Enabling LED control.\n");
1542 priv->config &= ~CFG_NO_LED;
1543 ipw_led_init(priv);
1544 }
1545
1546 IPW_DEBUG_INFO("exit\n");
1547 return count;
1548}
1549
1550static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1551
Andrew Mortonad3fee52005-06-20 14:30:36 -07001552static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001553 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001554{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001555 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001556 return sprintf(buf, "0x%08x\n", (int)p->status);
1557}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001558
James Ketrenos43f66a62005-03-25 12:31:53 -06001559static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1560
Andrew Mortonad3fee52005-06-20 14:30:36 -07001561static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1562 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001563{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001564 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001565 return sprintf(buf, "0x%08x\n", (int)p->config);
1566}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567
James Ketrenos43f66a62005-03-25 12:31:53 -06001568static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1569
Andrew Mortonad3fee52005-06-20 14:30:36 -07001570static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001571 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001572{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001573 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001574 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001575}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001576
James Ketrenos43f66a62005-03-25 12:31:53 -06001577static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1578
Andrew Mortonad3fee52005-06-20 14:30:36 -07001579static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001580 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001581{
1582 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001583 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001584
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001585 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001586 return 0;
1587
1588 return sprintf(buf, "0x%08x\n", tmp);
1589}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001590
1591static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001592
Andrew Mortonad3fee52005-06-20 14:30:36 -07001593static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1594 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001595{
1596 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001597 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001598
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001599 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001600 return 0;
1601
1602 return sprintf(buf, "0x%08x\n", tmp);
1603}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001604
1605static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001606
1607/*
1608 * Add a device attribute to view/control the delay between eeprom
1609 * operations.
1610 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001611static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001612 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001613{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001614 struct ipw_priv *p = dev_get_drvdata(d);
1615 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001616 return sprintf(buf, "%i\n", n);
1617}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001618static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001619 struct device_attribute *attr,
1620 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001621{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001622 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001623 sscanf(buf, "%i", &p->eeprom_delay);
1624 return strnlen(buf, count);
1625}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001626
1627static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1628 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001629
Andrew Mortonad3fee52005-06-20 14:30:36 -07001630static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001632{
1633 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001634 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001635
James Ketrenosb095c382005-08-24 22:04:42 -05001636 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001637 return sprintf(buf, "0x%08x\n", reg);
1638}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001639static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001640 struct device_attribute *attr,
1641 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001642{
1643 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001644 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001645
1646 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001647 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001648 return strnlen(buf, count);
1649}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001650
1651static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1652 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001653
Andrew Mortonad3fee52005-06-20 14:30:36 -07001654static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001655 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001656{
1657 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001658 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001659
1660 reg = ipw_read_reg32(p, 0x301100);
1661 return sprintf(buf, "0x%08x\n", reg);
1662}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001663static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001664 struct device_attribute *attr,
1665 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001666{
1667 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001668 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001669
1670 sscanf(buf, "%x", &reg);
1671 ipw_write_reg32(p, 0x301100, reg);
1672 return strnlen(buf, count);
1673}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001674
1675static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1676 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001677
Andrew Mortonad3fee52005-06-20 14:30:36 -07001678static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001679 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001680{
1681 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001682 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001683
Jeff Garzikbf794512005-07-31 13:07:26 -04001684 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001685 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001686 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001687 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001688
James Ketrenos43f66a62005-03-25 12:31:53 -06001689 return sprintf(buf, "0x%08x\n", reg);
1690}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001691static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001692 struct device_attribute *attr,
1693 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001694{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001695 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001696
1697 sscanf(buf, "%x", &priv->indirect_dword);
1698 priv->status |= STATUS_INDIRECT_DWORD;
1699 return strnlen(buf, count);
1700}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001701
1702static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1703 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001704
Andrew Mortonad3fee52005-06-20 14:30:36 -07001705static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001706 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001707{
1708 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001709 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001710
Jeff Garzikbf794512005-07-31 13:07:26 -04001711 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001712 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001713 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001714 reg = 0;
1715
1716 return sprintf(buf, "0x%02x\n", reg);
1717}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001718static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001719 struct device_attribute *attr,
1720 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001721{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001722 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001723
1724 sscanf(buf, "%x", &priv->indirect_byte);
1725 priv->status |= STATUS_INDIRECT_BYTE;
1726 return strnlen(buf, count);
1727}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001728
1729static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001730 show_indirect_byte, store_indirect_byte);
1731
Andrew Mortonad3fee52005-06-20 14:30:36 -07001732static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001733 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001734{
1735 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001736 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001737
Jeff Garzikbf794512005-07-31 13:07:26 -04001738 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001740 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001741 reg = 0;
1742
1743 return sprintf(buf, "0x%08x\n", reg);
1744}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001745static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001746 struct device_attribute *attr,
1747 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001748{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001749 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001750
1751 sscanf(buf, "%x", &priv->direct_dword);
1752 priv->status |= STATUS_DIRECT_DWORD;
1753 return strnlen(buf, count);
1754}
James Ketrenos43f66a62005-03-25 12:31:53 -06001755
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001756static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1757 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001758
Arjan van de Ven858119e2006-01-14 13:20:43 -08001759static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001760{
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001761 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001762 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001763 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1764 } else {
James Ketrenos43f66a62005-03-25 12:31:53 -06001765 priv->status &= ~STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05001766 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1767 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001768
1769 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1770}
1771
Andrew Mortonad3fee52005-06-20 14:30:36 -07001772static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001773 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001774{
1775 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001776 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001777 2 - HW based RF kill active
1778 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001779 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001780 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001781 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001782 return sprintf(buf, "%i\n", val);
1783}
1784
1785static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1786{
Jeff Garzikbf794512005-07-31 13:07:26 -04001787 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001788 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001789 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001790
1791 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1792 disable_radio ? "OFF" : "ON");
1793
1794 if (disable_radio) {
1795 priv->status |= STATUS_RF_KILL_SW;
1796
Dan Williams0b531672007-10-09 13:55:24 -04001797 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001798 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04001799 cancel_delayed_work(&priv->request_direct_scan);
1800 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04001801 cancel_delayed_work(&priv->scan_event);
1802 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001803 queue_work(priv->workqueue, &priv->down);
1804 } else {
1805 priv->status &= ~STATUS_RF_KILL_SW;
1806 if (rf_kill_active(priv)) {
1807 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1808 "disabled by HW switch\n");
1809 /* Make sure the RF_KILL check timer is running */
1810 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001811 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001812 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001813 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001814 queue_work(priv->workqueue, &priv->up);
1815 }
1816
1817 return 1;
1818}
1819
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001820static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1821 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001822{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001823 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001824
James Ketrenos43f66a62005-03-25 12:31:53 -06001825 ipw_radio_kill_sw(priv, buf[0] == '1');
1826
1827 return count;
1828}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001829
1830static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001831
James Ketrenosb095c382005-08-24 22:04:42 -05001832static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1833 char *buf)
1834{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001835 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001836 int pos = 0, len = 0;
1837 if (priv->config & CFG_SPEED_SCAN) {
1838 while (priv->speed_scan[pos] != 0)
1839 len += sprintf(&buf[len], "%d ",
1840 priv->speed_scan[pos++]);
1841 return len + sprintf(&buf[len], "\n");
1842 }
1843
1844 return sprintf(buf, "0\n");
1845}
1846
1847static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1848 const char *buf, size_t count)
1849{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001850 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001851 int channel, pos = 0;
1852 const char *p = buf;
1853
1854 /* list of space separated channels to scan, optionally ending with 0 */
1855 while ((channel = simple_strtol(p, NULL, 0))) {
1856 if (pos == MAX_SPEED_SCAN - 1) {
1857 priv->speed_scan[pos] = 0;
1858 break;
1859 }
1860
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001861 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001862 priv->speed_scan[pos++] = channel;
1863 else
1864 IPW_WARNING("Skipping invalid channel request: %d\n",
1865 channel);
1866 p = strchr(p, ' ');
1867 if (!p)
1868 break;
1869 while (*p == ' ' || *p == '\t')
1870 p++;
1871 }
1872
1873 if (pos == 0)
1874 priv->config &= ~CFG_SPEED_SCAN;
1875 else {
1876 priv->speed_scan_pos = 0;
1877 priv->config |= CFG_SPEED_SCAN;
1878 }
1879
1880 return count;
1881}
1882
1883static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1884 store_speed_scan);
1885
1886static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1887 char *buf)
1888{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001889 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001890 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1891}
1892
1893static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1894 const char *buf, size_t count)
1895{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001896 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001897 if (buf[0] == '1')
1898 priv->config |= CFG_NET_STATS;
1899 else
1900 priv->config &= ~CFG_NET_STATS;
1901
1902 return count;
1903}
1904
James Ketrenosafbf30a2005-08-25 00:05:33 -05001905static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1906 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001907
Zhu Yi375dd242007-02-14 16:04:24 +08001908static ssize_t show_channels(struct device *d,
1909 struct device_attribute *attr,
1910 char *buf)
1911{
1912 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001913 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001914 int len = 0, i;
1915
1916 len = sprintf(&buf[len],
1917 "Displaying %d channels in 2.4Ghz band "
1918 "(802.11bg):\n", geo->bg_channels);
1919
1920 for (i = 0; i < geo->bg_channels; i++) {
1921 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1922 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001923 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001924 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001925 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1926 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001927 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001928 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001929 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001930 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001931 "B" : "B/G");
1932 }
1933
1934 len += sprintf(&buf[len],
1935 "Displaying %d channels in 5.2Ghz band "
1936 "(802.11a):\n", geo->a_channels);
1937 for (i = 0; i < geo->a_channels; i++) {
1938 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1939 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001940 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001941 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001942 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1943 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001944 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001945 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001946 "passive only" : "active/passive");
1947 }
1948
1949 return len;
1950}
1951
1952static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1953
James Ketrenosea2b26e2005-08-24 21:25:16 -05001954static void notify_wx_assoc_event(struct ipw_priv *priv)
1955{
1956 union iwreq_data wrqu;
1957 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1958 if (priv->status & STATUS_ASSOCIATED)
1959 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1960 else
1961 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1962 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1963}
1964
James Ketrenos43f66a62005-03-25 12:31:53 -06001965static void ipw_irq_tasklet(struct ipw_priv *priv)
1966{
1967 u32 inta, inta_mask, handled = 0;
1968 unsigned long flags;
1969 int rc = 0;
1970
Zhu Yi89c318e2006-06-08 22:19:49 -07001971 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001972
James Ketrenosb095c382005-08-24 22:04:42 -05001973 inta = ipw_read32(priv, IPW_INTA_RW);
1974 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1975 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001976
1977 /* Add any cached INTA values that need to be handled */
1978 inta |= priv->isr_inta;
1979
Zhu Yi89c318e2006-06-08 22:19:49 -07001980 spin_unlock_irqrestore(&priv->irq_lock, flags);
1981
1982 spin_lock_irqsave(&priv->lock, flags);
1983
James Ketrenos43f66a62005-03-25 12:31:53 -06001984 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001985 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001986 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001987 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001988 }
1989
James Ketrenosb095c382005-08-24 22:04:42 -05001990 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001991 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001992 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001993 priv->status &= ~STATUS_HCMD_ACTIVE;
1994 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001995 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 }
1997
James Ketrenosb095c382005-08-24 22:04:42 -05001998 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002000 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05002001 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06002002 }
2003
James Ketrenosb095c382005-08-24 22:04:42 -05002004 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002005 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002006 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05002007 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
James Ketrenosb095c382005-08-24 22:04:42 -05002010 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002011 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002012 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05002013 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002014 }
2015
James Ketrenosb095c382005-08-24 22:04:42 -05002016 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002017 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002018 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05002019 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 }
2021
James Ketrenosb095c382005-08-24 22:04:42 -05002022 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002024 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002025 }
2026
James Ketrenosb095c382005-08-24 22:04:42 -05002027 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002028 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002029 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002030 }
2031
James Ketrenosb095c382005-08-24 22:04:42 -05002032 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002033 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002034 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002035 }
2036
James Ketrenosb095c382005-08-24 22:04:42 -05002037 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002038 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002039 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002040 }
2041
James Ketrenosb095c382005-08-24 22:04:42 -05002042 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002043 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002044 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002045 }
2046
James Ketrenosb095c382005-08-24 22:04:42 -05002047 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2049 priv->status |= STATUS_RF_KILL_HW;
Matthew Garrett25f94ae2009-11-11 14:36:31 -05002050 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
James Ketrenos43f66a62005-03-25 12:31:53 -06002051 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002052 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002053 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002054 cancel_delayed_work(&priv->request_direct_scan);
2055 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002056 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002057 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002058 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002059 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002060 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002061
James Ketrenosb095c382005-08-24 22:04:42 -05002062 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002063 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002064 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002065 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002066 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2067 struct ipw_fw_error *error =
2068 ipw_alloc_error_log(priv);
2069 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002070 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002071 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002072 } else {
2073 priv->error = ipw_alloc_error_log(priv);
2074 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002075 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002076 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002077 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2078 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002079 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2080 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002081 }
2082
James Ketrenosb095c382005-08-24 22:04:42 -05002083 /* XXX: If hardware encryption is for WPA/WPA2,
2084 * we have to notify the supplicant. */
2085 if (priv->ieee->sec.encrypt) {
2086 priv->status &= ~STATUS_ASSOCIATED;
2087 notify_wx_assoc_event(priv);
2088 }
2089
2090 /* Keep the restart process from trying to send host
2091 * commands by clearing the INIT status bit */
2092 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002093
2094 /* Cancel currently queued command. */
2095 priv->status &= ~STATUS_HCMD_ACTIVE;
2096 wake_up_interruptible(&priv->wait_command_queue);
2097
James Ketrenos43f66a62005-03-25 12:31:53 -06002098 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002099 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002100 }
2101
James Ketrenosb095c382005-08-24 22:04:42 -05002102 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002103 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002104 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002105 }
2106
2107 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002108 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002109 }
2110
Zhu Yi89c318e2006-06-08 22:19:49 -07002111 spin_unlock_irqrestore(&priv->lock, flags);
2112
James Ketrenos43f66a62005-03-25 12:31:53 -06002113 /* enable all interrupts */
2114 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002115}
Jeff Garzikbf794512005-07-31 13:07:26 -04002116
James Ketrenos43f66a62005-03-25 12:31:53 -06002117#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2118static char *get_cmd_string(u8 cmd)
2119{
2120 switch (cmd) {
2121 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002122 IPW_CMD(POWER_DOWN);
2123 IPW_CMD(SYSTEM_CONFIG);
2124 IPW_CMD(MULTICAST_ADDRESS);
2125 IPW_CMD(SSID);
2126 IPW_CMD(ADAPTER_ADDRESS);
2127 IPW_CMD(PORT_TYPE);
2128 IPW_CMD(RTS_THRESHOLD);
2129 IPW_CMD(FRAG_THRESHOLD);
2130 IPW_CMD(POWER_MODE);
2131 IPW_CMD(WEP_KEY);
2132 IPW_CMD(TGI_TX_KEY);
2133 IPW_CMD(SCAN_REQUEST);
2134 IPW_CMD(SCAN_REQUEST_EXT);
2135 IPW_CMD(ASSOCIATE);
2136 IPW_CMD(SUPPORTED_RATES);
2137 IPW_CMD(SCAN_ABORT);
2138 IPW_CMD(TX_FLUSH);
2139 IPW_CMD(QOS_PARAMETERS);
2140 IPW_CMD(DINO_CONFIG);
2141 IPW_CMD(RSN_CAPABILITIES);
2142 IPW_CMD(RX_KEY);
2143 IPW_CMD(CARD_DISABLE);
2144 IPW_CMD(SEED_NUMBER);
2145 IPW_CMD(TX_POWER);
2146 IPW_CMD(COUNTRY_INFO);
2147 IPW_CMD(AIRONET_INFO);
2148 IPW_CMD(AP_TX_POWER);
2149 IPW_CMD(CCKM_INFO);
2150 IPW_CMD(CCX_VER_INFO);
2151 IPW_CMD(SET_CALIBRATION);
2152 IPW_CMD(SENSITIVITY_CALIB);
2153 IPW_CMD(RETRY_LIMIT);
2154 IPW_CMD(IPW_PRE_POWER_DOWN);
2155 IPW_CMD(VAP_BEACON_TEMPLATE);
2156 IPW_CMD(VAP_DTIM_PERIOD);
2157 IPW_CMD(EXT_SUPPORTED_RATES);
2158 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2159 IPW_CMD(VAP_QUIET_INTERVALS);
2160 IPW_CMD(VAP_CHANNEL_SWITCH);
2161 IPW_CMD(VAP_MANDATORY_CHANNELS);
2162 IPW_CMD(VAP_CELL_PWR_LIMIT);
2163 IPW_CMD(VAP_CF_PARAM_SET);
2164 IPW_CMD(VAP_SET_BEACONING_STATE);
2165 IPW_CMD(MEASUREMENT);
2166 IPW_CMD(POWER_CAPABILITY);
2167 IPW_CMD(SUPPORTED_CHANNELS);
2168 IPW_CMD(TPC_REPORT);
2169 IPW_CMD(WME_INFO);
2170 IPW_CMD(PRODUCTION_COMMAND);
2171 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002172 return "UNKNOWN";
2173 }
2174}
James Ketrenos43f66a62005-03-25 12:31:53 -06002175
2176#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002177
2178static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002179{
2180 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002181 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002182
James Ketrenosa613bff2005-08-24 21:43:11 -05002183 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002184 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002185 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2186 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002187 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002188 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002189 }
2190
2191 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002192
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002193 if (priv->cmdlog) {
2194 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2195 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2196 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2197 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2198 cmd->len);
2199 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2200 }
2201
James Ketrenosb095c382005-08-24 22:04:42 -05002202 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2203 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2204 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002205
2206#ifndef DEBUG_CMD_WEP_KEY
2207 if (cmd->cmd == IPW_CMD_WEP_KEY)
2208 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2209 else
2210#endif
2211 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2212
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002213 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002214 if (rc) {
2215 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002216 IPW_ERROR("Failed to send %s: Reason %d\n",
2217 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002218 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002219 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002220 }
2221 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002222
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002223 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2224 !(priv->
2225 status & STATUS_HCMD_ACTIVE),
2226 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002227 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002228 spin_lock_irqsave(&priv->lock, flags);
2229 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002230 IPW_ERROR("Failed to send %s: Command timed out.\n",
2231 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002232 priv->status &= ~STATUS_HCMD_ACTIVE;
2233 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002234 rc = -EIO;
2235 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002236 }
2237 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002238 } else
2239 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002240
James Ketrenosb095c382005-08-24 22:04:42 -05002241 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002242 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2243 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002244 rc = -EIO;
2245 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002246 }
2247
Zhu Yi2638bc32006-01-24 16:37:52 +08002248 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002249 if (priv->cmdlog) {
2250 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2251 priv->cmdlog_pos %= priv->cmdlog_len;
2252 }
2253 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002254}
2255
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002256static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002257{
2258 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002259 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002260 };
2261
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002262 return __ipw_send_cmd(priv, &cmd);
2263}
2264
2265static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2266 void *data)
2267{
2268 struct host_cmd cmd = {
2269 .cmd = command,
2270 .len = len,
2271 .param = data,
2272 };
2273
2274 return __ipw_send_cmd(priv, &cmd);
2275}
2276
2277static int ipw_send_host_complete(struct ipw_priv *priv)
2278{
James Ketrenos43f66a62005-03-25 12:31:53 -06002279 if (!priv) {
2280 IPW_ERROR("Invalid args\n");
2281 return -1;
2282 }
2283
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002284 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002285}
2286
Zhu Yid685b8c2006-04-13 17:20:27 +08002287static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002288{
Zhu Yid685b8c2006-04-13 17:20:27 +08002289 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2290 sizeof(priv->sys_config),
2291 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002292}
2293
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002294static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002295{
James Ketrenos43f66a62005-03-25 12:31:53 -06002296 if (!priv || !ssid) {
2297 IPW_ERROR("Invalid args\n");
2298 return -1;
2299 }
2300
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002301 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002302 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002303}
2304
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002305static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002306{
James Ketrenos43f66a62005-03-25 12:31:53 -06002307 if (!priv || !mac) {
2308 IPW_ERROR("Invalid args\n");
2309 return -1;
2310 }
2311
Johannes Berge1749612008-10-27 15:59:26 -07002312 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2313 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002314
Zhu Yi2638bc32006-01-24 16:37:52 +08002315 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002316}
2317
James Ketrenosa613bff2005-08-24 21:43:11 -05002318/*
2319 * NOTE: This must be executed from our workqueue as it results in udelay
2320 * being called which may corrupt the keyboard if executed on default
2321 * workqueue
2322 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002323static void ipw_adapter_restart(void *adapter)
2324{
2325 struct ipw_priv *priv = adapter;
2326
2327 if (priv->status & STATUS_RF_KILL_MASK)
2328 return;
2329
2330 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002331
2332 if (priv->assoc_network &&
2333 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2334 ipw_remove_current_network(priv);
2335
James Ketrenos43f66a62005-03-25 12:31:53 -06002336 if (ipw_up(priv)) {
2337 IPW_ERROR("Failed to up device\n");
2338 return;
2339 }
2340}
2341
David Howellsc4028952006-11-22 14:57:56 +00002342static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002343{
David Howellsc4028952006-11-22 14:57:56 +00002344 struct ipw_priv *priv =
2345 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002346 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002347 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002348 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002349}
2350
Zhu Yie65054b2010-03-30 09:36:16 +08002351static void ipw_abort_scan(struct ipw_priv *priv);
2352
2353#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
James Ketrenos43f66a62005-03-25 12:31:53 -06002354
2355static void ipw_scan_check(void *data)
2356{
2357 struct ipw_priv *priv = data;
Zhu Yie65054b2010-03-30 09:36:16 +08002358
2359 if (priv->status & STATUS_SCAN_ABORTING) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002360 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002361 "adapter after (%dms).\n",
2362 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002363 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yie65054b2010-03-30 09:36:16 +08002364 } else if (priv->status & STATUS_SCANNING) {
2365 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2366 "after (%dms).\n",
2367 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2368 ipw_abort_scan(priv);
2369 queue_delayed_work(priv->workqueue, &priv->scan_check, HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002370 }
2371}
2372
David Howellsc4028952006-11-22 14:57:56 +00002373static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002374{
David Howellsc4028952006-11-22 14:57:56 +00002375 struct ipw_priv *priv =
2376 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002377 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002378 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002379 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002380}
2381
James Ketrenos43f66a62005-03-25 12:31:53 -06002382static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2383 struct ipw_scan_request_ext *request)
2384{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002385 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002386 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002387}
2388
2389static int ipw_send_scan_abort(struct ipw_priv *priv)
2390{
James Ketrenos43f66a62005-03-25 12:31:53 -06002391 if (!priv) {
2392 IPW_ERROR("Invalid args\n");
2393 return -1;
2394 }
2395
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002396 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002397}
2398
2399static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2400{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002401 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002402 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002403 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002404
2405 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002406 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002407}
2408
2409static int ipw_send_associate(struct ipw_priv *priv,
2410 struct ipw_associate *associate)
2411{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002412 if (!priv || !associate) {
2413 IPW_ERROR("Invalid args\n");
2414 return -1;
2415 }
2416
Al Viro5b5e8072007-12-27 01:54:06 -05002417 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2418 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002419}
2420
2421static int ipw_send_supported_rates(struct ipw_priv *priv,
2422 struct ipw_supported_rates *rates)
2423{
James Ketrenos43f66a62005-03-25 12:31:53 -06002424 if (!priv || !rates) {
2425 IPW_ERROR("Invalid args\n");
2426 return -1;
2427 }
2428
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002429 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002430 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002431}
2432
2433static int ipw_set_random_seed(struct ipw_priv *priv)
2434{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002435 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002436
2437 if (!priv) {
2438 IPW_ERROR("Invalid args\n");
2439 return -1;
2440 }
2441
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002442 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002443
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002444 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002445}
2446
James Ketrenos43f66a62005-03-25 12:31:53 -06002447static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2448{
Al Viroe62e1ee2007-12-27 01:36:46 -05002449 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002450 if (!priv) {
2451 IPW_ERROR("Invalid args\n");
2452 return -1;
2453 }
2454
Al Viroe62e1ee2007-12-27 01:36:46 -05002455 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002456}
James Ketrenos43f66a62005-03-25 12:31:53 -06002457
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002458static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002459{
James Ketrenos43f66a62005-03-25 12:31:53 -06002460 if (!priv || !power) {
2461 IPW_ERROR("Invalid args\n");
2462 return -1;
2463 }
2464
Zhu Yi2638bc32006-01-24 16:37:52 +08002465 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002466}
James Ketrenos43f66a62005-03-25 12:31:53 -06002467
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002468static int ipw_set_tx_power(struct ipw_priv *priv)
2469{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002470 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002471 struct ipw_tx_power tx_power;
2472 s8 max_power;
2473 int i;
2474
2475 memset(&tx_power, 0, sizeof(tx_power));
2476
2477 /* configure device for 'G' band */
2478 tx_power.ieee_mode = IPW_G_MODE;
2479 tx_power.num_channels = geo->bg_channels;
2480 for (i = 0; i < geo->bg_channels; i++) {
2481 max_power = geo->bg[i].max_power;
2482 tx_power.channels_tx_power[i].channel_number =
2483 geo->bg[i].channel;
2484 tx_power.channels_tx_power[i].tx_power = max_power ?
2485 min(max_power, priv->tx_power) : priv->tx_power;
2486 }
2487 if (ipw_send_tx_power(priv, &tx_power))
2488 return -EIO;
2489
2490 /* configure device to also handle 'B' band */
2491 tx_power.ieee_mode = IPW_B_MODE;
2492 if (ipw_send_tx_power(priv, &tx_power))
2493 return -EIO;
2494
2495 /* configure device to also handle 'A' band */
2496 if (priv->ieee->abg_true) {
2497 tx_power.ieee_mode = IPW_A_MODE;
2498 tx_power.num_channels = geo->a_channels;
2499 for (i = 0; i < tx_power.num_channels; i++) {
2500 max_power = geo->a[i].max_power;
2501 tx_power.channels_tx_power[i].channel_number =
2502 geo->a[i].channel;
2503 tx_power.channels_tx_power[i].tx_power = max_power ?
2504 min(max_power, priv->tx_power) : priv->tx_power;
2505 }
2506 if (ipw_send_tx_power(priv, &tx_power))
2507 return -EIO;
2508 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 return 0;
2510}
2511
2512static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2513{
2514 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002515 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002516 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002517
2518 if (!priv) {
2519 IPW_ERROR("Invalid args\n");
2520 return -1;
2521 }
2522
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002523 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2524 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002525}
2526
2527static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2528{
2529 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002530 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002531 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002532
2533 if (!priv) {
2534 IPW_ERROR("Invalid args\n");
2535 return -1;
2536 }
2537
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002538 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2539 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002540}
2541
2542static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2543{
Al Viroe62e1ee2007-12-27 01:36:46 -05002544 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002545
2546 if (!priv) {
2547 IPW_ERROR("Invalid args\n");
2548 return -1;
2549 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002550
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 /* If on battery, set to 3, if AC set to CAM, else user
2552 * level */
2553 switch (mode) {
2554 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002555 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002556 break;
2557 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002558 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002559 break;
2560 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002561 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002562 break;
2563 }
2564
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002565 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002566 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002567}
2568
James Ketrenosafbf30a2005-08-25 00:05:33 -05002569static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2570{
2571 struct ipw_retry_limit retry_limit = {
2572 .short_retry_limit = slimit,
2573 .long_retry_limit = llimit
2574 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002575
2576 if (!priv) {
2577 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002578 return -1;
2579 }
2580
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002581 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002582 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002583}
2584
2585/*
2586 * The IPW device contains a Microwire compatible EEPROM that stores
2587 * various data like the MAC address. Usually the firmware has exclusive
2588 * access to the eeprom, but during device initialization (before the
2589 * device driver has sent the HostComplete command to the firmware) the
2590 * device driver has read access to the EEPROM by way of indirect addressing
2591 * through a couple of memory mapped registers.
2592 *
2593 * The following is a simplified implementation for pulling data out of the
2594 * the eeprom, along with some helper functions to find information in
2595 * the per device private data's copy of the eeprom.
2596 *
2597 * NOTE: To better understand how these functions work (i.e what is a chip
2598 * select and why do have to keep driving the eeprom clock?), read
2599 * just about any data sheet for a Microwire compatible EEPROM.
2600 */
2601
2602/* write a 32 bit value into the indirect accessor register */
2603static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2604{
2605 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002606
James Ketrenos43f66a62005-03-25 12:31:53 -06002607 /* the eeprom requires some time to complete the operation */
2608 udelay(p->eeprom_delay);
2609
2610 return;
2611}
2612
2613/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002614static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002615{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002616 eeprom_write_reg(priv, 0);
2617 eeprom_write_reg(priv, EEPROM_BIT_CS);
2618 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2619 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002620}
2621
2622/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002623static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002624{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625 eeprom_write_reg(priv, EEPROM_BIT_CS);
2626 eeprom_write_reg(priv, 0);
2627 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002628}
2629
2630/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002631static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002632{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002633 int d = (bit ? EEPROM_BIT_DI : 0);
2634 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2635 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002636}
2637
2638/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002639static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002640{
2641 int i;
2642
2643 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002644 eeprom_write_bit(priv, 1);
2645 eeprom_write_bit(priv, op & 2);
2646 eeprom_write_bit(priv, op & 1);
2647 for (i = 7; i >= 0; i--) {
2648 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002649 }
2650}
2651
2652/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002653static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002654{
2655 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002656 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002657
James Ketrenos43f66a62005-03-25 12:31:53 -06002658 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002660
2661 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002662 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002663
2664 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002665 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002666 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002667 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2668 eeprom_write_reg(priv, EEPROM_BIT_CS);
2669 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2670 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002672
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002674 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002675 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002676
James Ketrenos43f66a62005-03-25 12:31:53 -06002677 return r;
2678}
2679
2680/* helper function for pulling the mac address out of the private */
2681/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002682static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002683{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002684 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002685}
2686
2687/*
2688 * Either the device driver (i.e. the host) or the firmware can
2689 * load eeprom data into the designated region in SRAM. If neither
2690 * happens then the FW will shutdown with a fatal error.
2691 *
2692 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2693 * bit needs region of shared SRAM needs to be non-zero.
2694 */
2695static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2696{
2697 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002698 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002699
James Ketrenos43f66a62005-03-25 12:31:53 -06002700 IPW_DEBUG_TRACE(">>\n");
2701
2702 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002703 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002704 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002705
Jeff Garzikbf794512005-07-31 13:07:26 -04002706 /*
2707 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002708 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002709 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002710 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002711 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002712 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2713
2714 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002715 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002716 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002717
2718 /* Do not load eeprom data on fatal error or suspend */
2719 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2720 } else {
2721 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2722
2723 /* Load eeprom data on fatal error or suspend */
2724 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2725 }
2726
2727 IPW_DEBUG_TRACE("<<\n");
2728}
2729
Arjan van de Ven858119e2006-01-14 13:20:43 -08002730static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002731{
2732 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002733 if (!count)
2734 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002735 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002736 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002737 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002738}
2739
2740static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2741{
James Ketrenosb095c382005-08-24 22:04:42 -05002742 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002743 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002744 sizeof(struct command_block));
2745}
2746
2747static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002748{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
Frans Pop9fd1ea42010-03-24 19:46:31 +01002750 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002751
James Ketrenos43f66a62005-03-25 12:31:53 -06002752 /* Start the dma */
2753 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002754
James Ketrenos43f66a62005-03-25 12:31:53 -06002755 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002756 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002757
Frans Pop9fd1ea42010-03-24 19:46:31 +01002758 IPW_DEBUG_FW("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002759 return 0;
2760}
2761
2762static void ipw_fw_dma_abort(struct ipw_priv *priv)
2763{
2764 u32 control = 0;
2765
2766 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002767
Pavel Machek67fd6b42006-07-11 15:34:05 +02002768 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002769 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002770 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002771 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002772
Frans Pop9fd1ea42010-03-24 19:46:31 +01002773 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002774}
2775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2777 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002778{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002779 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002780 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002781 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 IPW_DEBUG_FW(">> :\n");
2783
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002784 ipw_write_indirect(priv, address, (u8 *) cb,
2785 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002786
2787 IPW_DEBUG_FW("<< :\n");
2788 return 0;
2789
2790}
2791
2792static int ipw_fw_dma_kick(struct ipw_priv *priv)
2793{
2794 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002795 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002796
2797 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002798
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800 ipw_fw_dma_write_command_block(priv, index,
2801 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002802
2803 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002804 ipw_clear_bit(priv, IPW_RESET_REG,
2805 IPW_RESET_REG_MASTER_DISABLED |
2806 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002807
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002808 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002809 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002810 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002811
2812 IPW_DEBUG_FW("<< :\n");
2813 return 0;
2814}
2815
2816static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2817{
2818 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002819 u32 register_value = 0;
2820 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
2822 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002823 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002824 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002825
2826 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002827 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002828 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002829
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002830 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002831 cb_fields_address = address;
2832 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002833 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002834
2835 cb_fields_address += sizeof(u32);
2836 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002837 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002838
2839 cb_fields_address += sizeof(u32);
2840 register_value = ipw_read_reg32(priv, cb_fields_address);
Frans Pop9fd1ea42010-03-24 19:46:31 +01002841 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002842 register_value);
2843
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 Status Field is 0x%x\n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002847
2848 IPW_DEBUG_FW(">> :\n");
2849}
2850
2851static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2852{
2853 u32 current_cb_address = 0;
2854 u32 current_cb_index = 0;
2855
2856 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002857 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002858
James Ketrenosb095c382005-08-24 22:04:42 -05002859 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002860 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002861
Frans Pop9fd1ea42010-03-24 19:46:31 +01002862 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002863 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002864
2865 IPW_DEBUG_FW(">> :\n");
2866 return current_cb_index;
2867
2868}
2869
2870static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2871 u32 src_address,
2872 u32 dest_address,
2873 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002874 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002875{
2876
Jeff Garzikbf794512005-07-31 13:07:26 -04002877 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002878 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2879 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002880 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002881 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002882
2883 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2884 src_address, dest_address, length);
2885
2886 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2887 return -1;
2888
2889 last_cb_element = priv->sram_desc.last_cb_index;
2890 cb = &priv->sram_desc.cb_list[last_cb_element];
2891 priv->sram_desc.last_cb_index++;
2892
2893 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002894 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002895 control |= CB_INT_ENABLED;
2896
2897 if (is_last)
2898 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002899
James Ketrenos43f66a62005-03-25 12:31:53 -06002900 control |= length;
2901
2902 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002903 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002904
2905 /* Copy the Source and Destination addresses */
2906 cb->dest_addr = dest_address;
2907 cb->source_addr = src_address;
2908
2909 /* Copy the Control Word last */
2910 cb->control = control;
2911
2912 return 0;
2913}
2914
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002915static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2916 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002917{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002918 int ret, i;
2919 u32 size;
2920
Frans Pop9fd1ea42010-03-24 19:46:31 +01002921 IPW_DEBUG_FW(">>\n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002922 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2923 nr, dest_address, len);
2924
2925 for (i = 0; i < nr; i++) {
2926 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2927 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2928 dest_address +
2929 i * CB_MAX_LENGTH, size,
2930 0, 0);
2931 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 IPW_DEBUG_FW_INFO(": Failed\n");
2933 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002934 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002935 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002936 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002937
Frans Pop9fd1ea42010-03-24 19:46:31 +01002938 IPW_DEBUG_FW("<<\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002939 return 0;
2940}
2941
2942static int ipw_fw_dma_wait(struct ipw_priv *priv)
2943{
Zhu Yi397ae122006-01-24 16:37:22 +08002944 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 u32 watchdog = 0;
2946
Frans Pop9fd1ea42010-03-24 19:46:31 +01002947 IPW_DEBUG_FW(">> :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002948
2949 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002950 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002951 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002952
2953 while (current_index < priv->sram_desc.last_cb_index) {
2954 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002955 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002956 current_index = ipw_fw_dma_command_block_index(priv);
2957
Zhu Yi397ae122006-01-24 16:37:22 +08002958 if (previous_index < current_index) {
2959 watchdog = 0;
2960 continue;
2961 }
2962 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002963 IPW_DEBUG_FW_INFO("Timeout\n");
2964 ipw_fw_dma_dump_command_block(priv);
2965 ipw_fw_dma_abort(priv);
2966 return -1;
2967 }
2968 }
2969
2970 ipw_fw_dma_abort(priv);
2971
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002972 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002973 ipw_set_bit(priv, IPW_RESET_REG,
2974 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002975
Frans Pop9fd1ea42010-03-24 19:46:31 +01002976 IPW_DEBUG_FW("<< dmaWaitSync\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002977 return 0;
2978}
2979
Jeff Garzikbf794512005-07-31 13:07:26 -04002980static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002981{
2982 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002983 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002984 unsigned long flags;
2985
2986 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002987 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002988 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002989 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2990 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002991 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002992 &priv->ieee->network_free_list);
2993 }
2994 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002995 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002996}
2997
2998/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002999 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 * Reads debug register from domain0.
3001 * If card is present, pre-defined value should
3002 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04003003 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003004 * @param priv
3005 * @return 1 if card is present, 0 otherwise
3006 */
3007static inline int ipw_alive(struct ipw_priv *priv)
3008{
3009 return ipw_read32(priv, 0x90) == 0xd55555d5;
3010}
3011
Zhu Yic7b6a672006-01-24 16:37:05 +08003012/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08003013static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06003014 int timeout)
3015{
3016 int i = 0;
3017
3018 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04003019 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06003020 return i;
3021 mdelay(10);
3022 i += 10;
3023 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04003024
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 return -ETIME;
3026}
3027
Jeff Garzikbf794512005-07-31 13:07:26 -04003028/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06003029 * the ipw hardware. It assumes the buffer has all the bits for the
3030 * image and the caller is handling the memory allocation and clean up.
3031 */
3032
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003033static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003034{
3035 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003036
Frans Pop9fd1ea42010-03-24 19:46:31 +01003037 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003038 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003039 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003040
Zhu Yic7b6a672006-01-24 16:37:05 +08003041 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003042 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3043 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003044 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003045 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003046 return -1;
3047 }
3048
3049 IPW_DEBUG_INFO("stop master %dms\n", rc);
3050
3051 return rc;
3052}
3053
3054static void ipw_arc_release(struct ipw_priv *priv)
3055{
Frans Pop9fd1ea42010-03-24 19:46:31 +01003056 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003057 mdelay(5);
3058
James Ketrenosb095c382005-08-24 22:04:42 -05003059 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003060
3061 /* no one knows timing, for safety add some delay */
3062 mdelay(5);
3063}
3064
James Ketrenos43f66a62005-03-25 12:31:53 -06003065struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003066 __le32 address;
3067 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003068};
3069
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003070static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003071{
3072 int rc = 0, i, addr;
3073 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003074 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003075
Al Viroe62e1ee2007-12-27 01:36:46 -05003076 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003077
Frans Pop9fd1ea42010-03-24 19:46:31 +01003078 IPW_DEBUG_TRACE(">>\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003079
3080 rc = ipw_stop_master(priv);
3081
3082 if (rc < 0)
3083 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003084
James Ketrenosb095c382005-08-24 22:04:42 -05003085 for (addr = IPW_SHARED_LOWER_BOUND;
3086 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003087 ipw_write32(priv, addr, 0);
3088 }
3089
3090 /* no ucode (yet) */
3091 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3092 /* destroy DMA queues */
3093 /* reset sequence */
3094
James Ketrenosb095c382005-08-24 22:04:42 -05003095 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003096 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003097 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 mdelay(1);
3099
3100 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003101 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003102 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003103
James Ketrenosb095c382005-08-24 22:04:42 -05003104 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003105 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003106
James Ketrenos43f66a62005-03-25 12:31:53 -06003107 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003108 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3109 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003110 mdelay(1);
3111
3112 /* write ucode */
3113 /**
3114 * @bug
3115 * Do NOT set indirect address register once and then
3116 * store data to indirect data register in the loop.
3117 * It seems very reasonable, but in this case DINO do not
3118 * accept ucode. It is essential to set address each time.
3119 */
3120 /* load new ipw uCode */
3121 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003122 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003123 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003124
James Ketrenos43f66a62005-03-25 12:31:53 -06003125 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003126 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3127 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003128
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003129 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003130
3131 /* wait for alive response */
3132 for (i = 0; i < 100; i++) {
3133 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003134 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003135 if (cr & DINO_RXFIFO_DATA)
3136 break;
3137 mdelay(1);
3138 }
3139
3140 if (cr & DINO_RXFIFO_DATA) {
3141 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003142 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003143
3144 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003145 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003146 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003147 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003148 memcpy(&priv->dino_alive, response_buffer,
3149 sizeof(priv->dino_alive));
3150 if (priv->dino_alive.alive_command == 1
3151 && priv->dino_alive.ucode_valid == 1) {
3152 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003153 IPW_DEBUG_INFO
3154 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3155 "of %02d/%02d/%02d %02d:%02d\n",
3156 priv->dino_alive.software_revision,
3157 priv->dino_alive.software_revision,
3158 priv->dino_alive.device_identifier,
3159 priv->dino_alive.device_identifier,
3160 priv->dino_alive.time_stamp[0],
3161 priv->dino_alive.time_stamp[1],
3162 priv->dino_alive.time_stamp[2],
3163 priv->dino_alive.time_stamp[3],
3164 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003165 } else {
3166 IPW_DEBUG_INFO("Microcode is not alive\n");
3167 rc = -EINVAL;
3168 }
3169 } else {
3170 IPW_DEBUG_INFO("No alive response from DINO\n");
3171 rc = -ETIME;
3172 }
3173
3174 /* disable DINO, otherwise for some reason
3175 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003176 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003177
James Ketrenos43f66a62005-03-25 12:31:53 -06003178 return rc;
3179}
3180
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003181static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003182{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003183 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003184 int offset = 0;
3185 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003186 int total_nr = 0;
3187 int i;
3188 struct pci_pool *pool;
3189 u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL];
3190 dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL];
James Ketrenos43f66a62005-03-25 12:31:53 -06003191
Frans Pop9fd1ea42010-03-24 19:46:31 +01003192 IPW_DEBUG_TRACE("<< :\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003193
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003194 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3195 if (!pool) {
3196 IPW_ERROR("pci_pool_create failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003197 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003198 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003199
3200 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003201 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003202
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003203 /* the DMA is already ready this would be a bug. */
3204 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003205
3206 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003207 u32 chunk_len;
3208 u8 *start;
3209 int size;
3210 int nr = 0;
3211
James Ketrenos43f66a62005-03-25 12:31:53 -06003212 chunk = (struct fw_chunk *)(data + offset);
3213 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003214 chunk_len = le32_to_cpu(chunk->length);
3215 start = data + offset;
3216
3217 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3218 for (i = 0; i < nr; i++) {
3219 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3220 &phys[total_nr]);
3221 if (!virts[total_nr]) {
3222 ret = -ENOMEM;
3223 goto out;
3224 }
3225 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3226 CB_MAX_LENGTH);
3227 memcpy(virts[total_nr], start, size);
3228 start += size;
3229 total_nr++;
3230 /* We don't support fw chunk larger than 64*8K */
3231 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3232 }
3233
James Ketrenos43f66a62005-03-25 12:31:53 -06003234 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003235 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003236 * offeset*/
3237 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003238 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3239 nr, le32_to_cpu(chunk->address),
3240 chunk_len);
3241 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003242 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3243 goto out;
3244 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003245
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003246 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 } while (offset < len);
3248
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003249 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003250 ret = ipw_fw_dma_kick(priv);
3251 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 IPW_ERROR("dmaKick Failed\n");
3253 goto out;
3254 }
3255
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003256 ret = ipw_fw_dma_wait(priv);
3257 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003258 IPW_ERROR("dmaWaitSync Failed\n");
3259 goto out;
3260 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003261 out:
3262 for (i = 0; i < total_nr; i++)
3263 pci_pool_free(pool, virts[i], phys[i]);
3264
3265 pci_pool_destroy(pool);
3266
3267 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003268}
3269
3270/* stop nic */
3271static int ipw_stop_nic(struct ipw_priv *priv)
3272{
3273 int rc = 0;
3274
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003275 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003276 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003277
James Ketrenosb095c382005-08-24 22:04:42 -05003278 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3279 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003280 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003281 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003282 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003283 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003284
James Ketrenosb095c382005-08-24 22:04:42 -05003285 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003286
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 return rc;
3288}
3289
3290static void ipw_start_nic(struct ipw_priv *priv)
3291{
3292 IPW_DEBUG_TRACE(">>\n");
3293
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003294 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003295 ipw_clear_bit(priv, IPW_RESET_REG,
3296 IPW_RESET_REG_MASTER_DISABLED |
3297 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003298 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003299
James Ketrenos43f66a62005-03-25 12:31:53 -06003300 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003301 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3302 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003303
3304 IPW_DEBUG_TRACE("<<\n");
3305}
Jeff Garzikbf794512005-07-31 13:07:26 -04003306
James Ketrenos43f66a62005-03-25 12:31:53 -06003307static int ipw_init_nic(struct ipw_priv *priv)
3308{
3309 int rc;
3310
3311 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003312 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003313 /*prvHwInitNic */
3314 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003315 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003316
3317 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003318 ipw_write32(priv, IPW_READ_INT_REGISTER,
3319 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003320
3321 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003322 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3323 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003324 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003325 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3326
3327 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003328 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003329
3330 udelay(10);
3331
3332 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003333 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003334
3335 IPW_DEBUG_TRACE(">>\n");
3336 return 0;
3337}
3338
Jeff Garzikbf794512005-07-31 13:07:26 -04003339/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003340 * Probe is an ok place to call this from.
3341 */
3342static int ipw_reset_nic(struct ipw_priv *priv)
3343{
3344 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003345 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003346
3347 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003348
James Ketrenos43f66a62005-03-25 12:31:53 -06003349 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003350
James Ketrenosa613bff2005-08-24 21:43:11 -05003351 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003352 /* Clear the 'host command active' bit... */
3353 priv->status &= ~STATUS_HCMD_ACTIVE;
3354 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003355 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3356 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003357 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003358
3359 IPW_DEBUG_TRACE("<<\n");
3360 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003361}
James Ketrenos43f66a62005-03-25 12:31:53 -06003362
James Ketrenos9006ea72006-03-08 03:22:28 +08003363
3364struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003365 __le32 ver;
3366 __le32 boot_size;
3367 __le32 ucode_size;
3368 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003369 u8 data[0];
3370};
3371
Jeff Garzikbf794512005-07-31 13:07:26 -04003372static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003373 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003374{
James Ketrenos9006ea72006-03-08 03:22:28 +08003375 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003376 int rc;
3377
3378 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003379 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003380 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003381 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003382 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003383 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003384
James Ketrenos9006ea72006-03-08 03:22:28 +08003385 if ((*raw)->size < sizeof(*fw)) {
3386 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003387 return -EINVAL;
3388 }
3389
James Ketrenos9006ea72006-03-08 03:22:28 +08003390 fw = (void *)(*raw)->data;
3391
Zhu Yi0070f8c2006-04-13 17:20:12 +08003392 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3393 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003394 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3395 name, (*raw)->size);
3396 return -EINVAL;
3397 }
3398
3399 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003400 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003401 le32_to_cpu(fw->ver) >> 16,
3402 le32_to_cpu(fw->ver) & 0xff,
3403 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003404 return 0;
3405}
3406
James Ketrenosb095c382005-08-24 22:04:42 -05003407#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003408
Arjan van de Ven858119e2006-01-14 13:20:43 -08003409static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003410 struct ipw_rx_queue *rxq)
3411{
3412 unsigned long flags;
3413 int i;
3414
3415 spin_lock_irqsave(&rxq->lock, flags);
3416
3417 INIT_LIST_HEAD(&rxq->rx_free);
3418 INIT_LIST_HEAD(&rxq->rx_used);
3419
3420 /* Fill the rx_used queue with _all_ of the Rx buffers */
3421 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3422 /* In the reset function, these buffers may have been allocated
3423 * to an SKB, so we need to unmap and free potential storage */
3424 if (rxq->pool[i].skb != NULL) {
3425 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003426 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003427 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003428 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003429 }
3430 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3431 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003432
James Ketrenos43f66a62005-03-25 12:31:53 -06003433 /* Set us so that we have processed and used all buffers, but have
3434 * not restocked the Rx queue with fresh buffers */
3435 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003436 rxq->free_count = 0;
3437 spin_unlock_irqrestore(&rxq->lock, flags);
3438}
3439
3440#ifdef CONFIG_PM
3441static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003442static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003443
3444static void free_firmware(void)
3445{
3446 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003447 release_firmware(raw);
3448 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003449 fw_loaded = 0;
3450 }
3451}
3452#else
3453#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003454#endif
3455
3456static int ipw_load(struct ipw_priv *priv)
3457{
3458#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003459 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003460#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003461 struct ipw_fw *fw;
3462 u8 *boot_img, *ucode_img, *fw_img;
3463 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003464 int rc = 0, retries = 3;
3465
Zhu Yi397ae122006-01-24 16:37:22 +08003466 switch (priv->ieee->iw_mode) {
3467 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003468 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003469 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003470#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003471 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003472 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003473 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003474#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003475 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003476 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003477 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003478 }
Zhu Yi397ae122006-01-24 16:37:22 +08003479
James Ketrenos9006ea72006-03-08 03:22:28 +08003480 if (!name) {
3481 rc = -EINVAL;
3482 goto error;
3483 }
3484
3485#ifdef CONFIG_PM
3486 if (!fw_loaded) {
3487#endif
3488 rc = ipw_get_fw(priv, &raw, name);
3489 if (rc < 0)
3490 goto error;
3491#ifdef CONFIG_PM
3492 }
3493#endif
3494
3495 fw = (void *)raw->data;
3496 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003497 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3498 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3499 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003500
Zhu Yi397ae122006-01-24 16:37:22 +08003501 if (rc < 0)
3502 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003503
3504 if (!priv->rxq)
3505 priv->rxq = ipw_rx_queue_alloc(priv);
3506 else
3507 ipw_rx_queue_reset(priv, priv->rxq);
3508 if (!priv->rxq) {
3509 IPW_ERROR("Unable to initialize Rx queue\n");
3510 goto error;
3511 }
3512
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003513 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003514 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003515 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003516 priv->status &= ~STATUS_INT_ENABLED;
3517
3518 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003519 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003520
James Ketrenos43f66a62005-03-25 12:31:53 -06003521 ipw_stop_nic(priv);
3522
3523 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003524 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003525 IPW_ERROR("Unable to reset NIC\n");
3526 goto error;
3527 }
3528
James Ketrenosb095c382005-08-24 22:04:42 -05003529 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3530 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003531
3532 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003533 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003534 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003535 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003536 goto error;
3537 }
3538
3539 /* kick start the device */
3540 ipw_start_nic(priv);
3541
Zhu Yic7b6a672006-01-24 16:37:05 +08003542 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003543 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3544 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 if (rc < 0) {
3546 IPW_ERROR("device failed to boot initial fw image\n");
3547 goto error;
3548 }
3549 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3550
Jeff Garzikbf794512005-07-31 13:07:26 -04003551 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003552 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003553
3554 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003555 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003556 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003557 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003558 goto error;
3559 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003560
James Ketrenos43f66a62005-03-25 12:31:53 -06003561 /* stop nic */
3562 ipw_stop_nic(priv);
3563
3564 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003565 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003566 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003567 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 goto error;
3569 }
Zhu Yi397ae122006-01-24 16:37:22 +08003570#ifdef CONFIG_PM
3571 fw_loaded = 1;
3572#endif
3573
James Ketrenos43f66a62005-03-25 12:31:53 -06003574 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3575
3576 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003577 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003578 IPW_ERROR("Unable to initialize queues\n");
3579 goto error;
3580 }
3581
3582 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003583 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003584 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003585 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003586
James Ketrenos43f66a62005-03-25 12:31:53 -06003587 /* kick start the device */
3588 ipw_start_nic(priv);
3589
James Ketrenosb095c382005-08-24 22:04:42 -05003590 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003591 if (retries > 0) {
3592 IPW_WARNING("Parity error. Retrying init.\n");
3593 retries--;
3594 goto retry;
3595 }
3596
3597 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3598 rc = -EIO;
3599 goto error;
3600 }
3601
3602 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003603 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3604 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003605 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003606 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003607 goto error;
3608 }
3609 IPW_DEBUG_INFO("device response after %dms\n", rc);
3610
3611 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003612 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003613
3614 /* read eeprom data and initialize the eeprom region of sram */
3615 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003616 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003617
3618 /* enable interrupts */
3619 ipw_enable_interrupts(priv);
3620
3621 /* Ensure our queue has valid packets */
3622 ipw_rx_queue_replenish(priv);
3623
James Ketrenosb095c382005-08-24 22:04:42 -05003624 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003625
3626 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003627 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003628
3629#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003630 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003631#endif
3632 return 0;
3633
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003634 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003635 if (priv->rxq) {
3636 ipw_rx_queue_free(priv, priv->rxq);
3637 priv->rxq = NULL;
3638 }
3639 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003640 if (raw)
3641 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003642#ifdef CONFIG_PM
3643 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003644 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003645#endif
3646
3647 return rc;
3648}
3649
Jeff Garzikbf794512005-07-31 13:07:26 -04003650/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003651 * DMA services
3652 *
3653 * Theory of operation
3654 *
3655 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3656 * 2 empty entries always kept in the buffer to protect from overflow.
3657 *
3658 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003659 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3660 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003661 * Tx queue resumed.
3662 *
3663 * The IPW operates with six queues, one receive queue in the device's
3664 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003665 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003666 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003667 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003668 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003669 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003670 * we only utilize the first data transmit queue (queue1).
3671 */
3672
3673/**
3674 * Driver allocates buffers of this size for Rx
3675 */
3676
Dan Williams943dbef2008-02-14 17:49:41 -05003677/**
3678 * ipw_rx_queue_space - Return number of free slots available in queue.
3679 */
3680static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3681{
3682 int s = q->read - q->write;
3683 if (s <= 0)
3684 s += RX_QUEUE_SIZE;
3685 /* keep some buffer to not confuse full and empty queue */
3686 s -= 2;
3687 if (s < 0)
3688 s = 0;
3689 return s;
3690}
3691
3692static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003693{
3694 int s = q->last_used - q->first_empty;
3695 if (s <= 0)
3696 s += q->n_bd;
3697 s -= 2; /* keep some reserve to not confuse empty and full situations */
3698 if (s < 0)
3699 s = 0;
3700 return s;
3701}
3702
3703static inline int ipw_queue_inc_wrap(int index, int n_bd)
3704{
3705 return (++index == n_bd) ? 0 : index;
3706}
3707
3708/**
3709 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003710 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003711 * @param q queue to init
3712 * @param count Number of BD's to allocate. Should be power of 2
3713 * @param read_register Address for 'read' register
3714 * (not offset within BAR, full address)
3715 * @param write_register Address for 'write' register
3716 * (not offset within BAR, full address)
3717 * @param base_register Address for 'base' register
3718 * (not offset within BAR, full address)
3719 * @param size Address for 'size' register
3720 * (not offset within BAR, full address)
3721 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003722static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003723 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003724{
3725 q->n_bd = count;
3726
3727 q->low_mark = q->n_bd / 4;
3728 if (q->low_mark < 4)
3729 q->low_mark = 4;
3730
3731 q->high_mark = q->n_bd / 8;
3732 if (q->high_mark < 2)
3733 q->high_mark = 2;
3734
3735 q->first_empty = q->last_used = 0;
3736 q->reg_r = read;
3737 q->reg_w = write;
3738
3739 ipw_write32(priv, base, q->dma_addr);
3740 ipw_write32(priv, size, count);
3741 ipw_write32(priv, read, 0);
3742 ipw_write32(priv, write, 0);
3743
3744 _ipw_read32(priv, 0x90);
3745}
3746
Jeff Garzikbf794512005-07-31 13:07:26 -04003747static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003748 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003749 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003750{
3751 struct pci_dev *dev = priv->pci_dev;
3752
3753 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3754 if (!q->txb) {
3755 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3756 return -ENOMEM;
3757 }
3758
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003759 q->bd =
3760 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003761 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003762 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003763 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003764 kfree(q->txb);
3765 q->txb = NULL;
3766 return -ENOMEM;
3767 }
3768
3769 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3770 return 0;
3771}
3772
3773/**
3774 * Free one TFD, those at index [txq->q.last_used].
3775 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003776 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003777 * @param dev
3778 * @param txq
3779 */
3780static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3781 struct clx2_tx_queue *txq)
3782{
3783 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3784 struct pci_dev *dev = priv->pci_dev;
3785 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003786
James Ketrenos43f66a62005-03-25 12:31:53 -06003787 /* classify bd */
3788 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3789 /* nothing to cleanup after for host commands */
3790 return;
3791
3792 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003793 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3794 IPW_ERROR("Too many chunks: %i\n",
3795 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003796 /** @todo issue fatal error, it is quite serious situation */
3797 return;
3798 }
3799
3800 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003801 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3802 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3803 le16_to_cpu(bd->u.data.chunk_len[i]),
3804 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003805 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003806 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003807 txq->txb[txq->q.last_used] = NULL;
3808 }
3809 }
3810}
3811
3812/**
3813 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003814 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003815 * Empty queue by removing and destroying all BD's.
3816 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003817 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003818 * @param dev
3819 * @param q
3820 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003821static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003822{
3823 struct clx2_queue *q = &txq->q;
3824 struct pci_dev *dev = priv->pci_dev;
3825
Jeff Garzikbf794512005-07-31 13:07:26 -04003826 if (q->n_bd == 0)
3827 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003828
3829 /* first, empty all BD's */
3830 for (; q->first_empty != q->last_used;
3831 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3832 ipw_queue_tx_free_tfd(priv, txq);
3833 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003834
James Ketrenos43f66a62005-03-25 12:31:53 -06003835 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003836 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003837 q->dma_addr);
3838 kfree(txq->txb);
3839
3840 /* 0 fill whole structure */
3841 memset(txq, 0, sizeof(*txq));
3842}
3843
James Ketrenos43f66a62005-03-25 12:31:53 -06003844/**
3845 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003846 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003847 * @param priv
3848 */
3849static void ipw_tx_queue_free(struct ipw_priv *priv)
3850{
3851 /* Tx CMD queue */
3852 ipw_queue_tx_free(priv, &priv->txq_cmd);
3853
3854 /* Tx queues */
3855 ipw_queue_tx_free(priv, &priv->txq[0]);
3856 ipw_queue_tx_free(priv, &priv->txq[1]);
3857 ipw_queue_tx_free(priv, &priv->txq[2]);
3858 ipw_queue_tx_free(priv, &priv->txq[3]);
3859}
3860
Arjan van de Ven858119e2006-01-14 13:20:43 -08003861static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003862{
3863 /* First 3 bytes are manufacturer */
3864 bssid[0] = priv->mac_addr[0];
3865 bssid[1] = priv->mac_addr[1];
3866 bssid[2] = priv->mac_addr[2];
3867
3868 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003869 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003870
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003871 bssid[0] &= 0xfe; /* clear multicast bit */
3872 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003873}
3874
Arjan van de Ven858119e2006-01-14 13:20:43 -08003875static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003876{
3877 struct ipw_station_entry entry;
3878 int i;
3879
3880 for (i = 0; i < priv->num_stations; i++) {
3881 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3882 /* Another node is active in network */
3883 priv->missed_adhoc_beacons = 0;
3884 if (!(priv->config & CFG_STATIC_CHANNEL))
3885 /* when other nodes drop out, we drop out */
3886 priv->config &= ~CFG_ADHOC_PERSIST;
3887
3888 return i;
3889 }
3890 }
3891
3892 if (i == MAX_STATIONS)
3893 return IPW_INVALID_STATION;
3894
Johannes Berge1749612008-10-27 15:59:26 -07003895 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003896
3897 entry.reserved = 0;
3898 entry.support_mode = 0;
3899 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3900 memcpy(priv->stations[i], bssid, ETH_ALEN);
3901 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003902 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 priv->num_stations++;
3904
3905 return i;
3906}
3907
Arjan van de Ven858119e2006-01-14 13:20:43 -08003908static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003909{
3910 int i;
3911
Jeff Garzikbf794512005-07-31 13:07:26 -04003912 for (i = 0; i < priv->num_stations; i++)
3913 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003914 return i;
3915
3916 return IPW_INVALID_STATION;
3917}
3918
3919static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3920{
3921 int err;
3922
Hong Liu7b996592005-08-25 17:36:13 +08003923 if (priv->status & STATUS_ASSOCIATING) {
3924 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3925 queue_work(priv->workqueue, &priv->disassociate);
3926 return;
3927 }
3928
3929 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003930 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3931 return;
3932 }
3933
Johannes Berge1749612008-10-27 15:59:26 -07003934 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003935 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003936 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003937 priv->assoc_request.channel);
3938
3939 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3940 priv->status |= STATUS_DISASSOCIATING;
3941
3942 if (quiet)
3943 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3944 else
3945 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003946
James Ketrenos43f66a62005-03-25 12:31:53 -06003947 err = ipw_send_associate(priv, &priv->assoc_request);
3948 if (err) {
3949 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3950 "failed.\n");
3951 return;
3952 }
3953
3954}
3955
James Ketrenosc848d0a2005-08-24 21:56:24 -05003956static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003957{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003958 struct ipw_priv *priv = data;
3959 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3960 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003961 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003962 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003963 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003964}
3965
David Howellsc4028952006-11-22 14:57:56 +00003966static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003967{
David Howellsc4028952006-11-22 14:57:56 +00003968 struct ipw_priv *priv =
3969 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003970 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003971 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003972 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003973}
3974
David Howellsc4028952006-11-22 14:57:56 +00003975static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003976{
David Howellsc4028952006-11-22 14:57:56 +00003977 struct ipw_priv *priv =
3978 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003979
3980#ifdef CONFIG_IPW2200_PROMISCUOUS
3981 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3982 priv->sys_config.accept_all_data_frames = 1;
3983 priv->sys_config.accept_non_directed_frames = 1;
3984 priv->sys_config.accept_all_mgmt_bcpr = 1;
3985 priv->sys_config.accept_all_mgmt_frames = 1;
3986 }
3987#endif
3988
3989 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003990}
3991
3992struct ipw_status_code {
3993 u16 status;
3994 const char *reason;
3995};
3996
3997static const struct ipw_status_code ipw_status_codes[] = {
3998 {0x00, "Successful"},
3999 {0x01, "Unspecified failure"},
4000 {0x0A, "Cannot support all requested capabilities in the "
4001 "Capability information field"},
4002 {0x0B, "Reassociation denied due to inability to confirm that "
4003 "association exists"},
4004 {0x0C, "Association denied due to reason outside the scope of this "
4005 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004006 {0x0D,
4007 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06004008 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004009 {0x0E,
4010 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06004011 "transaction sequence number out of expected sequence"},
4012 {0x0F, "Authentication rejected because of challenge failure"},
4013 {0x10, "Authentication rejected due to timeout waiting for next "
4014 "frame in sequence"},
4015 {0x11, "Association denied because AP is unable to handle additional "
4016 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004017 {0x12,
4018 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06004019 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004020 {0x13,
4021 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004022 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004023 {0x14,
4024 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004025 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004026 {0x15,
4027 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004028 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004029 {0x19,
4030 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004031 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004032 {0x1A,
4033 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004034 "DSSS-OFDM operation"},
4035 {0x28, "Invalid Information Element"},
4036 {0x29, "Group Cipher is not valid"},
4037 {0x2A, "Pairwise Cipher is not valid"},
4038 {0x2B, "AKMP is not valid"},
4039 {0x2C, "Unsupported RSN IE version"},
4040 {0x2D, "Invalid RSN IE Capabilities"},
4041 {0x2E, "Cipher suite is rejected per security policy"},
4042};
4043
Jeff Garzikbf794512005-07-31 13:07:26 -04004044static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004045{
4046 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004047 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004048 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004049 return ipw_status_codes[i].reason;
4050 return "Unknown status value.";
4051}
James Ketrenos43f66a62005-03-25 12:31:53 -06004052
4053static void inline average_init(struct average *avg)
4054{
4055 memset(avg, 0, sizeof(*avg));
4056}
4057
Zhu Yi00d21de2006-04-13 17:19:02 +08004058#define DEPTH_RSSI 8
4059#define DEPTH_NOISE 16
4060static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4061{
4062 return ((depth-1)*prev_avg + val)/depth;
4063}
4064
Arjan van de Ven858119e2006-01-14 13:20:43 -08004065static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004066{
4067 avg->sum -= avg->entries[avg->pos];
4068 avg->sum += val;
4069 avg->entries[avg->pos++] = val;
4070 if (unlikely(avg->pos == AVG_ENTRIES)) {
4071 avg->init = 1;
4072 avg->pos = 0;
4073 }
4074}
4075
Arjan van de Ven858119e2006-01-14 13:20:43 -08004076static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004077{
4078 if (!unlikely(avg->init)) {
4079 if (avg->pos)
4080 return avg->sum / avg->pos;
4081 return 0;
4082 }
4083
4084 return avg->sum / AVG_ENTRIES;
4085}
4086
4087static void ipw_reset_stats(struct ipw_priv *priv)
4088{
4089 u32 len = sizeof(u32);
4090
4091 priv->quality = 0;
4092
4093 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004094 priv->exp_avg_rssi = -60;
4095 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004096
4097 priv->last_rate = 0;
4098 priv->last_missed_beacons = 0;
4099 priv->last_rx_packets = 0;
4100 priv->last_tx_packets = 0;
4101 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004102
James Ketrenos43f66a62005-03-25 12:31:53 -06004103 /* Firmware managed, reset only when NIC is restarted, so we have to
4104 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004105 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004106 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004107 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004108 &priv->last_tx_failures, &len);
4109
4110 /* Driver managed, reset with each association */
4111 priv->missed_adhoc_beacons = 0;
4112 priv->missed_beacons = 0;
4113 priv->tx_packets = 0;
4114 priv->rx_packets = 0;
4115
4116}
4117
Arjan van de Ven858119e2006-01-14 13:20:43 -08004118static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004119{
4120 u32 i = 0x80000000;
4121 u32 mask = priv->rates_mask;
4122 /* If currently associated in B mode, restrict the maximum
4123 * rate match to B rates */
4124 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004125 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004126
4127 /* TODO: Verify that the rate is supported by the current rates
4128 * list. */
4129
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004130 while (i && !(mask & i))
4131 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004132 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004133 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004134 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004135 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004136 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004137 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004138 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004139 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004140 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004141 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004142 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004143 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004144 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004145 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004146 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004147 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004148 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004149 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004150 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004151 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004152 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004153 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004154 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004155 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004156 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004157 }
4158
Jeff Garzikbf794512005-07-31 13:07:26 -04004159 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004160 return 11000000;
4161 else
4162 return 54000000;
4163}
4164
4165static u32 ipw_get_current_rate(struct ipw_priv *priv)
4166{
4167 u32 rate, len = sizeof(rate);
4168 int err;
4169
Jeff Garzikbf794512005-07-31 13:07:26 -04004170 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 return 0;
4172
4173 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004174 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004175 &len);
4176 if (err) {
4177 IPW_DEBUG_INFO("failed querying ordinals.\n");
4178 return 0;
4179 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004180 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004181 return ipw_get_max_rate(priv);
4182
4183 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004184 case IPW_TX_RATE_1MB:
4185 return 1000000;
4186 case IPW_TX_RATE_2MB:
4187 return 2000000;
4188 case IPW_TX_RATE_5MB:
4189 return 5500000;
4190 case IPW_TX_RATE_6MB:
4191 return 6000000;
4192 case IPW_TX_RATE_9MB:
4193 return 9000000;
4194 case IPW_TX_RATE_11MB:
4195 return 11000000;
4196 case IPW_TX_RATE_12MB:
4197 return 12000000;
4198 case IPW_TX_RATE_18MB:
4199 return 18000000;
4200 case IPW_TX_RATE_24MB:
4201 return 24000000;
4202 case IPW_TX_RATE_36MB:
4203 return 36000000;
4204 case IPW_TX_RATE_48MB:
4205 return 48000000;
4206 case IPW_TX_RATE_54MB:
4207 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004208 }
4209
4210 return 0;
4211}
4212
James Ketrenos43f66a62005-03-25 12:31:53 -06004213#define IPW_STATS_INTERVAL (2 * HZ)
4214static void ipw_gather_stats(struct ipw_priv *priv)
4215{
4216 u32 rx_err, rx_err_delta, rx_packets_delta;
4217 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4218 u32 missed_beacons_percent, missed_beacons_delta;
4219 u32 quality = 0;
4220 u32 len = sizeof(u32);
4221 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004222 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004223 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004224 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004225
4226 if (!(priv->status & STATUS_ASSOCIATED)) {
4227 priv->quality = 0;
4228 return;
4229 }
4230
4231 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004232 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004233 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004234 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004235 priv->last_missed_beacons = priv->missed_beacons;
4236 if (priv->assoc_request.beacon_interval) {
4237 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004238 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004239 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004240 } else {
4241 missed_beacons_percent = 0;
4242 }
4243 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4244
4245 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4246 rx_err_delta = rx_err - priv->last_rx_err;
4247 priv->last_rx_err = rx_err;
4248
4249 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4250 tx_failures_delta = tx_failures - priv->last_tx_failures;
4251 priv->last_tx_failures = tx_failures;
4252
4253 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4254 priv->last_rx_packets = priv->rx_packets;
4255
4256 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4257 priv->last_tx_packets = priv->tx_packets;
4258
4259 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004260 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004261 * Missed beacon: 100% = 0, 0% = 70% missed
4262 * Rate: 60% = 1Mbs, 100% = Max
4263 * Rx and Tx errors represent a straight % of total Rx/Tx
4264 * RSSI: 100% = > -50, 0% = < -80
4265 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004266 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004267 * The lowest computed quality is used.
4268 *
4269 */
4270#define BEACON_THRESHOLD 5
4271 beacon_quality = 100 - missed_beacons_percent;
4272 if (beacon_quality < BEACON_THRESHOLD)
4273 beacon_quality = 0;
4274 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004275 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004276 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004277 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004278 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004279
James Ketrenos43f66a62005-03-25 12:31:53 -06004280 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004281 max_rate = ipw_get_max_rate(priv);
4282 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004283 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4284 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004285
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004286 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004287 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004288 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004289 else
4290 rx_quality = 100;
4291 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4292 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004293
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004294 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004295 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004296 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004297 else
4298 tx_quality = 100;
4299 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4300 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004301
Zhu Yi00d21de2006-04-13 17:19:02 +08004302 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004303 signal_quality =
4304 (100 *
4305 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4306 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4307 (priv->ieee->perfect_rssi - rssi) *
4308 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4309 62 * (priv->ieee->perfect_rssi - rssi))) /
4310 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4311 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4312 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004313 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004314 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004315 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004316
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004317 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004318 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004319
Reinette Chatre21f8a732009-08-18 10:25:05 -07004320 quality = min(rx_quality, signal_quality);
4321 quality = min(tx_quality, quality);
4322 quality = min(rate_quality, quality);
4323 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004324 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004325 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4326 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004327 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004328 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4329 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004330 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4332 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004333 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004334 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4335 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004336 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004337 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4338 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004339
4340 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004341
4342 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004343 IPW_STATS_INTERVAL);
4344}
4345
David Howellsc4028952006-11-22 14:57:56 +00004346static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004347{
David Howellsc4028952006-11-22 14:57:56 +00004348 struct ipw_priv *priv =
4349 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004350 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004351 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004352 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004353}
4354
Ben Cahille7582562005-10-06 15:34:41 -05004355/* Missed beacon behavior:
4356 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4357 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4358 * Above disassociate threshold, give up and stop scanning.
4359 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004360static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004361 int missed_count)
4362{
4363 priv->notif_missed_beacons = missed_count;
4364
James Ketrenosafbf30a2005-08-25 00:05:33 -05004365 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004366 priv->status & STATUS_ASSOCIATED) {
4367 /* If associated and we've hit the missed
4368 * beacon threshold, disassociate, turn
4369 * off roaming, and abort any active scans */
4370 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004371 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004372 "Missed beacon: %d - disassociate\n", missed_count);
4373 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004374 if (priv->status & STATUS_SCANNING) {
4375 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4376 IPW_DL_STATE,
4377 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004378 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004379 }
4380
James Ketrenosea2b26e2005-08-24 21:25:16 -05004381 queue_work(priv->workqueue, &priv->disassociate);
4382 return;
4383 }
4384
4385 if (priv->status & STATUS_ROAMING) {
4386 /* If we are currently roaming, then just
4387 * print a debug statement... */
4388 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4389 "Missed beacon: %d - roam in progress\n",
4390 missed_count);
4391 return;
4392 }
4393
Zhu Yi4bfdb912006-01-24 16:37:16 +08004394 if (roaming &&
4395 (missed_count > priv->roaming_threshold &&
4396 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004397 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004398 * bit in the status and kick off a scan.
4399 * This can happen several times before we reach
4400 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004401 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4402 "Missed beacon: %d - initiate "
4403 "roaming\n", missed_count);
4404 if (!(priv->status & STATUS_ROAMING)) {
4405 priv->status |= STATUS_ROAMING;
4406 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004407 queue_delayed_work(priv->workqueue,
4408 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004409 }
4410 return;
4411 }
4412
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004413 if (priv->status & STATUS_SCANNING &&
4414 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004415 /* Stop scan to keep fw from getting
4416 * stuck (only if we aren't roaming --
4417 * otherwise we'll never scan more than 2 or 3
4418 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004419 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4420 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004421 queue_work(priv->workqueue, &priv->abort_scan);
4422 }
4423
4424 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004425}
4426
Dan Williams0b531672007-10-09 13:55:24 -04004427static void ipw_scan_event(struct work_struct *work)
4428{
4429 union iwreq_data wrqu;
4430
4431 struct ipw_priv *priv =
4432 container_of(work, struct ipw_priv, scan_event.work);
4433
4434 wrqu.data.length = 0;
4435 wrqu.data.flags = 0;
4436 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4437}
4438
4439static void handle_scan_event(struct ipw_priv *priv)
4440{
4441 /* Only userspace-requested scan completion events go out immediately */
4442 if (!priv->user_requested_scan) {
4443 if (!delayed_work_pending(&priv->scan_event))
4444 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004445 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004446 } else {
4447 union iwreq_data wrqu;
4448
4449 priv->user_requested_scan = 0;
4450 cancel_delayed_work(&priv->scan_event);
4451
4452 wrqu.data.length = 0;
4453 wrqu.data.flags = 0;
4454 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4455 }
4456}
4457
James Ketrenos43f66a62005-03-25 12:31:53 -06004458/**
4459 * Handle host notification packet.
4460 * Called from interrupt routine
4461 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004462static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004463 struct ipw_rx_notification *notif)
4464{
John W. Linville9387b7c2008-09-30 20:59:05 -04004465 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004466 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004467
Al Viroe62e1ee2007-12-27 01:36:46 -05004468 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004469
James Ketrenos43f66a62005-03-25 12:31:53 -06004470 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004471 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4472 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004473
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004474 switch (assoc->state) {
4475 case CMAS_ASSOCIATED:{
4476 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4477 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004478 "associated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004479 print_ssid(ssid, priv->essid,
4480 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004481 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004482
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004483 switch (priv->ieee->iw_mode) {
4484 case IW_MODE_INFRA:
4485 memcpy(priv->ieee->bssid,
4486 priv->bssid, ETH_ALEN);
4487 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004488
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004489 case IW_MODE_ADHOC:
4490 memcpy(priv->ieee->bssid,
4491 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004492
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004493 /* clear out the station table */
4494 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004495
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004496 IPW_DEBUG_ASSOC
4497 ("queueing adhoc check\n");
4498 queue_delayed_work(priv->
4499 workqueue,
4500 &priv->
4501 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004502 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004504 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004505 break;
4506 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004507
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004508 priv->status &= ~STATUS_ASSOCIATING;
4509 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004510 queue_work(priv->workqueue,
4511 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004512
Zhu Yie43e3c12006-04-13 17:20:45 +08004513#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004514#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004515 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004516 if ((priv->status & STATUS_AUTH) &&
4517 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4518 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004519 if ((sizeof
4520 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004521 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004522 <= size)
4523 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004524 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004525 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004526 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004527 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004528 };
4529
4530 IPW_DEBUG_QOS
4531 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004532 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004533 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004534 ieee,
4535 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004536 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004537 *)
4538 &notif->u.raw, &stats);
4539 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004540 }
James Ketrenosb095c382005-08-24 22:04:42 -05004541#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004542
James Ketrenosa613bff2005-08-24 21:43:11 -05004543 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004544
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004545 break;
4546 }
4547
4548 case CMAS_AUTHENTICATED:{
4549 if (priv->
4550 status & (STATUS_ASSOCIATED |
4551 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 struct notif_authenticate *auth
4553 = &notif->u.auth;
4554 IPW_DEBUG(IPW_DL_NOTIF |
4555 IPW_DL_STATE |
4556 IPW_DL_ASSOC,
4557 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004558 "%pM"
Frans Pop9fd1ea42010-03-24 19:46:31 +01004559 ": (0x%04X) - %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004560 print_ssid(ssid,
4561 priv->
4562 essid,
4563 priv->
4564 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004565 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004566 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004567 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004568 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004569 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004570
4571 priv->status &=
4572 ~(STATUS_ASSOCIATING |
4573 STATUS_AUTH |
4574 STATUS_ASSOCIATED);
4575
James Ketrenosa613bff2005-08-24 21:43:11 -05004576 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004577 break;
4578 }
4579
4580 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4581 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004582 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004583 print_ssid(ssid, priv->essid,
4584 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004585 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004586 break;
4587 }
4588
4589 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004590 if (priv->status & STATUS_AUTH) {
4591 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004592 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004593 *resp;
4594 resp =
4595 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004596 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004597 *)&notif->u.raw;
4598 IPW_DEBUG(IPW_DL_NOTIF |
4599 IPW_DL_STATE |
4600 IPW_DL_ASSOC,
4601 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004602 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004603 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004604 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004605 (resp->status)));
4606 }
4607
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004608 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4609 IPW_DL_ASSOC,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004610 "disassociated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004611 print_ssid(ssid, priv->essid,
4612 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004613 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614
4615 priv->status &=
4616 ~(STATUS_DISASSOCIATING |
4617 STATUS_ASSOCIATING |
4618 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004619 if (priv->assoc_network
4620 && (priv->assoc_network->
4621 capability &
4622 WLAN_CAPABILITY_IBSS))
4623 ipw_remove_current_network
4624 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004625
James Ketrenosa613bff2005-08-24 21:43:11 -05004626 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004627
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004628 break;
4629 }
4630
James Ketrenosb095c382005-08-24 22:04:42 -05004631 case CMAS_RX_ASSOC_RESP:
4632 break;
4633
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004634 default:
4635 IPW_ERROR("assoc: unknown (%d)\n",
4636 assoc->state);
4637 break;
4638 }
4639
James Ketrenos43f66a62005-03-25 12:31:53 -06004640 break;
4641 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004642
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004643 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4644 struct notif_authenticate *auth = &notif->u.auth;
4645 switch (auth->state) {
4646 case CMAS_AUTHENTICATED:
4647 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Frans Pop9fd1ea42010-03-24 19:46:31 +01004648 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004649 print_ssid(ssid, priv->essid,
4650 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004651 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004652 priv->status |= STATUS_AUTH;
4653 break;
4654
4655 case CMAS_INIT:
4656 if (priv->status & STATUS_AUTH) {
4657 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4658 IPW_DL_ASSOC,
4659 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004660 le16_to_cpu(auth->status),
4661 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004662 (auth->
4663 status)));
4664 }
4665 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4666 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004667 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004668 print_ssid(ssid, priv->essid,
4669 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004670 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004671
4672 priv->status &= ~(STATUS_ASSOCIATING |
4673 STATUS_AUTH |
4674 STATUS_ASSOCIATED);
4675
James Ketrenosa613bff2005-08-24 21:43:11 -05004676 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004677 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004678
4679 case CMAS_TX_AUTH_SEQ_1:
4680 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4681 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4682 break;
4683 case CMAS_RX_AUTH_SEQ_2:
4684 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4685 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4686 break;
4687 case CMAS_AUTH_SEQ_1_PASS:
4688 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4689 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4690 break;
4691 case CMAS_AUTH_SEQ_1_FAIL:
4692 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4693 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4694 break;
4695 case CMAS_TX_AUTH_SEQ_3:
4696 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4697 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4698 break;
4699 case CMAS_RX_AUTH_SEQ_4:
4700 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4701 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4702 break;
4703 case CMAS_AUTH_SEQ_2_PASS:
4704 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4705 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4706 break;
4707 case CMAS_AUTH_SEQ_2_FAIL:
4708 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4709 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4710 break;
4711 case CMAS_TX_ASSOC:
4712 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4713 IPW_DL_ASSOC, "TX_ASSOC\n");
4714 break;
4715 case CMAS_RX_ASSOC_RESP:
4716 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4717 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004718
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004719 break;
4720 case CMAS_ASSOCIATED:
4721 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4722 IPW_DL_ASSOC, "ASSOCIATED\n");
4723 break;
4724 default:
4725 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4726 auth->state);
4727 break;
4728 }
4729 break;
4730 }
4731
4732 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4733 struct notif_channel_result *x =
4734 &notif->u.channel_result;
4735
Al Viroe62e1ee2007-12-27 01:36:46 -05004736 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004737 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4738 x->channel_num);
4739 } else {
4740 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4741 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004742 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004743 }
4744 break;
4745 }
4746
4747 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4748 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004749 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004750 IPW_DEBUG_SCAN
4751 ("Scan completed: type %d, %d channels, "
4752 "%d status\n", x->scan_type,
4753 x->num_channels, x->status);
4754 } else {
4755 IPW_ERROR("Scan completed of wrong size %d "
4756 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004757 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004758 }
4759
4760 priv->status &=
4761 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4762
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004763 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004764 cancel_delayed_work(&priv->scan_check);
4765
James Ketrenosb095c382005-08-24 22:04:42 -05004766 if (priv->status & STATUS_EXIT_PENDING)
4767 break;
4768
4769 priv->ieee->scans++;
4770
4771#ifdef CONFIG_IPW2200_MONITOR
4772 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004773 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004774 queue_delayed_work(priv->workqueue,
4775 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004776 break;
4777 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004778 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004779#endif /* CONFIG_IPW2200_MONITOR */
4780
Dan Williamsea177302008-06-02 17:51:23 -04004781 /* Do queued direct scans first */
4782 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4783 queue_delayed_work(priv->workqueue,
4784 &priv->request_direct_scan, 0);
4785 }
4786
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004787 if (!(priv->status & (STATUS_ASSOCIATED |
4788 STATUS_ASSOCIATING |
4789 STATUS_ROAMING |
4790 STATUS_DISASSOCIATING)))
4791 queue_work(priv->workqueue, &priv->associate);
4792 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004793 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4794 /* If a scan completed and we are in roam mode, then
4795 * the scan that completed was the one requested as a
4796 * result of entering roam... so, schedule the
4797 * roam work */
4798 queue_work(priv->workqueue,
4799 &priv->roam);
4800 else
4801 /* Don't schedule if we aborted the scan */
4802 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004803 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004804 queue_delayed_work(priv->workqueue,
4805 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004806 else if (priv->config & CFG_BACKGROUND_SCAN
4807 && priv->status & STATUS_ASSOCIATED)
4808 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004809 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004810 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004811
4812 /* Send an empty event to user space.
4813 * We don't send the received data on the event because
4814 * it would require us to do complex transcoding, and
4815 * we want to minimise the work done in the irq handler
4816 * Use a request to extract the data.
4817 * Also, we generate this even for any scan, regardless
4818 * on how the scan was initiated. User space can just
4819 * sync on periodic scan to get fresh data...
4820 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004821 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4822 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004823 break;
4824 }
4825
4826 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4827 struct notif_frag_length *x = &notif->u.frag_len;
4828
Al Viroe62e1ee2007-12-27 01:36:46 -05004829 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004830 IPW_ERROR("Frag length: %d\n",
4831 le16_to_cpu(x->frag_length));
4832 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004833 IPW_ERROR("Frag length of wrong size %d "
4834 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004835 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004836 break;
4837 }
4838
4839 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4840 struct notif_link_deterioration *x =
4841 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004842
Al Viroe62e1ee2007-12-27 01:36:46 -05004843 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004844 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004845 "link deterioration: type %d, cnt %d\n",
4846 x->silence_notification_type,
4847 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004848 memcpy(&priv->last_link_deterioration, x,
4849 sizeof(*x));
4850 } else {
4851 IPW_ERROR("Link Deterioration of wrong size %d "
4852 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004853 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004854 }
4855 break;
4856 }
4857
4858 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4859 IPW_ERROR("Dino config\n");
4860 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004861 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004862 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004863
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004864 break;
4865 }
4866
4867 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4868 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004869 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004870 IPW_ERROR
4871 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004872 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004874 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004875
James Ketrenosa613bff2005-08-24 21:43:11 -05004876 if (le32_to_cpu(x->state) ==
4877 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4878 ipw_handle_missed_beacon(priv,
4879 le32_to_cpu(x->
4880 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004881
James Ketrenos43f66a62005-03-25 12:31:53 -06004882 break;
4883 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004884
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4886 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004887 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004888 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4889 "0x%02x station %d\n",
4890 x->key_state, x->security_type,
4891 x->station_index);
4892 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004893 }
4894
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004895 IPW_ERROR
4896 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004897 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004898 break;
4899 }
4900
4901 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4902 struct notif_calibration *x = &notif->u.calibration;
4903
Al Viroe62e1ee2007-12-27 01:36:46 -05004904 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004905 memcpy(&priv->calib, x, sizeof(*x));
4906 IPW_DEBUG_INFO("TODO: Calibration\n");
4907 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004908 }
4909
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004910 IPW_ERROR
4911 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004912 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004913 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004914 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004915
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004916 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004917 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004918 priv->exp_avg_noise =
4919 exponential_average(priv->exp_avg_noise,
4920 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4921 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004922 break;
4923 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004924
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004925 IPW_ERROR
4926 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004927 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004929 }
4930
James Ketrenos43f66a62005-03-25 12:31:53 -06004931 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004932 IPW_DEBUG_NOTIF("Unknown notification: "
4933 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004934 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004935 }
4936}
4937
4938/**
4939 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004940 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 * @param priv
4942 * @return error code
4943 */
4944static int ipw_queue_reset(struct ipw_priv *priv)
4945{
4946 int rc = 0;
4947 /** @todo customize queue sizes */
4948 int nTx = 64, nTxCmd = 8;
4949 ipw_tx_queue_free(priv);
4950 /* Tx CMD queue */
4951 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004952 IPW_TX_CMD_QUEUE_READ_INDEX,
4953 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4954 IPW_TX_CMD_QUEUE_BD_BASE,
4955 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004956 if (rc) {
4957 IPW_ERROR("Tx Cmd queue init failed\n");
4958 goto error;
4959 }
4960 /* Tx queue(s) */
4961 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004962 IPW_TX_QUEUE_0_READ_INDEX,
4963 IPW_TX_QUEUE_0_WRITE_INDEX,
4964 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004965 if (rc) {
4966 IPW_ERROR("Tx 0 queue init failed\n");
4967 goto error;
4968 }
4969 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004970 IPW_TX_QUEUE_1_READ_INDEX,
4971 IPW_TX_QUEUE_1_WRITE_INDEX,
4972 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 if (rc) {
4974 IPW_ERROR("Tx 1 queue init failed\n");
4975 goto error;
4976 }
4977 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004978 IPW_TX_QUEUE_2_READ_INDEX,
4979 IPW_TX_QUEUE_2_WRITE_INDEX,
4980 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004981 if (rc) {
4982 IPW_ERROR("Tx 2 queue init failed\n");
4983 goto error;
4984 }
4985 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004986 IPW_TX_QUEUE_3_READ_INDEX,
4987 IPW_TX_QUEUE_3_WRITE_INDEX,
4988 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004989 if (rc) {
4990 IPW_ERROR("Tx 3 queue init failed\n");
4991 goto error;
4992 }
4993 /* statistics */
4994 priv->rx_bufs_min = 0;
4995 priv->rx_pend_max = 0;
4996 return rc;
4997
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004998 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004999 ipw_tx_queue_free(priv);
5000 return rc;
5001}
5002
5003/**
5004 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04005005 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01005006 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06005007 * new 'R' index need to be reclaimed. As result, some free space
5008 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04005009 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005010 * @note Need to protect against garbage in 'R' index
5011 * @param priv
5012 * @param txq
5013 * @param qindex
5014 * @return Number of used entries remains in the queue
5015 */
Jeff Garzikbf794512005-07-31 13:07:26 -04005016static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 struct clx2_tx_queue *txq, int qindex)
5018{
5019 u32 hw_tail;
5020 int used;
5021 struct clx2_queue *q = &txq->q;
5022
5023 hw_tail = ipw_read32(priv, q->reg_r);
5024 if (hw_tail >= q->n_bd) {
5025 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005026 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5027 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 goto done;
5029 }
5030 for (; q->last_used != hw_tail;
5031 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5032 ipw_queue_tx_free_tfd(priv, txq);
5033 priv->tx_packets++;
5034 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005035 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005036 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005037 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005038 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005039 used = q->first_empty - q->last_used;
5040 if (used < 0)
5041 used += q->n_bd;
5042
5043 return used;
5044}
5045
5046static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5047 int len, int sync)
5048{
5049 struct clx2_tx_queue *txq = &priv->txq_cmd;
5050 struct clx2_queue *q = &txq->q;
5051 struct tfd_frame *tfd;
5052
Dan Williams943dbef2008-02-14 17:49:41 -05005053 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005054 IPW_ERROR("No space for Tx\n");
5055 return -EBUSY;
5056 }
5057
5058 tfd = &txq->bd[q->first_empty];
5059 txq->txb[q->first_empty] = NULL;
5060
5061 memset(tfd, 0, sizeof(*tfd));
5062 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5063 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5064 priv->hcmd_seq++;
5065 tfd->u.cmd.index = hcmd;
5066 tfd->u.cmd.length = len;
5067 memcpy(tfd->u.cmd.payload, buf, len);
5068 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5069 ipw_write32(priv, q->reg_w, q->first_empty);
5070 _ipw_read32(priv, 0x90);
5071
5072 return 0;
5073}
5074
Jeff Garzikbf794512005-07-31 13:07:26 -04005075/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005076 * Rx theory of operation
5077 *
5078 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005079 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005080 * 0 to 31
5081 *
5082 * Rx Queue Indexes
5083 * The host/firmware share two index registers for managing the Rx buffers.
5084 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005085 * The READ index maps to the first position that the firmware may be writing
5086 * to -- the driver can read up to (but not including) this position and get
5087 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 * The READ index is managed by the firmware once the card is enabled.
5089 *
5090 * The WRITE index maps to the last position the driver has read from -- the
5091 * position preceding WRITE is the last slot the firmware can place a packet.
5092 *
5093 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005094 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005096 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005097 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5098 *
5099 * When the firmware places a packet in a buffer it will advance the READ index
5100 * and fire the RX interrupt. The driver can then query the READ index and
5101 * process as many packets as possible, moving the WRITE index forward as it
5102 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005103 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005104 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005105 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005106 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005107 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005108 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5109 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5110 * 'processed' and 'read' driver indexes as well)
5111 * + A received packet is processed and handed to the kernel network stack,
5112 * detached from the ipw->rxq. The driver 'processed' index is updated.
5113 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005114 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5115 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 * were enough free buffers and RX_STALLED is set it is cleared.
5117 *
5118 *
5119 * Driver sequence:
5120 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005122 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5123 * ipw_rx_queue_restock
5124 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5125 * queue, updates firmware pointers, and updates
5126 * the WRITE index. If insufficient rx_free buffers
5127 * are available, schedules ipw_rx_queue_replenish
5128 *
5129 * -- enable interrupts --
5130 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005131 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005132 * Moves the packet buffer from queue to rx_used.
5133 * Calls ipw_rx_queue_restock to refill any empty
5134 * slots.
5135 * ...
5136 *
5137 */
5138
Jeff Garzikbf794512005-07-31 13:07:26 -04005139/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005140 * If there are slots in the RX queue that need to be restocked,
5141 * and we have free pre-allocated buffers, fill the ranks as much
5142 * as we can pulling from rx_free.
5143 *
5144 * This moves the 'write' index forward to catch up with 'processed', and
5145 * also updates the memory address in the firmware to reference the new
5146 * target buffer.
5147 */
5148static void ipw_rx_queue_restock(struct ipw_priv *priv)
5149{
5150 struct ipw_rx_queue *rxq = priv->rxq;
5151 struct list_head *element;
5152 struct ipw_rx_mem_buffer *rxb;
5153 unsigned long flags;
5154 int write;
5155
5156 spin_lock_irqsave(&rxq->lock, flags);
5157 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005158 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005159 element = rxq->rx_free.next;
5160 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5161 list_del(element);
5162
James Ketrenosb095c382005-08-24 22:04:42 -05005163 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005164 rxb->dma_addr);
5165 rxq->queue[rxq->write] = rxb;
5166 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5167 rxq->free_count--;
5168 }
5169 spin_unlock_irqrestore(&rxq->lock, flags);
5170
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005172 * refill it */
5173 if (rxq->free_count <= RX_LOW_WATERMARK)
5174 queue_work(priv->workqueue, &priv->rx_replenish);
5175
5176 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005177 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005178 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005179}
5180
5181/*
5182 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 * Also restock the Rx queue via ipw_rx_queue_restock.
5184 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005185 * This is called as a scheduled work item (except for during intialization)
5186 */
5187static void ipw_rx_queue_replenish(void *data)
5188{
5189 struct ipw_priv *priv = data;
5190 struct ipw_rx_queue *rxq = priv->rxq;
5191 struct list_head *element;
5192 struct ipw_rx_mem_buffer *rxb;
5193 unsigned long flags;
5194
5195 spin_lock_irqsave(&rxq->lock, flags);
5196 while (!list_empty(&rxq->rx_used)) {
5197 element = rxq->rx_used.next;
5198 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005199 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005200 if (!rxb->skb) {
5201 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5202 priv->net_dev->name);
5203 /* We don't reschedule replenish work here -- we will
5204 * call the restock method and if it still needs
5205 * more buffers it will schedule replenish */
5206 break;
5207 }
5208 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005209
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005210 rxb->dma_addr =
5211 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005212 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005213
James Ketrenos43f66a62005-03-25 12:31:53 -06005214 list_add_tail(&rxb->list, &rxq->rx_free);
5215 rxq->free_count++;
5216 }
5217 spin_unlock_irqrestore(&rxq->lock, flags);
5218
5219 ipw_rx_queue_restock(priv);
5220}
5221
David Howellsc4028952006-11-22 14:57:56 +00005222static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005223{
David Howellsc4028952006-11-22 14:57:56 +00005224 struct ipw_priv *priv =
5225 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005226 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005227 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005228 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005229}
5230
James Ketrenos43f66a62005-03-25 12:31:53 -06005231/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005232 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005233 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005234 * non NULL it is unmapped and freed
5235 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005236static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005237{
5238 int i;
5239
5240 if (!rxq)
5241 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005242
James Ketrenos43f66a62005-03-25 12:31:53 -06005243 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5244 if (rxq->pool[i].skb != NULL) {
5245 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005246 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005247 dev_kfree_skb(rxq->pool[i].skb);
5248 }
5249 }
5250
5251 kfree(rxq);
5252}
5253
5254static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5255{
5256 struct ipw_rx_queue *rxq;
5257 int i;
5258
Takisc75f4742005-12-01 01:41:45 -08005259 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005260 if (unlikely(!rxq)) {
5261 IPW_ERROR("memory allocation failed\n");
5262 return NULL;
5263 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005264 spin_lock_init(&rxq->lock);
5265 INIT_LIST_HEAD(&rxq->rx_free);
5266 INIT_LIST_HEAD(&rxq->rx_used);
5267
5268 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005269 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005270 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5271
5272 /* Set us so that we have processed and used all buffers, but have
5273 * not restocked the Rx queue with fresh buffers */
5274 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005275 rxq->free_count = 0;
5276
5277 return rxq;
5278}
5279
5280static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5281{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005282 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283 if (ieee_mode == IEEE_A) {
5284 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005285 case LIBIPW_OFDM_RATE_6MB:
5286 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005287 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005288 case LIBIPW_OFDM_RATE_9MB:
5289 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005291 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005292 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005293 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5294 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005295 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005296 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5297 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005298 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005299 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5300 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005301 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005302 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5303 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005304 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005305 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5306 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005307 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005308 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005309 default:
5310 return 0;
5311 }
5312 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005313
James Ketrenos43f66a62005-03-25 12:31:53 -06005314 /* B and G mixed */
5315 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005316 case LIBIPW_CCK_RATE_1MB:
5317 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5318 case LIBIPW_CCK_RATE_2MB:
5319 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5320 case LIBIPW_CCK_RATE_5MB:
5321 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5322 case LIBIPW_CCK_RATE_11MB:
5323 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005324 }
5325
5326 /* If we are limited to B modulations, bail at this point */
5327 if (ieee_mode == IEEE_B)
5328 return 0;
5329
5330 /* G */
5331 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005332 case LIBIPW_OFDM_RATE_6MB:
5333 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5334 case LIBIPW_OFDM_RATE_9MB:
5335 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5336 case LIBIPW_OFDM_RATE_12MB:
5337 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5338 case LIBIPW_OFDM_RATE_18MB:
5339 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5340 case LIBIPW_OFDM_RATE_24MB:
5341 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5342 case LIBIPW_OFDM_RATE_36MB:
5343 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5344 case LIBIPW_OFDM_RATE_48MB:
5345 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5346 case LIBIPW_OFDM_RATE_54MB:
5347 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005348 }
5349
5350 return 0;
5351}
5352
Jeff Garzikbf794512005-07-31 13:07:26 -04005353static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005354 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005355 struct ipw_supported_rates *rates)
5356{
5357 int num_rates, i;
5358
5359 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005360 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005361 rates->num_rates = 0;
5362 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005363 if (!ipw_is_rate_in_mask(priv, network->mode,
5364 network->rates[i])) {
5365
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005366 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005367 IPW_DEBUG_SCAN("Adding masked mandatory "
5368 "rate %02X\n",
5369 network->rates[i]);
5370 rates->supported_rates[rates->num_rates++] =
5371 network->rates[i];
5372 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005373 }
5374
James Ketrenos43f66a62005-03-25 12:31:53 -06005375 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5376 network->rates[i], priv->rates_mask);
5377 continue;
5378 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005379
James Ketrenos43f66a62005-03-25 12:31:53 -06005380 rates->supported_rates[rates->num_rates++] = network->rates[i];
5381 }
5382
James Ketrenosa613bff2005-08-24 21:43:11 -05005383 num_rates = min(network->rates_ex_len,
5384 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005385 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005386 if (!ipw_is_rate_in_mask(priv, network->mode,
5387 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005388 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005389 IPW_DEBUG_SCAN("Adding masked mandatory "
5390 "rate %02X\n",
5391 network->rates_ex[i]);
5392 rates->supported_rates[rates->num_rates++] =
5393 network->rates[i];
5394 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005395 }
5396
James Ketrenos43f66a62005-03-25 12:31:53 -06005397 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5398 network->rates_ex[i], priv->rates_mask);
5399 continue;
5400 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005402 rates->supported_rates[rates->num_rates++] =
5403 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005404 }
5405
James Ketrenosea2b26e2005-08-24 21:25:16 -05005406 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005407}
5408
Arjan van de Ven858119e2006-01-14 13:20:43 -08005409static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005410 const struct ipw_supported_rates *src)
5411{
5412 u8 i;
5413 for (i = 0; i < src->num_rates; i++)
5414 dest->supported_rates[i] = src->supported_rates[i];
5415 dest->num_rates = src->num_rates;
5416}
5417
5418/* TODO: Look at sniffed packets in the air to determine if the basic rate
5419 * mask should ever be used -- right now all callers to add the scan rates are
5420 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5421static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005422 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005423{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005424 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5425 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005426
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005427 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005428 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005429 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005430
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005431 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005432 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005433 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005434
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005435 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005436 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005437 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005438
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005439 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005440 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005441 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005442}
5443
5444static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005445 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005446{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005447 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5448 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005449
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005450 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005451 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005452 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005453
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005454 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005455 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005456 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005457
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005459 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005460 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005461
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005462 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005463 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005464 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005465
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005466 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005467 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005468 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005469
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005470 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005471 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005472 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005473
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005474 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005475 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005476 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005477
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005478 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005479 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005480 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005481}
5482
5483struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005484 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005485 struct ipw_supported_rates rates;
5486};
5487
James Ketrenosc848d0a2005-08-24 21:56:24 -05005488static int ipw_find_adhoc_network(struct ipw_priv *priv,
5489 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005490 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005491 int roaming)
5492{
5493 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005494 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005495
5496 /* Verify that this network's capability is compatible with the
5497 * current mode (AdHoc or Infrastructure) */
5498 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5499 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005500 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005501 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005502 print_ssid(ssid, network->ssid,
5503 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005504 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005505 return 0;
5506 }
5507
James Ketrenosc848d0a2005-08-24 21:56:24 -05005508 if (unlikely(roaming)) {
5509 /* If we are roaming, then ensure check if this is a valid
5510 * network to try and roam to */
5511 if ((network->ssid_len != match->network->ssid_len) ||
5512 memcmp(network->ssid, match->network->ssid,
5513 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005514 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005515 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005516 print_ssid(ssid, network->ssid,
5517 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005518 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005519 return 0;
5520 }
5521 } else {
5522 /* If an ESSID has been configured then compare the broadcast
5523 * ESSID to ours */
5524 if ((priv->config & CFG_STATIC_ESSID) &&
5525 ((network->ssid_len != priv->essid_len) ||
5526 memcmp(network->ssid, priv->essid,
5527 min(network->ssid_len, priv->essid_len)))) {
5528 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005529
James Ketrenosc848d0a2005-08-24 21:56:24 -05005530 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005531 print_ssid(ssid, network->ssid,
5532 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005533 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005534 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005535 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005536 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005537 print_ssid(ssid, priv->essid,
5538 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005539 return 0;
5540 }
5541 }
5542
5543 /* If the old network rate is better than this one, don't bother
5544 * testing everything else. */
5545
5546 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005547 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5548 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005549 print_ssid(ssid, match->network->ssid,
5550 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005551 return 0;
5552 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005553 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5554 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005555 print_ssid(ssid, match->network->ssid,
5556 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005557 return 0;
5558 }
5559
5560 /* Now go through and see if the requested network is valid... */
5561 if (priv->ieee->scan_age != 0 &&
5562 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005563 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005564 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005565 print_ssid(ssid, network->ssid,
5566 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005567 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005568 jiffies_to_msecs(jiffies -
5569 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005570 return 0;
5571 }
5572
5573 if ((priv->config & CFG_STATIC_CHANNEL) &&
5574 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005575 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005576 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005577 print_ssid(ssid, network->ssid,
5578 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005579 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005580 network->channel, priv->channel);
5581 return 0;
5582 }
5583
5584 /* Verify privacy compatability */
5585 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5586 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005587 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005588 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005589 print_ssid(ssid, network->ssid,
5590 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005591 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005592 priv->
5593 capability & CAP_PRIVACY_ON ? "on" : "off",
5594 network->
5595 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5596 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005597 return 0;
5598 }
5599
5600 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005601 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5602 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005603 ".\n", print_ssid(ssid, network->ssid,
5604 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005605 network->bssid,
5606 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005607 return 0;
5608 }
5609
5610 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005611 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005612 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005613 "because of invalid frequency/mode "
5614 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005615 print_ssid(ssid, network->ssid,
5616 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005617 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005618 return 0;
5619 }
5620
5621 /* Ensure that the rates supported by the driver are compatible with
5622 * this AP, including verification of basic rates (mandatory) */
5623 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005624 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625 "because configured rate mask excludes "
5626 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005627 print_ssid(ssid, network->ssid,
5628 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005629 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005630 return 0;
5631 }
5632
5633 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005634 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005635 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005636 print_ssid(ssid, network->ssid,
5637 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005638 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005639 return 0;
5640 }
5641
5642 /* TODO: Perform any further minimal comparititive tests. We do not
5643 * want to put too much policy logic here; intelligent scan selection
5644 * should occur within a generic IEEE 802.11 user space tool. */
5645
5646 /* Set up 'new' AP to this network */
5647 ipw_copy_rates(&match->rates, &rates);
5648 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005649 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005650 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005651 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005652
5653 return 1;
5654}
5655
David Howellsc4028952006-11-22 14:57:56 +00005656static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005657{
John W. Linville9387b7c2008-09-30 20:59:05 -04005658 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005659 struct ipw_priv *priv =
5660 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005661 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005662 struct ipw_network_match match = {
5663 .network = priv->assoc_network
5664 };
5665
James Ketrenosafbf30a2005-08-25 00:05:33 -05005666 if ((priv->status & STATUS_ASSOCIATED) &&
5667 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005668 /* First pass through ROAM process -- look for a better
5669 * network */
5670 unsigned long flags;
5671
5672 spin_lock_irqsave(&priv->ieee->lock, flags);
5673 list_for_each_entry(network, &priv->ieee->network_list, list) {
5674 if (network != priv->assoc_network)
5675 ipw_find_adhoc_network(priv, &match, network,
5676 1);
5677 }
5678 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5679
5680 if (match.network == priv->assoc_network) {
5681 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5682 "merge to.\n");
5683 return;
5684 }
5685
Zhu Yi46441512006-01-24 16:37:59 +08005686 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005687 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5688 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005689 print_ssid(ssid, priv->essid,
5690 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005691 ipw_remove_current_network(priv);
5692 }
5693
5694 ipw_disassociate(priv);
5695 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005696 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005697 return;
5698 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005699}
5700
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005701static int ipw_best_network(struct ipw_priv *priv,
5702 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005703 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005704{
5705 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005706 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005707
5708 /* Verify that this network's capability is compatible with the
5709 * current mode (AdHoc or Infrastructure) */
5710 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005711 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005712 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5713 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005714 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005715 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005716 print_ssid(ssid, network->ssid,
5717 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005718 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005719 return 0;
5720 }
5721
James Ketrenos43f66a62005-03-25 12:31:53 -06005722 if (unlikely(roaming)) {
5723 /* If we are roaming, then ensure check if this is a valid
5724 * network to try and roam to */
5725 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005726 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005728 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005729 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005730 print_ssid(ssid, network->ssid,
5731 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005732 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005733 return 0;
5734 }
5735 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005736 /* If an ESSID has been configured then compare the broadcast
5737 * ESSID to ours */
5738 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005739 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005740 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005741 min(network->ssid_len, priv->essid_len)))) {
5742 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005743 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005744 print_ssid(ssid, network->ssid,
5745 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005746 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005747 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005748 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005749 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005750 print_ssid(ssid, priv->essid,
5751 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005752 return 0;
5753 }
5754 }
5755
5756 /* If the old network rate is better than this one, don't bother
5757 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005758 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005759 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005760 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005761 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005762 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005763 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5764 "'%s (%pM)' has a stronger signal.\n",
5765 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005766 print_ssid(ssid, match->network->ssid,
5767 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005768 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005769 return 0;
5770 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005771
James Ketrenos43f66a62005-03-25 12:31:53 -06005772 /* If this network has already had an association attempt within the
5773 * last 3 seconds, do not try and associate again... */
5774 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005775 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005776 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005777 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005779 print_ssid(ssid, network->ssid,
5780 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005781 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005782 jiffies_to_msecs(jiffies -
5783 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005784 return 0;
5785 }
5786
5787 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005788 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005789 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005790 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005791 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005792 print_ssid(ssid, network->ssid,
5793 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005794 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005795 jiffies_to_msecs(jiffies -
5796 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005798 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005799
Jeff Garzikbf794512005-07-31 13:07:26 -04005800 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005801 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005802 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005803 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005804 print_ssid(ssid, network->ssid,
5805 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005806 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 network->channel, priv->channel);
5808 return 0;
5809 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005810
James Ketrenos43f66a62005-03-25 12:31:53 -06005811 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005812 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005813 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005814 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005816 print_ssid(ssid, network->ssid,
5817 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005818 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005819 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005821 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005822 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005823 return 0;
5824 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005825
5826 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005827 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005828 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5829 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005830 print_ssid(ssid, network->ssid,
5831 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005832 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005833 return 0;
5834 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005835
James Ketrenos43f66a62005-03-25 12:31:53 -06005836 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005837 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005838 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005839 "because of invalid frequency/mode "
5840 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005841 print_ssid(ssid, network->ssid,
5842 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005843 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 return 0;
5845 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005846
Liu Hong1fe0adb2005-08-19 09:33:10 -05005847 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005848 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005849 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005850 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005851 print_ssid(ssid, network->ssid,
5852 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005853 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005854 return 0;
5855 }
5856
James Ketrenosea2b26e2005-08-24 21:25:16 -05005857 /* Ensure that the rates supported by the driver are compatible with
5858 * this AP, including verification of basic rates (mandatory) */
5859 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005860 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005861 "because configured rate mask excludes "
5862 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005863 print_ssid(ssid, network->ssid,
5864 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005865 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005866 return 0;
5867 }
5868
James Ketrenos43f66a62005-03-25 12:31:53 -06005869 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005870 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005871 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005872 print_ssid(ssid, network->ssid,
5873 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005874 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005875 return 0;
5876 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005877
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 /* TODO: Perform any further minimal comparititive tests. We do not
5879 * want to put too much policy logic here; intelligent scan selection
5880 * should occur within a generic IEEE 802.11 user space tool. */
5881
5882 /* Set up 'new' AP to this network */
5883 ipw_copy_rates(&match->rates, &rates);
5884 match->network = network;
5885
Johannes Berge1749612008-10-27 15:59:26 -07005886 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005887 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005888 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005889
5890 return 1;
5891}
5892
Jeff Garzikbf794512005-07-31 13:07:26 -04005893static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005894 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005895{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005896 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005897 int i;
5898
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 /*
5900 * For the purposes of scanning, we can set our wireless mode
5901 * to trigger scans across combinations of bands, but when it
5902 * comes to creating a new ad-hoc network, we have tell the FW
5903 * exactly which band to use.
5904 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005905 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 * chossen band. Attempting to create a new ad-hoc network
5907 * with an invalid channel for wireless mode will trigger a
5908 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005909 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005910 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005911 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5912 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005913 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005914 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005915 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005916 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005917 IPW_WARNING("Overriding invalid channel\n");
5918 priv->channel = geo->a[0].channel;
5919 }
5920 break;
5921
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005922 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005923 if (priv->ieee->mode & IEEE_G)
5924 network->mode = IEEE_G;
5925 else
5926 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005927 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005928 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005929 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005930 IPW_WARNING("Overriding invalid channel\n");
5931 priv->channel = geo->bg[0].channel;
5932 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005933 break;
5934
5935 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005936 IPW_WARNING("Overriding invalid channel\n");
5937 if (priv->ieee->mode & IEEE_A) {
5938 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005939 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005940 } else if (priv->ieee->mode & IEEE_G) {
5941 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005942 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005943 } else {
5944 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005945 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005946 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005947 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005948 }
5949
5950 network->channel = priv->channel;
5951 priv->config |= CFG_ADHOC_PERSIST;
5952 ipw_create_bssid(priv, network->bssid);
5953 network->ssid_len = priv->essid_len;
5954 memcpy(network->ssid, priv->essid, priv->essid_len);
5955 memset(&network->stats, 0, sizeof(network->stats));
5956 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005957 if (!(priv->config & CFG_PREAMBLE_LONG))
5958 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005959 if (priv->capability & CAP_PRIVACY_ON)
5960 network->capability |= WLAN_CAPABILITY_PRIVACY;
5961 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005962 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005963 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005964 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005965 &priv->rates.supported_rates[network->rates_len],
5966 network->rates_ex_len);
5967 network->last_scanned = 0;
5968 network->flags = 0;
5969 network->last_associate = 0;
5970 network->time_stamp[0] = 0;
5971 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005972 network->beacon_interval = 100; /* Default */
5973 network->listen_interval = 10; /* Default */
5974 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005975 network->wpa_ie_len = 0;
5976 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005977}
5978
James Ketrenosb095c382005-08-24 22:04:42 -05005979static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5980{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005981 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005982
5983 if (!(priv->ieee->sec.flags & (1 << index)))
5984 return;
5985
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005986 key.key_id = index;
5987 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5988 key.security_type = type;
5989 key.station_index = 0; /* always 0 for BSS */
5990 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005991 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005992 key.tx_counter[0] = cpu_to_le32(0);
5993 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005994
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005995 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005996}
5997
5998static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005999{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006000 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06006001 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06006002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006003 key.cmd_id = DINO_CMD_WEP_KEY;
6004 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006005
James Ketrenosb095c382005-08-24 22:04:42 -05006006 /* Note: AES keys cannot be set for multiple times.
6007 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04006008 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006009 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05006010 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006011 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006012 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06006013 }
6014
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006015 key.key_size = priv->ieee->sec.key_sizes[i];
6016 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05006017
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006018 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04006019 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006020}
6021
Zhu Yi1fbfea52005-08-05 17:22:56 +08006022static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6023{
6024 if (priv->ieee->host_encrypt)
6025 return;
6026
6027 switch (level) {
6028 case SEC_LEVEL_3:
6029 priv->sys_config.disable_unicast_decryption = 0;
6030 priv->ieee->host_decrypt = 0;
6031 break;
6032 case SEC_LEVEL_2:
6033 priv->sys_config.disable_unicast_decryption = 1;
6034 priv->ieee->host_decrypt = 1;
6035 break;
6036 case SEC_LEVEL_1:
6037 priv->sys_config.disable_unicast_decryption = 0;
6038 priv->ieee->host_decrypt = 0;
6039 break;
6040 case SEC_LEVEL_0:
6041 priv->sys_config.disable_unicast_decryption = 1;
6042 break;
6043 default:
6044 break;
6045 }
6046}
6047
6048static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6049{
6050 if (priv->ieee->host_encrypt)
6051 return;
6052
6053 switch (level) {
6054 case SEC_LEVEL_3:
6055 priv->sys_config.disable_multicast_decryption = 0;
6056 break;
6057 case SEC_LEVEL_2:
6058 priv->sys_config.disable_multicast_decryption = 1;
6059 break;
6060 case SEC_LEVEL_1:
6061 priv->sys_config.disable_multicast_decryption = 0;
6062 break;
6063 case SEC_LEVEL_0:
6064 priv->sys_config.disable_multicast_decryption = 1;
6065 break;
6066 default:
6067 break;
6068 }
6069}
6070
James Ketrenosb095c382005-08-24 22:04:42 -05006071static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6072{
6073 switch (priv->ieee->sec.level) {
6074 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006075 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6076 ipw_send_tgi_tx_key(priv,
6077 DCT_FLAG_EXT_SECURITY_CCM,
6078 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006079
Hong Liu567deaf2005-08-31 18:07:22 +08006080 if (!priv->ieee->host_mc_decrypt)
6081 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006082 break;
6083 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006084 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6085 ipw_send_tgi_tx_key(priv,
6086 DCT_FLAG_EXT_SECURITY_TKIP,
6087 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006088 break;
6089 case SEC_LEVEL_1:
6090 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006091 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6092 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006093 break;
6094 case SEC_LEVEL_0:
6095 default:
6096 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006097 }
6098}
6099
6100static void ipw_adhoc_check(void *data)
6101{
6102 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006103
James Ketrenosafbf30a2005-08-25 00:05:33 -05006104 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006105 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006106 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6107 IPW_DL_STATE | IPW_DL_ASSOC,
6108 "Missed beacon: %d - disassociate\n",
6109 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006110 ipw_remove_current_network(priv);
6111 ipw_disassociate(priv);
6112 return;
6113 }
6114
Jeff Garzikbf794512005-07-31 13:07:26 -04006115 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006116 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006117}
6118
David Howellsc4028952006-11-22 14:57:56 +00006119static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006120{
David Howellsc4028952006-11-22 14:57:56 +00006121 struct ipw_priv *priv =
6122 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006123 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006124 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006125 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006126}
6127
James Ketrenos43f66a62005-03-25 12:31:53 -06006128static void ipw_debug_config(struct ipw_priv *priv)
6129{
John W. Linville9387b7c2008-09-30 20:59:05 -04006130 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006131 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6132 "[CFG 0x%08X]\n", priv->config);
6133 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006134 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006135 else
6136 IPW_DEBUG_INFO("Channel unlocked.\n");
6137 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006138 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006139 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006140 else
6141 IPW_DEBUG_INFO("ESSID unlocked.\n");
6142 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006143 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006144 else
6145 IPW_DEBUG_INFO("BSSID unlocked.\n");
6146 if (priv->capability & CAP_PRIVACY_ON)
6147 IPW_DEBUG_INFO("PRIVACY on\n");
6148 else
6149 IPW_DEBUG_INFO("PRIVACY off\n");
6150 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6151}
James Ketrenos43f66a62005-03-25 12:31:53 -06006152
Arjan van de Ven858119e2006-01-14 13:20:43 -08006153static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006154{
6155 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006156 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006157 u32 reg;
6158 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006159 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006160
Jeff Garzikbf794512005-07-31 13:07:26 -04006161 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006162 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006163
James Ketrenos43f66a62005-03-25 12:31:53 -06006164 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006165 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006166 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006167 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006168 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006169 IPW_DEBUG_WX
6170 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006171 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006172 break;
6173 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006174
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006175 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006176 break;
6177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006178 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006179 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006180 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006181 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006182 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006183 IPW_DEBUG_WX
6184 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006185 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006186 }
6187 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006188 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006189
6190 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006191 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6192 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006193 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006194 IPW_DEBUG_WX
6195 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006196 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006197 break;
6198 }
6199
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006200 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6201 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6202 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006203 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006204
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006205 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6206 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6207 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006208 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006209
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006210 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6211 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6212 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006213 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006214
Reinette Chatre21f8a732009-08-18 10:25:05 -07006215 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006216 break;
6217 }
6218
Reinette Chatre21f8a732009-08-18 10:25:05 -07006219 fr.tx_rates = cpu_to_le16(new_tx_rates);
6220
James Ketrenos43f66a62005-03-25 12:31:53 -06006221 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006222 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006223}
6224
James Ketrenosea2b26e2005-08-24 21:25:16 -05006225static void ipw_abort_scan(struct ipw_priv *priv)
6226{
6227 int err;
6228
6229 if (priv->status & STATUS_SCAN_ABORTING) {
6230 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6231 return;
6232 }
6233 priv->status |= STATUS_SCAN_ABORTING;
6234
6235 err = ipw_send_scan_abort(priv);
6236 if (err)
6237 IPW_DEBUG_HC("Request to abort scan failed.\n");
6238}
6239
James Ketrenosafbf30a2005-08-25 00:05:33 -05006240static void ipw_add_scan_channels(struct ipw_priv *priv,
6241 struct ipw_scan_request_ext *scan,
6242 int scan_type)
6243{
6244 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006245 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006246 int i;
6247
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006248 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006249
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006250 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006251 int start = channel_index;
6252 for (i = 0; i < geo->a_channels; i++) {
6253 if ((priv->status & STATUS_ASSOCIATED) &&
6254 geo->a[i].channel == priv->channel)
6255 continue;
6256 channel_index++;
6257 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006258 ipw_set_scan_type(scan, channel_index,
6259 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006260 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006261 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6262 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006263 }
6264
6265 if (start != channel_index) {
6266 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6267 (channel_index - start);
6268 channel_index++;
6269 }
6270 }
6271
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006272 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006273 int start = channel_index;
6274 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006275 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006276 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006277 /* nop out the list */
6278 [0] = 0
6279 };
6280
6281 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006282 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006283 channel =
6284 priv->speed_scan[priv->speed_scan_pos];
6285 if (channel == 0) {
6286 priv->speed_scan_pos = 0;
6287 channel = priv->speed_scan[0];
6288 }
6289 if ((priv->status & STATUS_ASSOCIATED) &&
6290 channel == priv->channel) {
6291 priv->speed_scan_pos++;
6292 continue;
6293 }
6294
6295 /* If this channel has already been
6296 * added in scan, break from loop
6297 * and this will be the first channel
6298 * in the next scan.
6299 */
6300 if (channels[channel - 1] != 0)
6301 break;
6302
6303 channels[channel - 1] = 1;
6304 priv->speed_scan_pos++;
6305 channel_index++;
6306 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006307 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006308 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006309 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006310 geo->bg[index].
6311 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006312 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006313 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6314 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006315 }
6316 } else {
6317 for (i = 0; i < geo->bg_channels; i++) {
6318 if ((priv->status & STATUS_ASSOCIATED) &&
6319 geo->bg[i].channel == priv->channel)
6320 continue;
6321 channel_index++;
6322 scan->channels_list[channel_index] =
6323 geo->bg[i].channel;
6324 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006325 geo->bg[i].
6326 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006327 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006328 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6329 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006330 }
6331 }
6332
6333 if (start != channel_index) {
6334 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6335 (channel_index - start);
6336 }
6337 }
6338}
6339
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006340static int ipw_passive_dwell_time(struct ipw_priv *priv)
6341{
6342 /* staying on passive channels longer than the DTIM interval during a
6343 * scan, while associated, causes the firmware to cancel the scan
6344 * without notification. Hence, don't stay on passive channels longer
6345 * than the beacon interval.
6346 */
6347 if (priv->status & STATUS_ASSOCIATED
6348 && priv->assoc_network->beacon_interval > 10)
6349 return priv->assoc_network->beacon_interval - 10;
6350 else
6351 return 120;
6352}
6353
Dan Williamsea177302008-06-02 17:51:23 -04006354static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006355{
6356 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006357 int err = 0, scan_type;
6358
6359 if (!(priv->status & STATUS_INIT) ||
6360 (priv->status & STATUS_EXIT_PENDING))
6361 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006362
Zhu Yi46441512006-01-24 16:37:59 +08006363 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006364
Dan Williamsea177302008-06-02 17:51:23 -04006365 if (direct && (priv->direct_scan_ssid_len == 0)) {
6366 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6367 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6368 goto done;
6369 }
6370
James Ketrenosea2b26e2005-08-24 21:25:16 -05006371 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006372 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6373 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6374 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006375 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006376 }
6377
James Ketrenosafbf30a2005-08-25 00:05:33 -05006378 if (!(priv->status & STATUS_SCAN_FORCED) &&
6379 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006380 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006381 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6382 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006383 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006384 }
6385
6386 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006387 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6388 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6389 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006390 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006391 }
6392
6393 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006394 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395
Zhu Yi094c4d22006-08-21 11:39:03 +08006396 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006397 IPW_DEBUG_WX("use passive scanning\n");
6398 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006399 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006400 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006401 ipw_add_scan_channels(priv, &scan, scan_type);
6402 goto send_request;
6403 }
6404
6405 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006406 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006407 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006408 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006409 else
6410 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006411 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006412
James Ketrenosa613bff2005-08-24 21:43:11 -05006413 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006414 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006415
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006416 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6417 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006418 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006419
James Ketrenosb095c382005-08-24 22:04:42 -05006420#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006421 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006422 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006423 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006424
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006425 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6426 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006427 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006428 channel = priv->channel;
6429 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006430
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006431 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006432 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006433 channel = priv->channel;
6434 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006435
James Ketrenosb095c382005-08-24 22:04:42 -05006436 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006437 band = (u8) (IPW_B_MODE << 6) | 1;
6438 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006439 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006440 }
6441
James Ketrenosb095c382005-08-24 22:04:42 -05006442 scan.channels_list[0] = band;
6443 scan.channels_list[1] = channel;
6444 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006445
James Ketrenosb095c382005-08-24 22:04:42 -05006446 /* NOTE: The card will sit on this channel for this time
6447 * period. Scan aborts are timing sensitive and frequently
6448 * result in firmware restarts. As such, it is best to
6449 * set a small dwell_time here and just keep re-issuing
6450 * scans. Otherwise fast channel hopping will not actually
6451 * hop channels.
6452 *
6453 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006454 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006455 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006456 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006457#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006458 /* Honor direct scans first, otherwise if we are roaming make
6459 * this a direct scan for the current network. Finally,
6460 * ensure that every other scan is a fast channel hop scan */
6461 if (direct) {
6462 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6463 priv->direct_scan_ssid_len);
6464 if (err) {
6465 IPW_DEBUG_HC("Attempt to send SSID command "
6466 "failed\n");
6467 goto done;
6468 }
6469
6470 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6471 } else if ((priv->status & STATUS_ROAMING)
6472 || (!(priv->status & STATUS_ASSOCIATED)
6473 && (priv->config & CFG_STATIC_ESSID)
6474 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006475 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6476 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006477 IPW_DEBUG_HC("Attempt to send SSID command "
6478 "failed.\n");
6479 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006480 }
6481
6482 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006483 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006484 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006485
James Ketrenosafbf30a2005-08-25 00:05:33 -05006486 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006487#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006488 }
6489#endif
6490
Zhu Yi094c4d22006-08-21 11:39:03 +08006491send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006492 err = ipw_send_scan_request_ext(priv, &scan);
6493 if (err) {
6494 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006495 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006496 }
6497
6498 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006499 if (direct) {
6500 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6501 priv->direct_scan_ssid_len = 0;
6502 } else
6503 priv->status &= ~STATUS_SCAN_PENDING;
6504
James Ketrenosafbf30a2005-08-25 00:05:33 -05006505 queue_delayed_work(priv->workqueue, &priv->scan_check,
6506 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006507done:
Zhu Yi46441512006-01-24 16:37:59 +08006508 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006509 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006510}
6511
David Howellsc4028952006-11-22 14:57:56 +00006512static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006513{
David Howellsc4028952006-11-22 14:57:56 +00006514 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006515 container_of(work, struct ipw_priv, request_passive_scan.work);
6516 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006517}
6518
6519static void ipw_request_scan(struct work_struct *work)
6520{
6521 struct ipw_priv *priv =
6522 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006523 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6524}
6525
6526static void ipw_request_direct_scan(struct work_struct *work)
6527{
6528 struct ipw_priv *priv =
6529 container_of(work, struct ipw_priv, request_direct_scan.work);
6530 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006531}
6532
6533static void ipw_bg_abort_scan(struct work_struct *work)
6534{
6535 struct ipw_priv *priv =
6536 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006537 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006538 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006539 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006540}
6541
James Ketrenosea2b26e2005-08-24 21:25:16 -05006542static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6543{
James Ketrenosb095c382005-08-24 22:04:42 -05006544 /* This is called when wpa_supplicant loads and closes the driver
6545 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006546 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006547 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006548}
6549
James Ketrenosea2b26e2005-08-24 21:25:16 -05006550static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6551{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006552 struct libipw_device *ieee = priv->ieee;
6553 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006554 .flags = SEC_AUTH_MODE,
6555 };
6556 int ret = 0;
6557
James Ketrenosafbf30a2005-08-25 00:05:33 -05006558 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006559 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6560 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006561 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006562 sec.auth_mode = WLAN_AUTH_OPEN;
6563 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006564 } else if (value & IW_AUTH_ALG_LEAP) {
6565 sec.auth_mode = WLAN_AUTH_LEAP;
6566 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006567 } else
6568 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569
6570 if (ieee->set_security)
6571 ieee->set_security(ieee->dev, &sec);
6572 else
6573 ret = -EOPNOTSUPP;
6574
6575 return ret;
6576}
6577
Adrian Bunka73e22b2006-01-21 01:39:42 +01006578static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6579 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006580{
6581 /* make sure WPA is enabled */
6582 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006583}
6584
6585static int ipw_set_rsn_capa(struct ipw_priv *priv,
6586 char *capabilities, int length)
6587{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6589
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006590 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006591 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006592}
6593
James Ketrenosafbf30a2005-08-25 00:05:33 -05006594/*
6595 * WE-18 support
6596 */
6597
6598/* SIOCSIWGENIE */
6599static int ipw_wx_set_genie(struct net_device *dev,
6600 struct iw_request_info *info,
6601 union iwreq_data *wrqu, char *extra)
6602{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006603 struct ipw_priv *priv = libipw_priv(dev);
6604 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006605 u8 *buf;
6606 int err = 0;
6607
6608 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6609 (wrqu->data.length && extra == NULL))
6610 return -EINVAL;
6611
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 if (wrqu->data.length) {
6613 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6614 if (buf == NULL) {
6615 err = -ENOMEM;
6616 goto out;
6617 }
6618
6619 memcpy(buf, extra, wrqu->data.length);
6620 kfree(ieee->wpa_ie);
6621 ieee->wpa_ie = buf;
6622 ieee->wpa_ie_len = wrqu->data.length;
6623 } else {
6624 kfree(ieee->wpa_ie);
6625 ieee->wpa_ie = NULL;
6626 ieee->wpa_ie_len = 0;
6627 }
6628
6629 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6630 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006631 return err;
6632}
6633
6634/* SIOCGIWGENIE */
6635static int ipw_wx_get_genie(struct net_device *dev,
6636 struct iw_request_info *info,
6637 union iwreq_data *wrqu, char *extra)
6638{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006639 struct ipw_priv *priv = libipw_priv(dev);
6640 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006641 int err = 0;
6642
James Ketrenosafbf30a2005-08-25 00:05:33 -05006643 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6644 wrqu->data.length = 0;
6645 goto out;
6646 }
6647
6648 if (wrqu->data.length < ieee->wpa_ie_len) {
6649 err = -E2BIG;
6650 goto out;
6651 }
6652
6653 wrqu->data.length = ieee->wpa_ie_len;
6654 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6655
6656 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006657 return err;
6658}
6659
Zhu Yi1fbfea52005-08-05 17:22:56 +08006660static int wext_cipher2level(int cipher)
6661{
6662 switch (cipher) {
6663 case IW_AUTH_CIPHER_NONE:
6664 return SEC_LEVEL_0;
6665 case IW_AUTH_CIPHER_WEP40:
6666 case IW_AUTH_CIPHER_WEP104:
6667 return SEC_LEVEL_1;
6668 case IW_AUTH_CIPHER_TKIP:
6669 return SEC_LEVEL_2;
6670 case IW_AUTH_CIPHER_CCMP:
6671 return SEC_LEVEL_3;
6672 default:
6673 return -1;
6674 }
6675}
6676
James Ketrenosafbf30a2005-08-25 00:05:33 -05006677/* SIOCSIWAUTH */
6678static int ipw_wx_set_auth(struct net_device *dev,
6679 struct iw_request_info *info,
6680 union iwreq_data *wrqu, char *extra)
6681{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006682 struct ipw_priv *priv = libipw_priv(dev);
6683 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006684 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006685 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006686 unsigned long flags;
6687 int ret = 0;
6688
6689 switch (param->flags & IW_AUTH_INDEX) {
6690 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006691 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006692 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006693 ipw_set_hw_decrypt_unicast(priv,
6694 wext_cipher2level(param->value));
6695 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006696 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006697 ipw_set_hw_decrypt_multicast(priv,
6698 wext_cipher2level(param->value));
6699 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006700 case IW_AUTH_KEY_MGMT:
6701 /*
6702 * ipw2200 does not use these parameters
6703 */
6704 break;
6705
6706 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006707 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006708 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006709 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006710
6711 flags = crypt->ops->get_flags(crypt->priv);
6712
6713 if (param->value)
6714 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6715 else
6716 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6717
6718 crypt->ops->set_flags(flags, crypt->priv);
6719
6720 break;
6721
6722 case IW_AUTH_DROP_UNENCRYPTED:{
6723 /* HACK:
6724 *
6725 * wpa_supplicant calls set_wpa_enabled when the driver
6726 * is loaded and unloaded, regardless of if WPA is being
6727 * used. No other calls are made which can be used to
6728 * determine if encryption will be used or not prior to
6729 * association being expected. If encryption is not being
6730 * used, drop_unencrypted is set to false, else true -- we
6731 * can use this to determine if the CAP_PRIVACY_ON bit should
6732 * be set.
6733 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006734 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006735 .flags = SEC_ENABLED,
6736 .enabled = param->value,
6737 };
6738 priv->ieee->drop_unencrypted = param->value;
6739 /* We only change SEC_LEVEL for open mode. Others
6740 * are set by ipw_wpa_set_encryption.
6741 */
6742 if (!param->value) {
6743 sec.flags |= SEC_LEVEL;
6744 sec.level = SEC_LEVEL_0;
6745 } else {
6746 sec.flags |= SEC_LEVEL;
6747 sec.level = SEC_LEVEL_1;
6748 }
6749 if (priv->ieee->set_security)
6750 priv->ieee->set_security(priv->ieee->dev, &sec);
6751 break;
6752 }
6753
6754 case IW_AUTH_80211_AUTH_ALG:
6755 ret = ipw_wpa_set_auth_algs(priv, param->value);
6756 break;
6757
6758 case IW_AUTH_WPA_ENABLED:
6759 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006760 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006761 break;
6762
6763 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6764 ieee->ieee802_1x = param->value;
6765 break;
6766
James Ketrenosafbf30a2005-08-25 00:05:33 -05006767 case IW_AUTH_PRIVACY_INVOKED:
6768 ieee->privacy_invoked = param->value;
6769 break;
6770
6771 default:
6772 return -EOPNOTSUPP;
6773 }
6774 return ret;
6775}
6776
6777/* SIOCGIWAUTH */
6778static int ipw_wx_get_auth(struct net_device *dev,
6779 struct iw_request_info *info,
6780 union iwreq_data *wrqu, char *extra)
6781{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006782 struct ipw_priv *priv = libipw_priv(dev);
6783 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006784 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006785 struct iw_param *param = &wrqu->param;
6786 int ret = 0;
6787
6788 switch (param->flags & IW_AUTH_INDEX) {
6789 case IW_AUTH_WPA_VERSION:
6790 case IW_AUTH_CIPHER_PAIRWISE:
6791 case IW_AUTH_CIPHER_GROUP:
6792 case IW_AUTH_KEY_MGMT:
6793 /*
6794 * wpa_supplicant will control these internally
6795 */
6796 ret = -EOPNOTSUPP;
6797 break;
6798
6799 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006800 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006801 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006802 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006803
6804 param->value = (crypt->ops->get_flags(crypt->priv) &
6805 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6806
6807 break;
6808
6809 case IW_AUTH_DROP_UNENCRYPTED:
6810 param->value = ieee->drop_unencrypted;
6811 break;
6812
6813 case IW_AUTH_80211_AUTH_ALG:
6814 param->value = ieee->sec.auth_mode;
6815 break;
6816
6817 case IW_AUTH_WPA_ENABLED:
6818 param->value = ieee->wpa_enabled;
6819 break;
6820
6821 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6822 param->value = ieee->ieee802_1x;
6823 break;
6824
6825 case IW_AUTH_ROAMING_CONTROL:
6826 case IW_AUTH_PRIVACY_INVOKED:
6827 param->value = ieee->privacy_invoked;
6828 break;
6829
6830 default:
6831 return -EOPNOTSUPP;
6832 }
6833 return 0;
6834}
6835
6836/* SIOCSIWENCODEEXT */
6837static int ipw_wx_set_encodeext(struct net_device *dev,
6838 struct iw_request_info *info,
6839 union iwreq_data *wrqu, char *extra)
6840{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006841 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006842 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6843
6844 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006845 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006846 /* IPW HW can't build TKIP MIC,
6847 host decryption still needed */
6848 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6849 priv->ieee->host_mc_decrypt = 1;
6850 else {
6851 priv->ieee->host_encrypt = 0;
6852 priv->ieee->host_encrypt_msdu = 1;
6853 priv->ieee->host_decrypt = 1;
6854 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006855 } else {
6856 priv->ieee->host_encrypt = 0;
6857 priv->ieee->host_encrypt_msdu = 0;
6858 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006859 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006860 }
6861 }
6862
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006863 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006864}
6865
6866/* SIOCGIWENCODEEXT */
6867static int ipw_wx_get_encodeext(struct net_device *dev,
6868 struct iw_request_info *info,
6869 union iwreq_data *wrqu, char *extra)
6870{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006871 struct ipw_priv *priv = libipw_priv(dev);
6872 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006873}
6874
6875/* SIOCSIWMLME */
6876static int ipw_wx_set_mlme(struct net_device *dev,
6877 struct iw_request_info *info,
6878 union iwreq_data *wrqu, char *extra)
6879{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006880 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006881 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006882 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006883
6884 reason = cpu_to_le16(mlme->reason_code);
6885
6886 switch (mlme->cmd) {
6887 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006888 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006889 break;
6890
6891 case IW_MLME_DISASSOC:
6892 ipw_disassociate(priv);
6893 break;
6894
6895 default:
6896 return -EOPNOTSUPP;
6897 }
6898 return 0;
6899}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006900
Zhu Yie43e3c12006-04-13 17:20:45 +08006901#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006902
6903/* QoS */
6904/*
6905* get the modulation type of the current network or
6906* the card current mode
6907*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006908static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006909{
6910 u8 mode = 0;
6911
6912 if (priv->status & STATUS_ASSOCIATED) {
6913 unsigned long flags;
6914
6915 spin_lock_irqsave(&priv->ieee->lock, flags);
6916 mode = priv->assoc_network->mode;
6917 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6918 } else {
6919 mode = priv->ieee->mode;
6920 }
Frans Pop9fd1ea42010-03-24 19:46:31 +01006921 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
James Ketrenosb095c382005-08-24 22:04:42 -05006922 return mode;
6923}
6924
6925/*
6926* Handle management frame beacon and probe response
6927*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006928static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6929 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006930 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006931{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006932 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006933
James Ketrenosafbf30a2005-08-25 00:05:33 -05006934 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006935 network->qos_data.active = network->qos_data.supported;
6936
6937 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006938 if (active_network &&
6939 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006940 network->qos_data.active = network->qos_data.supported;
6941
6942 if ((network->qos_data.active == 1) && (active_network == 1) &&
6943 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6944 (network->qos_data.old_param_count !=
6945 network->qos_data.param_count)) {
6946 network->qos_data.old_param_count =
6947 network->qos_data.param_count;
6948 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006949 IPW_DEBUG_QOS("QoS parameters change call "
6950 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006951 }
6952 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006953 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6954 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006955 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006956 else
6957 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006958 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006959
James Ketrenosb095c382005-08-24 22:04:42 -05006960 if ((network->qos_data.active == 1) && (active_network == 1)) {
Frans Pop9fd1ea42010-03-24 19:46:31 +01006961 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006962 schedule_work(&priv->qos_activate);
6963 }
6964
6965 network->qos_data.active = 0;
6966 network->qos_data.supported = 0;
6967 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006968 if ((priv->status & STATUS_ASSOCIATED) &&
6969 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6970 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006971 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006972 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006973 priv->assoc_network->ssid_len) &&
6974 !memcmp(network->ssid,
6975 priv->assoc_network->ssid,
6976 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006977 queue_work(priv->workqueue,
6978 &priv->merge_networks);
6979 }
James Ketrenosb095c382005-08-24 22:04:42 -05006980 }
6981
6982 return 0;
6983}
6984
6985/*
6986* This function set up the firmware to support QoS. It sends
6987* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6988*/
6989static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006990 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006991{
6992 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006993 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6994 struct libipw_qos_parameters *active_one = NULL;
6995 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006996 u32 burst_duration;
6997 int i;
6998 u8 type;
6999
7000 type = ipw_qos_current_mode(priv);
7001
7002 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7003 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7004 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7005 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7006
7007 if (qos_network_data == NULL) {
7008 if (type == IEEE_B) {
7009 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7010 active_one = &def_parameters_CCK;
7011 } else
7012 active_one = &def_parameters_OFDM;
7013
James Ketrenosafbf30a2005-08-25 00:05:33 -05007014 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007015 burst_duration = ipw_qos_get_burst_duration(priv);
7016 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007017 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05007018 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007019 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007020 if (type == IEEE_B) {
7021 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7022 type);
7023 if (priv->qos_data.qos_enable == 0)
7024 active_one = &def_parameters_CCK;
7025 else
7026 active_one = priv->qos_data.def_qos_parm_CCK;
7027 } else {
7028 if (priv->qos_data.qos_enable == 0)
7029 active_one = &def_parameters_OFDM;
7030 else
7031 active_one = priv->qos_data.def_qos_parm_OFDM;
7032 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007033 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007034 } else {
7035 unsigned long flags;
7036 int active;
7037
7038 spin_lock_irqsave(&priv->ieee->lock, flags);
7039 active_one = &(qos_network_data->parameters);
7040 qos_network_data->old_param_count =
7041 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007042 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007043 active = qos_network_data->supported;
7044 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7045
7046 if (active == 0) {
7047 burst_duration = ipw_qos_get_burst_duration(priv);
7048 for (i = 0; i < QOS_QUEUE_NUM; i++)
7049 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007050 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007051 }
7052 }
7053
7054 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007055 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007056 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007057 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007058 if (err)
7059 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7060
7061 return err;
7062}
7063
7064/*
7065* send IPW_CMD_WME_INFO to the firmware
7066*/
7067static int ipw_qos_set_info_element(struct ipw_priv *priv)
7068{
7069 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007070 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007071
7072 if (priv == NULL)
7073 return -1;
7074
7075 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007076 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007077
7078 qos_info.version = QOS_VERSION_1;
7079 qos_info.ac_info = 0;
7080
7081 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7082 qos_info.qui_type = QOS_OUI_TYPE;
7083 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7084
7085 ret = ipw_send_qos_info_command(priv, &qos_info);
7086 if (ret != 0) {
7087 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7088 }
7089 return ret;
7090}
7091
7092/*
7093* Set the QoS parameter with the association request structure
7094*/
7095static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007096 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007097{
7098 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007099 struct libipw_qos_data *qos_data = NULL;
7100 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007101 .supported = 1,
7102 .active = 1,
7103 };
7104
7105 switch (priv->ieee->iw_mode) {
7106 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007107 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007108
7109 qos_data = &ibss_data;
7110 break;
7111
7112 case IW_MODE_INFRA:
7113 qos_data = &network->qos_data;
7114 break;
7115
7116 default:
7117 BUG();
7118 break;
7119 }
7120
7121 err = ipw_qos_activate(priv, qos_data);
7122 if (err) {
7123 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7124 return err;
7125 }
7126
7127 if (priv->qos_data.qos_enable && qos_data->supported) {
7128 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7129 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7130 return ipw_qos_set_info_element(priv);
7131 }
7132
7133 return 0;
7134}
7135
7136/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007137* handling the beaconing responses. if we get different QoS setting
7138* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007139* setting
7140*/
7141static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007142 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007143{
7144 int ret = 0;
7145 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007146 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007147 int set_qos_param = 0;
7148
James Ketrenosafbf30a2005-08-25 00:05:33 -05007149 if ((priv == NULL) || (network == NULL) ||
7150 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007151 return ret;
7152
7153 if (!(priv->status & STATUS_ASSOCIATED))
7154 return ret;
7155
James Ketrenosafbf30a2005-08-25 00:05:33 -05007156 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007157 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007158
7159 spin_lock_irqsave(&priv->ieee->lock, flags);
7160 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007161 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007162 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007163 priv->assoc_network->qos_data.active = 1;
7164 if ((network->qos_data.old_param_count !=
7165 network->qos_data.param_count)) {
7166 set_qos_param = 1;
7167 network->qos_data.old_param_count =
7168 network->qos_data.param_count;
7169 }
7170
7171 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007172 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7173 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007174 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007175 else
7176 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007177 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007178 priv->assoc_network->qos_data.active = 0;
7179 priv->assoc_network->qos_data.supported = 0;
7180 set_qos_param = 1;
7181 }
7182
7183 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7184
7185 if (set_qos_param == 1)
7186 schedule_work(&priv->qos_activate);
7187
7188 return ret;
7189}
7190
7191static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7192{
7193 u32 ret = 0;
7194
7195 if ((priv == NULL))
7196 return 0;
7197
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007198 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007199 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007200 else
James Ketrenosb095c382005-08-24 22:04:42 -05007201 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007202
James Ketrenosb095c382005-08-24 22:04:42 -05007203 return ret;
7204}
7205
7206/*
7207* Initialize the setting of QoS global
7208*/
7209static void ipw_qos_init(struct ipw_priv *priv, int enable,
7210 int burst_enable, u32 burst_duration_CCK,
7211 u32 burst_duration_OFDM)
7212{
7213 priv->qos_data.qos_enable = enable;
7214
7215 if (priv->qos_data.qos_enable) {
7216 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7217 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7218 IPW_DEBUG_QOS("QoS is enabled\n");
7219 } else {
7220 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7221 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7222 IPW_DEBUG_QOS("QoS is not enabled\n");
7223 }
7224
7225 priv->qos_data.burst_enable = burst_enable;
7226
7227 if (burst_enable) {
7228 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7229 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7230 } else {
7231 priv->qos_data.burst_duration_CCK = 0;
7232 priv->qos_data.burst_duration_OFDM = 0;
7233 }
7234}
7235
7236/*
7237* map the packet priority to the right TX Queue
7238*/
7239static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7240{
7241 if (priority > 7 || !priv->qos_data.qos_enable)
7242 priority = 0;
7243
7244 return from_priority_to_tx_queue[priority] - 1;
7245}
7246
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007247static int ipw_is_qos_active(struct net_device *dev,
7248 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007249{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007250 struct ipw_priv *priv = libipw_priv(dev);
7251 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007252 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007253 u8 *daddr = skb->data + ETH_ALEN;
7254 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007255
7256 if (!(priv->status & STATUS_ASSOCIATED))
7257 return 0;
7258
7259 qos_data = &priv->assoc_network->qos_data;
7260
James Ketrenosb095c382005-08-24 22:04:42 -05007261 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7262 if (unicast == 0)
7263 qos_data->active = 0;
7264 else
7265 qos_data->active = qos_data->supported;
7266 }
James Ketrenosb095c382005-08-24 22:04:42 -05007267 active = qos_data->active;
7268 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007269 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7270 "unicast %d\n",
7271 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007272 if (active && priv->qos_data.qos_enable)
7273 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007274
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007275 return 0;
7276
7277}
7278/*
7279* add QoS parameter to the TX command
7280*/
7281static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7282 u16 priority,
7283 struct tfd_data *tfd)
7284{
7285 int tx_queue_id = 0;
7286
7287
7288 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7289 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7290
7291 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7292 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007293 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007294 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007295 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007296}
7297
7298/*
7299* background support to run QoS activate functionality
7300*/
David Howellsc4028952006-11-22 14:57:56 +00007301static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007302{
David Howellsc4028952006-11-22 14:57:56 +00007303 struct ipw_priv *priv =
7304 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007305
Zhu Yi46441512006-01-24 16:37:59 +08007306 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007307
7308 if (priv->status & STATUS_ASSOCIATED)
7309 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7310
Zhu Yi46441512006-01-24 16:37:59 +08007311 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007312}
7313
James Ketrenos3b9990c2005-08-19 13:18:55 -05007314static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007315 struct libipw_probe_response *resp,
7316 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007317{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007318 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007319 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7320 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007321
James Ketrenos3b9990c2005-08-19 13:18:55 -05007322 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007323
James Ketrenos3b9990c2005-08-19 13:18:55 -05007324 return 0;
7325}
James Ketrenosb095c382005-08-24 22:04:42 -05007326
James Ketrenos3b9990c2005-08-19 13:18:55 -05007327static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007328 struct libipw_beacon *resp,
7329 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007330{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007331 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007332 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7333 (network == priv->assoc_network));
7334
7335 ipw_qos_handle_probe_response(priv, active_network, network);
7336
7337 return 0;
7338}
7339
7340static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007341 struct libipw_assoc_response *resp,
7342 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007343{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007344 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007345 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007346 return 0;
7347}
7348
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007349static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007350 *qos_param)
7351{
Zhu Yi4e226992006-01-24 16:37:36 +08007352 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7353 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007354}
7355
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007356static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007357 *qos_param)
7358{
Zhu Yi4e226992006-01-24 16:37:36 +08007359 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7360 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007361}
7362
Zhu Yie43e3c12006-04-13 17:20:45 +08007363#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007364
James Ketrenos43f66a62005-03-25 12:31:53 -06007365static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007366 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007367 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007368{
7369 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007370 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007371
7372 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007373 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007374
7375 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007376 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007377 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007378 memcpy(priv->essid, network->ssid, priv->essid_len);
7379 }
7380
7381 network->last_associate = jiffies;
7382
7383 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7384 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007385 priv->assoc_request.auth_key = 0;
7386
James Ketrenos43f66a62005-03-25 12:31:53 -06007387 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007388 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007389 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007390 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7391
Zhu Yi1ba61e02006-02-15 13:00:55 +08007392 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007393 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007394
7395 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7396 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7397 priv->assoc_request.auth_type = AUTH_LEAP;
7398 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007399 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007400
James Ketrenosa613bff2005-08-24 21:43:11 -05007401 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007402 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007403 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7404 priv->ieee->wpa_ie_len);
7405 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007406
Jeff Garzikbf794512005-07-31 13:07:26 -04007407 /*
7408 * It is valid for our ieee device to support multiple modes, but
7409 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007410 * just one mode.
7411 */
7412 if (network->mode & priv->ieee->mode & IEEE_A)
7413 priv->assoc_request.ieee_mode = IPW_A_MODE;
7414 else if (network->mode & priv->ieee->mode & IEEE_G)
7415 priv->assoc_request.ieee_mode = IPW_G_MODE;
7416 else if (network->mode & priv->ieee->mode & IEEE_B)
7417 priv->assoc_request.ieee_mode = IPW_B_MODE;
7418
Al Viro5b5e8072007-12-27 01:54:06 -05007419 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007420 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7421 && !(priv->config & CFG_PREAMBLE_LONG)) {
7422 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7423 } else {
7424 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7425
7426 /* Clear the short preamble if we won't be supporting it */
7427 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007428 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007429 }
7430
James Ketrenosafbf30a2005-08-25 00:05:33 -05007431 /* Clear capability bits that aren't used in Ad Hoc */
7432 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7433 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007434 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007435
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007437 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007438 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007439 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007440 network->channel,
7441 ipw_modes[priv->assoc_request.ieee_mode],
7442 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007443 (priv->assoc_request.preamble_length ==
7444 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7445 network->capability &
7446 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007447 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007448 priv->capability & CAP_PRIVACY_ON ?
7449 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007450 "(open)") : "",
7451 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007452 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007453 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007454 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007455
Al Viro5b5e8072007-12-27 01:54:06 -05007456 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007457 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007458 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007459 priv->assoc_request.assoc_type = HC_IBSS_START;
7460 priv->assoc_request.assoc_tsf_msw = 0;
7461 priv->assoc_request.assoc_tsf_lsw = 0;
7462 } else {
7463 if (unlikely(roaming))
7464 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7465 else
7466 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007467 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7468 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007469 }
7470
James Ketrenosafbf30a2005-08-25 00:05:33 -05007471 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007472
7473 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7474 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007475 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007476 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007477 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007478 priv->assoc_request.atim_window = 0;
7479 }
7480
Al Viro5b5e8072007-12-27 01:54:06 -05007481 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007482
James Ketrenos43f66a62005-03-25 12:31:53 -06007483 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7484 if (err) {
7485 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7486 return err;
7487 }
7488
7489 rates->ieee_mode = priv->assoc_request.ieee_mode;
7490 rates->purpose = IPW_RATE_CONNECT;
7491 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007492
James Ketrenos43f66a62005-03-25 12:31:53 -06007493 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7494 priv->sys_config.dot11g_auto_detection = 1;
7495 else
7496 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007497
7498 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7499 priv->sys_config.answer_broadcast_ssid_probe = 1;
7500 else
7501 priv->sys_config.answer_broadcast_ssid_probe = 0;
7502
Zhu Yid685b8c2006-04-13 17:20:27 +08007503 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007504 if (err) {
7505 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7506 return err;
7507 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007508
James Ketrenos43f66a62005-03-25 12:31:53 -06007509 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007510 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007511 if (err) {
7512 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7513 return err;
7514 }
7515
7516 /*
7517 * If preemption is enabled, it is possible for the association
7518 * to complete before we return from ipw_send_associate. Therefore
7519 * we have to be sure and update our priviate data first.
7520 */
7521 priv->channel = network->channel;
7522 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007523 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007524 priv->status &= ~STATUS_SECURITY_UPDATED;
7525
7526 priv->assoc_network = network;
7527
Zhu Yie43e3c12006-04-13 17:20:45 +08007528#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007529 ipw_qos_association(priv, network);
7530#endif
7531
James Ketrenos43f66a62005-03-25 12:31:53 -06007532 err = ipw_send_associate(priv, &priv->assoc_request);
7533 if (err) {
7534 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7535 return err;
7536 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007537
Frans Pop9fd1ea42010-03-24 19:46:31 +01007538 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007539 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007540 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007541
7542 return 0;
7543}
7544
7545static void ipw_roam(void *data)
7546{
7547 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007548 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007549 struct ipw_network_match match = {
7550 .network = priv->assoc_network
7551 };
7552
7553 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007554 *
7555 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 * setting the status ROAM bit and requesting a scan.
7557 * 2. When the scan completes, it schedules the ROAM work
7558 * 3. The ROAM work looks at all of the known networks for one that
7559 * is a better network than the currently associated. If none
7560 * found, the ROAM process is over (ROAM bit cleared)
7561 * 4. If a better network is found, a disassociation request is
7562 * sent.
7563 * 5. When the disassociation completes, the roam work is again
7564 * scheduled. The second time through, the driver is no longer
7565 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007566 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007567 * 6. At this point ,the roaming process is complete and the ROAM
7568 * status bit is cleared.
7569 */
7570
7571 /* If we are no longer associated, and the roaming bit is no longer
7572 * set, then we are not actively roaming, so just return */
7573 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7574 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007575
James Ketrenos43f66a62005-03-25 12:31:53 -06007576 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007577 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007578 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007579 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007580 u8 rssi = priv->assoc_network->stats.rssi;
7581 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007582 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007583 list_for_each_entry(network, &priv->ieee->network_list, list) {
7584 if (network != priv->assoc_network)
7585 ipw_best_network(priv, &match, network, 1);
7586 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007587 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007588 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007589
James Ketrenos43f66a62005-03-25 12:31:53 -06007590 if (match.network == priv->assoc_network) {
7591 IPW_DEBUG_ASSOC("No better APs in this network to "
7592 "roam to.\n");
7593 priv->status &= ~STATUS_ROAMING;
7594 ipw_debug_config(priv);
7595 return;
7596 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007597
James Ketrenos43f66a62005-03-25 12:31:53 -06007598 ipw_send_disassociate(priv, 1);
7599 priv->assoc_network = match.network;
7600
7601 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007602 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007603
7604 /* Second pass through ROAM process -- request association */
7605 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7606 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7607 priv->status &= ~STATUS_ROAMING;
7608}
7609
David Howellsc4028952006-11-22 14:57:56 +00007610static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007611{
David Howellsc4028952006-11-22 14:57:56 +00007612 struct ipw_priv *priv =
7613 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007614 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007615 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007616 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007617}
7618
7619static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007620{
7621 struct ipw_priv *priv = data;
7622
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007623 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007624 struct ipw_network_match match = {
7625 .network = NULL
7626 };
7627 struct ipw_supported_rates *rates;
7628 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007629 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007630 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007631
James Ketrenosb095c382005-08-24 22:04:42 -05007632 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7633 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7634 return 0;
7635 }
7636
James Ketrenosc848d0a2005-08-24 21:56:24 -05007637 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007638 IPW_DEBUG_ASSOC("Not attempting association (already in "
7639 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007640 return 0;
7641 }
7642
Hong Liue6324722005-09-14 21:04:15 -05007643 if (priv->status & STATUS_DISASSOCIATING) {
7644 IPW_DEBUG_ASSOC("Not attempting association (in "
7645 "disassociating)\n ");
7646 queue_work(priv->workqueue, &priv->associate);
7647 return 0;
7648 }
7649
James Ketrenosc848d0a2005-08-24 21:56:24 -05007650 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007651 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7652 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007653 return 0;
7654 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007655
7656 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007657 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007658 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007659 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007660 }
7661
James Ketrenosa613bff2005-08-24 21:43:11 -05007662 /* Protect our use of the network_list */
7663 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007664 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007665 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007666
7667 network = match.network;
7668 rates = &match.rates;
7669
7670 if (network == NULL &&
7671 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7672 priv->config & CFG_ADHOC_CREATE &&
7673 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007674 priv->config & CFG_STATIC_CHANNEL) {
7675 /* Use oldest network if the free list is empty */
7676 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007677 struct libipw_network *oldest = NULL;
7678 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007679
7680 list_for_each_entry(target, &priv->ieee->network_list, list) {
7681 if ((oldest == NULL) ||
7682 (target->last_scanned < oldest->last_scanned))
7683 oldest = target;
7684 }
7685
7686 /* If there are no more slots, expire the oldest */
7687 list_del(&oldest->list);
7688 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007689 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007690 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007691 print_ssid(ssid, target->ssid,
7692 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007693 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007694 list_add_tail(&target->list,
7695 &priv->ieee->network_free_list);
7696 }
7697
James Ketrenos43f66a62005-03-25 12:31:53 -06007698 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007699 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007700 ipw_adhoc_create(priv, network);
7701 rates = &priv->rates;
7702 list_del(element);
7703 list_add_tail(&network->list, &priv->ieee->network_list);
7704 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007705 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007706
James Ketrenos43f66a62005-03-25 12:31:53 -06007707 /* If we reached the end of the list, then we don't have any valid
7708 * matching APs */
7709 if (!network) {
7710 ipw_debug_config(priv);
7711
James Ketrenosb095c382005-08-24 22:04:42 -05007712 if (!(priv->status & STATUS_SCANNING)) {
7713 if (!(priv->config & CFG_SPEED_SCAN))
7714 queue_delayed_work(priv->workqueue,
7715 &priv->request_scan,
7716 SCAN_INTERVAL);
7717 else
David Howellsc4028952006-11-22 14:57:56 +00007718 queue_delayed_work(priv->workqueue,
7719 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007720 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007721
James Ketrenosc848d0a2005-08-24 21:56:24 -05007722 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007723 }
7724
7725 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007726
7727 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007728}
Jeff Garzikbf794512005-07-31 13:07:26 -04007729
David Howellsc4028952006-11-22 14:57:56 +00007730static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007731{
David Howellsc4028952006-11-22 14:57:56 +00007732 struct ipw_priv *priv =
7733 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007734 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007735 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007736 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007737}
7738
James Ketrenosb095c382005-08-24 22:04:42 -05007739static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7740 struct sk_buff *skb)
7741{
7742 struct ieee80211_hdr *hdr;
7743 u16 fc;
7744
7745 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007746 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007747 if (!(fc & IEEE80211_FCTL_PROTECTED))
7748 return;
7749
7750 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007751 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007752 switch (priv->ieee->sec.level) {
7753 case SEC_LEVEL_3:
7754 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007755 memmove(skb->data + LIBIPW_3ADDR_LEN,
7756 skb->data + LIBIPW_3ADDR_LEN + 8,
7757 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007758 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007759 break;
7760 case SEC_LEVEL_2:
7761 break;
7762 case SEC_LEVEL_1:
7763 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007764 memmove(skb->data + LIBIPW_3ADDR_LEN,
7765 skb->data + LIBIPW_3ADDR_LEN + 4,
7766 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007767 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007768 break;
7769 case SEC_LEVEL_0:
7770 break;
7771 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007772 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -05007773 priv->ieee->sec.level);
7774 break;
7775 }
7776}
7777
7778static void ipw_handle_data_packet(struct ipw_priv *priv,
7779 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007780 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007781{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007782 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007783 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007784 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7785
7786 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007787 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007788
Jeff Garzikbf794512005-07-31 13:07:26 -04007789 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007790 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007791 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007792 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007793 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007794 priv->wstats.discard.misc++;
7795 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7796 return;
7797 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007798 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007799 priv->wstats.discard.misc++;
7800 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7801 return;
7802 }
7803
7804 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007805 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007806
7807 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007808 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007809
7810 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7811
James Ketrenosb095c382005-08-24 22:04:42 -05007812 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007813 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007814 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007815 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007816 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007817 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7818
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007819 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007820 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007821 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007822 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007823 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007824 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007825}
7826
Zhu Yi459d4082006-04-13 17:21:00 +08007827#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007828static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7829 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007830 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007831{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007832 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007833 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7834 struct ipw_rx_frame *frame = &pkt->u.frame;
7835
7836 /* initial pull of some data */
7837 u16 received_channel = frame->received_channel;
7838 u8 antennaAndPhy = frame->antennaAndPhy;
7839 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7840 u16 pktrate = frame->rate;
7841
7842 /* Magic struct that slots into the radiotap header -- no reason
7843 * to build this manually element by element, we can write it much
7844 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007845 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007846
7847 short len = le16_to_cpu(pkt->u.frame.length);
7848
7849 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007850 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007851
7852 /* We only process data packets if the
7853 * interface is open */
7854 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7855 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007856 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007857 priv->wstats.discard.misc++;
7858 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7859 return;
7860 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007861 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007862 priv->wstats.discard.misc++;
7863 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7864 return;
7865 }
7866
7867 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7868 * that now */
7869 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7870 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007871 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007872 priv->wstats.discard.misc++;
7873 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7874 return;
7875 }
7876
7877 /* copy the frame itself */
7878 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7879 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7880
Mike Kershaw24a47db2005-08-26 00:41:54 -05007881 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7882
7883 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7884 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007885 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007886
7887 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007888 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7889 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007890 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007891 (1 << IEEE80211_RADIOTAP_RATE) |
7892 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7893 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007894 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007895 (1 << IEEE80211_RADIOTAP_ANTENNA));
7896
7897 /* Zero the flags, we'll add to them as we go */
7898 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007899 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7900 frame->parent_tsf[2] << 16 |
7901 frame->parent_tsf[1] << 8 |
7902 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007903
7904 /* Convert signal to DBM */
7905 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007906 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007907
7908 /* Convert the channel data and set the flags */
7909 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7910 if (received_channel > 14) { /* 802.11a */
7911 ipw_rt->rt_chbitmask =
7912 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7913 } else if (antennaAndPhy & 32) { /* 802.11b */
7914 ipw_rt->rt_chbitmask =
7915 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7916 } else { /* 802.11g */
7917 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007918 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007919 }
7920
7921 /* set the rate in multiples of 500k/s */
7922 switch (pktrate) {
7923 case IPW_TX_RATE_1MB:
7924 ipw_rt->rt_rate = 2;
7925 break;
7926 case IPW_TX_RATE_2MB:
7927 ipw_rt->rt_rate = 4;
7928 break;
7929 case IPW_TX_RATE_5MB:
7930 ipw_rt->rt_rate = 10;
7931 break;
7932 case IPW_TX_RATE_6MB:
7933 ipw_rt->rt_rate = 12;
7934 break;
7935 case IPW_TX_RATE_9MB:
7936 ipw_rt->rt_rate = 18;
7937 break;
7938 case IPW_TX_RATE_11MB:
7939 ipw_rt->rt_rate = 22;
7940 break;
7941 case IPW_TX_RATE_12MB:
7942 ipw_rt->rt_rate = 24;
7943 break;
7944 case IPW_TX_RATE_18MB:
7945 ipw_rt->rt_rate = 36;
7946 break;
7947 case IPW_TX_RATE_24MB:
7948 ipw_rt->rt_rate = 48;
7949 break;
7950 case IPW_TX_RATE_36MB:
7951 ipw_rt->rt_rate = 72;
7952 break;
7953 case IPW_TX_RATE_48MB:
7954 ipw_rt->rt_rate = 96;
7955 break;
7956 case IPW_TX_RATE_54MB:
7957 ipw_rt->rt_rate = 108;
7958 break;
7959 default:
7960 ipw_rt->rt_rate = 0;
7961 break;
7962 }
7963
7964 /* antenna number */
7965 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7966
7967 /* set the preamble flag if we have it */
7968 if ((antennaAndPhy & 64))
7969 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7970
7971 /* Set the size of the skb to the size of the frame */
7972 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007973
7974 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7975
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007976 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007977 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007978 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007979 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007980 /* no LED during capture */
7981 }
7982}
7983#endif
7984
Zhu Yid685b8c2006-04-13 17:20:27 +08007985#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007986#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007987 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7988 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7989
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007990#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007991 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7992
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007993#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007994 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7995
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007996#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007997 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7998
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007999#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008000 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8001
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008002#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08008003 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8004
8005static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8006 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008007 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08008008{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008009 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08008010 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8011 struct ipw_rx_frame *frame = &pkt->u.frame;
8012 struct ipw_rt_hdr *ipw_rt;
8013
8014 /* First cache any information we need before we overwrite
8015 * the information provided in the skb from the hardware */
8016 struct ieee80211_hdr *hdr;
8017 u16 channel = frame->received_channel;
8018 u8 phy_flags = frame->antennaAndPhy;
8019 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008020 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08008021 u8 rate = frame->rate;
8022 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08008023 struct sk_buff *skb;
8024 int hdr_only = 0;
8025 u16 filter = priv->prom_priv->filter;
8026
8027 /* If the filter is set to not include Rx frames then return */
8028 if (filter & IPW_PROM_NO_RX)
8029 return;
8030
Zhu Yid685b8c2006-04-13 17:20:27 +08008031 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008032 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008033
8034 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008035 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008036 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8037 return;
8038 }
8039
8040 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008041 if (unlikely(!netif_running(dev))) {
8042 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008043 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8044 return;
8045 }
8046
8047 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8048 * that now */
8049 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8050 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008051 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008052 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8053 return;
8054 }
8055
8056 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008057 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008058 if (filter & IPW_PROM_NO_MGMT)
8059 return;
8060 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8061 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008062 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008063 if (filter & IPW_PROM_NO_CTL)
8064 return;
8065 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8066 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008067 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008068 if (filter & IPW_PROM_NO_DATA)
8069 return;
8070 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8071 hdr_only = 1;
8072 }
8073
8074 /* Copy the SKB since this is for the promiscuous side */
8075 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8076 if (skb == NULL) {
8077 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8078 return;
8079 }
8080
8081 /* copy the frame data to write after where the radiotap header goes */
8082 ipw_rt = (void *)skb->data;
8083
8084 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008085 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008086
8087 memcpy(ipw_rt->payload, hdr, len);
8088
Zhu Yid685b8c2006-04-13 17:20:27 +08008089 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8090 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008091 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008092
8093 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008094 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008095
8096 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008097 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8098 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008099 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008100 (1 << IEEE80211_RADIOTAP_RATE) |
8101 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8102 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8103 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8104 (1 << IEEE80211_RADIOTAP_ANTENNA));
8105
8106 /* Zero the flags, we'll add to them as we go */
8107 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008108 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8109 frame->parent_tsf[2] << 16 |
8110 frame->parent_tsf[1] << 8 |
8111 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008112
8113 /* Convert to DBM */
8114 ipw_rt->rt_dbmsignal = signal;
8115 ipw_rt->rt_dbmnoise = noise;
8116
8117 /* Convert the channel data and set the flags */
8118 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8119 if (channel > 14) { /* 802.11a */
8120 ipw_rt->rt_chbitmask =
8121 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8122 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8123 ipw_rt->rt_chbitmask =
8124 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8125 } else { /* 802.11g */
8126 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008127 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008128 }
8129
8130 /* set the rate in multiples of 500k/s */
8131 switch (rate) {
8132 case IPW_TX_RATE_1MB:
8133 ipw_rt->rt_rate = 2;
8134 break;
8135 case IPW_TX_RATE_2MB:
8136 ipw_rt->rt_rate = 4;
8137 break;
8138 case IPW_TX_RATE_5MB:
8139 ipw_rt->rt_rate = 10;
8140 break;
8141 case IPW_TX_RATE_6MB:
8142 ipw_rt->rt_rate = 12;
8143 break;
8144 case IPW_TX_RATE_9MB:
8145 ipw_rt->rt_rate = 18;
8146 break;
8147 case IPW_TX_RATE_11MB:
8148 ipw_rt->rt_rate = 22;
8149 break;
8150 case IPW_TX_RATE_12MB:
8151 ipw_rt->rt_rate = 24;
8152 break;
8153 case IPW_TX_RATE_18MB:
8154 ipw_rt->rt_rate = 36;
8155 break;
8156 case IPW_TX_RATE_24MB:
8157 ipw_rt->rt_rate = 48;
8158 break;
8159 case IPW_TX_RATE_36MB:
8160 ipw_rt->rt_rate = 72;
8161 break;
8162 case IPW_TX_RATE_48MB:
8163 ipw_rt->rt_rate = 96;
8164 break;
8165 case IPW_TX_RATE_54MB:
8166 ipw_rt->rt_rate = 108;
8167 break;
8168 default:
8169 ipw_rt->rt_rate = 0;
8170 break;
8171 }
8172
8173 /* antenna number */
8174 ipw_rt->rt_antenna = (phy_flags & 3);
8175
8176 /* set the preamble flag if we have it */
8177 if (phy_flags & (1 << 6))
8178 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8179
8180 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8181
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008182 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008183 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008184 dev_kfree_skb_any(skb);
8185 }
8186}
8187#endif
8188
Arjan van de Ven858119e2006-01-14 13:20:43 -08008189static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008190 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008191{
8192 /* Filter incoming packets to determine if they are targetted toward
8193 * this network, discarding packets coming from ourselves */
8194 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008195 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008196 /* packets from our adapter are dropped (echo) */
8197 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8198 return 0;
8199
Peter Jones90700fd2005-08-26 16:51:06 -05008200 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008201 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008202 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008203
8204 /* packets to our adapter go through */
8205 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8206 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008207
Peter Jones90700fd2005-08-26 16:51:06 -05008208 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008209 /* packets from our adapter are dropped (echo) */
8210 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8211 return 0;
8212
Peter Jones90700fd2005-08-26 16:51:06 -05008213 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008214 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008215 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8216
8217 /* packets to our adapter go through */
8218 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8219 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008220 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008221
James Ketrenosea2b26e2005-08-24 21:25:16 -05008222 return 1;
8223}
8224
James Ketrenosafbf30a2005-08-25 00:05:33 -05008225#define IPW_PACKET_RETRY_TIME HZ
8226
Arjan van de Ven858119e2006-01-14 13:20:43 -08008227static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008228 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008229{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008230 u16 sc = le16_to_cpu(header->seq_ctl);
8231 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8232 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8233 u16 *last_seq, *last_frag;
8234 unsigned long *last_time;
8235
8236 switch (priv->ieee->iw_mode) {
8237 case IW_MODE_ADHOC:
8238 {
8239 struct list_head *p;
8240 struct ipw_ibss_seq *entry = NULL;
8241 u8 *mac = header->addr2;
8242 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8243
8244 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8245 entry =
8246 list_entry(p, struct ipw_ibss_seq, list);
8247 if (!memcmp(entry->mac, mac, ETH_ALEN))
8248 break;
8249 }
8250 if (p == &priv->ibss_mac_hash[index]) {
8251 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8252 if (!entry) {
8253 IPW_ERROR
8254 ("Cannot malloc new mac entry\n");
8255 return 0;
8256 }
8257 memcpy(entry->mac, mac, ETH_ALEN);
8258 entry->seq_num = seq;
8259 entry->frag_num = frag;
8260 entry->packet_time = jiffies;
8261 list_add(&entry->list,
8262 &priv->ibss_mac_hash[index]);
8263 return 0;
8264 }
8265 last_seq = &entry->seq_num;
8266 last_frag = &entry->frag_num;
8267 last_time = &entry->packet_time;
8268 break;
8269 }
8270 case IW_MODE_INFRA:
8271 last_seq = &priv->last_seq_num;
8272 last_frag = &priv->last_frag_num;
8273 last_time = &priv->last_packet_time;
8274 break;
8275 default:
8276 return 0;
8277 }
8278 if ((*last_seq == seq) &&
8279 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8280 if (*last_frag == frag)
8281 goto drop;
8282 if (*last_frag + 1 != frag)
8283 /* out-of-order fragment */
8284 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008285 } else
8286 *last_seq = seq;
8287
Zhu Yif57ce7c2005-07-13 12:22:15 -05008288 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008289 *last_time = jiffies;
8290 return 0;
8291
8292 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008293 /* Comment this line now since we observed the card receives
8294 * duplicate packets but the FCTL_RETRY bit is not set in the
8295 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008296 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008297 return 1;
8298}
8299
James Ketrenosb095c382005-08-24 22:04:42 -05008300static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8301 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008302 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008303{
8304 struct sk_buff *skb = rxb->skb;
8305 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008306 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008307 (skb->data + IPW_RX_FRAME_SIZE);
8308
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008309 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008310
8311 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8312 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8313 IEEE80211_STYPE_PROBE_RESP) ||
8314 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8315 IEEE80211_STYPE_BEACON))) {
8316 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8317 ipw_add_station(priv, header->addr2);
8318 }
8319
8320 if (priv->config & CFG_NET_STATS) {
8321 IPW_DEBUG_HC("sending stat packet\n");
8322
8323 /* Set the size of the skb to the size of the full
8324 * ipw header and 802.11 frame */
8325 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8326 IPW_RX_FRAME_SIZE);
8327
8328 /* Advance past the ipw packet header to the 802.11 frame */
8329 skb_pull(skb, IPW_RX_FRAME_SIZE);
8330
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008331 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008332 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8333
8334 skb->dev = priv->ieee->dev;
8335
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008336 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008337 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008338
8339 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008340 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008341 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8342 netif_rx(skb);
8343 rxb->skb = NULL;
8344 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008345}
8346
James Ketrenos43f66a62005-03-25 12:31:53 -06008347/*
8348 * Main entry function for recieving a packet with 80211 headers. This
8349 * should be called when ever the FW has notified us that there is a new
8350 * skb in the recieve queue.
8351 */
8352static void ipw_rx(struct ipw_priv *priv)
8353{
8354 struct ipw_rx_mem_buffer *rxb;
8355 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008356 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008357 u32 r, w, i;
8358 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008359 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008360
James Ketrenosb095c382005-08-24 22:04:42 -05008361 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8362 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008363 i = priv->rxq->read;
8364
8365 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8366 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008367
8368 while (i != r) {
8369 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008370 if (unlikely(rxb == NULL)) {
8371 printk(KERN_CRIT "Queue not allocated!\n");
8372 break;
8373 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008374 priv->rxq->queue[i] = NULL;
8375
8376 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008377 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008378 PCI_DMA_FROMDEVICE);
8379
8380 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8381 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8382 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008383 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008384
8385 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008386 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008387 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008388 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008389 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008390 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008391 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008392 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008393 .noise =
8394 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008395 .rate = pkt->u.frame.rate,
8396 .mac_time = jiffies,
8397 .received_channel =
8398 pkt->u.frame.received_channel,
8399 .freq =
8400 (pkt->u.frame.
8401 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008402 LIBIPW_24GHZ_BAND :
8403 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008404 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008405 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008406
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008407 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008408 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008409 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008410 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008411 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008412 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008413 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008414 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008415
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008416 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008417
Zhu Yid685b8c2006-04-13 17:20:27 +08008418#ifdef CONFIG_IPW2200_PROMISCUOUS
8419 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8420 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8421#endif
8422
James Ketrenosb095c382005-08-24 22:04:42 -05008423#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008424 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008425#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008426
8427 ipw_handle_data_packet_monitor(priv,
8428 rxb,
8429 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008430#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008431 ipw_handle_data_packet(priv, rxb,
8432 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008433#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008434 break;
8435 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008436#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008437
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008438 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008439 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008440 data +
8441 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008442 /* TODO: Check Ad-Hoc dest/source and make sure
8443 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008444 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008445 * frame control of the packet and disregard
8446 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008447
James Ketrenosea2b26e2005-08-24 21:25:16 -05008448 network_packet =
8449 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008450 if (network_packet && priv->assoc_network) {
8451 priv->assoc_network->stats.rssi =
8452 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008453 priv->exp_avg_rssi =
8454 exponential_average(priv->exp_avg_rssi,
8455 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008456 }
8457
8458 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008459 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008460
James Ketrenosa613bff2005-08-24 21:43:11 -05008461 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008462 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008463 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008464 IPW_DEBUG_DROP
8465 ("Received packet is too small. "
8466 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008467 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008468 priv->wstats.discard.misc++;
8469 break;
8470 }
8471
James Ketrenosa613bff2005-08-24 21:43:11 -05008472 switch (WLAN_FC_GET_TYPE
8473 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008474
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008475 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008476 ipw_handle_mgmt_packet(priv, rxb,
8477 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008478 break;
8479
8480 case IEEE80211_FTYPE_CTL:
8481 break;
8482
8483 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008484 if (unlikely(!network_packet ||
8485 is_duplicate_packet(priv,
8486 header)))
8487 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008488 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008489 "%pM, "
8490 "%pM, "
8491 "%pM\n",
8492 header->addr1,
8493 header->addr2,
8494 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008495 break;
8496 }
8497
8498 ipw_handle_data_packet(priv, rxb,
8499 &stats);
8500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008501 break;
8502 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008503 break;
8504 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008505
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008506 case RX_HOST_NOTIFICATION_TYPE:{
8507 IPW_DEBUG_RX
8508 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008509 pkt->u.notification.subtype,
8510 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008511 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008512 ipw_rx_notification(priv, &pkt->u.notification);
8513 break;
8514 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008515
8516 default:
8517 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8518 pkt->header.message_type);
8519 break;
8520 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008521
8522 /* For now we just don't re-use anything. We can tweak this
8523 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008524 * fail to Rx correctly */
8525 if (rxb->skb != NULL) {
8526 dev_kfree_skb_any(rxb->skb);
8527 rxb->skb = NULL;
8528 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008529
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008531 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008532 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008533
James Ketrenos43f66a62005-03-25 12:31:53 -06008534 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008535
8536 /* If there are a lot of unsued frames, restock the Rx queue
8537 * so the ucode won't assert */
8538 if (fill_rx) {
8539 priv->rxq->read = i;
8540 ipw_rx_queue_replenish(priv);
8541 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 }
8543
8544 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008545 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008546 ipw_rx_queue_restock(priv);
8547}
8548
James Ketrenosafbf30a2005-08-25 00:05:33 -05008549#define DEFAULT_RTS_THRESHOLD 2304U
8550#define MIN_RTS_THRESHOLD 1U
8551#define MAX_RTS_THRESHOLD 2304U
8552#define DEFAULT_BEACON_INTERVAL 100U
8553#define DEFAULT_SHORT_RETRY_LIMIT 7U
8554#define DEFAULT_LONG_RETRY_LIMIT 4U
8555
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008556/**
8557 * ipw_sw_reset
8558 * @option: options to control different reset behaviour
8559 * 0 = reset everything except the 'disable' module_param
8560 * 1 = reset everything and print out driver info (for probe only)
8561 * 2 = reset everything
8562 */
8563static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008564{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008565 int band, modulation;
8566 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008567
James Ketrenosafbf30a2005-08-25 00:05:33 -05008568 /* Initialize module parameter values here */
8569 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008570
James Ketrenosafbf30a2005-08-25 00:05:33 -05008571 /* We default to disabling the LED code as right now it causes
8572 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008573 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008574 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008575
James Ketrenosafbf30a2005-08-25 00:05:33 -05008576 if (associate)
8577 priv->config |= CFG_ASSOCIATE;
8578 else
8579 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008580
James Ketrenosafbf30a2005-08-25 00:05:33 -05008581 if (auto_create)
8582 priv->config |= CFG_ADHOC_CREATE;
8583 else
8584 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8585
Zhu Yi17ed0812006-01-24 16:36:31 +08008586 priv->config &= ~CFG_STATIC_ESSID;
8587 priv->essid_len = 0;
8588 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8589
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008590 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008591 priv->status |= STATUS_RF_KILL_SW;
8592 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 }
8594
Reinette Chatre21f8a732009-08-18 10:25:05 -07008595 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008596 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008597 priv->channel = default_channel;
8598 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008599 /* TODO: Validate that provided channel is in range */
8600 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008601#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008602 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8603 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008604#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008605
Reinette Chatre21f8a732009-08-18 10:25:05 -07008606 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008607 case 1:
8608 priv->ieee->iw_mode = IW_MODE_ADHOC;
8609 priv->net_dev->type = ARPHRD_ETHER;
8610
8611 break;
8612#ifdef CONFIG_IPW2200_MONITOR
8613 case 2:
8614 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008615#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008616 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8617#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008618 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008619#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008620 break;
8621#endif
8622 default:
8623 case 0:
8624 priv->net_dev->type = ARPHRD_ETHER;
8625 priv->ieee->iw_mode = IW_MODE_INFRA;
8626 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008627 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008628
James Ketrenosafbf30a2005-08-25 00:05:33 -05008629 if (hwcrypto) {
8630 priv->ieee->host_encrypt = 0;
8631 priv->ieee->host_encrypt_msdu = 0;
8632 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008633 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008634 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008635 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008636
Zhu Yie402c932005-08-05 17:20:40 +08008637 /* IPW2200/2915 is abled to do hardware fragmentation. */
8638 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008639
James Ketrenosafbf30a2005-08-25 00:05:33 -05008640 if ((priv->pci_dev->device == 0x4223) ||
8641 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008642 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008643 printk(KERN_INFO DRV_NAME
8644 ": Detected Intel PRO/Wireless 2915ABG Network "
8645 "Connection\n");
8646 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008647 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8648 modulation = LIBIPW_OFDM_MODULATION |
8649 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008650 priv->adapter = IPW_2915ABG;
8651 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008652 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008653 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008654 printk(KERN_INFO DRV_NAME
8655 ": Detected Intel PRO/Wireless 2200BG Network "
8656 "Connection\n");
8657
8658 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008659 band = LIBIPW_24GHZ_BAND;
8660 modulation = LIBIPW_OFDM_MODULATION |
8661 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008662 priv->adapter = IPW_2200BG;
8663 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008664 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008665
James Ketrenosafbf30a2005-08-25 00:05:33 -05008666 priv->ieee->freq_band = band;
8667 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008668
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008669 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008670
James Ketrenosafbf30a2005-08-25 00:05:33 -05008671 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8672 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008673
James Ketrenosafbf30a2005-08-25 00:05:33 -05008674 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8675 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8676 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008677
James Ketrenosafbf30a2005-08-25 00:05:33 -05008678 /* If power management is turned on, default to AC mode */
8679 priv->power_mode = IPW_POWER_AC;
8680 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008681
Zhu Yi0ece35b2005-08-05 17:26:51 +08008682 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008683}
8684
8685/*
8686 * This file defines the Wireless Extension handlers. It does not
8687 * define any methods of hardware manipulation and relies on the
8688 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008689 *
8690 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008691 * function used to poll the hardware vs. making unecessary calls.
8692 *
8693 */
8694
James Ketrenos43f66a62005-03-25 12:31:53 -06008695static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8696{
8697 if (channel == 0) {
8698 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8699 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008700 IPW_DEBUG_ASSOC("Attempting to associate with new "
8701 "parameters.\n");
8702 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008703 return 0;
8704 }
8705
8706 priv->config |= CFG_STATIC_CHANNEL;
8707
8708 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008709 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8710 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008711 return 0;
8712 }
8713
8714 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8715 priv->channel = channel;
8716
James Ketrenosb095c382005-08-24 22:04:42 -05008717#ifdef CONFIG_IPW2200_MONITOR
8718 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008719 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008720 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008721 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008722 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008723 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008724 }
8725
8726 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8727 udelay(10);
8728
8729 if (priv->status & STATUS_SCANNING)
8730 IPW_DEBUG_SCAN("Still scanning...\n");
8731 else
8732 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8733 1000 - i);
8734
8735 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008736 }
James Ketrenosb095c382005-08-24 22:04:42 -05008737#endif /* CONFIG_IPW2200_MONITOR */
8738
James Ketrenosc848d0a2005-08-24 21:56:24 -05008739 /* Network configuration changed -- force [re]association */
8740 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8741 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008742 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008743
8744 return 0;
8745}
8746
Jeff Garzikbf794512005-07-31 13:07:26 -04008747static int ipw_wx_set_freq(struct net_device *dev,
8748 struct iw_request_info *info,
8749 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008750{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008751 struct ipw_priv *priv = libipw_priv(dev);
8752 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008753 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008754 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008755 u8 channel, flags;
8756 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008757
James Ketrenosb095c382005-08-24 22:04:42 -05008758 if (fwrq->m == 0) {
8759 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008760 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008761 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008762 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008763 return ret;
8764 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008765 /* if setting by freq convert to channel */
8766 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008767 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008768 if (channel == 0)
8769 return -EINVAL;
8770 } else
8771 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008772
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008773 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008774 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008775
Liu Hong1fe0adb2005-08-19 09:33:10 -05008776 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008777 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008778 if (i == -1)
8779 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008780
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008781 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008782 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008783 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008784 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8785 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008786 }
8787 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008788
Frans Pop9fd1ea42010-03-24 19:46:31 +01008789 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008790 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008791 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008792 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008793 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008794}
8795
Jeff Garzikbf794512005-07-31 13:07:26 -04008796static int ipw_wx_get_freq(struct net_device *dev,
8797 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008798 union iwreq_data *wrqu, char *extra)
8799{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008800 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008801
8802 wrqu->freq.e = 0;
8803
8804 /* If we are associated, trying to associate, or have a statically
8805 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008806 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008808 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8809 int i;
8810
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008811 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008812 BUG_ON(i == -1);
8813 wrqu->freq.e = 1;
8814
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008815 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8816 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008817 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8818 break;
8819
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008820 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008821 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8822 break;
8823
8824 default:
8825 BUG();
8826 }
8827 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 wrqu->freq.m = 0;
8829
Zhu Yi46441512006-01-24 16:37:59 +08008830 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01008831 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 return 0;
8833}
8834
Jeff Garzikbf794512005-07-31 13:07:26 -04008835static int ipw_wx_set_mode(struct net_device *dev,
8836 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008837 union iwreq_data *wrqu, char *extra)
8838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008839 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 int err = 0;
8841
8842 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8843
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008845#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008846 case IW_MODE_MONITOR:
8847#endif
8848 case IW_MODE_ADHOC:
8849 case IW_MODE_INFRA:
8850 break;
8851 case IW_MODE_AUTO:
8852 wrqu->mode = IW_MODE_INFRA;
8853 break;
8854 default:
8855 return -EINVAL;
8856 }
James Ketrenosb095c382005-08-24 22:04:42 -05008857 if (wrqu->mode == priv->ieee->iw_mode)
8858 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008859
Zhu Yi46441512006-01-24 16:37:59 +08008860 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008861
8862 ipw_sw_reset(priv, 0);
8863
James Ketrenosb095c382005-08-24 22:04:42 -05008864#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008865 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008866 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008867
8868 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008869#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008870 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8871#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008872 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008873#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008874#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008875
Jeff Garzikbf794512005-07-31 13:07:26 -04008876 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008877 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008878 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008879
8880 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008881
James Ketrenosc848d0a2005-08-24 21:56:24 -05008882 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008883 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008884 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008885}
8886
Jeff Garzikbf794512005-07-31 13:07:26 -04008887static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008888 struct iw_request_info *info,
8889 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008890{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008891 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008892 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008893 wrqu->mode = priv->ieee->iw_mode;
8894 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008895 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008896 return 0;
8897}
8898
James Ketrenos43f66a62005-03-25 12:31:53 -06008899/* Values are in microsecond */
8900static const s32 timeout_duration[] = {
8901 350000,
8902 250000,
8903 75000,
8904 37000,
8905 25000,
8906};
8907
8908static const s32 period_duration[] = {
8909 400000,
8910 700000,
8911 1000000,
8912 1000000,
8913 1000000
8914};
8915
Jeff Garzikbf794512005-07-31 13:07:26 -04008916static int ipw_wx_get_range(struct net_device *dev,
8917 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008918 union iwreq_data *wrqu, char *extra)
8919{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008920 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008921 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008922 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008923 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008924
8925 wrqu->data.length = sizeof(*range);
8926 memset(range, 0, sizeof(*range));
8927
8928 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008929 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008930
8931 range->max_qual.qual = 100;
8932 /* TODO: Find real max RSSI and stick here */
8933 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008934 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008935 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008936
8937 range->avg_qual.qual = 70;
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008938 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008939 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008940 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008941 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008942 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008943 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008944
Jeff Garzikbf794512005-07-31 13:07:26 -04008945 for (i = 0; i < range->num_bitrates; i++)
8946 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008947 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008948
James Ketrenos43f66a62005-03-25 12:31:53 -06008949 range->max_rts = DEFAULT_RTS_THRESHOLD;
8950 range->min_frag = MIN_FRAG_THRESHOLD;
8951 range->max_frag = MAX_FRAG_THRESHOLD;
8952
8953 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008954 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008955 range->num_encoding_sizes = 2;
8956 range->max_encoding_tokens = WEP_KEYS;
8957
8958 /* Set the Wireless Extension versions */
8959 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008960 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008961
James Ketrenosb095c382005-08-24 22:04:42 -05008962 i = 0;
8963 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008964 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8965 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008966 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008967 continue;
8968
James Ketrenosb095c382005-08-24 22:04:42 -05008969 range->freq[i].i = geo->bg[j].channel;
8970 range->freq[i].m = geo->bg[j].freq * 100000;
8971 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008972 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008973 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008974 }
James Ketrenosb095c382005-08-24 22:04:42 -05008975
8976 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008977 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8978 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008979 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008980 continue;
8981
James Ketrenosb095c382005-08-24 22:04:42 -05008982 range->freq[i].i = geo->a[j].channel;
8983 range->freq[i].m = geo->a[j].freq * 100000;
8984 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008985 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008986 }
8987 }
8988
8989 range->num_channels = i;
8990 range->num_frequency = i;
8991
Zhu Yi46441512006-01-24 16:37:59 +08008992 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008993
8994 /* Event capability (kernel + driver) */
8995 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8996 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008997 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8998 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008999 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009000
Dan Williamsf1b50862006-01-30 13:58:56 -05009001 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9002 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9003
Dan Williams374fdfb2007-12-12 10:25:07 -05009004 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9005
James Ketrenos43f66a62005-03-25 12:31:53 -06009006 IPW_DEBUG_WX("GET Range\n");
9007 return 0;
9008}
9009
Jeff Garzikbf794512005-07-31 13:07:26 -04009010static int ipw_wx_set_wap(struct net_device *dev,
9011 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009012 union iwreq_data *wrqu, char *extra)
9013{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009014 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009015
9016 static const unsigned char any[] = {
9017 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9018 };
9019 static const unsigned char off[] = {
9020 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9021 };
9022
Jeff Garzikbf794512005-07-31 13:07:26 -04009023 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009024 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009025 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009026 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9027 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9028 /* we disable mandatory BSSID association */
9029 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9030 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009031 IPW_DEBUG_ASSOC("Attempting to associate with new "
9032 "parameters.\n");
9033 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009034 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009035 return 0;
9036 }
9037
9038 priv->config |= CFG_STATIC_BSSID;
9039 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9040 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009041 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 return 0;
9043 }
9044
Johannes Berge1749612008-10-27 15:59:26 -07009045 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9046 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009047
9048 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9049
James Ketrenosc848d0a2005-08-24 21:56:24 -05009050 /* Network configuration changed -- force [re]association */
9051 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9052 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009053 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009054
Zhu Yi46441512006-01-24 16:37:59 +08009055 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009056 return 0;
9057}
9058
Jeff Garzikbf794512005-07-31 13:07:26 -04009059static int ipw_wx_get_wap(struct net_device *dev,
9060 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009061 union iwreq_data *wrqu, char *extra)
9062{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009063 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009064
James Ketrenos43f66a62005-03-25 12:31:53 -06009065 /* If we are associated, trying to associate, or have a statically
9066 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009067 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009068 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9070 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009071 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009072 } else
9073 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9074
Johannes Berge1749612008-10-27 15:59:26 -07009075 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9076 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009077 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009078 return 0;
9079}
9080
Jeff Garzikbf794512005-07-31 13:07:26 -04009081static int ipw_wx_set_essid(struct net_device *dev,
9082 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009083 union iwreq_data *wrqu, char *extra)
9084{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009085 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009086 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009087 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009088
Zhu Yiab644b02006-08-21 11:37:13 +08009089 mutex_lock(&priv->mutex);
9090
9091 if (!wrqu->essid.flags)
9092 {
9093 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9094 ipw_disassociate(priv);
9095 priv->config &= ~CFG_STATIC_ESSID;
9096 ipw_associate(priv);
9097 mutex_unlock(&priv->mutex);
9098 return 0;
9099 }
9100
Zhu Yia9f0d422006-08-21 11:37:26 +08009101 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009102
9103 priv->config |= CFG_STATIC_ESSID;
9104
Zhu Yia9f0d422006-08-21 11:37:26 +08009105 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9106 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009108 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 return 0;
9110 }
9111
John W. Linville9387b7c2008-09-30 20:59:05 -04009112 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9113 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009114
9115 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009116 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009117
James Ketrenosc848d0a2005-08-24 21:56:24 -05009118 /* Network configuration changed -- force [re]association */
9119 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9120 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009121 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009122
Zhu Yi46441512006-01-24 16:37:59 +08009123 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009124 return 0;
9125}
9126
Jeff Garzikbf794512005-07-31 13:07:26 -04009127static int ipw_wx_get_essid(struct net_device *dev,
9128 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 union iwreq_data *wrqu, char *extra)
9130{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009131 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009132 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009133
9134 /* If we are associated, trying to associate, or have a statically
9135 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009136 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009138 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9139 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009140 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009141 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009143 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 } else {
9145 IPW_DEBUG_WX("Getting essid: ANY\n");
9146 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009147 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 }
Zhu Yi46441512006-01-24 16:37:59 +08009149 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 return 0;
9151}
9152
Jeff Garzikbf794512005-07-31 13:07:26 -04009153static int ipw_wx_set_nick(struct net_device *dev,
9154 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009155 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009156{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009157 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009158
9159 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9160 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9161 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009162 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009163 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009165 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009166 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009167 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009168 return 0;
9169
9170}
9171
Jeff Garzikbf794512005-07-31 13:07:26 -04009172static int ipw_wx_get_nick(struct net_device *dev,
9173 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009174 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009175{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009176 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009177 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009178 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009179 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009180 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009181 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009182 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009183 return 0;
9184}
9185
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009186static int ipw_wx_set_sens(struct net_device *dev,
9187 struct iw_request_info *info,
9188 union iwreq_data *wrqu, char *extra)
9189{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009190 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009191 int err = 0;
9192
9193 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9194 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9195 mutex_lock(&priv->mutex);
9196
9197 if (wrqu->sens.fixed == 0)
9198 {
9199 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9200 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9201 goto out;
9202 }
9203 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9204 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9205 err = -EINVAL;
9206 goto out;
9207 }
9208
9209 priv->roaming_threshold = wrqu->sens.value;
9210 priv->disassociate_threshold = 3*wrqu->sens.value;
9211 out:
9212 mutex_unlock(&priv->mutex);
9213 return err;
9214}
9215
9216static int ipw_wx_get_sens(struct net_device *dev,
9217 struct iw_request_info *info,
9218 union iwreq_data *wrqu, char *extra)
9219{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009220 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009221 mutex_lock(&priv->mutex);
9222 wrqu->sens.fixed = 1;
9223 wrqu->sens.value = priv->roaming_threshold;
9224 mutex_unlock(&priv->mutex);
9225
Frans Pop9fd1ea42010-03-24 19:46:31 +01009226 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009227 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9228
9229 return 0;
9230}
9231
James Ketrenos43f66a62005-03-25 12:31:53 -06009232static int ipw_wx_set_rate(struct net_device *dev,
9233 struct iw_request_info *info,
9234 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009235{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009236 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009237 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009238 u32 target_rate = wrqu->bitrate.value;
9239 u32 fixed, mask;
9240
9241 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9242 /* value = X, fixed = 1 means only rate X */
9243 /* value = X, fixed = 0 means all rates lower equal X */
9244
9245 if (target_rate == -1) {
9246 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009247 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009248 /* Now we should reassociate */
9249 goto apply;
9250 }
9251
9252 mask = 0;
9253 fixed = wrqu->bitrate.fixed;
9254
9255 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009256 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009257 if (target_rate == 1000000)
9258 goto apply;
9259
9260 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009261 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009262 if (target_rate == 2000000)
9263 goto apply;
9264
9265 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009266 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009267 if (target_rate == 5500000)
9268 goto apply;
9269
9270 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009271 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009272 if (target_rate == 6000000)
9273 goto apply;
9274
9275 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009276 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009277 if (target_rate == 9000000)
9278 goto apply;
9279
9280 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009281 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009282 if (target_rate == 11000000)
9283 goto apply;
9284
9285 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009286 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009287 if (target_rate == 12000000)
9288 goto apply;
9289
9290 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009291 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009292 if (target_rate == 18000000)
9293 goto apply;
9294
9295 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009296 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009297 if (target_rate == 24000000)
9298 goto apply;
9299
9300 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009301 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009302 if (target_rate == 36000000)
9303 goto apply;
9304
9305 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009306 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009307 if (target_rate == 48000000)
9308 goto apply;
9309
9310 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009311 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009312 if (target_rate == 54000000)
9313 goto apply;
9314
9315 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9316 return -EINVAL;
9317
9318 apply:
9319 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9320 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009321 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009322 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009323 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009324 ipw_set_fixed_rate(priv, priv->ieee->mode);
9325 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009326 priv->config |= CFG_FIXED_RATE;
9327
James Ketrenosc848d0a2005-08-24 21:56:24 -05009328 if (priv->rates_mask == mask) {
9329 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009330 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009331 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009332 }
9333
James Ketrenosc848d0a2005-08-24 21:56:24 -05009334 priv->rates_mask = mask;
9335
9336 /* Network configuration changed -- force [re]association */
9337 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9338 if (!ipw_disassociate(priv))
9339 ipw_associate(priv);
9340
Zhu Yi46441512006-01-24 16:37:59 +08009341 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009342 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009343}
9344
Jeff Garzikbf794512005-07-31 13:07:26 -04009345static int ipw_wx_get_rate(struct net_device *dev,
9346 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009347 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009348{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009349 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009350 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009352 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009353 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009354 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009355 return 0;
9356}
9357
Jeff Garzikbf794512005-07-31 13:07:26 -04009358static int ipw_wx_set_rts(struct net_device *dev,
9359 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009360 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009361{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009362 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009363 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009364 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009365 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9366 else {
9367 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009368 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009369 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009370 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009371 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009372 priv->rts_threshold = wrqu->rts.value;
9373 }
9374
9375 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009376 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009377 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06009378 return 0;
9379}
9380
Jeff Garzikbf794512005-07-31 13:07:26 -04009381static int ipw_wx_get_rts(struct net_device *dev,
9382 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009383 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009384{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009385 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009386 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009387 wrqu->rts.value = priv->rts_threshold;
9388 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009389 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009390 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009391 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009392 return 0;
9393}
9394
Jeff Garzikbf794512005-07-31 13:07:26 -04009395static int ipw_wx_set_txpow(struct net_device *dev,
9396 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009397 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009398{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009399 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009400 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009401
Zhu Yi46441512006-01-24 16:37:59 +08009402 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009403 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009404 err = -EINPROGRESS;
9405 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009406 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009407
James Ketrenosb095c382005-08-24 22:04:42 -05009408 if (!wrqu->power.fixed)
9409 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009410
James Ketrenosc848d0a2005-08-24 21:56:24 -05009411 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009412 err = -EINVAL;
9413 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009414 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009415
James Ketrenosb095c382005-08-24 22:04:42 -05009416 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009417 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009418 err = -EINVAL;
9419 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009420 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009421
9422 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009423 err = ipw_set_tx_power(priv);
9424 out:
Zhu Yi46441512006-01-24 16:37:59 +08009425 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009426 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009427}
9428
Jeff Garzikbf794512005-07-31 13:07:26 -04009429static int ipw_wx_get_txpow(struct net_device *dev,
9430 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009431 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009432{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009433 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009434 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009435 wrqu->power.value = priv->tx_power;
9436 wrqu->power.fixed = 1;
9437 wrqu->power.flags = IW_TXPOW_DBM;
9438 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009439 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009440
Frans Pop9fd1ea42010-03-24 19:46:31 +01009441 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
Zhu Yi22501c82005-08-11 10:49:17 +08009442 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009443
9444 return 0;
9445}
9446
Jeff Garzikbf794512005-07-31 13:07:26 -04009447static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009448 struct iw_request_info *info,
9449 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009450{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009451 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009452 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009453 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009454 priv->ieee->fts = DEFAULT_FTS;
9455 else {
9456 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009457 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009458 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009459 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009460 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009461
James Ketrenos43f66a62005-03-25 12:31:53 -06009462 priv->ieee->fts = wrqu->frag.value & ~0x1;
9463 }
9464
9465 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009466 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009467 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009468 return 0;
9469}
9470
Jeff Garzikbf794512005-07-31 13:07:26 -04009471static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009472 struct iw_request_info *info,
9473 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009474{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009475 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009476 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009477 wrqu->frag.value = priv->ieee->fts;
9478 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009479 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009480 mutex_unlock(&priv->mutex);
Frans Pop9fd1ea42010-03-24 19:46:31 +01009481 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009482
9483 return 0;
9484}
9485
Jeff Garzikbf794512005-07-31 13:07:26 -04009486static int ipw_wx_set_retry(struct net_device *dev,
9487 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009488 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009489{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009490 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009491
9492 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9493 return -EINVAL;
9494
9495 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9496 return 0;
9497
Zhu Yid5f7ac22006-08-21 11:38:17 +08009498 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009499 return -EINVAL;
9500
Zhu Yi46441512006-01-24 16:37:59 +08009501 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009502 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009503 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009504 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009505 priv->long_retry_limit = (u8) wrqu->retry.value;
9506 else {
9507 priv->short_retry_limit = (u8) wrqu->retry.value;
9508 priv->long_retry_limit = (u8) wrqu->retry.value;
9509 }
9510
9511 ipw_send_retry_limit(priv, priv->short_retry_limit,
9512 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009513 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009514 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9515 priv->short_retry_limit, priv->long_retry_limit);
9516 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009517}
9518
Jeff Garzikbf794512005-07-31 13:07:26 -04009519static int ipw_wx_get_retry(struct net_device *dev,
9520 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009521 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009522{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009523 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009524
Zhu Yi46441512006-01-24 16:37:59 +08009525 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009526 wrqu->retry.disabled = 0;
9527
9528 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009529 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009530 return -EINVAL;
9531 }
9532
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009533 if (wrqu->retry.flags & IW_RETRY_LONG) {
9534 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009535 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009536 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9537 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009538 wrqu->retry.value = priv->short_retry_limit;
9539 } else {
9540 wrqu->retry.flags = IW_RETRY_LIMIT;
9541 wrqu->retry.value = priv->short_retry_limit;
9542 }
Zhu Yi46441512006-01-24 16:37:59 +08009543 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009544
Frans Pop9fd1ea42010-03-24 19:46:31 +01009545 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009546
9547 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009548}
9549
Jeff Garzikbf794512005-07-31 13:07:26 -04009550static int ipw_wx_set_scan(struct net_device *dev,
9551 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009552 union iwreq_data *wrqu, char *extra)
9553{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009554 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009555 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009556 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009557
Dan Williams0b531672007-10-09 13:55:24 -04009558 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009559
Dan Williams0b531672007-10-09 13:55:24 -04009560 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009561
Zhu Yi094c4d22006-08-21 11:39:03 +08009562 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009563 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009564 int len = min((int)req->essid_len,
9565 (int)sizeof(priv->direct_scan_ssid));
9566 memcpy(priv->direct_scan_ssid, req->essid, len);
9567 priv->direct_scan_ssid_len = len;
9568 work = &priv->request_direct_scan;
9569 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9570 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009571 }
Dan Williamsea177302008-06-02 17:51:23 -04009572 } else {
9573 /* Normal active broadcast scan */
9574 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009575 }
James Ketrenos8935f392005-10-05 15:59:08 -05009576
Dan Williamsea177302008-06-02 17:51:23 -04009577 mutex_unlock(&priv->mutex);
9578
James Ketrenos43f66a62005-03-25 12:31:53 -06009579 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009580
Dan Williamsea177302008-06-02 17:51:23 -04009581 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009582
James Ketrenos43f66a62005-03-25 12:31:53 -06009583 return 0;
9584}
9585
Jeff Garzikbf794512005-07-31 13:07:26 -04009586static int ipw_wx_get_scan(struct net_device *dev,
9587 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009588 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009589{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009590 struct ipw_priv *priv = libipw_priv(dev);
9591 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009592}
9593
Jeff Garzikbf794512005-07-31 13:07:26 -04009594static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009595 struct iw_request_info *info,
9596 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009597{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009598 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009599 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009600 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009601
Zhu Yi46441512006-01-24 16:37:59 +08009602 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009603 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009604
Hong Liucaeff812005-08-05 17:25:50 +08009605 /* In IBSS mode, we need to notify the firmware to update
9606 * the beacon info after we changed the capability. */
9607 if (cap != priv->capability &&
9608 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9609 priv->status & STATUS_ASSOCIATED)
9610 ipw_disassociate(priv);
9611
Zhu Yi46441512006-01-24 16:37:59 +08009612 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009613 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009614}
9615
Jeff Garzikbf794512005-07-31 13:07:26 -04009616static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009617 struct iw_request_info *info,
9618 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009619{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009620 struct ipw_priv *priv = libipw_priv(dev);
9621 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009622}
9623
Jeff Garzikbf794512005-07-31 13:07:26 -04009624static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009625 struct iw_request_info *info,
9626 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009627{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009628 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009629 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009630 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009631 if (wrqu->power.disabled) {
9632 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9633 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9634 if (err) {
9635 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009636 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009637 return err;
9638 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009639 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009640 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009641 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009642 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009643
9644 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009645 case IW_POWER_ON: /* If not specified */
9646 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009647 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009648 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009649 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009650 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9651 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009652 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009653 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009654 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009655
James Ketrenos43f66a62005-03-25 12:31:53 -06009656 /* If the user hasn't specified a power management mode yet, default
9657 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009658 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009659 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009660 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009661 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009662
James Ketrenos43f66a62005-03-25 12:31:53 -06009663 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9664 if (err) {
9665 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009666 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009667 return err;
9668 }
9669
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009670 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009671 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009672 return 0;
9673}
9674
Jeff Garzikbf794512005-07-31 13:07:26 -04009675static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009676 struct iw_request_info *info,
9677 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009678{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009679 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009680 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009681 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009682 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009683 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009684 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009685
Zhu Yi46441512006-01-24 16:37:59 +08009686 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009688
James Ketrenos43f66a62005-03-25 12:31:53 -06009689 return 0;
9690}
9691
Jeff Garzikbf794512005-07-31 13:07:26 -04009692static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009693 struct iw_request_info *info,
9694 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009695{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009696 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009697 int mode = *(int *)extra;
9698 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009699
Zhu Yi46441512006-01-24 16:37:59 +08009700 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009701 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009702 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009703
Zhu Yi4e157f02007-07-12 16:09:32 +08009704 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009705 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009706 if (err) {
9707 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009708 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 return err;
9710 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009711 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009712 }
Zhu Yi46441512006-01-24 16:37:59 +08009713 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009714 return 0;
9715}
9716
9717#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009718static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009719 struct iw_request_info *info,
9720 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009721{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009722 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009723 int level = IPW_POWER_LEVEL(priv->power_mode);
9724 char *p = extra;
9725
9726 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9727
9728 switch (level) {
9729 case IPW_POWER_AC:
9730 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9731 break;
9732 case IPW_POWER_BATTERY:
9733 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9734 break;
9735 default:
9736 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009737 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009738 timeout_duration[level - 1] / 1000,
9739 period_duration[level - 1] / 1000);
9740 }
9741
9742 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009743 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009744
9745 wrqu->data.length = p - extra + 1;
9746
9747 return 0;
9748}
9749
9750static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009751 struct iw_request_info *info,
9752 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009753{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009754 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009755 int mode = *(int *)extra;
9756 u8 band = 0, modulation = 0;
9757
9758 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009759 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009760 return -EINVAL;
9761 }
Zhu Yi46441512006-01-24 16:37:59 +08009762 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009763 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009764 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009766 band |= LIBIPW_52GHZ_BAND;
9767 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009768 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009769 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 } else {
9771 if (mode & IEEE_A) {
9772 IPW_WARNING("Attempt to set 2200BG into "
9773 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009774 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 return -EINVAL;
9776 }
9777
James Ketrenosa33a1982005-09-14 14:28:59 -05009778 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009779 }
9780
9781 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009782 band |= LIBIPW_24GHZ_BAND;
9783 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009784 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009785 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009786
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009788 band |= LIBIPW_24GHZ_BAND;
9789 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009791 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009792
9793 priv->ieee->mode = mode;
9794 priv->ieee->freq_band = band;
9795 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009796 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009797
James Ketrenosc848d0a2005-08-24 21:56:24 -05009798 /* Network configuration changed -- force [re]association */
9799 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9800 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009801 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009802 ipw_associate(priv);
9803 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009804
James Ketrenosa613bff2005-08-24 21:43:11 -05009805 /* Update the band LEDs */
9806 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009807
Jeff Garzikbf794512005-07-31 13:07:26 -04009808 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009809 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009810 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009811 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009812 return 0;
9813}
9814
9815static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009816 struct iw_request_info *info,
9817 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009818{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009819 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009820 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009821 switch (priv->ieee->mode) {
9822 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009823 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9824 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009825 case IEEE_B:
9826 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9827 break;
9828 case IEEE_A | IEEE_B:
9829 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9830 break;
9831 case IEEE_G:
9832 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9833 break;
9834 case IEEE_A | IEEE_G:
9835 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9836 break;
9837 case IEEE_B | IEEE_G:
9838 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9839 break;
9840 case IEEE_A | IEEE_B | IEEE_G:
9841 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9842 break;
9843 default:
9844 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009845 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009846 }
9847
James Ketrenos43f66a62005-03-25 12:31:53 -06009848 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9849
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009850 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009851 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009853 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009854}
9855
James Ketrenosea2b26e2005-08-24 21:25:16 -05009856static int ipw_wx_set_preamble(struct net_device *dev,
9857 struct iw_request_info *info,
9858 union iwreq_data *wrqu, char *extra)
9859{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009860 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009861 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009862 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009863 /* Switching from SHORT -> LONG requires a disassociation */
9864 if (mode == 1) {
9865 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9866 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009867
9868 /* Network configuration changed -- force [re]association */
9869 IPW_DEBUG_ASSOC
9870 ("[re]association triggered due to preamble change.\n");
9871 if (!ipw_disassociate(priv))
9872 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009873 }
9874 goto done;
9875 }
9876
9877 if (mode == 0) {
9878 priv->config &= ~CFG_PREAMBLE_LONG;
9879 goto done;
9880 }
Zhu Yi46441512006-01-24 16:37:59 +08009881 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009882 return -EINVAL;
9883
9884 done:
Zhu Yi46441512006-01-24 16:37:59 +08009885 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009886 return 0;
9887}
9888
9889static int ipw_wx_get_preamble(struct net_device *dev,
9890 struct iw_request_info *info,
9891 union iwreq_data *wrqu, char *extra)
9892{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009893 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009894 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009895 if (priv->config & CFG_PREAMBLE_LONG)
9896 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9897 else
9898 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009899 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009900 return 0;
9901}
9902
James Ketrenosb095c382005-08-24 22:04:42 -05009903#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009904static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009905 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009906 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009907{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009908 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 int *parms = (int *)extra;
9910 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009911 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009912 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 if (enable) {
9914 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009915#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009916 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9917#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009918 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009919#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009920 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009921 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009922
James Ketrenos43f66a62005-03-25 12:31:53 -06009923 ipw_set_channel(priv, parms[1]);
9924 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009925 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009926 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009927 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009928 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009929 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009930 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 }
Zhu Yi46441512006-01-24 16:37:59 +08009932 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009933 return 0;
9934}
9935
Pavel Machek67fd6b42006-07-11 15:34:05 +02009936#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009937
Jeff Garzikbf794512005-07-31 13:07:26 -04009938static int ipw_wx_reset(struct net_device *dev,
9939 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009940 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009941{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009942 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009943 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009944 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009945 return 0;
9946}
James Ketrenosb095c382005-08-24 22:04:42 -05009947
James Ketrenosb095c382005-08-24 22:04:42 -05009948static int ipw_wx_sw_reset(struct net_device *dev,
9949 struct iw_request_info *info,
9950 union iwreq_data *wrqu, char *extra)
9951{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009952 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009953 union iwreq_data wrqu_sec = {
9954 .encoding = {
9955 .flags = IW_ENCODE_DISABLED,
9956 },
9957 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009958 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009959
9960 IPW_DEBUG_WX("SW_RESET\n");
9961
Zhu Yi46441512006-01-24 16:37:59 +08009962 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009963
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009964 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009965 if (!ret) {
9966 free_firmware();
9967 ipw_adapter_restart(priv);
9968 }
James Ketrenosb095c382005-08-24 22:04:42 -05009969
9970 /* The SW reset bit might have been toggled on by the 'disable'
9971 * module parameter, so take appropriate action */
9972 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9973
Zhu Yi46441512006-01-24 16:37:59 +08009974 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009975 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009976 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009977
9978 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9979 /* Configuration likely changed -- force [re]association */
9980 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9981 "reset.\n");
9982 if (!ipw_disassociate(priv))
9983 ipw_associate(priv);
9984 }
9985
Zhu Yi46441512006-01-24 16:37:59 +08009986 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009987
9988 return 0;
9989}
James Ketrenos43f66a62005-03-25 12:31:53 -06009990
9991/* Rebase the WE IOCTLs to zero for the handler array */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009992static iw_handler ipw_wx_handlers[] = {
Joe Perches56b632e2010-03-18 18:29:38 -07009993 IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname),
9994 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9995 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
9996 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
9997 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
9998 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
9999 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
10000 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
10001 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
10002 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
10003 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
10004 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
10005 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
10006 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
10007 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
10008 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
10009 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
10010 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
10011 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
10012 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
10013 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
10014 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
10015 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
10016 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
10017 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
10018 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
10019 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
10020 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
10021 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
10022 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
10023 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
10024 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
10025 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
10026 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
10027 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
10028 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
10029 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
10030 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
10031 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
10032 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
10033 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
James Ketrenos43f66a62005-03-25 12:31:53 -060010034};
10035
James Ketrenosb095c382005-08-24 22:04:42 -050010036enum {
10037 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10038 IPW_PRIV_GET_POWER,
10039 IPW_PRIV_SET_MODE,
10040 IPW_PRIV_GET_MODE,
10041 IPW_PRIV_SET_PREAMBLE,
10042 IPW_PRIV_GET_PREAMBLE,
10043 IPW_PRIV_RESET,
10044 IPW_PRIV_SW_RESET,
10045#ifdef CONFIG_IPW2200_MONITOR
10046 IPW_PRIV_SET_MONITOR,
10047#endif
10048};
James Ketrenos43f66a62005-03-25 12:31:53 -060010049
Jeff Garzikbf794512005-07-31 13:07:26 -040010050static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010051 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010052 .cmd = IPW_PRIV_SET_POWER,
10053 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10054 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010056 .cmd = IPW_PRIV_GET_POWER,
10057 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10058 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010060 .cmd = IPW_PRIV_SET_MODE,
10061 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10062 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010063 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010064 .cmd = IPW_PRIV_GET_MODE,
10065 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10066 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010067 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010068 .cmd = IPW_PRIV_SET_PREAMBLE,
10069 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10070 .name = "set_preamble"},
10071 {
10072 .cmd = IPW_PRIV_GET_PREAMBLE,
10073 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10074 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010075 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010076 IPW_PRIV_RESET,
10077 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010078 {
10079 IPW_PRIV_SW_RESET,
10080 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10081#ifdef CONFIG_IPW2200_MONITOR
10082 {
10083 IPW_PRIV_SET_MONITOR,
10084 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10085#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010086};
10087
10088static iw_handler ipw_priv_handler[] = {
10089 ipw_wx_set_powermode,
10090 ipw_wx_get_powermode,
10091 ipw_wx_set_wireless_mode,
10092 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010093 ipw_wx_set_preamble,
10094 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010095 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010096 ipw_wx_sw_reset,
10097#ifdef CONFIG_IPW2200_MONITOR
10098 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010099#endif
10100};
10101
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010102static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010103 .standard = ipw_wx_handlers,
10104 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10105 .num_private = ARRAY_SIZE(ipw_priv_handler),
10106 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10107 .private = ipw_priv_handler,
10108 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010109 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010110};
10111
James Ketrenos43f66a62005-03-25 12:31:53 -060010112/*
10113 * Get wireless statistics.
10114 * Called by /proc/net/wireless
10115 * Also called by SIOCGIWSTATS
10116 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010117static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010118{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010119 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010120 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010121
James Ketrenos43f66a62005-03-25 12:31:53 -060010122 wstats = &priv->wstats;
10123
James Ketrenosea2b26e2005-08-24 21:25:16 -050010124 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010125 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010126 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10127 * and associated; if not associcated, the values are all meaningless
10128 * anyway, so set them all to NULL and INVALID */
10129 if (!(priv->status & STATUS_ASSOCIATED)) {
10130 wstats->miss.beacon = 0;
10131 wstats->discard.retries = 0;
10132 wstats->qual.qual = 0;
10133 wstats->qual.level = 0;
10134 wstats->qual.noise = 0;
10135 wstats->qual.updated = 7;
10136 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010137 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010139 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010140
10141 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010142 wstats->qual.level = priv->exp_avg_rssi;
10143 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010144 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010145 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010146
10147 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10148 wstats->discard.retries = priv->last_tx_failures;
10149 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010150
James Ketrenos43f66a62005-03-25 12:31:53 -060010151/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10152 goto fail_get_ordinal;
10153 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010154
James Ketrenos43f66a62005-03-25 12:31:53 -060010155 return wstats;
10156}
10157
James Ketrenos43f66a62005-03-25 12:31:53 -060010158/* net device stuff */
10159
Arjan van de Ven858119e2006-01-14 13:20:43 -080010160static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010161{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010162 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010163 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010164 sys_config->answer_broadcast_ssid_probe = 0;
10165 sys_config->accept_all_data_frames = 0;
10166 sys_config->accept_non_directed_frames = 1;
10167 sys_config->exclude_unicast_unencrypted = 0;
10168 sys_config->disable_unicast_decryption = 1;
10169 sys_config->exclude_multicast_unencrypted = 0;
10170 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010171 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10172 antenna = CFG_SYS_ANTENNA_BOTH;
10173 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010174 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010175 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010176 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010177 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010178 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010179 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010180}
10181
10182static int ipw_net_open(struct net_device *dev)
10183{
James Ketrenos43f66a62005-03-25 12:31:53 -060010184 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010185 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010186 return 0;
10187}
10188
10189static int ipw_net_stop(struct net_device *dev)
10190{
10191 IPW_DEBUG_INFO("dev->close\n");
10192 netif_stop_queue(dev);
10193 return 0;
10194}
10195
10196/*
10197todo:
10198
10199modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010200we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010201*/
10202
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010203static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010204 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010205{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010206 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010207 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010208 int i = 0;
10209 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010210#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010211 int tx_id = ipw_get_tx_queue_number(priv, pri);
10212 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10213#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010214 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010215#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010216 struct clx2_queue *q = &txq->q;
10217 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010218 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010219
Zhu Yib8ddafd2008-11-27 13:42:20 +080010220 if (!(priv->status & STATUS_ASSOCIATED))
10221 goto drop;
10222
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010223 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010224 switch (priv->ieee->iw_mode) {
10225 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010226 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010227 id = ipw_find_station(priv, hdr->addr1);
10228 if (id == IPW_INVALID_STATION) {
10229 id = ipw_add_station(priv, hdr->addr1);
10230 if (id == IPW_INVALID_STATION) {
10231 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010232 "invalid cell: %pM\n",
10233 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010234 goto drop;
10235 }
10236 }
10237 break;
10238
10239 case IW_MODE_INFRA:
10240 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010241 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010242 id = 0;
10243 break;
10244 }
10245
10246 tfd = &txq->bd[q->first_empty];
10247 txq->txb[q->first_empty] = txb;
10248 memset(tfd, 0, sizeof(*tfd));
10249 tfd->u.data.station_number = id;
10250
10251 tfd->control_flags.message_type = TX_FRAME_TYPE;
10252 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10253
10254 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010255 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010256
James Ketrenos43f66a62005-03-25 12:31:53 -060010257 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010258 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010259 else
James Ketrenosb095c382005-08-24 22:04:42 -050010260 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010261
James Ketrenosea2b26e2005-08-24 21:25:16 -050010262 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10263 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010264
James Ketrenosc848d0a2005-08-24 21:56:24 -050010265 fc = le16_to_cpu(hdr->frame_ctl);
10266 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010267
10268 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10269
James Ketrenosb095c382005-08-24 22:04:42 -050010270 if (likely(unicast))
10271 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10272
10273 if (txb->encrypted && !priv->ieee->host_encrypt) {
10274 switch (priv->ieee->sec.level) {
10275 case SEC_LEVEL_3:
10276 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010277 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010278 /* XXX: ACK flag must be set for CCMP even if it
10279 * is a multicast/broadcast packet, because CCMP
10280 * group communication encrypted by GTK is
10281 * actually done by the AP. */
10282 if (!unicast)
10283 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10284
10285 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10286 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10287 tfd->u.data.key_index = 0;
10288 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10289 break;
10290 case SEC_LEVEL_2:
10291 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010292 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010293 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10294 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10295 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10296 break;
10297 case SEC_LEVEL_1:
10298 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010299 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010300 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10301 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010302 40)
10303 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10304 else
10305 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10306 break;
10307 case SEC_LEVEL_0:
10308 break;
10309 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010310 printk(KERN_ERR "Unknown security level %d\n",
James Ketrenosb095c382005-08-24 22:04:42 -050010311 priv->ieee->sec.level);
10312 break;
10313 }
10314 } else
10315 /* No hardware encryption */
10316 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10317
Zhu Yie43e3c12006-04-13 17:20:45 +080010318#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010319 if (fc & IEEE80211_STYPE_QOS_DATA)
10320 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010321#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010322
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010324 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10325 txb->nr_frags));
10326 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10327 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10328 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10329 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10330 i, le32_to_cpu(tfd->u.data.num_chunks),
10331 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010332 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010333 i, tfd->u.data.num_chunks,
10334 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010335 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010336 txb->fragments[i]->len - hdr_len);
10337
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010338 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010339 cpu_to_le32(pci_map_single
10340 (priv->pci_dev,
10341 txb->fragments[i]->data + hdr_len,
10342 txb->fragments[i]->len - hdr_len,
10343 PCI_DMA_TODEVICE));
10344 tfd->u.data.chunk_len[i] =
10345 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010346 }
10347
10348 if (i != txb->nr_frags) {
10349 struct sk_buff *skb;
10350 u16 remaining_bytes = 0;
10351 int j;
10352
10353 for (j = i; j < txb->nr_frags; j++)
10354 remaining_bytes += txb->fragments[j]->len - hdr_len;
10355
10356 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10357 remaining_bytes);
10358 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10359 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010360 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010361 for (j = i; j < txb->nr_frags; j++) {
10362 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010363
James Ketrenos43f66a62005-03-25 12:31:53 -060010364 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010365 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010366 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010367 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010368 }
10369 dev_kfree_skb_any(txb->fragments[i]);
10370 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010371 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010372 cpu_to_le32(pci_map_single
10373 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010374 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010375 PCI_DMA_TODEVICE));
10376
Marcin Slusarz5c058632008-02-13 00:06:12 +010010377 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010378 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010379 }
10380
10381 /* kick DMA */
10382 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10383 ipw_write32(priv, q->reg_w, q->first_empty);
10384
Dan Williams943dbef2008-02-14 17:49:41 -050010385 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010386 netif_stop_queue(priv->net_dev);
10387
James Ketrenos227d2dc2005-07-28 16:25:55 -050010388 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010389
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010390 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010391 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010392 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010393 return NETDEV_TX_OK;
10394}
10395
10396static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10397{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010398 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010399#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010400 int tx_id = ipw_get_tx_queue_number(priv, pri);
10401 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10402#else
10403 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010404#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010405
Dan Williams943dbef2008-02-14 17:49:41 -050010406 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010407 return 1;
10408
10409 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010410}
10411
Zhu Yid685b8c2006-04-13 17:20:27 +080010412#ifdef CONFIG_IPW2200_PROMISCUOUS
10413static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010414 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010415{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010416 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010417 struct ieee80211_hdr *hdr;
10418 u8 n;
10419 u16 filter = priv->prom_priv->filter;
10420 int hdr_only = 0;
10421
10422 if (filter & IPW_PROM_NO_TX)
10423 return;
10424
10425 memset(&dummystats, 0, sizeof(dummystats));
10426
10427 /* Filtering of fragment chains is done agains the first fragment */
10428 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010429 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010430 if (filter & IPW_PROM_NO_MGMT)
10431 return;
10432 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10433 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010434 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010435 if (filter & IPW_PROM_NO_CTL)
10436 return;
10437 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10438 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010439 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010440 if (filter & IPW_PROM_NO_DATA)
10441 return;
10442 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10443 hdr_only = 1;
10444 }
10445
10446 for(n=0; n<txb->nr_frags; ++n) {
10447 struct sk_buff *src = txb->fragments[n];
10448 struct sk_buff *dst;
10449 struct ieee80211_radiotap_header *rt_hdr;
10450 int len;
10451
10452 if (hdr_only) {
10453 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010454 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010455 } else
10456 len = src->len;
10457
Johannes Berg007e5dd2008-11-27 23:13:38 +010010458 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10459 if (!dst)
10460 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010461
10462 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10463
10464 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10465 rt_hdr->it_pad = 0;
10466 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010467 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010468
Al Viroe62e1ee2007-12-27 01:36:46 -050010469 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010470 ieee80211chan2mhz(priv->channel));
10471 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010472 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010473 cpu_to_le16(IEEE80211_CHAN_OFDM |
10474 IEEE80211_CHAN_5GHZ);
10475 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010476 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010477 cpu_to_le16(IEEE80211_CHAN_CCK |
10478 IEEE80211_CHAN_2GHZ);
10479 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010480 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010481 cpu_to_le16(IEEE80211_CHAN_OFDM |
10482 IEEE80211_CHAN_2GHZ);
10483
Al Viro743b84d2007-12-27 01:43:16 -050010484 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010485
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010486 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010487
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010488 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010489 dev_kfree_skb_any(dst);
10490 }
10491}
10492#endif
10493
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010494static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10495 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010496{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010497 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010498 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010499 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010500
10501 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010502 spin_lock_irqsave(&priv->lock, flags);
10503
Zhu Yid685b8c2006-04-13 17:20:27 +080010504#ifdef CONFIG_IPW2200_PROMISCUOUS
10505 if (rtap_iface && netif_running(priv->prom_net_dev))
10506 ipw_handle_promiscuous_tx(priv, txb);
10507#endif
10508
James Ketrenos227d2dc2005-07-28 16:25:55 -050010509 ret = ipw_tx_skb(priv, txb, pri);
10510 if (ret == NETDEV_TX_OK)
10511 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010512 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010513
James Ketrenos227d2dc2005-07-28 16:25:55 -050010514 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010515}
10516
James Ketrenos43f66a62005-03-25 12:31:53 -060010517static void ipw_net_set_multicast_list(struct net_device *dev)
10518{
10519
10520}
10521
10522static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10523{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010524 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010525 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010526
James Ketrenos43f66a62005-03-25 12:31:53 -060010527 if (!is_valid_ether_addr(addr->sa_data))
10528 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010529 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010530 priv->config |= CFG_CUSTOM_MAC;
10531 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010532 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10533 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010534 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010535 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010536 return 0;
10537}
10538
Jeff Garzikbf794512005-07-31 13:07:26 -040010539static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010540 struct ethtool_drvinfo *info)
10541{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010542 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010543 char vers[64];
10544 char date[32];
10545 u32 len;
10546
10547 strcpy(info->driver, DRV_NAME);
10548 strcpy(info->version, DRV_VERSION);
10549
10550 len = sizeof(vers);
10551 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10552 len = sizeof(date);
10553 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10554
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010555 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010556 vers, date);
10557 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010558 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010559}
10560
10561static u32 ipw_ethtool_get_link(struct net_device *dev)
10562{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010563 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010564 return (priv->status & STATUS_ASSOCIATED) != 0;
10565}
10566
10567static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10568{
James Ketrenosb095c382005-08-24 22:04:42 -050010569 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010570}
10571
10572static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010573 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010574{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010575 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010576
James Ketrenosb095c382005-08-24 22:04:42 -050010577 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010578 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010579 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010580 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010581 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010582 return 0;
10583}
10584
10585static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010586 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010587{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010588 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010589 int i;
10590
James Ketrenosb095c382005-08-24 22:04:42 -050010591 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010592 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010593 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010594 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010595 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10596 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010597 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010598 return 0;
10599}
10600
Jeff Garzik7282d492006-09-13 14:30:00 -040010601static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010602 .get_link = ipw_ethtool_get_link,
10603 .get_drvinfo = ipw_ethtool_get_drvinfo,
10604 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10605 .get_eeprom = ipw_ethtool_get_eeprom,
10606 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010607};
10608
David Howells7d12e782006-10-05 14:55:46 +010010609static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010610{
10611 struct ipw_priv *priv = data;
10612 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010613
James Ketrenos43f66a62005-03-25 12:31:53 -060010614 if (!priv)
10615 return IRQ_NONE;
10616
Zhu Yi89c318e2006-06-08 22:19:49 -070010617 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010618
10619 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010620 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010621 goto none;
10622 }
10623
James Ketrenosb095c382005-08-24 22:04:42 -050010624 inta = ipw_read32(priv, IPW_INTA_RW);
10625 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010626
James Ketrenos43f66a62005-03-25 12:31:53 -060010627 if (inta == 0xFFFFFFFF) {
10628 /* Hardware disappeared */
10629 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10630 goto none;
10631 }
10632
James Ketrenosb095c382005-08-24 22:04:42 -050010633 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010634 /* Shared interrupt */
10635 goto none;
10636 }
10637
10638 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010639 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010640
James Ketrenos43f66a62005-03-25 12:31:53 -060010641 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010642 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10643 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010644
James Ketrenos43f66a62005-03-25 12:31:53 -060010645 /* Cache INTA value for our tasklet */
10646 priv->isr_inta = inta;
10647
10648 tasklet_schedule(&priv->irq_tasklet);
10649
Zhu Yi89c318e2006-06-08 22:19:49 -070010650 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010651
10652 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010653 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010654 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010655 return IRQ_NONE;
10656}
10657
10658static void ipw_rf_kill(void *adapter)
10659{
10660 struct ipw_priv *priv = adapter;
10661 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010662
James Ketrenos43f66a62005-03-25 12:31:53 -060010663 spin_lock_irqsave(&priv->lock, flags);
10664
10665 if (rf_kill_active(priv)) {
10666 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10667 if (priv->workqueue)
10668 queue_delayed_work(priv->workqueue,
10669 &priv->rf_kill, 2 * HZ);
10670 goto exit_unlock;
10671 }
10672
10673 /* RF Kill is now disabled, so bring the device back up */
10674
10675 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10676 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10677 "device\n");
10678
10679 /* we can not do an adapter restart while inside an irq lock */
10680 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010681 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010682 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10683 "enabled\n");
10684
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010685 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010686 spin_unlock_irqrestore(&priv->lock, flags);
10687}
10688
David Howellsc4028952006-11-22 14:57:56 +000010689static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010690{
David Howellsc4028952006-11-22 14:57:56 +000010691 struct ipw_priv *priv =
10692 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010693 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010694 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010695 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010696}
10697
Adrian Bunka73e22b2006-01-21 01:39:42 +010010698static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010699{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010700 priv->last_seq_num = -1;
10701 priv->last_frag_num = -1;
10702 priv->last_packet_time = 0;
10703
James Ketrenosa613bff2005-08-24 21:43:11 -050010704 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010705
James Ketrenosc848d0a2005-08-24 21:56:24 -050010706 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010707 cancel_delayed_work(&priv->request_direct_scan);
10708 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010709 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010710 ipw_reset_stats(priv);
10711 /* Ensure the rate is updated immediately */
10712 priv->last_rate = ipw_get_current_rate(priv);
10713 ipw_gather_stats(priv);
10714 ipw_led_link_up(priv);
10715 notify_wx_assoc_event(priv);
10716
10717 if (priv->config & CFG_BACKGROUND_SCAN)
10718 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10719}
10720
David Howellsc4028952006-11-22 14:57:56 +000010721static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010722{
David Howellsc4028952006-11-22 14:57:56 +000010723 struct ipw_priv *priv =
10724 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010725 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010726 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010727 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010728}
10729
Adrian Bunka73e22b2006-01-21 01:39:42 +010010730static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010731{
10732 ipw_led_link_down(priv);
10733 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010734 notify_wx_assoc_event(priv);
10735
10736 /* Cancel any queued work ... */
10737 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010738 cancel_delayed_work(&priv->request_direct_scan);
10739 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010740 cancel_delayed_work(&priv->adhoc_check);
10741 cancel_delayed_work(&priv->gather_stats);
10742
10743 ipw_reset_stats(priv);
10744
James Ketrenosafbf30a2005-08-25 00:05:33 -050010745 if (!(priv->status & STATUS_EXIT_PENDING)) {
10746 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010747 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010748 } else
10749 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010750}
10751
David Howellsc4028952006-11-22 14:57:56 +000010752static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010753{
David Howellsc4028952006-11-22 14:57:56 +000010754 struct ipw_priv *priv =
10755 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010756 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010757 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010758 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010759}
10760
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010761static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010762{
10763 int ret = 0;
10764
James Ketrenos43f66a62005-03-25 12:31:53 -060010765 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010766 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010767 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010768
David Howellsc4028952006-11-22 14:57:56 +000010769 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10770 INIT_WORK(&priv->associate, ipw_bg_associate);
10771 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10772 INIT_WORK(&priv->system_config, ipw_system_config);
10773 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10774 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10775 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10776 INIT_WORK(&priv->up, ipw_bg_up);
10777 INIT_WORK(&priv->down, ipw_bg_down);
10778 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010779 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10780 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010781 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010782 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10783 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10784 INIT_WORK(&priv->roam, ipw_bg_roam);
10785 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10786 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10787 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10788 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10789 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10790 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10791 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010792
Zhu Yie43e3c12006-04-13 17:20:45 +080010793#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010794 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010795#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010796
10797 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10798 ipw_irq_tasklet, (unsigned long)priv);
10799
10800 return ret;
10801}
10802
James Ketrenos43f66a62005-03-25 12:31:53 -060010803static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010804 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010805{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010806 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010807 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010808 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010810 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010811 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010812 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010813 priv->ieee->sec.flags &= ~(1 << i);
10814 else {
10815 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010816 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010817 priv->ieee->sec.flags |= (1 << i);
10818 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010819 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010820 } else if (sec->level != SEC_LEVEL_1)
10821 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010822 }
10823
James Ketrenosb095c382005-08-24 22:04:42 -050010824 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010825 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010826 priv->ieee->sec.active_key = sec->active_key;
10827 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010828 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010829 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010830 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010831 } else
10832 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010833
10834 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010835 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10836 priv->ieee->sec.auth_mode = sec->auth_mode;
10837 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010838 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10839 priv->capability |= CAP_SHARED_KEY;
10840 else
10841 priv->capability &= ~CAP_SHARED_KEY;
10842 priv->status |= STATUS_SECURITY_UPDATED;
10843 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010844
James Ketrenosb095c382005-08-24 22:04:42 -050010845 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10846 priv->ieee->sec.flags |= SEC_ENABLED;
10847 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010848 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010849 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010850 priv->capability |= CAP_PRIVACY_ON;
10851 else
10852 priv->capability &= ~CAP_PRIVACY_ON;
10853 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010854
James Ketrenosafbf30a2005-08-25 00:05:33 -050010855 if (sec->flags & SEC_ENCRYPT)
10856 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010857
James Ketrenosb095c382005-08-24 22:04:42 -050010858 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10859 priv->ieee->sec.level = sec->level;
10860 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010861 priv->status |= STATUS_SECURITY_UPDATED;
10862 }
10863
Zhu Yi1fbfea52005-08-05 17:22:56 +080010864 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10865 ipw_set_hwcrypto_keys(priv);
10866
Jeff Garzikbf794512005-07-31 13:07:26 -040010867 /* To match current functionality of ipw2100 (which works well w/
10868 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010869 * privacy capability changes ... */
10870#if 0
10871 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010872 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010873 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010874 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010875 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010876 IPW_DEBUG_ASSOC("Disassociating due to capability "
10877 "change.\n");
10878 ipw_disassociate(priv);
10879 }
10880#endif
10881}
10882
Jeff Garzikbf794512005-07-31 13:07:26 -040010883static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010884 struct ipw_supported_rates *rates)
10885{
10886 /* TODO: Mask out rates based on priv->rates_mask */
10887
10888 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010889 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010890 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010891 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 rates->ieee_mode = IPW_A_MODE;
10893 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010894 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10895 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010896 break;
10897
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010898 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010899 rates->ieee_mode = IPW_G_MODE;
10900 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010901 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10902 LIBIPW_CCK_DEFAULT_RATES_MASK);
10903 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10904 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10905 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010906 }
10907 break;
10908 }
10909
10910 return 0;
10911}
10912
Jeff Garzikbf794512005-07-31 13:07:26 -040010913static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010914{
James Ketrenos43f66a62005-03-25 12:31:53 -060010915 /* This is only called from ipw_up, which resets/reloads the firmware
10916 so, we don't need to first disable the card before we configure
10917 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010918 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010919 goto error;
10920
10921 /* initialize adapter address */
10922 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10923 goto error;
10924
10925 /* set basic system config settings */
10926 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010927
10928 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10929 * Does not support BT priority yet (don't abort or defer our Tx) */
10930 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010931 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010932
10933 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10934 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010935 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010936 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10937 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010938 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010939 }
10940
Zhu Yid685b8c2006-04-13 17:20:27 +080010941#ifdef CONFIG_IPW2200_PROMISCUOUS
10942 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10943 priv->sys_config.accept_all_data_frames = 1;
10944 priv->sys_config.accept_non_directed_frames = 1;
10945 priv->sys_config.accept_all_mgmt_bcpr = 1;
10946 priv->sys_config.accept_all_mgmt_frames = 1;
10947 }
10948#endif
10949
James Ketrenosc848d0a2005-08-24 21:56:24 -050010950 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10951 priv->sys_config.answer_broadcast_ssid_probe = 1;
10952 else
10953 priv->sys_config.answer_broadcast_ssid_probe = 0;
10954
Zhu Yid685b8c2006-04-13 17:20:27 +080010955 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010956 goto error;
10957
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010958 init_supported_rates(priv, &priv->rates);
10959 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010960 goto error;
10961
10962 /* Set request-to-send threshold */
10963 if (priv->rts_threshold) {
10964 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10965 goto error;
10966 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010967#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010968 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10969 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010970#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010971
10972 if (ipw_set_random_seed(priv))
10973 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010974
James Ketrenos43f66a62005-03-25 12:31:53 -060010975 /* final state transition to the RUN state */
10976 if (ipw_send_host_complete(priv))
10977 goto error;
10978
James Ketrenose6666192005-08-12 09:17:04 -050010979 priv->status |= STATUS_INIT;
10980
10981 ipw_led_init(priv);
10982 ipw_led_radio_on(priv);
10983 priv->notif_missed_beacons = 0;
10984
10985 /* Set hardware WEP key if it is configured. */
10986 if ((priv->capability & CAP_PRIVACY_ON) &&
10987 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10988 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10989 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010990
10991 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010992
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010993 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010994 return -EIO;
10995}
10996
James Ketrenos4f36f802005-08-03 20:36:56 -050010997/*
10998 * NOTE:
10999 *
11000 * These tables have been tested in conjunction with the
11001 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11002 *
11003 * Altering this values, using it on other hardware, or in geographies
11004 * not intended for resale of the above mentioned Intel adapters has
11005 * not been tested.
11006 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011007 * Remember to update the table in README.ipw2200 when changing this
11008 * table.
11009 *
James Ketrenos4f36f802005-08-03 20:36:56 -050011010 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011011static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050011012 { /* Restricted */
11013 "---",
11014 .bg_channels = 11,
11015 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11016 {2427, 4}, {2432, 5}, {2437, 6},
11017 {2442, 7}, {2447, 8}, {2452, 9},
11018 {2457, 10}, {2462, 11}},
11019 },
11020
11021 { /* Custom US/Canada */
11022 "ZZF",
11023 .bg_channels = 11,
11024 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11025 {2427, 4}, {2432, 5}, {2437, 6},
11026 {2442, 7}, {2447, 8}, {2452, 9},
11027 {2457, 10}, {2462, 11}},
11028 .a_channels = 8,
11029 .a = {{5180, 36},
11030 {5200, 40},
11031 {5220, 44},
11032 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011033 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11034 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11035 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11036 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011037 },
11038
11039 { /* Rest of World */
11040 "ZZD",
11041 .bg_channels = 13,
11042 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11043 {2427, 4}, {2432, 5}, {2437, 6},
11044 {2442, 7}, {2447, 8}, {2452, 9},
11045 {2457, 10}, {2462, 11}, {2467, 12},
11046 {2472, 13}},
11047 },
11048
11049 { /* Custom USA & Europe & High */
11050 "ZZA",
11051 .bg_channels = 11,
11052 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11053 {2427, 4}, {2432, 5}, {2437, 6},
11054 {2442, 7}, {2447, 8}, {2452, 9},
11055 {2457, 10}, {2462, 11}},
11056 .a_channels = 13,
11057 .a = {{5180, 36},
11058 {5200, 40},
11059 {5220, 44},
11060 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011061 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11062 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11063 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11064 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011065 {5745, 149},
11066 {5765, 153},
11067 {5785, 157},
11068 {5805, 161},
11069 {5825, 165}},
11070 },
11071
11072 { /* Custom NA & Europe */
11073 "ZZB",
11074 .bg_channels = 11,
11075 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11076 {2427, 4}, {2432, 5}, {2437, 6},
11077 {2442, 7}, {2447, 8}, {2452, 9},
11078 {2457, 10}, {2462, 11}},
11079 .a_channels = 13,
11080 .a = {{5180, 36},
11081 {5200, 40},
11082 {5220, 44},
11083 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011084 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11085 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11086 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11087 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11088 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11089 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11090 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11091 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11092 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011093 },
11094
11095 { /* Custom Japan */
11096 "ZZC",
11097 .bg_channels = 11,
11098 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11099 {2427, 4}, {2432, 5}, {2437, 6},
11100 {2442, 7}, {2447, 8}, {2452, 9},
11101 {2457, 10}, {2462, 11}},
11102 .a_channels = 4,
11103 .a = {{5170, 34}, {5190, 38},
11104 {5210, 42}, {5230, 46}},
11105 },
11106
11107 { /* Custom */
11108 "ZZM",
11109 .bg_channels = 11,
11110 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11111 {2427, 4}, {2432, 5}, {2437, 6},
11112 {2442, 7}, {2447, 8}, {2452, 9},
11113 {2457, 10}, {2462, 11}},
11114 },
11115
11116 { /* Europe */
11117 "ZZE",
11118 .bg_channels = 13,
11119 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11120 {2427, 4}, {2432, 5}, {2437, 6},
11121 {2442, 7}, {2447, 8}, {2452, 9},
11122 {2457, 10}, {2462, 11}, {2467, 12},
11123 {2472, 13}},
11124 .a_channels = 19,
11125 .a = {{5180, 36},
11126 {5200, 40},
11127 {5220, 44},
11128 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011129 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11130 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11131 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11132 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11133 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11134 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11135 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11136 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11137 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11138 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11139 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11140 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11141 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11142 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11143 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011144 },
11145
11146 { /* Custom Japan */
11147 "ZZJ",
11148 .bg_channels = 14,
11149 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11150 {2427, 4}, {2432, 5}, {2437, 6},
11151 {2442, 7}, {2447, 8}, {2452, 9},
11152 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011153 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011154 .a_channels = 4,
11155 .a = {{5170, 34}, {5190, 38},
11156 {5210, 42}, {5230, 46}},
11157 },
11158
James Ketrenos03520572005-10-19 16:12:31 -050011159 { /* Rest of World */
11160 "ZZR",
11161 .bg_channels = 14,
11162 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11163 {2427, 4}, {2432, 5}, {2437, 6},
11164 {2442, 7}, {2447, 8}, {2452, 9},
11165 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011166 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11167 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011168 },
11169
James Ketrenos4f36f802005-08-03 20:36:56 -050011170 { /* High Band */
11171 "ZZH",
11172 .bg_channels = 13,
11173 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11174 {2427, 4}, {2432, 5}, {2437, 6},
11175 {2442, 7}, {2447, 8}, {2452, 9},
11176 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011177 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11178 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011179 .a_channels = 4,
11180 .a = {{5745, 149}, {5765, 153},
11181 {5785, 157}, {5805, 161}},
11182 },
11183
11184 { /* Custom Europe */
11185 "ZZG",
11186 .bg_channels = 13,
11187 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11188 {2427, 4}, {2432, 5}, {2437, 6},
11189 {2442, 7}, {2447, 8}, {2452, 9},
11190 {2457, 10}, {2462, 11},
11191 {2467, 12}, {2472, 13}},
11192 .a_channels = 4,
11193 .a = {{5180, 36}, {5200, 40},
11194 {5220, 44}, {5240, 48}},
11195 },
11196
11197 { /* Europe */
11198 "ZZK",
11199 .bg_channels = 13,
11200 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11201 {2427, 4}, {2432, 5}, {2437, 6},
11202 {2442, 7}, {2447, 8}, {2452, 9},
11203 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011204 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11205 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011206 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011207 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11208 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11209 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11210 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11211 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11212 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11213 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11214 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11215 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11216 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11217 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11218 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11219 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11220 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11221 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11222 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11223 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11224 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11225 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11226 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11227 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11228 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11229 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11230 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011231 },
11232
11233 { /* Europe */
11234 "ZZL",
11235 .bg_channels = 11,
11236 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11237 {2427, 4}, {2432, 5}, {2437, 6},
11238 {2442, 7}, {2447, 8}, {2452, 9},
11239 {2457, 10}, {2462, 11}},
11240 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011241 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11242 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11243 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11244 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11245 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11246 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11247 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11248 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11249 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11250 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11251 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11252 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11253 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011254 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011255};
11256
James Ketrenos43f66a62005-03-25 12:31:53 -060011257#define MAX_HW_RESTARTS 5
11258static int ipw_up(struct ipw_priv *priv)
11259{
James Ketrenos4f36f802005-08-03 20:36:56 -050011260 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011261
Dan Williamsc3d72b92009-02-11 13:26:06 -050011262 /* Age scan list entries found before suspend */
11263 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011264 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011265 priv->suspend_time = 0;
11266 }
11267
James Ketrenos43f66a62005-03-25 12:31:53 -060011268 if (priv->status & STATUS_EXIT_PENDING)
11269 return -EIO;
11270
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011271 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011272 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011273 GFP_KERNEL);
11274 if (priv->cmdlog == NULL) {
11275 IPW_ERROR("Error allocating %d command log entries.\n",
11276 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011277 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011278 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011279 priv->cmdlog_len = cmdlog;
11280 }
11281 }
11282
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011283 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011284 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011285 * Also start the clocks. */
11286 rc = ipw_load(priv);
11287 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011288 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011289 return rc;
11290 }
11291
11292 ipw_init_ordinals(priv);
11293 if (!(priv->config & CFG_CUSTOM_MAC))
11294 eeprom_parse_mac(priv, priv->mac_addr);
11295 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011296 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011297
James Ketrenos4f36f802005-08-03 20:36:56 -050011298 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11299 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11300 ipw_geos[j].name, 3))
11301 break;
11302 }
James Ketrenos03520572005-10-19 16:12:31 -050011303 if (j == ARRAY_SIZE(ipw_geos)) {
11304 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11305 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11306 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11307 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011308 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011309 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011310 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011311 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011312 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011313 }
11314
James Ketrenosb095c382005-08-24 22:04:42 -050011315 if (priv->status & STATUS_RF_KILL_SW) {
11316 IPW_WARNING("Radio disabled by module parameter.\n");
11317 return 0;
11318 } else if (rf_kill_active(priv)) {
11319 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11320 "Kill switch must be turned off for "
11321 "wireless networking to work.\n");
11322 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11323 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. */
David Howellsc4028952006-11-22 14:57:56 +000011333 queue_delayed_work(priv->workqueue,
11334 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011335
James Ketrenos43f66a62005-03-25 12:31:53 -060011336 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011337 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011338
James Ketrenosc848d0a2005-08-24 21:56:24 -050011339 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011340 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11341 i, MAX_HW_RESTARTS);
11342
11343 /* We had an error bringing up the hardware, so take it
11344 * all the way back down so we can try again */
11345 ipw_down(priv);
11346 }
11347
Jeff Garzikbf794512005-07-31 13:07:26 -040011348 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011349 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011350 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011351
James Ketrenos43f66a62005-03-25 12:31:53 -060011352 return -EIO;
11353}
11354
David Howellsc4028952006-11-22 14:57:56 +000011355static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011356{
David Howellsc4028952006-11-22 14:57:56 +000011357 struct ipw_priv *priv =
11358 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011359 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011360 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011361 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011362}
11363
James Ketrenosb095c382005-08-24 22:04:42 -050011364static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011365{
James Ketrenosb095c382005-08-24 22:04:42 -050011366 int i;
11367
11368 if (priv->status & STATUS_SCANNING) {
11369 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11370 ipw_abort_scan(priv);
11371 }
11372
11373 if (priv->status & STATUS_ASSOCIATED) {
11374 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11375 ipw_disassociate(priv);
11376 }
11377
11378 ipw_led_shutdown(priv);
11379
11380 /* Wait up to 1s for status to change to not scanning and not
11381 * associated (disassociation can take a while for a ful 802.11
11382 * exchange */
11383 for (i = 1000; i && (priv->status &
11384 (STATUS_DISASSOCIATING |
11385 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11386 udelay(10);
11387
11388 if (priv->status & (STATUS_DISASSOCIATING |
11389 STATUS_ASSOCIATED | STATUS_SCANNING))
11390 IPW_DEBUG_INFO("Still associated or scanning...\n");
11391 else
11392 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11393
James Ketrenosc848d0a2005-08-24 21:56:24 -050011394 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011395 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011396
11397 priv->status &= ~STATUS_INIT;
11398}
11399
James Ketrenos43f66a62005-03-25 12:31:53 -060011400static void ipw_down(struct ipw_priv *priv)
11401{
James Ketrenosb095c382005-08-24 22:04:42 -050011402 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11403
11404 priv->status |= STATUS_EXIT_PENDING;
11405
11406 if (ipw_is_init(priv))
11407 ipw_deinit(priv);
11408
11409 /* Wipe out the EXIT_PENDING status bit if we are not actually
11410 * exiting the module */
11411 if (!exit_pending)
11412 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011413
11414 /* tell the device to stop sending interrupts */
11415 ipw_disable_interrupts(priv);
11416
11417 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011418 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011419 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011420
11421 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011422
11423 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011424}
11425
David Howellsc4028952006-11-22 14:57:56 +000011426static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011427{
David Howellsc4028952006-11-22 14:57:56 +000011428 struct ipw_priv *priv =
11429 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011430 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011431 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011432 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011433}
11434
11435/* Called by register_netdev() */
11436static int ipw_net_init(struct net_device *dev)
11437{
John W. Linvillea3caa992009-08-25 14:12:25 -040011438 int i, rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011439 struct ipw_priv *priv = libipw_priv(dev);
John W. Linvillea3caa992009-08-25 14:12:25 -040011440 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11441 struct wireless_dev *wdev = &priv->ieee->wdev;
Zhu Yi46441512006-01-24 16:37:59 +080011442 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011443
James Ketrenosc848d0a2005-08-24 21:56:24 -050011444 if (ipw_up(priv)) {
John W. Linvillea3caa992009-08-25 14:12:25 -040011445 rc = -EIO;
11446 goto out;
James Ketrenos43f66a62005-03-25 12:31:53 -060011447 }
11448
John W. Linvillea3caa992009-08-25 14:12:25 -040011449 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11450
11451 /* fill-out priv->ieee->bg_band */
11452 if (geo->bg_channels) {
11453 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11454
11455 bg_band->band = IEEE80211_BAND_2GHZ;
11456 bg_band->n_channels = geo->bg_channels;
11457 bg_band->channels =
11458 kzalloc(geo->bg_channels *
11459 sizeof(struct ieee80211_channel), GFP_KERNEL);
11460 /* translate geo->bg to bg_band.channels */
11461 for (i = 0; i < geo->bg_channels; i++) {
11462 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11463 bg_band->channels[i].center_freq = geo->bg[i].freq;
11464 bg_band->channels[i].hw_value = geo->bg[i].channel;
11465 bg_band->channels[i].max_power = geo->bg[i].max_power;
11466 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11467 bg_band->channels[i].flags |=
11468 IEEE80211_CHAN_PASSIVE_SCAN;
11469 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11470 bg_band->channels[i].flags |=
11471 IEEE80211_CHAN_NO_IBSS;
11472 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11473 bg_band->channels[i].flags |=
11474 IEEE80211_CHAN_RADAR;
11475 /* No equivalent for LIBIPW_CH_80211H_RULES,
11476 LIBIPW_CH_UNIFORM_SPREADING, or
11477 LIBIPW_CH_B_ONLY... */
11478 }
11479 /* point at bitrate info */
11480 bg_band->bitrates = ipw2200_bg_rates;
11481 bg_band->n_bitrates = ipw2200_num_bg_rates;
11482
11483 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11484 }
11485
11486 /* fill-out priv->ieee->a_band */
11487 if (geo->a_channels) {
11488 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11489
11490 a_band->band = IEEE80211_BAND_5GHZ;
11491 a_band->n_channels = geo->a_channels;
11492 a_band->channels =
11493 kzalloc(geo->a_channels *
11494 sizeof(struct ieee80211_channel), GFP_KERNEL);
11495 /* translate geo->bg to a_band.channels */
11496 for (i = 0; i < geo->a_channels; i++) {
11497 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11498 a_band->channels[i].center_freq = geo->a[i].freq;
11499 a_band->channels[i].hw_value = geo->a[i].channel;
11500 a_band->channels[i].max_power = geo->a[i].max_power;
11501 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11502 a_band->channels[i].flags |=
11503 IEEE80211_CHAN_PASSIVE_SCAN;
11504 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11505 a_band->channels[i].flags |=
11506 IEEE80211_CHAN_NO_IBSS;
11507 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11508 a_band->channels[i].flags |=
11509 IEEE80211_CHAN_RADAR;
11510 /* No equivalent for LIBIPW_CH_80211H_RULES,
11511 LIBIPW_CH_UNIFORM_SPREADING, or
11512 LIBIPW_CH_B_ONLY... */
11513 }
11514 /* point at bitrate info */
11515 a_band->bitrates = ipw2200_a_rates;
11516 a_band->n_bitrates = ipw2200_num_a_rates;
11517
11518 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11519 }
11520
11521 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11522
11523 /* With that information in place, we can now register the wiphy... */
11524 if (wiphy_register(wdev->wiphy)) {
11525 rc = -EIO;
11526 goto out;
11527 }
11528
11529out:
Zhu Yi46441512006-01-24 16:37:59 +080011530 mutex_unlock(&priv->mutex);
John W. Linvillea3caa992009-08-25 14:12:25 -040011531 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -060011532}
11533
11534/* PCI driver stuff */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000011535static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
James Ketrenos43f66a62005-03-25 12:31:53 -060011536 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11537 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11538 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11539 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11540 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11541 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11542 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11543 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11544 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11545 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11552 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011553 {PCI_VDEVICE(INTEL, 0x104f), 0},
11554 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11555 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11556 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11557 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011558
James Ketrenos43f66a62005-03-25 12:31:53 -060011559 /* required last entry */
11560 {0,}
11561};
11562
11563MODULE_DEVICE_TABLE(pci, card_ids);
11564
11565static struct attribute *ipw_sysfs_entries[] = {
11566 &dev_attr_rf_kill.attr,
11567 &dev_attr_direct_dword.attr,
11568 &dev_attr_indirect_byte.attr,
11569 &dev_attr_indirect_dword.attr,
11570 &dev_attr_mem_gpio_reg.attr,
11571 &dev_attr_command_event_reg.attr,
11572 &dev_attr_nic_type.attr,
11573 &dev_attr_status.attr,
11574 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011575 &dev_attr_error.attr,
11576 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011577 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011578 &dev_attr_eeprom_delay.attr,
11579 &dev_attr_ucode_version.attr,
11580 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011581 &dev_attr_scan_age.attr,
11582 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011583 &dev_attr_speed_scan.attr,
11584 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011585 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011586#ifdef CONFIG_IPW2200_PROMISCUOUS
11587 &dev_attr_rtap_iface.attr,
11588 &dev_attr_rtap_filter.attr,
11589#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011590 NULL
11591};
11592
11593static struct attribute_group ipw_attribute_group = {
11594 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011595 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011596};
11597
Zhu Yid685b8c2006-04-13 17:20:27 +080011598#ifdef CONFIG_IPW2200_PROMISCUOUS
11599static int ipw_prom_open(struct net_device *dev)
11600{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011601 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011602 struct ipw_priv *priv = prom_priv->priv;
11603
11604 IPW_DEBUG_INFO("prom dev->open\n");
11605 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011606
11607 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11608 priv->sys_config.accept_all_data_frames = 1;
11609 priv->sys_config.accept_non_directed_frames = 1;
11610 priv->sys_config.accept_all_mgmt_bcpr = 1;
11611 priv->sys_config.accept_all_mgmt_frames = 1;
11612
11613 ipw_send_system_config(priv);
11614 }
11615
11616 return 0;
11617}
11618
11619static int ipw_prom_stop(struct net_device *dev)
11620{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011621 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011622 struct ipw_priv *priv = prom_priv->priv;
11623
11624 IPW_DEBUG_INFO("prom dev->stop\n");
11625
11626 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11627 priv->sys_config.accept_all_data_frames = 0;
11628 priv->sys_config.accept_non_directed_frames = 0;
11629 priv->sys_config.accept_all_mgmt_bcpr = 0;
11630 priv->sys_config.accept_all_mgmt_frames = 0;
11631
11632 ipw_send_system_config(priv);
11633 }
11634
11635 return 0;
11636}
11637
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011638static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11639 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011640{
11641 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011642 dev_kfree_skb(skb);
11643 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011644}
11645
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011646static const struct net_device_ops ipw_prom_netdev_ops = {
11647 .ndo_open = ipw_prom_open,
11648 .ndo_stop = ipw_prom_stop,
11649 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011650 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011651 .ndo_set_mac_address = eth_mac_addr,
11652 .ndo_validate_addr = eth_validate_addr,
11653};
11654
Zhu Yid685b8c2006-04-13 17:20:27 +080011655static int ipw_prom_alloc(struct ipw_priv *priv)
11656{
11657 int rc = 0;
11658
11659 if (priv->prom_net_dev)
11660 return -EPERM;
11661
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011662 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011663 if (priv->prom_net_dev == NULL)
11664 return -ENOMEM;
11665
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011666 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011667 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11668 priv->prom_priv->priv = priv;
11669
11670 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011671 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011672
11673 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011674 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011675
11676 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011677 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011678
11679 rc = register_netdev(priv->prom_net_dev);
11680 if (rc) {
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011681 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011682 priv->prom_net_dev = NULL;
11683 return rc;
11684 }
11685
11686 return 0;
11687}
11688
11689static void ipw_prom_free(struct ipw_priv *priv)
11690{
11691 if (!priv->prom_net_dev)
11692 return;
11693
11694 unregister_netdev(priv->prom_net_dev);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011695 free_libipw(priv->prom_net_dev, 1);
Zhu Yid685b8c2006-04-13 17:20:27 +080011696
11697 priv->prom_net_dev = NULL;
11698}
11699
11700#endif
11701
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011702static const struct net_device_ops ipw_netdev_ops = {
11703 .ndo_init = ipw_net_init,
11704 .ndo_open = ipw_net_open,
11705 .ndo_stop = ipw_net_stop,
11706 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11707 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011708 .ndo_start_xmit = libipw_xmit,
11709 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011710 .ndo_validate_addr = eth_validate_addr,
11711};
Zhu Yid685b8c2006-04-13 17:20:27 +080011712
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011713static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11714 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011715{
11716 int err = 0;
11717 struct net_device *net_dev;
11718 void __iomem *base;
11719 u32 length, val;
11720 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011721 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011722
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011723 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011724 if (net_dev == NULL) {
11725 err = -ENOMEM;
11726 goto out;
11727 }
11728
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011729 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011730 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011731
James Ketrenos43f66a62005-03-25 12:31:53 -060011732 priv->net_dev = net_dev;
11733 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011734 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011735 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011736 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011737 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11738 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011739
Zhu Yi46441512006-01-24 16:37:59 +080011740 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011741 if (pci_enable_device(pdev)) {
11742 err = -ENODEV;
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011743 goto out_free_libipw;
James Ketrenos43f66a62005-03-25 12:31:53 -060011744 }
11745
11746 pci_set_master(pdev);
11747
Yang Hongyang284901a2009-04-06 19:01:15 -070011748 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011749 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011750 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011751 if (err) {
11752 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11753 goto out_pci_disable_device;
11754 }
11755
11756 pci_set_drvdata(pdev, priv);
11757
11758 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011759 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011760 goto out_pci_disable_device;
11761
Jeff Garzikbf794512005-07-31 13:07:26 -040011762 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011763 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011764 pci_read_config_dword(pdev, 0x40, &val);
11765 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011766 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011767
James Ketrenos43f66a62005-03-25 12:31:53 -060011768 length = pci_resource_len(pdev, 0);
11769 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011770
Arjan van de Ven275f1652008-10-20 21:42:39 -070011771 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011772 if (!base) {
11773 err = -ENODEV;
11774 goto out_pci_release_regions;
11775 }
11776
11777 priv->hw_base = base;
11778 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11779 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11780
11781 err = ipw_setup_deferred_work(priv);
11782 if (err) {
11783 IPW_ERROR("Unable to setup deferred work\n");
11784 goto out_iounmap;
11785 }
11786
James Ketrenosb095c382005-08-24 22:04:42 -050011787 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011788
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011789 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011790 if (err) {
11791 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11792 goto out_destroy_workqueue;
11793 }
11794
James Ketrenos43f66a62005-03-25 12:31:53 -060011795 SET_NETDEV_DEV(net_dev, &pdev->dev);
11796
Zhu Yi46441512006-01-24 16:37:59 +080011797 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011798
James Ketrenos43f66a62005-03-25 12:31:53 -060011799 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11800 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011801 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011802
Zhu Yie43e3c12006-04-13 17:20:45 +080011803#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011804 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011805 priv->ieee->handle_probe_response = ipw_handle_beacon;
11806 priv->ieee->handle_beacon = ipw_handle_probe_response;
11807 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011808#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011809
James Ketrenosc848d0a2005-08-24 21:56:24 -050011810 priv->ieee->perfect_rssi = -20;
11811 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011812
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011813 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011814 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011815 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011816 net_dev->wireless_handlers = &ipw_wx_handler_def;
11817 net_dev->ethtool_ops = &ipw_ethtool_ops;
11818 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011819 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011820 net_dev->mem_start = pci_resource_start(pdev, 0);
11821 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11822
11823 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11824 if (err) {
11825 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011826 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011827 goto out_release_irq;
11828 }
11829
Zhu Yi46441512006-01-24 16:37:59 +080011830 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011831 err = register_netdev(net_dev);
11832 if (err) {
11833 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011834 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011835 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011836
Zhu Yid685b8c2006-04-13 17:20:27 +080011837#ifdef CONFIG_IPW2200_PROMISCUOUS
11838 if (rtap_iface) {
11839 err = ipw_prom_alloc(priv);
11840 if (err) {
11841 IPW_ERROR("Failed to register promiscuous network "
11842 "device (error %d).\n", err);
11843 unregister_netdev(priv->net_dev);
11844 goto out_remove_sysfs;
11845 }
11846 }
11847#endif
11848
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011849 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11850 "channels, %d 802.11a channels)\n",
11851 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11852 priv->ieee->geo.a_channels);
11853
James Ketrenos43f66a62005-03-25 12:31:53 -060011854 return 0;
11855
James Ketrenosa613bff2005-08-24 21:43:11 -050011856 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011857 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011858 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011859 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011860 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011861 destroy_workqueue(priv->workqueue);
11862 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011863 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011864 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011865 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011866 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011867 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011868 pci_disable_device(pdev);
11869 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011870 out_free_libipw:
11871 free_libipw(priv->net_dev, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011872 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011873 return err;
11874}
11875
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011876static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011877{
11878 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011879 struct list_head *p, *q;
11880 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011881
James Ketrenos43f66a62005-03-25 12:31:53 -060011882 if (!priv)
11883 return;
11884
Zhu Yi46441512006-01-24 16:37:59 +080011885 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011886
James Ketrenosafbf30a2005-08-25 00:05:33 -050011887 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011888 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011889 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11890
Zhu Yi46441512006-01-24 16:37:59 +080011891 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011892
11893 unregister_netdev(priv->net_dev);
11894
11895 if (priv->rxq) {
11896 ipw_rx_queue_free(priv, priv->rxq);
11897 priv->rxq = NULL;
11898 }
11899 ipw_tx_queue_free(priv);
11900
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011901 if (priv->cmdlog) {
11902 kfree(priv->cmdlog);
11903 priv->cmdlog = NULL;
11904 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011905 /* ipw_down will ensure that there is no more pending work
11906 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011907 cancel_delayed_work(&priv->adhoc_check);
11908 cancel_delayed_work(&priv->gather_stats);
11909 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011910 cancel_delayed_work(&priv->request_direct_scan);
11911 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011912 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011913 cancel_delayed_work(&priv->rf_kill);
11914 cancel_delayed_work(&priv->scan_check);
11915 destroy_workqueue(priv->workqueue);
11916 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011917
James Ketrenosafbf30a2005-08-25 00:05:33 -050011918 /* Free MAC hash list for ADHOC */
11919 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11920 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011921 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011922 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011923 }
11924 }
11925
Jesper Juhl8f760782006-06-27 02:55:06 -070011926 kfree(priv->error);
11927 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011928
Zhu Yid685b8c2006-04-13 17:20:27 +080011929#ifdef CONFIG_IPW2200_PROMISCUOUS
11930 ipw_prom_free(priv);
11931#endif
11932
James Ketrenos43f66a62005-03-25 12:31:53 -060011933 free_irq(pdev->irq, priv);
11934 iounmap(priv->hw_base);
11935 pci_release_regions(pdev);
11936 pci_disable_device(pdev);
11937 pci_set_drvdata(pdev, NULL);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011938 /* wiphy_unregister needs to be here, before free_libipw */
John W. Linvillea3caa992009-08-25 14:12:25 -040011939 wiphy_unregister(priv->ieee->wdev.wiphy);
11940 kfree(priv->ieee->a_band.channels);
11941 kfree(priv->ieee->bg_band.channels);
Pavel Roskin27ae60f2010-03-12 00:01:22 -050011942 free_libipw(priv->net_dev, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011943 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011944}
11945
James Ketrenos43f66a62005-03-25 12:31:53 -060011946#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011947static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011948{
11949 struct ipw_priv *priv = pci_get_drvdata(pdev);
11950 struct net_device *dev = priv->net_dev;
11951
11952 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11953
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011954 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011955 ipw_down(priv);
11956
11957 /* Remove the PRESENT state of the device */
11958 netif_device_detach(dev);
11959
James Ketrenos43f66a62005-03-25 12:31:53 -060011960 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011961 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011962 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011963
Dan Williamsc3d72b92009-02-11 13:26:06 -050011964 priv->suspend_at = get_seconds();
11965
James Ketrenos43f66a62005-03-25 12:31:53 -060011966 return 0;
11967}
11968
11969static int ipw_pci_resume(struct pci_dev *pdev)
11970{
11971 struct ipw_priv *priv = pci_get_drvdata(pdev);
11972 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011973 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011974 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011975
James Ketrenos43f66a62005-03-25 12:31:53 -060011976 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11977
James Ketrenosea2b26e2005-08-24 21:25:16 -050011978 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011979 err = pci_enable_device(pdev);
11980 if (err) {
11981 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11982 dev->name);
11983 return err;
11984 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011985 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011986
James Ketrenos43f66a62005-03-25 12:31:53 -060011987 /*
11988 * Suspend/Resume resets the PCI configuration space, so we have to
11989 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11990 * from interfering with C3 CPU state. pci_restore_state won't help
11991 * here since it only restores the first 64 bytes pci config header.
11992 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011993 pci_read_config_dword(pdev, 0x40, &val);
11994 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011995 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11996
11997 /* Set the device back into the PRESENT state; this will also wake
11998 * the queue of needed */
11999 netif_device_attach(dev);
12000
Dan Williamsc3d72b92009-02-11 13:26:06 -050012001 priv->suspend_time = get_seconds() - priv->suspend_at;
12002
James Ketrenos43f66a62005-03-25 12:31:53 -060012003 /* Bring the device back up */
12004 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040012005
James Ketrenos43f66a62005-03-25 12:31:53 -060012006 return 0;
12007}
12008#endif
12009
Zhu Yic8c22c92006-08-21 11:38:39 +080012010static void ipw_pci_shutdown(struct pci_dev *pdev)
12011{
12012 struct ipw_priv *priv = pci_get_drvdata(pdev);
12013
12014 /* Take down the device; powers it off, etc. */
12015 ipw_down(priv);
12016
12017 pci_disable_device(pdev);
12018}
12019
James Ketrenos43f66a62005-03-25 12:31:53 -060012020/* driver initialization stuff */
12021static struct pci_driver ipw_driver = {
12022 .name = DRV_NAME,
12023 .id_table = card_ids,
12024 .probe = ipw_pci_probe,
12025 .remove = __devexit_p(ipw_pci_remove),
12026#ifdef CONFIG_PM
12027 .suspend = ipw_pci_suspend,
12028 .resume = ipw_pci_resume,
12029#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080012030 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060012031};
12032
12033static int __init ipw_init(void)
12034{
12035 int ret;
12036
12037 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12038 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12039
Jeff Garzik29917622006-08-19 17:48:59 -040012040 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060012041 if (ret) {
12042 IPW_ERROR("Unable to initialize PCI module\n");
12043 return ret;
12044 }
12045
Jeff Garzik0edd5b42005-09-07 00:48:31 -040012046 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060012047 if (ret) {
12048 IPW_ERROR("Unable to create driver sysfs file\n");
12049 pci_unregister_driver(&ipw_driver);
12050 return ret;
12051 }
12052
12053 return ret;
12054}
12055
12056static void __exit ipw_exit(void)
12057{
12058 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12059 pci_unregister_driver(&ipw_driver);
12060}
12061
12062module_param(disable, int, 0444);
12063MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12064
12065module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060012066MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060012067
12068module_param(auto_create, int, 0444);
12069MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12070
Reinette Chatre21f8a732009-08-18 10:25:05 -070012071module_param_named(led, led_support, int, 0444);
Niels de Vos61a2d072008-07-31 00:07:23 -070012072MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
James Ketrenosa613bff2005-08-24 21:43:11 -050012073
James Ketrenos43f66a62005-03-25 12:31:53 -060012074module_param(debug, int, 0444);
12075MODULE_PARM_DESC(debug, "debug output mask");
12076
Reinette Chatre21f8a732009-08-18 10:25:05 -070012077module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040012078MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060012079
Zhu Yid685b8c2006-04-13 17:20:27 +080012080#ifdef CONFIG_IPW2200_PROMISCUOUS
12081module_param(rtap_iface, int, 0444);
12082MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12083#endif
12084
Zhu Yie43e3c12006-04-13 17:20:45 +080012085#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050012086module_param(qos_enable, int, 0444);
12087MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060012088
James Ketrenosb095c382005-08-24 22:04:42 -050012089module_param(qos_burst_enable, int, 0444);
12090MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12091
12092module_param(qos_no_ack_mask, int, 0444);
12093MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12094
12095module_param(burst_duration_CCK, int, 0444);
12096MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12097
12098module_param(burst_duration_OFDM, int, 0444);
12099MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080012100#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012101
12102#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012103module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012104MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12105#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012106module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012107MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12108#endif
12109
Zhu Yi810dabd2006-01-24 16:36:59 +080012110module_param(bt_coexist, int, 0444);
12111MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12112
James Ketrenosb095c382005-08-24 22:04:42 -050012113module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012114MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012115
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012116module_param(cmdlog, int, 0444);
12117MODULE_PARM_DESC(cmdlog,
12118 "allocate a ring buffer for logging firmware commands");
12119
Zhu Yi4bfdb912006-01-24 16:37:16 +080012120module_param(roaming, int, 0444);
12121MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12122
Zhu Yid2b83e12006-04-13 17:19:36 +080012123module_param(antenna, int, 0444);
12124MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12125
James Ketrenos43f66a62005-03-25 12:31:53 -060012126module_exit(ipw_exit);
12127module_init(ipw_init);