blob: 9fe0e8078a8820538c7e4e51a4f9da9435816c2c [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
112
Zhu Yie43e3c12006-04-13 17:20:45 +0800113#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500114static int qos_enable = 0;
115static int qos_burst_enable = 0;
116static int qos_no_ack_mask = 0;
117static int burst_duration_CCK = 0;
118static int burst_duration_OFDM = 0;
119
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400120static struct libipw_qos_parameters def_qos_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500121 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
122 QOS_TX3_CW_MIN_OFDM},
123 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
124 QOS_TX3_CW_MAX_OFDM},
125 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
126 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
127 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
128 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
129};
130
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400131static struct libipw_qos_parameters def_qos_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500132 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
133 QOS_TX3_CW_MIN_CCK},
134 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
135 QOS_TX3_CW_MAX_CCK},
136 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
137 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
138 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
139 QOS_TX3_TXOP_LIMIT_CCK}
140};
141
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400142static struct libipw_qos_parameters def_parameters_OFDM = {
James Ketrenosb095c382005-08-24 22:04:42 -0500143 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
144 DEF_TX3_CW_MIN_OFDM},
145 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
146 DEF_TX3_CW_MAX_OFDM},
147 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
148 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
149 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
150 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
151};
152
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400153static struct libipw_qos_parameters def_parameters_CCK = {
James Ketrenosb095c382005-08-24 22:04:42 -0500154 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
155 DEF_TX3_CW_MIN_CCK},
156 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
157 DEF_TX3_CW_MAX_CCK},
158 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
159 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
160 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
161 DEF_TX3_TXOP_LIMIT_CCK}
162};
163
164static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
165
166static int from_priority_to_tx_queue[] = {
167 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
168 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
169};
170
171static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
172
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400173static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -0500174 *qos_param);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400175static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -0500176 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800177#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500178
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000179static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500180static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600181static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400182static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600183 struct clx2_tx_queue *txq, int qindex);
184static int ipw_queue_reset(struct ipw_priv *priv);
185
186static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
187 int len, int sync);
188
189static void ipw_tx_queue_free(struct ipw_priv *);
190
191static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
192static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
193static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600194static int ipw_up(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000195static void ipw_bg_up(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600196static void ipw_down(struct ipw_priv *);
David Howellsc4028952006-11-22 14:57:56 +0000197static void ipw_bg_down(struct work_struct *work);
James Ketrenos43f66a62005-03-25 12:31:53 -0600198static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400199static int init_supported_rates(struct ipw_priv *priv,
200 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500201static void ipw_set_hwcrypto_keys(struct ipw_priv *);
202static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600203
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500204static int snprint_line(char *buf, size_t count,
205 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600206{
207 int out, i, j, l;
208 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400209
James Ketrenos43f66a62005-03-25 12:31:53 -0600210 out = snprintf(buf, count, "%08X", ofs);
211
212 for (l = 0, i = 0; i < 2; i++) {
213 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400214 for (j = 0; j < 8 && l < len; j++, l++)
215 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600216 data[(i * 8 + j)]);
217 for (; j < 8; j++)
218 out += snprintf(buf + out, count - out, " ");
219 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400220
James Ketrenos43f66a62005-03-25 12:31:53 -0600221 out += snprintf(buf + out, count - out, " ");
222 for (l = 0, i = 0; i < 2; i++) {
223 out += snprintf(buf + out, count - out, " ");
224 for (j = 0; j < 8 && l < len; j++, l++) {
225 c = data[(i * 8 + j)];
226 if (!isascii(c) || !isprint(c))
227 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400228
James Ketrenos43f66a62005-03-25 12:31:53 -0600229 out += snprintf(buf + out, count - out, "%c", c);
230 }
231
232 for (; j < 8; j++)
233 out += snprintf(buf + out, count - out, " ");
234 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400235
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500236 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600237}
238
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400239static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600240{
241 char line[81];
242 u32 ofs = 0;
243 if (!(ipw_debug_level & level))
244 return;
245
246 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500247 snprint_line(line, sizeof(line), &data[ofs],
248 min(len, 16U), ofs);
249 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600250 ofs += 16;
251 len -= min(len, 16U);
252 }
253}
254
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500255static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
256{
257 size_t out = size;
258 u32 ofs = 0;
259 int total = 0;
260
261 while (size && len) {
262 out = snprint_line(output, size, &data[ofs],
263 min_t(size_t, len, 16U), ofs);
264
265 ofs += 16;
266 output += out;
267 size -= out;
268 len -= min_t(size_t, len, 16U);
269 total += out;
270 }
271 return total;
272}
273
Zhu Yic8fe6672006-01-24 16:36:36 +0800274/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600275static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
276#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
277
Zhu Yic8fe6672006-01-24 16:36:36 +0800278/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600279static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
280#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
281
Zhu Yic8fe6672006-01-24 16:36:36 +0800282/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600283static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
284static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
285{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400286 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
287 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600288 _ipw_write_reg8(a, b, c);
289}
290
Zhu Yic8fe6672006-01-24 16:36:36 +0800291/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600292static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
293static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
294{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400295 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
296 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600297 _ipw_write_reg16(a, b, c);
298}
299
Zhu Yic8fe6672006-01-24 16:36:36 +0800300/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600301static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
302static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
303{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400304 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
305 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600306 _ipw_write_reg32(a, b, c);
307}
308
Zhu Yic8fe6672006-01-24 16:36:36 +0800309/* 8-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100310static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
311 u8 val)
312{
313 writeb(val, ipw->hw_base + ofs);
314}
Zhu Yic8fe6672006-01-24 16:36:36 +0800315
316/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Takashi Iwaifb55d882008-07-31 19:02:06 +0200317#define ipw_write8(ipw, ofs, val) do { \
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100318 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
319 __LINE__, (u32)(ofs), (u32)(val)); \
320 _ipw_write8(ipw, ofs, val); \
321} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600322
Zhu Yic8fe6672006-01-24 16:36:36 +0800323/* 16-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100324static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
325 u16 val)
326{
327 writew(val, ipw->hw_base + ofs);
328}
Zhu Yic8fe6672006-01-24 16:36:36 +0800329
330/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100331#define ipw_write16(ipw, ofs, val) do { \
332 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
333 __LINE__, (u32)(ofs), (u32)(val)); \
334 _ipw_write16(ipw, ofs, val); \
335} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600336
Zhu Yic8fe6672006-01-24 16:36:36 +0800337/* 32-bit direct write (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100338static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
339 u32 val)
340{
341 writel(val, ipw->hw_base + ofs);
342}
Zhu Yic8fe6672006-01-24 16:36:36 +0800343
344/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100345#define ipw_write32(ipw, ofs, val) do { \
346 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
347 __LINE__, (u32)(ofs), (u32)(val)); \
348 _ipw_write32(ipw, ofs, val); \
349} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600350
Zhu Yic8fe6672006-01-24 16:36:36 +0800351/* 8-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100352static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400353{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100354 return readb(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600355}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400356
Zhu Yic8fe6672006-01-24 16:36:36 +0800357/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100358#define ipw_read8(ipw, ofs) ({ \
359 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
360 (u32)(ofs)); \
361 _ipw_read8(ipw, ofs); \
362})
James Ketrenos43f66a62005-03-25 12:31:53 -0600363
Zhu Yic8fe6672006-01-24 16:36:36 +0800364/* 16-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100365static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400366{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100367 return readw(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600368}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400369
Zhu Yic8fe6672006-01-24 16:36:36 +0800370/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100371#define ipw_read16(ipw, ofs) ({ \
372 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
373 (u32)(ofs)); \
374 _ipw_read16(ipw, ofs); \
375})
James Ketrenos43f66a62005-03-25 12:31:53 -0600376
Zhu Yic8fe6672006-01-24 16:36:36 +0800377/* 32-bit direct read (low 4K) */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100378static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400379{
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100380 return readl(ipw->hw_base + ofs);
James Ketrenos43f66a62005-03-25 12:31:53 -0600381}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400382
Zhu Yic8fe6672006-01-24 16:36:36 +0800383/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100384#define ipw_read32(ipw, ofs) ({ \
385 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
386 (u32)(ofs)); \
387 _ipw_read32(ipw, ofs); \
388})
James Ketrenos43f66a62005-03-25 12:31:53 -0600389
390static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
Zhu Yic8fe6672006-01-24 16:36:36 +0800391/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100392#define ipw_read_indirect(a, b, c, d) ({ \
393 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
394 __LINE__, (u32)(b), (u32)(d)); \
395 _ipw_read_indirect(a, b, c, d); \
396})
James Ketrenos43f66a62005-03-25 12:31:53 -0600397
Zhu Yic8fe6672006-01-24 16:36:36 +0800398/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400399static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
400 int num);
Jiri Slaby1788bcd2009-02-12 22:29:40 +0100401#define ipw_write_indirect(a, b, c, d) do { \
402 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
403 __LINE__, (u32)(b), (u32)(d)); \
404 _ipw_write_indirect(a, b, c, d); \
405} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -0600406
Zhu Yic8fe6672006-01-24 16:36:36 +0800407/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400408static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600409{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400410 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500411 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
412 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600413}
414
Zhu Yic8fe6672006-01-24 16:36:36 +0800415/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600416static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
417{
Zhu Yi2638bc32006-01-24 16:37:52 +0800418 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800419 u32 dif_len = reg - aligned_addr;
420
James Ketrenos43f66a62005-03-25 12:31:53 -0600421 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800422 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
423 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600424}
425
Zhu Yic8fe6672006-01-24 16:36:36 +0800426/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400427static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600428{
Zhu Yi2638bc32006-01-24 16:37:52 +0800429 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800430 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
431
James Ketrenos43f66a62005-03-25 12:31:53 -0600432 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800433 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
434 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600435}
436
Zhu Yic8fe6672006-01-24 16:36:36 +0800437/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600438static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
439{
440 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500441 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600442 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500443 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400444 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600445}
446
Zhu Yic8fe6672006-01-24 16:36:36 +0800447/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600448static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
449{
450 u32 value;
451
452 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
453
James Ketrenosb095c382005-08-24 22:04:42 -0500454 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
455 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600456 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
457 return value;
458}
459
Zhu Yic8fe6672006-01-24 16:36:36 +0800460/* General purpose, no alignment requirement, iterative (multi-byte) read, */
461/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600462static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
463 int num)
464{
Zhu Yi2638bc32006-01-24 16:37:52 +0800465 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600466 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600467 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400468
James Ketrenos43f66a62005-03-25 12:31:53 -0600469 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
470
James Ketrenosea2b26e2005-08-24 21:25:16 -0500471 if (num <= 0) {
472 return;
473 }
474
Zhu Yic8fe6672006-01-24 16:36:36 +0800475 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500477 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600478 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500479 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500480 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600481 aligned_addr += 4;
482 }
483
Zhu Yic8fe6672006-01-24 16:36:36 +0800484 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500485 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500486 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500487 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400488
Zhu Yic8fe6672006-01-24 16:36:36 +0800489 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500490 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500491 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500492 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500493 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500494 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600495}
496
Zhu Yic8fe6672006-01-24 16:36:36 +0800497/* General purpose, no alignment requirement, iterative (multi-byte) write, */
498/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400499static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600500 int num)
501{
Zhu Yi2638bc32006-01-24 16:37:52 +0800502 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600503 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600504 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400505
James Ketrenos43f66a62005-03-25 12:31:53 -0600506 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400507
James Ketrenosea2b26e2005-08-24 21:25:16 -0500508 if (num <= 0) {
509 return;
510 }
511
Zhu Yic8fe6672006-01-24 16:36:36 +0800512 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600513 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500514 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800515 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500516 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500517 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600518 aligned_addr += 4;
519 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400520
Zhu Yic8fe6672006-01-24 16:36:36 +0800521 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500522 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500523 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500524 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400525
Zhu Yic8fe6672006-01-24 16:36:36 +0800526 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500527 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500528 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500529 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500530 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500531 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600532}
533
Zhu Yic8fe6672006-01-24 16:36:36 +0800534/* General purpose, no alignment requirement, iterative (multi-byte) write, */
535/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400536static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600537 int num)
538{
539 memcpy_toio((priv->hw_base + addr), buf, num);
540}
541
Zhu Yic8fe6672006-01-24 16:36:36 +0800542/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600543static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
544{
545 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
546}
547
Zhu Yic8fe6672006-01-24 16:36:36 +0800548/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600549static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
550{
551 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
552}
553
Zhu Yi89c318e2006-06-08 22:19:49 -0700554static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600555{
556 if (priv->status & STATUS_INT_ENABLED)
557 return;
558 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500559 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600560}
561
Zhu Yi89c318e2006-06-08 22:19:49 -0700562static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600563{
564 if (!(priv->status & STATUS_INT_ENABLED))
565 return;
566 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500567 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600568}
569
Zhu Yi89c318e2006-06-08 22:19:49 -0700570static inline void ipw_enable_interrupts(struct ipw_priv *priv)
571{
572 unsigned long flags;
573
574 spin_lock_irqsave(&priv->irq_lock, flags);
575 __ipw_enable_interrupts(priv);
576 spin_unlock_irqrestore(&priv->irq_lock, flags);
577}
578
579static inline void ipw_disable_interrupts(struct ipw_priv *priv)
580{
581 unsigned long flags;
582
583 spin_lock_irqsave(&priv->irq_lock, flags);
584 __ipw_disable_interrupts(priv);
585 spin_unlock_irqrestore(&priv->irq_lock, flags);
586}
587
James Ketrenos43f66a62005-03-25 12:31:53 -0600588static char *ipw_error_desc(u32 val)
589{
590 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400591 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600592 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400593 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600594 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400595 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600596 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400597 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600598 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400599 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500600 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400601 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500602 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400603 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500604 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400605 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500606 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400607 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500608 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400609 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500610 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400611 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500612 return "DMA_STATUS";
613 case IPW_FW_ERROR_DINO_ERROR:
614 return "DINO_ERROR";
615 case IPW_FW_ERROR_EEPROM_ERROR:
616 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400617 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500618 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400619 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500620 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400621 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500622 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600623 }
624}
625
James Ketrenosb39860c2005-08-12 09:36:32 -0500626static void ipw_dump_error_log(struct ipw_priv *priv,
627 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600628{
James Ketrenosb39860c2005-08-12 09:36:32 -0500629 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600630
James Ketrenosb39860c2005-08-12 09:36:32 -0500631 if (!error) {
632 IPW_ERROR("Error allocating and capturing error log. "
633 "Nothing to dump.\n");
634 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600635 }
636
James Ketrenosb39860c2005-08-12 09:36:32 -0500637 IPW_ERROR("Start IPW Error Log Dump:\n");
638 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
639 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600640
James Ketrenosb39860c2005-08-12 09:36:32 -0500641 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400642 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500643 ipw_error_desc(error->elem[i].desc),
644 error->elem[i].time,
645 error->elem[i].blink1,
646 error->elem[i].blink2,
647 error->elem[i].link1,
648 error->elem[i].link2, error->elem[i].data);
649 for (i = 0; i < error->log_len; i++)
650 IPW_ERROR("%i\t0x%08x\t%i\n",
651 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500652 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600653}
James Ketrenos43f66a62005-03-25 12:31:53 -0600654
James Ketrenosc848d0a2005-08-24 21:56:24 -0500655static inline int ipw_is_init(struct ipw_priv *priv)
656{
657 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600658}
659
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400660static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600661{
662 u32 addr, field_info, field_len, field_count, total_len;
663
664 IPW_DEBUG_ORD("ordinal = %i\n", ord);
665
666 if (!priv || !val || !len) {
667 IPW_DEBUG_ORD("Invalid argument\n");
668 return -EINVAL;
669 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400670
James Ketrenos43f66a62005-03-25 12:31:53 -0600671 /* verify device ordinal tables have been initialized */
672 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
673 IPW_DEBUG_ORD("Access ordinals before initialization\n");
674 return -EINVAL;
675 }
676
677 switch (IPW_ORD_TABLE_ID_MASK & ord) {
678 case IPW_ORD_TABLE_0_MASK:
679 /*
680 * TABLE 0: Direct access to a table of 32 bit values
681 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400682 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600683 * read from the table
684 */
685
686 /* remove the table id from the ordinal */
687 ord &= IPW_ORD_TABLE_VALUE_MASK;
688
689 /* boundary check */
690 if (ord > priv->table0_len) {
691 IPW_DEBUG_ORD("ordinal value (%i) longer then "
692 "max (%i)\n", ord, priv->table0_len);
693 return -EINVAL;
694 }
695
696 /* verify we have enough room to store the value */
697 if (*len < sizeof(u32)) {
698 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200699 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 return -EINVAL;
701 }
702
703 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400704 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600705
706 *len = sizeof(u32);
707 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400708 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600709 break;
710
711 case IPW_ORD_TABLE_1_MASK:
712 /*
713 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400714 *
715 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600716 * representing starting addr for the data (which is
717 * also a u32)
718 */
719
720 /* remove the table id from the ordinal */
721 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400722
James Ketrenos43f66a62005-03-25 12:31:53 -0600723 /* boundary check */
724 if (ord > priv->table1_len) {
725 IPW_DEBUG_ORD("ordinal value too long\n");
726 return -EINVAL;
727 }
728
729 /* verify we have enough room to store the value */
730 if (*len < sizeof(u32)) {
731 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200732 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600733 return -EINVAL;
734 }
735
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400736 *((u32 *) val) =
737 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600738 *len = sizeof(u32);
739 break;
740
741 case IPW_ORD_TABLE_2_MASK:
742 /*
743 * TABLE 2: Indirect access to a table of variable sized values
744 *
745 * This table consist of six values, each containing
746 * - dword containing the starting offset of the data
747 * - dword containing the lengh in the first 16bits
748 * and the count in the second 16bits
749 */
750
751 /* remove the table id from the ordinal */
752 ord &= IPW_ORD_TABLE_VALUE_MASK;
753
754 /* boundary check */
755 if (ord > priv->table2_len) {
756 IPW_DEBUG_ORD("ordinal value too long\n");
757 return -EINVAL;
758 }
759
760 /* get the address of statistic */
761 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400762
763 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600764 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400765 field_info =
766 ipw_read_reg32(priv,
767 priv->table2_addr + (ord << 3) +
768 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400769
James Ketrenos43f66a62005-03-25 12:31:53 -0600770 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400771 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400772
James Ketrenos43f66a62005-03-25 12:31:53 -0600773 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400774 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400775
James Ketrenos43f66a62005-03-25 12:31:53 -0600776 /* abort if not enought memory */
777 total_len = field_len * field_count;
778 if (total_len > *len) {
779 *len = total_len;
780 return -EINVAL;
781 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400782
James Ketrenos43f66a62005-03-25 12:31:53 -0600783 *len = total_len;
784 if (!total_len)
785 return 0;
786
787 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400788 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600789 addr, total_len, field_info);
790 ipw_read_indirect(priv, addr, val, total_len);
791 break;
792
793 default:
794 IPW_DEBUG_ORD("Invalid ordinal!\n");
795 return -EINVAL;
796
797 }
798
James Ketrenos43f66a62005-03-25 12:31:53 -0600799 return 0;
800}
801
802static void ipw_init_ordinals(struct ipw_priv *priv)
803{
804 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400805 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600806
807 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
808 priv->table0_addr, priv->table0_len);
809
810 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
811 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
812
813 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
814 priv->table1_addr, priv->table1_len);
815
816 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
817 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400818 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600819
820 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
821 priv->table2_addr, priv->table2_len);
822
823}
824
Adrian Bunka73e22b2006-01-21 01:39:42 +0100825static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500826{
James Ketrenosb095c382005-08-24 22:04:42 -0500827 reg &= ~IPW_START_STANDBY;
828 if (reg & IPW_GATE_ODMA)
829 reg &= ~IPW_GATE_ODMA;
830 if (reg & IPW_GATE_IDMA)
831 reg &= ~IPW_GATE_IDMA;
832 if (reg & IPW_GATE_ADMA)
833 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500834 return reg;
835}
836
837/*
838 * LED behavior:
839 * - On radio ON, turn on any LEDs that require to be on during start
840 * - On initialization, start unassociated blink
841 * - On association, disable unassociated blink
842 * - On disassociation, start unassociated blink
843 * - On radio OFF, turn off any LEDs started during radio on
844 *
845 */
Zhu Yiede61112006-01-24 16:37:10 +0800846#define LD_TIME_LINK_ON msecs_to_jiffies(300)
847#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
848#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500849
Adrian Bunka73e22b2006-01-21 01:39:42 +0100850static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500851{
852 unsigned long flags;
853 u32 led;
854
855 /* If configured to not use LEDs, or nic_type is 1,
856 * then we don't toggle a LINK led */
857 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
858 return;
859
860 spin_lock_irqsave(&priv->lock, flags);
861
862 if (!(priv->status & STATUS_RF_KILL_MASK) &&
863 !(priv->status & STATUS_LED_LINK_ON)) {
864 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500865 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500866 led |= priv->led_association_on;
867
868 led = ipw_register_toggle(led);
869
870 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500871 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500872
873 priv->status |= STATUS_LED_LINK_ON;
874
875 /* If we aren't associated, schedule turning the LED off */
876 if (!(priv->status & STATUS_ASSOCIATED))
877 queue_delayed_work(priv->workqueue,
878 &priv->led_link_off,
879 LD_TIME_LINK_ON);
880 }
881
882 spin_unlock_irqrestore(&priv->lock, flags);
883}
884
David Howellsc4028952006-11-22 14:57:56 +0000885static void ipw_bg_led_link_on(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500886{
David Howellsc4028952006-11-22 14:57:56 +0000887 struct ipw_priv *priv =
888 container_of(work, struct ipw_priv, led_link_on.work);
Zhu Yi46441512006-01-24 16:37:59 +0800889 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000890 ipw_led_link_on(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800891 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500892}
893
Adrian Bunka73e22b2006-01-21 01:39:42 +0100894static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500895{
896 unsigned long flags;
897 u32 led;
898
899 /* If configured not to use LEDs, or nic type is 1,
900 * then we don't goggle the LINK led. */
901 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
902 return;
903
904 spin_lock_irqsave(&priv->lock, flags);
905
906 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500907 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500908 led &= priv->led_association_off;
909 led = ipw_register_toggle(led);
910
911 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500912 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500913
914 IPW_DEBUG_LED("Link LED Off\n");
915
916 priv->status &= ~STATUS_LED_LINK_ON;
917
918 /* If we aren't associated and the radio is on, schedule
919 * turning the LED on (blink while unassociated) */
920 if (!(priv->status & STATUS_RF_KILL_MASK) &&
921 !(priv->status & STATUS_ASSOCIATED))
922 queue_delayed_work(priv->workqueue, &priv->led_link_on,
923 LD_TIME_LINK_OFF);
924
925 }
926
927 spin_unlock_irqrestore(&priv->lock, flags);
928}
929
David Howellsc4028952006-11-22 14:57:56 +0000930static void ipw_bg_led_link_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -0500931{
David Howellsc4028952006-11-22 14:57:56 +0000932 struct ipw_priv *priv =
933 container_of(work, struct ipw_priv, led_link_off.work);
Zhu Yi46441512006-01-24 16:37:59 +0800934 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +0000935 ipw_led_link_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +0800936 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500937}
938
Arjan van de Ven858119e2006-01-14 13:20:43 -0800939static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500940{
James Ketrenosa613bff2005-08-24 21:43:11 -0500941 u32 led;
942
943 if (priv->config & CFG_NO_LED)
944 return;
945
James Ketrenosb095c382005-08-24 22:04:42 -0500946 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500947 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500948
949 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500950 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500951 led |= priv->led_activity_on;
952
953 led = ipw_register_toggle(led);
954
955 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500956 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500957
958 IPW_DEBUG_LED("Activity LED On\n");
959
960 priv->status |= STATUS_LED_ACT_ON;
961
James Ketrenosc848d0a2005-08-24 21:56:24 -0500962 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500963 queue_delayed_work(priv->workqueue, &priv->led_act_off,
964 LD_TIME_ACT_ON);
965 } else {
966 /* Reschedule LED off for full time period */
967 cancel_delayed_work(&priv->led_act_off);
968 queue_delayed_work(priv->workqueue, &priv->led_act_off,
969 LD_TIME_ACT_ON);
970 }
James Ketrenosb095c382005-08-24 22:04:42 -0500971}
James Ketrenosa613bff2005-08-24 21:43:11 -0500972
Adrian Bunka73e22b2006-01-21 01:39:42 +0100973#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500974void ipw_led_activity_on(struct ipw_priv *priv)
975{
976 unsigned long flags;
977 spin_lock_irqsave(&priv->lock, flags);
978 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500979 spin_unlock_irqrestore(&priv->lock, flags);
980}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100981#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500982
Adrian Bunka73e22b2006-01-21 01:39:42 +0100983static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500984{
985 unsigned long flags;
986 u32 led;
987
988 if (priv->config & CFG_NO_LED)
989 return;
990
991 spin_lock_irqsave(&priv->lock, flags);
992
993 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500994 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500995 led &= priv->led_activity_off;
996
997 led = ipw_register_toggle(led);
998
999 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001000 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001001
1002 IPW_DEBUG_LED("Activity LED Off\n");
1003
1004 priv->status &= ~STATUS_LED_ACT_ON;
1005 }
1006
1007 spin_unlock_irqrestore(&priv->lock, flags);
1008}
1009
David Howellsc4028952006-11-22 14:57:56 +00001010static void ipw_bg_led_activity_off(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05001011{
David Howellsc4028952006-11-22 14:57:56 +00001012 struct ipw_priv *priv =
1013 container_of(work, struct ipw_priv, led_act_off.work);
Zhu Yi46441512006-01-24 16:37:59 +08001014 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00001015 ipw_led_activity_off(priv);
Zhu Yi46441512006-01-24 16:37:59 +08001016 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001017}
1018
Adrian Bunka73e22b2006-01-21 01:39:42 +01001019static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001020{
1021 unsigned long flags;
1022 u32 led;
1023
1024 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001025 if (priv->config & CFG_NO_LED ||
1026 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001027 return;
1028
1029 spin_lock_irqsave(&priv->lock, flags);
1030
James Ketrenosb095c382005-08-24 22:04:42 -05001031 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001032 if (priv->assoc_network->mode == IEEE_A) {
1033 led |= priv->led_ofdm_on;
1034 led &= priv->led_association_off;
1035 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1036 } else if (priv->assoc_network->mode == IEEE_G) {
1037 led |= priv->led_ofdm_on;
1038 led |= priv->led_association_on;
1039 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1040 } else {
1041 led &= priv->led_ofdm_off;
1042 led |= priv->led_association_on;
1043 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1044 }
1045
1046 led = ipw_register_toggle(led);
1047
1048 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001049 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001050
1051 spin_unlock_irqrestore(&priv->lock, flags);
1052}
1053
Adrian Bunka73e22b2006-01-21 01:39:42 +01001054static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001055{
1056 unsigned long flags;
1057 u32 led;
1058
1059 /* Only nic type 1 supports mode LEDs */
1060 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1061 return;
1062
1063 spin_lock_irqsave(&priv->lock, flags);
1064
James Ketrenosb095c382005-08-24 22:04:42 -05001065 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001066 led &= priv->led_ofdm_off;
1067 led &= priv->led_association_off;
1068
1069 led = ipw_register_toggle(led);
1070
1071 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001072 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001073
1074 spin_unlock_irqrestore(&priv->lock, flags);
1075}
1076
Adrian Bunka73e22b2006-01-21 01:39:42 +01001077static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001078{
1079 ipw_led_link_on(priv);
1080}
1081
Adrian Bunka73e22b2006-01-21 01:39:42 +01001082static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001083{
1084 ipw_led_activity_off(priv);
1085 ipw_led_link_off(priv);
1086}
1087
Adrian Bunka73e22b2006-01-21 01:39:42 +01001088static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001089{
1090 /* Set the Link Led on for all nic types */
1091 ipw_led_link_on(priv);
1092}
1093
Adrian Bunka73e22b2006-01-21 01:39:42 +01001094static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001095{
1096 ipw_led_activity_off(priv);
1097 ipw_led_link_off(priv);
1098
1099 if (priv->status & STATUS_RF_KILL_MASK)
1100 ipw_led_radio_off(priv);
1101}
1102
Adrian Bunka73e22b2006-01-21 01:39:42 +01001103static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001104{
1105 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1106
1107 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001108 priv->led_activity_on = IPW_ACTIVITY_LED;
1109 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001110
James Ketrenosb095c382005-08-24 22:04:42 -05001111 priv->led_association_on = IPW_ASSOCIATED_LED;
1112 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001113
1114 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001115 priv->led_ofdm_on = IPW_OFDM_LED;
1116 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001117
1118 switch (priv->nic_type) {
1119 case EEPROM_NIC_TYPE_1:
1120 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001121 priv->led_activity_on = IPW_ASSOCIATED_LED;
1122 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1123 priv->led_association_on = IPW_ACTIVITY_LED;
1124 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001125
1126 if (!(priv->config & CFG_NO_LED))
1127 ipw_led_band_on(priv);
1128
1129 /* And we don't blink link LEDs for this nic, so
1130 * just return here */
1131 return;
1132
1133 case EEPROM_NIC_TYPE_3:
1134 case EEPROM_NIC_TYPE_2:
1135 case EEPROM_NIC_TYPE_4:
1136 case EEPROM_NIC_TYPE_0:
1137 break;
1138
1139 default:
1140 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1141 priv->nic_type);
1142 priv->nic_type = EEPROM_NIC_TYPE_0;
1143 break;
1144 }
1145
1146 if (!(priv->config & CFG_NO_LED)) {
1147 if (priv->status & STATUS_ASSOCIATED)
1148 ipw_led_link_on(priv);
1149 else
1150 ipw_led_link_off(priv);
1151 }
1152}
1153
Adrian Bunka73e22b2006-01-21 01:39:42 +01001154static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001155{
James Ketrenosa613bff2005-08-24 21:43:11 -05001156 ipw_led_activity_off(priv);
1157 ipw_led_link_off(priv);
1158 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001159 cancel_delayed_work(&priv->led_link_on);
1160 cancel_delayed_work(&priv->led_link_off);
1161 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001162}
1163
James Ketrenos43f66a62005-03-25 12:31:53 -06001164/*
1165 * The following adds a new attribute to the sysfs representation
1166 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1167 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001168 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001169 * See the level definitions in ipw for details.
1170 */
1171static ssize_t show_debug_level(struct device_driver *d, char *buf)
1172{
1173 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1174}
James Ketrenosa613bff2005-08-24 21:43:11 -05001175
1176static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1177 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001178{
1179 char *p = (char *)buf;
1180 u32 val;
1181
1182 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1183 p++;
1184 if (p[0] == 'x' || p[0] == 'X')
1185 p++;
1186 val = simple_strtoul(p, &p, 16);
1187 } else
1188 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001189 if (p == buf)
1190 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001191 ": %s is not in hex or decimal form.\n", buf);
1192 else
1193 ipw_debug_level = val;
1194
1195 return strnlen(buf, count);
1196}
1197
Jeff Garzikbf794512005-07-31 13:07:26 -04001198static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001199 show_debug_level, store_debug_level);
1200
James Ketrenosb39860c2005-08-12 09:36:32 -05001201static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1202{
Zhu Yic8fe6672006-01-24 16:36:36 +08001203 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001204 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1205}
1206
1207static void ipw_capture_event_log(struct ipw_priv *priv,
1208 u32 log_len, struct ipw_event *log)
1209{
1210 u32 base;
1211
1212 if (log_len) {
1213 base = ipw_read32(priv, IPW_EVENT_LOG);
1214 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1215 (u8 *) log, sizeof(*log) * log_len);
1216 }
1217}
1218
1219static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1220{
1221 struct ipw_fw_error *error;
1222 u32 log_len = ipw_get_event_log_len(priv);
1223 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1224 u32 elem_len = ipw_read_reg32(priv, base);
1225
1226 error = kmalloc(sizeof(*error) +
1227 sizeof(*error->elem) * elem_len +
1228 sizeof(*error->log) * log_len, GFP_ATOMIC);
1229 if (!error) {
1230 IPW_ERROR("Memory allocation for firmware error log "
1231 "failed.\n");
1232 return NULL;
1233 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001234 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001235 error->status = priv->status;
1236 error->config = priv->config;
1237 error->elem_len = elem_len;
1238 error->log_len = log_len;
1239 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001240 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001241
1242 ipw_capture_event_log(priv, log_len, error->log);
1243
1244 if (elem_len)
1245 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1246 sizeof(*error->elem) * elem_len);
1247
1248 return error;
1249}
1250
James Ketrenosb39860c2005-08-12 09:36:32 -05001251static ssize_t show_event_log(struct device *d,
1252 struct device_attribute *attr, char *buf)
1253{
1254 struct ipw_priv *priv = dev_get_drvdata(d);
1255 u32 log_len = ipw_get_event_log_len(priv);
Reinette Chatre412e9e72007-12-18 22:01:02 -08001256 u32 log_size;
1257 struct ipw_event *log;
James Ketrenosb39860c2005-08-12 09:36:32 -05001258 u32 len = 0, i;
1259
Reinette Chatre412e9e72007-12-18 22:01:02 -08001260 /* not using min() because of its strict type checking */
1261 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1262 sizeof(*log) * log_len : PAGE_SIZE;
1263 log = kzalloc(log_size, GFP_KERNEL);
1264 if (!log) {
1265 IPW_ERROR("Unable to allocate memory for log\n");
1266 return 0;
1267 }
1268 log_len = log_size / sizeof(*log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001269 ipw_capture_event_log(priv, log_len, log);
1270
1271 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1272 for (i = 0; i < log_len; i++)
1273 len += snprintf(buf + len, PAGE_SIZE - len,
1274 "\n%08X%08X%08X",
1275 log[i].time, log[i].event, log[i].data);
1276 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
Reinette Chatre412e9e72007-12-18 22:01:02 -08001277 kfree(log);
James Ketrenosb39860c2005-08-12 09:36:32 -05001278 return len;
1279}
1280
1281static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1282
1283static ssize_t show_error(struct device *d,
1284 struct device_attribute *attr, char *buf)
1285{
1286 struct ipw_priv *priv = dev_get_drvdata(d);
1287 u32 len = 0, i;
1288 if (!priv->error)
1289 return 0;
1290 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001291 "%08lX%08X%08X%08X",
1292 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001293 priv->error->status,
1294 priv->error->config, priv->error->elem_len);
1295 for (i = 0; i < priv->error->elem_len; i++)
1296 len += snprintf(buf + len, PAGE_SIZE - len,
1297 "\n%08X%08X%08X%08X%08X%08X%08X",
1298 priv->error->elem[i].time,
1299 priv->error->elem[i].desc,
1300 priv->error->elem[i].blink1,
1301 priv->error->elem[i].blink2,
1302 priv->error->elem[i].link1,
1303 priv->error->elem[i].link2,
1304 priv->error->elem[i].data);
1305
1306 len += snprintf(buf + len, PAGE_SIZE - len,
1307 "\n%08X", priv->error->log_len);
1308 for (i = 0; i < priv->error->log_len; i++)
1309 len += snprintf(buf + len, PAGE_SIZE - len,
1310 "\n%08X%08X%08X",
1311 priv->error->log[i].time,
1312 priv->error->log[i].event,
1313 priv->error->log[i].data);
1314 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1315 return len;
1316}
1317
1318static ssize_t clear_error(struct device *d,
1319 struct device_attribute *attr,
1320 const char *buf, size_t count)
1321{
1322 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001323
1324 kfree(priv->error);
1325 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001326 return count;
1327}
1328
1329static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1330
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001331static ssize_t show_cmd_log(struct device *d,
1332 struct device_attribute *attr, char *buf)
1333{
1334 struct ipw_priv *priv = dev_get_drvdata(d);
1335 u32 len = 0, i;
1336 if (!priv->cmdlog)
1337 return 0;
1338 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1339 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1340 i = (i + 1) % priv->cmdlog_len) {
1341 len +=
1342 snprintf(buf + len, PAGE_SIZE - len,
1343 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1344 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1345 priv->cmdlog[i].cmd.len);
1346 len +=
1347 snprintk_buf(buf + len, PAGE_SIZE - len,
1348 (u8 *) priv->cmdlog[i].cmd.param,
1349 priv->cmdlog[i].cmd.len);
1350 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1351 }
1352 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1353 return len;
1354}
1355
1356static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1357
Zhu Yid685b8c2006-04-13 17:20:27 +08001358#ifdef CONFIG_IPW2200_PROMISCUOUS
1359static void ipw_prom_free(struct ipw_priv *priv);
1360static int ipw_prom_alloc(struct ipw_priv *priv);
1361static ssize_t store_rtap_iface(struct device *d,
1362 struct device_attribute *attr,
1363 const char *buf, size_t count)
1364{
1365 struct ipw_priv *priv = dev_get_drvdata(d);
1366 int rc = 0;
1367
1368 if (count < 1)
1369 return -EINVAL;
1370
1371 switch (buf[0]) {
1372 case '0':
1373 if (!rtap_iface)
1374 return count;
1375
1376 if (netif_running(priv->prom_net_dev)) {
1377 IPW_WARNING("Interface is up. Cannot unregister.\n");
1378 return count;
1379 }
1380
1381 ipw_prom_free(priv);
1382 rtap_iface = 0;
1383 break;
1384
1385 case '1':
1386 if (rtap_iface)
1387 return count;
1388
1389 rc = ipw_prom_alloc(priv);
1390 if (!rc)
1391 rtap_iface = 1;
1392 break;
1393
1394 default:
1395 return -EINVAL;
1396 }
1397
1398 if (rc) {
1399 IPW_ERROR("Failed to register promiscuous network "
1400 "device (error %d).\n", rc);
1401 }
1402
1403 return count;
1404}
1405
1406static ssize_t show_rtap_iface(struct device *d,
1407 struct device_attribute *attr,
1408 char *buf)
1409{
1410 struct ipw_priv *priv = dev_get_drvdata(d);
1411 if (rtap_iface)
1412 return sprintf(buf, "%s", priv->prom_net_dev->name);
1413 else {
1414 buf[0] = '-';
1415 buf[1] = '1';
1416 buf[2] = '\0';
1417 return 3;
1418 }
1419}
1420
1421static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1422 store_rtap_iface);
1423
1424static ssize_t store_rtap_filter(struct device *d,
1425 struct device_attribute *attr,
1426 const char *buf, size_t count)
1427{
1428 struct ipw_priv *priv = dev_get_drvdata(d);
1429
1430 if (!priv->prom_priv) {
1431 IPW_ERROR("Attempting to set filter without "
1432 "rtap_iface enabled.\n");
1433 return -EPERM;
1434 }
1435
1436 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1437
1438 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1439 BIT_ARG16(priv->prom_priv->filter));
1440
1441 return count;
1442}
1443
1444static ssize_t show_rtap_filter(struct device *d,
1445 struct device_attribute *attr,
1446 char *buf)
1447{
1448 struct ipw_priv *priv = dev_get_drvdata(d);
1449 return sprintf(buf, "0x%04X",
1450 priv->prom_priv ? priv->prom_priv->filter : 0);
1451}
1452
1453static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1454 store_rtap_filter);
1455#endif
1456
James Ketrenosa613bff2005-08-24 21:43:11 -05001457static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1458 char *buf)
1459{
1460 struct ipw_priv *priv = dev_get_drvdata(d);
1461 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1462}
1463
1464static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1465 const char *buf, size_t count)
1466{
1467 struct ipw_priv *priv = dev_get_drvdata(d);
1468 struct net_device *dev = priv->net_dev;
1469 char buffer[] = "00000000";
1470 unsigned long len =
1471 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1472 unsigned long val;
1473 char *p = buffer;
1474
1475 IPW_DEBUG_INFO("enter\n");
1476
1477 strncpy(buffer, buf, len);
1478 buffer[len] = 0;
1479
1480 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1481 p++;
1482 if (p[0] == 'x' || p[0] == 'X')
1483 p++;
1484 val = simple_strtoul(p, &p, 16);
1485 } else
1486 val = simple_strtoul(p, &p, 10);
1487 if (p == buffer) {
1488 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1489 } else {
1490 priv->ieee->scan_age = val;
1491 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1492 }
1493
1494 IPW_DEBUG_INFO("exit\n");
1495 return len;
1496}
1497
1498static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1499
1500static ssize_t show_led(struct device *d, struct device_attribute *attr,
1501 char *buf)
1502{
1503 struct ipw_priv *priv = dev_get_drvdata(d);
1504 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1505}
1506
1507static ssize_t store_led(struct device *d, struct device_attribute *attr,
1508 const char *buf, size_t count)
1509{
1510 struct ipw_priv *priv = dev_get_drvdata(d);
1511
1512 IPW_DEBUG_INFO("enter\n");
1513
1514 if (count == 0)
1515 return 0;
1516
1517 if (*buf == 0) {
1518 IPW_DEBUG_LED("Disabling LED control.\n");
1519 priv->config |= CFG_NO_LED;
1520 ipw_led_shutdown(priv);
1521 } else {
1522 IPW_DEBUG_LED("Enabling LED control.\n");
1523 priv->config &= ~CFG_NO_LED;
1524 ipw_led_init(priv);
1525 }
1526
1527 IPW_DEBUG_INFO("exit\n");
1528 return count;
1529}
1530
1531static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1532
Andrew Mortonad3fee52005-06-20 14:30:36 -07001533static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001534 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001535{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001536 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001537 return sprintf(buf, "0x%08x\n", (int)p->status);
1538}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001539
James Ketrenos43f66a62005-03-25 12:31:53 -06001540static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1541
Andrew Mortonad3fee52005-06-20 14:30:36 -07001542static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1543 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001544{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001545 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001546 return sprintf(buf, "0x%08x\n", (int)p->config);
1547}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001548
James Ketrenos43f66a62005-03-25 12:31:53 -06001549static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1550
Andrew Mortonad3fee52005-06-20 14:30:36 -07001551static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001553{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001554 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosa613bff2005-08-24 21:43:11 -05001555 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001556}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557
James Ketrenos43f66a62005-03-25 12:31:53 -06001558static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1559
Andrew Mortonad3fee52005-06-20 14:30:36 -07001560static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001561 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001562{
1563 u32 len = sizeof(u32), tmp = 0;
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
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001566 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001567 return 0;
1568
1569 return sprintf(buf, "0x%08x\n", tmp);
1570}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001571
1572static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001573
Andrew Mortonad3fee52005-06-20 14:30:36 -07001574static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1575 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001576{
1577 u32 len = sizeof(u32), tmp = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001578 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001579
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001580 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001581 return 0;
1582
1583 return sprintf(buf, "0x%08x\n", tmp);
1584}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001585
1586static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001587
1588/*
1589 * Add a device attribute to view/control the delay between eeprom
1590 * operations.
1591 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001592static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001593 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001594{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001595 struct ipw_priv *p = dev_get_drvdata(d);
1596 int n = p->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001597 return sprintf(buf, "%i\n", n);
1598}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001599static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001600 struct device_attribute *attr,
1601 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001602{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001603 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001604 sscanf(buf, "%i", &p->eeprom_delay);
1605 return strnlen(buf, count);
1606}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001607
1608static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1609 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001610
Andrew Mortonad3fee52005-06-20 14:30:36 -07001611static ssize_t show_command_event_reg(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{
1614 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001615 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001616
James Ketrenosb095c382005-08-24 22:04:42 -05001617 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001618 return sprintf(buf, "0x%08x\n", reg);
1619}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001620static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001621 struct device_attribute *attr,
1622 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001623{
1624 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001625 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001626
1627 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001628 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001629 return strnlen(buf, count);
1630}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631
1632static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1633 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001634
Andrew Mortonad3fee52005-06-20 14:30:36 -07001635static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001636 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001637{
1638 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001639 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001640
1641 reg = ipw_read_reg32(p, 0x301100);
1642 return sprintf(buf, "0x%08x\n", reg);
1643}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001644static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001645 struct device_attribute *attr,
1646 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001647{
1648 u32 reg;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001649 struct ipw_priv *p = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001650
1651 sscanf(buf, "%x", &reg);
1652 ipw_write_reg32(p, 0x301100, reg);
1653 return strnlen(buf, count);
1654}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001655
1656static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1657 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001658
Andrew Mortonad3fee52005-06-20 14:30:36 -07001659static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001660 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001661{
1662 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001663 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001664
Jeff Garzikbf794512005-07-31 13:07:26 -04001665 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001666 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001667 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001668 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001669
James Ketrenos43f66a62005-03-25 12:31:53 -06001670 return sprintf(buf, "0x%08x\n", reg);
1671}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001672static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001673 struct device_attribute *attr,
1674 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001675{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001676 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001677
1678 sscanf(buf, "%x", &priv->indirect_dword);
1679 priv->status |= STATUS_INDIRECT_DWORD;
1680 return strnlen(buf, count);
1681}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001682
1683static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1684 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001685
Andrew Mortonad3fee52005-06-20 14:30:36 -07001686static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001687 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001688{
1689 u8 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001690 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001691
Jeff Garzikbf794512005-07-31 13:07:26 -04001692 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001693 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001694 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001695 reg = 0;
1696
1697 return sprintf(buf, "0x%02x\n", reg);
1698}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001699static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001700 struct device_attribute *attr,
1701 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001702{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001703 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001704
1705 sscanf(buf, "%x", &priv->indirect_byte);
1706 priv->status |= STATUS_INDIRECT_BYTE;
1707 return strnlen(buf, count);
1708}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001709
1710static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001711 show_indirect_byte, store_indirect_byte);
1712
Andrew Mortonad3fee52005-06-20 14:30:36 -07001713static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001714 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001715{
1716 u32 reg = 0;
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001717 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001718
Jeff Garzikbf794512005-07-31 13:07:26 -04001719 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001720 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001721 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001722 reg = 0;
1723
1724 return sprintf(buf, "0x%08x\n", reg);
1725}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001726static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001727 struct device_attribute *attr,
1728 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001729{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001730 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001731
1732 sscanf(buf, "%x", &priv->direct_dword);
1733 priv->status |= STATUS_DIRECT_DWORD;
1734 return strnlen(buf, count);
1735}
James Ketrenos43f66a62005-03-25 12:31:53 -06001736
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001737static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1738 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001739
Arjan van de Ven858119e2006-01-14 13:20:43 -08001740static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001741{
1742 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1743 priv->status |= STATUS_RF_KILL_HW;
1744 else
1745 priv->status &= ~STATUS_RF_KILL_HW;
1746
1747 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1748}
1749
Andrew Mortonad3fee52005-06-20 14:30:36 -07001750static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001751 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001752{
1753 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001754 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001755 2 - HW based RF kill active
1756 3 - Both HW and SW baed RF kill active */
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001757 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenos43f66a62005-03-25 12:31:53 -06001758 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001759 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 return sprintf(buf, "%i\n", val);
1761}
1762
1763static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1764{
Jeff Garzikbf794512005-07-31 13:07:26 -04001765 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001766 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001767 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001768
1769 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1770 disable_radio ? "OFF" : "ON");
1771
1772 if (disable_radio) {
1773 priv->status |= STATUS_RF_KILL_SW;
1774
Dan Williams0b531672007-10-09 13:55:24 -04001775 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04001777 cancel_delayed_work(&priv->request_direct_scan);
1778 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04001779 cancel_delayed_work(&priv->scan_event);
1780 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 queue_work(priv->workqueue, &priv->down);
1782 } else {
1783 priv->status &= ~STATUS_RF_KILL_SW;
1784 if (rf_kill_active(priv)) {
1785 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1786 "disabled by HW switch\n");
1787 /* Make sure the RF_KILL check timer is running */
1788 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001789 queue_delayed_work(priv->workqueue, &priv->rf_kill,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05001790 round_jiffies_relative(2 * HZ));
Jeff Garzikbf794512005-07-31 13:07:26 -04001791 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001792 queue_work(priv->workqueue, &priv->up);
1793 }
1794
1795 return 1;
1796}
1797
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001798static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1799 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001800{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001801 struct ipw_priv *priv = dev_get_drvdata(d);
Jeff Garzikbf794512005-07-31 13:07:26 -04001802
James Ketrenos43f66a62005-03-25 12:31:53 -06001803 ipw_radio_kill_sw(priv, buf[0] == '1');
1804
1805 return count;
1806}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001807
1808static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001809
James Ketrenosb095c382005-08-24 22:04:42 -05001810static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1811 char *buf)
1812{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001813 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001814 int pos = 0, len = 0;
1815 if (priv->config & CFG_SPEED_SCAN) {
1816 while (priv->speed_scan[pos] != 0)
1817 len += sprintf(&buf[len], "%d ",
1818 priv->speed_scan[pos++]);
1819 return len + sprintf(&buf[len], "\n");
1820 }
1821
1822 return sprintf(buf, "0\n");
1823}
1824
1825static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1826 const char *buf, size_t count)
1827{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001828 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001829 int channel, pos = 0;
1830 const char *p = buf;
1831
1832 /* list of space separated channels to scan, optionally ending with 0 */
1833 while ((channel = simple_strtol(p, NULL, 0))) {
1834 if (pos == MAX_SPEED_SCAN - 1) {
1835 priv->speed_scan[pos] = 0;
1836 break;
1837 }
1838
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001839 if (libipw_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001840 priv->speed_scan[pos++] = channel;
1841 else
1842 IPW_WARNING("Skipping invalid channel request: %d\n",
1843 channel);
1844 p = strchr(p, ' ');
1845 if (!p)
1846 break;
1847 while (*p == ' ' || *p == '\t')
1848 p++;
1849 }
1850
1851 if (pos == 0)
1852 priv->config &= ~CFG_SPEED_SCAN;
1853 else {
1854 priv->speed_scan_pos = 0;
1855 priv->config |= CFG_SPEED_SCAN;
1856 }
1857
1858 return count;
1859}
1860
1861static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1862 store_speed_scan);
1863
1864static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1865 char *buf)
1866{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001867 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001868 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1869}
1870
1871static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1872 const char *buf, size_t count)
1873{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07001874 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosb095c382005-08-24 22:04:42 -05001875 if (buf[0] == '1')
1876 priv->config |= CFG_NET_STATS;
1877 else
1878 priv->config &= ~CFG_NET_STATS;
1879
1880 return count;
1881}
1882
James Ketrenosafbf30a2005-08-25 00:05:33 -05001883static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1884 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001885
Zhu Yi375dd242007-02-14 16:04:24 +08001886static ssize_t show_channels(struct device *d,
1887 struct device_attribute *attr,
1888 char *buf)
1889{
1890 struct ipw_priv *priv = dev_get_drvdata(d);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001891 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi375dd242007-02-14 16:04:24 +08001892 int len = 0, i;
1893
1894 len = sprintf(&buf[len],
1895 "Displaying %d channels in 2.4Ghz band "
1896 "(802.11bg):\n", geo->bg_channels);
1897
1898 for (i = 0; i < geo->bg_channels; i++) {
1899 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1900 geo->bg[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001901 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001902 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001903 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1904 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001905 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001906 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001907 "passive only" : "active/passive",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001908 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001909 "B" : "B/G");
1910 }
1911
1912 len += sprintf(&buf[len],
1913 "Displaying %d channels in 5.2Ghz band "
1914 "(802.11a):\n", geo->a_channels);
1915 for (i = 0; i < geo->a_channels; i++) {
1916 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1917 geo->a[i].channel,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001918 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
Zhu Yi375dd242007-02-14 16:04:24 +08001919 " (radar spectrum)" : "",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001920 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1921 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
Zhu Yi375dd242007-02-14 16:04:24 +08001922 ? "" : ", IBSS",
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001923 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
Zhu Yi375dd242007-02-14 16:04:24 +08001924 "passive only" : "active/passive");
1925 }
1926
1927 return len;
1928}
1929
1930static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
1931
James Ketrenosea2b26e2005-08-24 21:25:16 -05001932static void notify_wx_assoc_event(struct ipw_priv *priv)
1933{
1934 union iwreq_data wrqu;
1935 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1936 if (priv->status & STATUS_ASSOCIATED)
1937 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1938 else
1939 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1940 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1941}
1942
James Ketrenos43f66a62005-03-25 12:31:53 -06001943static void ipw_irq_tasklet(struct ipw_priv *priv)
1944{
1945 u32 inta, inta_mask, handled = 0;
1946 unsigned long flags;
1947 int rc = 0;
1948
Zhu Yi89c318e2006-06-08 22:19:49 -07001949 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001950
James Ketrenosb095c382005-08-24 22:04:42 -05001951 inta = ipw_read32(priv, IPW_INTA_RW);
1952 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1953 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001954
1955 /* Add any cached INTA values that need to be handled */
1956 inta |= priv->isr_inta;
1957
Zhu Yi89c318e2006-06-08 22:19:49 -07001958 spin_unlock_irqrestore(&priv->irq_lock, flags);
1959
1960 spin_lock_irqsave(&priv->lock, flags);
1961
James Ketrenos43f66a62005-03-25 12:31:53 -06001962 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001963 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001964 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001965 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001966 }
1967
James Ketrenosb095c382005-08-24 22:04:42 -05001968 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001969 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001970 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001971 priv->status &= ~STATUS_HCMD_ACTIVE;
1972 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001973 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001974 }
1975
James Ketrenosb095c382005-08-24 22:04:42 -05001976 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001977 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001978 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001979 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001980 }
1981
James Ketrenosb095c382005-08-24 22:04:42 -05001982 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001983 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001984 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001985 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001986 }
1987
James Ketrenosb095c382005-08-24 22:04:42 -05001988 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001989 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001990 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001991 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 }
1993
James Ketrenosb095c382005-08-24 22:04:42 -05001994 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001995 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001996 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001997 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001998 }
1999
James Ketrenosb095c382005-08-24 22:04:42 -05002000 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002002 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002003 }
2004
James Ketrenosb095c382005-08-24 22:04:42 -05002005 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002006 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002007 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
James Ketrenosb095c382005-08-24 22:04:42 -05002010 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002011 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002012 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002013 }
2014
James Ketrenosb095c382005-08-24 22:04:42 -05002015 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002017 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002018 }
2019
James Ketrenosb095c382005-08-24 22:04:42 -05002020 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002022 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 }
2024
James Ketrenosb095c382005-08-24 22:04:42 -05002025 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2027 priv->status |= STATUS_RF_KILL_HW;
2028 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05002029 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06002030 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -04002031 cancel_delayed_work(&priv->request_direct_scan);
2032 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -04002033 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -05002034 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06002035 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05002036 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06002037 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002038
James Ketrenosb095c382005-08-24 22:04:42 -05002039 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002040 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002041 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002042 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002043 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2044 struct ipw_fw_error *error =
2045 ipw_alloc_error_log(priv);
2046 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07002047 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002048 }
James Ketrenosb39860c2005-08-12 09:36:32 -05002049 } else {
2050 priv->error = ipw_alloc_error_log(priv);
2051 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002052 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002053 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08002054 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2055 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05002056 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2057 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05002058 }
2059
James Ketrenosb095c382005-08-24 22:04:42 -05002060 /* XXX: If hardware encryption is for WPA/WPA2,
2061 * we have to notify the supplicant. */
2062 if (priv->ieee->sec.encrypt) {
2063 priv->status &= ~STATUS_ASSOCIATED;
2064 notify_wx_assoc_event(priv);
2065 }
2066
2067 /* Keep the restart process from trying to send host
2068 * commands by clearing the INIT status bit */
2069 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002070
2071 /* Cancel currently queued command. */
2072 priv->status &= ~STATUS_HCMD_ACTIVE;
2073 wake_up_interruptible(&priv->wait_command_queue);
2074
James Ketrenos43f66a62005-03-25 12:31:53 -06002075 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002076 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002077 }
2078
James Ketrenosb095c382005-08-24 22:04:42 -05002079 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002080 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002081 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002082 }
2083
2084 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002085 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002086 }
2087
Zhu Yi89c318e2006-06-08 22:19:49 -07002088 spin_unlock_irqrestore(&priv->lock, flags);
2089
James Ketrenos43f66a62005-03-25 12:31:53 -06002090 /* enable all interrupts */
2091 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002092}
Jeff Garzikbf794512005-07-31 13:07:26 -04002093
James Ketrenos43f66a62005-03-25 12:31:53 -06002094#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2095static char *get_cmd_string(u8 cmd)
2096{
2097 switch (cmd) {
2098 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002099 IPW_CMD(POWER_DOWN);
2100 IPW_CMD(SYSTEM_CONFIG);
2101 IPW_CMD(MULTICAST_ADDRESS);
2102 IPW_CMD(SSID);
2103 IPW_CMD(ADAPTER_ADDRESS);
2104 IPW_CMD(PORT_TYPE);
2105 IPW_CMD(RTS_THRESHOLD);
2106 IPW_CMD(FRAG_THRESHOLD);
2107 IPW_CMD(POWER_MODE);
2108 IPW_CMD(WEP_KEY);
2109 IPW_CMD(TGI_TX_KEY);
2110 IPW_CMD(SCAN_REQUEST);
2111 IPW_CMD(SCAN_REQUEST_EXT);
2112 IPW_CMD(ASSOCIATE);
2113 IPW_CMD(SUPPORTED_RATES);
2114 IPW_CMD(SCAN_ABORT);
2115 IPW_CMD(TX_FLUSH);
2116 IPW_CMD(QOS_PARAMETERS);
2117 IPW_CMD(DINO_CONFIG);
2118 IPW_CMD(RSN_CAPABILITIES);
2119 IPW_CMD(RX_KEY);
2120 IPW_CMD(CARD_DISABLE);
2121 IPW_CMD(SEED_NUMBER);
2122 IPW_CMD(TX_POWER);
2123 IPW_CMD(COUNTRY_INFO);
2124 IPW_CMD(AIRONET_INFO);
2125 IPW_CMD(AP_TX_POWER);
2126 IPW_CMD(CCKM_INFO);
2127 IPW_CMD(CCX_VER_INFO);
2128 IPW_CMD(SET_CALIBRATION);
2129 IPW_CMD(SENSITIVITY_CALIB);
2130 IPW_CMD(RETRY_LIMIT);
2131 IPW_CMD(IPW_PRE_POWER_DOWN);
2132 IPW_CMD(VAP_BEACON_TEMPLATE);
2133 IPW_CMD(VAP_DTIM_PERIOD);
2134 IPW_CMD(EXT_SUPPORTED_RATES);
2135 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2136 IPW_CMD(VAP_QUIET_INTERVALS);
2137 IPW_CMD(VAP_CHANNEL_SWITCH);
2138 IPW_CMD(VAP_MANDATORY_CHANNELS);
2139 IPW_CMD(VAP_CELL_PWR_LIMIT);
2140 IPW_CMD(VAP_CF_PARAM_SET);
2141 IPW_CMD(VAP_SET_BEACONING_STATE);
2142 IPW_CMD(MEASUREMENT);
2143 IPW_CMD(POWER_CAPABILITY);
2144 IPW_CMD(SUPPORTED_CHANNELS);
2145 IPW_CMD(TPC_REPORT);
2146 IPW_CMD(WME_INFO);
2147 IPW_CMD(PRODUCTION_COMMAND);
2148 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002149 return "UNKNOWN";
2150 }
2151}
James Ketrenos43f66a62005-03-25 12:31:53 -06002152
2153#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002154
2155static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002156{
2157 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002158 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002159
James Ketrenosa613bff2005-08-24 21:43:11 -05002160 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002161 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002162 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2163 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002164 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002165 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002166 }
2167
2168 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002169
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002170 if (priv->cmdlog) {
2171 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2172 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2173 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2174 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2175 cmd->len);
2176 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2177 }
2178
James Ketrenosb095c382005-08-24 22:04:42 -05002179 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2180 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2181 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002182
2183#ifndef DEBUG_CMD_WEP_KEY
2184 if (cmd->cmd == IPW_CMD_WEP_KEY)
2185 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2186 else
2187#endif
2188 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2189
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002190 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002191 if (rc) {
2192 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002193 IPW_ERROR("Failed to send %s: Reason %d\n",
2194 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002195 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002196 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002197 }
2198 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002199
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002200 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2201 !(priv->
2202 status & STATUS_HCMD_ACTIVE),
2203 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002204 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002205 spin_lock_irqsave(&priv->lock, flags);
2206 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002207 IPW_ERROR("Failed to send %s: Command timed out.\n",
2208 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002209 priv->status &= ~STATUS_HCMD_ACTIVE;
2210 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002211 rc = -EIO;
2212 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002213 }
2214 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002215 } else
2216 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002217
James Ketrenosb095c382005-08-24 22:04:42 -05002218 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002219 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2220 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002221 rc = -EIO;
2222 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002223 }
2224
Zhu Yi2638bc32006-01-24 16:37:52 +08002225 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002226 if (priv->cmdlog) {
2227 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2228 priv->cmdlog_pos %= priv->cmdlog_len;
2229 }
2230 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002231}
2232
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002233static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002234{
2235 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002236 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002237 };
2238
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002239 return __ipw_send_cmd(priv, &cmd);
2240}
2241
2242static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2243 void *data)
2244{
2245 struct host_cmd cmd = {
2246 .cmd = command,
2247 .len = len,
2248 .param = data,
2249 };
2250
2251 return __ipw_send_cmd(priv, &cmd);
2252}
2253
2254static int ipw_send_host_complete(struct ipw_priv *priv)
2255{
James Ketrenos43f66a62005-03-25 12:31:53 -06002256 if (!priv) {
2257 IPW_ERROR("Invalid args\n");
2258 return -1;
2259 }
2260
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002261 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002262}
2263
Zhu Yid685b8c2006-04-13 17:20:27 +08002264static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002265{
Zhu Yid685b8c2006-04-13 17:20:27 +08002266 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2267 sizeof(priv->sys_config),
2268 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002269}
2270
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002271static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002272{
James Ketrenos43f66a62005-03-25 12:31:53 -06002273 if (!priv || !ssid) {
2274 IPW_ERROR("Invalid args\n");
2275 return -1;
2276 }
2277
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002278 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002279 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002280}
2281
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002282static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002283{
James Ketrenos43f66a62005-03-25 12:31:53 -06002284 if (!priv || !mac) {
2285 IPW_ERROR("Invalid args\n");
2286 return -1;
2287 }
2288
Johannes Berge1749612008-10-27 15:59:26 -07002289 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2290 priv->net_dev->name, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002291
Zhu Yi2638bc32006-01-24 16:37:52 +08002292 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002293}
2294
James Ketrenosa613bff2005-08-24 21:43:11 -05002295/*
2296 * NOTE: This must be executed from our workqueue as it results in udelay
2297 * being called which may corrupt the keyboard if executed on default
2298 * workqueue
2299 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002300static void ipw_adapter_restart(void *adapter)
2301{
2302 struct ipw_priv *priv = adapter;
2303
2304 if (priv->status & STATUS_RF_KILL_MASK)
2305 return;
2306
2307 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002308
2309 if (priv->assoc_network &&
2310 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2311 ipw_remove_current_network(priv);
2312
James Ketrenos43f66a62005-03-25 12:31:53 -06002313 if (ipw_up(priv)) {
2314 IPW_ERROR("Failed to up device\n");
2315 return;
2316 }
2317}
2318
David Howellsc4028952006-11-22 14:57:56 +00002319static void ipw_bg_adapter_restart(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002320{
David Howellsc4028952006-11-22 14:57:56 +00002321 struct ipw_priv *priv =
2322 container_of(work, struct ipw_priv, adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08002323 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002324 ipw_adapter_restart(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002325 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002326}
2327
James Ketrenos43f66a62005-03-25 12:31:53 -06002328#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2329
2330static void ipw_scan_check(void *data)
2331{
2332 struct ipw_priv *priv = data;
2333 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2334 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002335 "adapter after (%dms).\n",
2336 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002337 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002338 }
2339}
2340
David Howellsc4028952006-11-22 14:57:56 +00002341static void ipw_bg_scan_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05002342{
David Howellsc4028952006-11-22 14:57:56 +00002343 struct ipw_priv *priv =
2344 container_of(work, struct ipw_priv, scan_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08002345 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00002346 ipw_scan_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08002347 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002348}
2349
James Ketrenos43f66a62005-03-25 12:31:53 -06002350static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2351 struct ipw_scan_request_ext *request)
2352{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002353 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002354 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002355}
2356
2357static int ipw_send_scan_abort(struct ipw_priv *priv)
2358{
James Ketrenos43f66a62005-03-25 12:31:53 -06002359 if (!priv) {
2360 IPW_ERROR("Invalid args\n");
2361 return -1;
2362 }
2363
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002364 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002365}
2366
2367static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2368{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002369 struct ipw_sensitivity_calib calib = {
Zhu Yi851ca262006-08-21 11:37:58 +08002370 .beacon_rssi_raw = cpu_to_le16(sens),
James Ketrenos43f66a62005-03-25 12:31:53 -06002371 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002372
2373 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002374 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002375}
2376
2377static int ipw_send_associate(struct ipw_priv *priv,
2378 struct ipw_associate *associate)
2379{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002380 if (!priv || !associate) {
2381 IPW_ERROR("Invalid args\n");
2382 return -1;
2383 }
2384
Al Viro5b5e8072007-12-27 01:54:06 -05002385 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2386 associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002387}
2388
2389static int ipw_send_supported_rates(struct ipw_priv *priv,
2390 struct ipw_supported_rates *rates)
2391{
James Ketrenos43f66a62005-03-25 12:31:53 -06002392 if (!priv || !rates) {
2393 IPW_ERROR("Invalid args\n");
2394 return -1;
2395 }
2396
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002397 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002398 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002399}
2400
2401static int ipw_set_random_seed(struct ipw_priv *priv)
2402{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002403 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002404
2405 if (!priv) {
2406 IPW_ERROR("Invalid args\n");
2407 return -1;
2408 }
2409
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002410 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002411
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002412 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002413}
2414
James Ketrenos43f66a62005-03-25 12:31:53 -06002415static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2416{
Al Viroe62e1ee2007-12-27 01:36:46 -05002417 __le32 v = cpu_to_le32(phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002418 if (!priv) {
2419 IPW_ERROR("Invalid args\n");
2420 return -1;
2421 }
2422
Al Viroe62e1ee2007-12-27 01:36:46 -05002423 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
James Ketrenos43f66a62005-03-25 12:31:53 -06002424}
James Ketrenos43f66a62005-03-25 12:31:53 -06002425
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002426static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002427{
James Ketrenos43f66a62005-03-25 12:31:53 -06002428 if (!priv || !power) {
2429 IPW_ERROR("Invalid args\n");
2430 return -1;
2431 }
2432
Zhu Yi2638bc32006-01-24 16:37:52 +08002433 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002434}
James Ketrenos43f66a62005-03-25 12:31:53 -06002435
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002436static int ipw_set_tx_power(struct ipw_priv *priv)
2437{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002438 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002439 struct ipw_tx_power tx_power;
2440 s8 max_power;
2441 int i;
2442
2443 memset(&tx_power, 0, sizeof(tx_power));
2444
2445 /* configure device for 'G' band */
2446 tx_power.ieee_mode = IPW_G_MODE;
2447 tx_power.num_channels = geo->bg_channels;
2448 for (i = 0; i < geo->bg_channels; i++) {
2449 max_power = geo->bg[i].max_power;
2450 tx_power.channels_tx_power[i].channel_number =
2451 geo->bg[i].channel;
2452 tx_power.channels_tx_power[i].tx_power = max_power ?
2453 min(max_power, priv->tx_power) : priv->tx_power;
2454 }
2455 if (ipw_send_tx_power(priv, &tx_power))
2456 return -EIO;
2457
2458 /* configure device to also handle 'B' band */
2459 tx_power.ieee_mode = IPW_B_MODE;
2460 if (ipw_send_tx_power(priv, &tx_power))
2461 return -EIO;
2462
2463 /* configure device to also handle 'A' band */
2464 if (priv->ieee->abg_true) {
2465 tx_power.ieee_mode = IPW_A_MODE;
2466 tx_power.num_channels = geo->a_channels;
2467 for (i = 0; i < tx_power.num_channels; i++) {
2468 max_power = geo->a[i].max_power;
2469 tx_power.channels_tx_power[i].channel_number =
2470 geo->a[i].channel;
2471 tx_power.channels_tx_power[i].tx_power = max_power ?
2472 min(max_power, priv->tx_power) : priv->tx_power;
2473 }
2474 if (ipw_send_tx_power(priv, &tx_power))
2475 return -EIO;
2476 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002477 return 0;
2478}
2479
2480static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2481{
2482 struct ipw_rts_threshold rts_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002483 .rts_threshold = cpu_to_le16(rts),
James Ketrenos43f66a62005-03-25 12:31:53 -06002484 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002485
2486 if (!priv) {
2487 IPW_ERROR("Invalid args\n");
2488 return -1;
2489 }
2490
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002491 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2492 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002493}
2494
2495static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2496{
2497 struct ipw_frag_threshold frag_threshold = {
Zhu Yi851ca262006-08-21 11:37:58 +08002498 .frag_threshold = cpu_to_le16(frag),
James Ketrenos43f66a62005-03-25 12:31:53 -06002499 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002500
2501 if (!priv) {
2502 IPW_ERROR("Invalid args\n");
2503 return -1;
2504 }
2505
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002506 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2507 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002508}
2509
2510static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2511{
Al Viroe62e1ee2007-12-27 01:36:46 -05002512 __le32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002513
2514 if (!priv) {
2515 IPW_ERROR("Invalid args\n");
2516 return -1;
2517 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002518
James Ketrenos43f66a62005-03-25 12:31:53 -06002519 /* If on battery, set to 3, if AC set to CAM, else user
2520 * level */
2521 switch (mode) {
2522 case IPW_POWER_BATTERY:
Al Viroe62e1ee2007-12-27 01:36:46 -05002523 param = cpu_to_le32(IPW_POWER_INDEX_3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002524 break;
2525 case IPW_POWER_AC:
Al Viroe62e1ee2007-12-27 01:36:46 -05002526 param = cpu_to_le32(IPW_POWER_MODE_CAM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002527 break;
2528 default:
Al Viroe62e1ee2007-12-27 01:36:46 -05002529 param = cpu_to_le32(mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530 break;
2531 }
2532
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002533 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002534 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002535}
2536
James Ketrenosafbf30a2005-08-25 00:05:33 -05002537static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2538{
2539 struct ipw_retry_limit retry_limit = {
2540 .short_retry_limit = slimit,
2541 .long_retry_limit = llimit
2542 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002543
2544 if (!priv) {
2545 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002546 return -1;
2547 }
2548
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002549 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002550 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002551}
2552
2553/*
2554 * The IPW device contains a Microwire compatible EEPROM that stores
2555 * various data like the MAC address. Usually the firmware has exclusive
2556 * access to the eeprom, but during device initialization (before the
2557 * device driver has sent the HostComplete command to the firmware) the
2558 * device driver has read access to the EEPROM by way of indirect addressing
2559 * through a couple of memory mapped registers.
2560 *
2561 * The following is a simplified implementation for pulling data out of the
2562 * the eeprom, along with some helper functions to find information in
2563 * the per device private data's copy of the eeprom.
2564 *
2565 * NOTE: To better understand how these functions work (i.e what is a chip
2566 * select and why do have to keep driving the eeprom clock?), read
2567 * just about any data sheet for a Microwire compatible EEPROM.
2568 */
2569
2570/* write a 32 bit value into the indirect accessor register */
2571static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2572{
2573 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002574
James Ketrenos43f66a62005-03-25 12:31:53 -06002575 /* the eeprom requires some time to complete the operation */
2576 udelay(p->eeprom_delay);
2577
2578 return;
2579}
2580
2581/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002582static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002583{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584 eeprom_write_reg(priv, 0);
2585 eeprom_write_reg(priv, EEPROM_BIT_CS);
2586 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2587 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002588}
2589
2590/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002591static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002592{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002593 eeprom_write_reg(priv, EEPROM_BIT_CS);
2594 eeprom_write_reg(priv, 0);
2595 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002596}
2597
2598/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002599static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002600{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002601 int d = (bit ? EEPROM_BIT_DI : 0);
2602 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2603 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002604}
2605
2606/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002607static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002608{
2609 int i;
2610
2611 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 eeprom_write_bit(priv, 1);
2613 eeprom_write_bit(priv, op & 2);
2614 eeprom_write_bit(priv, op & 1);
2615 for (i = 7; i >= 0; i--) {
2616 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002617 }
2618}
2619
2620/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002621static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002622{
2623 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002624 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002625
James Ketrenos43f66a62005-03-25 12:31:53 -06002626 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002627 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002628
2629 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002631
2632 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002633 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002634 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002635 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2636 eeprom_write_reg(priv, EEPROM_BIT_CS);
2637 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2638 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002639 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002640
James Ketrenos43f66a62005-03-25 12:31:53 -06002641 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002642 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002643 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002644
James Ketrenos43f66a62005-03-25 12:31:53 -06002645 return r;
2646}
2647
2648/* helper function for pulling the mac address out of the private */
2649/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002650static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002651{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002652 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002653}
2654
2655/*
2656 * Either the device driver (i.e. the host) or the firmware can
2657 * load eeprom data into the designated region in SRAM. If neither
2658 * happens then the FW will shutdown with a fatal error.
2659 *
2660 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2661 * bit needs region of shared SRAM needs to be non-zero.
2662 */
2663static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2664{
2665 int i;
Al Viroe62e1ee2007-12-27 01:36:46 -05002666 __le16 *eeprom = (__le16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002667
James Ketrenos43f66a62005-03-25 12:31:53 -06002668 IPW_DEBUG_TRACE(">>\n");
2669
2670 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002671 for (i = 0; i < 128; i++)
Al Viroe62e1ee2007-12-27 01:36:46 -05002672 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002673
Jeff Garzikbf794512005-07-31 13:07:26 -04002674 /*
2675 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002676 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002677 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002679 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002680 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2681
2682 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002683 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002684 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002685
2686 /* Do not load eeprom data on fatal error or suspend */
2687 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2688 } else {
2689 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2690
2691 /* Load eeprom data on fatal error or suspend */
2692 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2693 }
2694
2695 IPW_DEBUG_TRACE("<<\n");
2696}
2697
Arjan van de Ven858119e2006-01-14 13:20:43 -08002698static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002699{
2700 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002701 if (!count)
2702 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002703 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002704 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002705 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002706}
2707
2708static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2709{
James Ketrenosb095c382005-08-24 22:04:42 -05002710 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002711 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002712 sizeof(struct command_block));
2713}
2714
2715static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002716{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002717
2718 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002719
James Ketrenos43f66a62005-03-25 12:31:53 -06002720 /* Start the dma */
2721 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002722
James Ketrenos43f66a62005-03-25 12:31:53 -06002723 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002724 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002725
2726 IPW_DEBUG_FW("<< : \n");
2727 return 0;
2728}
2729
2730static void ipw_fw_dma_abort(struct ipw_priv *priv)
2731{
2732 u32 control = 0;
2733
2734 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002735
Pavel Machek67fd6b42006-07-11 15:34:05 +02002736 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002737 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002738 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002739 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002740
James Ketrenos43f66a62005-03-25 12:31:53 -06002741 IPW_DEBUG_FW("<< \n");
2742}
2743
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002744static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2745 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002746{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002747 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002748 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002749 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002750 IPW_DEBUG_FW(">> :\n");
2751
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002752 ipw_write_indirect(priv, address, (u8 *) cb,
2753 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002754
2755 IPW_DEBUG_FW("<< :\n");
2756 return 0;
2757
2758}
2759
2760static int ipw_fw_dma_kick(struct ipw_priv *priv)
2761{
2762 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002763 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002764
2765 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002766
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002768 ipw_fw_dma_write_command_block(priv, index,
2769 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002770
2771 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002772 ipw_clear_bit(priv, IPW_RESET_REG,
2773 IPW_RESET_REG_MASTER_DISABLED |
2774 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002777 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002778 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002779
2780 IPW_DEBUG_FW("<< :\n");
2781 return 0;
2782}
2783
2784static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2785{
2786 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002787 u32 register_value = 0;
2788 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002789
2790 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002791 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002792 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002793
2794 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002795 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2796 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002797
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002798 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 cb_fields_address = address;
2800 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002801 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002802
2803 cb_fields_address += sizeof(u32);
2804 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002806
2807 cb_fields_address += sizeof(u32);
2808 register_value = ipw_read_reg32(priv, cb_fields_address);
2809 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2810 register_value);
2811
2812 cb_fields_address += sizeof(u32);
2813 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002814 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002815
2816 IPW_DEBUG_FW(">> :\n");
2817}
2818
2819static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2820{
2821 u32 current_cb_address = 0;
2822 u32 current_cb_index = 0;
2823
2824 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002825 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002826
James Ketrenosb095c382005-08-24 22:04:42 -05002827 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002828 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002829
James Ketrenos43f66a62005-03-25 12:31:53 -06002830 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002831 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002832
2833 IPW_DEBUG_FW(">> :\n");
2834 return current_cb_index;
2835
2836}
2837
2838static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2839 u32 src_address,
2840 u32 dest_address,
2841 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002842 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002843{
2844
Jeff Garzikbf794512005-07-31 13:07:26 -04002845 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2847 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002848 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002849 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002850
2851 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2852 src_address, dest_address, length);
2853
2854 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2855 return -1;
2856
2857 last_cb_element = priv->sram_desc.last_cb_index;
2858 cb = &priv->sram_desc.cb_list[last_cb_element];
2859 priv->sram_desc.last_cb_index++;
2860
2861 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002862 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002863 control |= CB_INT_ENABLED;
2864
2865 if (is_last)
2866 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002867
James Ketrenos43f66a62005-03-25 12:31:53 -06002868 control |= length;
2869
2870 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002871 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002872
2873 /* Copy the Source and Destination addresses */
2874 cb->dest_addr = dest_address;
2875 cb->source_addr = src_address;
2876
2877 /* Copy the Control Word last */
2878 cb->control = control;
2879
2880 return 0;
2881}
2882
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002883static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2884 int nr, u32 dest_address, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002885{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002886 int ret, i;
2887 u32 size;
2888
James Ketrenos43f66a62005-03-25 12:31:53 -06002889 IPW_DEBUG_FW(">> \n");
Zhu Yi11ebd1b2009-08-28 11:42:31 +08002890 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2891 nr, dest_address, len);
2892
2893 for (i = 0; i < nr; i++) {
2894 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2895 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2896 dest_address +
2897 i * CB_MAX_LENGTH, size,
2898 0, 0);
2899 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002900 IPW_DEBUG_FW_INFO(": Failed\n");
2901 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002902 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002903 IPW_DEBUG_FW_INFO(": Added new cb\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002904 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002905
James Ketrenos43f66a62005-03-25 12:31:53 -06002906 IPW_DEBUG_FW("<< \n");
2907 return 0;
2908}
2909
2910static int ipw_fw_dma_wait(struct ipw_priv *priv)
2911{
Zhu Yi397ae122006-01-24 16:37:22 +08002912 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002913 u32 watchdog = 0;
2914
2915 IPW_DEBUG_FW(">> : \n");
2916
2917 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002918 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002919 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002920
2921 while (current_index < priv->sram_desc.last_cb_index) {
2922 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002923 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002924 current_index = ipw_fw_dma_command_block_index(priv);
2925
Zhu Yi397ae122006-01-24 16:37:22 +08002926 if (previous_index < current_index) {
2927 watchdog = 0;
2928 continue;
2929 }
2930 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002931 IPW_DEBUG_FW_INFO("Timeout\n");
2932 ipw_fw_dma_dump_command_block(priv);
2933 ipw_fw_dma_abort(priv);
2934 return -1;
2935 }
2936 }
2937
2938 ipw_fw_dma_abort(priv);
2939
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002940 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002941 ipw_set_bit(priv, IPW_RESET_REG,
2942 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002943
2944 IPW_DEBUG_FW("<< dmaWaitSync \n");
2945 return 0;
2946}
2947
Jeff Garzikbf794512005-07-31 13:07:26 -04002948static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002949{
2950 struct list_head *element, *safe;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002951 struct libipw_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002952 unsigned long flags;
2953
2954 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002955 list_for_each_safe(element, safe, &priv->ieee->network_list) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04002956 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06002957 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2958 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002959 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002960 &priv->ieee->network_free_list);
2961 }
2962 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002963 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002964}
2965
2966/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002967 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002968 * Reads debug register from domain0.
2969 * If card is present, pre-defined value should
2970 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002971 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002972 * @param priv
2973 * @return 1 if card is present, 0 otherwise
2974 */
2975static inline int ipw_alive(struct ipw_priv *priv)
2976{
2977 return ipw_read32(priv, 0x90) == 0xd55555d5;
2978}
2979
Zhu Yic7b6a672006-01-24 16:37:05 +08002980/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002981static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002982 int timeout)
2983{
2984 int i = 0;
2985
2986 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002987 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002988 return i;
2989 mdelay(10);
2990 i += 10;
2991 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002992
James Ketrenos43f66a62005-03-25 12:31:53 -06002993 return -ETIME;
2994}
2995
Jeff Garzikbf794512005-07-31 13:07:26 -04002996/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002997 * the ipw hardware. It assumes the buffer has all the bits for the
2998 * image and the caller is handling the memory allocation and clean up.
2999 */
3000
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003001static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003002{
3003 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003004
James Ketrenos43f66a62005-03-25 12:31:53 -06003005 IPW_DEBUG_TRACE(">> \n");
3006 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05003007 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003008
Zhu Yic7b6a672006-01-24 16:37:05 +08003009 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05003010 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3011 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06003012 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003013 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003014 return -1;
3015 }
3016
3017 IPW_DEBUG_INFO("stop master %dms\n", rc);
3018
3019 return rc;
3020}
3021
3022static void ipw_arc_release(struct ipw_priv *priv)
3023{
3024 IPW_DEBUG_TRACE(">> \n");
3025 mdelay(5);
3026
James Ketrenosb095c382005-08-24 22:04:42 -05003027 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003028
3029 /* no one knows timing, for safety add some delay */
3030 mdelay(5);
3031}
3032
James Ketrenos43f66a62005-03-25 12:31:53 -06003033struct fw_chunk {
Al Viroe62e1ee2007-12-27 01:36:46 -05003034 __le32 address;
3035 __le32 length;
James Ketrenos43f66a62005-03-25 12:31:53 -06003036};
3037
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003038static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003039{
3040 int rc = 0, i, addr;
3041 u8 cr = 0;
Al Viroe62e1ee2007-12-27 01:36:46 -05003042 __le16 *image;
James Ketrenos43f66a62005-03-25 12:31:53 -06003043
Al Viroe62e1ee2007-12-27 01:36:46 -05003044 image = (__le16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003045
James Ketrenos43f66a62005-03-25 12:31:53 -06003046 IPW_DEBUG_TRACE(">> \n");
3047
3048 rc = ipw_stop_master(priv);
3049
3050 if (rc < 0)
3051 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003052
James Ketrenosb095c382005-08-24 22:04:42 -05003053 for (addr = IPW_SHARED_LOWER_BOUND;
3054 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003055 ipw_write32(priv, addr, 0);
3056 }
3057
3058 /* no ucode (yet) */
3059 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3060 /* destroy DMA queues */
3061 /* reset sequence */
3062
James Ketrenosb095c382005-08-24 22:04:42 -05003063 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003064 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003065 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003066 mdelay(1);
3067
3068 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003069 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003071
James Ketrenosb095c382005-08-24 22:04:42 -05003072 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003073 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003074
James Ketrenos43f66a62005-03-25 12:31:53 -06003075 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003076 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3077 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003078 mdelay(1);
3079
3080 /* write ucode */
3081 /**
3082 * @bug
3083 * Do NOT set indirect address register once and then
3084 * store data to indirect data register in the loop.
3085 * It seems very reasonable, but in this case DINO do not
3086 * accept ucode. It is essential to set address each time.
3087 */
3088 /* load new ipw uCode */
3089 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003090 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
Al Viroe62e1ee2007-12-27 01:36:46 -05003091 le16_to_cpu(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003092
James Ketrenos43f66a62005-03-25 12:31:53 -06003093 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003094 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3095 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003096
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003097 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003098
3099 /* wait for alive response */
3100 for (i = 0; i < 100; i++) {
3101 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003102 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003103 if (cr & DINO_RXFIFO_DATA)
3104 break;
3105 mdelay(1);
3106 }
3107
3108 if (cr & DINO_RXFIFO_DATA) {
3109 /* alive_command_responce size is NOT multiple of 4 */
Al Viroe62e1ee2007-12-27 01:36:46 -05003110 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003111
3112 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003113 response_buffer[i] =
Al Viroe62e1ee2007-12-27 01:36:46 -05003114 cpu_to_le32(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003115 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003116 memcpy(&priv->dino_alive, response_buffer,
3117 sizeof(priv->dino_alive));
3118 if (priv->dino_alive.alive_command == 1
3119 && priv->dino_alive.ucode_valid == 1) {
3120 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003121 IPW_DEBUG_INFO
3122 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3123 "of %02d/%02d/%02d %02d:%02d\n",
3124 priv->dino_alive.software_revision,
3125 priv->dino_alive.software_revision,
3126 priv->dino_alive.device_identifier,
3127 priv->dino_alive.device_identifier,
3128 priv->dino_alive.time_stamp[0],
3129 priv->dino_alive.time_stamp[1],
3130 priv->dino_alive.time_stamp[2],
3131 priv->dino_alive.time_stamp[3],
3132 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003133 } else {
3134 IPW_DEBUG_INFO("Microcode is not alive\n");
3135 rc = -EINVAL;
3136 }
3137 } else {
3138 IPW_DEBUG_INFO("No alive response from DINO\n");
3139 rc = -ETIME;
3140 }
3141
3142 /* disable DINO, otherwise for some reason
3143 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003144 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003145
James Ketrenos43f66a62005-03-25 12:31:53 -06003146 return rc;
3147}
3148
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003149static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003150{
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003151 int ret = -1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003152 int offset = 0;
3153 struct fw_chunk *chunk;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003154 int total_nr = 0;
3155 int i;
3156 struct pci_pool *pool;
3157 u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL];
3158 dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL];
James Ketrenos43f66a62005-03-25 12:31:53 -06003159
3160 IPW_DEBUG_TRACE("<< : \n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003161
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003162 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3163 if (!pool) {
3164 IPW_ERROR("pci_pool_create failed\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003165 return -ENOMEM;
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003166 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003167
3168 /* Start the Dma */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003169 ret = ipw_fw_dma_enable(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003170
Alexander Beregalov0ee904c2009-04-11 14:50:23 +00003171 /* the DMA is already ready this would be a bug. */
3172 BUG_ON(priv->sram_desc.last_cb_index > 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003173
3174 do {
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003175 u32 chunk_len;
3176 u8 *start;
3177 int size;
3178 int nr = 0;
3179
James Ketrenos43f66a62005-03-25 12:31:53 -06003180 chunk = (struct fw_chunk *)(data + offset);
3181 offset += sizeof(struct fw_chunk);
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003182 chunk_len = le32_to_cpu(chunk->length);
3183 start = data + offset;
3184
3185 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3186 for (i = 0; i < nr; i++) {
3187 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3188 &phys[total_nr]);
3189 if (!virts[total_nr]) {
3190 ret = -ENOMEM;
3191 goto out;
3192 }
3193 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3194 CB_MAX_LENGTH);
3195 memcpy(virts[total_nr], start, size);
3196 start += size;
3197 total_nr++;
3198 /* We don't support fw chunk larger than 64*8K */
3199 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3200 }
3201
James Ketrenos43f66a62005-03-25 12:31:53 -06003202 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003203 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003204 * offeset*/
3205 /* Dma loading */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003206 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3207 nr, le32_to_cpu(chunk->address),
3208 chunk_len);
3209 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003210 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3211 goto out;
3212 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003213
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003214 offset += chunk_len;
James Ketrenos43f66a62005-03-25 12:31:53 -06003215 } while (offset < len);
3216
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003217 /* Run the DMA and wait for the answer */
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003218 ret = ipw_fw_dma_kick(priv);
3219 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 IPW_ERROR("dmaKick Failed\n");
3221 goto out;
3222 }
3223
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003224 ret = ipw_fw_dma_wait(priv);
3225 if (ret) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 IPW_ERROR("dmaWaitSync Failed\n");
3227 goto out;
3228 }
Zhu Yi11ebd1b2009-08-28 11:42:31 +08003229 out:
3230 for (i = 0; i < total_nr; i++)
3231 pci_pool_free(pool, virts[i], phys[i]);
3232
3233 pci_pool_destroy(pool);
3234
3235 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06003236}
3237
3238/* stop nic */
3239static int ipw_stop_nic(struct ipw_priv *priv)
3240{
3241 int rc = 0;
3242
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003243 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003244 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003245
James Ketrenosb095c382005-08-24 22:04:42 -05003246 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3247 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003248 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003249 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003250 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003251 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003252
James Ketrenosb095c382005-08-24 22:04:42 -05003253 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003254
James Ketrenos43f66a62005-03-25 12:31:53 -06003255 return rc;
3256}
3257
3258static void ipw_start_nic(struct ipw_priv *priv)
3259{
3260 IPW_DEBUG_TRACE(">>\n");
3261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003262 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003263 ipw_clear_bit(priv, IPW_RESET_REG,
3264 IPW_RESET_REG_MASTER_DISABLED |
3265 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003266 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003267
James Ketrenos43f66a62005-03-25 12:31:53 -06003268 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003269 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3270 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003271
3272 IPW_DEBUG_TRACE("<<\n");
3273}
Jeff Garzikbf794512005-07-31 13:07:26 -04003274
James Ketrenos43f66a62005-03-25 12:31:53 -06003275static int ipw_init_nic(struct ipw_priv *priv)
3276{
3277 int rc;
3278
3279 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003280 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003281 /*prvHwInitNic */
3282 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003283 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003284
3285 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003286 ipw_write32(priv, IPW_READ_INT_REGISTER,
3287 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003288
3289 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003290 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3291 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003292 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003293 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3294
3295 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003296 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003297
3298 udelay(10);
3299
3300 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003301 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003302
3303 IPW_DEBUG_TRACE(">>\n");
3304 return 0;
3305}
3306
Jeff Garzikbf794512005-07-31 13:07:26 -04003307/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003308 * Probe is an ok place to call this from.
3309 */
3310static int ipw_reset_nic(struct ipw_priv *priv)
3311{
3312 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003313 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003314
3315 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003316
James Ketrenos43f66a62005-03-25 12:31:53 -06003317 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003318
James Ketrenosa613bff2005-08-24 21:43:11 -05003319 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 /* Clear the 'host command active' bit... */
3321 priv->status &= ~STATUS_HCMD_ACTIVE;
3322 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003323 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3324 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003325 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003326
3327 IPW_DEBUG_TRACE("<<\n");
3328 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003329}
James Ketrenos43f66a62005-03-25 12:31:53 -06003330
James Ketrenos9006ea72006-03-08 03:22:28 +08003331
3332struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003333 __le32 ver;
3334 __le32 boot_size;
3335 __le32 ucode_size;
3336 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003337 u8 data[0];
3338};
3339
Jeff Garzikbf794512005-07-31 13:07:26 -04003340static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003341 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003342{
James Ketrenos9006ea72006-03-08 03:22:28 +08003343 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003344 int rc;
3345
3346 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003347 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003348 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003349 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003350 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003351 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003352
James Ketrenos9006ea72006-03-08 03:22:28 +08003353 if ((*raw)->size < sizeof(*fw)) {
3354 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003355 return -EINVAL;
3356 }
3357
James Ketrenos9006ea72006-03-08 03:22:28 +08003358 fw = (void *)(*raw)->data;
3359
Zhu Yi0070f8c2006-04-13 17:20:12 +08003360 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3361 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003362 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3363 name, (*raw)->size);
3364 return -EINVAL;
3365 }
3366
3367 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003368 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003369 le32_to_cpu(fw->ver) >> 16,
3370 le32_to_cpu(fw->ver) & 0xff,
3371 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003372 return 0;
3373}
3374
James Ketrenosb095c382005-08-24 22:04:42 -05003375#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003376
Arjan van de Ven858119e2006-01-14 13:20:43 -08003377static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003378 struct ipw_rx_queue *rxq)
3379{
3380 unsigned long flags;
3381 int i;
3382
3383 spin_lock_irqsave(&rxq->lock, flags);
3384
3385 INIT_LIST_HEAD(&rxq->rx_free);
3386 INIT_LIST_HEAD(&rxq->rx_used);
3387
3388 /* Fill the rx_used queue with _all_ of the Rx buffers */
3389 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3390 /* In the reset function, these buffers may have been allocated
3391 * to an SKB, so we need to unmap and free potential storage */
3392 if (rxq->pool[i].skb != NULL) {
3393 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003394 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003395 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003396 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003397 }
3398 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3399 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003400
James Ketrenos43f66a62005-03-25 12:31:53 -06003401 /* Set us so that we have processed and used all buffers, but have
3402 * not restocked the Rx queue with fresh buffers */
3403 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003404 rxq->free_count = 0;
3405 spin_unlock_irqrestore(&rxq->lock, flags);
3406}
3407
3408#ifdef CONFIG_PM
3409static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003410static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003411
3412static void free_firmware(void)
3413{
3414 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003415 release_firmware(raw);
3416 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003417 fw_loaded = 0;
3418 }
3419}
3420#else
3421#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003422#endif
3423
3424static int ipw_load(struct ipw_priv *priv)
3425{
3426#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003427 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003428#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003429 struct ipw_fw *fw;
3430 u8 *boot_img, *ucode_img, *fw_img;
3431 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003432 int rc = 0, retries = 3;
3433
Zhu Yi397ae122006-01-24 16:37:22 +08003434 switch (priv->ieee->iw_mode) {
3435 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003436 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003437 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003438#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003439 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003440 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003441 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003442#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003443 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003444 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003445 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003446 }
Zhu Yi397ae122006-01-24 16:37:22 +08003447
James Ketrenos9006ea72006-03-08 03:22:28 +08003448 if (!name) {
3449 rc = -EINVAL;
3450 goto error;
3451 }
3452
3453#ifdef CONFIG_PM
3454 if (!fw_loaded) {
3455#endif
3456 rc = ipw_get_fw(priv, &raw, name);
3457 if (rc < 0)
3458 goto error;
3459#ifdef CONFIG_PM
3460 }
3461#endif
3462
3463 fw = (void *)raw->data;
3464 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003465 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3466 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3467 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003468
Zhu Yi397ae122006-01-24 16:37:22 +08003469 if (rc < 0)
3470 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003471
3472 if (!priv->rxq)
3473 priv->rxq = ipw_rx_queue_alloc(priv);
3474 else
3475 ipw_rx_queue_reset(priv, priv->rxq);
3476 if (!priv->rxq) {
3477 IPW_ERROR("Unable to initialize Rx queue\n");
3478 goto error;
3479 }
3480
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003481 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003482 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003483 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003484 priv->status &= ~STATUS_INT_ENABLED;
3485
3486 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003487 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003488
James Ketrenos43f66a62005-03-25 12:31:53 -06003489 ipw_stop_nic(priv);
3490
3491 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003492 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003493 IPW_ERROR("Unable to reset NIC\n");
3494 goto error;
3495 }
3496
James Ketrenosb095c382005-08-24 22:04:42 -05003497 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3498 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003499
3500 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003501 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003502 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003503 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003504 goto error;
3505 }
3506
3507 /* kick start the device */
3508 ipw_start_nic(priv);
3509
Zhu Yic7b6a672006-01-24 16:37:05 +08003510 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003511 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3512 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003513 if (rc < 0) {
3514 IPW_ERROR("device failed to boot initial fw image\n");
3515 goto error;
3516 }
3517 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3518
Jeff Garzikbf794512005-07-31 13:07:26 -04003519 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003520 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003521
3522 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003523 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003524 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003525 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003526 goto error;
3527 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003528
James Ketrenos43f66a62005-03-25 12:31:53 -06003529 /* stop nic */
3530 ipw_stop_nic(priv);
3531
3532 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003533 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003534 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003535 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003536 goto error;
3537 }
Zhu Yi397ae122006-01-24 16:37:22 +08003538#ifdef CONFIG_PM
3539 fw_loaded = 1;
3540#endif
3541
James Ketrenos43f66a62005-03-25 12:31:53 -06003542 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3543
3544 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003545 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003546 IPW_ERROR("Unable to initialize queues\n");
3547 goto error;
3548 }
3549
3550 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003551 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003552 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003553 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003554
James Ketrenos43f66a62005-03-25 12:31:53 -06003555 /* kick start the device */
3556 ipw_start_nic(priv);
3557
James Ketrenosb095c382005-08-24 22:04:42 -05003558 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003559 if (retries > 0) {
3560 IPW_WARNING("Parity error. Retrying init.\n");
3561 retries--;
3562 goto retry;
3563 }
3564
3565 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3566 rc = -EIO;
3567 goto error;
3568 }
3569
3570 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003571 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3572 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003573 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003574 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003575 goto error;
3576 }
3577 IPW_DEBUG_INFO("device response after %dms\n", rc);
3578
3579 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003580 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003581
3582 /* read eeprom data and initialize the eeprom region of sram */
3583 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003584 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003585
3586 /* enable interrupts */
3587 ipw_enable_interrupts(priv);
3588
3589 /* Ensure our queue has valid packets */
3590 ipw_rx_queue_replenish(priv);
3591
James Ketrenosb095c382005-08-24 22:04:42 -05003592 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003593
3594 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003595 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003596
3597#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003598 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003599#endif
3600 return 0;
3601
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003602 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003603 if (priv->rxq) {
3604 ipw_rx_queue_free(priv, priv->rxq);
3605 priv->rxq = NULL;
3606 }
3607 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003608 if (raw)
3609 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003610#ifdef CONFIG_PM
3611 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003612 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003613#endif
3614
3615 return rc;
3616}
3617
Jeff Garzikbf794512005-07-31 13:07:26 -04003618/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003619 * DMA services
3620 *
3621 * Theory of operation
3622 *
3623 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3624 * 2 empty entries always kept in the buffer to protect from overflow.
3625 *
3626 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003627 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3628 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003629 * Tx queue resumed.
3630 *
3631 * The IPW operates with six queues, one receive queue in the device's
3632 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003633 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003634 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003635 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003636 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003637 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003638 * we only utilize the first data transmit queue (queue1).
3639 */
3640
3641/**
3642 * Driver allocates buffers of this size for Rx
3643 */
3644
Dan Williams943dbef2008-02-14 17:49:41 -05003645/**
3646 * ipw_rx_queue_space - Return number of free slots available in queue.
3647 */
3648static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3649{
3650 int s = q->read - q->write;
3651 if (s <= 0)
3652 s += RX_QUEUE_SIZE;
3653 /* keep some buffer to not confuse full and empty queue */
3654 s -= 2;
3655 if (s < 0)
3656 s = 0;
3657 return s;
3658}
3659
3660static inline int ipw_tx_queue_space(const struct clx2_queue *q)
James Ketrenos43f66a62005-03-25 12:31:53 -06003661{
3662 int s = q->last_used - q->first_empty;
3663 if (s <= 0)
3664 s += q->n_bd;
3665 s -= 2; /* keep some reserve to not confuse empty and full situations */
3666 if (s < 0)
3667 s = 0;
3668 return s;
3669}
3670
3671static inline int ipw_queue_inc_wrap(int index, int n_bd)
3672{
3673 return (++index == n_bd) ? 0 : index;
3674}
3675
3676/**
3677 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003678 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003679 * @param q queue to init
3680 * @param count Number of BD's to allocate. Should be power of 2
3681 * @param read_register Address for 'read' register
3682 * (not offset within BAR, full address)
3683 * @param write_register Address for 'write' register
3684 * (not offset within BAR, full address)
3685 * @param base_register Address for 'base' register
3686 * (not offset within BAR, full address)
3687 * @param size Address for 'size' register
3688 * (not offset within BAR, full address)
3689 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003690static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003691 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003692{
3693 q->n_bd = count;
3694
3695 q->low_mark = q->n_bd / 4;
3696 if (q->low_mark < 4)
3697 q->low_mark = 4;
3698
3699 q->high_mark = q->n_bd / 8;
3700 if (q->high_mark < 2)
3701 q->high_mark = 2;
3702
3703 q->first_empty = q->last_used = 0;
3704 q->reg_r = read;
3705 q->reg_w = write;
3706
3707 ipw_write32(priv, base, q->dma_addr);
3708 ipw_write32(priv, size, count);
3709 ipw_write32(priv, read, 0);
3710 ipw_write32(priv, write, 0);
3711
3712 _ipw_read32(priv, 0x90);
3713}
3714
Jeff Garzikbf794512005-07-31 13:07:26 -04003715static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003716 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003717 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003718{
3719 struct pci_dev *dev = priv->pci_dev;
3720
3721 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3722 if (!q->txb) {
3723 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3724 return -ENOMEM;
3725 }
3726
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003727 q->bd =
3728 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003729 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003730 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003731 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003732 kfree(q->txb);
3733 q->txb = NULL;
3734 return -ENOMEM;
3735 }
3736
3737 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3738 return 0;
3739}
3740
3741/**
3742 * Free one TFD, those at index [txq->q.last_used].
3743 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003744 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003745 * @param dev
3746 * @param txq
3747 */
3748static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3749 struct clx2_tx_queue *txq)
3750{
3751 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3752 struct pci_dev *dev = priv->pci_dev;
3753 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003754
James Ketrenos43f66a62005-03-25 12:31:53 -06003755 /* classify bd */
3756 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3757 /* nothing to cleanup after for host commands */
3758 return;
3759
3760 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003761 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3762 IPW_ERROR("Too many chunks: %i\n",
3763 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003764 /** @todo issue fatal error, it is quite serious situation */
3765 return;
3766 }
3767
3768 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003769 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3770 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3771 le16_to_cpu(bd->u.data.chunk_len[i]),
3772 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003773 if (txq->txb[txq->q.last_used]) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04003774 libipw_txb_free(txq->txb[txq->q.last_used]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003775 txq->txb[txq->q.last_used] = NULL;
3776 }
3777 }
3778}
3779
3780/**
3781 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003782 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003783 * Empty queue by removing and destroying all BD's.
3784 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003785 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003786 * @param dev
3787 * @param q
3788 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003789static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003790{
3791 struct clx2_queue *q = &txq->q;
3792 struct pci_dev *dev = priv->pci_dev;
3793
Jeff Garzikbf794512005-07-31 13:07:26 -04003794 if (q->n_bd == 0)
3795 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003796
3797 /* first, empty all BD's */
3798 for (; q->first_empty != q->last_used;
3799 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3800 ipw_queue_tx_free_tfd(priv, txq);
3801 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003802
James Ketrenos43f66a62005-03-25 12:31:53 -06003803 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003804 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003805 q->dma_addr);
3806 kfree(txq->txb);
3807
3808 /* 0 fill whole structure */
3809 memset(txq, 0, sizeof(*txq));
3810}
3811
James Ketrenos43f66a62005-03-25 12:31:53 -06003812/**
3813 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003814 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003815 * @param priv
3816 */
3817static void ipw_tx_queue_free(struct ipw_priv *priv)
3818{
3819 /* Tx CMD queue */
3820 ipw_queue_tx_free(priv, &priv->txq_cmd);
3821
3822 /* Tx queues */
3823 ipw_queue_tx_free(priv, &priv->txq[0]);
3824 ipw_queue_tx_free(priv, &priv->txq[1]);
3825 ipw_queue_tx_free(priv, &priv->txq[2]);
3826 ipw_queue_tx_free(priv, &priv->txq[3]);
3827}
3828
Arjan van de Ven858119e2006-01-14 13:20:43 -08003829static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003830{
3831 /* First 3 bytes are manufacturer */
3832 bssid[0] = priv->mac_addr[0];
3833 bssid[1] = priv->mac_addr[1];
3834 bssid[2] = priv->mac_addr[2];
3835
3836 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003837 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003838
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003839 bssid[0] &= 0xfe; /* clear multicast bit */
3840 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003841}
3842
Arjan van de Ven858119e2006-01-14 13:20:43 -08003843static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003844{
3845 struct ipw_station_entry entry;
3846 int i;
3847
3848 for (i = 0; i < priv->num_stations; i++) {
3849 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3850 /* Another node is active in network */
3851 priv->missed_adhoc_beacons = 0;
3852 if (!(priv->config & CFG_STATIC_CHANNEL))
3853 /* when other nodes drop out, we drop out */
3854 priv->config &= ~CFG_ADHOC_PERSIST;
3855
3856 return i;
3857 }
3858 }
3859
3860 if (i == MAX_STATIONS)
3861 return IPW_INVALID_STATION;
3862
Johannes Berge1749612008-10-27 15:59:26 -07003863 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06003864
3865 entry.reserved = 0;
3866 entry.support_mode = 0;
3867 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3868 memcpy(priv->stations[i], bssid, ETH_ALEN);
3869 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003870 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003871 priv->num_stations++;
3872
3873 return i;
3874}
3875
Arjan van de Ven858119e2006-01-14 13:20:43 -08003876static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003877{
3878 int i;
3879
Jeff Garzikbf794512005-07-31 13:07:26 -04003880 for (i = 0; i < priv->num_stations; i++)
3881 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003882 return i;
3883
3884 return IPW_INVALID_STATION;
3885}
3886
3887static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3888{
3889 int err;
3890
Hong Liu7b996592005-08-25 17:36:13 +08003891 if (priv->status & STATUS_ASSOCIATING) {
3892 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3893 queue_work(priv->workqueue, &priv->disassociate);
3894 return;
3895 }
3896
3897 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003898 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3899 return;
3900 }
3901
Johannes Berge1749612008-10-27 15:59:26 -07003902 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 "on channel %d.\n",
Johannes Berge1749612008-10-27 15:59:26 -07003904 priv->assoc_request.bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06003905 priv->assoc_request.channel);
3906
3907 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3908 priv->status |= STATUS_DISASSOCIATING;
3909
3910 if (quiet)
3911 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3912 else
3913 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003914
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 err = ipw_send_associate(priv, &priv->assoc_request);
3916 if (err) {
3917 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3918 "failed.\n");
3919 return;
3920 }
3921
3922}
3923
James Ketrenosc848d0a2005-08-24 21:56:24 -05003924static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003925{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003926 struct ipw_priv *priv = data;
3927 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3928 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003929 ipw_send_disassociate(data, 0);
Zhu Yib8ddafd2008-11-27 13:42:20 +08003930 netif_carrier_off(priv->net_dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003931 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003932}
3933
David Howellsc4028952006-11-22 14:57:56 +00003934static void ipw_bg_disassociate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06003935{
David Howellsc4028952006-11-22 14:57:56 +00003936 struct ipw_priv *priv =
3937 container_of(work, struct ipw_priv, disassociate);
Zhu Yi46441512006-01-24 16:37:59 +08003938 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00003939 ipw_disassociate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08003940 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003941}
3942
David Howellsc4028952006-11-22 14:57:56 +00003943static void ipw_system_config(struct work_struct *work)
Zhu Yid8bad6d2005-07-13 12:25:38 -05003944{
David Howellsc4028952006-11-22 14:57:56 +00003945 struct ipw_priv *priv =
3946 container_of(work, struct ipw_priv, system_config);
Zhu Yid685b8c2006-04-13 17:20:27 +08003947
3948#ifdef CONFIG_IPW2200_PROMISCUOUS
3949 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3950 priv->sys_config.accept_all_data_frames = 1;
3951 priv->sys_config.accept_non_directed_frames = 1;
3952 priv->sys_config.accept_all_mgmt_bcpr = 1;
3953 priv->sys_config.accept_all_mgmt_frames = 1;
3954 }
3955#endif
3956
3957 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003958}
3959
3960struct ipw_status_code {
3961 u16 status;
3962 const char *reason;
3963};
3964
3965static const struct ipw_status_code ipw_status_codes[] = {
3966 {0x00, "Successful"},
3967 {0x01, "Unspecified failure"},
3968 {0x0A, "Cannot support all requested capabilities in the "
3969 "Capability information field"},
3970 {0x0B, "Reassociation denied due to inability to confirm that "
3971 "association exists"},
3972 {0x0C, "Association denied due to reason outside the scope of this "
3973 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003974 {0x0D,
3975 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003976 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003977 {0x0E,
3978 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 "transaction sequence number out of expected sequence"},
3980 {0x0F, "Authentication rejected because of challenge failure"},
3981 {0x10, "Authentication rejected due to timeout waiting for next "
3982 "frame in sequence"},
3983 {0x11, "Association denied because AP is unable to handle additional "
3984 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003985 {0x12,
3986 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003987 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003988 {0x13,
3989 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003990 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003991 {0x14,
3992 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003993 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003994 {0x15,
3995 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003996 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003997 {0x19,
3998 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003999 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004000 {0x1A,
4001 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06004002 "DSSS-OFDM operation"},
4003 {0x28, "Invalid Information Element"},
4004 {0x29, "Group Cipher is not valid"},
4005 {0x2A, "Pairwise Cipher is not valid"},
4006 {0x2B, "AKMP is not valid"},
4007 {0x2C, "Unsupported RSN IE version"},
4008 {0x2D, "Invalid RSN IE Capabilities"},
4009 {0x2E, "Cipher suite is rejected per security policy"},
4010};
4011
Jeff Garzikbf794512005-07-31 13:07:26 -04004012static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06004013{
4014 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04004015 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004016 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06004017 return ipw_status_codes[i].reason;
4018 return "Unknown status value.";
4019}
James Ketrenos43f66a62005-03-25 12:31:53 -06004020
4021static void inline average_init(struct average *avg)
4022{
4023 memset(avg, 0, sizeof(*avg));
4024}
4025
Zhu Yi00d21de2006-04-13 17:19:02 +08004026#define DEPTH_RSSI 8
4027#define DEPTH_NOISE 16
4028static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4029{
4030 return ((depth-1)*prev_avg + val)/depth;
4031}
4032
Arjan van de Ven858119e2006-01-14 13:20:43 -08004033static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06004034{
4035 avg->sum -= avg->entries[avg->pos];
4036 avg->sum += val;
4037 avg->entries[avg->pos++] = val;
4038 if (unlikely(avg->pos == AVG_ENTRIES)) {
4039 avg->init = 1;
4040 avg->pos = 0;
4041 }
4042}
4043
Arjan van de Ven858119e2006-01-14 13:20:43 -08004044static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06004045{
4046 if (!unlikely(avg->init)) {
4047 if (avg->pos)
4048 return avg->sum / avg->pos;
4049 return 0;
4050 }
4051
4052 return avg->sum / AVG_ENTRIES;
4053}
4054
4055static void ipw_reset_stats(struct ipw_priv *priv)
4056{
4057 u32 len = sizeof(u32);
4058
4059 priv->quality = 0;
4060
4061 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08004062 priv->exp_avg_rssi = -60;
4063 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06004064
4065 priv->last_rate = 0;
4066 priv->last_missed_beacons = 0;
4067 priv->last_rx_packets = 0;
4068 priv->last_tx_packets = 0;
4069 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004070
James Ketrenos43f66a62005-03-25 12:31:53 -06004071 /* Firmware managed, reset only when NIC is restarted, so we have to
4072 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04004073 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06004074 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04004075 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004076 &priv->last_tx_failures, &len);
4077
4078 /* Driver managed, reset with each association */
4079 priv->missed_adhoc_beacons = 0;
4080 priv->missed_beacons = 0;
4081 priv->tx_packets = 0;
4082 priv->rx_packets = 0;
4083
4084}
4085
Arjan van de Ven858119e2006-01-14 13:20:43 -08004086static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004087{
4088 u32 i = 0x80000000;
4089 u32 mask = priv->rates_mask;
4090 /* If currently associated in B mode, restrict the maximum
4091 * rate match to B rates */
4092 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004093 mask &= LIBIPW_CCK_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06004094
4095 /* TODO: Verify that the rate is supported by the current rates
4096 * list. */
4097
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004098 while (i && !(mask & i))
4099 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004100 switch (i) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004101 case LIBIPW_CCK_RATE_1MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004102 return 1000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004103 case LIBIPW_CCK_RATE_2MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004104 return 2000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004105 case LIBIPW_CCK_RATE_5MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004106 return 5500000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004107 case LIBIPW_OFDM_RATE_6MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004108 return 6000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004109 case LIBIPW_OFDM_RATE_9MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004110 return 9000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004111 case LIBIPW_CCK_RATE_11MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004112 return 11000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004113 case LIBIPW_OFDM_RATE_12MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004114 return 12000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004115 case LIBIPW_OFDM_RATE_18MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004116 return 18000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004117 case LIBIPW_OFDM_RATE_24MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004118 return 24000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004119 case LIBIPW_OFDM_RATE_36MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004120 return 36000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004121 case LIBIPW_OFDM_RATE_48MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004122 return 48000000;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004123 case LIBIPW_OFDM_RATE_54MB_MASK:
James Ketrenosea2b26e2005-08-24 21:25:16 -05004124 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004125 }
4126
Jeff Garzikbf794512005-07-31 13:07:26 -04004127 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004128 return 11000000;
4129 else
4130 return 54000000;
4131}
4132
4133static u32 ipw_get_current_rate(struct ipw_priv *priv)
4134{
4135 u32 rate, len = sizeof(rate);
4136 int err;
4137
Jeff Garzikbf794512005-07-31 13:07:26 -04004138 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004139 return 0;
4140
4141 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004142 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004143 &len);
4144 if (err) {
4145 IPW_DEBUG_INFO("failed querying ordinals.\n");
4146 return 0;
4147 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004148 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004149 return ipw_get_max_rate(priv);
4150
4151 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004152 case IPW_TX_RATE_1MB:
4153 return 1000000;
4154 case IPW_TX_RATE_2MB:
4155 return 2000000;
4156 case IPW_TX_RATE_5MB:
4157 return 5500000;
4158 case IPW_TX_RATE_6MB:
4159 return 6000000;
4160 case IPW_TX_RATE_9MB:
4161 return 9000000;
4162 case IPW_TX_RATE_11MB:
4163 return 11000000;
4164 case IPW_TX_RATE_12MB:
4165 return 12000000;
4166 case IPW_TX_RATE_18MB:
4167 return 18000000;
4168 case IPW_TX_RATE_24MB:
4169 return 24000000;
4170 case IPW_TX_RATE_36MB:
4171 return 36000000;
4172 case IPW_TX_RATE_48MB:
4173 return 48000000;
4174 case IPW_TX_RATE_54MB:
4175 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004176 }
4177
4178 return 0;
4179}
4180
James Ketrenos43f66a62005-03-25 12:31:53 -06004181#define IPW_STATS_INTERVAL (2 * HZ)
4182static void ipw_gather_stats(struct ipw_priv *priv)
4183{
4184 u32 rx_err, rx_err_delta, rx_packets_delta;
4185 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4186 u32 missed_beacons_percent, missed_beacons_delta;
4187 u32 quality = 0;
4188 u32 len = sizeof(u32);
4189 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004190 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004191 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004192 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004193
4194 if (!(priv->status & STATUS_ASSOCIATED)) {
4195 priv->quality = 0;
4196 return;
4197 }
4198
4199 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004200 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004201 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004202 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004203 priv->last_missed_beacons = priv->missed_beacons;
4204 if (priv->assoc_request.beacon_interval) {
4205 missed_beacons_percent = missed_beacons_delta *
Al Viro5b5e8072007-12-27 01:54:06 -05004206 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004207 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004208 } else {
4209 missed_beacons_percent = 0;
4210 }
4211 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4212
4213 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4214 rx_err_delta = rx_err - priv->last_rx_err;
4215 priv->last_rx_err = rx_err;
4216
4217 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4218 tx_failures_delta = tx_failures - priv->last_tx_failures;
4219 priv->last_tx_failures = tx_failures;
4220
4221 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4222 priv->last_rx_packets = priv->rx_packets;
4223
4224 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4225 priv->last_tx_packets = priv->tx_packets;
4226
4227 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004228 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004229 * Missed beacon: 100% = 0, 0% = 70% missed
4230 * Rate: 60% = 1Mbs, 100% = Max
4231 * Rx and Tx errors represent a straight % of total Rx/Tx
4232 * RSSI: 100% = > -50, 0% = < -80
4233 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004234 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004235 * The lowest computed quality is used.
4236 *
4237 */
4238#define BEACON_THRESHOLD 5
4239 beacon_quality = 100 - missed_beacons_percent;
4240 if (beacon_quality < BEACON_THRESHOLD)
4241 beacon_quality = 0;
4242 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004243 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004244 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004245 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004246 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004247
James Ketrenos43f66a62005-03-25 12:31:53 -06004248 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004249 max_rate = ipw_get_max_rate(priv);
4250 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004251 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4252 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004253
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004254 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004255 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004256 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004257 else
4258 rx_quality = 100;
4259 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4260 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004262 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004263 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004264 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004265 else
4266 tx_quality = 100;
4267 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4268 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004269
Zhu Yi00d21de2006-04-13 17:19:02 +08004270 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004271 signal_quality =
4272 (100 *
4273 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4274 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4275 (priv->ieee->perfect_rssi - rssi) *
4276 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4277 62 * (priv->ieee->perfect_rssi - rssi))) /
4278 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4279 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4280 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004281 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004282 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004283 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004284
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004285 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004286 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004287
Reinette Chatre21f8a732009-08-18 10:25:05 -07004288 quality = min(rx_quality, signal_quality);
4289 quality = min(tx_quality, quality);
4290 quality = min(rate_quality, quality);
4291 quality = min(beacon_quality, quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004292 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004293 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4294 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004295 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004296 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4297 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004298 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004299 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4300 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004301 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004302 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4303 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004304 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004305 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4306 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004307
4308 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004309
4310 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004311 IPW_STATS_INTERVAL);
4312}
4313
David Howellsc4028952006-11-22 14:57:56 +00004314static void ipw_bg_gather_stats(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05004315{
David Howellsc4028952006-11-22 14:57:56 +00004316 struct ipw_priv *priv =
4317 container_of(work, struct ipw_priv, gather_stats.work);
Zhu Yi46441512006-01-24 16:37:59 +08004318 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00004319 ipw_gather_stats(priv);
Zhu Yi46441512006-01-24 16:37:59 +08004320 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004321}
4322
Ben Cahille7582562005-10-06 15:34:41 -05004323/* Missed beacon behavior:
4324 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4325 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4326 * Above disassociate threshold, give up and stop scanning.
4327 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004328static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004329 int missed_count)
4330{
4331 priv->notif_missed_beacons = missed_count;
4332
James Ketrenosafbf30a2005-08-25 00:05:33 -05004333 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004334 priv->status & STATUS_ASSOCIATED) {
4335 /* If associated and we've hit the missed
4336 * beacon threshold, disassociate, turn
4337 * off roaming, and abort any active scans */
4338 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004339 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004340 "Missed beacon: %d - disassociate\n", missed_count);
4341 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004342 if (priv->status & STATUS_SCANNING) {
4343 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4344 IPW_DL_STATE,
4345 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004346 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004347 }
4348
James Ketrenosea2b26e2005-08-24 21:25:16 -05004349 queue_work(priv->workqueue, &priv->disassociate);
4350 return;
4351 }
4352
4353 if (priv->status & STATUS_ROAMING) {
4354 /* If we are currently roaming, then just
4355 * print a debug statement... */
4356 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4357 "Missed beacon: %d - roam in progress\n",
4358 missed_count);
4359 return;
4360 }
4361
Zhu Yi4bfdb912006-01-24 16:37:16 +08004362 if (roaming &&
4363 (missed_count > priv->roaming_threshold &&
4364 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004365 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004366 * bit in the status and kick off a scan.
4367 * This can happen several times before we reach
4368 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004369 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4370 "Missed beacon: %d - initiate "
4371 "roaming\n", missed_count);
4372 if (!(priv->status & STATUS_ROAMING)) {
4373 priv->status |= STATUS_ROAMING;
4374 if (!(priv->status & STATUS_SCANNING))
David Howellsc4028952006-11-22 14:57:56 +00004375 queue_delayed_work(priv->workqueue,
4376 &priv->request_scan, 0);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004377 }
4378 return;
4379 }
4380
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01004381 if (priv->status & STATUS_SCANNING &&
4382 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004383 /* Stop scan to keep fw from getting
4384 * stuck (only if we aren't roaming --
4385 * otherwise we'll never scan more than 2 or 3
4386 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004387 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4388 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004389 queue_work(priv->workqueue, &priv->abort_scan);
4390 }
4391
4392 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004393}
4394
Dan Williams0b531672007-10-09 13:55:24 -04004395static void ipw_scan_event(struct work_struct *work)
4396{
4397 union iwreq_data wrqu;
4398
4399 struct ipw_priv *priv =
4400 container_of(work, struct ipw_priv, scan_event.work);
4401
4402 wrqu.data.length = 0;
4403 wrqu.data.flags = 0;
4404 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4405}
4406
4407static void handle_scan_event(struct ipw_priv *priv)
4408{
4409 /* Only userspace-requested scan completion events go out immediately */
4410 if (!priv->user_requested_scan) {
4411 if (!delayed_work_pending(&priv->scan_event))
4412 queue_delayed_work(priv->workqueue, &priv->scan_event,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004413 round_jiffies_relative(msecs_to_jiffies(4000)));
Dan Williams0b531672007-10-09 13:55:24 -04004414 } else {
4415 union iwreq_data wrqu;
4416
4417 priv->user_requested_scan = 0;
4418 cancel_delayed_work(&priv->scan_event);
4419
4420 wrqu.data.length = 0;
4421 wrqu.data.flags = 0;
4422 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4423 }
4424}
4425
James Ketrenos43f66a62005-03-25 12:31:53 -06004426/**
4427 * Handle host notification packet.
4428 * Called from interrupt routine
4429 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004430static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004431 struct ipw_rx_notification *notif)
4432{
John W. Linville9387b7c2008-09-30 20:59:05 -04004433 DECLARE_SSID_BUF(ssid);
Al Viroe62e1ee2007-12-27 01:36:46 -05004434 u16 size = le16_to_cpu(notif->size);
James Ketrenosa613bff2005-08-24 21:43:11 -05004435
Al Viroe62e1ee2007-12-27 01:36:46 -05004436 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004437
James Ketrenos43f66a62005-03-25 12:31:53 -06004438 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004439 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4440 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004441
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004442 switch (assoc->state) {
4443 case CMAS_ASSOCIATED:{
4444 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4445 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004446 "associated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004447 print_ssid(ssid, priv->essid,
4448 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004449 priv->bssid);
Jeff Garzikbf794512005-07-31 13:07:26 -04004450
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004451 switch (priv->ieee->iw_mode) {
4452 case IW_MODE_INFRA:
4453 memcpy(priv->ieee->bssid,
4454 priv->bssid, ETH_ALEN);
4455 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004456
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004457 case IW_MODE_ADHOC:
4458 memcpy(priv->ieee->bssid,
4459 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004460
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004461 /* clear out the station table */
4462 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004463
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004464 IPW_DEBUG_ASSOC
4465 ("queueing adhoc check\n");
4466 queue_delayed_work(priv->
4467 workqueue,
4468 &priv->
4469 adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05004470 le16_to_cpu(priv->
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004471 assoc_request.
Al Viro5b5e8072007-12-27 01:54:06 -05004472 beacon_interval));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004473 break;
4474 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004475
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004476 priv->status &= ~STATUS_ASSOCIATING;
4477 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004478 queue_work(priv->workqueue,
4479 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004480
Zhu Yie43e3c12006-04-13 17:20:45 +08004481#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004482#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
John W. Linville72118012008-09-30 21:43:03 -04004483 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
James Ketrenosafbf30a2005-08-25 00:05:33 -05004484 if ((priv->status & STATUS_AUTH) &&
4485 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4486 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004487 if ((sizeof
4488 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004489 libipw_assoc_response)
Al Viroe62e1ee2007-12-27 01:36:46 -05004490 <= size)
4491 && (size <= 2314)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004492 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004493 libipw_rx_stats
James Ketrenosb095c382005-08-24 22:04:42 -05004494 stats = {
Al Viroe62e1ee2007-12-27 01:36:46 -05004495 .len = size - 1,
James Ketrenosb095c382005-08-24 22:04:42 -05004496 };
4497
4498 IPW_DEBUG_QOS
4499 ("QoS Associate "
Al Viroe62e1ee2007-12-27 01:36:46 -05004500 "size %d\n", size);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004501 libipw_rx_mgt(priv->
James Ketrenosb095c382005-08-24 22:04:42 -05004502 ieee,
4503 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004504 libipw_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004505 *)
4506 &notif->u.raw, &stats);
4507 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004508 }
James Ketrenosb095c382005-08-24 22:04:42 -05004509#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004510
James Ketrenosa613bff2005-08-24 21:43:11 -05004511 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004512
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004513 break;
4514 }
4515
4516 case CMAS_AUTHENTICATED:{
4517 if (priv->
4518 status & (STATUS_ASSOCIATED |
4519 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 struct notif_authenticate *auth
4521 = &notif->u.auth;
4522 IPW_DEBUG(IPW_DL_NOTIF |
4523 IPW_DL_STATE |
4524 IPW_DL_ASSOC,
4525 "deauthenticated: '%s' "
Johannes Berge1749612008-10-27 15:59:26 -07004526 "%pM"
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004527 ": (0x%04X) - %s \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004528 print_ssid(ssid,
4529 priv->
4530 essid,
4531 priv->
4532 essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004533 priv->bssid,
Al Viro83f7d572008-03-16 22:26:44 +00004534 le16_to_cpu(auth->status),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004535 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004536 (le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004537 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004538
4539 priv->status &=
4540 ~(STATUS_ASSOCIATING |
4541 STATUS_AUTH |
4542 STATUS_ASSOCIATED);
4543
James Ketrenosa613bff2005-08-24 21:43:11 -05004544 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004545 break;
4546 }
4547
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004550 "authenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004551 print_ssid(ssid, priv->essid,
4552 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004553 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004554 break;
4555 }
4556
4557 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004558 if (priv->status & STATUS_AUTH) {
4559 struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004560 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004561 *resp;
4562 resp =
4563 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04004564 libipw_assoc_response
James Ketrenosea2b26e2005-08-24 21:25:16 -05004565 *)&notif->u.raw;
4566 IPW_DEBUG(IPW_DL_NOTIF |
4567 IPW_DL_STATE |
4568 IPW_DL_ASSOC,
4569 "association failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004570 le16_to_cpu(resp->status),
James Ketrenosea2b26e2005-08-24 21:25:16 -05004571 ipw_get_status_code
Al Viro83f7d572008-03-16 22:26:44 +00004572 (le16_to_cpu
James Ketrenosea2b26e2005-08-24 21:25:16 -05004573 (resp->status)));
4574 }
4575
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004576 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4577 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004578 "disassociated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004579 print_ssid(ssid, priv->essid,
4580 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004581 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004582
4583 priv->status &=
4584 ~(STATUS_DISASSOCIATING |
4585 STATUS_ASSOCIATING |
4586 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004587 if (priv->assoc_network
4588 && (priv->assoc_network->
4589 capability &
4590 WLAN_CAPABILITY_IBSS))
4591 ipw_remove_current_network
4592 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004593
James Ketrenosa613bff2005-08-24 21:43:11 -05004594 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004595
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004596 break;
4597 }
4598
James Ketrenosb095c382005-08-24 22:04:42 -05004599 case CMAS_RX_ASSOC_RESP:
4600 break;
4601
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004602 default:
4603 IPW_ERROR("assoc: unknown (%d)\n",
4604 assoc->state);
4605 break;
4606 }
4607
James Ketrenos43f66a62005-03-25 12:31:53 -06004608 break;
4609 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004610
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004611 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4612 struct notif_authenticate *auth = &notif->u.auth;
4613 switch (auth->state) {
4614 case CMAS_AUTHENTICATED:
4615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Johannes Berge1749612008-10-27 15:59:26 -07004616 "authenticated: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004617 print_ssid(ssid, priv->essid,
4618 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004619 priv->bssid);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004620 priv->status |= STATUS_AUTH;
4621 break;
4622
4623 case CMAS_INIT:
4624 if (priv->status & STATUS_AUTH) {
4625 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4626 IPW_DL_ASSOC,
4627 "authentication failed (0x%04X): %s\n",
Al Viro83f7d572008-03-16 22:26:44 +00004628 le16_to_cpu(auth->status),
4629 ipw_get_status_code(le16_to_cpu
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004630 (auth->
4631 status)));
4632 }
4633 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4634 IPW_DL_ASSOC,
Johannes Berge1749612008-10-27 15:59:26 -07004635 "deauthenticated: '%s' %pM\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004636 print_ssid(ssid, priv->essid,
4637 priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07004638 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06004639
4640 priv->status &= ~(STATUS_ASSOCIATING |
4641 STATUS_AUTH |
4642 STATUS_ASSOCIATED);
4643
James Ketrenosa613bff2005-08-24 21:43:11 -05004644 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004645 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004646
4647 case CMAS_TX_AUTH_SEQ_1:
4648 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4649 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4650 break;
4651 case CMAS_RX_AUTH_SEQ_2:
4652 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4653 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4654 break;
4655 case CMAS_AUTH_SEQ_1_PASS:
4656 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4657 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4658 break;
4659 case CMAS_AUTH_SEQ_1_FAIL:
4660 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4661 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4662 break;
4663 case CMAS_TX_AUTH_SEQ_3:
4664 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4665 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4666 break;
4667 case CMAS_RX_AUTH_SEQ_4:
4668 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4669 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4670 break;
4671 case CMAS_AUTH_SEQ_2_PASS:
4672 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4673 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4674 break;
4675 case CMAS_AUTH_SEQ_2_FAIL:
4676 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4677 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4678 break;
4679 case CMAS_TX_ASSOC:
4680 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4681 IPW_DL_ASSOC, "TX_ASSOC\n");
4682 break;
4683 case CMAS_RX_ASSOC_RESP:
4684 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4685 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004686
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004687 break;
4688 case CMAS_ASSOCIATED:
4689 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4690 IPW_DL_ASSOC, "ASSOCIATED\n");
4691 break;
4692 default:
4693 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4694 auth->state);
4695 break;
4696 }
4697 break;
4698 }
4699
4700 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4701 struct notif_channel_result *x =
4702 &notif->u.channel_result;
4703
Al Viroe62e1ee2007-12-27 01:36:46 -05004704 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004705 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4706 x->channel_num);
4707 } else {
4708 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4709 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004710 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004711 }
4712 break;
4713 }
4714
4715 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4716 struct notif_scan_complete *x = &notif->u.scan_complete;
Al Viroe62e1ee2007-12-27 01:36:46 -05004717 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004718 IPW_DEBUG_SCAN
4719 ("Scan completed: type %d, %d channels, "
4720 "%d status\n", x->scan_type,
4721 x->num_channels, x->status);
4722 } else {
4723 IPW_ERROR("Scan completed of wrong size %d "
4724 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004725 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004726 }
4727
4728 priv->status &=
4729 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4730
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004731 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004732 cancel_delayed_work(&priv->scan_check);
4733
James Ketrenosb095c382005-08-24 22:04:42 -05004734 if (priv->status & STATUS_EXIT_PENDING)
4735 break;
4736
4737 priv->ieee->scans++;
4738
4739#ifdef CONFIG_IPW2200_MONITOR
4740 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004741 priv->status |= STATUS_SCAN_FORCED;
David Howellsc4028952006-11-22 14:57:56 +00004742 queue_delayed_work(priv->workqueue,
4743 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05004744 break;
4745 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004746 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004747#endif /* CONFIG_IPW2200_MONITOR */
4748
Dan Williamsea177302008-06-02 17:51:23 -04004749 /* Do queued direct scans first */
4750 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4751 queue_delayed_work(priv->workqueue,
4752 &priv->request_direct_scan, 0);
4753 }
4754
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004755 if (!(priv->status & (STATUS_ASSOCIATED |
4756 STATUS_ASSOCIATING |
4757 STATUS_ROAMING |
4758 STATUS_DISASSOCIATING)))
4759 queue_work(priv->workqueue, &priv->associate);
4760 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004761 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4762 /* If a scan completed and we are in roam mode, then
4763 * the scan that completed was the one requested as a
4764 * result of entering roam... so, schedule the
4765 * roam work */
4766 queue_work(priv->workqueue,
4767 &priv->roam);
4768 else
4769 /* Don't schedule if we aborted the scan */
4770 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004771 } else if (priv->status & STATUS_SCAN_PENDING)
David Howellsc4028952006-11-22 14:57:56 +00004772 queue_delayed_work(priv->workqueue,
4773 &priv->request_scan, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05004774 else if (priv->config & CFG_BACKGROUND_SCAN
4775 && priv->status & STATUS_ASSOCIATED)
4776 queue_delayed_work(priv->workqueue,
Stephen Hemminger1c9d5e42007-06-22 21:34:06 -07004777 &priv->request_scan,
Anton Blanchardbe84e3d2007-10-15 00:38:01 -05004778 round_jiffies_relative(HZ));
Zhu Yi07f02e42006-04-13 17:19:25 +08004779
4780 /* Send an empty event to user space.
4781 * We don't send the received data on the event because
4782 * it would require us to do complex transcoding, and
4783 * we want to minimise the work done in the irq handler
4784 * Use a request to extract the data.
4785 * Also, we generate this even for any scan, regardless
4786 * on how the scan was initiated. User space can just
4787 * sync on periodic scan to get fresh data...
4788 * Jean II */
Dan Williams0b531672007-10-09 13:55:24 -04004789 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4790 handle_scan_event(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004791 break;
4792 }
4793
4794 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4795 struct notif_frag_length *x = &notif->u.frag_len;
4796
Al Viroe62e1ee2007-12-27 01:36:46 -05004797 if (size == sizeof(*x))
James Ketrenosa613bff2005-08-24 21:43:11 -05004798 IPW_ERROR("Frag length: %d\n",
4799 le16_to_cpu(x->frag_length));
4800 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004801 IPW_ERROR("Frag length of wrong size %d "
4802 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004803 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004804 break;
4805 }
4806
4807 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4808 struct notif_link_deterioration *x =
4809 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004810
Al Viroe62e1ee2007-12-27 01:36:46 -05004811 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004812 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004813 "link deterioration: type %d, cnt %d\n",
4814 x->silence_notification_type,
4815 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004816 memcpy(&priv->last_link_deterioration, x,
4817 sizeof(*x));
4818 } else {
4819 IPW_ERROR("Link Deterioration of wrong size %d "
4820 "(should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004821 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004822 }
4823 break;
4824 }
4825
4826 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4827 IPW_ERROR("Dino config\n");
4828 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004829 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004830 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004831
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004832 break;
4833 }
4834
4835 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4836 struct notif_beacon_state *x = &notif->u.beacon_state;
Al Viroe62e1ee2007-12-27 01:36:46 -05004837 if (size != sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004838 IPW_ERROR
4839 ("Beacon state of wrong size %d (should "
Al Viroe62e1ee2007-12-27 01:36:46 -05004840 "be %zd)\n", size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004841 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004842 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004843
James Ketrenosa613bff2005-08-24 21:43:11 -05004844 if (le32_to_cpu(x->state) ==
4845 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4846 ipw_handle_missed_beacon(priv,
4847 le32_to_cpu(x->
4848 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004849
James Ketrenos43f66a62005-03-25 12:31:53 -06004850 break;
4851 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004853 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4854 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
Al Viroe62e1ee2007-12-27 01:36:46 -05004855 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004856 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4857 "0x%02x station %d\n",
4858 x->key_state, x->security_type,
4859 x->station_index);
4860 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004861 }
4862
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004863 IPW_ERROR
4864 ("TGi Tx Key of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004865 size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004866 break;
4867 }
4868
4869 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4870 struct notif_calibration *x = &notif->u.calibration;
4871
Al Viroe62e1ee2007-12-27 01:36:46 -05004872 if (size == sizeof(*x)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 memcpy(&priv->calib, x, sizeof(*x));
4874 IPW_DEBUG_INFO("TODO: Calibration\n");
4875 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 }
4877
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004878 IPW_ERROR
4879 ("Calibration of wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004880 size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004881 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004882 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004883
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004884 case HOST_NOTIFICATION_NOISE_STATS:{
Al Viroe62e1ee2007-12-27 01:36:46 -05004885 if (size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004886 priv->exp_avg_noise =
4887 exponential_average(priv->exp_avg_noise,
4888 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4889 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004890 break;
4891 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004892
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004893 IPW_ERROR
4894 ("Noise stat is wrong size %d (should be %zd)\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004895 size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004896 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004897 }
4898
James Ketrenos43f66a62005-03-25 12:31:53 -06004899 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004900 IPW_DEBUG_NOTIF("Unknown notification: "
4901 "subtype=%d,flags=0x%2x,size=%d\n",
Al Viroe62e1ee2007-12-27 01:36:46 -05004902 notif->subtype, notif->flags, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004903 }
4904}
4905
4906/**
4907 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004908 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004909 * @param priv
4910 * @return error code
4911 */
4912static int ipw_queue_reset(struct ipw_priv *priv)
4913{
4914 int rc = 0;
4915 /** @todo customize queue sizes */
4916 int nTx = 64, nTxCmd = 8;
4917 ipw_tx_queue_free(priv);
4918 /* Tx CMD queue */
4919 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004920 IPW_TX_CMD_QUEUE_READ_INDEX,
4921 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4922 IPW_TX_CMD_QUEUE_BD_BASE,
4923 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004924 if (rc) {
4925 IPW_ERROR("Tx Cmd queue init failed\n");
4926 goto error;
4927 }
4928 /* Tx queue(s) */
4929 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004930 IPW_TX_QUEUE_0_READ_INDEX,
4931 IPW_TX_QUEUE_0_WRITE_INDEX,
4932 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004933 if (rc) {
4934 IPW_ERROR("Tx 0 queue init failed\n");
4935 goto error;
4936 }
4937 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004938 IPW_TX_QUEUE_1_READ_INDEX,
4939 IPW_TX_QUEUE_1_WRITE_INDEX,
4940 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 if (rc) {
4942 IPW_ERROR("Tx 1 queue init failed\n");
4943 goto error;
4944 }
4945 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004946 IPW_TX_QUEUE_2_READ_INDEX,
4947 IPW_TX_QUEUE_2_WRITE_INDEX,
4948 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004949 if (rc) {
4950 IPW_ERROR("Tx 2 queue init failed\n");
4951 goto error;
4952 }
4953 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004954 IPW_TX_QUEUE_3_READ_INDEX,
4955 IPW_TX_QUEUE_3_WRITE_INDEX,
4956 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004957 if (rc) {
4958 IPW_ERROR("Tx 3 queue init failed\n");
4959 goto error;
4960 }
4961 /* statistics */
4962 priv->rx_bufs_min = 0;
4963 priv->rx_pend_max = 0;
4964 return rc;
4965
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004966 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004967 ipw_tx_queue_free(priv);
4968 return rc;
4969}
4970
4971/**
4972 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004973 *
Stefano Brivio8ff9d212008-01-12 23:12:26 +01004974 * When FW advances 'R' index, all entries between old and
James Ketrenos43f66a62005-03-25 12:31:53 -06004975 * new 'R' index need to be reclaimed. As result, some free space
4976 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004977 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004978 * @note Need to protect against garbage in 'R' index
4979 * @param priv
4980 * @param txq
4981 * @param qindex
4982 * @return Number of used entries remains in the queue
4983 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004984static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004985 struct clx2_tx_queue *txq, int qindex)
4986{
4987 u32 hw_tail;
4988 int used;
4989 struct clx2_queue *q = &txq->q;
4990
4991 hw_tail = ipw_read32(priv, q->reg_r);
4992 if (hw_tail >= q->n_bd) {
4993 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004994 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4995 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004996 goto done;
4997 }
4998 for (; q->last_used != hw_tail;
4999 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5000 ipw_queue_tx_free_tfd(priv, txq);
5001 priv->tx_packets++;
5002 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005003 done:
Dan Williams943dbef2008-02-14 17:49:41 -05005004 if ((ipw_tx_queue_space(q) > q->low_mark) &&
David S. Miller521c4d92008-07-22 18:32:47 -07005005 (qindex >= 0))
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005006 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005007 used = q->first_empty - q->last_used;
5008 if (used < 0)
5009 used += q->n_bd;
5010
5011 return used;
5012}
5013
5014static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5015 int len, int sync)
5016{
5017 struct clx2_tx_queue *txq = &priv->txq_cmd;
5018 struct clx2_queue *q = &txq->q;
5019 struct tfd_frame *tfd;
5020
Dan Williams943dbef2008-02-14 17:49:41 -05005021 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005022 IPW_ERROR("No space for Tx\n");
5023 return -EBUSY;
5024 }
5025
5026 tfd = &txq->bd[q->first_empty];
5027 txq->txb[q->first_empty] = NULL;
5028
5029 memset(tfd, 0, sizeof(*tfd));
5030 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5031 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5032 priv->hcmd_seq++;
5033 tfd->u.cmd.index = hcmd;
5034 tfd->u.cmd.length = len;
5035 memcpy(tfd->u.cmd.payload, buf, len);
5036 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5037 ipw_write32(priv, q->reg_w, q->first_empty);
5038 _ipw_read32(priv, 0x90);
5039
5040 return 0;
5041}
5042
Jeff Garzikbf794512005-07-31 13:07:26 -04005043/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005044 * Rx theory of operation
5045 *
5046 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05005047 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 * 0 to 31
5049 *
5050 * Rx Queue Indexes
5051 * The host/firmware share two index registers for managing the Rx buffers.
5052 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005053 * The READ index maps to the first position that the firmware may be writing
5054 * to -- the driver can read up to (but not including) this position and get
5055 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06005056 * The READ index is managed by the firmware once the card is enabled.
5057 *
5058 * The WRITE index maps to the last position the driver has read from -- the
5059 * position preceding WRITE is the last slot the firmware can place a packet.
5060 *
5061 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04005062 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005064 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06005065 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5066 *
5067 * When the firmware places a packet in a buffer it will advance the READ index
5068 * and fire the RX interrupt. The driver can then query the READ index and
5069 * process as many packets as possible, moving the WRITE index forward as it
5070 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04005071 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005072 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005073 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06005074 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04005075 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06005076 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5077 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5078 * 'processed' and 'read' driver indexes as well)
5079 * + A received packet is processed and handed to the kernel network stack,
5080 * detached from the ipw->rxq. The driver 'processed' index is updated.
5081 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04005082 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5083 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06005084 * were enough free buffers and RX_STALLED is set it is cleared.
5085 *
5086 *
5087 * Driver sequence:
5088 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005089 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06005090 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5091 * ipw_rx_queue_restock
5092 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5093 * queue, updates firmware pointers, and updates
5094 * the WRITE index. If insufficient rx_free buffers
5095 * are available, schedules ipw_rx_queue_replenish
5096 *
5097 * -- enable interrupts --
5098 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04005099 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06005100 * Moves the packet buffer from queue to rx_used.
5101 * Calls ipw_rx_queue_restock to refill any empty
5102 * slots.
5103 * ...
5104 *
5105 */
5106
Jeff Garzikbf794512005-07-31 13:07:26 -04005107/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005108 * If there are slots in the RX queue that need to be restocked,
5109 * and we have free pre-allocated buffers, fill the ranks as much
5110 * as we can pulling from rx_free.
5111 *
5112 * This moves the 'write' index forward to catch up with 'processed', and
5113 * also updates the memory address in the firmware to reference the new
5114 * target buffer.
5115 */
5116static void ipw_rx_queue_restock(struct ipw_priv *priv)
5117{
5118 struct ipw_rx_queue *rxq = priv->rxq;
5119 struct list_head *element;
5120 struct ipw_rx_mem_buffer *rxb;
5121 unsigned long flags;
5122 int write;
5123
5124 spin_lock_irqsave(&rxq->lock, flags);
5125 write = rxq->write;
Dan Williams943dbef2008-02-14 17:49:41 -05005126 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005127 element = rxq->rx_free.next;
5128 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5129 list_del(element);
5130
James Ketrenosb095c382005-08-24 22:04:42 -05005131 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005132 rxb->dma_addr);
5133 rxq->queue[rxq->write] = rxb;
5134 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5135 rxq->free_count--;
5136 }
5137 spin_unlock_irqrestore(&rxq->lock, flags);
5138
Jeff Garzikbf794512005-07-31 13:07:26 -04005139 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005140 * refill it */
5141 if (rxq->free_count <= RX_LOW_WATERMARK)
5142 queue_work(priv->workqueue, &priv->rx_replenish);
5143
5144 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005145 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005146 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005147}
5148
5149/*
5150 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005151 * Also restock the Rx queue via ipw_rx_queue_restock.
5152 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005153 * This is called as a scheduled work item (except for during intialization)
5154 */
5155static void ipw_rx_queue_replenish(void *data)
5156{
5157 struct ipw_priv *priv = data;
5158 struct ipw_rx_queue *rxq = priv->rxq;
5159 struct list_head *element;
5160 struct ipw_rx_mem_buffer *rxb;
5161 unsigned long flags;
5162
5163 spin_lock_irqsave(&rxq->lock, flags);
5164 while (!list_empty(&rxq->rx_used)) {
5165 element = rxq->rx_used.next;
5166 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005167 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005168 if (!rxb->skb) {
5169 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5170 priv->net_dev->name);
5171 /* We don't reschedule replenish work here -- we will
5172 * call the restock method and if it still needs
5173 * more buffers it will schedule replenish */
5174 break;
5175 }
5176 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005178 rxb->dma_addr =
5179 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005180 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005181
James Ketrenos43f66a62005-03-25 12:31:53 -06005182 list_add_tail(&rxb->list, &rxq->rx_free);
5183 rxq->free_count++;
5184 }
5185 spin_unlock_irqrestore(&rxq->lock, flags);
5186
5187 ipw_rx_queue_restock(priv);
5188}
5189
David Howellsc4028952006-11-22 14:57:56 +00005190static void ipw_bg_rx_queue_replenish(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005191{
David Howellsc4028952006-11-22 14:57:56 +00005192 struct ipw_priv *priv =
5193 container_of(work, struct ipw_priv, rx_replenish);
Zhu Yi46441512006-01-24 16:37:59 +08005194 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00005195 ipw_rx_queue_replenish(priv);
Zhu Yi46441512006-01-24 16:37:59 +08005196 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005197}
5198
James Ketrenos43f66a62005-03-25 12:31:53 -06005199/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005200 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005201 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005202 * non NULL it is unmapped and freed
5203 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005204static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005205{
5206 int i;
5207
5208 if (!rxq)
5209 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005210
James Ketrenos43f66a62005-03-25 12:31:53 -06005211 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5212 if (rxq->pool[i].skb != NULL) {
5213 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005214 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005215 dev_kfree_skb(rxq->pool[i].skb);
5216 }
5217 }
5218
5219 kfree(rxq);
5220}
5221
5222static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5223{
5224 struct ipw_rx_queue *rxq;
5225 int i;
5226
Takisc75f4742005-12-01 01:41:45 -08005227 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005228 if (unlikely(!rxq)) {
5229 IPW_ERROR("memory allocation failed\n");
5230 return NULL;
5231 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005232 spin_lock_init(&rxq->lock);
5233 INIT_LIST_HEAD(&rxq->rx_free);
5234 INIT_LIST_HEAD(&rxq->rx_used);
5235
5236 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005237 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005238 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5239
5240 /* Set us so that we have processed and used all buffers, but have
5241 * not restocked the Rx queue with fresh buffers */
5242 rxq->read = rxq->write = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005243 rxq->free_count = 0;
5244
5245 return rxq;
5246}
5247
5248static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5249{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005250 rate &= ~LIBIPW_BASIC_RATE_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06005251 if (ieee_mode == IEEE_A) {
5252 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005253 case LIBIPW_OFDM_RATE_6MB:
5254 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005255 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005256 case LIBIPW_OFDM_RATE_9MB:
5257 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005258 1 : 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005259 case LIBIPW_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005260 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005261 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5262 case LIBIPW_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005263 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005264 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5265 case LIBIPW_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005266 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005267 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5268 case LIBIPW_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005269 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005270 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5271 case LIBIPW_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005272 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005273 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5274 case LIBIPW_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005275 return priv->
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005276 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005277 default:
5278 return 0;
5279 }
5280 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005281
James Ketrenos43f66a62005-03-25 12:31:53 -06005282 /* B and G mixed */
5283 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005284 case LIBIPW_CCK_RATE_1MB:
5285 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5286 case LIBIPW_CCK_RATE_2MB:
5287 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5288 case LIBIPW_CCK_RATE_5MB:
5289 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5290 case LIBIPW_CCK_RATE_11MB:
5291 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005292 }
5293
5294 /* If we are limited to B modulations, bail at this point */
5295 if (ieee_mode == IEEE_B)
5296 return 0;
5297
5298 /* G */
5299 switch (rate) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005300 case LIBIPW_OFDM_RATE_6MB:
5301 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5302 case LIBIPW_OFDM_RATE_9MB:
5303 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5304 case LIBIPW_OFDM_RATE_12MB:
5305 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5306 case LIBIPW_OFDM_RATE_18MB:
5307 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5308 case LIBIPW_OFDM_RATE_24MB:
5309 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5310 case LIBIPW_OFDM_RATE_36MB:
5311 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5312 case LIBIPW_OFDM_RATE_48MB:
5313 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5314 case LIBIPW_OFDM_RATE_54MB:
5315 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005316 }
5317
5318 return 0;
5319}
5320
Jeff Garzikbf794512005-07-31 13:07:26 -04005321static int ipw_compatible_rates(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005322 const struct libipw_network *network,
James Ketrenos43f66a62005-03-25 12:31:53 -06005323 struct ipw_supported_rates *rates)
5324{
5325 int num_rates, i;
5326
5327 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005328 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005329 rates->num_rates = 0;
5330 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005331 if (!ipw_is_rate_in_mask(priv, network->mode,
5332 network->rates[i])) {
5333
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005334 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005335 IPW_DEBUG_SCAN("Adding masked mandatory "
5336 "rate %02X\n",
5337 network->rates[i]);
5338 rates->supported_rates[rates->num_rates++] =
5339 network->rates[i];
5340 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005341 }
5342
James Ketrenos43f66a62005-03-25 12:31:53 -06005343 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5344 network->rates[i], priv->rates_mask);
5345 continue;
5346 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005347
James Ketrenos43f66a62005-03-25 12:31:53 -06005348 rates->supported_rates[rates->num_rates++] = network->rates[i];
5349 }
5350
James Ketrenosa613bff2005-08-24 21:43:11 -05005351 num_rates = min(network->rates_ex_len,
5352 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005353 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005354 if (!ipw_is_rate_in_mask(priv, network->mode,
5355 network->rates_ex[i])) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005356 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005357 IPW_DEBUG_SCAN("Adding masked mandatory "
5358 "rate %02X\n",
5359 network->rates_ex[i]);
5360 rates->supported_rates[rates->num_rates++] =
5361 network->rates[i];
5362 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005363 }
5364
James Ketrenos43f66a62005-03-25 12:31:53 -06005365 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5366 network->rates_ex[i], priv->rates_mask);
5367 continue;
5368 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005369
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005370 rates->supported_rates[rates->num_rates++] =
5371 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005372 }
5373
James Ketrenosea2b26e2005-08-24 21:25:16 -05005374 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005375}
5376
Arjan van de Ven858119e2006-01-14 13:20:43 -08005377static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005378 const struct ipw_supported_rates *src)
5379{
5380 u8 i;
5381 for (i = 0; i < src->num_rates; i++)
5382 dest->supported_rates[i] = src->supported_rates[i];
5383 dest->num_rates = src->num_rates;
5384}
5385
5386/* TODO: Look at sniffed packets in the air to determine if the basic rate
5387 * mask should ever be used -- right now all callers to add the scan rates are
5388 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5389static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005390 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005391{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005392 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5393 LIBIPW_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005394
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005395 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005396 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005397 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005398
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005399 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005400 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005401 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005402
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005403 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005404 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005405 LIBIPW_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005406
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005407 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005408 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005409 LIBIPW_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005410}
5411
5412static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005413 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005414{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005415 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5416 LIBIPW_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005417
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005418 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005419 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005420 LIBIPW_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005421
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005422 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005423 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005424 LIBIPW_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005425
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005426 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005427 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005428 LIBIPW_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005429
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005430 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005431 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005432 LIBIPW_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005433
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005434 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005435 rates->supported_rates[rates->num_rates++] = basic_mask |
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005436 LIBIPW_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005437
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005438 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005439 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005440 LIBIPW_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005441
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005442 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005443 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005444 LIBIPW_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005445
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005446 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005447 rates->supported_rates[rates->num_rates++] =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005448 LIBIPW_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005449}
5450
5451struct ipw_network_match {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005452 struct libipw_network *network;
James Ketrenos43f66a62005-03-25 12:31:53 -06005453 struct ipw_supported_rates rates;
5454};
5455
James Ketrenosc848d0a2005-08-24 21:56:24 -05005456static int ipw_find_adhoc_network(struct ipw_priv *priv,
5457 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005458 struct libipw_network *network,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005459 int roaming)
5460{
5461 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005462 DECLARE_SSID_BUF(ssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005463
5464 /* Verify that this network's capability is compatible with the
5465 * current mode (AdHoc or Infrastructure) */
5466 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5467 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005468 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005469 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005470 print_ssid(ssid, network->ssid,
5471 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005472 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005473 return 0;
5474 }
5475
James Ketrenosc848d0a2005-08-24 21:56:24 -05005476 if (unlikely(roaming)) {
5477 /* If we are roaming, then ensure check if this is a valid
5478 * network to try and roam to */
5479 if ((network->ssid_len != match->network->ssid_len) ||
5480 memcmp(network->ssid, match->network->ssid,
5481 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005482 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005483 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005484 print_ssid(ssid, network->ssid,
5485 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005486 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005487 return 0;
5488 }
5489 } else {
5490 /* If an ESSID has been configured then compare the broadcast
5491 * ESSID to ours */
5492 if ((priv->config & CFG_STATIC_ESSID) &&
5493 ((network->ssid_len != priv->essid_len) ||
5494 memcmp(network->ssid, priv->essid,
5495 min(network->ssid_len, priv->essid_len)))) {
5496 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005497
James Ketrenosc848d0a2005-08-24 21:56:24 -05005498 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005499 print_ssid(ssid, network->ssid,
5500 network->ssid_len),
James Ketrenosc848d0a2005-08-24 21:56:24 -05005501 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005502 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005503 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005504 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005505 print_ssid(ssid, priv->essid,
5506 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005507 return 0;
5508 }
5509 }
5510
5511 /* If the old network rate is better than this one, don't bother
5512 * testing everything else. */
5513
5514 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005515 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5516 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005517 print_ssid(ssid, match->network->ssid,
5518 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005519 return 0;
5520 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005521 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5522 "current network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005523 print_ssid(ssid, match->network->ssid,
5524 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005525 return 0;
5526 }
5527
5528 /* Now go through and see if the requested network is valid... */
5529 if (priv->ieee->scan_age != 0 &&
5530 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005531 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005532 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005533 print_ssid(ssid, network->ssid,
5534 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005535 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005536 jiffies_to_msecs(jiffies -
5537 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005538 return 0;
5539 }
5540
5541 if ((priv->config & CFG_STATIC_CHANNEL) &&
5542 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005543 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005544 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005545 print_ssid(ssid, network->ssid,
5546 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005547 network->bssid,
James Ketrenosc848d0a2005-08-24 21:56:24 -05005548 network->channel, priv->channel);
5549 return 0;
5550 }
5551
5552 /* Verify privacy compatability */
5553 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5554 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005555 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005556 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005557 print_ssid(ssid, network->ssid,
5558 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005559 network->bssid,
James Ketrenosafbf30a2005-08-25 00:05:33 -05005560 priv->
5561 capability & CAP_PRIVACY_ON ? "on" : "off",
5562 network->
5563 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5564 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005565 return 0;
5566 }
5567
5568 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005569 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5570 "because of the same BSSID match: %pM"
John W. Linville9387b7c2008-09-30 20:59:05 -04005571 ".\n", print_ssid(ssid, network->ssid,
5572 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005573 network->bssid,
5574 priv->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005575 return 0;
5576 }
5577
5578 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005579 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005580 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005581 "because of invalid frequency/mode "
5582 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005583 print_ssid(ssid, network->ssid,
5584 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005585 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005586 return 0;
5587 }
5588
5589 /* Ensure that the rates supported by the driver are compatible with
5590 * this AP, including verification of basic rates (mandatory) */
5591 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005592 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005593 "because configured rate mask excludes "
5594 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005595 print_ssid(ssid, network->ssid,
5596 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005597 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005598 return 0;
5599 }
5600
5601 if (rates.num_rates == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07005602 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
James Ketrenosc848d0a2005-08-24 21:56:24 -05005603 "because of no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005604 print_ssid(ssid, network->ssid,
5605 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005606 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005607 return 0;
5608 }
5609
5610 /* TODO: Perform any further minimal comparititive tests. We do not
5611 * want to put too much policy logic here; intelligent scan selection
5612 * should occur within a generic IEEE 802.11 user space tool. */
5613
5614 /* Set up 'new' AP to this network */
5615 ipw_copy_rates(&match->rates, &rates);
5616 match->network = network;
Johannes Berge1749612008-10-27 15:59:26 -07005617 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005618 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005619 network->bssid);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005620
5621 return 1;
5622}
5623
David Howellsc4028952006-11-22 14:57:56 +00005624static void ipw_merge_adhoc_network(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05005625{
John W. Linville9387b7c2008-09-30 20:59:05 -04005626 DECLARE_SSID_BUF(ssid);
David Howellsc4028952006-11-22 14:57:56 +00005627 struct ipw_priv *priv =
5628 container_of(work, struct ipw_priv, merge_networks);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005629 struct libipw_network *network = NULL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005630 struct ipw_network_match match = {
5631 .network = priv->assoc_network
5632 };
5633
James Ketrenosafbf30a2005-08-25 00:05:33 -05005634 if ((priv->status & STATUS_ASSOCIATED) &&
5635 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005636 /* First pass through ROAM process -- look for a better
5637 * network */
5638 unsigned long flags;
5639
5640 spin_lock_irqsave(&priv->ieee->lock, flags);
5641 list_for_each_entry(network, &priv->ieee->network_list, list) {
5642 if (network != priv->assoc_network)
5643 ipw_find_adhoc_network(priv, &match, network,
5644 1);
5645 }
5646 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5647
5648 if (match.network == priv->assoc_network) {
5649 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5650 "merge to.\n");
5651 return;
5652 }
5653
Zhu Yi46441512006-01-24 16:37:59 +08005654 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005655 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5656 IPW_DEBUG_MERGE("remove network %s\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005657 print_ssid(ssid, priv->essid,
5658 priv->essid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005659 ipw_remove_current_network(priv);
5660 }
5661
5662 ipw_disassociate(priv);
5663 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005664 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005665 return;
5666 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005667}
5668
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005669static int ipw_best_network(struct ipw_priv *priv,
5670 struct ipw_network_match *match,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005671 struct libipw_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005672{
5673 struct ipw_supported_rates rates;
John W. Linville9387b7c2008-09-30 20:59:05 -04005674 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005675
5676 /* Verify that this network's capability is compatible with the
5677 * current mode (AdHoc or Infrastructure) */
5678 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005679 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005680 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5681 !(network->capability & WLAN_CAPABILITY_IBSS))) {
Johannes Berge1749612008-10-27 15:59:26 -07005682 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005683 "capability mismatch.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005684 print_ssid(ssid, network->ssid,
5685 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005686 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005687 return 0;
5688 }
5689
James Ketrenos43f66a62005-03-25 12:31:53 -06005690 if (unlikely(roaming)) {
5691 /* If we are roaming, then ensure check if this is a valid
5692 * network to try and roam to */
5693 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005694 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005695 network->ssid_len)) {
Johannes Berge1749612008-10-27 15:59:26 -07005696 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005697 "because of non-network ESSID.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005698 print_ssid(ssid, network->ssid,
5699 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005700 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005701 return 0;
5702 }
5703 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005704 /* If an ESSID has been configured then compare the broadcast
5705 * ESSID to ours */
5706 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005707 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005708 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005709 min(network->ssid_len, priv->essid_len)))) {
5710 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005711 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005712 print_ssid(ssid, network->ssid,
5713 network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005714 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005715 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005716 "because of ESSID mismatch: '%s'.\n",
Johannes Berge1749612008-10-27 15:59:26 -07005717 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005718 print_ssid(ssid, priv->essid,
5719 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005720 return 0;
5721 }
5722 }
5723
5724 /* If the old network rate is better than this one, don't bother
5725 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005726 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005728 strncpy(escaped,
John W. Linville9387b7c2008-09-30 20:59:05 -04005729 print_ssid(ssid, network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005730 sizeof(escaped));
Johannes Berge1749612008-10-27 15:59:26 -07005731 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5732 "'%s (%pM)' has a stronger signal.\n",
5733 escaped, network->bssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04005734 print_ssid(ssid, match->network->ssid,
5735 match->network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005736 match->network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005737 return 0;
5738 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005739
James Ketrenos43f66a62005-03-25 12:31:53 -06005740 /* If this network has already had an association attempt within the
5741 * last 3 seconds, do not try and associate again... */
5742 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005743 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
Johannes Berge1749612008-10-27 15:59:26 -07005744 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005745 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005746 "assoc attempt).\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005747 print_ssid(ssid, network->ssid,
5748 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005749 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005750 jiffies_to_msecs(jiffies -
5751 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005752 return 0;
5753 }
5754
5755 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005756 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005757 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
Johannes Berge1749612008-10-27 15:59:26 -07005758 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005759 "because of age: %ums.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005760 print_ssid(ssid, network->ssid,
5761 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005762 network->bssid,
Zhu Yi2638bc32006-01-24 16:37:52 +08005763 jiffies_to_msecs(jiffies -
5764 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005765 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005766 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005767
Jeff Garzikbf794512005-07-31 13:07:26 -04005768 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005769 (network->channel != priv->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005770 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005771 "because of channel mismatch: %d != %d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005772 print_ssid(ssid, network->ssid,
5773 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005774 network->bssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005775 network->channel, priv->channel);
5776 return 0;
5777 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005778
James Ketrenos43f66a62005-03-25 12:31:53 -06005779 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005780 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005781 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
Johannes Berge1749612008-10-27 15:59:26 -07005782 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005783 "because of privacy mismatch: %s != %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005784 print_ssid(ssid, network->ssid,
5785 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005786 network->bssid,
Jeff Garzikbf794512005-07-31 13:07:26 -04005787 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005788 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005789 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005790 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005791 return 0;
5792 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005793
5794 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005795 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07005796 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5797 "because of BSSID mismatch: %pM.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005798 print_ssid(ssid, network->ssid,
5799 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005800 network->bssid, priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005801 return 0;
5802 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005803
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 /* Filter out any incompatible freq / mode combinations */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005805 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
Johannes Berge1749612008-10-27 15:59:26 -07005806 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 "because of invalid frequency/mode "
5808 "combination.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005809 print_ssid(ssid, network->ssid,
5810 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005811 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005812 return 0;
5813 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005814
Liu Hong1fe0adb2005-08-19 09:33:10 -05005815 /* Filter out invalid channel in current GEO */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005816 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
Johannes Berge1749612008-10-27 15:59:26 -07005817 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
Liu Hong1fe0adb2005-08-19 09:33:10 -05005818 "because of invalid channel in current GEO\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005819 print_ssid(ssid, network->ssid,
5820 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005821 network->bssid);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005822 return 0;
5823 }
5824
James Ketrenosea2b26e2005-08-24 21:25:16 -05005825 /* Ensure that the rates supported by the driver are compatible with
5826 * this AP, including verification of basic rates (mandatory) */
5827 if (!ipw_compatible_rates(priv, network, &rates)) {
Johannes Berge1749612008-10-27 15:59:26 -07005828 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005829 "because configured rate mask excludes "
5830 "AP mandatory rate.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005831 print_ssid(ssid, network->ssid,
5832 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005833 network->bssid);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005834 return 0;
5835 }
5836
James Ketrenos43f66a62005-03-25 12:31:53 -06005837 if (rates.num_rates == 0) {
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 no compatible rates.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005840 print_ssid(ssid, network->ssid,
5841 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005842 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005843 return 0;
5844 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005845
James Ketrenos43f66a62005-03-25 12:31:53 -06005846 /* TODO: Perform any further minimal comparititive tests. We do not
5847 * want to put too much policy logic here; intelligent scan selection
5848 * should occur within a generic IEEE 802.11 user space tool. */
5849
5850 /* Set up 'new' AP to this network */
5851 ipw_copy_rates(&match->rates, &rates);
5852 match->network = network;
5853
Johannes Berge1749612008-10-27 15:59:26 -07005854 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005855 print_ssid(ssid, network->ssid, network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07005856 network->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06005857
5858 return 1;
5859}
5860
Jeff Garzikbf794512005-07-31 13:07:26 -04005861static void ipw_adhoc_create(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005862 struct libipw_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005863{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005864 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005865 int i;
5866
James Ketrenos43f66a62005-03-25 12:31:53 -06005867 /*
5868 * For the purposes of scanning, we can set our wireless mode
5869 * to trigger scans across combinations of bands, but when it
5870 * comes to creating a new ad-hoc network, we have tell the FW
5871 * exactly which band to use.
5872 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005873 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005874 * chossen band. Attempting to create a new ad-hoc network
5875 * with an invalid channel for wireless mode will trigger a
5876 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005877 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005879 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5880 case LIBIPW_52GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005881 network->mode = IEEE_A;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005882 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005883 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005884 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005885 IPW_WARNING("Overriding invalid channel\n");
5886 priv->channel = geo->a[0].channel;
5887 }
5888 break;
5889
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005890 case LIBIPW_24GHZ_BAND:
James Ketrenosafbf30a2005-08-25 00:05:33 -05005891 if (priv->ieee->mode & IEEE_G)
5892 network->mode = IEEE_G;
5893 else
5894 network->mode = IEEE_B;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005895 i = libipw_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005896 BUG_ON(i == -1);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04005897 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005898 IPW_WARNING("Overriding invalid channel\n");
5899 priv->channel = geo->bg[0].channel;
5900 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005901 break;
5902
5903 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005904 IPW_WARNING("Overriding invalid channel\n");
5905 if (priv->ieee->mode & IEEE_A) {
5906 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005907 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005908 } else if (priv->ieee->mode & IEEE_G) {
5909 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005910 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005911 } else {
5912 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005913 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005914 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005915 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005916 }
5917
5918 network->channel = priv->channel;
5919 priv->config |= CFG_ADHOC_PERSIST;
5920 ipw_create_bssid(priv, network->bssid);
5921 network->ssid_len = priv->essid_len;
5922 memcpy(network->ssid, priv->essid, priv->essid_len);
5923 memset(&network->stats, 0, sizeof(network->stats));
5924 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005925 if (!(priv->config & CFG_PREAMBLE_LONG))
5926 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005927 if (priv->capability & CAP_PRIVACY_ON)
5928 network->capability |= WLAN_CAPABILITY_PRIVACY;
5929 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005930 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005931 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005932 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005933 &priv->rates.supported_rates[network->rates_len],
5934 network->rates_ex_len);
5935 network->last_scanned = 0;
5936 network->flags = 0;
5937 network->last_associate = 0;
5938 network->time_stamp[0] = 0;
5939 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005940 network->beacon_interval = 100; /* Default */
5941 network->listen_interval = 10; /* Default */
5942 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005943 network->wpa_ie_len = 0;
5944 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005945}
5946
James Ketrenosb095c382005-08-24 22:04:42 -05005947static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5948{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005949 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005950
5951 if (!(priv->ieee->sec.flags & (1 << index)))
5952 return;
5953
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005954 key.key_id = index;
5955 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5956 key.security_type = type;
5957 key.station_index = 0; /* always 0 for BSS */
5958 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005959 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi851ca262006-08-21 11:37:58 +08005960 key.tx_counter[0] = cpu_to_le32(0);
5961 key.tx_counter[1] = cpu_to_le32(0);
James Ketrenosb095c382005-08-24 22:04:42 -05005962
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005963 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005964}
5965
5966static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005967{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005968 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005969 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005970
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005971 key.cmd_id = DINO_CMD_WEP_KEY;
5972 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005973
James Ketrenosb095c382005-08-24 22:04:42 -05005974 /* Note: AES keys cannot be set for multiple times.
5975 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005976 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005977 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005978 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005979 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005980 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005981 }
5982
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005983 key.key_size = priv->ieee->sec.key_sizes[i];
5984 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005985
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005986 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005987 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005988}
5989
Zhu Yi1fbfea52005-08-05 17:22:56 +08005990static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5991{
5992 if (priv->ieee->host_encrypt)
5993 return;
5994
5995 switch (level) {
5996 case SEC_LEVEL_3:
5997 priv->sys_config.disable_unicast_decryption = 0;
5998 priv->ieee->host_decrypt = 0;
5999 break;
6000 case SEC_LEVEL_2:
6001 priv->sys_config.disable_unicast_decryption = 1;
6002 priv->ieee->host_decrypt = 1;
6003 break;
6004 case SEC_LEVEL_1:
6005 priv->sys_config.disable_unicast_decryption = 0;
6006 priv->ieee->host_decrypt = 0;
6007 break;
6008 case SEC_LEVEL_0:
6009 priv->sys_config.disable_unicast_decryption = 1;
6010 break;
6011 default:
6012 break;
6013 }
6014}
6015
6016static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6017{
6018 if (priv->ieee->host_encrypt)
6019 return;
6020
6021 switch (level) {
6022 case SEC_LEVEL_3:
6023 priv->sys_config.disable_multicast_decryption = 0;
6024 break;
6025 case SEC_LEVEL_2:
6026 priv->sys_config.disable_multicast_decryption = 1;
6027 break;
6028 case SEC_LEVEL_1:
6029 priv->sys_config.disable_multicast_decryption = 0;
6030 break;
6031 case SEC_LEVEL_0:
6032 priv->sys_config.disable_multicast_decryption = 1;
6033 break;
6034 default:
6035 break;
6036 }
6037}
6038
James Ketrenosb095c382005-08-24 22:04:42 -05006039static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6040{
6041 switch (priv->ieee->sec.level) {
6042 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006043 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6044 ipw_send_tgi_tx_key(priv,
6045 DCT_FLAG_EXT_SECURITY_CCM,
6046 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006047
Hong Liu567deaf2005-08-31 18:07:22 +08006048 if (!priv->ieee->host_mc_decrypt)
6049 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05006050 break;
6051 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05006052 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6053 ipw_send_tgi_tx_key(priv,
6054 DCT_FLAG_EXT_SECURITY_TKIP,
6055 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05006056 break;
6057 case SEC_LEVEL_1:
6058 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05006059 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6060 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05006061 break;
6062 case SEC_LEVEL_0:
6063 default:
6064 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06006065 }
6066}
6067
6068static void ipw_adhoc_check(void *data)
6069{
6070 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04006071
James Ketrenosafbf30a2005-08-25 00:05:33 -05006072 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06006073 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006074 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6075 IPW_DL_STATE | IPW_DL_ASSOC,
6076 "Missed beacon: %d - disassociate\n",
6077 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06006078 ipw_remove_current_network(priv);
6079 ipw_disassociate(priv);
6080 return;
6081 }
6082
Jeff Garzikbf794512005-07-31 13:07:26 -04006083 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
Al Viro5b5e8072007-12-27 01:54:06 -05006084 le16_to_cpu(priv->assoc_request.beacon_interval));
James Ketrenos43f66a62005-03-25 12:31:53 -06006085}
6086
David Howellsc4028952006-11-22 14:57:56 +00006087static void ipw_bg_adhoc_check(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006088{
David Howellsc4028952006-11-22 14:57:56 +00006089 struct ipw_priv *priv =
6090 container_of(work, struct ipw_priv, adhoc_check.work);
Zhu Yi46441512006-01-24 16:37:59 +08006091 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006092 ipw_adhoc_check(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006093 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006094}
6095
James Ketrenos43f66a62005-03-25 12:31:53 -06006096static void ipw_debug_config(struct ipw_priv *priv)
6097{
John W. Linville9387b7c2008-09-30 20:59:05 -04006098 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006099 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6100 "[CFG 0x%08X]\n", priv->config);
6101 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006102 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006103 else
6104 IPW_DEBUG_INFO("Channel unlocked.\n");
6105 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04006106 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04006107 print_ssid(ssid, priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06006108 else
6109 IPW_DEBUG_INFO("ESSID unlocked.\n");
6110 if (priv->config & CFG_STATIC_BSSID)
Johannes Berge1749612008-10-27 15:59:26 -07006111 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06006112 else
6113 IPW_DEBUG_INFO("BSSID unlocked.\n");
6114 if (priv->capability & CAP_PRIVACY_ON)
6115 IPW_DEBUG_INFO("PRIVACY on\n");
6116 else
6117 IPW_DEBUG_INFO("PRIVACY off\n");
6118 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6119}
James Ketrenos43f66a62005-03-25 12:31:53 -06006120
Arjan van de Ven858119e2006-01-14 13:20:43 -08006121static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006122{
6123 /* TODO: Verify that this works... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07006124 struct ipw_fixed_rate fr;
James Ketrenos43f66a62005-03-25 12:31:53 -06006125 u32 reg;
6126 u16 mask = 0;
Reinette Chatre21f8a732009-08-18 10:25:05 -07006127 u16 new_tx_rates = priv->rates_mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006128
Jeff Garzikbf794512005-07-31 13:07:26 -04006129 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006130 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006131
James Ketrenos43f66a62005-03-25 12:31:53 -06006132 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006133 case LIBIPW_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006134 /* IEEE_A */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006135 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006136 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006137 IPW_DEBUG_WX
6138 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006139 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006140 break;
6141 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006142
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006143 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
James Ketrenos43f66a62005-03-25 12:31:53 -06006144 break;
6145
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006146 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006147 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006148 if (mode == IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006149 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006150 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006151 IPW_DEBUG_WX
6152 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006153 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006154 }
6155 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006156 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006157
6158 /* IEEE_G */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006159 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6160 LIBIPW_OFDM_RATES_MASK)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006161 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006162 IPW_DEBUG_WX
6163 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
Reinette Chatre21f8a732009-08-18 10:25:05 -07006164 new_tx_rates = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006165 break;
6166 }
6167
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006168 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6169 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6170 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006171 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006172
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006173 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6174 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6175 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006176 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006177
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006178 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6179 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6180 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06006181 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006182
Reinette Chatre21f8a732009-08-18 10:25:05 -07006183 new_tx_rates |= mask;
James Ketrenos43f66a62005-03-25 12:31:53 -06006184 break;
6185 }
6186
Reinette Chatre21f8a732009-08-18 10:25:05 -07006187 fr.tx_rates = cpu_to_le16(new_tx_rates);
6188
James Ketrenos43f66a62005-03-25 12:31:53 -06006189 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006190 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006191}
6192
James Ketrenosea2b26e2005-08-24 21:25:16 -05006193static void ipw_abort_scan(struct ipw_priv *priv)
6194{
6195 int err;
6196
6197 if (priv->status & STATUS_SCAN_ABORTING) {
6198 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6199 return;
6200 }
6201 priv->status |= STATUS_SCAN_ABORTING;
6202
6203 err = ipw_send_scan_abort(priv);
6204 if (err)
6205 IPW_DEBUG_HC("Request to abort scan failed.\n");
6206}
6207
James Ketrenosafbf30a2005-08-25 00:05:33 -05006208static void ipw_add_scan_channels(struct ipw_priv *priv,
6209 struct ipw_scan_request_ext *scan,
6210 int scan_type)
6211{
6212 int channel_index = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006213 const struct libipw_geo *geo;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006214 int i;
6215
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006216 geo = libipw_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006217
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006218 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006219 int start = channel_index;
6220 for (i = 0; i < geo->a_channels; i++) {
6221 if ((priv->status & STATUS_ASSOCIATED) &&
6222 geo->a[i].channel == priv->channel)
6223 continue;
6224 channel_index++;
6225 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006226 ipw_set_scan_type(scan, channel_index,
6227 geo->a[i].
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006228 flags & LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006229 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6230 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006231 }
6232
6233 if (start != channel_index) {
6234 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6235 (channel_index - start);
6236 channel_index++;
6237 }
6238 }
6239
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006240 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006241 int start = channel_index;
6242 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006243 int index;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006244 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006245 /* nop out the list */
6246 [0] = 0
6247 };
6248
6249 u8 channel;
Zhu Yi7dd24592009-07-27 10:10:20 +08006250 while (channel_index < IPW_SCAN_CHANNELS - 1) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006251 channel =
6252 priv->speed_scan[priv->speed_scan_pos];
6253 if (channel == 0) {
6254 priv->speed_scan_pos = 0;
6255 channel = priv->speed_scan[0];
6256 }
6257 if ((priv->status & STATUS_ASSOCIATED) &&
6258 channel == priv->channel) {
6259 priv->speed_scan_pos++;
6260 continue;
6261 }
6262
6263 /* If this channel has already been
6264 * added in scan, break from loop
6265 * and this will be the first channel
6266 * in the next scan.
6267 */
6268 if (channels[channel - 1] != 0)
6269 break;
6270
6271 channels[channel - 1] = 1;
6272 priv->speed_scan_pos++;
6273 channel_index++;
6274 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006275 index =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006276 libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006277 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006278 geo->bg[index].
6279 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006280 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006281 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6282 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006283 }
6284 } else {
6285 for (i = 0; i < geo->bg_channels; i++) {
6286 if ((priv->status & STATUS_ASSOCIATED) &&
6287 geo->bg[i].channel == priv->channel)
6288 continue;
6289 channel_index++;
6290 scan->channels_list[channel_index] =
6291 geo->bg[i].channel;
6292 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006293 geo->bg[i].
6294 flags &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006295 LIBIPW_CH_PASSIVE_ONLY ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05006296 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6297 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006298 }
6299 }
6300
6301 if (start != channel_index) {
6302 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6303 (channel_index - start);
6304 }
6305 }
6306}
6307
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006308static int ipw_passive_dwell_time(struct ipw_priv *priv)
6309{
6310 /* staying on passive channels longer than the DTIM interval during a
6311 * scan, while associated, causes the firmware to cancel the scan
6312 * without notification. Hence, don't stay on passive channels longer
6313 * than the beacon interval.
6314 */
6315 if (priv->status & STATUS_ASSOCIATED
6316 && priv->assoc_network->beacon_interval > 10)
6317 return priv->assoc_network->beacon_interval - 10;
6318 else
6319 return 120;
6320}
6321
Dan Williamsea177302008-06-02 17:51:23 -04006322static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
James Ketrenosea2b26e2005-08-24 21:25:16 -05006323{
6324 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006325 int err = 0, scan_type;
6326
6327 if (!(priv->status & STATUS_INIT) ||
6328 (priv->status & STATUS_EXIT_PENDING))
6329 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006330
Zhu Yi46441512006-01-24 16:37:59 +08006331 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006332
Dan Williamsea177302008-06-02 17:51:23 -04006333 if (direct && (priv->direct_scan_ssid_len == 0)) {
6334 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6335 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6336 goto done;
6337 }
6338
James Ketrenosea2b26e2005-08-24 21:25:16 -05006339 if (priv->status & STATUS_SCANNING) {
Dan Williamsea177302008-06-02 17:51:23 -04006340 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6341 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6342 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006343 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006344 }
6345
James Ketrenosafbf30a2005-08-25 00:05:33 -05006346 if (!(priv->status & STATUS_SCAN_FORCED) &&
6347 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006348 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
Dan Williamsea177302008-06-02 17:51:23 -04006349 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6350 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006351 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006352 }
6353
6354 if (priv->status & STATUS_RF_KILL_MASK) {
Dan Williamsea177302008-06-02 17:51:23 -04006355 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6356 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6357 STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006358 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006359 }
6360
6361 memset(&scan, 0, sizeof(scan));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006362 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006363
Zhu Yi094c4d22006-08-21 11:39:03 +08006364 if (type == IW_SCAN_TYPE_PASSIVE) {
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006365 IPW_DEBUG_WX("use passive scanning\n");
6366 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
Zhu Yi094c4d22006-08-21 11:39:03 +08006367 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006368 cpu_to_le16(ipw_passive_dwell_time(priv));
Zhu Yi094c4d22006-08-21 11:39:03 +08006369 ipw_add_scan_channels(priv, &scan, scan_type);
6370 goto send_request;
6371 }
6372
6373 /* Use active scan by default. */
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006374 if (priv->config & CFG_SPEED_SCAN)
James Ketrenosb095c382005-08-24 22:04:42 -05006375 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006376 cpu_to_le16(30);
James Ketrenosb095c382005-08-24 22:04:42 -05006377 else
6378 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006379 cpu_to_le16(20);
James Ketrenosb095c382005-08-24 22:04:42 -05006380
James Ketrenosa613bff2005-08-24 21:43:11 -05006381 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006382 cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006383
Helmut Schaa14a4dfe2008-12-10 13:17:26 +01006384 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6385 cpu_to_le16(ipw_passive_dwell_time(priv));
Dan Williamsea177302008-06-02 17:51:23 -04006386 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006387
James Ketrenosb095c382005-08-24 22:04:42 -05006388#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006389 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006390 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006391 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006392
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006393 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6394 case LIBIPW_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006396 channel = priv->channel;
6397 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006398
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006399 case LIBIPW_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006400 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006401 channel = priv->channel;
6402 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006403
James Ketrenosb095c382005-08-24 22:04:42 -05006404 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006405 band = (u8) (IPW_B_MODE << 6) | 1;
6406 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006407 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006408 }
6409
James Ketrenosb095c382005-08-24 22:04:42 -05006410 scan.channels_list[0] = band;
6411 scan.channels_list[1] = channel;
6412 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006413
James Ketrenosb095c382005-08-24 22:04:42 -05006414 /* NOTE: The card will sit on this channel for this time
6415 * period. Scan aborts are timing sensitive and frequently
6416 * result in firmware restarts. As such, it is best to
6417 * set a small dwell_time here and just keep re-issuing
6418 * scans. Otherwise fast channel hopping will not actually
6419 * hop channels.
6420 *
6421 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006422 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
Zhu Yi094c4d22006-08-21 11:39:03 +08006423 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006424 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006425#endif /* CONFIG_IPW2200_MONITOR */
Dan Williamsea177302008-06-02 17:51:23 -04006426 /* Honor direct scans first, otherwise if we are roaming make
6427 * this a direct scan for the current network. Finally,
6428 * ensure that every other scan is a fast channel hop scan */
6429 if (direct) {
6430 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6431 priv->direct_scan_ssid_len);
6432 if (err) {
6433 IPW_DEBUG_HC("Attempt to send SSID command "
6434 "failed\n");
6435 goto done;
6436 }
6437
6438 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6439 } else if ((priv->status & STATUS_ROAMING)
6440 || (!(priv->status & STATUS_ASSOCIATED)
6441 && (priv->config & CFG_STATIC_ESSID)
6442 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006443 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6444 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006445 IPW_DEBUG_HC("Attempt to send SSID command "
6446 "failed.\n");
6447 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006448 }
6449
6450 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006451 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006452 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006453
James Ketrenosafbf30a2005-08-25 00:05:33 -05006454 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006455#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006456 }
6457#endif
6458
Zhu Yi094c4d22006-08-21 11:39:03 +08006459send_request:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006460 err = ipw_send_scan_request_ext(priv, &scan);
6461 if (err) {
6462 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006463 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006464 }
6465
6466 priv->status |= STATUS_SCANNING;
Dan Williamsea177302008-06-02 17:51:23 -04006467 if (direct) {
6468 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6469 priv->direct_scan_ssid_len = 0;
6470 } else
6471 priv->status &= ~STATUS_SCAN_PENDING;
6472
James Ketrenosafbf30a2005-08-25 00:05:33 -05006473 queue_delayed_work(priv->workqueue, &priv->scan_check,
6474 IPW_SCAN_CHECK_WATCHDOG);
Zhu Yi094c4d22006-08-21 11:39:03 +08006475done:
Zhu Yi46441512006-01-24 16:37:59 +08006476 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006477 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006478}
6479
David Howellsc4028952006-11-22 14:57:56 +00006480static void ipw_request_passive_scan(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05006481{
David Howellsc4028952006-11-22 14:57:56 +00006482 struct ipw_priv *priv =
Dan Williamsea177302008-06-02 17:51:23 -04006483 container_of(work, struct ipw_priv, request_passive_scan.work);
6484 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
David Howellsc4028952006-11-22 14:57:56 +00006485}
6486
6487static void ipw_request_scan(struct work_struct *work)
6488{
6489 struct ipw_priv *priv =
6490 container_of(work, struct ipw_priv, request_scan.work);
Dan Williamsea177302008-06-02 17:51:23 -04006491 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6492}
6493
6494static void ipw_request_direct_scan(struct work_struct *work)
6495{
6496 struct ipw_priv *priv =
6497 container_of(work, struct ipw_priv, request_direct_scan.work);
6498 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
David Howellsc4028952006-11-22 14:57:56 +00006499}
6500
6501static void ipw_bg_abort_scan(struct work_struct *work)
6502{
6503 struct ipw_priv *priv =
6504 container_of(work, struct ipw_priv, abort_scan);
Zhu Yi46441512006-01-24 16:37:59 +08006505 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00006506 ipw_abort_scan(priv);
Zhu Yi46441512006-01-24 16:37:59 +08006507 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006508}
6509
James Ketrenosea2b26e2005-08-24 21:25:16 -05006510static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6511{
James Ketrenosb095c382005-08-24 22:04:42 -05006512 /* This is called when wpa_supplicant loads and closes the driver
6513 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006514 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006515 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006516}
6517
James Ketrenosea2b26e2005-08-24 21:25:16 -05006518static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6519{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006520 struct libipw_device *ieee = priv->ieee;
6521 struct libipw_security sec = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006522 .flags = SEC_AUTH_MODE,
6523 };
6524 int ret = 0;
6525
James Ketrenosafbf30a2005-08-25 00:05:33 -05006526 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006527 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6528 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006529 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006530 sec.auth_mode = WLAN_AUTH_OPEN;
6531 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006532 } else if (value & IW_AUTH_ALG_LEAP) {
6533 sec.auth_mode = WLAN_AUTH_LEAP;
6534 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006535 } else
6536 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006537
6538 if (ieee->set_security)
6539 ieee->set_security(ieee->dev, &sec);
6540 else
6541 ret = -EOPNOTSUPP;
6542
6543 return ret;
6544}
6545
Adrian Bunka73e22b2006-01-21 01:39:42 +01006546static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6547 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006548{
6549 /* make sure WPA is enabled */
6550 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006551}
6552
6553static int ipw_set_rsn_capa(struct ipw_priv *priv,
6554 char *capabilities, int length)
6555{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006556 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6557
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006558 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006559 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006560}
6561
James Ketrenosafbf30a2005-08-25 00:05:33 -05006562/*
6563 * WE-18 support
6564 */
6565
6566/* SIOCSIWGENIE */
6567static int ipw_wx_set_genie(struct net_device *dev,
6568 struct iw_request_info *info,
6569 union iwreq_data *wrqu, char *extra)
6570{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006571 struct ipw_priv *priv = libipw_priv(dev);
6572 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006573 u8 *buf;
6574 int err = 0;
6575
6576 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6577 (wrqu->data.length && extra == NULL))
6578 return -EINVAL;
6579
James Ketrenosafbf30a2005-08-25 00:05:33 -05006580 if (wrqu->data.length) {
6581 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6582 if (buf == NULL) {
6583 err = -ENOMEM;
6584 goto out;
6585 }
6586
6587 memcpy(buf, extra, wrqu->data.length);
6588 kfree(ieee->wpa_ie);
6589 ieee->wpa_ie = buf;
6590 ieee->wpa_ie_len = wrqu->data.length;
6591 } else {
6592 kfree(ieee->wpa_ie);
6593 ieee->wpa_ie = NULL;
6594 ieee->wpa_ie_len = 0;
6595 }
6596
6597 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6598 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006599 return err;
6600}
6601
6602/* SIOCGIWGENIE */
6603static int ipw_wx_get_genie(struct net_device *dev,
6604 struct iw_request_info *info,
6605 union iwreq_data *wrqu, char *extra)
6606{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006607 struct ipw_priv *priv = libipw_priv(dev);
6608 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006609 int err = 0;
6610
James Ketrenosafbf30a2005-08-25 00:05:33 -05006611 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6612 wrqu->data.length = 0;
6613 goto out;
6614 }
6615
6616 if (wrqu->data.length < ieee->wpa_ie_len) {
6617 err = -E2BIG;
6618 goto out;
6619 }
6620
6621 wrqu->data.length = ieee->wpa_ie_len;
6622 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6623
6624 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006625 return err;
6626}
6627
Zhu Yi1fbfea52005-08-05 17:22:56 +08006628static int wext_cipher2level(int cipher)
6629{
6630 switch (cipher) {
6631 case IW_AUTH_CIPHER_NONE:
6632 return SEC_LEVEL_0;
6633 case IW_AUTH_CIPHER_WEP40:
6634 case IW_AUTH_CIPHER_WEP104:
6635 return SEC_LEVEL_1;
6636 case IW_AUTH_CIPHER_TKIP:
6637 return SEC_LEVEL_2;
6638 case IW_AUTH_CIPHER_CCMP:
6639 return SEC_LEVEL_3;
6640 default:
6641 return -1;
6642 }
6643}
6644
James Ketrenosafbf30a2005-08-25 00:05:33 -05006645/* SIOCSIWAUTH */
6646static int ipw_wx_set_auth(struct net_device *dev,
6647 struct iw_request_info *info,
6648 union iwreq_data *wrqu, char *extra)
6649{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006650 struct ipw_priv *priv = libipw_priv(dev);
6651 struct libipw_device *ieee = priv->ieee;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006652 struct iw_param *param = &wrqu->param;
John W. Linville274bfb82008-10-29 11:35:05 -04006653 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006654 unsigned long flags;
6655 int ret = 0;
6656
6657 switch (param->flags & IW_AUTH_INDEX) {
6658 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006659 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006660 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006661 ipw_set_hw_decrypt_unicast(priv,
6662 wext_cipher2level(param->value));
6663 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006664 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006665 ipw_set_hw_decrypt_multicast(priv,
6666 wext_cipher2level(param->value));
6667 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006668 case IW_AUTH_KEY_MGMT:
6669 /*
6670 * ipw2200 does not use these parameters
6671 */
6672 break;
6673
6674 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006675 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006676 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006677 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006678
6679 flags = crypt->ops->get_flags(crypt->priv);
6680
6681 if (param->value)
6682 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6683 else
6684 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6685
6686 crypt->ops->set_flags(flags, crypt->priv);
6687
6688 break;
6689
6690 case IW_AUTH_DROP_UNENCRYPTED:{
6691 /* HACK:
6692 *
6693 * wpa_supplicant calls set_wpa_enabled when the driver
6694 * is loaded and unloaded, regardless of if WPA is being
6695 * used. No other calls are made which can be used to
6696 * determine if encryption will be used or not prior to
6697 * association being expected. If encryption is not being
6698 * used, drop_unencrypted is set to false, else true -- we
6699 * can use this to determine if the CAP_PRIVACY_ON bit should
6700 * be set.
6701 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006702 struct libipw_security sec = {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006703 .flags = SEC_ENABLED,
6704 .enabled = param->value,
6705 };
6706 priv->ieee->drop_unencrypted = param->value;
6707 /* We only change SEC_LEVEL for open mode. Others
6708 * are set by ipw_wpa_set_encryption.
6709 */
6710 if (!param->value) {
6711 sec.flags |= SEC_LEVEL;
6712 sec.level = SEC_LEVEL_0;
6713 } else {
6714 sec.flags |= SEC_LEVEL;
6715 sec.level = SEC_LEVEL_1;
6716 }
6717 if (priv->ieee->set_security)
6718 priv->ieee->set_security(priv->ieee->dev, &sec);
6719 break;
6720 }
6721
6722 case IW_AUTH_80211_AUTH_ALG:
6723 ret = ipw_wpa_set_auth_algs(priv, param->value);
6724 break;
6725
6726 case IW_AUTH_WPA_ENABLED:
6727 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006728 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006729 break;
6730
6731 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6732 ieee->ieee802_1x = param->value;
6733 break;
6734
James Ketrenosafbf30a2005-08-25 00:05:33 -05006735 case IW_AUTH_PRIVACY_INVOKED:
6736 ieee->privacy_invoked = param->value;
6737 break;
6738
6739 default:
6740 return -EOPNOTSUPP;
6741 }
6742 return ret;
6743}
6744
6745/* SIOCGIWAUTH */
6746static int ipw_wx_get_auth(struct net_device *dev,
6747 struct iw_request_info *info,
6748 union iwreq_data *wrqu, char *extra)
6749{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006750 struct ipw_priv *priv = libipw_priv(dev);
6751 struct libipw_device *ieee = priv->ieee;
John W. Linville274bfb82008-10-29 11:35:05 -04006752 struct lib80211_crypt_data *crypt;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006753 struct iw_param *param = &wrqu->param;
6754 int ret = 0;
6755
6756 switch (param->flags & IW_AUTH_INDEX) {
6757 case IW_AUTH_WPA_VERSION:
6758 case IW_AUTH_CIPHER_PAIRWISE:
6759 case IW_AUTH_CIPHER_GROUP:
6760 case IW_AUTH_KEY_MGMT:
6761 /*
6762 * wpa_supplicant will control these internally
6763 */
6764 ret = -EOPNOTSUPP;
6765 break;
6766
6767 case IW_AUTH_TKIP_COUNTERMEASURES:
John W. Linville274bfb82008-10-29 11:35:05 -04006768 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006769 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006770 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006771
6772 param->value = (crypt->ops->get_flags(crypt->priv) &
6773 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6774
6775 break;
6776
6777 case IW_AUTH_DROP_UNENCRYPTED:
6778 param->value = ieee->drop_unencrypted;
6779 break;
6780
6781 case IW_AUTH_80211_AUTH_ALG:
6782 param->value = ieee->sec.auth_mode;
6783 break;
6784
6785 case IW_AUTH_WPA_ENABLED:
6786 param->value = ieee->wpa_enabled;
6787 break;
6788
6789 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6790 param->value = ieee->ieee802_1x;
6791 break;
6792
6793 case IW_AUTH_ROAMING_CONTROL:
6794 case IW_AUTH_PRIVACY_INVOKED:
6795 param->value = ieee->privacy_invoked;
6796 break;
6797
6798 default:
6799 return -EOPNOTSUPP;
6800 }
6801 return 0;
6802}
6803
6804/* SIOCSIWENCODEEXT */
6805static int ipw_wx_set_encodeext(struct net_device *dev,
6806 struct iw_request_info *info,
6807 union iwreq_data *wrqu, char *extra)
6808{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006809 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006810 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6811
6812 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006813 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006814 /* IPW HW can't build TKIP MIC,
6815 host decryption still needed */
6816 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6817 priv->ieee->host_mc_decrypt = 1;
6818 else {
6819 priv->ieee->host_encrypt = 0;
6820 priv->ieee->host_encrypt_msdu = 1;
6821 priv->ieee->host_decrypt = 1;
6822 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006823 } else {
6824 priv->ieee->host_encrypt = 0;
6825 priv->ieee->host_encrypt_msdu = 0;
6826 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006827 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006828 }
6829 }
6830
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006831 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006832}
6833
6834/* SIOCGIWENCODEEXT */
6835static int ipw_wx_get_encodeext(struct net_device *dev,
6836 struct iw_request_info *info,
6837 union iwreq_data *wrqu, char *extra)
6838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006839 struct ipw_priv *priv = libipw_priv(dev);
6840 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006841}
6842
6843/* SIOCSIWMLME */
6844static int ipw_wx_set_mlme(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6847{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006848 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006849 struct iw_mlme *mlme = (struct iw_mlme *)extra;
Al Viroe62e1ee2007-12-27 01:36:46 -05006850 __le16 reason;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006851
6852 reason = cpu_to_le16(mlme->reason_code);
6853
6854 switch (mlme->cmd) {
6855 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006856 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006857 break;
6858
6859 case IW_MLME_DISASSOC:
6860 ipw_disassociate(priv);
6861 break;
6862
6863 default:
6864 return -EOPNOTSUPP;
6865 }
6866 return 0;
6867}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006868
Zhu Yie43e3c12006-04-13 17:20:45 +08006869#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006870
6871/* QoS */
6872/*
6873* get the modulation type of the current network or
6874* the card current mode
6875*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006876static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006877{
6878 u8 mode = 0;
6879
6880 if (priv->status & STATUS_ASSOCIATED) {
6881 unsigned long flags;
6882
6883 spin_lock_irqsave(&priv->ieee->lock, flags);
6884 mode = priv->assoc_network->mode;
6885 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6886 } else {
6887 mode = priv->ieee->mode;
6888 }
6889 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6890 return mode;
6891}
6892
6893/*
6894* Handle management frame beacon and probe response
6895*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006896static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6897 int active_network,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006898 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006899{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006900 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006901
James Ketrenosafbf30a2005-08-25 00:05:33 -05006902 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006903 network->qos_data.active = network->qos_data.supported;
6904
6905 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006906 if (active_network &&
6907 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006908 network->qos_data.active = network->qos_data.supported;
6909
6910 if ((network->qos_data.active == 1) && (active_network == 1) &&
6911 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6912 (network->qos_data.old_param_count !=
6913 network->qos_data.param_count)) {
6914 network->qos_data.old_param_count =
6915 network->qos_data.param_count;
6916 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006917 IPW_DEBUG_QOS("QoS parameters change call "
6918 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006919 }
6920 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006921 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6922 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006923 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006924 else
6925 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006926 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006927
James Ketrenosb095c382005-08-24 22:04:42 -05006928 if ((network->qos_data.active == 1) && (active_network == 1)) {
6929 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6930 schedule_work(&priv->qos_activate);
6931 }
6932
6933 network->qos_data.active = 0;
6934 network->qos_data.supported = 0;
6935 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006936 if ((priv->status & STATUS_ASSOCIATED) &&
6937 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6938 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
John W. Linvillec5d3dce2008-09-30 17:17:26 -04006939 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006940 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006941 priv->assoc_network->ssid_len) &&
6942 !memcmp(network->ssid,
6943 priv->assoc_network->ssid,
6944 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006945 queue_work(priv->workqueue,
6946 &priv->merge_networks);
6947 }
James Ketrenosb095c382005-08-24 22:04:42 -05006948 }
6949
6950 return 0;
6951}
6952
6953/*
6954* This function set up the firmware to support QoS. It sends
6955* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6956*/
6957static int ipw_qos_activate(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006958 struct libipw_qos_data *qos_network_data)
James Ketrenosb095c382005-08-24 22:04:42 -05006959{
6960 int err;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04006961 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6962 struct libipw_qos_parameters *active_one = NULL;
6963 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05006964 u32 burst_duration;
6965 int i;
6966 u8 type;
6967
6968 type = ipw_qos_current_mode(priv);
6969
6970 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6971 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6972 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6973 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6974
6975 if (qos_network_data == NULL) {
6976 if (type == IEEE_B) {
6977 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6978 active_one = &def_parameters_CCK;
6979 } else
6980 active_one = &def_parameters_OFDM;
6981
James Ketrenosafbf30a2005-08-25 00:05:33 -05006982 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006983 burst_duration = ipw_qos_get_burst_duration(priv);
6984 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006985 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
Al Viro8fffc152007-12-27 01:25:40 -05006986 cpu_to_le16(burst_duration);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006987 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006988 if (type == IEEE_B) {
6989 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6990 type);
6991 if (priv->qos_data.qos_enable == 0)
6992 active_one = &def_parameters_CCK;
6993 else
6994 active_one = priv->qos_data.def_qos_parm_CCK;
6995 } else {
6996 if (priv->qos_data.qos_enable == 0)
6997 active_one = &def_parameters_OFDM;
6998 else
6999 active_one = priv->qos_data.def_qos_parm_OFDM;
7000 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007001 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007002 } else {
7003 unsigned long flags;
7004 int active;
7005
7006 spin_lock_irqsave(&priv->ieee->lock, flags);
7007 active_one = &(qos_network_data->parameters);
7008 qos_network_data->old_param_count =
7009 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007010 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007011 active = qos_network_data->supported;
7012 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7013
7014 if (active == 0) {
7015 burst_duration = ipw_qos_get_burst_duration(priv);
7016 for (i = 0; i < QOS_QUEUE_NUM; i++)
7017 qos_parameters[QOS_PARAM_SET_ACTIVE].
Al Viro8fffc152007-12-27 01:25:40 -05007018 tx_op_limit[i] = cpu_to_le16(burst_duration);
James Ketrenosb095c382005-08-24 22:04:42 -05007019 }
7020 }
7021
7022 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007023 err = ipw_send_qos_params_command(priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007024 (struct libipw_qos_parameters *)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007025 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007026 if (err)
7027 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7028
7029 return err;
7030}
7031
7032/*
7033* send IPW_CMD_WME_INFO to the firmware
7034*/
7035static int ipw_qos_set_info_element(struct ipw_priv *priv)
7036{
7037 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007038 struct libipw_qos_information_element qos_info;
James Ketrenosb095c382005-08-24 22:04:42 -05007039
7040 if (priv == NULL)
7041 return -1;
7042
7043 qos_info.elementID = QOS_ELEMENT_ID;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007044 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenosb095c382005-08-24 22:04:42 -05007045
7046 qos_info.version = QOS_VERSION_1;
7047 qos_info.ac_info = 0;
7048
7049 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7050 qos_info.qui_type = QOS_OUI_TYPE;
7051 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7052
7053 ret = ipw_send_qos_info_command(priv, &qos_info);
7054 if (ret != 0) {
7055 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7056 }
7057 return ret;
7058}
7059
7060/*
7061* Set the QoS parameter with the association request structure
7062*/
7063static int ipw_qos_association(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007064 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007065{
7066 int err = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007067 struct libipw_qos_data *qos_data = NULL;
7068 struct libipw_qos_data ibss_data = {
James Ketrenosb095c382005-08-24 22:04:42 -05007069 .supported = 1,
7070 .active = 1,
7071 };
7072
7073 switch (priv->ieee->iw_mode) {
7074 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02007075 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05007076
7077 qos_data = &ibss_data;
7078 break;
7079
7080 case IW_MODE_INFRA:
7081 qos_data = &network->qos_data;
7082 break;
7083
7084 default:
7085 BUG();
7086 break;
7087 }
7088
7089 err = ipw_qos_activate(priv, qos_data);
7090 if (err) {
7091 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7092 return err;
7093 }
7094
7095 if (priv->qos_data.qos_enable && qos_data->supported) {
7096 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7097 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7098 return ipw_qos_set_info_element(priv);
7099 }
7100
7101 return 0;
7102}
7103
7104/*
Matt LaPlante0779bf22006-11-30 05:24:39 +01007105* handling the beaconing responses. if we get different QoS setting
7106* off the network from the associated setting, adjust the QoS
James Ketrenosb095c382005-08-24 22:04:42 -05007107* setting
7108*/
7109static int ipw_qos_association_resp(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007110 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007111{
7112 int ret = 0;
7113 unsigned long flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007114 u32 size = sizeof(struct libipw_qos_parameters);
James Ketrenosb095c382005-08-24 22:04:42 -05007115 int set_qos_param = 0;
7116
James Ketrenosafbf30a2005-08-25 00:05:33 -05007117 if ((priv == NULL) || (network == NULL) ||
7118 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007119 return ret;
7120
7121 if (!(priv->status & STATUS_ASSOCIATED))
7122 return ret;
7123
James Ketrenosafbf30a2005-08-25 00:05:33 -05007124 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007125 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007126
7127 spin_lock_irqsave(&priv->ieee->lock, flags);
7128 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007129 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007130 sizeof(struct libipw_qos_data));
James Ketrenosb095c382005-08-24 22:04:42 -05007131 priv->assoc_network->qos_data.active = 1;
7132 if ((network->qos_data.old_param_count !=
7133 network->qos_data.param_count)) {
7134 set_qos_param = 1;
7135 network->qos_data.old_param_count =
7136 network->qos_data.param_count;
7137 }
7138
7139 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007140 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7141 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007142 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007143 else
7144 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007145 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007146 priv->assoc_network->qos_data.active = 0;
7147 priv->assoc_network->qos_data.supported = 0;
7148 set_qos_param = 1;
7149 }
7150
7151 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7152
7153 if (set_qos_param == 1)
7154 schedule_work(&priv->qos_activate);
7155
7156 return ret;
7157}
7158
7159static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7160{
7161 u32 ret = 0;
7162
7163 if ((priv == NULL))
7164 return 0;
7165
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007166 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007167 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007168 else
James Ketrenosb095c382005-08-24 22:04:42 -05007169 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007170
James Ketrenosb095c382005-08-24 22:04:42 -05007171 return ret;
7172}
7173
7174/*
7175* Initialize the setting of QoS global
7176*/
7177static void ipw_qos_init(struct ipw_priv *priv, int enable,
7178 int burst_enable, u32 burst_duration_CCK,
7179 u32 burst_duration_OFDM)
7180{
7181 priv->qos_data.qos_enable = enable;
7182
7183 if (priv->qos_data.qos_enable) {
7184 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7185 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7186 IPW_DEBUG_QOS("QoS is enabled\n");
7187 } else {
7188 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7189 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7190 IPW_DEBUG_QOS("QoS is not enabled\n");
7191 }
7192
7193 priv->qos_data.burst_enable = burst_enable;
7194
7195 if (burst_enable) {
7196 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7197 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7198 } else {
7199 priv->qos_data.burst_duration_CCK = 0;
7200 priv->qos_data.burst_duration_OFDM = 0;
7201 }
7202}
7203
7204/*
7205* map the packet priority to the right TX Queue
7206*/
7207static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7208{
7209 if (priority > 7 || !priv->qos_data.qos_enable)
7210 priority = 0;
7211
7212 return from_priority_to_tx_queue[priority] - 1;
7213}
7214
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007215static int ipw_is_qos_active(struct net_device *dev,
7216 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007217{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007218 struct ipw_priv *priv = libipw_priv(dev);
7219 struct libipw_qos_data *qos_data = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007220 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007221 u8 *daddr = skb->data + ETH_ALEN;
7222 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007223
7224 if (!(priv->status & STATUS_ASSOCIATED))
7225 return 0;
7226
7227 qos_data = &priv->assoc_network->qos_data;
7228
James Ketrenosb095c382005-08-24 22:04:42 -05007229 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7230 if (unicast == 0)
7231 qos_data->active = 0;
7232 else
7233 qos_data->active = qos_data->supported;
7234 }
James Ketrenosb095c382005-08-24 22:04:42 -05007235 active = qos_data->active;
7236 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007237 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7238 "unicast %d\n",
7239 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007240 if (active && priv->qos_data.qos_enable)
7241 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007242
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007243 return 0;
7244
7245}
7246/*
7247* add QoS parameter to the TX command
7248*/
7249static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7250 u16 priority,
7251 struct tfd_data *tfd)
7252{
7253 int tx_queue_id = 0;
7254
7255
7256 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7257 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7258
7259 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7260 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
Zhu Yi851ca262006-08-21 11:37:58 +08007261 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
James Ketrenosb095c382005-08-24 22:04:42 -05007262 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007263 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007264}
7265
7266/*
7267* background support to run QoS activate functionality
7268*/
David Howellsc4028952006-11-22 14:57:56 +00007269static void ipw_bg_qos_activate(struct work_struct *work)
James Ketrenosb095c382005-08-24 22:04:42 -05007270{
David Howellsc4028952006-11-22 14:57:56 +00007271 struct ipw_priv *priv =
7272 container_of(work, struct ipw_priv, qos_activate);
James Ketrenosb095c382005-08-24 22:04:42 -05007273
Zhu Yi46441512006-01-24 16:37:59 +08007274 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007275
7276 if (priv->status & STATUS_ASSOCIATED)
7277 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7278
Zhu Yi46441512006-01-24 16:37:59 +08007279 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007280}
7281
James Ketrenos3b9990c2005-08-19 13:18:55 -05007282static int ipw_handle_probe_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007283 struct libipw_probe_response *resp,
7284 struct libipw_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007285{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007286 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007287 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7288 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007289
James Ketrenos3b9990c2005-08-19 13:18:55 -05007290 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007291
James Ketrenos3b9990c2005-08-19 13:18:55 -05007292 return 0;
7293}
James Ketrenosb095c382005-08-24 22:04:42 -05007294
James Ketrenos3b9990c2005-08-19 13:18:55 -05007295static int ipw_handle_beacon(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007296 struct libipw_beacon *resp,
7297 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007298{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007299 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007300 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7301 (network == priv->assoc_network));
7302
7303 ipw_qos_handle_probe_response(priv, active_network, network);
7304
7305 return 0;
7306}
7307
7308static int ipw_handle_assoc_response(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007309 struct libipw_assoc_response *resp,
7310 struct libipw_network *network)
James Ketrenos3b9990c2005-08-19 13:18:55 -05007311{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007312 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007313 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007314 return 0;
7315}
7316
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007317static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
James Ketrenosb095c382005-08-24 22:04:42 -05007318 *qos_param)
7319{
Zhu Yi4e226992006-01-24 16:37:36 +08007320 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7321 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007322}
7323
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007324static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
James Ketrenosb095c382005-08-24 22:04:42 -05007325 *qos_param)
7326{
Zhu Yi4e226992006-01-24 16:37:36 +08007327 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7328 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007329}
7330
Zhu Yie43e3c12006-04-13 17:20:45 +08007331#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007332
James Ketrenos43f66a62005-03-25 12:31:53 -06007333static int ipw_associate_network(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007334 struct libipw_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007335 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007336{
7337 int err;
John W. Linville9387b7c2008-09-30 20:59:05 -04007338 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007339
7340 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007341 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007342
7343 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007344 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007345 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007346 memcpy(priv->essid, network->ssid, priv->essid_len);
7347 }
7348
7349 network->last_associate = jiffies;
7350
7351 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7352 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007353 priv->assoc_request.auth_key = 0;
7354
James Ketrenos43f66a62005-03-25 12:31:53 -06007355 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007356 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007357 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007358 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7359
Zhu Yi1ba61e02006-02-15 13:00:55 +08007360 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007361 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007362
7363 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7364 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7365 priv->assoc_request.auth_type = AUTH_LEAP;
7366 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007367 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007368
James Ketrenosa613bff2005-08-24 21:43:11 -05007369 if (priv->ieee->wpa_ie_len) {
Al Viro5b5e8072007-12-27 01:54:06 -05007370 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
James Ketrenosea2b26e2005-08-24 21:25:16 -05007371 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7372 priv->ieee->wpa_ie_len);
7373 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007374
Jeff Garzikbf794512005-07-31 13:07:26 -04007375 /*
7376 * It is valid for our ieee device to support multiple modes, but
7377 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007378 * just one mode.
7379 */
7380 if (network->mode & priv->ieee->mode & IEEE_A)
7381 priv->assoc_request.ieee_mode = IPW_A_MODE;
7382 else if (network->mode & priv->ieee->mode & IEEE_G)
7383 priv->assoc_request.ieee_mode = IPW_G_MODE;
7384 else if (network->mode & priv->ieee->mode & IEEE_B)
7385 priv->assoc_request.ieee_mode = IPW_B_MODE;
7386
Al Viro5b5e8072007-12-27 01:54:06 -05007387 priv->assoc_request.capability = cpu_to_le16(network->capability);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007388 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7389 && !(priv->config & CFG_PREAMBLE_LONG)) {
7390 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7391 } else {
7392 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7393
7394 /* Clear the short preamble if we won't be supporting it */
7395 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007396 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007397 }
7398
James Ketrenosafbf30a2005-08-25 00:05:33 -05007399 /* Clear capability bits that aren't used in Ad Hoc */
7400 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7401 priv->assoc_request.capability &=
Al Viro5b5e8072007-12-27 01:54:06 -05007402 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007403
James Ketrenos43f66a62005-03-25 12:31:53 -06007404 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007405 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007406 roaming ? "Rea" : "A",
John W. Linville9387b7c2008-09-30 20:59:05 -04007407 print_ssid(ssid, priv->essid, priv->essid_len),
Jeff Garzikbf794512005-07-31 13:07:26 -04007408 network->channel,
7409 ipw_modes[priv->assoc_request.ieee_mode],
7410 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007411 (priv->assoc_request.preamble_length ==
7412 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7413 network->capability &
7414 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007415 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007416 priv->capability & CAP_PRIVACY_ON ?
7417 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007418 "(open)") : "",
7419 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007420 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007421 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007422 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007423
Al Viro5b5e8072007-12-27 01:54:06 -05007424 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
James Ketrenos43f66a62005-03-25 12:31:53 -06007425 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007426 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007427 priv->assoc_request.assoc_type = HC_IBSS_START;
7428 priv->assoc_request.assoc_tsf_msw = 0;
7429 priv->assoc_request.assoc_tsf_lsw = 0;
7430 } else {
7431 if (unlikely(roaming))
7432 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7433 else
7434 priv->assoc_request.assoc_type = HC_ASSOCIATE;
Al Viro5b5e8072007-12-27 01:54:06 -05007435 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7436 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007437 }
7438
James Ketrenosafbf30a2005-08-25 00:05:33 -05007439 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007440
7441 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7442 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
Al Viro5b5e8072007-12-27 01:54:06 -05007443 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
James Ketrenos43f66a62005-03-25 12:31:53 -06007444 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007445 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007446 priv->assoc_request.atim_window = 0;
7447 }
7448
Al Viro5b5e8072007-12-27 01:54:06 -05007449 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
Jeff Garzikbf794512005-07-31 13:07:26 -04007450
James Ketrenos43f66a62005-03-25 12:31:53 -06007451 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7452 if (err) {
7453 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7454 return err;
7455 }
7456
7457 rates->ieee_mode = priv->assoc_request.ieee_mode;
7458 rates->purpose = IPW_RATE_CONNECT;
7459 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007460
James Ketrenos43f66a62005-03-25 12:31:53 -06007461 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7462 priv->sys_config.dot11g_auto_detection = 1;
7463 else
7464 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007465
7466 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7467 priv->sys_config.answer_broadcast_ssid_probe = 1;
7468 else
7469 priv->sys_config.answer_broadcast_ssid_probe = 0;
7470
Zhu Yid685b8c2006-04-13 17:20:27 +08007471 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007472 if (err) {
7473 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7474 return err;
7475 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007476
James Ketrenos43f66a62005-03-25 12:31:53 -06007477 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007478 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007479 if (err) {
7480 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7481 return err;
7482 }
7483
7484 /*
7485 * If preemption is enabled, it is possible for the association
7486 * to complete before we return from ipw_send_associate. Therefore
7487 * we have to be sure and update our priviate data first.
7488 */
7489 priv->channel = network->channel;
7490 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007491 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007492 priv->status &= ~STATUS_SECURITY_UPDATED;
7493
7494 priv->assoc_network = network;
7495
Zhu Yie43e3c12006-04-13 17:20:45 +08007496#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007497 ipw_qos_association(priv, network);
7498#endif
7499
James Ketrenos43f66a62005-03-25 12:31:53 -06007500 err = ipw_send_associate(priv, &priv->assoc_request);
7501 if (err) {
7502 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7503 return err;
7504 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007505
Johannes Berge1749612008-10-27 15:59:26 -07007506 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007507 print_ssid(ssid, priv->essid, priv->essid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007508 priv->bssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007509
7510 return 0;
7511}
7512
7513static void ipw_roam(void *data)
7514{
7515 struct ipw_priv *priv = data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007516 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007517 struct ipw_network_match match = {
7518 .network = priv->assoc_network
7519 };
7520
7521 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007522 *
7523 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007524 * setting the status ROAM bit and requesting a scan.
7525 * 2. When the scan completes, it schedules the ROAM work
7526 * 3. The ROAM work looks at all of the known networks for one that
7527 * is a better network than the currently associated. If none
7528 * found, the ROAM process is over (ROAM bit cleared)
7529 * 4. If a better network is found, a disassociation request is
7530 * sent.
7531 * 5. When the disassociation completes, the roam work is again
7532 * scheduled. The second time through, the driver is no longer
7533 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007534 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007535 * 6. At this point ,the roaming process is complete and the ROAM
7536 * status bit is cleared.
7537 */
7538
7539 /* If we are no longer associated, and the roaming bit is no longer
7540 * set, then we are not actively roaming, so just return */
7541 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7542 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007543
James Ketrenos43f66a62005-03-25 12:31:53 -06007544 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007545 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007547 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007548 u8 rssi = priv->assoc_network->stats.rssi;
7549 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007550 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007551 list_for_each_entry(network, &priv->ieee->network_list, list) {
7552 if (network != priv->assoc_network)
7553 ipw_best_network(priv, &match, network, 1);
7554 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007555 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007557
James Ketrenos43f66a62005-03-25 12:31:53 -06007558 if (match.network == priv->assoc_network) {
7559 IPW_DEBUG_ASSOC("No better APs in this network to "
7560 "roam to.\n");
7561 priv->status &= ~STATUS_ROAMING;
7562 ipw_debug_config(priv);
7563 return;
7564 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007565
James Ketrenos43f66a62005-03-25 12:31:53 -06007566 ipw_send_disassociate(priv, 1);
7567 priv->assoc_network = match.network;
7568
7569 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007570 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007571
7572 /* Second pass through ROAM process -- request association */
7573 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7574 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7575 priv->status &= ~STATUS_ROAMING;
7576}
7577
David Howellsc4028952006-11-22 14:57:56 +00007578static void ipw_bg_roam(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -05007579{
David Howellsc4028952006-11-22 14:57:56 +00007580 struct ipw_priv *priv =
7581 container_of(work, struct ipw_priv, roam);
Zhu Yi46441512006-01-24 16:37:59 +08007582 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007583 ipw_roam(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007584 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007585}
7586
7587static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007588{
7589 struct ipw_priv *priv = data;
7590
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007591 struct libipw_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06007592 struct ipw_network_match match = {
7593 .network = NULL
7594 };
7595 struct ipw_supported_rates *rates;
7596 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007597 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04007598 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06007599
James Ketrenosb095c382005-08-24 22:04:42 -05007600 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7601 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7602 return 0;
7603 }
7604
James Ketrenosc848d0a2005-08-24 21:56:24 -05007605 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007606 IPW_DEBUG_ASSOC("Not attempting association (already in "
7607 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007608 return 0;
7609 }
7610
Hong Liue6324722005-09-14 21:04:15 -05007611 if (priv->status & STATUS_DISASSOCIATING) {
7612 IPW_DEBUG_ASSOC("Not attempting association (in "
7613 "disassociating)\n ");
7614 queue_work(priv->workqueue, &priv->associate);
7615 return 0;
7616 }
7617
James Ketrenosc848d0a2005-08-24 21:56:24 -05007618 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007619 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7620 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007621 return 0;
7622 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007623
7624 if (!(priv->config & CFG_ASSOCIATE) &&
Alexey Fisher3e4127f2008-11-06 09:51:16 +01007625 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007626 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007627 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007628 }
7629
James Ketrenosa613bff2005-08-24 21:43:11 -05007630 /* Protect our use of the network_list */
7631 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007632 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007633 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007634
7635 network = match.network;
7636 rates = &match.rates;
7637
7638 if (network == NULL &&
7639 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7640 priv->config & CFG_ADHOC_CREATE &&
7641 priv->config & CFG_STATIC_ESSID &&
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007642 priv->config & CFG_STATIC_CHANNEL) {
7643 /* Use oldest network if the free list is empty */
7644 if (list_empty(&priv->ieee->network_free_list)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007645 struct libipw_network *oldest = NULL;
7646 struct libipw_network *target;
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007647
7648 list_for_each_entry(target, &priv->ieee->network_list, list) {
7649 if ((oldest == NULL) ||
7650 (target->last_scanned < oldest->last_scanned))
7651 oldest = target;
7652 }
7653
7654 /* If there are no more slots, expire the oldest */
7655 list_del(&oldest->list);
7656 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07007657 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007658 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04007659 print_ssid(ssid, target->ssid,
7660 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07007661 target->bssid);
Dan Williamsa6d4eae2008-05-29 14:38:28 -04007662 list_add_tail(&target->list,
7663 &priv->ieee->network_free_list);
7664 }
7665
James Ketrenos43f66a62005-03-25 12:31:53 -06007666 element = priv->ieee->network_free_list.next;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007667 network = list_entry(element, struct libipw_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007668 ipw_adhoc_create(priv, network);
7669 rates = &priv->rates;
7670 list_del(element);
7671 list_add_tail(&network->list, &priv->ieee->network_list);
7672 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007673 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007674
James Ketrenos43f66a62005-03-25 12:31:53 -06007675 /* If we reached the end of the list, then we don't have any valid
7676 * matching APs */
7677 if (!network) {
7678 ipw_debug_config(priv);
7679
James Ketrenosb095c382005-08-24 22:04:42 -05007680 if (!(priv->status & STATUS_SCANNING)) {
7681 if (!(priv->config & CFG_SPEED_SCAN))
7682 queue_delayed_work(priv->workqueue,
7683 &priv->request_scan,
7684 SCAN_INTERVAL);
7685 else
David Howellsc4028952006-11-22 14:57:56 +00007686 queue_delayed_work(priv->workqueue,
7687 &priv->request_scan, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05007688 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007689
James Ketrenosc848d0a2005-08-24 21:56:24 -05007690 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007691 }
7692
7693 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007694
7695 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007696}
Jeff Garzikbf794512005-07-31 13:07:26 -04007697
David Howellsc4028952006-11-22 14:57:56 +00007698static void ipw_bg_associate(struct work_struct *work)
James Ketrenos43f66a62005-03-25 12:31:53 -06007699{
David Howellsc4028952006-11-22 14:57:56 +00007700 struct ipw_priv *priv =
7701 container_of(work, struct ipw_priv, associate);
Zhu Yi46441512006-01-24 16:37:59 +08007702 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +00007703 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08007704 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007705}
7706
James Ketrenosb095c382005-08-24 22:04:42 -05007707static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7708 struct sk_buff *skb)
7709{
7710 struct ieee80211_hdr *hdr;
7711 u16 fc;
7712
7713 hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -04007714 fc = le16_to_cpu(hdr->frame_control);
James Ketrenosb095c382005-08-24 22:04:42 -05007715 if (!(fc & IEEE80211_FCTL_PROTECTED))
7716 return;
7717
7718 fc &= ~IEEE80211_FCTL_PROTECTED;
John W. Linville72118012008-09-30 21:43:03 -04007719 hdr->frame_control = cpu_to_le16(fc);
James Ketrenosb095c382005-08-24 22:04:42 -05007720 switch (priv->ieee->sec.level) {
7721 case SEC_LEVEL_3:
7722 /* Remove CCMP HDR */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007723 memmove(skb->data + LIBIPW_3ADDR_LEN,
7724 skb->data + LIBIPW_3ADDR_LEN + 8,
7725 skb->len - LIBIPW_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007726 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007727 break;
7728 case SEC_LEVEL_2:
7729 break;
7730 case SEC_LEVEL_1:
7731 /* Remove IV */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007732 memmove(skb->data + LIBIPW_3ADDR_LEN,
7733 skb->data + LIBIPW_3ADDR_LEN + 4,
7734 skb->len - LIBIPW_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007735 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007736 break;
7737 case SEC_LEVEL_0:
7738 break;
7739 default:
7740 printk(KERN_ERR "Unknow security level %d\n",
7741 priv->ieee->sec.level);
7742 break;
7743 }
7744}
7745
7746static void ipw_handle_data_packet(struct ipw_priv *priv,
7747 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007748 struct libipw_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007749{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007750 struct net_device *dev = priv->net_dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007751 struct libipw_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007752 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7753
7754 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007755 dev->trans_start = jiffies;
James Ketrenos43f66a62005-03-25 12:31:53 -06007756
Jeff Garzikbf794512005-07-31 13:07:26 -04007757 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007758 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007759 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007760 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007761 dev->stats.rx_errors++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007762 priv->wstats.discard.misc++;
7763 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7764 return;
7765 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007766 dev->stats.rx_dropped++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007767 priv->wstats.discard.misc++;
7768 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7769 return;
7770 }
7771
7772 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007773 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007774
7775 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007776 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007777
7778 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7779
James Ketrenosb095c382005-08-24 22:04:42 -05007780 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007781 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
Hong Liu567deaf2005-08-31 18:07:22 +08007782 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007783 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007784 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007785 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7786
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007787 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007788 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007789 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007790 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007791 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007792 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007793}
7794
Zhu Yi459d4082006-04-13 17:21:00 +08007795#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007796static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7797 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007798 struct libipw_rx_stats *stats)
Mike Kershaw24a47db2005-08-26 00:41:54 -05007799{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007800 struct net_device *dev = priv->net_dev;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007801 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7802 struct ipw_rx_frame *frame = &pkt->u.frame;
7803
7804 /* initial pull of some data */
7805 u16 received_channel = frame->received_channel;
7806 u8 antennaAndPhy = frame->antennaAndPhy;
7807 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7808 u16 pktrate = frame->rate;
7809
7810 /* Magic struct that slots into the radiotap header -- no reason
7811 * to build this manually element by element, we can write it much
7812 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007813 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007814
7815 short len = le16_to_cpu(pkt->u.frame.length);
7816
7817 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007818 dev->trans_start = jiffies;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007819
7820 /* We only process data packets if the
7821 * interface is open */
7822 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7823 skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007824 dev->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007825 priv->wstats.discard.misc++;
7826 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7827 return;
7828 } else if (unlikely(!netif_running(priv->net_dev))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007829 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007830 priv->wstats.discard.misc++;
7831 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7832 return;
7833 }
7834
7835 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7836 * that now */
7837 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7838 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007839 dev->stats.rx_dropped++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007840 priv->wstats.discard.misc++;
7841 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7842 return;
7843 }
7844
7845 /* copy the frame itself */
7846 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7847 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7848
Mike Kershaw24a47db2005-08-26 00:41:54 -05007849 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7850
7851 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7852 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05007853 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
Mike Kershaw24a47db2005-08-26 00:41:54 -05007854
7855 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05007856 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7857 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007858 (1 << IEEE80211_RADIOTAP_FLAGS) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007859 (1 << IEEE80211_RADIOTAP_RATE) |
7860 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7861 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007862 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007863 (1 << IEEE80211_RADIOTAP_ANTENNA));
7864
7865 /* Zero the flags, we'll add to them as we go */
7866 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08007867 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7868 frame->parent_tsf[2] << 16 |
7869 frame->parent_tsf[1] << 8 |
7870 frame->parent_tsf[0]);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007871
7872 /* Convert signal to DBM */
7873 ipw_rt->rt_dbmsignal = antsignal;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007874 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007875
7876 /* Convert the channel data and set the flags */
7877 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7878 if (received_channel > 14) { /* 802.11a */
7879 ipw_rt->rt_chbitmask =
7880 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7881 } else if (antennaAndPhy & 32) { /* 802.11b */
7882 ipw_rt->rt_chbitmask =
7883 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7884 } else { /* 802.11g */
7885 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05007886 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007887 }
7888
7889 /* set the rate in multiples of 500k/s */
7890 switch (pktrate) {
7891 case IPW_TX_RATE_1MB:
7892 ipw_rt->rt_rate = 2;
7893 break;
7894 case IPW_TX_RATE_2MB:
7895 ipw_rt->rt_rate = 4;
7896 break;
7897 case IPW_TX_RATE_5MB:
7898 ipw_rt->rt_rate = 10;
7899 break;
7900 case IPW_TX_RATE_6MB:
7901 ipw_rt->rt_rate = 12;
7902 break;
7903 case IPW_TX_RATE_9MB:
7904 ipw_rt->rt_rate = 18;
7905 break;
7906 case IPW_TX_RATE_11MB:
7907 ipw_rt->rt_rate = 22;
7908 break;
7909 case IPW_TX_RATE_12MB:
7910 ipw_rt->rt_rate = 24;
7911 break;
7912 case IPW_TX_RATE_18MB:
7913 ipw_rt->rt_rate = 36;
7914 break;
7915 case IPW_TX_RATE_24MB:
7916 ipw_rt->rt_rate = 48;
7917 break;
7918 case IPW_TX_RATE_36MB:
7919 ipw_rt->rt_rate = 72;
7920 break;
7921 case IPW_TX_RATE_48MB:
7922 ipw_rt->rt_rate = 96;
7923 break;
7924 case IPW_TX_RATE_54MB:
7925 ipw_rt->rt_rate = 108;
7926 break;
7927 default:
7928 ipw_rt->rt_rate = 0;
7929 break;
7930 }
7931
7932 /* antenna number */
7933 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7934
7935 /* set the preamble flag if we have it */
7936 if ((antennaAndPhy & 64))
7937 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7938
7939 /* Set the size of the skb to the size of the frame */
7940 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007941
7942 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7943
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007944 if (!libipw_rx(priv->ieee, rxb->skb, stats))
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007945 dev->stats.rx_errors++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007946 else { /* libipw_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007947 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007948 /* no LED during capture */
7949 }
7950}
7951#endif
7952
Zhu Yid685b8c2006-04-13 17:20:27 +08007953#ifdef CONFIG_IPW2200_PROMISCUOUS
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007954#define libipw_is_probe_response(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007955 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7956 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7957
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007958#define libipw_is_management(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007959 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7960
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007961#define libipw_is_control(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007962 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7963
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007964#define libipw_is_data(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007965 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7966
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007967#define libipw_is_assoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007968 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7969
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007970#define libipw_is_reassoc_request(fc) \
Zhu Yid685b8c2006-04-13 17:20:27 +08007971 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7972
7973static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7974 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04007975 struct libipw_rx_stats *stats)
Zhu Yid685b8c2006-04-13 17:20:27 +08007976{
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00007977 struct net_device *dev = priv->prom_net_dev;
Zhu Yid685b8c2006-04-13 17:20:27 +08007978 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7979 struct ipw_rx_frame *frame = &pkt->u.frame;
7980 struct ipw_rt_hdr *ipw_rt;
7981
7982 /* First cache any information we need before we overwrite
7983 * the information provided in the skb from the hardware */
7984 struct ieee80211_hdr *hdr;
7985 u16 channel = frame->received_channel;
7986 u8 phy_flags = frame->antennaAndPhy;
7987 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
Reinette Chatre21f8a732009-08-18 10:25:05 -07007988 s8 noise = (s8) le16_to_cpu(frame->noise);
Zhu Yid685b8c2006-04-13 17:20:27 +08007989 u8 rate = frame->rate;
7990 short len = le16_to_cpu(pkt->u.frame.length);
Zhu Yid685b8c2006-04-13 17:20:27 +08007991 struct sk_buff *skb;
7992 int hdr_only = 0;
7993 u16 filter = priv->prom_priv->filter;
7994
7995 /* If the filter is set to not include Rx frames then return */
7996 if (filter & IPW_PROM_NO_RX)
7997 return;
7998
Zhu Yid685b8c2006-04-13 17:20:27 +08007999 /* We received data from the HW, so stop the watchdog */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008000 dev->trans_start = jiffies;
Zhu Yid685b8c2006-04-13 17:20:27 +08008001
8002 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008003 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008004 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8005 return;
8006 }
8007
8008 /* We only process data packets if the interface is open */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008009 if (unlikely(!netif_running(dev))) {
8010 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008011 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8012 return;
8013 }
8014
8015 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8016 * that now */
8017 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8018 /* FIXME: Should alloc bigger skb instead */
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008019 dev->stats.rx_dropped++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008020 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8021 return;
8022 }
8023
8024 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008025 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008026 if (filter & IPW_PROM_NO_MGMT)
8027 return;
8028 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8029 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008030 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008031 if (filter & IPW_PROM_NO_CTL)
8032 return;
8033 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8034 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008035 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +08008036 if (filter & IPW_PROM_NO_DATA)
8037 return;
8038 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8039 hdr_only = 1;
8040 }
8041
8042 /* Copy the SKB since this is for the promiscuous side */
8043 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8044 if (skb == NULL) {
8045 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8046 return;
8047 }
8048
8049 /* copy the frame data to write after where the radiotap header goes */
8050 ipw_rt = (void *)skb->data;
8051
8052 if (hdr_only)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008053 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +08008054
8055 memcpy(ipw_rt->payload, hdr, len);
8056
Zhu Yid685b8c2006-04-13 17:20:27 +08008057 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8058 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
Al Viro743b84d2007-12-27 01:43:16 -05008059 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
Zhu Yid685b8c2006-04-13 17:20:27 +08008060
8061 /* Set the size of the skb to the size of the frame */
Al Viro743b84d2007-12-27 01:43:16 -05008062 skb_put(skb, sizeof(*ipw_rt) + len);
Zhu Yid685b8c2006-04-13 17:20:27 +08008063
8064 /* Big bitfield of all the fields we provide in radiotap */
Al Viro743b84d2007-12-27 01:43:16 -05008065 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8066 (1 << IEEE80211_RADIOTAP_TSFT) |
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008067 (1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08008068 (1 << IEEE80211_RADIOTAP_RATE) |
8069 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8070 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8071 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8072 (1 << IEEE80211_RADIOTAP_ANTENNA));
8073
8074 /* Zero the flags, we'll add to them as we go */
8075 ipw_rt->rt_flags = 0;
Zhu Yi4b1f8a92006-12-05 14:42:14 +08008076 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8077 frame->parent_tsf[2] << 16 |
8078 frame->parent_tsf[1] << 8 |
8079 frame->parent_tsf[0]);
Zhu Yid685b8c2006-04-13 17:20:27 +08008080
8081 /* Convert to DBM */
8082 ipw_rt->rt_dbmsignal = signal;
8083 ipw_rt->rt_dbmnoise = noise;
8084
8085 /* Convert the channel data and set the flags */
8086 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8087 if (channel > 14) { /* 802.11a */
8088 ipw_rt->rt_chbitmask =
8089 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8090 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8091 ipw_rt->rt_chbitmask =
8092 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8093 } else { /* 802.11g */
8094 ipw_rt->rt_chbitmask =
Al Viro472caf82007-12-27 01:50:54 -05008095 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
Zhu Yid685b8c2006-04-13 17:20:27 +08008096 }
8097
8098 /* set the rate in multiples of 500k/s */
8099 switch (rate) {
8100 case IPW_TX_RATE_1MB:
8101 ipw_rt->rt_rate = 2;
8102 break;
8103 case IPW_TX_RATE_2MB:
8104 ipw_rt->rt_rate = 4;
8105 break;
8106 case IPW_TX_RATE_5MB:
8107 ipw_rt->rt_rate = 10;
8108 break;
8109 case IPW_TX_RATE_6MB:
8110 ipw_rt->rt_rate = 12;
8111 break;
8112 case IPW_TX_RATE_9MB:
8113 ipw_rt->rt_rate = 18;
8114 break;
8115 case IPW_TX_RATE_11MB:
8116 ipw_rt->rt_rate = 22;
8117 break;
8118 case IPW_TX_RATE_12MB:
8119 ipw_rt->rt_rate = 24;
8120 break;
8121 case IPW_TX_RATE_18MB:
8122 ipw_rt->rt_rate = 36;
8123 break;
8124 case IPW_TX_RATE_24MB:
8125 ipw_rt->rt_rate = 48;
8126 break;
8127 case IPW_TX_RATE_36MB:
8128 ipw_rt->rt_rate = 72;
8129 break;
8130 case IPW_TX_RATE_48MB:
8131 ipw_rt->rt_rate = 96;
8132 break;
8133 case IPW_TX_RATE_54MB:
8134 ipw_rt->rt_rate = 108;
8135 break;
8136 default:
8137 ipw_rt->rt_rate = 0;
8138 break;
8139 }
8140
8141 /* antenna number */
8142 ipw_rt->rt_antenna = (phy_flags & 3);
8143
8144 /* set the preamble flag if we have it */
8145 if (phy_flags & (1 << 6))
8146 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8147
8148 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8149
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008150 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008151 dev->stats.rx_errors++;
Zhu Yid685b8c2006-04-13 17:20:27 +08008152 dev_kfree_skb_any(skb);
8153 }
8154}
8155#endif
8156
Arjan van de Ven858119e2006-01-14 13:20:43 -08008157static int is_network_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008158 struct libipw_hdr_4addr *header)
James Ketrenosea2b26e2005-08-24 21:25:16 -05008159{
8160 /* Filter incoming packets to determine if they are targetted toward
8161 * this network, discarding packets coming from ourselves */
8162 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05008163 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008164 /* packets from our adapter are dropped (echo) */
8165 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8166 return 0;
8167
Peter Jones90700fd2005-08-26 16:51:06 -05008168 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008169 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05008170 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008171
8172 /* packets to our adapter go through */
8173 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8174 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05008175
Peter Jones90700fd2005-08-26 16:51:06 -05008176 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008177 /* packets from our adapter are dropped (echo) */
8178 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8179 return 0;
8180
Peter Jones90700fd2005-08-26 16:51:06 -05008181 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008182 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008183 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8184
8185 /* packets to our adapter go through */
8186 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8187 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008188 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008189
James Ketrenosea2b26e2005-08-24 21:25:16 -05008190 return 1;
8191}
8192
James Ketrenosafbf30a2005-08-25 00:05:33 -05008193#define IPW_PACKET_RETRY_TIME HZ
8194
Arjan van de Ven858119e2006-01-14 13:20:43 -08008195static int is_duplicate_packet(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008196 struct libipw_hdr_4addr *header)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008197{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008198 u16 sc = le16_to_cpu(header->seq_ctl);
8199 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8200 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8201 u16 *last_seq, *last_frag;
8202 unsigned long *last_time;
8203
8204 switch (priv->ieee->iw_mode) {
8205 case IW_MODE_ADHOC:
8206 {
8207 struct list_head *p;
8208 struct ipw_ibss_seq *entry = NULL;
8209 u8 *mac = header->addr2;
8210 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8211
8212 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8213 entry =
8214 list_entry(p, struct ipw_ibss_seq, list);
8215 if (!memcmp(entry->mac, mac, ETH_ALEN))
8216 break;
8217 }
8218 if (p == &priv->ibss_mac_hash[index]) {
8219 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8220 if (!entry) {
8221 IPW_ERROR
8222 ("Cannot malloc new mac entry\n");
8223 return 0;
8224 }
8225 memcpy(entry->mac, mac, ETH_ALEN);
8226 entry->seq_num = seq;
8227 entry->frag_num = frag;
8228 entry->packet_time = jiffies;
8229 list_add(&entry->list,
8230 &priv->ibss_mac_hash[index]);
8231 return 0;
8232 }
8233 last_seq = &entry->seq_num;
8234 last_frag = &entry->frag_num;
8235 last_time = &entry->packet_time;
8236 break;
8237 }
8238 case IW_MODE_INFRA:
8239 last_seq = &priv->last_seq_num;
8240 last_frag = &priv->last_frag_num;
8241 last_time = &priv->last_packet_time;
8242 break;
8243 default:
8244 return 0;
8245 }
8246 if ((*last_seq == seq) &&
8247 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8248 if (*last_frag == frag)
8249 goto drop;
8250 if (*last_frag + 1 != frag)
8251 /* out-of-order fragment */
8252 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008253 } else
8254 *last_seq = seq;
8255
Zhu Yif57ce7c2005-07-13 12:22:15 -05008256 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008257 *last_time = jiffies;
8258 return 0;
8259
8260 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008261 /* Comment this line now since we observed the card receives
8262 * duplicate packets but the FCTL_RETRY bit is not set in the
8263 * IBSS mode with fragmentation enabled.
John W. Linville72118012008-09-30 21:43:03 -04008264 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008265 return 1;
8266}
8267
James Ketrenosb095c382005-08-24 22:04:42 -05008268static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8269 struct ipw_rx_mem_buffer *rxb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008270 struct libipw_rx_stats *stats)
James Ketrenosb095c382005-08-24 22:04:42 -05008271{
8272 struct sk_buff *skb = rxb->skb;
8273 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008274 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
James Ketrenosb095c382005-08-24 22:04:42 -05008275 (skb->data + IPW_RX_FRAME_SIZE);
8276
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008277 libipw_rx_mgt(priv->ieee, header, stats);
James Ketrenosb095c382005-08-24 22:04:42 -05008278
8279 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8280 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8281 IEEE80211_STYPE_PROBE_RESP) ||
8282 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8283 IEEE80211_STYPE_BEACON))) {
8284 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8285 ipw_add_station(priv, header->addr2);
8286 }
8287
8288 if (priv->config & CFG_NET_STATS) {
8289 IPW_DEBUG_HC("sending stat packet\n");
8290
8291 /* Set the size of the skb to the size of the full
8292 * ipw header and 802.11 frame */
8293 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8294 IPW_RX_FRAME_SIZE);
8295
8296 /* Advance past the ipw packet header to the 802.11 frame */
8297 skb_pull(skb, IPW_RX_FRAME_SIZE);
8298
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008299 /* Push the libipw_rx_stats before the 802.11 frame */
James Ketrenosb095c382005-08-24 22:04:42 -05008300 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8301
8302 skb->dev = priv->ieee->dev;
8303
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008304 /* Point raw at the libipw_stats */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07008305 skb_reset_mac_header(skb);
James Ketrenosb095c382005-08-24 22:04:42 -05008306
8307 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08008308 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
James Ketrenosb095c382005-08-24 22:04:42 -05008309 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8310 netif_rx(skb);
8311 rxb->skb = NULL;
8312 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008313}
8314
James Ketrenos43f66a62005-03-25 12:31:53 -06008315/*
8316 * Main entry function for recieving a packet with 80211 headers. This
8317 * should be called when ever the FW has notified us that there is a new
8318 * skb in the recieve queue.
8319 */
8320static void ipw_rx(struct ipw_priv *priv)
8321{
8322 struct ipw_rx_mem_buffer *rxb;
8323 struct ipw_rx_packet *pkt;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008324 struct libipw_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008325 u32 r, w, i;
8326 u8 network_packet;
Dan Williams943dbef2008-02-14 17:49:41 -05008327 u8 fill_rx = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008328
James Ketrenosb095c382005-08-24 22:04:42 -05008329 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8330 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
Dan Williams943dbef2008-02-14 17:49:41 -05008331 i = priv->rxq->read;
8332
8333 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8334 fill_rx = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008335
8336 while (i != r) {
8337 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008338 if (unlikely(rxb == NULL)) {
8339 printk(KERN_CRIT "Queue not allocated!\n");
8340 break;
8341 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008342 priv->rxq->queue[i] = NULL;
8343
8344 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008345 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008346 PCI_DMA_FROMDEVICE);
8347
8348 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8349 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8350 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008351 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008352
8353 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008354 case RX_FRAME_TYPE: /* 802.11 frame */ {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008355 struct libipw_rx_stats stats = {
Zhu Yi851ca262006-08-21 11:37:58 +08008356 .rssi = pkt->u.frame.rssi_dbm -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008357 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008358 .signal =
Reinette Chatre21f8a732009-08-18 10:25:05 -07008359 pkt->u.frame.rssi_dbm -
Bill Mossb1916082006-02-15 08:50:18 +08008360 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008361 .noise =
8362 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008363 .rate = pkt->u.frame.rate,
8364 .mac_time = jiffies,
8365 .received_channel =
8366 pkt->u.frame.received_channel,
8367 .freq =
8368 (pkt->u.frame.
8369 control & (1 << 0)) ?
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008370 LIBIPW_24GHZ_BAND :
8371 LIBIPW_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008372 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008373 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008374
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008375 if (stats.rssi != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008376 stats.mask |= LIBIPW_STATMASK_RSSI;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008377 if (stats.signal != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008378 stats.mask |= LIBIPW_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008379 if (stats.noise != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008380 stats.mask |= LIBIPW_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008381 if (stats.rate != 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008382 stats.mask |= LIBIPW_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008383
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008384 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008385
Zhu Yid685b8c2006-04-13 17:20:27 +08008386#ifdef CONFIG_IPW2200_PROMISCUOUS
8387 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8388 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8389#endif
8390
James Ketrenosb095c382005-08-24 22:04:42 -05008391#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008392 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008393#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008394
8395 ipw_handle_data_packet_monitor(priv,
8396 rxb,
8397 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008398#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008399 ipw_handle_data_packet(priv, rxb,
8400 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008401#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008402 break;
8403 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008404#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008405
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008406 header =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008407 (struct libipw_hdr_4addr *)(rxb->skb->
James Ketrenos0dacca12005-09-21 12:23:41 -05008408 data +
8409 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008410 /* TODO: Check Ad-Hoc dest/source and make sure
8411 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008412 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008413 * frame control of the packet and disregard
8414 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008415
James Ketrenosea2b26e2005-08-24 21:25:16 -05008416 network_packet =
8417 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008418 if (network_packet && priv->assoc_network) {
8419 priv->assoc_network->stats.rssi =
8420 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008421 priv->exp_avg_rssi =
8422 exponential_average(priv->exp_avg_rssi,
8423 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008424 }
8425
8426 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008427 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008428
James Ketrenosa613bff2005-08-24 21:43:11 -05008429 if (le16_to_cpu(pkt->u.frame.length) <
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008430 libipw_get_hdrlen(le16_to_cpu(
Zhu Yi9d0be032006-02-15 06:18:19 +08008431 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008432 IPW_DEBUG_DROP
8433 ("Received packet is too small. "
8434 "Dropping.\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +00008435 priv->net_dev->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008436 priv->wstats.discard.misc++;
8437 break;
8438 }
8439
James Ketrenosa613bff2005-08-24 21:43:11 -05008440 switch (WLAN_FC_GET_TYPE
8441 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008442
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008443 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008444 ipw_handle_mgmt_packet(priv, rxb,
8445 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008446 break;
8447
8448 case IEEE80211_FTYPE_CTL:
8449 break;
8450
8451 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008452 if (unlikely(!network_packet ||
8453 is_duplicate_packet(priv,
8454 header)))
8455 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008456 IPW_DEBUG_DROP("Dropping: "
Johannes Berge1749612008-10-27 15:59:26 -07008457 "%pM, "
8458 "%pM, "
8459 "%pM\n",
8460 header->addr1,
8461 header->addr2,
8462 header->addr3);
James Ketrenosb095c382005-08-24 22:04:42 -05008463 break;
8464 }
8465
8466 ipw_handle_data_packet(priv, rxb,
8467 &stats);
8468
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008469 break;
8470 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008471 break;
8472 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008473
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008474 case RX_HOST_NOTIFICATION_TYPE:{
8475 IPW_DEBUG_RX
8476 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008477 pkt->u.notification.subtype,
8478 pkt->u.notification.flags,
Zhu Yi720eeb42006-12-05 14:41:40 +08008479 le16_to_cpu(pkt->u.notification.size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008480 ipw_rx_notification(priv, &pkt->u.notification);
8481 break;
8482 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008483
8484 default:
8485 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8486 pkt->header.message_type);
8487 break;
8488 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008489
8490 /* For now we just don't re-use anything. We can tweak this
8491 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008492 * fail to Rx correctly */
8493 if (rxb->skb != NULL) {
8494 dev_kfree_skb_any(rxb->skb);
8495 rxb->skb = NULL;
8496 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008497
James Ketrenos43f66a62005-03-25 12:31:53 -06008498 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008499 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008500 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008501
James Ketrenos43f66a62005-03-25 12:31:53 -06008502 i = (i + 1) % RX_QUEUE_SIZE;
Dan Williams943dbef2008-02-14 17:49:41 -05008503
8504 /* If there are a lot of unsued frames, restock the Rx queue
8505 * so the ucode won't assert */
8506 if (fill_rx) {
8507 priv->rxq->read = i;
8508 ipw_rx_queue_replenish(priv);
8509 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008510 }
8511
8512 /* Backtrack one entry */
Dan Williams943dbef2008-02-14 17:49:41 -05008513 priv->rxq->read = i;
James Ketrenos43f66a62005-03-25 12:31:53 -06008514 ipw_rx_queue_restock(priv);
8515}
8516
James Ketrenosafbf30a2005-08-25 00:05:33 -05008517#define DEFAULT_RTS_THRESHOLD 2304U
8518#define MIN_RTS_THRESHOLD 1U
8519#define MAX_RTS_THRESHOLD 2304U
8520#define DEFAULT_BEACON_INTERVAL 100U
8521#define DEFAULT_SHORT_RETRY_LIMIT 7U
8522#define DEFAULT_LONG_RETRY_LIMIT 4U
8523
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008524/**
8525 * ipw_sw_reset
8526 * @option: options to control different reset behaviour
8527 * 0 = reset everything except the 'disable' module_param
8528 * 1 = reset everything and print out driver info (for probe only)
8529 * 2 = reset everything
8530 */
8531static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008532{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008533 int band, modulation;
8534 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008535
James Ketrenosafbf30a2005-08-25 00:05:33 -05008536 /* Initialize module parameter values here */
8537 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008538
James Ketrenosafbf30a2005-08-25 00:05:33 -05008539 /* We default to disabling the LED code as right now it causes
8540 * too many systems to lock up... */
Reinette Chatre21f8a732009-08-18 10:25:05 -07008541 if (!led_support)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008542 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008543
James Ketrenosafbf30a2005-08-25 00:05:33 -05008544 if (associate)
8545 priv->config |= CFG_ASSOCIATE;
8546 else
8547 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008548
James Ketrenosafbf30a2005-08-25 00:05:33 -05008549 if (auto_create)
8550 priv->config |= CFG_ADHOC_CREATE;
8551 else
8552 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8553
Zhu Yi17ed0812006-01-24 16:36:31 +08008554 priv->config &= ~CFG_STATIC_ESSID;
8555 priv->essid_len = 0;
8556 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8557
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008558 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008559 priv->status |= STATUS_RF_KILL_SW;
8560 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008561 }
8562
Reinette Chatre21f8a732009-08-18 10:25:05 -07008563 if (default_channel != 0) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008564 priv->config |= CFG_STATIC_CHANNEL;
Reinette Chatre21f8a732009-08-18 10:25:05 -07008565 priv->channel = default_channel;
8566 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008567 /* TODO: Validate that provided channel is in range */
8568 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008569#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008570 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8571 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008572#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008573
Reinette Chatre21f8a732009-08-18 10:25:05 -07008574 switch (network_mode) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008575 case 1:
8576 priv->ieee->iw_mode = IW_MODE_ADHOC;
8577 priv->net_dev->type = ARPHRD_ETHER;
8578
8579 break;
8580#ifdef CONFIG_IPW2200_MONITOR
8581 case 2:
8582 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008583#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008584 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8585#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008586 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008587#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008588 break;
8589#endif
8590 default:
8591 case 0:
8592 priv->net_dev->type = ARPHRD_ETHER;
8593 priv->ieee->iw_mode = IW_MODE_INFRA;
8594 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008595 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008596
James Ketrenosafbf30a2005-08-25 00:05:33 -05008597 if (hwcrypto) {
8598 priv->ieee->host_encrypt = 0;
8599 priv->ieee->host_encrypt_msdu = 0;
8600 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008601 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008603 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008604
Zhu Yie402c932005-08-05 17:20:40 +08008605 /* IPW2200/2915 is abled to do hardware fragmentation. */
8606 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008607
James Ketrenosafbf30a2005-08-25 00:05:33 -05008608 if ((priv->pci_dev->device == 0x4223) ||
8609 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008610 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008611 printk(KERN_INFO DRV_NAME
8612 ": Detected Intel PRO/Wireless 2915ABG Network "
8613 "Connection\n");
8614 priv->ieee->abg_true = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008615 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8616 modulation = LIBIPW_OFDM_MODULATION |
8617 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008618 priv->adapter = IPW_2915ABG;
8619 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008620 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008621 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008622 printk(KERN_INFO DRV_NAME
8623 ": Detected Intel PRO/Wireless 2200BG Network "
8624 "Connection\n");
8625
8626 priv->ieee->abg_true = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008627 band = LIBIPW_24GHZ_BAND;
8628 modulation = LIBIPW_OFDM_MODULATION |
8629 LIBIPW_CCK_MODULATION;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008630 priv->adapter = IPW_2200BG;
8631 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008632 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008633
James Ketrenosafbf30a2005-08-25 00:05:33 -05008634 priv->ieee->freq_band = band;
8635 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008636
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008637 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008638
James Ketrenosafbf30a2005-08-25 00:05:33 -05008639 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8640 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008641
James Ketrenosafbf30a2005-08-25 00:05:33 -05008642 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8643 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8644 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008645
James Ketrenosafbf30a2005-08-25 00:05:33 -05008646 /* If power management is turned on, default to AC mode */
8647 priv->power_mode = IPW_POWER_AC;
8648 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008649
Zhu Yi0ece35b2005-08-05 17:26:51 +08008650 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008651}
8652
8653/*
8654 * This file defines the Wireless Extension handlers. It does not
8655 * define any methods of hardware manipulation and relies on the
8656 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008657 *
8658 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008659 * function used to poll the hardware vs. making unecessary calls.
8660 *
8661 */
8662
John W. Linville8cc31742009-11-13 16:56:13 -05008663static int ipw_wx_get_name(struct net_device *dev,
8664 struct iw_request_info *info,
8665 union iwreq_data *wrqu, char *extra)
8666{
8667 struct ipw_priv *priv = libipw_priv(dev);
8668 mutex_lock(&priv->mutex);
8669 if (priv->status & STATUS_RF_KILL_MASK)
8670 strcpy(wrqu->name, "radio off");
8671 else if (!(priv->status & STATUS_ASSOCIATED))
8672 strcpy(wrqu->name, "unassociated");
8673 else
8674 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8675 ipw_modes[priv->assoc_request.ieee_mode]);
8676 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8677 mutex_unlock(&priv->mutex);
8678 return 0;
8679}
8680
James Ketrenos43f66a62005-03-25 12:31:53 -06008681static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8682{
8683 if (channel == 0) {
8684 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8685 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008686 IPW_DEBUG_ASSOC("Attempting to associate with new "
8687 "parameters.\n");
8688 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008689 return 0;
8690 }
8691
8692 priv->config |= CFG_STATIC_CHANNEL;
8693
8694 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008695 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8696 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008697 return 0;
8698 }
8699
8700 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8701 priv->channel = channel;
8702
James Ketrenosb095c382005-08-24 22:04:42 -05008703#ifdef CONFIG_IPW2200_MONITOR
8704 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008705 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008706 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008707 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008708 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008709 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008710 }
8711
8712 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8713 udelay(10);
8714
8715 if (priv->status & STATUS_SCANNING)
8716 IPW_DEBUG_SCAN("Still scanning...\n");
8717 else
8718 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8719 1000 - i);
8720
8721 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008722 }
James Ketrenosb095c382005-08-24 22:04:42 -05008723#endif /* CONFIG_IPW2200_MONITOR */
8724
James Ketrenosc848d0a2005-08-24 21:56:24 -05008725 /* Network configuration changed -- force [re]association */
8726 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8727 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008728 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008729
8730 return 0;
8731}
8732
Jeff Garzikbf794512005-07-31 13:07:26 -04008733static int ipw_wx_set_freq(struct net_device *dev,
8734 struct iw_request_info *info,
8735 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008736{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008737 struct ipw_priv *priv = libipw_priv(dev);
8738 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008740 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008741 u8 channel, flags;
8742 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008743
James Ketrenosb095c382005-08-24 22:04:42 -05008744 if (fwrq->m == 0) {
8745 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008746 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008747 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008748 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008749 return ret;
8750 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008751 /* if setting by freq convert to channel */
8752 if (fwrq->e == 1) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008753 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008754 if (channel == 0)
8755 return -EINVAL;
8756 } else
8757 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008758
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008759 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008760 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008761
Liu Hong1fe0adb2005-08-19 09:33:10 -05008762 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008763 i = libipw_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008764 if (i == -1)
8765 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008766
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008767 flags = (band == LIBIPW_24GHZ_BAND) ?
Liu Hong1fe0adb2005-08-19 09:33:10 -05008768 geo->bg[i].flags : geo->a[i].flags;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008769 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008770 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8771 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 }
8773 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008774
James Ketrenos43f66a62005-03-25 12:31:53 -06008775 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008776 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008777 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008778 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008779 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008780}
8781
Jeff Garzikbf794512005-07-31 13:07:26 -04008782static int ipw_wx_get_freq(struct net_device *dev,
8783 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008784 union iwreq_data *wrqu, char *extra)
8785{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008786 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008787
8788 wrqu->freq.e = 0;
8789
8790 /* If we are associated, trying to associate, or have a statically
8791 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008792 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008794 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8795 int i;
8796
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008797 i = libipw_channel_to_index(priv->ieee, priv->channel);
Zhu Yic580f672006-08-21 11:37:01 +08008798 BUG_ON(i == -1);
8799 wrqu->freq.e = 1;
8800
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008801 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8802 case LIBIPW_52GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008803 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8804 break;
8805
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008806 case LIBIPW_24GHZ_BAND:
Zhu Yic580f672006-08-21 11:37:01 +08008807 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8808 break;
8809
8810 default:
8811 BUG();
8812 }
8813 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008814 wrqu->freq.m = 0;
8815
Zhu Yi46441512006-01-24 16:37:59 +08008816 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008817 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8818 return 0;
8819}
8820
Jeff Garzikbf794512005-07-31 13:07:26 -04008821static int ipw_wx_set_mode(struct net_device *dev,
8822 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008823 union iwreq_data *wrqu, char *extra)
8824{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008825 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008826 int err = 0;
8827
8828 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8829
James Ketrenos43f66a62005-03-25 12:31:53 -06008830 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008831#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 case IW_MODE_MONITOR:
8833#endif
8834 case IW_MODE_ADHOC:
8835 case IW_MODE_INFRA:
8836 break;
8837 case IW_MODE_AUTO:
8838 wrqu->mode = IW_MODE_INFRA;
8839 break;
8840 default:
8841 return -EINVAL;
8842 }
James Ketrenosb095c382005-08-24 22:04:42 -05008843 if (wrqu->mode == priv->ieee->iw_mode)
8844 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008845
Zhu Yi46441512006-01-24 16:37:59 +08008846 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008847
8848 ipw_sw_reset(priv, 0);
8849
James Ketrenosb095c382005-08-24 22:04:42 -05008850#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008851 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008853
8854 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008855#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008856 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8857#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008858 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008859#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008860#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008861
Jeff Garzikbf794512005-07-31 13:07:26 -04008862 /* Free the existing firmware and reset the fw_loaded
Nick Andrew877d0312009-01-26 11:06:57 +01008863 * flag so ipw_load() will bring in the new firmware */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008864 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008865
8866 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008867
James Ketrenosc848d0a2005-08-24 21:56:24 -05008868 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008869 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008870 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008871}
8872
Jeff Garzikbf794512005-07-31 13:07:26 -04008873static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008874 struct iw_request_info *info,
8875 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008876{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008877 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008878 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 wrqu->mode = priv->ieee->iw_mode;
8880 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008881 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008882 return 0;
8883}
8884
James Ketrenos43f66a62005-03-25 12:31:53 -06008885/* Values are in microsecond */
8886static const s32 timeout_duration[] = {
8887 350000,
8888 250000,
8889 75000,
8890 37000,
8891 25000,
8892};
8893
8894static const s32 period_duration[] = {
8895 400000,
8896 700000,
8897 1000000,
8898 1000000,
8899 1000000
8900};
8901
Jeff Garzikbf794512005-07-31 13:07:26 -04008902static int ipw_wx_get_range(struct net_device *dev,
8903 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008904 union iwreq_data *wrqu, char *extra)
8905{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008906 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 struct iw_range *range = (struct iw_range *)extra;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008908 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008909 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008910
8911 wrqu->data.length = sizeof(*range);
8912 memset(range, 0, sizeof(*range));
8913
8914 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008915 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008916
8917 range->max_qual.qual = 100;
8918 /* TODO: Find real max RSSI and stick here */
8919 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008920 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008921 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008922
8923 range->avg_qual.qual = 70;
8924 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008925 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008927 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008928 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008929 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008930
Jeff Garzikbf794512005-07-31 13:07:26 -04008931 for (i = 0; i < range->num_bitrates; i++)
8932 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008933 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008934
James Ketrenos43f66a62005-03-25 12:31:53 -06008935 range->max_rts = DEFAULT_RTS_THRESHOLD;
8936 range->min_frag = MIN_FRAG_THRESHOLD;
8937 range->max_frag = MAX_FRAG_THRESHOLD;
8938
8939 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008940 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008941 range->num_encoding_sizes = 2;
8942 range->max_encoding_tokens = WEP_KEYS;
8943
8944 /* Set the Wireless Extension versions */
8945 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008946 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008947
James Ketrenosb095c382005-08-24 22:04:42 -05008948 i = 0;
8949 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008950 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8951 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008952 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008953 continue;
8954
James Ketrenosb095c382005-08-24 22:04:42 -05008955 range->freq[i].i = geo->bg[j].channel;
8956 range->freq[i].m = geo->bg[j].freq * 100000;
8957 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008958 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008959 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008960 }
James Ketrenosb095c382005-08-24 22:04:42 -05008961
8962 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008963 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8964 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04008965 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
Zhu Yie815de42006-03-02 05:55:51 +08008966 continue;
8967
James Ketrenosb095c382005-08-24 22:04:42 -05008968 range->freq[i].i = geo->a[j].channel;
8969 range->freq[i].m = geo->a[j].freq * 100000;
8970 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008971 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008972 }
8973 }
8974
8975 range->num_channels = i;
8976 range->num_frequency = i;
8977
Zhu Yi46441512006-01-24 16:37:59 +08008978 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008979
8980 /* Event capability (kernel + driver) */
8981 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8982 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008983 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8984 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008985 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008986
Dan Williamsf1b50862006-01-30 13:58:56 -05008987 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8988 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8989
Dan Williams374fdfb2007-12-12 10:25:07 -05008990 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
8991
James Ketrenos43f66a62005-03-25 12:31:53 -06008992 IPW_DEBUG_WX("GET Range\n");
8993 return 0;
8994}
8995
Jeff Garzikbf794512005-07-31 13:07:26 -04008996static int ipw_wx_set_wap(struct net_device *dev,
8997 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008998 union iwreq_data *wrqu, char *extra)
8999{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009000 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009001
9002 static const unsigned char any[] = {
9003 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9004 };
9005 static const unsigned char off[] = {
9006 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9007 };
9008
Jeff Garzikbf794512005-07-31 13:07:26 -04009009 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06009010 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009011 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009012 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9013 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9014 /* we disable mandatory BSSID association */
9015 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9016 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009017 IPW_DEBUG_ASSOC("Attempting to associate with new "
9018 "parameters.\n");
9019 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08009020 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009021 return 0;
9022 }
9023
9024 priv->config |= CFG_STATIC_BSSID;
9025 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9026 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009027 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009028 return 0;
9029 }
9030
Johannes Berge1749612008-10-27 15:59:26 -07009031 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9032 wrqu->ap_addr.sa_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06009033
9034 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9035
James Ketrenosc848d0a2005-08-24 21:56:24 -05009036 /* Network configuration changed -- force [re]association */
9037 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9038 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009039 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009040
Zhu Yi46441512006-01-24 16:37:59 +08009041 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 return 0;
9043}
9044
Jeff Garzikbf794512005-07-31 13:07:26 -04009045static int ipw_wx_get_wap(struct net_device *dev,
9046 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009047 union iwreq_data *wrqu, char *extra)
9048{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009049 struct ipw_priv *priv = libipw_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -07009050
James Ketrenos43f66a62005-03-25 12:31:53 -06009051 /* If we are associated, trying to associate, or have a statically
9052 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009053 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009054 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06009055 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9056 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009057 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06009058 } else
9059 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9060
Johannes Berge1749612008-10-27 15:59:26 -07009061 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9062 wrqu->ap_addr.sa_data);
Zhu Yi46441512006-01-24 16:37:59 +08009063 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009064 return 0;
9065}
9066
Jeff Garzikbf794512005-07-31 13:07:26 -04009067static int ipw_wx_set_essid(struct net_device *dev,
9068 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 union iwreq_data *wrqu, char *extra)
9070{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009071 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08009072 int length;
John W. Linville9387b7c2008-09-30 20:59:05 -04009073 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009074
Zhu Yiab644b02006-08-21 11:37:13 +08009075 mutex_lock(&priv->mutex);
9076
9077 if (!wrqu->essid.flags)
9078 {
9079 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9080 ipw_disassociate(priv);
9081 priv->config &= ~CFG_STATIC_ESSID;
9082 ipw_associate(priv);
9083 mutex_unlock(&priv->mutex);
9084 return 0;
9085 }
9086
Zhu Yia9f0d422006-08-21 11:37:26 +08009087 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06009088
9089 priv->config |= CFG_STATIC_ESSID;
9090
Zhu Yia9f0d422006-08-21 11:37:26 +08009091 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9092 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009093 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009094 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009095 return 0;
9096 }
9097
John W. Linville9387b7c2008-09-30 20:59:05 -04009098 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9099 print_ssid(ssid, extra, length), length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009100
9101 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08009102 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009103
James Ketrenosc848d0a2005-08-24 21:56:24 -05009104 /* Network configuration changed -- force [re]association */
9105 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9106 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009108
Zhu Yi46441512006-01-24 16:37:59 +08009109 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009110 return 0;
9111}
9112
Jeff Garzikbf794512005-07-31 13:07:26 -04009113static int ipw_wx_get_essid(struct net_device *dev,
9114 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009115 union iwreq_data *wrqu, char *extra)
9116{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009117 struct ipw_priv *priv = libipw_priv(dev);
John W. Linville9387b7c2008-09-30 20:59:05 -04009118 DECLARE_SSID_BUF(ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06009119
9120 /* If we are associated, trying to associate, or have a statically
9121 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08009122 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009123 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04009124 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9125 IPW_DEBUG_WX("Getting essid: '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04009126 print_ssid(ssid, priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04009127 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009129 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009130 } else {
9131 IPW_DEBUG_WX("Getting essid: ANY\n");
9132 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009133 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06009134 }
Zhu Yi46441512006-01-24 16:37:59 +08009135 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 return 0;
9137}
9138
Jeff Garzikbf794512005-07-31 13:07:26 -04009139static int ipw_wx_set_nick(struct net_device *dev,
9140 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009141 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009142{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009143 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144
9145 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9146 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9147 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08009148 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009149 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009151 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06009152 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08009153 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 return 0;
9155
9156}
9157
Jeff Garzikbf794512005-07-31 13:07:26 -04009158static int ipw_wx_get_nick(struct net_device *dev,
9159 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009160 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009161{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009162 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009163 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08009164 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009165 wrqu->data.length = strlen(priv->nick);
James Ketrenos43f66a62005-03-25 12:31:53 -06009166 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08009168 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 return 0;
9170}
9171
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009172static int ipw_wx_set_sens(struct net_device *dev,
9173 struct iw_request_info *info,
9174 union iwreq_data *wrqu, char *extra)
9175{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009176 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009177 int err = 0;
9178
9179 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9180 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9181 mutex_lock(&priv->mutex);
9182
9183 if (wrqu->sens.fixed == 0)
9184 {
9185 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9186 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9187 goto out;
9188 }
9189 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9190 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9191 err = -EINVAL;
9192 goto out;
9193 }
9194
9195 priv->roaming_threshold = wrqu->sens.value;
9196 priv->disassociate_threshold = 3*wrqu->sens.value;
9197 out:
9198 mutex_unlock(&priv->mutex);
9199 return err;
9200}
9201
9202static int ipw_wx_get_sens(struct net_device *dev,
9203 struct iw_request_info *info,
9204 union iwreq_data *wrqu, char *extra)
9205{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009206 struct ipw_priv *priv = libipw_priv(dev);
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009207 mutex_lock(&priv->mutex);
9208 wrqu->sens.fixed = 1;
9209 wrqu->sens.value = priv->roaming_threshold;
9210 mutex_unlock(&priv->mutex);
9211
9212 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9213 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9214
9215 return 0;
9216}
9217
James Ketrenos43f66a62005-03-25 12:31:53 -06009218static int ipw_wx_set_rate(struct net_device *dev,
9219 struct iw_request_info *info,
9220 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009221{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009222 /* TODO: We should use semaphores or locks for access to priv */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009223 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009224 u32 target_rate = wrqu->bitrate.value;
9225 u32 fixed, mask;
9226
9227 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9228 /* value = X, fixed = 1 means only rate X */
9229 /* value = X, fixed = 0 means all rates lower equal X */
9230
9231 if (target_rate == -1) {
9232 fixed = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009233 mask = LIBIPW_DEFAULT_RATES_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009234 /* Now we should reassociate */
9235 goto apply;
9236 }
9237
9238 mask = 0;
9239 fixed = wrqu->bitrate.fixed;
9240
9241 if (target_rate == 1000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009242 mask |= LIBIPW_CCK_RATE_1MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009243 if (target_rate == 1000000)
9244 goto apply;
9245
9246 if (target_rate == 2000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009247 mask |= LIBIPW_CCK_RATE_2MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009248 if (target_rate == 2000000)
9249 goto apply;
9250
9251 if (target_rate == 5500000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009252 mask |= LIBIPW_CCK_RATE_5MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009253 if (target_rate == 5500000)
9254 goto apply;
9255
9256 if (target_rate == 6000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009257 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009258 if (target_rate == 6000000)
9259 goto apply;
9260
9261 if (target_rate == 9000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009262 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009263 if (target_rate == 9000000)
9264 goto apply;
9265
9266 if (target_rate == 11000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009267 mask |= LIBIPW_CCK_RATE_11MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009268 if (target_rate == 11000000)
9269 goto apply;
9270
9271 if (target_rate == 12000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009272 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009273 if (target_rate == 12000000)
9274 goto apply;
9275
9276 if (target_rate == 18000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009277 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009278 if (target_rate == 18000000)
9279 goto apply;
9280
9281 if (target_rate == 24000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009282 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009283 if (target_rate == 24000000)
9284 goto apply;
9285
9286 if (target_rate == 36000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009287 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009288 if (target_rate == 36000000)
9289 goto apply;
9290
9291 if (target_rate == 48000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009292 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009293 if (target_rate == 48000000)
9294 goto apply;
9295
9296 if (target_rate == 54000000 || !fixed)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009297 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009298 if (target_rate == 54000000)
9299 goto apply;
9300
9301 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9302 return -EINVAL;
9303
9304 apply:
9305 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9306 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009307 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009308 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009309 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009310 ipw_set_fixed_rate(priv, priv->ieee->mode);
9311 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009312 priv->config |= CFG_FIXED_RATE;
9313
James Ketrenosc848d0a2005-08-24 21:56:24 -05009314 if (priv->rates_mask == mask) {
9315 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009316 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009317 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009318 }
9319
James Ketrenosc848d0a2005-08-24 21:56:24 -05009320 priv->rates_mask = mask;
9321
9322 /* Network configuration changed -- force [re]association */
9323 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9324 if (!ipw_disassociate(priv))
9325 ipw_associate(priv);
9326
Zhu Yi46441512006-01-24 16:37:59 +08009327 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009328 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009329}
9330
Jeff Garzikbf794512005-07-31 13:07:26 -04009331static int ipw_wx_get_rate(struct net_device *dev,
9332 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009333 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009334{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009335 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009336 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009337 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009338 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009339 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009340 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9341 return 0;
9342}
9343
Jeff Garzikbf794512005-07-31 13:07:26 -04009344static int ipw_wx_set_rts(struct net_device *dev,
9345 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009347{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009348 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009349 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009350 if (wrqu->rts.disabled || !wrqu->rts.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9352 else {
9353 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009354 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009355 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009356 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009357 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009358 priv->rts_threshold = wrqu->rts.value;
9359 }
9360
9361 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009362 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9364 return 0;
9365}
9366
Jeff Garzikbf794512005-07-31 13:07:26 -04009367static int ipw_wx_get_rts(struct net_device *dev,
9368 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009369 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009370{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009371 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009372 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 wrqu->rts.value = priv->rts_threshold;
9374 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009375 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009376 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009377 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9378 return 0;
9379}
9380
Jeff Garzikbf794512005-07-31 13:07:26 -04009381static int ipw_wx_set_txpow(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 Yi6de9f7f2005-08-11 14:39:33 +08009386 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009387
Zhu Yi46441512006-01-24 16:37:59 +08009388 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009389 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009390 err = -EINPROGRESS;
9391 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009392 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009393
James Ketrenosb095c382005-08-24 22:04:42 -05009394 if (!wrqu->power.fixed)
9395 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009396
James Ketrenosc848d0a2005-08-24 21:56:24 -05009397 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009398 err = -EINVAL;
9399 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009400 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009401
James Ketrenosb095c382005-08-24 22:04:42 -05009402 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009403 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009404 err = -EINVAL;
9405 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009406 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009407
9408 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009409 err = ipw_set_tx_power(priv);
9410 out:
Zhu Yi46441512006-01-24 16:37:59 +08009411 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009412 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009413}
9414
Jeff Garzikbf794512005-07-31 13:07:26 -04009415static int ipw_wx_get_txpow(struct net_device *dev,
9416 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009417 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009418{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009419 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009420 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 wrqu->power.value = priv->tx_power;
9422 wrqu->power.fixed = 1;
9423 wrqu->power.flags = IW_TXPOW_DBM;
9424 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009425 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009426
Jeff Garzikbf794512005-07-31 13:07:26 -04009427 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009428 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009429
9430 return 0;
9431}
9432
Jeff Garzikbf794512005-07-31 13:07:26 -04009433static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009434 struct iw_request_info *info,
9435 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009436{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009437 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009438 mutex_lock(&priv->mutex);
Zhu Yiea8862d2007-01-11 17:32:54 +08009439 if (wrqu->frag.disabled || !wrqu->frag.fixed)
James Ketrenos43f66a62005-03-25 12:31:53 -06009440 priv->ieee->fts = DEFAULT_FTS;
9441 else {
9442 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009443 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009444 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009446 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009447
James Ketrenos43f66a62005-03-25 12:31:53 -06009448 priv->ieee->fts = wrqu->frag.value & ~0x1;
9449 }
9450
9451 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009452 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009453 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9454 return 0;
9455}
9456
Jeff Garzikbf794512005-07-31 13:07:26 -04009457static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009458 struct iw_request_info *info,
9459 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009460{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009461 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009462 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463 wrqu->frag.value = priv->ieee->fts;
9464 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009465 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009466 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009467 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9468
9469 return 0;
9470}
9471
Jeff Garzikbf794512005-07-31 13:07:26 -04009472static int ipw_wx_set_retry(struct net_device *dev,
9473 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009474 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009475{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009476 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009477
9478 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9479 return -EINVAL;
9480
9481 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9482 return 0;
9483
Zhu Yid5f7ac22006-08-21 11:38:17 +08009484 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009485 return -EINVAL;
9486
Zhu Yi46441512006-01-24 16:37:59 +08009487 mutex_lock(&priv->mutex);
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009488 if (wrqu->retry.flags & IW_RETRY_SHORT)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009489 priv->short_retry_limit = (u8) wrqu->retry.value;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009490 else if (wrqu->retry.flags & IW_RETRY_LONG)
James Ketrenosafbf30a2005-08-25 00:05:33 -05009491 priv->long_retry_limit = (u8) wrqu->retry.value;
9492 else {
9493 priv->short_retry_limit = (u8) wrqu->retry.value;
9494 priv->long_retry_limit = (u8) wrqu->retry.value;
9495 }
9496
9497 ipw_send_retry_limit(priv, priv->short_retry_limit,
9498 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009499 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009500 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9501 priv->short_retry_limit, priv->long_retry_limit);
9502 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009503}
9504
Jeff Garzikbf794512005-07-31 13:07:26 -04009505static int ipw_wx_get_retry(struct net_device *dev,
9506 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009507 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009508{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009509 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009510
Zhu Yi46441512006-01-24 16:37:59 +08009511 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009512 wrqu->retry.disabled = 0;
9513
9514 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009515 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009516 return -EINVAL;
9517 }
9518
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009519 if (wrqu->retry.flags & IW_RETRY_LONG) {
9520 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009521 wrqu->retry.value = priv->long_retry_limit;
Jean Tourrilhes919ee6d2006-08-29 18:01:40 -07009522 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9523 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009524 wrqu->retry.value = priv->short_retry_limit;
9525 } else {
9526 wrqu->retry.flags = IW_RETRY_LIMIT;
9527 wrqu->retry.value = priv->short_retry_limit;
9528 }
Zhu Yi46441512006-01-24 16:37:59 +08009529 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009530
9531 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9532
9533 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009534}
9535
Jeff Garzikbf794512005-07-31 13:07:26 -04009536static int ipw_wx_set_scan(struct net_device *dev,
9537 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009538 union iwreq_data *wrqu, char *extra)
9539{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009540 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi094c4d22006-08-21 11:39:03 +08009541 struct iw_scan_req *req = (struct iw_scan_req *)extra;
Dan Williamsea177302008-06-02 17:51:23 -04009542 struct delayed_work *work = NULL;
Zhu Yi094c4d22006-08-21 11:39:03 +08009543
Dan Williams0b531672007-10-09 13:55:24 -04009544 mutex_lock(&priv->mutex);
Dan Williamsea177302008-06-02 17:51:23 -04009545
Dan Williams0b531672007-10-09 13:55:24 -04009546 priv->user_requested_scan = 1;
Dan Williams0b531672007-10-09 13:55:24 -04009547
Zhu Yi094c4d22006-08-21 11:39:03 +08009548 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05009549 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Dan Williamsea177302008-06-02 17:51:23 -04009550 int len = min((int)req->essid_len,
9551 (int)sizeof(priv->direct_scan_ssid));
9552 memcpy(priv->direct_scan_ssid, req->essid, len);
9553 priv->direct_scan_ssid_len = len;
9554 work = &priv->request_direct_scan;
9555 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9556 work = &priv->request_passive_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009557 }
Dan Williamsea177302008-06-02 17:51:23 -04009558 } else {
9559 /* Normal active broadcast scan */
9560 work = &priv->request_scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009561 }
James Ketrenos8935f392005-10-05 15:59:08 -05009562
Dan Williamsea177302008-06-02 17:51:23 -04009563 mutex_unlock(&priv->mutex);
9564
James Ketrenos43f66a62005-03-25 12:31:53 -06009565 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009566
Dan Williamsea177302008-06-02 17:51:23 -04009567 queue_delayed_work(priv->workqueue, work, 0);
James Ketrenosb095c382005-08-24 22:04:42 -05009568
James Ketrenos43f66a62005-03-25 12:31:53 -06009569 return 0;
9570}
9571
Jeff Garzikbf794512005-07-31 13:07:26 -04009572static int ipw_wx_get_scan(struct net_device *dev,
9573 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009574 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009575{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009576 struct ipw_priv *priv = libipw_priv(dev);
9577 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
James Ketrenos43f66a62005-03-25 12:31:53 -06009578}
9579
Jeff Garzikbf794512005-07-31 13:07:26 -04009580static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009581 struct iw_request_info *info,
9582 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009583{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009584 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009585 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009586 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009587
Zhu Yi46441512006-01-24 16:37:59 +08009588 mutex_lock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009589 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009590
Hong Liucaeff812005-08-05 17:25:50 +08009591 /* In IBSS mode, we need to notify the firmware to update
9592 * the beacon info after we changed the capability. */
9593 if (cap != priv->capability &&
9594 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9595 priv->status & STATUS_ASSOCIATED)
9596 ipw_disassociate(priv);
9597
Zhu Yi46441512006-01-24 16:37:59 +08009598 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009599 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009600}
9601
Jeff Garzikbf794512005-07-31 13:07:26 -04009602static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009603 struct iw_request_info *info,
9604 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009605{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009606 struct ipw_priv *priv = libipw_priv(dev);
9607 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
James Ketrenos43f66a62005-03-25 12:31:53 -06009608}
9609
Jeff Garzikbf794512005-07-31 13:07:26 -04009610static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009611 struct iw_request_info *info,
9612 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009613{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009614 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009615 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009616 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009617 if (wrqu->power.disabled) {
9618 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9619 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9620 if (err) {
9621 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009622 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009623 return err;
9624 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009625 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009626 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009627 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009628 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009629
9630 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009631 case IW_POWER_ON: /* If not specified */
9632 case IW_POWER_MODE: /* If set all mask */
Jean Delvarec03983a2007-10-19 23:22:55 +02009633 case IW_POWER_ALL_R: /* If explicitly state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009635 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009636 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9637 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009638 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009639 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009640 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009641
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 /* If the user hasn't specified a power management mode yet, default
9643 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009644 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009646 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009647 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
Zhu Yi4e157f02007-07-12 16:09:32 +08009648
James Ketrenos43f66a62005-03-25 12:31:53 -06009649 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9650 if (err) {
9651 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009652 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 return err;
9654 }
9655
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009656 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009657 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009658 return 0;
9659}
9660
Jeff Garzikbf794512005-07-31 13:07:26 -04009661static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009662 struct iw_request_info *info,
9663 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009664{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009665 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009666 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009667 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009668 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009669 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009671
Zhu Yi46441512006-01-24 16:37:59 +08009672 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009673 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009674
James Ketrenos43f66a62005-03-25 12:31:53 -06009675 return 0;
9676}
9677
Jeff Garzikbf794512005-07-31 13:07:26 -04009678static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009679 struct iw_request_info *info,
9680 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009681{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009682 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 int mode = *(int *)extra;
9684 int err;
Zhu Yi4e157f02007-07-12 16:09:32 +08009685
Zhu Yi46441512006-01-24 16:37:59 +08009686 mutex_lock(&priv->mutex);
Zhu Yi4e157f02007-07-12 16:09:32 +08009687 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
James Ketrenos43f66a62005-03-25 12:31:53 -06009688 mode = IPW_POWER_AC;
Jeff Garzikbf794512005-07-31 13:07:26 -04009689
Zhu Yi4e157f02007-07-12 16:09:32 +08009690 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009691 err = ipw_send_power_mode(priv, mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 if (err) {
9693 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009694 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009695 return err;
9696 }
Zhu Yi4e157f02007-07-12 16:09:32 +08009697 priv->power_mode = IPW_POWER_ENABLED | mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06009698 }
Zhu Yi46441512006-01-24 16:37:59 +08009699 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009700 return 0;
9701}
9702
9703#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009704static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009705 struct iw_request_info *info,
9706 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009707{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009708 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 int level = IPW_POWER_LEVEL(priv->power_mode);
9710 char *p = extra;
9711
9712 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9713
9714 switch (level) {
9715 case IPW_POWER_AC:
9716 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9717 break;
9718 case IPW_POWER_BATTERY:
9719 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9720 break;
9721 default:
9722 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009723 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009724 timeout_duration[level - 1] / 1000,
9725 period_duration[level - 1] / 1000);
9726 }
9727
9728 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009729 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009730
9731 wrqu->data.length = p - extra + 1;
9732
9733 return 0;
9734}
9735
9736static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009737 struct iw_request_info *info,
9738 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009739{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009740 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 int mode = *(int *)extra;
9742 u8 band = 0, modulation = 0;
9743
9744 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009745 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009746 return -EINVAL;
9747 }
Zhu Yi46441512006-01-24 16:37:59 +08009748 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009749 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009750 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009751 if (mode & IEEE_A) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009752 band |= LIBIPW_52GHZ_BAND;
9753 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009754 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009755 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 } else {
9757 if (mode & IEEE_A) {
9758 IPW_WARNING("Attempt to set 2200BG into "
9759 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009760 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009761 return -EINVAL;
9762 }
9763
James Ketrenosa33a1982005-09-14 14:28:59 -05009764 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 }
9766
9767 if (mode & IEEE_B) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009768 band |= LIBIPW_24GHZ_BAND;
9769 modulation |= LIBIPW_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009771 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009772
James Ketrenos43f66a62005-03-25 12:31:53 -06009773 if (mode & IEEE_G) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009774 band |= LIBIPW_24GHZ_BAND;
9775 modulation |= LIBIPW_OFDM_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06009776 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009777 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009778
9779 priv->ieee->mode = mode;
9780 priv->ieee->freq_band = band;
9781 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009782 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009783
James Ketrenosc848d0a2005-08-24 21:56:24 -05009784 /* Network configuration changed -- force [re]association */
9785 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9786 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009788 ipw_associate(priv);
9789 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009790
James Ketrenosa613bff2005-08-24 21:43:11 -05009791 /* Update the band LEDs */
9792 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009793
Jeff Garzikbf794512005-07-31 13:07:26 -04009794 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009795 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009796 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009797 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009798 return 0;
9799}
9800
9801static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009802 struct iw_request_info *info,
9803 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009804{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009805 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009806 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009807 switch (priv->ieee->mode) {
9808 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009809 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9810 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009811 case IEEE_B:
9812 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9813 break;
9814 case IEEE_A | IEEE_B:
9815 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9816 break;
9817 case IEEE_G:
9818 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9819 break;
9820 case IEEE_A | IEEE_G:
9821 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9822 break;
9823 case IEEE_B | IEEE_G:
9824 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9825 break;
9826 case IEEE_A | IEEE_B | IEEE_G:
9827 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9828 break;
9829 default:
9830 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009831 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009832 }
9833
James Ketrenos43f66a62005-03-25 12:31:53 -06009834 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9835
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009836 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009837 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009838
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009839 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009840}
9841
James Ketrenosea2b26e2005-08-24 21:25:16 -05009842static int ipw_wx_set_preamble(struct net_device *dev,
9843 struct iw_request_info *info,
9844 union iwreq_data *wrqu, char *extra)
9845{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009846 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009847 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009848 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009849 /* Switching from SHORT -> LONG requires a disassociation */
9850 if (mode == 1) {
9851 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9852 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009853
9854 /* Network configuration changed -- force [re]association */
9855 IPW_DEBUG_ASSOC
9856 ("[re]association triggered due to preamble change.\n");
9857 if (!ipw_disassociate(priv))
9858 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009859 }
9860 goto done;
9861 }
9862
9863 if (mode == 0) {
9864 priv->config &= ~CFG_PREAMBLE_LONG;
9865 goto done;
9866 }
Zhu Yi46441512006-01-24 16:37:59 +08009867 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009868 return -EINVAL;
9869
9870 done:
Zhu Yi46441512006-01-24 16:37:59 +08009871 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009872 return 0;
9873}
9874
9875static int ipw_wx_get_preamble(struct net_device *dev,
9876 struct iw_request_info *info,
9877 union iwreq_data *wrqu, char *extra)
9878{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009879 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009880 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 if (priv->config & CFG_PREAMBLE_LONG)
9882 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9883 else
9884 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009885 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009886 return 0;
9887}
9888
James Ketrenosb095c382005-08-24 22:04:42 -05009889#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009890static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009891 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009892 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009893{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009894 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009895 int *parms = (int *)extra;
9896 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009897 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009898 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009899 if (enable) {
9900 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009901#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009902 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9903#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009904 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009905#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009906 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009907 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009908
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 ipw_set_channel(priv, parms[1]);
9910 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009911 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009912 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009914 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009915 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009916 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 }
Zhu Yi46441512006-01-24 16:37:59 +08009918 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009919 return 0;
9920}
9921
Pavel Machek67fd6b42006-07-11 15:34:05 +02009922#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009923
Jeff Garzikbf794512005-07-31 13:07:26 -04009924static int ipw_wx_reset(struct net_device *dev,
9925 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009926 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009927{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009928 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009929 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009930 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 return 0;
9932}
James Ketrenosb095c382005-08-24 22:04:42 -05009933
James Ketrenosb095c382005-08-24 22:04:42 -05009934static int ipw_wx_sw_reset(struct net_device *dev,
9935 struct iw_request_info *info,
9936 union iwreq_data *wrqu, char *extra)
9937{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009938 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05009939 union iwreq_data wrqu_sec = {
9940 .encoding = {
9941 .flags = IW_ENCODE_DISABLED,
9942 },
9943 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009944 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009945
9946 IPW_DEBUG_WX("SW_RESET\n");
9947
Zhu Yi46441512006-01-24 16:37:59 +08009948 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009949
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009950 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009951 if (!ret) {
9952 free_firmware();
9953 ipw_adapter_restart(priv);
9954 }
James Ketrenosb095c382005-08-24 22:04:42 -05009955
9956 /* The SW reset bit might have been toggled on by the 'disable'
9957 * module parameter, so take appropriate action */
9958 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9959
Zhu Yi46441512006-01-24 16:37:59 +08009960 mutex_unlock(&priv->mutex);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04009961 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009962 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009963
9964 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9965 /* Configuration likely changed -- force [re]association */
9966 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9967 "reset.\n");
9968 if (!ipw_disassociate(priv))
9969 ipw_associate(priv);
9970 }
9971
Zhu Yi46441512006-01-24 16:37:59 +08009972 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009973
9974 return 0;
9975}
James Ketrenos43f66a62005-03-25 12:31:53 -06009976
9977/* Rebase the WE IOCTLs to zero for the handler array */
9978#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009979static iw_handler ipw_wx_handlers[] = {
John W. Linville8cc31742009-11-13 16:56:13 -05009980 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009981 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9982 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9983 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9984 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009985 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9986 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009987 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9988 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9989 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9990 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9991 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9992 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9993 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9994 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9995 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9996 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9997 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9998 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9999 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
10000 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
10001 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
10002 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
10003 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
10004 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10005 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10006 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10007 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10008 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10009 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -050010010 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10011 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10012 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10013 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -050010014 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10015 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10016 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10017 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10018 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10019 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10020 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -060010021};
10022
James Ketrenosb095c382005-08-24 22:04:42 -050010023enum {
10024 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10025 IPW_PRIV_GET_POWER,
10026 IPW_PRIV_SET_MODE,
10027 IPW_PRIV_GET_MODE,
10028 IPW_PRIV_SET_PREAMBLE,
10029 IPW_PRIV_GET_PREAMBLE,
10030 IPW_PRIV_RESET,
10031 IPW_PRIV_SW_RESET,
10032#ifdef CONFIG_IPW2200_MONITOR
10033 IPW_PRIV_SET_MONITOR,
10034#endif
10035};
James Ketrenos43f66a62005-03-25 12:31:53 -060010036
Jeff Garzikbf794512005-07-31 13:07:26 -040010037static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -060010038 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010039 .cmd = IPW_PRIV_SET_POWER,
10040 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10041 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010042 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010043 .cmd = IPW_PRIV_GET_POWER,
10044 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10045 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010047 .cmd = IPW_PRIV_SET_MODE,
10048 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10049 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010051 .cmd = IPW_PRIV_GET_MODE,
10052 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10053 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010055 .cmd = IPW_PRIV_SET_PREAMBLE,
10056 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10057 .name = "set_preamble"},
10058 {
10059 .cmd = IPW_PRIV_GET_PREAMBLE,
10060 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10061 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010063 IPW_PRIV_RESET,
10064 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -050010065 {
10066 IPW_PRIV_SW_RESET,
10067 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10068#ifdef CONFIG_IPW2200_MONITOR
10069 {
10070 IPW_PRIV_SET_MONITOR,
10071 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10072#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -060010073};
10074
10075static iw_handler ipw_priv_handler[] = {
10076 ipw_wx_set_powermode,
10077 ipw_wx_get_powermode,
10078 ipw_wx_set_wireless_mode,
10079 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -050010080 ipw_wx_set_preamble,
10081 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -040010082 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -050010083 ipw_wx_sw_reset,
10084#ifdef CONFIG_IPW2200_MONITOR
10085 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -060010086#endif
10087};
10088
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010089static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010090 .standard = ipw_wx_handlers,
10091 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10092 .num_private = ARRAY_SIZE(ipw_priv_handler),
10093 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10094 .private = ipw_priv_handler,
10095 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010096 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -060010097};
10098
James Ketrenos43f66a62005-03-25 12:31:53 -060010099/*
10100 * Get wireless statistics.
10101 * Called by /proc/net/wireless
10102 * Also called by SIOCGIWSTATS
10103 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010104static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -060010105{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010106 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010107 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010108
James Ketrenos43f66a62005-03-25 12:31:53 -060010109 wstats = &priv->wstats;
10110
James Ketrenosea2b26e2005-08-24 21:25:16 -050010111 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -050010112 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -060010113 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10114 * and associated; if not associcated, the values are all meaningless
10115 * anyway, so set them all to NULL and INVALID */
10116 if (!(priv->status & STATUS_ASSOCIATED)) {
10117 wstats->miss.beacon = 0;
10118 wstats->discard.retries = 0;
10119 wstats->qual.qual = 0;
10120 wstats->qual.level = 0;
10121 wstats->qual.noise = 0;
10122 wstats->qual.updated = 7;
10123 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010124 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -040010126 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010127
10128 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +080010129 wstats->qual.level = priv->exp_avg_rssi;
10130 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -060010131 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +080010132 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010133
10134 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10135 wstats->discard.retries = priv->last_tx_failures;
10136 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -040010137
James Ketrenos43f66a62005-03-25 12:31:53 -060010138/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10139 goto fail_get_ordinal;
10140 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -040010141
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 return wstats;
10143}
10144
James Ketrenos43f66a62005-03-25 12:31:53 -060010145/* net device stuff */
10146
Arjan van de Ven858119e2006-01-14 13:20:43 -080010147static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010148{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010149 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010150 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010151 sys_config->answer_broadcast_ssid_probe = 0;
10152 sys_config->accept_all_data_frames = 0;
10153 sys_config->accept_non_directed_frames = 1;
10154 sys_config->exclude_unicast_unencrypted = 0;
10155 sys_config->disable_unicast_decryption = 1;
10156 sys_config->exclude_multicast_unencrypted = 0;
10157 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010158 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10159 antenna = CFG_SYS_ANTENNA_BOTH;
10160 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010161 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010162 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010163 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010164 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +020010165 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +080010166 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010167}
10168
10169static int ipw_net_open(struct net_device *dev)
10170{
James Ketrenos43f66a62005-03-25 12:31:53 -060010171 IPW_DEBUG_INFO("dev->open\n");
David S. Miller521c4d92008-07-22 18:32:47 -070010172 netif_start_queue(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010173 return 0;
10174}
10175
10176static int ipw_net_stop(struct net_device *dev)
10177{
10178 IPW_DEBUG_INFO("dev->close\n");
10179 netif_stop_queue(dev);
10180 return 0;
10181}
10182
10183/*
10184todo:
10185
10186modify to send one tfd per fragment instead of using chunking. otherwise
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010187we need to heavily modify the libipw_skb_to_txb.
James Ketrenos43f66a62005-03-25 12:31:53 -060010188*/
10189
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010190static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010191 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010192{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010193 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010194 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 int i = 0;
10196 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010197#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010198 int tx_id = ipw_get_tx_queue_number(priv, pri);
10199 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10200#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010201 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010202#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 struct clx2_queue *q = &txq->q;
10204 u8 id, hdr_len, unicast;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010205 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010206
Zhu Yib8ddafd2008-11-27 13:42:20 +080010207 if (!(priv->status & STATUS_ASSOCIATED))
10208 goto drop;
10209
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010210 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 switch (priv->ieee->iw_mode) {
10212 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010213 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010214 id = ipw_find_station(priv, hdr->addr1);
10215 if (id == IPW_INVALID_STATION) {
10216 id = ipw_add_station(priv, hdr->addr1);
10217 if (id == IPW_INVALID_STATION) {
10218 IPW_WARNING("Attempt to send data to "
Johannes Berge1749612008-10-27 15:59:26 -070010219 "invalid cell: %pM\n",
10220 hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010221 goto drop;
10222 }
10223 }
10224 break;
10225
10226 case IW_MODE_INFRA:
10227 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010228 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010229 id = 0;
10230 break;
10231 }
10232
10233 tfd = &txq->bd[q->first_empty];
10234 txq->txb[q->first_empty] = txb;
10235 memset(tfd, 0, sizeof(*tfd));
10236 tfd->u.data.station_number = id;
10237
10238 tfd->control_flags.message_type = TX_FRAME_TYPE;
10239 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10240
10241 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010242 tfd->u.data.len = cpu_to_le16(txb->payload_size);
Jeff Garzikbf794512005-07-31 13:07:26 -040010243
James Ketrenos43f66a62005-03-25 12:31:53 -060010244 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010245 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010246 else
James Ketrenosb095c382005-08-24 22:04:42 -050010247 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010248
James Ketrenosea2b26e2005-08-24 21:25:16 -050010249 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10250 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010251
James Ketrenosc848d0a2005-08-24 21:56:24 -050010252 fc = le16_to_cpu(hdr->frame_ctl);
10253 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010254
10255 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10256
James Ketrenosb095c382005-08-24 22:04:42 -050010257 if (likely(unicast))
10258 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10259
10260 if (txb->encrypted && !priv->ieee->host_encrypt) {
10261 switch (priv->ieee->sec.level) {
10262 case SEC_LEVEL_3:
10263 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010264 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010265 /* XXX: ACK flag must be set for CCMP even if it
10266 * is a multicast/broadcast packet, because CCMP
10267 * group communication encrypted by GTK is
10268 * actually done by the AP. */
10269 if (!unicast)
10270 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10271
10272 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10273 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10274 tfd->u.data.key_index = 0;
10275 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10276 break;
10277 case SEC_LEVEL_2:
10278 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010279 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
James Ketrenosb095c382005-08-24 22:04:42 -050010280 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10281 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10282 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10283 break;
10284 case SEC_LEVEL_1:
10285 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
Zhu Yi851ca262006-08-21 11:37:58 +080010286 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
John W. Linville274bfb82008-10-29 11:35:05 -040010287 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10288 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
James Ketrenosb095c382005-08-24 22:04:42 -050010289 40)
10290 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10291 else
10292 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10293 break;
10294 case SEC_LEVEL_0:
10295 break;
10296 default:
10297 printk(KERN_ERR "Unknow security level %d\n",
10298 priv->ieee->sec.level);
10299 break;
10300 }
10301 } else
10302 /* No hardware encryption */
10303 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10304
Zhu Yie43e3c12006-04-13 17:20:45 +080010305#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010306 if (fc & IEEE80211_STYPE_QOS_DATA)
10307 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010308#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010309
James Ketrenos43f66a62005-03-25 12:31:53 -060010310 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010311 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10312 txb->nr_frags));
10313 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10314 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10315 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10316 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10317 i, le32_to_cpu(tfd->u.data.num_chunks),
10318 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010319 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010320 i, tfd->u.data.num_chunks,
10321 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010322 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 txb->fragments[i]->len - hdr_len);
10324
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010325 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010326 cpu_to_le32(pci_map_single
10327 (priv->pci_dev,
10328 txb->fragments[i]->data + hdr_len,
10329 txb->fragments[i]->len - hdr_len,
10330 PCI_DMA_TODEVICE));
10331 tfd->u.data.chunk_len[i] =
10332 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010333 }
10334
10335 if (i != txb->nr_frags) {
10336 struct sk_buff *skb;
10337 u16 remaining_bytes = 0;
10338 int j;
10339
10340 for (j = i; j < txb->nr_frags; j++)
10341 remaining_bytes += txb->fragments[j]->len - hdr_len;
10342
10343 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10344 remaining_bytes);
10345 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10346 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010347 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010348 for (j = i; j < txb->nr_frags; j++) {
10349 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010350
James Ketrenos43f66a62005-03-25 12:31:53 -060010351 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010352 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010353 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010354 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010355 }
10356 dev_kfree_skb_any(txb->fragments[i]);
10357 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010358 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010359 cpu_to_le32(pci_map_single
10360 (priv->pci_dev, skb->data,
Al Viro49587302007-12-27 01:57:47 -050010361 remaining_bytes,
James Ketrenosa613bff2005-08-24 21:43:11 -050010362 PCI_DMA_TODEVICE));
10363
Marcin Slusarz5c058632008-02-13 00:06:12 +010010364 le32_add_cpu(&tfd->u.data.num_chunks, 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010365 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010366 }
10367
10368 /* kick DMA */
10369 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10370 ipw_write32(priv, q->reg_w, q->first_empty);
10371
Dan Williams943dbef2008-02-14 17:49:41 -050010372 if (ipw_tx_queue_space(q) < q->high_mark)
James Ketrenosf6970142006-02-14 09:10:51 +080010373 netif_stop_queue(priv->net_dev);
10374
James Ketrenos227d2dc2005-07-28 16:25:55 -050010375 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010376
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010377 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010378 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010379 libipw_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010380 return NETDEV_TX_OK;
10381}
10382
10383static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10384{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010385 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010386#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010387 int tx_id = ipw_get_tx_queue_number(priv, pri);
10388 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10389#else
10390 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010391#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010392
Dan Williams943dbef2008-02-14 17:49:41 -050010393 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
James Ketrenos227d2dc2005-07-28 16:25:55 -050010394 return 1;
10395
10396 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010397}
10398
Zhu Yid685b8c2006-04-13 17:20:27 +080010399#ifdef CONFIG_IPW2200_PROMISCUOUS
10400static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010401 struct libipw_txb *txb)
Zhu Yid685b8c2006-04-13 17:20:27 +080010402{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010403 struct libipw_rx_stats dummystats;
Zhu Yid685b8c2006-04-13 17:20:27 +080010404 struct ieee80211_hdr *hdr;
10405 u8 n;
10406 u16 filter = priv->prom_priv->filter;
10407 int hdr_only = 0;
10408
10409 if (filter & IPW_PROM_NO_TX)
10410 return;
10411
10412 memset(&dummystats, 0, sizeof(dummystats));
10413
10414 /* Filtering of fragment chains is done agains the first fragment */
10415 hdr = (void *)txb->fragments[0]->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010416 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010417 if (filter & IPW_PROM_NO_MGMT)
10418 return;
10419 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10420 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010421 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010422 if (filter & IPW_PROM_NO_CTL)
10423 return;
10424 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10425 hdr_only = 1;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010426 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
Zhu Yid685b8c2006-04-13 17:20:27 +080010427 if (filter & IPW_PROM_NO_DATA)
10428 return;
10429 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10430 hdr_only = 1;
10431 }
10432
10433 for(n=0; n<txb->nr_frags; ++n) {
10434 struct sk_buff *src = txb->fragments[n];
10435 struct sk_buff *dst;
10436 struct ieee80211_radiotap_header *rt_hdr;
10437 int len;
10438
10439 if (hdr_only) {
10440 hdr = (void *)src->data;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010441 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
Zhu Yid685b8c2006-04-13 17:20:27 +080010442 } else
10443 len = src->len;
10444
Johannes Berg007e5dd2008-11-27 23:13:38 +010010445 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10446 if (!dst)
10447 continue;
Zhu Yid685b8c2006-04-13 17:20:27 +080010448
10449 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10450
10451 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10452 rt_hdr->it_pad = 0;
10453 rt_hdr->it_present = 0; /* after all, it's just an idea */
Al Viro743b84d2007-12-27 01:43:16 -050010454 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
Zhu Yid685b8c2006-04-13 17:20:27 +080010455
Al Viroe62e1ee2007-12-27 01:36:46 -050010456 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
Zhu Yid685b8c2006-04-13 17:20:27 +080010457 ieee80211chan2mhz(priv->channel));
10458 if (priv->channel > 14) /* 802.11a */
Al Viroe62e1ee2007-12-27 01:36:46 -050010459 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010460 cpu_to_le16(IEEE80211_CHAN_OFDM |
10461 IEEE80211_CHAN_5GHZ);
10462 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
Al Viroe62e1ee2007-12-27 01:36:46 -050010463 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010464 cpu_to_le16(IEEE80211_CHAN_CCK |
10465 IEEE80211_CHAN_2GHZ);
10466 else /* 802.11g */
Al Viroe62e1ee2007-12-27 01:36:46 -050010467 *(__le16*)skb_put(dst, sizeof(u16)) =
Zhu Yid685b8c2006-04-13 17:20:27 +080010468 cpu_to_le16(IEEE80211_CHAN_OFDM |
10469 IEEE80211_CHAN_2GHZ);
10470
Al Viro743b84d2007-12-27 01:43:16 -050010471 rt_hdr->it_len = cpu_to_le16(dst->len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010472
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -030010473 skb_copy_from_linear_data(src, skb_put(dst, len), len);
Zhu Yid685b8c2006-04-13 17:20:27 +080010474
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010475 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
Zhu Yid685b8c2006-04-13 17:20:27 +080010476 dev_kfree_skb_any(dst);
10477 }
10478}
10479#endif
10480
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010481static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10482 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010483{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010484 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010485 unsigned long flags;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000010486 netdev_tx_t ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010487
10488 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010489 spin_lock_irqsave(&priv->lock, flags);
10490
Zhu Yid685b8c2006-04-13 17:20:27 +080010491#ifdef CONFIG_IPW2200_PROMISCUOUS
10492 if (rtap_iface && netif_running(priv->prom_net_dev))
10493 ipw_handle_promiscuous_tx(priv, txb);
10494#endif
10495
James Ketrenos227d2dc2005-07-28 16:25:55 -050010496 ret = ipw_tx_skb(priv, txb, pri);
10497 if (ret == NETDEV_TX_OK)
10498 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010499 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010500
James Ketrenos227d2dc2005-07-28 16:25:55 -050010501 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010502}
10503
James Ketrenos43f66a62005-03-25 12:31:53 -060010504static void ipw_net_set_multicast_list(struct net_device *dev)
10505{
10506
10507}
10508
10509static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10510{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010511 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010512 struct sockaddr *addr = p;
Joe Perches0795af52007-10-03 17:59:30 -070010513
James Ketrenos43f66a62005-03-25 12:31:53 -060010514 if (!is_valid_ether_addr(addr->sa_data))
10515 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010516 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010517 priv->config |= CFG_CUSTOM_MAC;
10518 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -070010519 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10520 priv->net_dev->name, priv->mac_addr);
James Ketrenosa613bff2005-08-24 21:43:11 -050010521 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010522 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010523 return 0;
10524}
10525
Jeff Garzikbf794512005-07-31 13:07:26 -040010526static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010527 struct ethtool_drvinfo *info)
10528{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010529 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010530 char vers[64];
10531 char date[32];
10532 u32 len;
10533
10534 strcpy(info->driver, DRV_NAME);
10535 strcpy(info->version, DRV_VERSION);
10536
10537 len = sizeof(vers);
10538 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10539 len = sizeof(date);
10540 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10541
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010542 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010543 vers, date);
10544 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010545 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010546}
10547
10548static u32 ipw_ethtool_get_link(struct net_device *dev)
10549{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010550 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010551 return (priv->status & STATUS_ASSOCIATED) != 0;
10552}
10553
10554static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10555{
James Ketrenosb095c382005-08-24 22:04:42 -050010556 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010557}
10558
10559static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010560 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010561{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010562 struct ipw_priv *p = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010563
James Ketrenosb095c382005-08-24 22:04:42 -050010564 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010565 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010566 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010567 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010568 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010569 return 0;
10570}
10571
10572static int ipw_ethtool_set_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 int i;
10577
James Ketrenosb095c382005-08-24 22:04:42 -050010578 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010579 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010580 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010581 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010582 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10583 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010584 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010585 return 0;
10586}
10587
Jeff Garzik7282d492006-09-13 14:30:00 -040010588static const struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010589 .get_link = ipw_ethtool_get_link,
10590 .get_drvinfo = ipw_ethtool_get_drvinfo,
10591 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10592 .get_eeprom = ipw_ethtool_get_eeprom,
10593 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010594};
10595
David Howells7d12e782006-10-05 14:55:46 +010010596static irqreturn_t ipw_isr(int irq, void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -060010597{
10598 struct ipw_priv *priv = data;
10599 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010600
James Ketrenos43f66a62005-03-25 12:31:53 -060010601 if (!priv)
10602 return IRQ_NONE;
10603
Zhu Yi89c318e2006-06-08 22:19:49 -070010604 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010605
10606 if (!(priv->status & STATUS_INT_ENABLED)) {
Zhu Yid00d0122007-07-12 16:09:40 +080010607 /* IRQ is disabled */
James Ketrenos43f66a62005-03-25 12:31:53 -060010608 goto none;
10609 }
10610
James Ketrenosb095c382005-08-24 22:04:42 -050010611 inta = ipw_read32(priv, IPW_INTA_RW);
10612 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010613
James Ketrenos43f66a62005-03-25 12:31:53 -060010614 if (inta == 0xFFFFFFFF) {
10615 /* Hardware disappeared */
10616 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10617 goto none;
10618 }
10619
James Ketrenosb095c382005-08-24 22:04:42 -050010620 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010621 /* Shared interrupt */
10622 goto none;
10623 }
10624
10625 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010626 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010627
James Ketrenos43f66a62005-03-25 12:31:53 -060010628 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010629 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10630 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010631
James Ketrenos43f66a62005-03-25 12:31:53 -060010632 /* Cache INTA value for our tasklet */
10633 priv->isr_inta = inta;
10634
10635 tasklet_schedule(&priv->irq_tasklet);
10636
Zhu Yi89c318e2006-06-08 22:19:49 -070010637 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010638
10639 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010640 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010641 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010642 return IRQ_NONE;
10643}
10644
10645static void ipw_rf_kill(void *adapter)
10646{
10647 struct ipw_priv *priv = adapter;
10648 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010649
James Ketrenos43f66a62005-03-25 12:31:53 -060010650 spin_lock_irqsave(&priv->lock, flags);
10651
10652 if (rf_kill_active(priv)) {
10653 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10654 if (priv->workqueue)
10655 queue_delayed_work(priv->workqueue,
10656 &priv->rf_kill, 2 * HZ);
10657 goto exit_unlock;
10658 }
10659
10660 /* RF Kill is now disabled, so bring the device back up */
10661
10662 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10663 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10664 "device\n");
10665
10666 /* we can not do an adapter restart while inside an irq lock */
10667 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010668 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010669 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10670 "enabled\n");
10671
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010672 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010673 spin_unlock_irqrestore(&priv->lock, flags);
10674}
10675
David Howellsc4028952006-11-22 14:57:56 +000010676static void ipw_bg_rf_kill(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010677{
David Howellsc4028952006-11-22 14:57:56 +000010678 struct ipw_priv *priv =
10679 container_of(work, struct ipw_priv, rf_kill.work);
Zhu Yi46441512006-01-24 16:37:59 +080010680 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010681 ipw_rf_kill(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010682 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010683}
10684
Adrian Bunka73e22b2006-01-21 01:39:42 +010010685static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010686{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010687 priv->last_seq_num = -1;
10688 priv->last_frag_num = -1;
10689 priv->last_packet_time = 0;
10690
James Ketrenosa613bff2005-08-24 21:43:11 -050010691 netif_carrier_on(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010692
James Ketrenosc848d0a2005-08-24 21:56:24 -050010693 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010694 cancel_delayed_work(&priv->request_direct_scan);
10695 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010696 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010697 ipw_reset_stats(priv);
10698 /* Ensure the rate is updated immediately */
10699 priv->last_rate = ipw_get_current_rate(priv);
10700 ipw_gather_stats(priv);
10701 ipw_led_link_up(priv);
10702 notify_wx_assoc_event(priv);
10703
10704 if (priv->config & CFG_BACKGROUND_SCAN)
10705 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10706}
10707
David Howellsc4028952006-11-22 14:57:56 +000010708static void ipw_bg_link_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010709{
David Howellsc4028952006-11-22 14:57:56 +000010710 struct ipw_priv *priv =
10711 container_of(work, struct ipw_priv, link_up);
Zhu Yi46441512006-01-24 16:37:59 +080010712 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010713 ipw_link_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010714 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010715}
10716
Adrian Bunka73e22b2006-01-21 01:39:42 +010010717static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010718{
10719 ipw_led_link_down(priv);
10720 netif_carrier_off(priv->net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010721 notify_wx_assoc_event(priv);
10722
10723 /* Cancel any queued work ... */
10724 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010725 cancel_delayed_work(&priv->request_direct_scan);
10726 cancel_delayed_work(&priv->request_passive_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010727 cancel_delayed_work(&priv->adhoc_check);
10728 cancel_delayed_work(&priv->gather_stats);
10729
10730 ipw_reset_stats(priv);
10731
James Ketrenosafbf30a2005-08-25 00:05:33 -050010732 if (!(priv->status & STATUS_EXIT_PENDING)) {
10733 /* Queue up another scan... */
David Howellsc4028952006-11-22 14:57:56 +000010734 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
Dan Williams0b531672007-10-09 13:55:24 -040010735 } else
10736 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050010737}
10738
David Howellsc4028952006-11-22 14:57:56 +000010739static void ipw_bg_link_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050010740{
David Howellsc4028952006-11-22 14:57:56 +000010741 struct ipw_priv *priv =
10742 container_of(work, struct ipw_priv, link_down);
Zhu Yi46441512006-01-24 16:37:59 +080010743 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000010744 ipw_link_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080010745 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010746}
10747
Adrian Bunk2ef19e62007-12-11 23:20:22 +010010748static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010749{
10750 int ret = 0;
10751
James Ketrenos43f66a62005-03-25 12:31:53 -060010752 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010753 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010754 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010755
David Howellsc4028952006-11-22 14:57:56 +000010756 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10757 INIT_WORK(&priv->associate, ipw_bg_associate);
10758 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10759 INIT_WORK(&priv->system_config, ipw_system_config);
10760 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10761 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10762 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10763 INIT_WORK(&priv->up, ipw_bg_up);
10764 INIT_WORK(&priv->down, ipw_bg_down);
10765 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040010766 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10767 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040010768 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
David Howellsc4028952006-11-22 14:57:56 +000010769 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10770 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10771 INIT_WORK(&priv->roam, ipw_bg_roam);
10772 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10773 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10774 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10775 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10776 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10777 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10778 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
James Ketrenos43f66a62005-03-25 12:31:53 -060010779
Zhu Yie43e3c12006-04-13 17:20:45 +080010780#ifdef CONFIG_IPW2200_QOS
David Howellsc4028952006-11-22 14:57:56 +000010781 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
Zhu Yie43e3c12006-04-13 17:20:45 +080010782#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010783
10784 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10785 ipw_irq_tasklet, (unsigned long)priv);
10786
10787 return ret;
10788}
10789
James Ketrenos43f66a62005-03-25 12:31:53 -060010790static void shim__set_security(struct net_device *dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010791 struct libipw_security *sec)
James Ketrenos43f66a62005-03-25 12:31:53 -060010792{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010793 struct ipw_priv *priv = libipw_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060010794 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010795 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010796 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010797 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010798 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010799 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010800 priv->ieee->sec.flags &= ~(1 << i);
10801 else {
10802 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010803 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010804 priv->ieee->sec.flags |= (1 << i);
10805 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010806 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010807 } else if (sec->level != SEC_LEVEL_1)
10808 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 }
10810
James Ketrenosb095c382005-08-24 22:04:42 -050010811 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010812 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010813 priv->ieee->sec.active_key = sec->active_key;
10814 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010815 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010816 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010818 } else
10819 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010820
10821 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010822 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10823 priv->ieee->sec.auth_mode = sec->auth_mode;
10824 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010825 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10826 priv->capability |= CAP_SHARED_KEY;
10827 else
10828 priv->capability &= ~CAP_SHARED_KEY;
10829 priv->status |= STATUS_SECURITY_UPDATED;
10830 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010831
James Ketrenosb095c382005-08-24 22:04:42 -050010832 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10833 priv->ieee->sec.flags |= SEC_ENABLED;
10834 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010835 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010836 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010837 priv->capability |= CAP_PRIVACY_ON;
10838 else
10839 priv->capability &= ~CAP_PRIVACY_ON;
10840 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010841
James Ketrenosafbf30a2005-08-25 00:05:33 -050010842 if (sec->flags & SEC_ENCRYPT)
10843 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010844
James Ketrenosb095c382005-08-24 22:04:42 -050010845 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10846 priv->ieee->sec.level = sec->level;
10847 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010848 priv->status |= STATUS_SECURITY_UPDATED;
10849 }
10850
Zhu Yi1fbfea52005-08-05 17:22:56 +080010851 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10852 ipw_set_hwcrypto_keys(priv);
10853
Jeff Garzikbf794512005-07-31 13:07:26 -040010854 /* To match current functionality of ipw2100 (which works well w/
10855 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010856 * privacy capability changes ... */
10857#if 0
10858 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010859 (((priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010860 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010861 (!(priv->assoc_request.capability &
Al Viro5b5e8072007-12-27 01:54:06 -050010862 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010863 IPW_DEBUG_ASSOC("Disassociating due to capability "
10864 "change.\n");
10865 ipw_disassociate(priv);
10866 }
10867#endif
10868}
10869
Jeff Garzikbf794512005-07-31 13:07:26 -040010870static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010871 struct ipw_supported_rates *rates)
10872{
10873 /* TODO: Mask out rates based on priv->rates_mask */
10874
10875 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010876 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010877 switch (priv->ieee->freq_band) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010878 case LIBIPW_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -060010879 rates->ieee_mode = IPW_A_MODE;
10880 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010881 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10882 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010883 break;
10884
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010885 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010886 rates->ieee_mode = IPW_G_MODE;
10887 rates->purpose = IPW_RATE_CAPABILITIES;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010888 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10889 LIBIPW_CCK_DEFAULT_RATES_MASK);
10890 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10891 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10892 LIBIPW_OFDM_DEFAULT_RATES_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010893 }
10894 break;
10895 }
10896
10897 return 0;
10898}
10899
Jeff Garzikbf794512005-07-31 13:07:26 -040010900static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010901{
James Ketrenos43f66a62005-03-25 12:31:53 -060010902 /* This is only called from ipw_up, which resets/reloads the firmware
10903 so, we don't need to first disable the card before we configure
10904 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010905 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010906 goto error;
10907
10908 /* initialize adapter address */
10909 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10910 goto error;
10911
10912 /* set basic system config settings */
10913 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010914
10915 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10916 * Does not support BT priority yet (don't abort or defer our Tx) */
10917 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010918 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010919
10920 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10921 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010922 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010923 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10924 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010925 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010926 }
10927
Zhu Yid685b8c2006-04-13 17:20:27 +080010928#ifdef CONFIG_IPW2200_PROMISCUOUS
10929 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10930 priv->sys_config.accept_all_data_frames = 1;
10931 priv->sys_config.accept_non_directed_frames = 1;
10932 priv->sys_config.accept_all_mgmt_bcpr = 1;
10933 priv->sys_config.accept_all_mgmt_frames = 1;
10934 }
10935#endif
10936
James Ketrenosc848d0a2005-08-24 21:56:24 -050010937 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10938 priv->sys_config.answer_broadcast_ssid_probe = 1;
10939 else
10940 priv->sys_config.answer_broadcast_ssid_probe = 0;
10941
Zhu Yid685b8c2006-04-13 17:20:27 +080010942 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010943 goto error;
10944
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010945 init_supported_rates(priv, &priv->rates);
10946 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010947 goto error;
10948
10949 /* Set request-to-send threshold */
10950 if (priv->rts_threshold) {
10951 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10952 goto error;
10953 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010954#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010955 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10956 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010957#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010958
10959 if (ipw_set_random_seed(priv))
10960 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010961
James Ketrenos43f66a62005-03-25 12:31:53 -060010962 /* final state transition to the RUN state */
10963 if (ipw_send_host_complete(priv))
10964 goto error;
10965
James Ketrenose6666192005-08-12 09:17:04 -050010966 priv->status |= STATUS_INIT;
10967
10968 ipw_led_init(priv);
10969 ipw_led_radio_on(priv);
10970 priv->notif_missed_beacons = 0;
10971
10972 /* Set hardware WEP key if it is configured. */
10973 if ((priv->capability & CAP_PRIVACY_ON) &&
10974 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10975 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10976 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010977
10978 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010979
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010980 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010981 return -EIO;
10982}
10983
James Ketrenos4f36f802005-08-03 20:36:56 -050010984/*
10985 * NOTE:
10986 *
10987 * These tables have been tested in conjunction with the
10988 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10989 *
10990 * Altering this values, using it on other hardware, or in geographies
10991 * not intended for resale of the above mentioned Intel adapters has
10992 * not been tested.
10993 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010994 * Remember to update the table in README.ipw2200 when changing this
10995 * table.
10996 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010997 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040010998static const struct libipw_geo ipw_geos[] = {
James Ketrenos4f36f802005-08-03 20:36:56 -050010999 { /* Restricted */
11000 "---",
11001 .bg_channels = 11,
11002 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11003 {2427, 4}, {2432, 5}, {2437, 6},
11004 {2442, 7}, {2447, 8}, {2452, 9},
11005 {2457, 10}, {2462, 11}},
11006 },
11007
11008 { /* Custom US/Canada */
11009 "ZZF",
11010 .bg_channels = 11,
11011 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11012 {2427, 4}, {2432, 5}, {2437, 6},
11013 {2442, 7}, {2447, 8}, {2452, 9},
11014 {2457, 10}, {2462, 11}},
11015 .a_channels = 8,
11016 .a = {{5180, 36},
11017 {5200, 40},
11018 {5220, 44},
11019 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011020 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11021 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11022 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11023 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011024 },
11025
11026 { /* Rest of World */
11027 "ZZD",
11028 .bg_channels = 13,
11029 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11030 {2427, 4}, {2432, 5}, {2437, 6},
11031 {2442, 7}, {2447, 8}, {2452, 9},
11032 {2457, 10}, {2462, 11}, {2467, 12},
11033 {2472, 13}},
11034 },
11035
11036 { /* Custom USA & Europe & High */
11037 "ZZA",
11038 .bg_channels = 11,
11039 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11040 {2427, 4}, {2432, 5}, {2437, 6},
11041 {2442, 7}, {2447, 8}, {2452, 9},
11042 {2457, 10}, {2462, 11}},
11043 .a_channels = 13,
11044 .a = {{5180, 36},
11045 {5200, 40},
11046 {5220, 44},
11047 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011048 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11049 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11050 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11051 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
James Ketrenos4f36f802005-08-03 20:36:56 -050011052 {5745, 149},
11053 {5765, 153},
11054 {5785, 157},
11055 {5805, 161},
11056 {5825, 165}},
11057 },
11058
11059 { /* Custom NA & Europe */
11060 "ZZB",
11061 .bg_channels = 11,
11062 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11063 {2427, 4}, {2432, 5}, {2437, 6},
11064 {2442, 7}, {2447, 8}, {2452, 9},
11065 {2457, 10}, {2462, 11}},
11066 .a_channels = 13,
11067 .a = {{5180, 36},
11068 {5200, 40},
11069 {5220, 44},
11070 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011071 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11072 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11073 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11074 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11075 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11076 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11077 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11078 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11079 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011080 },
11081
11082 { /* Custom Japan */
11083 "ZZC",
11084 .bg_channels = 11,
11085 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11086 {2427, 4}, {2432, 5}, {2437, 6},
11087 {2442, 7}, {2447, 8}, {2452, 9},
11088 {2457, 10}, {2462, 11}},
11089 .a_channels = 4,
11090 .a = {{5170, 34}, {5190, 38},
11091 {5210, 42}, {5230, 46}},
11092 },
11093
11094 { /* Custom */
11095 "ZZM",
11096 .bg_channels = 11,
11097 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11098 {2427, 4}, {2432, 5}, {2437, 6},
11099 {2442, 7}, {2447, 8}, {2452, 9},
11100 {2457, 10}, {2462, 11}},
11101 },
11102
11103 { /* Europe */
11104 "ZZE",
11105 .bg_channels = 13,
11106 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11107 {2427, 4}, {2432, 5}, {2437, 6},
11108 {2442, 7}, {2447, 8}, {2452, 9},
11109 {2457, 10}, {2462, 11}, {2467, 12},
11110 {2472, 13}},
11111 .a_channels = 19,
11112 .a = {{5180, 36},
11113 {5200, 40},
11114 {5220, 44},
11115 {5240, 48},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011116 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11117 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11118 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11119 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11120 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11121 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11122 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11123 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11124 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11125 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11126 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11127 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11128 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11129 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11130 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011131 },
11132
11133 { /* Custom Japan */
11134 "ZZJ",
11135 .bg_channels = 14,
11136 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11137 {2427, 4}, {2432, 5}, {2437, 6},
11138 {2442, 7}, {2447, 8}, {2452, 9},
11139 {2457, 10}, {2462, 11}, {2467, 12},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011140 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011141 .a_channels = 4,
11142 .a = {{5170, 34}, {5190, 38},
11143 {5210, 42}, {5230, 46}},
11144 },
11145
James Ketrenos03520572005-10-19 16:12:31 -050011146 { /* Rest of World */
11147 "ZZR",
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 |
11154 LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos03520572005-10-19 16:12:31 -050011155 },
11156
James Ketrenos4f36f802005-08-03 20:36:56 -050011157 { /* High Band */
11158 "ZZH",
11159 .bg_channels = 13,
11160 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11161 {2427, 4}, {2432, 5}, {2437, 6},
11162 {2442, 7}, {2447, 8}, {2452, 9},
11163 {2457, 10}, {2462, 11},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011164 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11165 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011166 .a_channels = 4,
11167 .a = {{5745, 149}, {5765, 153},
11168 {5785, 157}, {5805, 161}},
11169 },
11170
11171 { /* Custom Europe */
11172 "ZZG",
11173 .bg_channels = 13,
11174 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11175 {2427, 4}, {2432, 5}, {2437, 6},
11176 {2442, 7}, {2447, 8}, {2452, 9},
11177 {2457, 10}, {2462, 11},
11178 {2467, 12}, {2472, 13}},
11179 .a_channels = 4,
11180 .a = {{5180, 36}, {5200, 40},
11181 {5220, 44}, {5240, 48}},
11182 },
11183
11184 { /* Europe */
11185 "ZZK",
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},
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011191 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11192 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011193 .a_channels = 24,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011194 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11195 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11196 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11197 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11198 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11199 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11200 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11201 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11202 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11203 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11204 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11205 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11206 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11207 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11208 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11209 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11210 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11211 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11212 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11213 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11214 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11215 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11216 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11217 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011218 },
11219
11220 { /* Europe */
11221 "ZZL",
11222 .bg_channels = 11,
11223 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11224 {2427, 4}, {2432, 5}, {2437, 6},
11225 {2442, 7}, {2447, 8}, {2452, 9},
11226 {2457, 10}, {2462, 11}},
11227 .a_channels = 13,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011228 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11229 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11230 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11231 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11232 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11233 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11234 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11235 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11236 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11237 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11238 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11239 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11240 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
James Ketrenos4f36f802005-08-03 20:36:56 -050011241 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011242};
11243
James Ketrenos43f66a62005-03-25 12:31:53 -060011244#define MAX_HW_RESTARTS 5
11245static int ipw_up(struct ipw_priv *priv)
11246{
James Ketrenos4f36f802005-08-03 20:36:56 -050011247 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011248
Dan Williamsc3d72b92009-02-11 13:26:06 -050011249 /* Age scan list entries found before suspend */
11250 if (priv->suspend_time) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011251 libipw_networks_age(priv->ieee, priv->suspend_time);
Dan Williamsc3d72b92009-02-11 13:26:06 -050011252 priv->suspend_time = 0;
11253 }
11254
James Ketrenos43f66a62005-03-25 12:31:53 -060011255 if (priv->status & STATUS_EXIT_PENDING)
11256 return -EIO;
11257
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011258 if (cmdlog && !priv->cmdlog) {
Yan Burmane6e3f122006-12-02 13:38:14 +020011259 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011260 GFP_KERNEL);
11261 if (priv->cmdlog == NULL) {
11262 IPW_ERROR("Error allocating %d command log entries.\n",
11263 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011264 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011265 } else {
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011266 priv->cmdlog_len = cmdlog;
11267 }
11268 }
11269
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011270 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011271 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011272 * Also start the clocks. */
11273 rc = ipw_load(priv);
11274 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011275 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011276 return rc;
11277 }
11278
11279 ipw_init_ordinals(priv);
11280 if (!(priv->config & CFG_CUSTOM_MAC))
11281 eeprom_parse_mac(priv, priv->mac_addr);
11282 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
John W. Linville5e5eab52009-10-06 16:45:14 -040011283 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -060011284
James Ketrenos4f36f802005-08-03 20:36:56 -050011285 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11286 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11287 ipw_geos[j].name, 3))
11288 break;
11289 }
James Ketrenos03520572005-10-19 16:12:31 -050011290 if (j == ARRAY_SIZE(ipw_geos)) {
11291 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11292 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11293 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11294 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011295 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011296 }
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011297 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011298 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011299 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011300 }
11301
James Ketrenosb095c382005-08-24 22:04:42 -050011302 if (priv->status & STATUS_RF_KILL_SW) {
11303 IPW_WARNING("Radio disabled by module parameter.\n");
11304 return 0;
11305 } else if (rf_kill_active(priv)) {
11306 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11307 "Kill switch must be turned off for "
11308 "wireless networking to work.\n");
11309 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11310 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011311 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011312 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011313
11314 rc = ipw_config(priv);
11315 if (!rc) {
11316 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011317
James Ketrenose6666192005-08-12 09:17:04 -050011318 /* If configure to try and auto-associate, kick
11319 * off a scan. */
David Howellsc4028952006-11-22 14:57:56 +000011320 queue_delayed_work(priv->workqueue,
11321 &priv->request_scan, 0);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011322
James Ketrenos43f66a62005-03-25 12:31:53 -060011323 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011324 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011325
James Ketrenosc848d0a2005-08-24 21:56:24 -050011326 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011327 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11328 i, MAX_HW_RESTARTS);
11329
11330 /* We had an error bringing up the hardware, so take it
11331 * all the way back down so we can try again */
11332 ipw_down(priv);
11333 }
11334
Jeff Garzikbf794512005-07-31 13:07:26 -040011335 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011336 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011337 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011338
James Ketrenos43f66a62005-03-25 12:31:53 -060011339 return -EIO;
11340}
11341
David Howellsc4028952006-11-22 14:57:56 +000011342static void ipw_bg_up(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011343{
David Howellsc4028952006-11-22 14:57:56 +000011344 struct ipw_priv *priv =
11345 container_of(work, struct ipw_priv, up);
Zhu Yi46441512006-01-24 16:37:59 +080011346 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011347 ipw_up(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011348 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011349}
11350
James Ketrenosb095c382005-08-24 22:04:42 -050011351static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011352{
James Ketrenosb095c382005-08-24 22:04:42 -050011353 int i;
11354
11355 if (priv->status & STATUS_SCANNING) {
11356 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11357 ipw_abort_scan(priv);
11358 }
11359
11360 if (priv->status & STATUS_ASSOCIATED) {
11361 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11362 ipw_disassociate(priv);
11363 }
11364
11365 ipw_led_shutdown(priv);
11366
11367 /* Wait up to 1s for status to change to not scanning and not
11368 * associated (disassociation can take a while for a ful 802.11
11369 * exchange */
11370 for (i = 1000; i && (priv->status &
11371 (STATUS_DISASSOCIATING |
11372 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11373 udelay(10);
11374
11375 if (priv->status & (STATUS_DISASSOCIATING |
11376 STATUS_ASSOCIATED | STATUS_SCANNING))
11377 IPW_DEBUG_INFO("Still associated or scanning...\n");
11378 else
11379 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11380
James Ketrenosc848d0a2005-08-24 21:56:24 -050011381 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011382 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011383
11384 priv->status &= ~STATUS_INIT;
11385}
11386
James Ketrenos43f66a62005-03-25 12:31:53 -060011387static void ipw_down(struct ipw_priv *priv)
11388{
James Ketrenosb095c382005-08-24 22:04:42 -050011389 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11390
11391 priv->status |= STATUS_EXIT_PENDING;
11392
11393 if (ipw_is_init(priv))
11394 ipw_deinit(priv);
11395
11396 /* Wipe out the EXIT_PENDING status bit if we are not actually
11397 * exiting the module */
11398 if (!exit_pending)
11399 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011400
11401 /* tell the device to stop sending interrupts */
11402 ipw_disable_interrupts(priv);
11403
11404 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011405 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011406 netif_carrier_off(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011407
11408 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011409
11410 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011411}
11412
David Howellsc4028952006-11-22 14:57:56 +000011413static void ipw_bg_down(struct work_struct *work)
James Ketrenosc848d0a2005-08-24 21:56:24 -050011414{
David Howellsc4028952006-11-22 14:57:56 +000011415 struct ipw_priv *priv =
11416 container_of(work, struct ipw_priv, down);
Zhu Yi46441512006-01-24 16:37:59 +080011417 mutex_lock(&priv->mutex);
David Howellsc4028952006-11-22 14:57:56 +000011418 ipw_down(priv);
Zhu Yi46441512006-01-24 16:37:59 +080011419 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011420}
11421
11422/* Called by register_netdev() */
11423static int ipw_net_init(struct net_device *dev)
11424{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011425 struct ipw_priv *priv = libipw_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011426 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011427
James Ketrenosc848d0a2005-08-24 21:56:24 -050011428 if (ipw_up(priv)) {
John W. Linville8cc31742009-11-13 16:56:13 -050011429 mutex_unlock(&priv->mutex);
11430 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011431 }
11432
Zhu Yi46441512006-01-24 16:37:59 +080011433 mutex_unlock(&priv->mutex);
John W. Linville8cc31742009-11-13 16:56:13 -050011434 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011435}
11436
11437/* PCI driver stuff */
11438static struct pci_device_id card_ids[] = {
11439 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11440 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11441 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11442 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11443 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11444 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11445 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11446 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11447 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11448 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11449 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11450 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11451 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11452 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11453 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11454 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11455 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
Joe Perches8ab0ea72009-06-24 22:13:27 -070011456 {PCI_VDEVICE(INTEL, 0x104f), 0},
11457 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11458 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11459 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11460 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011461
James Ketrenos43f66a62005-03-25 12:31:53 -060011462 /* required last entry */
11463 {0,}
11464};
11465
11466MODULE_DEVICE_TABLE(pci, card_ids);
11467
11468static struct attribute *ipw_sysfs_entries[] = {
11469 &dev_attr_rf_kill.attr,
11470 &dev_attr_direct_dword.attr,
11471 &dev_attr_indirect_byte.attr,
11472 &dev_attr_indirect_dword.attr,
11473 &dev_attr_mem_gpio_reg.attr,
11474 &dev_attr_command_event_reg.attr,
11475 &dev_attr_nic_type.attr,
11476 &dev_attr_status.attr,
11477 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011478 &dev_attr_error.attr,
11479 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011480 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011481 &dev_attr_eeprom_delay.attr,
11482 &dev_attr_ucode_version.attr,
11483 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011484 &dev_attr_scan_age.attr,
11485 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011486 &dev_attr_speed_scan.attr,
11487 &dev_attr_net_stats.attr,
Zhu Yi375dd242007-02-14 16:04:24 +080011488 &dev_attr_channels.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011489#ifdef CONFIG_IPW2200_PROMISCUOUS
11490 &dev_attr_rtap_iface.attr,
11491 &dev_attr_rtap_filter.attr,
11492#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011493 NULL
11494};
11495
11496static struct attribute_group ipw_attribute_group = {
11497 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011498 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011499};
11500
Zhu Yid685b8c2006-04-13 17:20:27 +080011501#ifdef CONFIG_IPW2200_PROMISCUOUS
11502static int ipw_prom_open(struct net_device *dev)
11503{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011504 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011505 struct ipw_priv *priv = prom_priv->priv;
11506
11507 IPW_DEBUG_INFO("prom dev->open\n");
11508 netif_carrier_off(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011509
11510 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11511 priv->sys_config.accept_all_data_frames = 1;
11512 priv->sys_config.accept_non_directed_frames = 1;
11513 priv->sys_config.accept_all_mgmt_bcpr = 1;
11514 priv->sys_config.accept_all_mgmt_frames = 1;
11515
11516 ipw_send_system_config(priv);
11517 }
11518
11519 return 0;
11520}
11521
11522static int ipw_prom_stop(struct net_device *dev)
11523{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011524 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011525 struct ipw_priv *priv = prom_priv->priv;
11526
11527 IPW_DEBUG_INFO("prom dev->stop\n");
11528
11529 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11530 priv->sys_config.accept_all_data_frames = 0;
11531 priv->sys_config.accept_non_directed_frames = 0;
11532 priv->sys_config.accept_all_mgmt_bcpr = 0;
11533 priv->sys_config.accept_all_mgmt_frames = 0;
11534
11535 ipw_send_system_config(priv);
11536 }
11537
11538 return 0;
11539}
11540
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000011541static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11542 struct net_device *dev)
Zhu Yid685b8c2006-04-13 17:20:27 +080011543{
11544 IPW_DEBUG_INFO("prom dev->xmit\n");
Patrick McHardy4153e772009-06-12 04:08:02 +000011545 dev_kfree_skb(skb);
11546 return NETDEV_TX_OK;
Zhu Yid685b8c2006-04-13 17:20:27 +080011547}
11548
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011549static const struct net_device_ops ipw_prom_netdev_ops = {
11550 .ndo_open = ipw_prom_open,
11551 .ndo_stop = ipw_prom_stop,
11552 .ndo_start_xmit = ipw_prom_hard_start_xmit,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011553 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011554 .ndo_set_mac_address = eth_mac_addr,
11555 .ndo_validate_addr = eth_validate_addr,
11556};
11557
Zhu Yid685b8c2006-04-13 17:20:27 +080011558static int ipw_prom_alloc(struct ipw_priv *priv)
11559{
11560 int rc = 0;
11561
11562 if (priv->prom_net_dev)
11563 return -EPERM;
11564
John W. Linville8cc31742009-11-13 16:56:13 -050011565 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
Zhu Yid685b8c2006-04-13 17:20:27 +080011566 if (priv->prom_net_dev == NULL)
11567 return -ENOMEM;
11568
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011569 priv->prom_priv = libipw_priv(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011570 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11571 priv->prom_priv->priv = priv;
11572
11573 strcpy(priv->prom_net_dev->name, "rtap%d");
Daniel Drake3f2eeac2008-04-02 20:33:54 +010011574 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
Zhu Yid685b8c2006-04-13 17:20:27 +080011575
11576 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011577 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
Zhu Yid685b8c2006-04-13 17:20:27 +080011578
11579 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +090011580 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011581
11582 rc = register_netdev(priv->prom_net_dev);
11583 if (rc) {
John W. Linville8cc31742009-11-13 16:56:13 -050011584 free_ieee80211(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011585 priv->prom_net_dev = NULL;
11586 return rc;
11587 }
11588
11589 return 0;
11590}
11591
11592static void ipw_prom_free(struct ipw_priv *priv)
11593{
11594 if (!priv->prom_net_dev)
11595 return;
11596
11597 unregister_netdev(priv->prom_net_dev);
John W. Linville8cc31742009-11-13 16:56:13 -050011598 free_ieee80211(priv->prom_net_dev);
Zhu Yid685b8c2006-04-13 17:20:27 +080011599
11600 priv->prom_net_dev = NULL;
11601}
11602
11603#endif
11604
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011605static const struct net_device_ops ipw_netdev_ops = {
11606 .ndo_init = ipw_net_init,
11607 .ndo_open = ipw_net_open,
11608 .ndo_stop = ipw_net_stop,
11609 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11610 .ndo_set_mac_address = ipw_net_set_mac_address,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011611 .ndo_start_xmit = libipw_xmit,
11612 .ndo_change_mtu = libipw_change_mtu,
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011613 .ndo_validate_addr = eth_validate_addr,
11614};
Zhu Yid685b8c2006-04-13 17:20:27 +080011615
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011616static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11617 const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011618{
11619 int err = 0;
11620 struct net_device *net_dev;
11621 void __iomem *base;
11622 u32 length, val;
11623 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011624 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011625
John W. Linville8cc31742009-11-13 16:56:13 -050011626 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
James Ketrenos43f66a62005-03-25 12:31:53 -060011627 if (net_dev == NULL) {
11628 err = -ENOMEM;
11629 goto out;
11630 }
11631
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040011632 priv = libipw_priv(net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011633 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011634
James Ketrenos43f66a62005-03-25 12:31:53 -060011635 priv->net_dev = net_dev;
11636 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011637 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011638 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011639 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011640 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11641 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011642
Zhu Yi46441512006-01-24 16:37:59 +080011643 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011644 if (pci_enable_device(pdev)) {
11645 err = -ENODEV;
11646 goto out_free_ieee80211;
11647 }
11648
11649 pci_set_master(pdev);
11650
Yang Hongyang284901a2009-04-06 19:01:15 -070011651 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Jeff Garzikbf794512005-07-31 13:07:26 -040011652 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -070011653 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
James Ketrenos43f66a62005-03-25 12:31:53 -060011654 if (err) {
11655 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11656 goto out_pci_disable_device;
11657 }
11658
11659 pci_set_drvdata(pdev, priv);
11660
11661 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011662 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011663 goto out_pci_disable_device;
11664
Jeff Garzikbf794512005-07-31 13:07:26 -040011665 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011666 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011667 pci_read_config_dword(pdev, 0x40, &val);
11668 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011669 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011670
James Ketrenos43f66a62005-03-25 12:31:53 -060011671 length = pci_resource_len(pdev, 0);
11672 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011673
Arjan van de Ven275f1652008-10-20 21:42:39 -070011674 base = pci_ioremap_bar(pdev, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011675 if (!base) {
11676 err = -ENODEV;
11677 goto out_pci_release_regions;
11678 }
11679
11680 priv->hw_base = base;
11681 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11682 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11683
11684 err = ipw_setup_deferred_work(priv);
11685 if (err) {
11686 IPW_ERROR("Unable to setup deferred work\n");
11687 goto out_iounmap;
11688 }
11689
James Ketrenosb095c382005-08-24 22:04:42 -050011690 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011691
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011692 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011693 if (err) {
11694 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11695 goto out_destroy_workqueue;
11696 }
11697
James Ketrenos43f66a62005-03-25 12:31:53 -060011698 SET_NETDEV_DEV(net_dev, &pdev->dev);
11699
Zhu Yi46441512006-01-24 16:37:59 +080011700 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011701
James Ketrenos43f66a62005-03-25 12:31:53 -060011702 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11703 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011704 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011705
Zhu Yie43e3c12006-04-13 17:20:45 +080011706#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011707 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011708 priv->ieee->handle_probe_response = ipw_handle_beacon;
11709 priv->ieee->handle_beacon = ipw_handle_probe_response;
11710 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011711#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011712
James Ketrenosc848d0a2005-08-24 21:56:24 -050011713 priv->ieee->perfect_rssi = -20;
11714 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011715
Stephen Hemminger44e9ad02009-03-20 19:36:41 +000011716 net_dev->netdev_ops = &ipw_netdev_ops;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011717 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011718 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011719 net_dev->wireless_handlers = &ipw_wx_handler_def;
11720 net_dev->ethtool_ops = &ipw_ethtool_ops;
11721 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011722 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011723 net_dev->mem_start = pci_resource_start(pdev, 0);
11724 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11725
11726 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11727 if (err) {
11728 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011729 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011730 goto out_release_irq;
11731 }
11732
Zhu Yi46441512006-01-24 16:37:59 +080011733 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011734 err = register_netdev(net_dev);
11735 if (err) {
11736 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011737 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011738 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011739
Zhu Yid685b8c2006-04-13 17:20:27 +080011740#ifdef CONFIG_IPW2200_PROMISCUOUS
11741 if (rtap_iface) {
11742 err = ipw_prom_alloc(priv);
11743 if (err) {
11744 IPW_ERROR("Failed to register promiscuous network "
11745 "device (error %d).\n", err);
11746 unregister_netdev(priv->net_dev);
11747 goto out_remove_sysfs;
11748 }
11749 }
11750#endif
11751
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011752 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11753 "channels, %d 802.11a channels)\n",
11754 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11755 priv->ieee->geo.a_channels);
11756
James Ketrenos43f66a62005-03-25 12:31:53 -060011757 return 0;
11758
James Ketrenosa613bff2005-08-24 21:43:11 -050011759 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011760 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011761 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011762 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011763 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011764 destroy_workqueue(priv->workqueue);
11765 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011766 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011767 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011768 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011769 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011770 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011771 pci_disable_device(pdev);
11772 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011773 out_free_ieee80211:
John W. Linville8cc31742009-11-13 16:56:13 -050011774 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011775 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011776 return err;
11777}
11778
Adrian Bunk2ef19e62007-12-11 23:20:22 +010011779static void __devexit ipw_pci_remove(struct pci_dev *pdev)
James Ketrenos43f66a62005-03-25 12:31:53 -060011780{
11781 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011782 struct list_head *p, *q;
11783 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011784
James Ketrenos43f66a62005-03-25 12:31:53 -060011785 if (!priv)
11786 return;
11787
Zhu Yi46441512006-01-24 16:37:59 +080011788 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011789
James Ketrenosafbf30a2005-08-25 00:05:33 -050011790 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011791 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011792 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11793
Zhu Yi46441512006-01-24 16:37:59 +080011794 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011795
11796 unregister_netdev(priv->net_dev);
11797
11798 if (priv->rxq) {
11799 ipw_rx_queue_free(priv, priv->rxq);
11800 priv->rxq = NULL;
11801 }
11802 ipw_tx_queue_free(priv);
11803
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011804 if (priv->cmdlog) {
11805 kfree(priv->cmdlog);
11806 priv->cmdlog = NULL;
11807 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011808 /* ipw_down will ensure that there is no more pending work
11809 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011810 cancel_delayed_work(&priv->adhoc_check);
11811 cancel_delayed_work(&priv->gather_stats);
11812 cancel_delayed_work(&priv->request_scan);
Dan Williamsea177302008-06-02 17:51:23 -040011813 cancel_delayed_work(&priv->request_direct_scan);
11814 cancel_delayed_work(&priv->request_passive_scan);
Dan Williams0b531672007-10-09 13:55:24 -040011815 cancel_delayed_work(&priv->scan_event);
James Ketrenosa613bff2005-08-24 21:43:11 -050011816 cancel_delayed_work(&priv->rf_kill);
11817 cancel_delayed_work(&priv->scan_check);
11818 destroy_workqueue(priv->workqueue);
11819 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011820
James Ketrenosafbf30a2005-08-25 00:05:33 -050011821 /* Free MAC hash list for ADHOC */
11822 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11823 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011824 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011825 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011826 }
11827 }
11828
Jesper Juhl8f760782006-06-27 02:55:06 -070011829 kfree(priv->error);
11830 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011831
Zhu Yid685b8c2006-04-13 17:20:27 +080011832#ifdef CONFIG_IPW2200_PROMISCUOUS
11833 ipw_prom_free(priv);
11834#endif
11835
James Ketrenos43f66a62005-03-25 12:31:53 -060011836 free_irq(pdev->irq, priv);
11837 iounmap(priv->hw_base);
11838 pci_release_regions(pdev);
11839 pci_disable_device(pdev);
11840 pci_set_drvdata(pdev, NULL);
John W. Linville8cc31742009-11-13 16:56:13 -050011841 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011842 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011843}
11844
James Ketrenos43f66a62005-03-25 12:31:53 -060011845#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011846static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011847{
11848 struct ipw_priv *priv = pci_get_drvdata(pdev);
11849 struct net_device *dev = priv->net_dev;
11850
11851 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11852
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011853 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011854 ipw_down(priv);
11855
11856 /* Remove the PRESENT state of the device */
11857 netif_device_detach(dev);
11858
James Ketrenos43f66a62005-03-25 12:31:53 -060011859 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011860 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011861 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011862
Dan Williamsc3d72b92009-02-11 13:26:06 -050011863 priv->suspend_at = get_seconds();
11864
James Ketrenos43f66a62005-03-25 12:31:53 -060011865 return 0;
11866}
11867
11868static int ipw_pci_resume(struct pci_dev *pdev)
11869{
11870 struct ipw_priv *priv = pci_get_drvdata(pdev);
11871 struct net_device *dev = priv->net_dev;
John W. Linville02e0e5e2006-11-07 20:53:48 -050011872 int err;
James Ketrenos43f66a62005-03-25 12:31:53 -060011873 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011874
James Ketrenos43f66a62005-03-25 12:31:53 -060011875 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11876
James Ketrenosea2b26e2005-08-24 21:25:16 -050011877 pci_set_power_state(pdev, PCI_D0);
John W. Linville02e0e5e2006-11-07 20:53:48 -050011878 err = pci_enable_device(pdev);
11879 if (err) {
11880 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11881 dev->name);
11882 return err;
11883 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011884 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011885
James Ketrenos43f66a62005-03-25 12:31:53 -060011886 /*
11887 * Suspend/Resume resets the PCI configuration space, so we have to
11888 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11889 * from interfering with C3 CPU state. pci_restore_state won't help
11890 * here since it only restores the first 64 bytes pci config header.
11891 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011892 pci_read_config_dword(pdev, 0x40, &val);
11893 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011894 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11895
11896 /* Set the device back into the PRESENT state; this will also wake
11897 * the queue of needed */
11898 netif_device_attach(dev);
11899
Dan Williamsc3d72b92009-02-11 13:26:06 -050011900 priv->suspend_time = get_seconds() - priv->suspend_at;
11901
James Ketrenos43f66a62005-03-25 12:31:53 -060011902 /* Bring the device back up */
11903 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011904
James Ketrenos43f66a62005-03-25 12:31:53 -060011905 return 0;
11906}
11907#endif
11908
Zhu Yic8c22c92006-08-21 11:38:39 +080011909static void ipw_pci_shutdown(struct pci_dev *pdev)
11910{
11911 struct ipw_priv *priv = pci_get_drvdata(pdev);
11912
11913 /* Take down the device; powers it off, etc. */
11914 ipw_down(priv);
11915
11916 pci_disable_device(pdev);
11917}
11918
James Ketrenos43f66a62005-03-25 12:31:53 -060011919/* driver initialization stuff */
11920static struct pci_driver ipw_driver = {
11921 .name = DRV_NAME,
11922 .id_table = card_ids,
11923 .probe = ipw_pci_probe,
11924 .remove = __devexit_p(ipw_pci_remove),
11925#ifdef CONFIG_PM
11926 .suspend = ipw_pci_suspend,
11927 .resume = ipw_pci_resume,
11928#endif
Zhu Yic8c22c92006-08-21 11:38:39 +080011929 .shutdown = ipw_pci_shutdown,
James Ketrenos43f66a62005-03-25 12:31:53 -060011930};
11931
11932static int __init ipw_init(void)
11933{
11934 int ret;
11935
11936 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11937 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11938
Jeff Garzik29917622006-08-19 17:48:59 -040011939 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060011940 if (ret) {
11941 IPW_ERROR("Unable to initialize PCI module\n");
11942 return ret;
11943 }
11944
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011945 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011946 if (ret) {
11947 IPW_ERROR("Unable to create driver sysfs file\n");
11948 pci_unregister_driver(&ipw_driver);
11949 return ret;
11950 }
11951
11952 return ret;
11953}
11954
11955static void __exit ipw_exit(void)
11956{
11957 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11958 pci_unregister_driver(&ipw_driver);
11959}
11960
11961module_param(disable, int, 0444);
11962MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11963
11964module_param(associate, int, 0444);
Tim Gardner5c7f9b72008-10-14 10:38:03 -060011965MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
James Ketrenos43f66a62005-03-25 12:31:53 -060011966
11967module_param(auto_create, int, 0444);
11968MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11969
Reinette Chatre21f8a732009-08-18 10:25:05 -070011970module_param_named(led, led_support, int, 0444);
Niels de Vos61a2d072008-07-31 00:07:23 -070011971MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
James Ketrenosa613bff2005-08-24 21:43:11 -050011972
James Ketrenos43f66a62005-03-25 12:31:53 -060011973module_param(debug, int, 0444);
11974MODULE_PARM_DESC(debug, "debug output mask");
11975
Reinette Chatre21f8a732009-08-18 10:25:05 -070011976module_param_named(channel, default_channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011977MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011978
Zhu Yid685b8c2006-04-13 17:20:27 +080011979#ifdef CONFIG_IPW2200_PROMISCUOUS
11980module_param(rtap_iface, int, 0444);
11981MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11982#endif
11983
Zhu Yie43e3c12006-04-13 17:20:45 +080011984#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011985module_param(qos_enable, int, 0444);
11986MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011987
James Ketrenosb095c382005-08-24 22:04:42 -050011988module_param(qos_burst_enable, int, 0444);
11989MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11990
11991module_param(qos_no_ack_mask, int, 0444);
11992MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11993
11994module_param(burst_duration_CCK, int, 0444);
11995MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11996
11997module_param(burst_duration_OFDM, int, 0444);
11998MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011999#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050012000
12001#ifdef CONFIG_IPW2200_MONITOR
Reinette Chatre21f8a732009-08-18 10:25:05 -070012002module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012003MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12004#else
Reinette Chatre21f8a732009-08-18 10:25:05 -070012005module_param_named(mode, network_mode, int, 0444);
James Ketrenos43f66a62005-03-25 12:31:53 -060012006MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12007#endif
12008
Zhu Yi810dabd2006-01-24 16:36:59 +080012009module_param(bt_coexist, int, 0444);
12010MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12011
James Ketrenosb095c382005-08-24 22:04:42 -050012012module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080012013MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050012014
James Ketrenosf6c5cb72005-08-25 00:39:09 -050012015module_param(cmdlog, int, 0444);
12016MODULE_PARM_DESC(cmdlog,
12017 "allocate a ring buffer for logging firmware commands");
12018
Zhu Yi4bfdb912006-01-24 16:37:16 +080012019module_param(roaming, int, 0444);
12020MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12021
Zhu Yid2b83e12006-04-13 17:19:36 +080012022module_param(antenna, int, 0444);
12023MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12024
James Ketrenos43f66a62005-03-25 12:31:53 -060012025module_exit(ipw_exit);
12026module_init(ipw_init);