blob: 94172558cd03a879440d88e749f9aabb2ebf6c56 [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:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
Zhu Yi7c567892006-02-24 04:20:48 +080036#define IPW2200_VERSION "git-1.1.1"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080038#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060039#define DRV_VERSION IPW2200_VERSION
40
James Ketrenosb095c382005-08-24 22:04:42 -050041#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
James Ketrenos43f66a62005-03-25 12:31:53 -060043MODULE_DESCRIPTION(DRV_DESCRIPTION);
44MODULE_VERSION(DRV_VERSION);
45MODULE_AUTHOR(DRV_COPYRIGHT);
46MODULE_LICENSE("GPL");
47
James Ketrenosf6c5cb72005-08-25 00:39:09 -050048static int cmdlog = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080049#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060050static int debug = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080051#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060052static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060053static int mode = 0;
54
55static u32 ipw_debug_level;
56static int associate = 1;
57static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050058static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060059static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080060static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080061static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080062static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060063static const char ipw_modes[] = {
64 'a', 'b', 'g', '?'
65};
Zhu Yid2b83e12006-04-13 17:19:36 +080066static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -060067
Zhu Yid685b8c2006-04-13 17:20:27 +080068#ifdef CONFIG_IPW2200_PROMISCUOUS
69static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
70#endif
71
72
James Ketrenosb095c382005-08-24 22:04:42 -050073#ifdef CONFIG_IPW_QOS
74static int qos_enable = 0;
75static int qos_burst_enable = 0;
76static int qos_no_ack_mask = 0;
77static int burst_duration_CCK = 0;
78static int burst_duration_OFDM = 0;
79
80static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
81 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
82 QOS_TX3_CW_MIN_OFDM},
83 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
84 QOS_TX3_CW_MAX_OFDM},
85 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
86 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
87 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
88 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
89};
90
91static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
92 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
93 QOS_TX3_CW_MIN_CCK},
94 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
95 QOS_TX3_CW_MAX_CCK},
96 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
97 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
98 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
99 QOS_TX3_TXOP_LIMIT_CCK}
100};
101
102static struct ieee80211_qos_parameters def_parameters_OFDM = {
103 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
104 DEF_TX3_CW_MIN_OFDM},
105 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
106 DEF_TX3_CW_MAX_OFDM},
107 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
108 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
109 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
110 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
111};
112
113static struct ieee80211_qos_parameters def_parameters_CCK = {
114 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
115 DEF_TX3_CW_MIN_CCK},
116 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
117 DEF_TX3_CW_MAX_CCK},
118 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
119 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
120 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
121 DEF_TX3_TXOP_LIMIT_CCK}
122};
123
124static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
125
126static int from_priority_to_tx_queue[] = {
127 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
128 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
129};
130
131static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
132
133static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
134 *qos_param);
135static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
136 *qos_param);
137#endif /* CONFIG_IPW_QOS */
138
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000139static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500140static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600141static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400142static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600143 struct clx2_tx_queue *txq, int qindex);
144static int ipw_queue_reset(struct ipw_priv *priv);
145
146static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
147 int len, int sync);
148
149static void ipw_tx_queue_free(struct ipw_priv *);
150
151static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
152static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
153static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600154static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500155static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600156static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500157static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600158static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400159static int init_supported_rates(struct ipw_priv *priv,
160 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500161static void ipw_set_hwcrypto_keys(struct ipw_priv *);
162static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600163
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500164static int snprint_line(char *buf, size_t count,
165 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600166{
167 int out, i, j, l;
168 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400169
James Ketrenos43f66a62005-03-25 12:31:53 -0600170 out = snprintf(buf, count, "%08X", ofs);
171
172 for (l = 0, i = 0; i < 2; i++) {
173 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400174 for (j = 0; j < 8 && l < len; j++, l++)
175 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600176 data[(i * 8 + j)]);
177 for (; j < 8; j++)
178 out += snprintf(buf + out, count - out, " ");
179 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400180
James Ketrenos43f66a62005-03-25 12:31:53 -0600181 out += snprintf(buf + out, count - out, " ");
182 for (l = 0, i = 0; i < 2; i++) {
183 out += snprintf(buf + out, count - out, " ");
184 for (j = 0; j < 8 && l < len; j++, l++) {
185 c = data[(i * 8 + j)];
186 if (!isascii(c) || !isprint(c))
187 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400188
James Ketrenos43f66a62005-03-25 12:31:53 -0600189 out += snprintf(buf + out, count - out, "%c", c);
190 }
191
192 for (; j < 8; j++)
193 out += snprintf(buf + out, count - out, " ");
194 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400195
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500196 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600197}
198
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400199static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600200{
201 char line[81];
202 u32 ofs = 0;
203 if (!(ipw_debug_level & level))
204 return;
205
206 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500207 snprint_line(line, sizeof(line), &data[ofs],
208 min(len, 16U), ofs);
209 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600210 ofs += 16;
211 len -= min(len, 16U);
212 }
213}
214
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500215static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
216{
217 size_t out = size;
218 u32 ofs = 0;
219 int total = 0;
220
221 while (size && len) {
222 out = snprint_line(output, size, &data[ofs],
223 min_t(size_t, len, 16U), ofs);
224
225 ofs += 16;
226 output += out;
227 size -= out;
228 len -= min_t(size_t, len, 16U);
229 total += out;
230 }
231 return total;
232}
233
Zhu Yic8fe6672006-01-24 16:36:36 +0800234/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600235static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
236#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
237
Zhu Yic8fe6672006-01-24 16:36:36 +0800238/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600239static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
240#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
241
Zhu Yic8fe6672006-01-24 16:36:36 +0800242/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600243static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
244static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
245{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400246 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
247 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600248 _ipw_write_reg8(a, b, c);
249}
250
Zhu Yic8fe6672006-01-24 16:36:36 +0800251/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600252static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
253static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
254{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400255 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
256 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600257 _ipw_write_reg16(a, b, c);
258}
259
Zhu Yic8fe6672006-01-24 16:36:36 +0800260/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600261static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
262static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
263{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400264 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
265 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600266 _ipw_write_reg32(a, b, c);
267}
268
Zhu Yic8fe6672006-01-24 16:36:36 +0800269/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600270#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800271
272/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600273#define ipw_write8(ipw, ofs, val) \
274 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
275 _ipw_write8(ipw, ofs, val)
276
Zhu Yic8fe6672006-01-24 16:36:36 +0800277/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600278#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800279
280/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600281#define ipw_write16(ipw, ofs, val) \
282 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
283 _ipw_write16(ipw, ofs, val)
284
Zhu Yic8fe6672006-01-24 16:36:36 +0800285/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600286#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800287
288/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600289#define ipw_write32(ipw, ofs, val) \
290 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
291 _ipw_write32(ipw, ofs, val)
292
Zhu Yic8fe6672006-01-24 16:36:36 +0800293/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600294#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800295
296/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400297static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
298{
299 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600300 return _ipw_read8(ipw, ofs);
301}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400302
Zhu Yic8fe6672006-01-24 16:36:36 +0800303/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600304#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
305
Zhu Yic8fe6672006-01-24 16:36:36 +0800306/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600307#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800308
309/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400310static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
311{
312 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600313 return _ipw_read16(ipw, ofs);
314}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315
Zhu Yic8fe6672006-01-24 16:36:36 +0800316/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600317#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
318
Zhu Yic8fe6672006-01-24 16:36:36 +0800319/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600320#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800321
322/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400323static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
324{
325 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 return _ipw_read32(ipw, ofs);
327}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400328
Zhu Yic8fe6672006-01-24 16:36:36 +0800329/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600330#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
331
Zhu Yic8fe6672006-01-24 16:36:36 +0800332/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600333static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500334static inline void __ipw_read_indirect(const char *f, int l,
335 struct ipw_priv *a, u32 b, u8 * c, int d)
336{
337 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
338 d);
339 _ipw_read_indirect(a, b, c, d);
340}
341
Zhu Yic8fe6672006-01-24 16:36:36 +0800342/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500343#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600344
Zhu Yic8fe6672006-01-24 16:36:36 +0800345/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400346static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
347 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600348#define ipw_write_indirect(a, b, c, d) \
349 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500350 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600351
Zhu Yic8fe6672006-01-24 16:36:36 +0800352/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400353static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600354{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400355 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500356 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
357 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600358}
359
Zhu Yic8fe6672006-01-24 16:36:36 +0800360/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600361static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
362{
Zhu Yi2638bc32006-01-24 16:37:52 +0800363 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800364 u32 dif_len = reg - aligned_addr;
365
James Ketrenos43f66a62005-03-25 12:31:53 -0600366 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800367 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
368 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600369}
370
Zhu Yic8fe6672006-01-24 16:36:36 +0800371/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400372static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600373{
Zhu Yi2638bc32006-01-24 16:37:52 +0800374 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800375 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
376
James Ketrenos43f66a62005-03-25 12:31:53 -0600377 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800378 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
379 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600380}
381
Zhu Yic8fe6672006-01-24 16:36:36 +0800382/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600383static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
384{
385 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500386 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600387 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500388 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400389 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600390}
391
Zhu Yic8fe6672006-01-24 16:36:36 +0800392/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600393static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
394{
395 u32 value;
396
397 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
398
James Ketrenosb095c382005-08-24 22:04:42 -0500399 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
400 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600401 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
402 return value;
403}
404
Zhu Yic8fe6672006-01-24 16:36:36 +0800405/* General purpose, no alignment requirement, iterative (multi-byte) read, */
406/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600407static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
408 int num)
409{
Zhu Yi2638bc32006-01-24 16:37:52 +0800410 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600411 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600412 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400413
James Ketrenos43f66a62005-03-25 12:31:53 -0600414 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
415
James Ketrenosea2b26e2005-08-24 21:25:16 -0500416 if (num <= 0) {
417 return;
418 }
419
Zhu Yic8fe6672006-01-24 16:36:36 +0800420 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600421 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500422 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600423 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500424 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500425 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600426 aligned_addr += 4;
427 }
428
Zhu Yic8fe6672006-01-24 16:36:36 +0800429 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500430 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500431 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500432 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400433
Zhu Yic8fe6672006-01-24 16:36:36 +0800434 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500435 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500436 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500437 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500438 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500439 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600440}
441
Zhu Yic8fe6672006-01-24 16:36:36 +0800442/* General purpose, no alignment requirement, iterative (multi-byte) write, */
443/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400444static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600445 int num)
446{
Zhu Yi2638bc32006-01-24 16:37:52 +0800447 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600448 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400450
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400452
James Ketrenosea2b26e2005-08-24 21:25:16 -0500453 if (num <= 0) {
454 return;
455 }
456
Zhu Yic8fe6672006-01-24 16:36:36 +0800457 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600458 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800460 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500462 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600463 aligned_addr += 4;
464 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500468 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500469 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400470
Zhu Yic8fe6672006-01-24 16:36:36 +0800471 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500472 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500474 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500475 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500476 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600477}
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479/* General purpose, no alignment requirement, iterative (multi-byte) write, */
480/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400481static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600482 int num)
483{
484 memcpy_toio((priv->hw_base + addr), buf, num);
485}
486
Zhu Yic8fe6672006-01-24 16:36:36 +0800487/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600488static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
489{
490 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
491}
492
Zhu Yic8fe6672006-01-24 16:36:36 +0800493/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600494static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
495{
496 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
497}
498
499static inline void ipw_enable_interrupts(struct ipw_priv *priv)
500{
501 if (priv->status & STATUS_INT_ENABLED)
502 return;
503 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500504 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600505}
506
507static inline void ipw_disable_interrupts(struct ipw_priv *priv)
508{
509 if (!(priv->status & STATUS_INT_ENABLED))
510 return;
511 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500512 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600513}
514
Brice Goglin0f52bf92005-12-01 01:41:46 -0800515#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600516static char *ipw_error_desc(u32 val)
517{
518 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400519 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600520 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400521 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600522 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400523 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400525 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600526 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400527 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500528 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400529 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500530 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400531 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500532 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400533 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500534 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400535 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500536 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400537 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500538 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400539 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500540 return "DMA_STATUS";
541 case IPW_FW_ERROR_DINO_ERROR:
542 return "DINO_ERROR";
543 case IPW_FW_ERROR_EEPROM_ERROR:
544 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400545 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500546 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400547 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500548 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400549 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500550 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600551 }
552}
553
James Ketrenosb39860c2005-08-12 09:36:32 -0500554static void ipw_dump_error_log(struct ipw_priv *priv,
555 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600556{
James Ketrenosb39860c2005-08-12 09:36:32 -0500557 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600558
James Ketrenosb39860c2005-08-12 09:36:32 -0500559 if (!error) {
560 IPW_ERROR("Error allocating and capturing error log. "
561 "Nothing to dump.\n");
562 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600563 }
564
James Ketrenosb39860c2005-08-12 09:36:32 -0500565 IPW_ERROR("Start IPW Error Log Dump:\n");
566 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
567 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600568
James Ketrenosb39860c2005-08-12 09:36:32 -0500569 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400570 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500571 ipw_error_desc(error->elem[i].desc),
572 error->elem[i].time,
573 error->elem[i].blink1,
574 error->elem[i].blink2,
575 error->elem[i].link1,
576 error->elem[i].link2, error->elem[i].data);
577 for (i = 0; i < error->log_len; i++)
578 IPW_ERROR("%i\t0x%08x\t%i\n",
579 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500580 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600581}
James Ketrenos43f66a62005-03-25 12:31:53 -0600582#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600583
James Ketrenosc848d0a2005-08-24 21:56:24 -0500584static inline int ipw_is_init(struct ipw_priv *priv)
585{
586 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600587}
588
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400589static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600590{
591 u32 addr, field_info, field_len, field_count, total_len;
592
593 IPW_DEBUG_ORD("ordinal = %i\n", ord);
594
595 if (!priv || !val || !len) {
596 IPW_DEBUG_ORD("Invalid argument\n");
597 return -EINVAL;
598 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400599
James Ketrenos43f66a62005-03-25 12:31:53 -0600600 /* verify device ordinal tables have been initialized */
601 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
602 IPW_DEBUG_ORD("Access ordinals before initialization\n");
603 return -EINVAL;
604 }
605
606 switch (IPW_ORD_TABLE_ID_MASK & ord) {
607 case IPW_ORD_TABLE_0_MASK:
608 /*
609 * TABLE 0: Direct access to a table of 32 bit values
610 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400611 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600612 * read from the table
613 */
614
615 /* remove the table id from the ordinal */
616 ord &= IPW_ORD_TABLE_VALUE_MASK;
617
618 /* boundary check */
619 if (ord > priv->table0_len) {
620 IPW_DEBUG_ORD("ordinal value (%i) longer then "
621 "max (%i)\n", ord, priv->table0_len);
622 return -EINVAL;
623 }
624
625 /* verify we have enough room to store the value */
626 if (*len < sizeof(u32)) {
627 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200628 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600629 return -EINVAL;
630 }
631
632 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400633 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600634
635 *len = sizeof(u32);
636 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400637 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600638 break;
639
640 case IPW_ORD_TABLE_1_MASK:
641 /*
642 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400643 *
644 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600645 * representing starting addr for the data (which is
646 * also a u32)
647 */
648
649 /* remove the table id from the ordinal */
650 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400651
James Ketrenos43f66a62005-03-25 12:31:53 -0600652 /* boundary check */
653 if (ord > priv->table1_len) {
654 IPW_DEBUG_ORD("ordinal value too long\n");
655 return -EINVAL;
656 }
657
658 /* verify we have enough room to store the value */
659 if (*len < sizeof(u32)) {
660 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200661 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600662 return -EINVAL;
663 }
664
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400665 *((u32 *) val) =
666 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600667 *len = sizeof(u32);
668 break;
669
670 case IPW_ORD_TABLE_2_MASK:
671 /*
672 * TABLE 2: Indirect access to a table of variable sized values
673 *
674 * This table consist of six values, each containing
675 * - dword containing the starting offset of the data
676 * - dword containing the lengh in the first 16bits
677 * and the count in the second 16bits
678 */
679
680 /* remove the table id from the ordinal */
681 ord &= IPW_ORD_TABLE_VALUE_MASK;
682
683 /* boundary check */
684 if (ord > priv->table2_len) {
685 IPW_DEBUG_ORD("ordinal value too long\n");
686 return -EINVAL;
687 }
688
689 /* get the address of statistic */
690 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400691
692 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600693 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400694 field_info =
695 ipw_read_reg32(priv,
696 priv->table2_addr + (ord << 3) +
697 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400698
James Ketrenos43f66a62005-03-25 12:31:53 -0600699 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400700 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400701
James Ketrenos43f66a62005-03-25 12:31:53 -0600702 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400703 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400704
James Ketrenos43f66a62005-03-25 12:31:53 -0600705 /* abort if not enought memory */
706 total_len = field_len * field_count;
707 if (total_len > *len) {
708 *len = total_len;
709 return -EINVAL;
710 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400711
James Ketrenos43f66a62005-03-25 12:31:53 -0600712 *len = total_len;
713 if (!total_len)
714 return 0;
715
716 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400717 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600718 addr, total_len, field_info);
719 ipw_read_indirect(priv, addr, val, total_len);
720 break;
721
722 default:
723 IPW_DEBUG_ORD("Invalid ordinal!\n");
724 return -EINVAL;
725
726 }
727
James Ketrenos43f66a62005-03-25 12:31:53 -0600728 return 0;
729}
730
731static void ipw_init_ordinals(struct ipw_priv *priv)
732{
733 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400734 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600735
736 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
737 priv->table0_addr, priv->table0_len);
738
739 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
740 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
741
742 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
743 priv->table1_addr, priv->table1_len);
744
745 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
746 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400747 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600748
749 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
750 priv->table2_addr, priv->table2_len);
751
752}
753
Adrian Bunka73e22b2006-01-21 01:39:42 +0100754static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500755{
James Ketrenosb095c382005-08-24 22:04:42 -0500756 reg &= ~IPW_START_STANDBY;
757 if (reg & IPW_GATE_ODMA)
758 reg &= ~IPW_GATE_ODMA;
759 if (reg & IPW_GATE_IDMA)
760 reg &= ~IPW_GATE_IDMA;
761 if (reg & IPW_GATE_ADMA)
762 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500763 return reg;
764}
765
766/*
767 * LED behavior:
768 * - On radio ON, turn on any LEDs that require to be on during start
769 * - On initialization, start unassociated blink
770 * - On association, disable unassociated blink
771 * - On disassociation, start unassociated blink
772 * - On radio OFF, turn off any LEDs started during radio on
773 *
774 */
Zhu Yiede61112006-01-24 16:37:10 +0800775#define LD_TIME_LINK_ON msecs_to_jiffies(300)
776#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
777#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500778
Adrian Bunka73e22b2006-01-21 01:39:42 +0100779static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500780{
781 unsigned long flags;
782 u32 led;
783
784 /* If configured to not use LEDs, or nic_type is 1,
785 * then we don't toggle a LINK led */
786 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
787 return;
788
789 spin_lock_irqsave(&priv->lock, flags);
790
791 if (!(priv->status & STATUS_RF_KILL_MASK) &&
792 !(priv->status & STATUS_LED_LINK_ON)) {
793 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500794 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500795 led |= priv->led_association_on;
796
797 led = ipw_register_toggle(led);
798
799 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500800 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500801
802 priv->status |= STATUS_LED_LINK_ON;
803
804 /* If we aren't associated, schedule turning the LED off */
805 if (!(priv->status & STATUS_ASSOCIATED))
806 queue_delayed_work(priv->workqueue,
807 &priv->led_link_off,
808 LD_TIME_LINK_ON);
809 }
810
811 spin_unlock_irqrestore(&priv->lock, flags);
812}
813
James Ketrenosc848d0a2005-08-24 21:56:24 -0500814static void ipw_bg_led_link_on(void *data)
815{
816 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800817 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500818 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800819 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500820}
821
Adrian Bunka73e22b2006-01-21 01:39:42 +0100822static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500823{
824 unsigned long flags;
825 u32 led;
826
827 /* If configured not to use LEDs, or nic type is 1,
828 * then we don't goggle the LINK led. */
829 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
830 return;
831
832 spin_lock_irqsave(&priv->lock, flags);
833
834 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500835 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500836 led &= priv->led_association_off;
837 led = ipw_register_toggle(led);
838
839 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500840 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500841
842 IPW_DEBUG_LED("Link LED Off\n");
843
844 priv->status &= ~STATUS_LED_LINK_ON;
845
846 /* If we aren't associated and the radio is on, schedule
847 * turning the LED on (blink while unassociated) */
848 if (!(priv->status & STATUS_RF_KILL_MASK) &&
849 !(priv->status & STATUS_ASSOCIATED))
850 queue_delayed_work(priv->workqueue, &priv->led_link_on,
851 LD_TIME_LINK_OFF);
852
853 }
854
855 spin_unlock_irqrestore(&priv->lock, flags);
856}
857
James Ketrenosc848d0a2005-08-24 21:56:24 -0500858static void ipw_bg_led_link_off(void *data)
859{
860 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800861 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500862 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800863 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500864}
865
Arjan van de Ven858119e2006-01-14 13:20:43 -0800866static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500867{
James Ketrenosa613bff2005-08-24 21:43:11 -0500868 u32 led;
869
870 if (priv->config & CFG_NO_LED)
871 return;
872
James Ketrenosb095c382005-08-24 22:04:42 -0500873 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500874 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500875
876 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500877 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500878 led |= priv->led_activity_on;
879
880 led = ipw_register_toggle(led);
881
882 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500883 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500884
885 IPW_DEBUG_LED("Activity LED On\n");
886
887 priv->status |= STATUS_LED_ACT_ON;
888
James Ketrenosc848d0a2005-08-24 21:56:24 -0500889 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500890 queue_delayed_work(priv->workqueue, &priv->led_act_off,
891 LD_TIME_ACT_ON);
892 } else {
893 /* Reschedule LED off for full time period */
894 cancel_delayed_work(&priv->led_act_off);
895 queue_delayed_work(priv->workqueue, &priv->led_act_off,
896 LD_TIME_ACT_ON);
897 }
James Ketrenosb095c382005-08-24 22:04:42 -0500898}
James Ketrenosa613bff2005-08-24 21:43:11 -0500899
Adrian Bunka73e22b2006-01-21 01:39:42 +0100900#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500901void ipw_led_activity_on(struct ipw_priv *priv)
902{
903 unsigned long flags;
904 spin_lock_irqsave(&priv->lock, flags);
905 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500906 spin_unlock_irqrestore(&priv->lock, flags);
907}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100908#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500909
Adrian Bunka73e22b2006-01-21 01:39:42 +0100910static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500911{
912 unsigned long flags;
913 u32 led;
914
915 if (priv->config & CFG_NO_LED)
916 return;
917
918 spin_lock_irqsave(&priv->lock, flags);
919
920 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500921 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500922 led &= priv->led_activity_off;
923
924 led = ipw_register_toggle(led);
925
926 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500927 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500928
929 IPW_DEBUG_LED("Activity LED Off\n");
930
931 priv->status &= ~STATUS_LED_ACT_ON;
932 }
933
934 spin_unlock_irqrestore(&priv->lock, flags);
935}
936
James Ketrenosc848d0a2005-08-24 21:56:24 -0500937static void ipw_bg_led_activity_off(void *data)
938{
939 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800940 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500941 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800942 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500943}
944
Adrian Bunka73e22b2006-01-21 01:39:42 +0100945static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500946{
947 unsigned long flags;
948 u32 led;
949
950 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500951 if (priv->config & CFG_NO_LED ||
952 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500953 return;
954
955 spin_lock_irqsave(&priv->lock, flags);
956
James Ketrenosb095c382005-08-24 22:04:42 -0500957 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500958 if (priv->assoc_network->mode == IEEE_A) {
959 led |= priv->led_ofdm_on;
960 led &= priv->led_association_off;
961 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
962 } else if (priv->assoc_network->mode == IEEE_G) {
963 led |= priv->led_ofdm_on;
964 led |= priv->led_association_on;
965 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
966 } else {
967 led &= priv->led_ofdm_off;
968 led |= priv->led_association_on;
969 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
970 }
971
972 led = ipw_register_toggle(led);
973
974 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500975 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500976
977 spin_unlock_irqrestore(&priv->lock, flags);
978}
979
Adrian Bunka73e22b2006-01-21 01:39:42 +0100980static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500981{
982 unsigned long flags;
983 u32 led;
984
985 /* Only nic type 1 supports mode LEDs */
986 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
987 return;
988
989 spin_lock_irqsave(&priv->lock, flags);
990
James Ketrenosb095c382005-08-24 22:04:42 -0500991 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500992 led &= priv->led_ofdm_off;
993 led &= priv->led_association_off;
994
995 led = ipw_register_toggle(led);
996
997 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500998 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500999
1000 spin_unlock_irqrestore(&priv->lock, flags);
1001}
1002
Adrian Bunka73e22b2006-01-21 01:39:42 +01001003static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001004{
1005 ipw_led_link_on(priv);
1006}
1007
Adrian Bunka73e22b2006-01-21 01:39:42 +01001008static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001009{
1010 ipw_led_activity_off(priv);
1011 ipw_led_link_off(priv);
1012}
1013
Adrian Bunka73e22b2006-01-21 01:39:42 +01001014static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001015{
1016 /* Set the Link Led on for all nic types */
1017 ipw_led_link_on(priv);
1018}
1019
Adrian Bunka73e22b2006-01-21 01:39:42 +01001020static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001021{
1022 ipw_led_activity_off(priv);
1023 ipw_led_link_off(priv);
1024
1025 if (priv->status & STATUS_RF_KILL_MASK)
1026 ipw_led_radio_off(priv);
1027}
1028
Adrian Bunka73e22b2006-01-21 01:39:42 +01001029static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001030{
1031 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1032
1033 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001034 priv->led_activity_on = IPW_ACTIVITY_LED;
1035 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001036
James Ketrenosb095c382005-08-24 22:04:42 -05001037 priv->led_association_on = IPW_ASSOCIATED_LED;
1038 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001039
1040 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001041 priv->led_ofdm_on = IPW_OFDM_LED;
1042 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001043
1044 switch (priv->nic_type) {
1045 case EEPROM_NIC_TYPE_1:
1046 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001047 priv->led_activity_on = IPW_ASSOCIATED_LED;
1048 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1049 priv->led_association_on = IPW_ACTIVITY_LED;
1050 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001051
1052 if (!(priv->config & CFG_NO_LED))
1053 ipw_led_band_on(priv);
1054
1055 /* And we don't blink link LEDs for this nic, so
1056 * just return here */
1057 return;
1058
1059 case EEPROM_NIC_TYPE_3:
1060 case EEPROM_NIC_TYPE_2:
1061 case EEPROM_NIC_TYPE_4:
1062 case EEPROM_NIC_TYPE_0:
1063 break;
1064
1065 default:
1066 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1067 priv->nic_type);
1068 priv->nic_type = EEPROM_NIC_TYPE_0;
1069 break;
1070 }
1071
1072 if (!(priv->config & CFG_NO_LED)) {
1073 if (priv->status & STATUS_ASSOCIATED)
1074 ipw_led_link_on(priv);
1075 else
1076 ipw_led_link_off(priv);
1077 }
1078}
1079
Adrian Bunka73e22b2006-01-21 01:39:42 +01001080static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001081{
James Ketrenosa613bff2005-08-24 21:43:11 -05001082 ipw_led_activity_off(priv);
1083 ipw_led_link_off(priv);
1084 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001085 cancel_delayed_work(&priv->led_link_on);
1086 cancel_delayed_work(&priv->led_link_off);
1087 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001088}
1089
James Ketrenos43f66a62005-03-25 12:31:53 -06001090/*
1091 * The following adds a new attribute to the sysfs representation
1092 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1093 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001094 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001095 * See the level definitions in ipw for details.
1096 */
1097static ssize_t show_debug_level(struct device_driver *d, char *buf)
1098{
1099 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1100}
James Ketrenosa613bff2005-08-24 21:43:11 -05001101
1102static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1103 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001104{
1105 char *p = (char *)buf;
1106 u32 val;
1107
1108 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1109 p++;
1110 if (p[0] == 'x' || p[0] == 'X')
1111 p++;
1112 val = simple_strtoul(p, &p, 16);
1113 } else
1114 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001115 if (p == buf)
1116 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001117 ": %s is not in hex or decimal form.\n", buf);
1118 else
1119 ipw_debug_level = val;
1120
1121 return strnlen(buf, count);
1122}
1123
Jeff Garzikbf794512005-07-31 13:07:26 -04001124static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001125 show_debug_level, store_debug_level);
1126
James Ketrenosb39860c2005-08-12 09:36:32 -05001127static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1128{
Zhu Yic8fe6672006-01-24 16:36:36 +08001129 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001130 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1131}
1132
1133static void ipw_capture_event_log(struct ipw_priv *priv,
1134 u32 log_len, struct ipw_event *log)
1135{
1136 u32 base;
1137
1138 if (log_len) {
1139 base = ipw_read32(priv, IPW_EVENT_LOG);
1140 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1141 (u8 *) log, sizeof(*log) * log_len);
1142 }
1143}
1144
1145static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1146{
1147 struct ipw_fw_error *error;
1148 u32 log_len = ipw_get_event_log_len(priv);
1149 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1150 u32 elem_len = ipw_read_reg32(priv, base);
1151
1152 error = kmalloc(sizeof(*error) +
1153 sizeof(*error->elem) * elem_len +
1154 sizeof(*error->log) * log_len, GFP_ATOMIC);
1155 if (!error) {
1156 IPW_ERROR("Memory allocation for firmware error log "
1157 "failed.\n");
1158 return NULL;
1159 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001160 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001161 error->status = priv->status;
1162 error->config = priv->config;
1163 error->elem_len = elem_len;
1164 error->log_len = log_len;
1165 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001166 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001167
1168 ipw_capture_event_log(priv, log_len, error->log);
1169
1170 if (elem_len)
1171 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1172 sizeof(*error->elem) * elem_len);
1173
1174 return error;
1175}
1176
1177static void ipw_free_error_log(struct ipw_fw_error *error)
1178{
1179 if (error)
1180 kfree(error);
1181}
1182
1183static ssize_t show_event_log(struct device *d,
1184 struct device_attribute *attr, char *buf)
1185{
1186 struct ipw_priv *priv = dev_get_drvdata(d);
1187 u32 log_len = ipw_get_event_log_len(priv);
1188 struct ipw_event log[log_len];
1189 u32 len = 0, i;
1190
1191 ipw_capture_event_log(priv, log_len, log);
1192
1193 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1194 for (i = 0; i < log_len; i++)
1195 len += snprintf(buf + len, PAGE_SIZE - len,
1196 "\n%08X%08X%08X",
1197 log[i].time, log[i].event, log[i].data);
1198 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1199 return len;
1200}
1201
1202static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1203
1204static ssize_t show_error(struct device *d,
1205 struct device_attribute *attr, char *buf)
1206{
1207 struct ipw_priv *priv = dev_get_drvdata(d);
1208 u32 len = 0, i;
1209 if (!priv->error)
1210 return 0;
1211 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001212 "%08lX%08X%08X%08X",
1213 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001214 priv->error->status,
1215 priv->error->config, priv->error->elem_len);
1216 for (i = 0; i < priv->error->elem_len; i++)
1217 len += snprintf(buf + len, PAGE_SIZE - len,
1218 "\n%08X%08X%08X%08X%08X%08X%08X",
1219 priv->error->elem[i].time,
1220 priv->error->elem[i].desc,
1221 priv->error->elem[i].blink1,
1222 priv->error->elem[i].blink2,
1223 priv->error->elem[i].link1,
1224 priv->error->elem[i].link2,
1225 priv->error->elem[i].data);
1226
1227 len += snprintf(buf + len, PAGE_SIZE - len,
1228 "\n%08X", priv->error->log_len);
1229 for (i = 0; i < priv->error->log_len; i++)
1230 len += snprintf(buf + len, PAGE_SIZE - len,
1231 "\n%08X%08X%08X",
1232 priv->error->log[i].time,
1233 priv->error->log[i].event,
1234 priv->error->log[i].data);
1235 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1236 return len;
1237}
1238
1239static ssize_t clear_error(struct device *d,
1240 struct device_attribute *attr,
1241 const char *buf, size_t count)
1242{
1243 struct ipw_priv *priv = dev_get_drvdata(d);
1244 if (priv->error) {
1245 ipw_free_error_log(priv->error);
1246 priv->error = NULL;
1247 }
1248 return count;
1249}
1250
1251static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1252
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001253static ssize_t show_cmd_log(struct device *d,
1254 struct device_attribute *attr, char *buf)
1255{
1256 struct ipw_priv *priv = dev_get_drvdata(d);
1257 u32 len = 0, i;
1258 if (!priv->cmdlog)
1259 return 0;
1260 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1261 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1262 i = (i + 1) % priv->cmdlog_len) {
1263 len +=
1264 snprintf(buf + len, PAGE_SIZE - len,
1265 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1266 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1267 priv->cmdlog[i].cmd.len);
1268 len +=
1269 snprintk_buf(buf + len, PAGE_SIZE - len,
1270 (u8 *) priv->cmdlog[i].cmd.param,
1271 priv->cmdlog[i].cmd.len);
1272 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1273 }
1274 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1275 return len;
1276}
1277
1278static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1279
Zhu Yid685b8c2006-04-13 17:20:27 +08001280#ifdef CONFIG_IPW2200_PROMISCUOUS
1281static void ipw_prom_free(struct ipw_priv *priv);
1282static int ipw_prom_alloc(struct ipw_priv *priv);
1283static ssize_t store_rtap_iface(struct device *d,
1284 struct device_attribute *attr,
1285 const char *buf, size_t count)
1286{
1287 struct ipw_priv *priv = dev_get_drvdata(d);
1288 int rc = 0;
1289
1290 if (count < 1)
1291 return -EINVAL;
1292
1293 switch (buf[0]) {
1294 case '0':
1295 if (!rtap_iface)
1296 return count;
1297
1298 if (netif_running(priv->prom_net_dev)) {
1299 IPW_WARNING("Interface is up. Cannot unregister.\n");
1300 return count;
1301 }
1302
1303 ipw_prom_free(priv);
1304 rtap_iface = 0;
1305 break;
1306
1307 case '1':
1308 if (rtap_iface)
1309 return count;
1310
1311 rc = ipw_prom_alloc(priv);
1312 if (!rc)
1313 rtap_iface = 1;
1314 break;
1315
1316 default:
1317 return -EINVAL;
1318 }
1319
1320 if (rc) {
1321 IPW_ERROR("Failed to register promiscuous network "
1322 "device (error %d).\n", rc);
1323 }
1324
1325 return count;
1326}
1327
1328static ssize_t show_rtap_iface(struct device *d,
1329 struct device_attribute *attr,
1330 char *buf)
1331{
1332 struct ipw_priv *priv = dev_get_drvdata(d);
1333 if (rtap_iface)
1334 return sprintf(buf, "%s", priv->prom_net_dev->name);
1335 else {
1336 buf[0] = '-';
1337 buf[1] = '1';
1338 buf[2] = '\0';
1339 return 3;
1340 }
1341}
1342
1343static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1344 store_rtap_iface);
1345
1346static ssize_t store_rtap_filter(struct device *d,
1347 struct device_attribute *attr,
1348 const char *buf, size_t count)
1349{
1350 struct ipw_priv *priv = dev_get_drvdata(d);
1351
1352 if (!priv->prom_priv) {
1353 IPW_ERROR("Attempting to set filter without "
1354 "rtap_iface enabled.\n");
1355 return -EPERM;
1356 }
1357
1358 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1359
1360 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1361 BIT_ARG16(priv->prom_priv->filter));
1362
1363 return count;
1364}
1365
1366static ssize_t show_rtap_filter(struct device *d,
1367 struct device_attribute *attr,
1368 char *buf)
1369{
1370 struct ipw_priv *priv = dev_get_drvdata(d);
1371 return sprintf(buf, "0x%04X",
1372 priv->prom_priv ? priv->prom_priv->filter : 0);
1373}
1374
1375static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1376 store_rtap_filter);
1377#endif
1378
James Ketrenosa613bff2005-08-24 21:43:11 -05001379static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1380 char *buf)
1381{
1382 struct ipw_priv *priv = dev_get_drvdata(d);
1383 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1384}
1385
1386static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1387 const char *buf, size_t count)
1388{
1389 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001390#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001391 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001392#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001393 char buffer[] = "00000000";
1394 unsigned long len =
1395 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1396 unsigned long val;
1397 char *p = buffer;
1398
1399 IPW_DEBUG_INFO("enter\n");
1400
1401 strncpy(buffer, buf, len);
1402 buffer[len] = 0;
1403
1404 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1405 p++;
1406 if (p[0] == 'x' || p[0] == 'X')
1407 p++;
1408 val = simple_strtoul(p, &p, 16);
1409 } else
1410 val = simple_strtoul(p, &p, 10);
1411 if (p == buffer) {
1412 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1413 } else {
1414 priv->ieee->scan_age = val;
1415 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1416 }
1417
1418 IPW_DEBUG_INFO("exit\n");
1419 return len;
1420}
1421
1422static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1423
1424static ssize_t show_led(struct device *d, struct device_attribute *attr,
1425 char *buf)
1426{
1427 struct ipw_priv *priv = dev_get_drvdata(d);
1428 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1429}
1430
1431static ssize_t store_led(struct device *d, struct device_attribute *attr,
1432 const char *buf, size_t count)
1433{
1434 struct ipw_priv *priv = dev_get_drvdata(d);
1435
1436 IPW_DEBUG_INFO("enter\n");
1437
1438 if (count == 0)
1439 return 0;
1440
1441 if (*buf == 0) {
1442 IPW_DEBUG_LED("Disabling LED control.\n");
1443 priv->config |= CFG_NO_LED;
1444 ipw_led_shutdown(priv);
1445 } else {
1446 IPW_DEBUG_LED("Enabling LED control.\n");
1447 priv->config &= ~CFG_NO_LED;
1448 ipw_led_init(priv);
1449 }
1450
1451 IPW_DEBUG_INFO("exit\n");
1452 return count;
1453}
1454
1455static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1456
Andrew Mortonad3fee52005-06-20 14:30:36 -07001457static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001458 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001459{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001460 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001461 return sprintf(buf, "0x%08x\n", (int)p->status);
1462}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001463
James Ketrenos43f66a62005-03-25 12:31:53 -06001464static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1465
Andrew Mortonad3fee52005-06-20 14:30:36 -07001466static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1467 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001468{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001469 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001470 return sprintf(buf, "0x%08x\n", (int)p->config);
1471}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001472
James Ketrenos43f66a62005-03-25 12:31:53 -06001473static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1474
Andrew Mortonad3fee52005-06-20 14:30:36 -07001475static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001476 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001477{
James Ketrenosa613bff2005-08-24 21:43:11 -05001478 struct ipw_priv *priv = d->driver_data;
1479 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001480}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001481
James Ketrenos43f66a62005-03-25 12:31:53 -06001482static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1483
Andrew Mortonad3fee52005-06-20 14:30:36 -07001484static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001485 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001486{
1487 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001488 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001489
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001490 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001491 return 0;
1492
1493 return sprintf(buf, "0x%08x\n", tmp);
1494}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001495
1496static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001497
Andrew Mortonad3fee52005-06-20 14:30:36 -07001498static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1499 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001500{
1501 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001502 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001503
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001504 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001505 return 0;
1506
1507 return sprintf(buf, "0x%08x\n", tmp);
1508}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001509
1510static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001511
1512/*
1513 * Add a device attribute to view/control the delay between eeprom
1514 * operations.
1515 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001516static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001517 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001518{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001519 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001520 return sprintf(buf, "%i\n", n);
1521}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001522static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001523 struct device_attribute *attr,
1524 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001525{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001526 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001527 sscanf(buf, "%i", &p->eeprom_delay);
1528 return strnlen(buf, count);
1529}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001530
1531static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1532 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001533
Andrew Mortonad3fee52005-06-20 14:30:36 -07001534static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001535 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001536{
1537 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001538 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001539
James Ketrenosb095c382005-08-24 22:04:42 -05001540 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001541 return sprintf(buf, "0x%08x\n", reg);
1542}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001543static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001544 struct device_attribute *attr,
1545 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001546{
1547 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001548 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001549
1550 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001551 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001552 return strnlen(buf, count);
1553}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001554
1555static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1556 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001557
Andrew Mortonad3fee52005-06-20 14:30:36 -07001558static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001559 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001560{
1561 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001562 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001563
1564 reg = ipw_read_reg32(p, 0x301100);
1565 return sprintf(buf, "0x%08x\n", reg);
1566}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001567static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001568 struct device_attribute *attr,
1569 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001570{
1571 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001572 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001573
1574 sscanf(buf, "%x", &reg);
1575 ipw_write_reg32(p, 0x301100, reg);
1576 return strnlen(buf, count);
1577}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578
1579static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1580 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001581
Andrew Mortonad3fee52005-06-20 14:30:36 -07001582static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001584{
1585 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001586 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001587
Jeff Garzikbf794512005-07-31 13:07:26 -04001588 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001589 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001590 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001591 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001592
James Ketrenos43f66a62005-03-25 12:31:53 -06001593 return sprintf(buf, "0x%08x\n", reg);
1594}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001595static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001596 struct device_attribute *attr,
1597 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001598{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001599 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001600
1601 sscanf(buf, "%x", &priv->indirect_dword);
1602 priv->status |= STATUS_INDIRECT_DWORD;
1603 return strnlen(buf, count);
1604}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001605
1606static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1607 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001608
Andrew Mortonad3fee52005-06-20 14:30:36 -07001609static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001610 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001611{
1612 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001613 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001614
Jeff Garzikbf794512005-07-31 13:07:26 -04001615 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001616 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001617 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001618 reg = 0;
1619
1620 return sprintf(buf, "0x%02x\n", reg);
1621}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001622static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001623 struct device_attribute *attr,
1624 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001625{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001626 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001627
1628 sscanf(buf, "%x", &priv->indirect_byte);
1629 priv->status |= STATUS_INDIRECT_BYTE;
1630 return strnlen(buf, count);
1631}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001632
1633static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001634 show_indirect_byte, store_indirect_byte);
1635
Andrew Mortonad3fee52005-06-20 14:30:36 -07001636static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001637 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001638{
1639 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001640 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001641
Jeff Garzikbf794512005-07-31 13:07:26 -04001642 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001643 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001644 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001645 reg = 0;
1646
1647 return sprintf(buf, "0x%08x\n", reg);
1648}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001649static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001650 struct device_attribute *attr,
1651 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001652{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001653 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001654
1655 sscanf(buf, "%x", &priv->direct_dword);
1656 priv->status |= STATUS_DIRECT_DWORD;
1657 return strnlen(buf, count);
1658}
James Ketrenos43f66a62005-03-25 12:31:53 -06001659
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001660static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1661 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001662
Arjan van de Ven858119e2006-01-14 13:20:43 -08001663static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001664{
1665 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1666 priv->status |= STATUS_RF_KILL_HW;
1667 else
1668 priv->status &= ~STATUS_RF_KILL_HW;
1669
1670 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1671}
1672
Andrew Mortonad3fee52005-06-20 14:30:36 -07001673static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001674 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001675{
1676 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001677 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001678 2 - HW based RF kill active
1679 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001680 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001681 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001682 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001683 return sprintf(buf, "%i\n", val);
1684}
1685
1686static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1687{
Jeff Garzikbf794512005-07-31 13:07:26 -04001688 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001689 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001690 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001691
1692 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1693 disable_radio ? "OFF" : "ON");
1694
1695 if (disable_radio) {
1696 priv->status |= STATUS_RF_KILL_SW;
1697
James Ketrenosa613bff2005-08-24 21:43:11 -05001698 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001699 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001700 queue_work(priv->workqueue, &priv->down);
1701 } else {
1702 priv->status &= ~STATUS_RF_KILL_SW;
1703 if (rf_kill_active(priv)) {
1704 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1705 "disabled by HW switch\n");
1706 /* Make sure the RF_KILL check timer is running */
1707 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001708 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001709 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001710 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001711 queue_work(priv->workqueue, &priv->up);
1712 }
1713
1714 return 1;
1715}
1716
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001717static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1718 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001719{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001720 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001721
James Ketrenos43f66a62005-03-25 12:31:53 -06001722 ipw_radio_kill_sw(priv, buf[0] == '1');
1723
1724 return count;
1725}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001726
1727static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001728
James Ketrenosb095c382005-08-24 22:04:42 -05001729static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1730 char *buf)
1731{
1732 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1733 int pos = 0, len = 0;
1734 if (priv->config & CFG_SPEED_SCAN) {
1735 while (priv->speed_scan[pos] != 0)
1736 len += sprintf(&buf[len], "%d ",
1737 priv->speed_scan[pos++]);
1738 return len + sprintf(&buf[len], "\n");
1739 }
1740
1741 return sprintf(buf, "0\n");
1742}
1743
1744static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1745 const char *buf, size_t count)
1746{
1747 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1748 int channel, pos = 0;
1749 const char *p = buf;
1750
1751 /* list of space separated channels to scan, optionally ending with 0 */
1752 while ((channel = simple_strtol(p, NULL, 0))) {
1753 if (pos == MAX_SPEED_SCAN - 1) {
1754 priv->speed_scan[pos] = 0;
1755 break;
1756 }
1757
Larry Finger1867b112006-02-28 09:48:28 -06001758 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001759 priv->speed_scan[pos++] = channel;
1760 else
1761 IPW_WARNING("Skipping invalid channel request: %d\n",
1762 channel);
1763 p = strchr(p, ' ');
1764 if (!p)
1765 break;
1766 while (*p == ' ' || *p == '\t')
1767 p++;
1768 }
1769
1770 if (pos == 0)
1771 priv->config &= ~CFG_SPEED_SCAN;
1772 else {
1773 priv->speed_scan_pos = 0;
1774 priv->config |= CFG_SPEED_SCAN;
1775 }
1776
1777 return count;
1778}
1779
1780static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1781 store_speed_scan);
1782
1783static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1784 char *buf)
1785{
1786 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1787 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1788}
1789
1790static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1791 const char *buf, size_t count)
1792{
1793 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1794 if (buf[0] == '1')
1795 priv->config |= CFG_NET_STATS;
1796 else
1797 priv->config &= ~CFG_NET_STATS;
1798
1799 return count;
1800}
1801
James Ketrenosafbf30a2005-08-25 00:05:33 -05001802static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1803 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001804
James Ketrenosea2b26e2005-08-24 21:25:16 -05001805static void notify_wx_assoc_event(struct ipw_priv *priv)
1806{
1807 union iwreq_data wrqu;
1808 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1809 if (priv->status & STATUS_ASSOCIATED)
1810 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1811 else
1812 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1813 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1814}
1815
James Ketrenos43f66a62005-03-25 12:31:53 -06001816static void ipw_irq_tasklet(struct ipw_priv *priv)
1817{
1818 u32 inta, inta_mask, handled = 0;
1819 unsigned long flags;
1820 int rc = 0;
1821
1822 spin_lock_irqsave(&priv->lock, flags);
1823
James Ketrenosb095c382005-08-24 22:04:42 -05001824 inta = ipw_read32(priv, IPW_INTA_RW);
1825 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1826 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001827
1828 /* Add any cached INTA values that need to be handled */
1829 inta |= priv->isr_inta;
1830
1831 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001832 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001833 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001834 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001835 }
1836
James Ketrenosb095c382005-08-24 22:04:42 -05001837 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001838 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001839 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001840 priv->status &= ~STATUS_HCMD_ACTIVE;
1841 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001842 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001843 }
1844
James Ketrenosb095c382005-08-24 22:04:42 -05001845 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001846 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001847 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001848 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001849 }
1850
James Ketrenosb095c382005-08-24 22:04:42 -05001851 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001852 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001853 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001854 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001855 }
1856
James Ketrenosb095c382005-08-24 22:04:42 -05001857 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001858 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001859 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001860 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001861 }
1862
James Ketrenosb095c382005-08-24 22:04:42 -05001863 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001864 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001865 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001866 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001867 }
1868
James Ketrenosb095c382005-08-24 22:04:42 -05001869 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001870 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001871 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001872 }
1873
James Ketrenosb095c382005-08-24 22:04:42 -05001874 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001875 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001876 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001877 }
1878
James Ketrenosb095c382005-08-24 22:04:42 -05001879 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001880 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001881 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001882 }
1883
James Ketrenosb095c382005-08-24 22:04:42 -05001884 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001885 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001886 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001887 }
1888
James Ketrenosb095c382005-08-24 22:04:42 -05001889 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001890 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001891 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001892 }
1893
James Ketrenosb095c382005-08-24 22:04:42 -05001894 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001895 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1896 priv->status |= STATUS_RF_KILL_HW;
1897 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001898 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001899 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001900 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001901 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001902 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001903 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001904
James Ketrenosb095c382005-08-24 22:04:42 -05001905 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001906 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001907 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001908 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001909#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001910 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1911 struct ipw_fw_error *error =
1912 ipw_alloc_error_log(priv);
1913 ipw_dump_error_log(priv, error);
1914 if (error)
1915 ipw_free_error_log(error);
1916 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001917#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001918 } else {
1919 priv->error = ipw_alloc_error_log(priv);
1920 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001921 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001922 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001923 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1924 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001925#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001926 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1927 ipw_dump_error_log(priv, priv->error);
1928#endif
1929 }
1930
James Ketrenosb095c382005-08-24 22:04:42 -05001931 /* XXX: If hardware encryption is for WPA/WPA2,
1932 * we have to notify the supplicant. */
1933 if (priv->ieee->sec.encrypt) {
1934 priv->status &= ~STATUS_ASSOCIATED;
1935 notify_wx_assoc_event(priv);
1936 }
1937
1938 /* Keep the restart process from trying to send host
1939 * commands by clearing the INIT status bit */
1940 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001941
1942 /* Cancel currently queued command. */
1943 priv->status &= ~STATUS_HCMD_ACTIVE;
1944 wake_up_interruptible(&priv->wait_command_queue);
1945
James Ketrenos43f66a62005-03-25 12:31:53 -06001946 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001947 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001948 }
1949
James Ketrenosb095c382005-08-24 22:04:42 -05001950 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001951 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001952 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001953 }
1954
1955 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001956 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001957 }
1958
1959 /* enable all interrupts */
1960 ipw_enable_interrupts(priv);
1961
1962 spin_unlock_irqrestore(&priv->lock, flags);
1963}
Jeff Garzikbf794512005-07-31 13:07:26 -04001964
James Ketrenos43f66a62005-03-25 12:31:53 -06001965#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1966static char *get_cmd_string(u8 cmd)
1967{
1968 switch (cmd) {
1969 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001970 IPW_CMD(POWER_DOWN);
1971 IPW_CMD(SYSTEM_CONFIG);
1972 IPW_CMD(MULTICAST_ADDRESS);
1973 IPW_CMD(SSID);
1974 IPW_CMD(ADAPTER_ADDRESS);
1975 IPW_CMD(PORT_TYPE);
1976 IPW_CMD(RTS_THRESHOLD);
1977 IPW_CMD(FRAG_THRESHOLD);
1978 IPW_CMD(POWER_MODE);
1979 IPW_CMD(WEP_KEY);
1980 IPW_CMD(TGI_TX_KEY);
1981 IPW_CMD(SCAN_REQUEST);
1982 IPW_CMD(SCAN_REQUEST_EXT);
1983 IPW_CMD(ASSOCIATE);
1984 IPW_CMD(SUPPORTED_RATES);
1985 IPW_CMD(SCAN_ABORT);
1986 IPW_CMD(TX_FLUSH);
1987 IPW_CMD(QOS_PARAMETERS);
1988 IPW_CMD(DINO_CONFIG);
1989 IPW_CMD(RSN_CAPABILITIES);
1990 IPW_CMD(RX_KEY);
1991 IPW_CMD(CARD_DISABLE);
1992 IPW_CMD(SEED_NUMBER);
1993 IPW_CMD(TX_POWER);
1994 IPW_CMD(COUNTRY_INFO);
1995 IPW_CMD(AIRONET_INFO);
1996 IPW_CMD(AP_TX_POWER);
1997 IPW_CMD(CCKM_INFO);
1998 IPW_CMD(CCX_VER_INFO);
1999 IPW_CMD(SET_CALIBRATION);
2000 IPW_CMD(SENSITIVITY_CALIB);
2001 IPW_CMD(RETRY_LIMIT);
2002 IPW_CMD(IPW_PRE_POWER_DOWN);
2003 IPW_CMD(VAP_BEACON_TEMPLATE);
2004 IPW_CMD(VAP_DTIM_PERIOD);
2005 IPW_CMD(EXT_SUPPORTED_RATES);
2006 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2007 IPW_CMD(VAP_QUIET_INTERVALS);
2008 IPW_CMD(VAP_CHANNEL_SWITCH);
2009 IPW_CMD(VAP_MANDATORY_CHANNELS);
2010 IPW_CMD(VAP_CELL_PWR_LIMIT);
2011 IPW_CMD(VAP_CF_PARAM_SET);
2012 IPW_CMD(VAP_SET_BEACONING_STATE);
2013 IPW_CMD(MEASUREMENT);
2014 IPW_CMD(POWER_CAPABILITY);
2015 IPW_CMD(SUPPORTED_CHANNELS);
2016 IPW_CMD(TPC_REPORT);
2017 IPW_CMD(WME_INFO);
2018 IPW_CMD(PRODUCTION_COMMAND);
2019 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 return "UNKNOWN";
2021 }
2022}
James Ketrenos43f66a62005-03-25 12:31:53 -06002023
2024#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002025
2026static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002027{
2028 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002029 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002030
James Ketrenosa613bff2005-08-24 21:43:11 -05002031 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002033 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2034 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002035 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002036 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002037 }
2038
2039 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002040
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002041 if (priv->cmdlog) {
2042 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2043 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2044 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2045 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2046 cmd->len);
2047 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2048 }
2049
James Ketrenosb095c382005-08-24 22:04:42 -05002050 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2051 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2052 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002053
2054#ifndef DEBUG_CMD_WEP_KEY
2055 if (cmd->cmd == IPW_CMD_WEP_KEY)
2056 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2057 else
2058#endif
2059 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2060
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002061 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002062 if (rc) {
2063 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002064 IPW_ERROR("Failed to send %s: Reason %d\n",
2065 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002066 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002067 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002068 }
2069 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002070
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002071 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2072 !(priv->
2073 status & STATUS_HCMD_ACTIVE),
2074 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002075 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002076 spin_lock_irqsave(&priv->lock, flags);
2077 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002078 IPW_ERROR("Failed to send %s: Command timed out.\n",
2079 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002080 priv->status &= ~STATUS_HCMD_ACTIVE;
2081 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002082 rc = -EIO;
2083 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002084 }
2085 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002086 } else
2087 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002088
James Ketrenosb095c382005-08-24 22:04:42 -05002089 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002090 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2091 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002092 rc = -EIO;
2093 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002094 }
2095
Zhu Yi2638bc32006-01-24 16:37:52 +08002096 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002097 if (priv->cmdlog) {
2098 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2099 priv->cmdlog_pos %= priv->cmdlog_len;
2100 }
2101 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002102}
2103
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002104static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002105{
2106 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002107 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002108 };
2109
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002110 return __ipw_send_cmd(priv, &cmd);
2111}
2112
2113static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2114 void *data)
2115{
2116 struct host_cmd cmd = {
2117 .cmd = command,
2118 .len = len,
2119 .param = data,
2120 };
2121
2122 return __ipw_send_cmd(priv, &cmd);
2123}
2124
2125static int ipw_send_host_complete(struct ipw_priv *priv)
2126{
James Ketrenos43f66a62005-03-25 12:31:53 -06002127 if (!priv) {
2128 IPW_ERROR("Invalid args\n");
2129 return -1;
2130 }
2131
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002132 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002133}
2134
Zhu Yid685b8c2006-04-13 17:20:27 +08002135static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002136{
Zhu Yid685b8c2006-04-13 17:20:27 +08002137 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2138 sizeof(priv->sys_config),
2139 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002140}
2141
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002142static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002143{
James Ketrenos43f66a62005-03-25 12:31:53 -06002144 if (!priv || !ssid) {
2145 IPW_ERROR("Invalid args\n");
2146 return -1;
2147 }
2148
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002149 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002150 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002151}
2152
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002153static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002154{
James Ketrenos43f66a62005-03-25 12:31:53 -06002155 if (!priv || !mac) {
2156 IPW_ERROR("Invalid args\n");
2157 return -1;
2158 }
2159
2160 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2161 priv->net_dev->name, MAC_ARG(mac));
2162
Zhu Yi2638bc32006-01-24 16:37:52 +08002163 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002164}
2165
James Ketrenosa613bff2005-08-24 21:43:11 -05002166/*
2167 * NOTE: This must be executed from our workqueue as it results in udelay
2168 * being called which may corrupt the keyboard if executed on default
2169 * workqueue
2170 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002171static void ipw_adapter_restart(void *adapter)
2172{
2173 struct ipw_priv *priv = adapter;
2174
2175 if (priv->status & STATUS_RF_KILL_MASK)
2176 return;
2177
2178 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002179
2180 if (priv->assoc_network &&
2181 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2182 ipw_remove_current_network(priv);
2183
James Ketrenos43f66a62005-03-25 12:31:53 -06002184 if (ipw_up(priv)) {
2185 IPW_ERROR("Failed to up device\n");
2186 return;
2187 }
2188}
2189
James Ketrenosc848d0a2005-08-24 21:56:24 -05002190static void ipw_bg_adapter_restart(void *data)
2191{
2192 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002193 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002194 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002195 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002196}
2197
James Ketrenos43f66a62005-03-25 12:31:53 -06002198#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2199
2200static void ipw_scan_check(void *data)
2201{
2202 struct ipw_priv *priv = data;
2203 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2204 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002205 "adapter after (%dms).\n",
2206 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002207 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002208 }
2209}
2210
James Ketrenosc848d0a2005-08-24 21:56:24 -05002211static void ipw_bg_scan_check(void *data)
2212{
2213 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002214 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002215 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002216 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002217}
2218
James Ketrenos43f66a62005-03-25 12:31:53 -06002219static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2220 struct ipw_scan_request_ext *request)
2221{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002222 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002223 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002224}
2225
2226static int ipw_send_scan_abort(struct ipw_priv *priv)
2227{
James Ketrenos43f66a62005-03-25 12:31:53 -06002228 if (!priv) {
2229 IPW_ERROR("Invalid args\n");
2230 return -1;
2231 }
2232
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002233 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002234}
2235
2236static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2237{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002238 struct ipw_sensitivity_calib calib = {
2239 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002240 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002241
2242 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002243 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002244}
2245
2246static int ipw_send_associate(struct ipw_priv *priv,
2247 struct ipw_associate *associate)
2248{
James Ketrenosa613bff2005-08-24 21:43:11 -05002249 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002250
2251 if (!priv || !associate) {
2252 IPW_ERROR("Invalid args\n");
2253 return -1;
2254 }
2255
James Ketrenosa613bff2005-08-24 21:43:11 -05002256 memcpy(&tmp_associate, associate, sizeof(*associate));
2257 tmp_associate.policy_support =
2258 cpu_to_le16(tmp_associate.policy_support);
2259 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2260 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2261 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2262 tmp_associate.listen_interval =
2263 cpu_to_le16(tmp_associate.listen_interval);
2264 tmp_associate.beacon_interval =
2265 cpu_to_le16(tmp_associate.beacon_interval);
2266 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2267
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002268 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002269 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002270}
2271
2272static int ipw_send_supported_rates(struct ipw_priv *priv,
2273 struct ipw_supported_rates *rates)
2274{
James Ketrenos43f66a62005-03-25 12:31:53 -06002275 if (!priv || !rates) {
2276 IPW_ERROR("Invalid args\n");
2277 return -1;
2278 }
2279
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002280 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002281 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002282}
2283
2284static int ipw_set_random_seed(struct ipw_priv *priv)
2285{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002286 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002287
2288 if (!priv) {
2289 IPW_ERROR("Invalid args\n");
2290 return -1;
2291 }
2292
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002293 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002294
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002295 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002296}
2297
James Ketrenos43f66a62005-03-25 12:31:53 -06002298static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2299{
James Ketrenos43f66a62005-03-25 12:31:53 -06002300 if (!priv) {
2301 IPW_ERROR("Invalid args\n");
2302 return -1;
2303 }
2304
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002305 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002306 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002307}
James Ketrenos43f66a62005-03-25 12:31:53 -06002308
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002309static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002310{
James Ketrenos43f66a62005-03-25 12:31:53 -06002311 if (!priv || !power) {
2312 IPW_ERROR("Invalid args\n");
2313 return -1;
2314 }
2315
Zhu Yi2638bc32006-01-24 16:37:52 +08002316 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002317}
James Ketrenos43f66a62005-03-25 12:31:53 -06002318
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002319static int ipw_set_tx_power(struct ipw_priv *priv)
2320{
Larry Finger1867b112006-02-28 09:48:28 -06002321 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002322 struct ipw_tx_power tx_power;
2323 s8 max_power;
2324 int i;
2325
2326 memset(&tx_power, 0, sizeof(tx_power));
2327
2328 /* configure device for 'G' band */
2329 tx_power.ieee_mode = IPW_G_MODE;
2330 tx_power.num_channels = geo->bg_channels;
2331 for (i = 0; i < geo->bg_channels; i++) {
2332 max_power = geo->bg[i].max_power;
2333 tx_power.channels_tx_power[i].channel_number =
2334 geo->bg[i].channel;
2335 tx_power.channels_tx_power[i].tx_power = max_power ?
2336 min(max_power, priv->tx_power) : priv->tx_power;
2337 }
2338 if (ipw_send_tx_power(priv, &tx_power))
2339 return -EIO;
2340
2341 /* configure device to also handle 'B' band */
2342 tx_power.ieee_mode = IPW_B_MODE;
2343 if (ipw_send_tx_power(priv, &tx_power))
2344 return -EIO;
2345
2346 /* configure device to also handle 'A' band */
2347 if (priv->ieee->abg_true) {
2348 tx_power.ieee_mode = IPW_A_MODE;
2349 tx_power.num_channels = geo->a_channels;
2350 for (i = 0; i < tx_power.num_channels; i++) {
2351 max_power = geo->a[i].max_power;
2352 tx_power.channels_tx_power[i].channel_number =
2353 geo->a[i].channel;
2354 tx_power.channels_tx_power[i].tx_power = max_power ?
2355 min(max_power, priv->tx_power) : priv->tx_power;
2356 }
2357 if (ipw_send_tx_power(priv, &tx_power))
2358 return -EIO;
2359 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002360 return 0;
2361}
2362
2363static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2364{
2365 struct ipw_rts_threshold rts_threshold = {
2366 .rts_threshold = rts,
2367 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002368
2369 if (!priv) {
2370 IPW_ERROR("Invalid args\n");
2371 return -1;
2372 }
2373
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002374 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2375 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002376}
2377
2378static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2379{
2380 struct ipw_frag_threshold frag_threshold = {
2381 .frag_threshold = frag,
2382 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002383
2384 if (!priv) {
2385 IPW_ERROR("Invalid args\n");
2386 return -1;
2387 }
2388
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002389 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2390 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002391}
2392
2393static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2394{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002395 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002396
2397 if (!priv) {
2398 IPW_ERROR("Invalid args\n");
2399 return -1;
2400 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002401
James Ketrenos43f66a62005-03-25 12:31:53 -06002402 /* If on battery, set to 3, if AC set to CAM, else user
2403 * level */
2404 switch (mode) {
2405 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002406 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002407 break;
2408 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002409 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002410 break;
2411 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002412 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002413 break;
2414 }
2415
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002416 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002417 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002418}
2419
James Ketrenosafbf30a2005-08-25 00:05:33 -05002420static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2421{
2422 struct ipw_retry_limit retry_limit = {
2423 .short_retry_limit = slimit,
2424 .long_retry_limit = llimit
2425 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002426
2427 if (!priv) {
2428 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002429 return -1;
2430 }
2431
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002432 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002433 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002434}
2435
2436/*
2437 * The IPW device contains a Microwire compatible EEPROM that stores
2438 * various data like the MAC address. Usually the firmware has exclusive
2439 * access to the eeprom, but during device initialization (before the
2440 * device driver has sent the HostComplete command to the firmware) the
2441 * device driver has read access to the EEPROM by way of indirect addressing
2442 * through a couple of memory mapped registers.
2443 *
2444 * The following is a simplified implementation for pulling data out of the
2445 * the eeprom, along with some helper functions to find information in
2446 * the per device private data's copy of the eeprom.
2447 *
2448 * NOTE: To better understand how these functions work (i.e what is a chip
2449 * select and why do have to keep driving the eeprom clock?), read
2450 * just about any data sheet for a Microwire compatible EEPROM.
2451 */
2452
2453/* write a 32 bit value into the indirect accessor register */
2454static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2455{
2456 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002457
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 /* the eeprom requires some time to complete the operation */
2459 udelay(p->eeprom_delay);
2460
2461 return;
2462}
2463
2464/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002465static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002466{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002467 eeprom_write_reg(priv, 0);
2468 eeprom_write_reg(priv, EEPROM_BIT_CS);
2469 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2470 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002471}
2472
2473/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002474static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002475{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002476 eeprom_write_reg(priv, EEPROM_BIT_CS);
2477 eeprom_write_reg(priv, 0);
2478 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002479}
2480
2481/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002482static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002483{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002484 int d = (bit ? EEPROM_BIT_DI : 0);
2485 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2486 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002487}
2488
2489/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002490static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002491{
2492 int i;
2493
2494 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002495 eeprom_write_bit(priv, 1);
2496 eeprom_write_bit(priv, op & 2);
2497 eeprom_write_bit(priv, op & 1);
2498 for (i = 7; i >= 0; i--) {
2499 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002500 }
2501}
2502
2503/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002504static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002505{
2506 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002507 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002508
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002510 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002511
2512 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002513 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002514
2515 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002516 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002518 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2521 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002523
James Ketrenos43f66a62005-03-25 12:31:53 -06002524 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002525 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002526 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002527
James Ketrenos43f66a62005-03-25 12:31:53 -06002528 return r;
2529}
2530
2531/* helper function for pulling the mac address out of the private */
2532/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002534{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002535 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002536}
2537
2538/*
2539 * Either the device driver (i.e. the host) or the firmware can
2540 * load eeprom data into the designated region in SRAM. If neither
2541 * happens then the FW will shutdown with a fatal error.
2542 *
2543 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2544 * bit needs region of shared SRAM needs to be non-zero.
2545 */
2546static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2547{
2548 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002549 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002550
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 IPW_DEBUG_TRACE(">>\n");
2552
2553 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002554 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002555 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002556
Jeff Garzikbf794512005-07-31 13:07:26 -04002557 /*
2558 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002559 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002560 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002561 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002562 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002563 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2564
2565 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002566 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002567 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002568
2569 /* Do not load eeprom data on fatal error or suspend */
2570 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2571 } else {
2572 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2573
2574 /* Load eeprom data on fatal error or suspend */
2575 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2576 }
2577
2578 IPW_DEBUG_TRACE("<<\n");
2579}
2580
Arjan van de Ven858119e2006-01-14 13:20:43 -08002581static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002582{
2583 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584 if (!count)
2585 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002586 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002587 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002588 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002589}
2590
2591static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2592{
James Ketrenosb095c382005-08-24 22:04:42 -05002593 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002594 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002595 sizeof(struct command_block));
2596}
2597
2598static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002599{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002600
2601 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002602
James Ketrenos43f66a62005-03-25 12:31:53 -06002603 /* Start the dma */
2604 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002605
James Ketrenos43f66a62005-03-25 12:31:53 -06002606 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002607 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002608
2609 IPW_DEBUG_FW("<< : \n");
2610 return 0;
2611}
2612
2613static void ipw_fw_dma_abort(struct ipw_priv *priv)
2614{
2615 u32 control = 0;
2616
2617 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002618
2619 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002620 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002621 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002622 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002623
James Ketrenos43f66a62005-03-25 12:31:53 -06002624 IPW_DEBUG_FW("<< \n");
2625}
2626
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002627static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2628 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002629{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002631 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002632 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002633 IPW_DEBUG_FW(">> :\n");
2634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002635 ipw_write_indirect(priv, address, (u8 *) cb,
2636 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002637
2638 IPW_DEBUG_FW("<< :\n");
2639 return 0;
2640
2641}
2642
2643static int ipw_fw_dma_kick(struct ipw_priv *priv)
2644{
2645 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002646 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002647
2648 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002649
James Ketrenos43f66a62005-03-25 12:31:53 -06002650 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002651 ipw_fw_dma_write_command_block(priv, index,
2652 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002653
2654 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002655 ipw_clear_bit(priv, IPW_RESET_REG,
2656 IPW_RESET_REG_MASTER_DISABLED |
2657 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002658
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002659 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002660 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002661 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002662
2663 IPW_DEBUG_FW("<< :\n");
2664 return 0;
2665}
2666
2667static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2668{
2669 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002670 u32 register_value = 0;
2671 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002672
2673 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002674 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002675 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002676
2677 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002678 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2679 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002680
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002681 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002682 cb_fields_address = address;
2683 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002684 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002685
2686 cb_fields_address += sizeof(u32);
2687 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002688 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002689
2690 cb_fields_address += sizeof(u32);
2691 register_value = ipw_read_reg32(priv, cb_fields_address);
2692 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2693 register_value);
2694
2695 cb_fields_address += sizeof(u32);
2696 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002697 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002698
2699 IPW_DEBUG_FW(">> :\n");
2700}
2701
2702static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2703{
2704 u32 current_cb_address = 0;
2705 u32 current_cb_index = 0;
2706
2707 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002708 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002709
James Ketrenosb095c382005-08-24 22:04:42 -05002710 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002711 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002712
James Ketrenos43f66a62005-03-25 12:31:53 -06002713 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002714 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002715
2716 IPW_DEBUG_FW(">> :\n");
2717 return current_cb_index;
2718
2719}
2720
2721static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2722 u32 src_address,
2723 u32 dest_address,
2724 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002725 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002726{
2727
Jeff Garzikbf794512005-07-31 13:07:26 -04002728 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002729 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2730 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002731 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002732 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002733
2734 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2735 src_address, dest_address, length);
2736
2737 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2738 return -1;
2739
2740 last_cb_element = priv->sram_desc.last_cb_index;
2741 cb = &priv->sram_desc.cb_list[last_cb_element];
2742 priv->sram_desc.last_cb_index++;
2743
2744 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002745 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002746 control |= CB_INT_ENABLED;
2747
2748 if (is_last)
2749 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002750
James Ketrenos43f66a62005-03-25 12:31:53 -06002751 control |= length;
2752
2753 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002754 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002755
2756 /* Copy the Source and Destination addresses */
2757 cb->dest_addr = dest_address;
2758 cb->source_addr = src_address;
2759
2760 /* Copy the Control Word last */
2761 cb->control = control;
2762
2763 return 0;
2764}
2765
2766static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002767 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002768{
2769 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002770 u32 src_offset = 0;
2771 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002772 int status = 0;
2773 IPW_DEBUG_FW(">> \n");
2774 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2775 src_phys, dest_address, length);
2776 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002777 status = ipw_fw_dma_add_command_block(priv,
2778 src_phys + src_offset,
2779 dest_address +
2780 dest_offset,
2781 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 if (status) {
2783 IPW_DEBUG_FW_INFO(": Failed\n");
2784 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002785 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002786 IPW_DEBUG_FW_INFO(": Added new cb\n");
2787
2788 src_offset += CB_MAX_LENGTH;
2789 dest_offset += CB_MAX_LENGTH;
2790 bytes_left -= CB_MAX_LENGTH;
2791 }
2792
2793 /* add the buffer tail */
2794 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002795 status =
2796 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2797 dest_address + dest_offset,
2798 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 if (status) {
2800 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2801 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002802 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002803 IPW_DEBUG_FW_INFO
2804 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002805 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002806
James Ketrenos43f66a62005-03-25 12:31:53 -06002807 IPW_DEBUG_FW("<< \n");
2808 return 0;
2809}
2810
2811static int ipw_fw_dma_wait(struct ipw_priv *priv)
2812{
Zhu Yi397ae122006-01-24 16:37:22 +08002813 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002814 u32 watchdog = 0;
2815
2816 IPW_DEBUG_FW(">> : \n");
2817
2818 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002819 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002820 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
2822 while (current_index < priv->sram_desc.last_cb_index) {
2823 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002824 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002825 current_index = ipw_fw_dma_command_block_index(priv);
2826
Zhu Yi397ae122006-01-24 16:37:22 +08002827 if (previous_index < current_index) {
2828 watchdog = 0;
2829 continue;
2830 }
2831 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002832 IPW_DEBUG_FW_INFO("Timeout\n");
2833 ipw_fw_dma_dump_command_block(priv);
2834 ipw_fw_dma_abort(priv);
2835 return -1;
2836 }
2837 }
2838
2839 ipw_fw_dma_abort(priv);
2840
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002841 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002842 ipw_set_bit(priv, IPW_RESET_REG,
2843 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002844
2845 IPW_DEBUG_FW("<< dmaWaitSync \n");
2846 return 0;
2847}
2848
Jeff Garzikbf794512005-07-31 13:07:26 -04002849static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002850{
2851 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002852 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002853 unsigned long flags;
2854
2855 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2857 network = list_entry(element, struct ieee80211_network, list);
2858 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2859 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002860 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002861 &priv->ieee->network_free_list);
2862 }
2863 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002864 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002865}
2866
2867/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002868 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002869 * Reads debug register from domain0.
2870 * If card is present, pre-defined value should
2871 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002872 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002873 * @param priv
2874 * @return 1 if card is present, 0 otherwise
2875 */
2876static inline int ipw_alive(struct ipw_priv *priv)
2877{
2878 return ipw_read32(priv, 0x90) == 0xd55555d5;
2879}
2880
Zhu Yic7b6a672006-01-24 16:37:05 +08002881/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002882static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 int timeout)
2884{
2885 int i = 0;
2886
2887 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002888 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002889 return i;
2890 mdelay(10);
2891 i += 10;
2892 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002893
James Ketrenos43f66a62005-03-25 12:31:53 -06002894 return -ETIME;
2895}
2896
Jeff Garzikbf794512005-07-31 13:07:26 -04002897/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002898 * the ipw hardware. It assumes the buffer has all the bits for the
2899 * image and the caller is handling the memory allocation and clean up.
2900 */
2901
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002902static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002903{
2904 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002905
James Ketrenos43f66a62005-03-25 12:31:53 -06002906 IPW_DEBUG_TRACE(">> \n");
2907 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002908 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002909
Zhu Yic7b6a672006-01-24 16:37:05 +08002910 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002911 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2912 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002913 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002914 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002915 return -1;
2916 }
2917
2918 IPW_DEBUG_INFO("stop master %dms\n", rc);
2919
2920 return rc;
2921}
2922
2923static void ipw_arc_release(struct ipw_priv *priv)
2924{
2925 IPW_DEBUG_TRACE(">> \n");
2926 mdelay(5);
2927
James Ketrenosb095c382005-08-24 22:04:42 -05002928 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002929
2930 /* no one knows timing, for safety add some delay */
2931 mdelay(5);
2932}
2933
James Ketrenos43f66a62005-03-25 12:31:53 -06002934struct fw_chunk {
2935 u32 address;
2936 u32 length;
2937};
2938
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002939static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002940{
2941 int rc = 0, i, addr;
2942 u8 cr = 0;
2943 u16 *image;
2944
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002945 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002946
James Ketrenos43f66a62005-03-25 12:31:53 -06002947 IPW_DEBUG_TRACE(">> \n");
2948
2949 rc = ipw_stop_master(priv);
2950
2951 if (rc < 0)
2952 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002953
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002954// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002955
James Ketrenosb095c382005-08-24 22:04:42 -05002956 for (addr = IPW_SHARED_LOWER_BOUND;
2957 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002958 ipw_write32(priv, addr, 0);
2959 }
2960
2961 /* no ucode (yet) */
2962 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2963 /* destroy DMA queues */
2964 /* reset sequence */
2965
James Ketrenosb095c382005-08-24 22:04:42 -05002966 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002967 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002968 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002969 mdelay(1);
2970
2971 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002972 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002973 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002974
James Ketrenosb095c382005-08-24 22:04:42 -05002975 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002976 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002977
James Ketrenos43f66a62005-03-25 12:31:53 -06002978 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002979 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2980 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002981 mdelay(1);
2982
2983 /* write ucode */
2984 /**
2985 * @bug
2986 * Do NOT set indirect address register once and then
2987 * store data to indirect data register in the loop.
2988 * It seems very reasonable, but in this case DINO do not
2989 * accept ucode. It is essential to set address each time.
2990 */
2991 /* load new ipw uCode */
2992 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002993 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002994 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002995
James Ketrenos43f66a62005-03-25 12:31:53 -06002996 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002997 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2998 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002999
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003000 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003001
3002 /* wait for alive response */
3003 for (i = 0; i < 100; i++) {
3004 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003005 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 if (cr & DINO_RXFIFO_DATA)
3007 break;
3008 mdelay(1);
3009 }
3010
3011 if (cr & DINO_RXFIFO_DATA) {
3012 /* alive_command_responce size is NOT multiple of 4 */
3013 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003014
3015 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003016 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05003017 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003018 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003019 memcpy(&priv->dino_alive, response_buffer,
3020 sizeof(priv->dino_alive));
3021 if (priv->dino_alive.alive_command == 1
3022 && priv->dino_alive.ucode_valid == 1) {
3023 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003024 IPW_DEBUG_INFO
3025 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3026 "of %02d/%02d/%02d %02d:%02d\n",
3027 priv->dino_alive.software_revision,
3028 priv->dino_alive.software_revision,
3029 priv->dino_alive.device_identifier,
3030 priv->dino_alive.device_identifier,
3031 priv->dino_alive.time_stamp[0],
3032 priv->dino_alive.time_stamp[1],
3033 priv->dino_alive.time_stamp[2],
3034 priv->dino_alive.time_stamp[3],
3035 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003036 } else {
3037 IPW_DEBUG_INFO("Microcode is not alive\n");
3038 rc = -EINVAL;
3039 }
3040 } else {
3041 IPW_DEBUG_INFO("No alive response from DINO\n");
3042 rc = -ETIME;
3043 }
3044
3045 /* disable DINO, otherwise for some reason
3046 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003047 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003048
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003049// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003050
3051 return rc;
3052}
3053
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003054static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003055{
3056 int rc = -1;
3057 int offset = 0;
3058 struct fw_chunk *chunk;
3059 dma_addr_t shared_phys;
3060 u8 *shared_virt;
3061
3062 IPW_DEBUG_TRACE("<< : \n");
3063 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3064
3065 if (!shared_virt)
3066 return -ENOMEM;
3067
3068 memmove(shared_virt, data, len);
3069
3070 /* Start the Dma */
3071 rc = ipw_fw_dma_enable(priv);
3072
3073 if (priv->sram_desc.last_cb_index > 0) {
3074 /* the DMA is already ready this would be a bug. */
3075 BUG();
3076 goto out;
3077 }
3078
3079 do {
3080 chunk = (struct fw_chunk *)(data + offset);
3081 offset += sizeof(struct fw_chunk);
3082 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003083 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003084 * offeset*/
3085 /* Dma loading */
3086 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003087 le32_to_cpu(chunk->address),
3088 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003089 if (rc) {
3090 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3091 goto out;
3092 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003093
James Ketrenosa613bff2005-08-24 21:43:11 -05003094 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003095 } while (offset < len);
3096
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003097 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 rc = ipw_fw_dma_kick(priv);
3099 if (rc) {
3100 IPW_ERROR("dmaKick Failed\n");
3101 goto out;
3102 }
3103
3104 rc = ipw_fw_dma_wait(priv);
3105 if (rc) {
3106 IPW_ERROR("dmaWaitSync Failed\n");
3107 goto out;
3108 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003109 out:
3110 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003111 return rc;
3112}
3113
3114/* stop nic */
3115static int ipw_stop_nic(struct ipw_priv *priv)
3116{
3117 int rc = 0;
3118
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003119 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003120 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003121
James Ketrenosb095c382005-08-24 22:04:42 -05003122 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3123 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003124 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003125 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003126 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003127 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003128
James Ketrenosb095c382005-08-24 22:04:42 -05003129 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003130
James Ketrenos43f66a62005-03-25 12:31:53 -06003131 return rc;
3132}
3133
3134static void ipw_start_nic(struct ipw_priv *priv)
3135{
3136 IPW_DEBUG_TRACE(">>\n");
3137
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003138 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003139 ipw_clear_bit(priv, IPW_RESET_REG,
3140 IPW_RESET_REG_MASTER_DISABLED |
3141 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003143
James Ketrenos43f66a62005-03-25 12:31:53 -06003144 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003145 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3146 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003147
3148 IPW_DEBUG_TRACE("<<\n");
3149}
Jeff Garzikbf794512005-07-31 13:07:26 -04003150
James Ketrenos43f66a62005-03-25 12:31:53 -06003151static int ipw_init_nic(struct ipw_priv *priv)
3152{
3153 int rc;
3154
3155 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003156 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003157 /*prvHwInitNic */
3158 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003159 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003160
3161 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003162 ipw_write32(priv, IPW_READ_INT_REGISTER,
3163 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003164
3165 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003166 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3167 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003168 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003169 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3170
3171 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003172 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003173
3174 udelay(10);
3175
3176 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003177 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003178
3179 IPW_DEBUG_TRACE(">>\n");
3180 return 0;
3181}
3182
Jeff Garzikbf794512005-07-31 13:07:26 -04003183/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003184 * Probe is an ok place to call this from.
3185 */
3186static int ipw_reset_nic(struct ipw_priv *priv)
3187{
3188 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003189 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003190
3191 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003192
James Ketrenos43f66a62005-03-25 12:31:53 -06003193 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003194
James Ketrenosa613bff2005-08-24 21:43:11 -05003195 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003196 /* Clear the 'host command active' bit... */
3197 priv->status &= ~STATUS_HCMD_ACTIVE;
3198 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003199 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3200 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003201 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003202
3203 IPW_DEBUG_TRACE("<<\n");
3204 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003205}
James Ketrenos43f66a62005-03-25 12:31:53 -06003206
James Ketrenos9006ea72006-03-08 03:22:28 +08003207
3208struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003209 __le32 ver;
3210 __le32 boot_size;
3211 __le32 ucode_size;
3212 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003213 u8 data[0];
3214};
3215
Jeff Garzikbf794512005-07-31 13:07:26 -04003216static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003217 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003218{
James Ketrenos9006ea72006-03-08 03:22:28 +08003219 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 int rc;
3221
3222 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003223 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003224 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003225 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003227 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003228
James Ketrenos9006ea72006-03-08 03:22:28 +08003229 if ((*raw)->size < sizeof(*fw)) {
3230 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003231 return -EINVAL;
3232 }
3233
James Ketrenos9006ea72006-03-08 03:22:28 +08003234 fw = (void *)(*raw)->data;
3235
Zhu Yi0070f8c2006-04-13 17:20:12 +08003236 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3237 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003238 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3239 name, (*raw)->size);
3240 return -EINVAL;
3241 }
3242
3243 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003245 le32_to_cpu(fw->ver) >> 16,
3246 le32_to_cpu(fw->ver) & 0xff,
3247 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003248 return 0;
3249}
3250
James Ketrenosb095c382005-08-24 22:04:42 -05003251#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003252
Arjan van de Ven858119e2006-01-14 13:20:43 -08003253static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003254 struct ipw_rx_queue *rxq)
3255{
3256 unsigned long flags;
3257 int i;
3258
3259 spin_lock_irqsave(&rxq->lock, flags);
3260
3261 INIT_LIST_HEAD(&rxq->rx_free);
3262 INIT_LIST_HEAD(&rxq->rx_used);
3263
3264 /* Fill the rx_used queue with _all_ of the Rx buffers */
3265 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3266 /* In the reset function, these buffers may have been allocated
3267 * to an SKB, so we need to unmap and free potential storage */
3268 if (rxq->pool[i].skb != NULL) {
3269 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003270 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003271 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003272 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003273 }
3274 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3275 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003276
James Ketrenos43f66a62005-03-25 12:31:53 -06003277 /* Set us so that we have processed and used all buffers, but have
3278 * not restocked the Rx queue with fresh buffers */
3279 rxq->read = rxq->write = 0;
3280 rxq->processed = RX_QUEUE_SIZE - 1;
3281 rxq->free_count = 0;
3282 spin_unlock_irqrestore(&rxq->lock, flags);
3283}
3284
3285#ifdef CONFIG_PM
3286static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003287static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003288
3289static void free_firmware(void)
3290{
3291 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003292 release_firmware(raw);
3293 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003294 fw_loaded = 0;
3295 }
3296}
3297#else
3298#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003299#endif
3300
3301static int ipw_load(struct ipw_priv *priv)
3302{
3303#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003304 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003305#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003306 struct ipw_fw *fw;
3307 u8 *boot_img, *ucode_img, *fw_img;
3308 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003309 int rc = 0, retries = 3;
3310
Zhu Yi397ae122006-01-24 16:37:22 +08003311 switch (priv->ieee->iw_mode) {
3312 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003313 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003314 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003315#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003316 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003317 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003318 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003319#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003320 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003321 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003322 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003323 }
Zhu Yi397ae122006-01-24 16:37:22 +08003324
James Ketrenos9006ea72006-03-08 03:22:28 +08003325 if (!name) {
3326 rc = -EINVAL;
3327 goto error;
3328 }
3329
3330#ifdef CONFIG_PM
3331 if (!fw_loaded) {
3332#endif
3333 rc = ipw_get_fw(priv, &raw, name);
3334 if (rc < 0)
3335 goto error;
3336#ifdef CONFIG_PM
3337 }
3338#endif
3339
3340 fw = (void *)raw->data;
3341 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003342 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3343 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3344 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003345
Zhu Yi397ae122006-01-24 16:37:22 +08003346 if (rc < 0)
3347 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003348
3349 if (!priv->rxq)
3350 priv->rxq = ipw_rx_queue_alloc(priv);
3351 else
3352 ipw_rx_queue_reset(priv, priv->rxq);
3353 if (!priv->rxq) {
3354 IPW_ERROR("Unable to initialize Rx queue\n");
3355 goto error;
3356 }
3357
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003358 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003359 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003360 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003361 priv->status &= ~STATUS_INT_ENABLED;
3362
3363 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003364 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003365
James Ketrenos43f66a62005-03-25 12:31:53 -06003366 ipw_stop_nic(priv);
3367
3368 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003369 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003370 IPW_ERROR("Unable to reset NIC\n");
3371 goto error;
3372 }
3373
James Ketrenosb095c382005-08-24 22:04:42 -05003374 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3375 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003376
3377 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003378 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003379 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003380 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003381 goto error;
3382 }
3383
3384 /* kick start the device */
3385 ipw_start_nic(priv);
3386
Zhu Yic7b6a672006-01-24 16:37:05 +08003387 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003388 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3389 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003390 if (rc < 0) {
3391 IPW_ERROR("device failed to boot initial fw image\n");
3392 goto error;
3393 }
3394 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3395
Jeff Garzikbf794512005-07-31 13:07:26 -04003396 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003397 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003398
3399 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003400 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003401 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003402 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003403 goto error;
3404 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003405
James Ketrenos43f66a62005-03-25 12:31:53 -06003406 /* stop nic */
3407 ipw_stop_nic(priv);
3408
3409 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003410 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003411 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003412 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003413 goto error;
3414 }
Zhu Yi397ae122006-01-24 16:37:22 +08003415#ifdef CONFIG_PM
3416 fw_loaded = 1;
3417#endif
3418
James Ketrenos43f66a62005-03-25 12:31:53 -06003419 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3420
3421 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003422 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003423 IPW_ERROR("Unable to initialize queues\n");
3424 goto error;
3425 }
3426
3427 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003428 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003429 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003430 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003431
James Ketrenos43f66a62005-03-25 12:31:53 -06003432 /* kick start the device */
3433 ipw_start_nic(priv);
3434
James Ketrenosb095c382005-08-24 22:04:42 -05003435 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003436 if (retries > 0) {
3437 IPW_WARNING("Parity error. Retrying init.\n");
3438 retries--;
3439 goto retry;
3440 }
3441
3442 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3443 rc = -EIO;
3444 goto error;
3445 }
3446
3447 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003448 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3449 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003450 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003451 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003452 goto error;
3453 }
3454 IPW_DEBUG_INFO("device response after %dms\n", rc);
3455
3456 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003457 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003458
3459 /* read eeprom data and initialize the eeprom region of sram */
3460 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003461 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003462
3463 /* enable interrupts */
3464 ipw_enable_interrupts(priv);
3465
3466 /* Ensure our queue has valid packets */
3467 ipw_rx_queue_replenish(priv);
3468
James Ketrenosb095c382005-08-24 22:04:42 -05003469 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003470
3471 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003472 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003473
3474#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003475 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003476#endif
3477 return 0;
3478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003479 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003480 if (priv->rxq) {
3481 ipw_rx_queue_free(priv, priv->rxq);
3482 priv->rxq = NULL;
3483 }
3484 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003485 if (raw)
3486 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003487#ifdef CONFIG_PM
3488 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003489 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003490#endif
3491
3492 return rc;
3493}
3494
Jeff Garzikbf794512005-07-31 13:07:26 -04003495/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003496 * DMA services
3497 *
3498 * Theory of operation
3499 *
3500 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3501 * 2 empty entries always kept in the buffer to protect from overflow.
3502 *
3503 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003504 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3505 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003506 * Tx queue resumed.
3507 *
3508 * The IPW operates with six queues, one receive queue in the device's
3509 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003510 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003511 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003512 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003513 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003514 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003515 * we only utilize the first data transmit queue (queue1).
3516 */
3517
3518/**
3519 * Driver allocates buffers of this size for Rx
3520 */
3521
3522static inline int ipw_queue_space(const struct clx2_queue *q)
3523{
3524 int s = q->last_used - q->first_empty;
3525 if (s <= 0)
3526 s += q->n_bd;
3527 s -= 2; /* keep some reserve to not confuse empty and full situations */
3528 if (s < 0)
3529 s = 0;
3530 return s;
3531}
3532
3533static inline int ipw_queue_inc_wrap(int index, int n_bd)
3534{
3535 return (++index == n_bd) ? 0 : index;
3536}
3537
3538/**
3539 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003540 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003541 * @param q queue to init
3542 * @param count Number of BD's to allocate. Should be power of 2
3543 * @param read_register Address for 'read' register
3544 * (not offset within BAR, full address)
3545 * @param write_register Address for 'write' register
3546 * (not offset within BAR, full address)
3547 * @param base_register Address for 'base' register
3548 * (not offset within BAR, full address)
3549 * @param size Address for 'size' register
3550 * (not offset within BAR, full address)
3551 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003552static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003553 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003554{
3555 q->n_bd = count;
3556
3557 q->low_mark = q->n_bd / 4;
3558 if (q->low_mark < 4)
3559 q->low_mark = 4;
3560
3561 q->high_mark = q->n_bd / 8;
3562 if (q->high_mark < 2)
3563 q->high_mark = 2;
3564
3565 q->first_empty = q->last_used = 0;
3566 q->reg_r = read;
3567 q->reg_w = write;
3568
3569 ipw_write32(priv, base, q->dma_addr);
3570 ipw_write32(priv, size, count);
3571 ipw_write32(priv, read, 0);
3572 ipw_write32(priv, write, 0);
3573
3574 _ipw_read32(priv, 0x90);
3575}
3576
Jeff Garzikbf794512005-07-31 13:07:26 -04003577static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003578 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003579 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003580{
3581 struct pci_dev *dev = priv->pci_dev;
3582
3583 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3584 if (!q->txb) {
3585 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3586 return -ENOMEM;
3587 }
3588
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003589 q->bd =
3590 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003591 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003592 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003593 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003594 kfree(q->txb);
3595 q->txb = NULL;
3596 return -ENOMEM;
3597 }
3598
3599 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3600 return 0;
3601}
3602
3603/**
3604 * Free one TFD, those at index [txq->q.last_used].
3605 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003606 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003607 * @param dev
3608 * @param txq
3609 */
3610static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3611 struct clx2_tx_queue *txq)
3612{
3613 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3614 struct pci_dev *dev = priv->pci_dev;
3615 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003616
James Ketrenos43f66a62005-03-25 12:31:53 -06003617 /* classify bd */
3618 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3619 /* nothing to cleanup after for host commands */
3620 return;
3621
3622 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003623 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3624 IPW_ERROR("Too many chunks: %i\n",
3625 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003626 /** @todo issue fatal error, it is quite serious situation */
3627 return;
3628 }
3629
3630 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003631 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3632 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3633 le16_to_cpu(bd->u.data.chunk_len[i]),
3634 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003635 if (txq->txb[txq->q.last_used]) {
3636 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3637 txq->txb[txq->q.last_used] = NULL;
3638 }
3639 }
3640}
3641
3642/**
3643 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003644 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003645 * Empty queue by removing and destroying all BD's.
3646 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003647 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003648 * @param dev
3649 * @param q
3650 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003651static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003652{
3653 struct clx2_queue *q = &txq->q;
3654 struct pci_dev *dev = priv->pci_dev;
3655
Jeff Garzikbf794512005-07-31 13:07:26 -04003656 if (q->n_bd == 0)
3657 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003658
3659 /* first, empty all BD's */
3660 for (; q->first_empty != q->last_used;
3661 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3662 ipw_queue_tx_free_tfd(priv, txq);
3663 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003664
James Ketrenos43f66a62005-03-25 12:31:53 -06003665 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003666 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003667 q->dma_addr);
3668 kfree(txq->txb);
3669
3670 /* 0 fill whole structure */
3671 memset(txq, 0, sizeof(*txq));
3672}
3673
James Ketrenos43f66a62005-03-25 12:31:53 -06003674/**
3675 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003676 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003677 * @param priv
3678 */
3679static void ipw_tx_queue_free(struct ipw_priv *priv)
3680{
3681 /* Tx CMD queue */
3682 ipw_queue_tx_free(priv, &priv->txq_cmd);
3683
3684 /* Tx queues */
3685 ipw_queue_tx_free(priv, &priv->txq[0]);
3686 ipw_queue_tx_free(priv, &priv->txq[1]);
3687 ipw_queue_tx_free(priv, &priv->txq[2]);
3688 ipw_queue_tx_free(priv, &priv->txq[3]);
3689}
3690
Arjan van de Ven858119e2006-01-14 13:20:43 -08003691static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003692{
3693 /* First 3 bytes are manufacturer */
3694 bssid[0] = priv->mac_addr[0];
3695 bssid[1] = priv->mac_addr[1];
3696 bssid[2] = priv->mac_addr[2];
3697
3698 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003699 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003700
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003701 bssid[0] &= 0xfe; /* clear multicast bit */
3702 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003703}
3704
Arjan van de Ven858119e2006-01-14 13:20:43 -08003705static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003706{
3707 struct ipw_station_entry entry;
3708 int i;
3709
3710 for (i = 0; i < priv->num_stations; i++) {
3711 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3712 /* Another node is active in network */
3713 priv->missed_adhoc_beacons = 0;
3714 if (!(priv->config & CFG_STATIC_CHANNEL))
3715 /* when other nodes drop out, we drop out */
3716 priv->config &= ~CFG_ADHOC_PERSIST;
3717
3718 return i;
3719 }
3720 }
3721
3722 if (i == MAX_STATIONS)
3723 return IPW_INVALID_STATION;
3724
3725 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3726
3727 entry.reserved = 0;
3728 entry.support_mode = 0;
3729 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3730 memcpy(priv->stations[i], bssid, ETH_ALEN);
3731 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003732 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003733 priv->num_stations++;
3734
3735 return i;
3736}
3737
Arjan van de Ven858119e2006-01-14 13:20:43 -08003738static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003739{
3740 int i;
3741
Jeff Garzikbf794512005-07-31 13:07:26 -04003742 for (i = 0; i < priv->num_stations; i++)
3743 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003744 return i;
3745
3746 return IPW_INVALID_STATION;
3747}
3748
3749static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3750{
3751 int err;
3752
Hong Liu7b996592005-08-25 17:36:13 +08003753 if (priv->status & STATUS_ASSOCIATING) {
3754 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3755 queue_work(priv->workqueue, &priv->disassociate);
3756 return;
3757 }
3758
3759 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003760 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3761 return;
3762 }
3763
3764 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3765 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003766 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003767 priv->assoc_request.channel);
3768
3769 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3770 priv->status |= STATUS_DISASSOCIATING;
3771
3772 if (quiet)
3773 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3774 else
3775 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003776
James Ketrenos43f66a62005-03-25 12:31:53 -06003777 err = ipw_send_associate(priv, &priv->assoc_request);
3778 if (err) {
3779 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3780 "failed.\n");
3781 return;
3782 }
3783
3784}
3785
James Ketrenosc848d0a2005-08-24 21:56:24 -05003786static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003787{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003788 struct ipw_priv *priv = data;
3789 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3790 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003792 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003793}
3794
James Ketrenosc848d0a2005-08-24 21:56:24 -05003795static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003796{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003797 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003798 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003799 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003800 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003801}
3802
Zhu Yid8bad6d2005-07-13 12:25:38 -05003803static void ipw_system_config(void *data)
3804{
3805 struct ipw_priv *priv = data;
Zhu Yid685b8c2006-04-13 17:20:27 +08003806
3807#ifdef CONFIG_IPW2200_PROMISCUOUS
3808 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3809 priv->sys_config.accept_all_data_frames = 1;
3810 priv->sys_config.accept_non_directed_frames = 1;
3811 priv->sys_config.accept_all_mgmt_bcpr = 1;
3812 priv->sys_config.accept_all_mgmt_frames = 1;
3813 }
3814#endif
3815
3816 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003817}
3818
3819struct ipw_status_code {
3820 u16 status;
3821 const char *reason;
3822};
3823
3824static const struct ipw_status_code ipw_status_codes[] = {
3825 {0x00, "Successful"},
3826 {0x01, "Unspecified failure"},
3827 {0x0A, "Cannot support all requested capabilities in the "
3828 "Capability information field"},
3829 {0x0B, "Reassociation denied due to inability to confirm that "
3830 "association exists"},
3831 {0x0C, "Association denied due to reason outside the scope of this "
3832 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003833 {0x0D,
3834 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003835 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003836 {0x0E,
3837 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003838 "transaction sequence number out of expected sequence"},
3839 {0x0F, "Authentication rejected because of challenge failure"},
3840 {0x10, "Authentication rejected due to timeout waiting for next "
3841 "frame in sequence"},
3842 {0x11, "Association denied because AP is unable to handle additional "
3843 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003844 {0x12,
3845 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003846 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003847 {0x13,
3848 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003849 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003850 {0x14,
3851 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003852 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003853 {0x15,
3854 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003855 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003856 {0x19,
3857 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003858 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003859 {0x1A,
3860 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003861 "DSSS-OFDM operation"},
3862 {0x28, "Invalid Information Element"},
3863 {0x29, "Group Cipher is not valid"},
3864 {0x2A, "Pairwise Cipher is not valid"},
3865 {0x2B, "AKMP is not valid"},
3866 {0x2C, "Unsupported RSN IE version"},
3867 {0x2D, "Invalid RSN IE Capabilities"},
3868 {0x2E, "Cipher suite is rejected per security policy"},
3869};
3870
Brice Goglin0f52bf92005-12-01 01:41:46 -08003871#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003872static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003873{
3874 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003875 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003876 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003877 return ipw_status_codes[i].reason;
3878 return "Unknown status value.";
3879}
3880#endif
3881
3882static void inline average_init(struct average *avg)
3883{
3884 memset(avg, 0, sizeof(*avg));
3885}
3886
Zhu Yi00d21de2006-04-13 17:19:02 +08003887#define DEPTH_RSSI 8
3888#define DEPTH_NOISE 16
3889static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3890{
3891 return ((depth-1)*prev_avg + val)/depth;
3892}
3893
Arjan van de Ven858119e2006-01-14 13:20:43 -08003894static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003895{
3896 avg->sum -= avg->entries[avg->pos];
3897 avg->sum += val;
3898 avg->entries[avg->pos++] = val;
3899 if (unlikely(avg->pos == AVG_ENTRIES)) {
3900 avg->init = 1;
3901 avg->pos = 0;
3902 }
3903}
3904
Arjan van de Ven858119e2006-01-14 13:20:43 -08003905static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003906{
3907 if (!unlikely(avg->init)) {
3908 if (avg->pos)
3909 return avg->sum / avg->pos;
3910 return 0;
3911 }
3912
3913 return avg->sum / AVG_ENTRIES;
3914}
3915
3916static void ipw_reset_stats(struct ipw_priv *priv)
3917{
3918 u32 len = sizeof(u32);
3919
3920 priv->quality = 0;
3921
3922 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003923 priv->exp_avg_rssi = -60;
3924 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003925
3926 priv->last_rate = 0;
3927 priv->last_missed_beacons = 0;
3928 priv->last_rx_packets = 0;
3929 priv->last_tx_packets = 0;
3930 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003931
James Ketrenos43f66a62005-03-25 12:31:53 -06003932 /* Firmware managed, reset only when NIC is restarted, so we have to
3933 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003934 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003935 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003936 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003937 &priv->last_tx_failures, &len);
3938
3939 /* Driver managed, reset with each association */
3940 priv->missed_adhoc_beacons = 0;
3941 priv->missed_beacons = 0;
3942 priv->tx_packets = 0;
3943 priv->rx_packets = 0;
3944
3945}
3946
Arjan van de Ven858119e2006-01-14 13:20:43 -08003947static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003948{
3949 u32 i = 0x80000000;
3950 u32 mask = priv->rates_mask;
3951 /* If currently associated in B mode, restrict the maximum
3952 * rate match to B rates */
3953 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3954 mask &= IEEE80211_CCK_RATES_MASK;
3955
3956 /* TODO: Verify that the rate is supported by the current rates
3957 * list. */
3958
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003959 while (i && !(mask & i))
3960 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003961 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003962 case IEEE80211_CCK_RATE_1MB_MASK:
3963 return 1000000;
3964 case IEEE80211_CCK_RATE_2MB_MASK:
3965 return 2000000;
3966 case IEEE80211_CCK_RATE_5MB_MASK:
3967 return 5500000;
3968 case IEEE80211_OFDM_RATE_6MB_MASK:
3969 return 6000000;
3970 case IEEE80211_OFDM_RATE_9MB_MASK:
3971 return 9000000;
3972 case IEEE80211_CCK_RATE_11MB_MASK:
3973 return 11000000;
3974 case IEEE80211_OFDM_RATE_12MB_MASK:
3975 return 12000000;
3976 case IEEE80211_OFDM_RATE_18MB_MASK:
3977 return 18000000;
3978 case IEEE80211_OFDM_RATE_24MB_MASK:
3979 return 24000000;
3980 case IEEE80211_OFDM_RATE_36MB_MASK:
3981 return 36000000;
3982 case IEEE80211_OFDM_RATE_48MB_MASK:
3983 return 48000000;
3984 case IEEE80211_OFDM_RATE_54MB_MASK:
3985 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003986 }
3987
Jeff Garzikbf794512005-07-31 13:07:26 -04003988 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003989 return 11000000;
3990 else
3991 return 54000000;
3992}
3993
3994static u32 ipw_get_current_rate(struct ipw_priv *priv)
3995{
3996 u32 rate, len = sizeof(rate);
3997 int err;
3998
Jeff Garzikbf794512005-07-31 13:07:26 -04003999 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004000 return 0;
4001
4002 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004003 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004004 &len);
4005 if (err) {
4006 IPW_DEBUG_INFO("failed querying ordinals.\n");
4007 return 0;
4008 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004009 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004010 return ipw_get_max_rate(priv);
4011
4012 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004013 case IPW_TX_RATE_1MB:
4014 return 1000000;
4015 case IPW_TX_RATE_2MB:
4016 return 2000000;
4017 case IPW_TX_RATE_5MB:
4018 return 5500000;
4019 case IPW_TX_RATE_6MB:
4020 return 6000000;
4021 case IPW_TX_RATE_9MB:
4022 return 9000000;
4023 case IPW_TX_RATE_11MB:
4024 return 11000000;
4025 case IPW_TX_RATE_12MB:
4026 return 12000000;
4027 case IPW_TX_RATE_18MB:
4028 return 18000000;
4029 case IPW_TX_RATE_24MB:
4030 return 24000000;
4031 case IPW_TX_RATE_36MB:
4032 return 36000000;
4033 case IPW_TX_RATE_48MB:
4034 return 48000000;
4035 case IPW_TX_RATE_54MB:
4036 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 }
4038
4039 return 0;
4040}
4041
James Ketrenos43f66a62005-03-25 12:31:53 -06004042#define IPW_STATS_INTERVAL (2 * HZ)
4043static void ipw_gather_stats(struct ipw_priv *priv)
4044{
4045 u32 rx_err, rx_err_delta, rx_packets_delta;
4046 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4047 u32 missed_beacons_percent, missed_beacons_delta;
4048 u32 quality = 0;
4049 u32 len = sizeof(u32);
4050 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004051 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004052 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004053 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004054
4055 if (!(priv->status & STATUS_ASSOCIATED)) {
4056 priv->quality = 0;
4057 return;
4058 }
4059
4060 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004061 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004062 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004063 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004064 priv->last_missed_beacons = priv->missed_beacons;
4065 if (priv->assoc_request.beacon_interval) {
4066 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004067 (HZ * priv->assoc_request.beacon_interval) /
4068 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 } else {
4070 missed_beacons_percent = 0;
4071 }
4072 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4073
4074 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4075 rx_err_delta = rx_err - priv->last_rx_err;
4076 priv->last_rx_err = rx_err;
4077
4078 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4079 tx_failures_delta = tx_failures - priv->last_tx_failures;
4080 priv->last_tx_failures = tx_failures;
4081
4082 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4083 priv->last_rx_packets = priv->rx_packets;
4084
4085 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4086 priv->last_tx_packets = priv->tx_packets;
4087
4088 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004089 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004090 * Missed beacon: 100% = 0, 0% = 70% missed
4091 * Rate: 60% = 1Mbs, 100% = Max
4092 * Rx and Tx errors represent a straight % of total Rx/Tx
4093 * RSSI: 100% = > -50, 0% = < -80
4094 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004095 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004096 * The lowest computed quality is used.
4097 *
4098 */
4099#define BEACON_THRESHOLD 5
4100 beacon_quality = 100 - missed_beacons_percent;
4101 if (beacon_quality < BEACON_THRESHOLD)
4102 beacon_quality = 0;
4103 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004104 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004105 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004106 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004107 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004108
James Ketrenos43f66a62005-03-25 12:31:53 -06004109 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004110 max_rate = ipw_get_max_rate(priv);
4111 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004112 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4113 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004114
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004115 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004116 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004117 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004118 else
4119 rx_quality = 100;
4120 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4121 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004122
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004123 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004124 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004125 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004126 else
4127 tx_quality = 100;
4128 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4129 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004130
Zhu Yi00d21de2006-04-13 17:19:02 +08004131 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004132 signal_quality =
4133 (100 *
4134 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4135 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4136 (priv->ieee->perfect_rssi - rssi) *
4137 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4138 62 * (priv->ieee->perfect_rssi - rssi))) /
4139 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4140 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4141 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004142 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004143 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004144 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004145
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004146 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004147 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004148
4149 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004150 min(rate_quality,
4151 min(tx_quality, min(rx_quality, signal_quality))));
4152 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004153 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4154 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004155 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004156 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4157 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004158 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004159 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4160 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004161 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004162 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4163 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004164 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004165 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4166 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004167
4168 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004169
4170 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 IPW_STATS_INTERVAL);
4172}
4173
James Ketrenosc848d0a2005-08-24 21:56:24 -05004174static void ipw_bg_gather_stats(void *data)
4175{
4176 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004177 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004178 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004179 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004180}
4181
Ben Cahille7582562005-10-06 15:34:41 -05004182/* Missed beacon behavior:
4183 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4184 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4185 * Above disassociate threshold, give up and stop scanning.
4186 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004187static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004188 int missed_count)
4189{
4190 priv->notif_missed_beacons = missed_count;
4191
James Ketrenosafbf30a2005-08-25 00:05:33 -05004192 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004193 priv->status & STATUS_ASSOCIATED) {
4194 /* If associated and we've hit the missed
4195 * beacon threshold, disassociate, turn
4196 * off roaming, and abort any active scans */
4197 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004198 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004199 "Missed beacon: %d - disassociate\n", missed_count);
4200 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004201 if (priv->status & STATUS_SCANNING) {
4202 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4203 IPW_DL_STATE,
4204 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004205 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004206 }
4207
James Ketrenosea2b26e2005-08-24 21:25:16 -05004208 queue_work(priv->workqueue, &priv->disassociate);
4209 return;
4210 }
4211
4212 if (priv->status & STATUS_ROAMING) {
4213 /* If we are currently roaming, then just
4214 * print a debug statement... */
4215 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4216 "Missed beacon: %d - roam in progress\n",
4217 missed_count);
4218 return;
4219 }
4220
Zhu Yi4bfdb912006-01-24 16:37:16 +08004221 if (roaming &&
4222 (missed_count > priv->roaming_threshold &&
4223 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004224 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004225 * bit in the status and kick off a scan.
4226 * This can happen several times before we reach
4227 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004228 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4229 "Missed beacon: %d - initiate "
4230 "roaming\n", missed_count);
4231 if (!(priv->status & STATUS_ROAMING)) {
4232 priv->status |= STATUS_ROAMING;
4233 if (!(priv->status & STATUS_SCANNING))
4234 queue_work(priv->workqueue,
4235 &priv->request_scan);
4236 }
4237 return;
4238 }
4239
4240 if (priv->status & STATUS_SCANNING) {
4241 /* Stop scan to keep fw from getting
4242 * stuck (only if we aren't roaming --
4243 * otherwise we'll never scan more than 2 or 3
4244 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004245 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4246 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004247 queue_work(priv->workqueue, &priv->abort_scan);
4248 }
4249
4250 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004251}
4252
James Ketrenos43f66a62005-03-25 12:31:53 -06004253/**
4254 * Handle host notification packet.
4255 * Called from interrupt routine
4256 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004257static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004258 struct ipw_rx_notification *notif)
4259{
James Ketrenosa613bff2005-08-24 21:43:11 -05004260 notif->size = le16_to_cpu(notif->size);
4261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004262 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004263
James Ketrenos43f66a62005-03-25 12:31:53 -06004264 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004265 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4266 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004267
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004268 switch (assoc->state) {
4269 case CMAS_ASSOCIATED:{
4270 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4271 IPW_DL_ASSOC,
4272 "associated: '%s' " MAC_FMT
4273 " \n",
4274 escape_essid(priv->essid,
4275 priv->essid_len),
4276 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004277
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004278 switch (priv->ieee->iw_mode) {
4279 case IW_MODE_INFRA:
4280 memcpy(priv->ieee->bssid,
4281 priv->bssid, ETH_ALEN);
4282 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004283
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004284 case IW_MODE_ADHOC:
4285 memcpy(priv->ieee->bssid,
4286 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004287
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004288 /* clear out the station table */
4289 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004290
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004291 IPW_DEBUG_ASSOC
4292 ("queueing adhoc check\n");
4293 queue_delayed_work(priv->
4294 workqueue,
4295 &priv->
4296 adhoc_check,
4297 priv->
4298 assoc_request.
4299 beacon_interval);
4300 break;
4301 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004302
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004303 priv->status &= ~STATUS_ASSOCIATING;
4304 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004305 queue_work(priv->workqueue,
4306 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004307
James Ketrenosb095c382005-08-24 22:04:42 -05004308#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004309#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4310 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4311 if ((priv->status & STATUS_AUTH) &&
4312 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4313 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004314 if ((sizeof
4315 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004316 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004317 <= notif->size)
4318 && (notif->size <= 2314)) {
4319 struct
4320 ieee80211_rx_stats
4321 stats = {
4322 .len =
4323 notif->
4324 size - 1,
4325 };
4326
4327 IPW_DEBUG_QOS
4328 ("QoS Associate "
4329 "size %d\n",
4330 notif->size);
4331 ieee80211_rx_mgt(priv->
4332 ieee,
4333 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004334 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004335 *)
4336 &notif->u.raw, &stats);
4337 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004338 }
James Ketrenosb095c382005-08-24 22:04:42 -05004339#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004340
James Ketrenosa613bff2005-08-24 21:43:11 -05004341 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004342
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004343 break;
4344 }
4345
4346 case CMAS_AUTHENTICATED:{
4347 if (priv->
4348 status & (STATUS_ASSOCIATED |
4349 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004350#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004351 struct notif_authenticate *auth
4352 = &notif->u.auth;
4353 IPW_DEBUG(IPW_DL_NOTIF |
4354 IPW_DL_STATE |
4355 IPW_DL_ASSOC,
4356 "deauthenticated: '%s' "
4357 MAC_FMT
4358 ": (0x%04X) - %s \n",
4359 escape_essid(priv->
4360 essid,
4361 priv->
4362 essid_len),
4363 MAC_ARG(priv->bssid),
4364 ntohs(auth->status),
4365 ipw_get_status_code
4366 (ntohs
4367 (auth->status)));
4368#endif
4369
4370 priv->status &=
4371 ~(STATUS_ASSOCIATING |
4372 STATUS_AUTH |
4373 STATUS_ASSOCIATED);
4374
James Ketrenosa613bff2005-08-24 21:43:11 -05004375 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004376 break;
4377 }
4378
4379 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4380 IPW_DL_ASSOC,
4381 "authenticated: '%s' " MAC_FMT
4382 "\n",
4383 escape_essid(priv->essid,
4384 priv->essid_len),
4385 MAC_ARG(priv->bssid));
4386 break;
4387 }
4388
4389 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004390 if (priv->status & STATUS_AUTH) {
4391 struct
4392 ieee80211_assoc_response
4393 *resp;
4394 resp =
4395 (struct
4396 ieee80211_assoc_response
4397 *)&notif->u.raw;
4398 IPW_DEBUG(IPW_DL_NOTIF |
4399 IPW_DL_STATE |
4400 IPW_DL_ASSOC,
4401 "association failed (0x%04X): %s\n",
4402 ntohs(resp->status),
4403 ipw_get_status_code
4404 (ntohs
4405 (resp->status)));
4406 }
4407
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4409 IPW_DL_ASSOC,
4410 "disassociated: '%s' " MAC_FMT
4411 " \n",
4412 escape_essid(priv->essid,
4413 priv->essid_len),
4414 MAC_ARG(priv->bssid));
4415
4416 priv->status &=
4417 ~(STATUS_DISASSOCIATING |
4418 STATUS_ASSOCIATING |
4419 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004420 if (priv->assoc_network
4421 && (priv->assoc_network->
4422 capability &
4423 WLAN_CAPABILITY_IBSS))
4424 ipw_remove_current_network
4425 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004426
James Ketrenosa613bff2005-08-24 21:43:11 -05004427 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004428
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004429 break;
4430 }
4431
James Ketrenosb095c382005-08-24 22:04:42 -05004432 case CMAS_RX_ASSOC_RESP:
4433 break;
4434
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004435 default:
4436 IPW_ERROR("assoc: unknown (%d)\n",
4437 assoc->state);
4438 break;
4439 }
4440
James Ketrenos43f66a62005-03-25 12:31:53 -06004441 break;
4442 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004443
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004444 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4445 struct notif_authenticate *auth = &notif->u.auth;
4446 switch (auth->state) {
4447 case CMAS_AUTHENTICATED:
4448 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4449 "authenticated: '%s' " MAC_FMT " \n",
4450 escape_essid(priv->essid,
4451 priv->essid_len),
4452 MAC_ARG(priv->bssid));
4453 priv->status |= STATUS_AUTH;
4454 break;
4455
4456 case CMAS_INIT:
4457 if (priv->status & STATUS_AUTH) {
4458 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4459 IPW_DL_ASSOC,
4460 "authentication failed (0x%04X): %s\n",
4461 ntohs(auth->status),
4462 ipw_get_status_code(ntohs
4463 (auth->
4464 status)));
4465 }
4466 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4467 IPW_DL_ASSOC,
4468 "deauthenticated: '%s' " MAC_FMT "\n",
4469 escape_essid(priv->essid,
4470 priv->essid_len),
4471 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004472
4473 priv->status &= ~(STATUS_ASSOCIATING |
4474 STATUS_AUTH |
4475 STATUS_ASSOCIATED);
4476
James Ketrenosa613bff2005-08-24 21:43:11 -05004477 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004478 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004479
4480 case CMAS_TX_AUTH_SEQ_1:
4481 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4482 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4483 break;
4484 case CMAS_RX_AUTH_SEQ_2:
4485 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4486 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4487 break;
4488 case CMAS_AUTH_SEQ_1_PASS:
4489 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4490 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4491 break;
4492 case CMAS_AUTH_SEQ_1_FAIL:
4493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4494 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4495 break;
4496 case CMAS_TX_AUTH_SEQ_3:
4497 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4498 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4499 break;
4500 case CMAS_RX_AUTH_SEQ_4:
4501 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4502 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4503 break;
4504 case CMAS_AUTH_SEQ_2_PASS:
4505 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4506 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4507 break;
4508 case CMAS_AUTH_SEQ_2_FAIL:
4509 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4510 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4511 break;
4512 case CMAS_TX_ASSOC:
4513 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4514 IPW_DL_ASSOC, "TX_ASSOC\n");
4515 break;
4516 case CMAS_RX_ASSOC_RESP:
4517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4518 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004519
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 break;
4521 case CMAS_ASSOCIATED:
4522 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4523 IPW_DL_ASSOC, "ASSOCIATED\n");
4524 break;
4525 default:
4526 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4527 auth->state);
4528 break;
4529 }
4530 break;
4531 }
4532
4533 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4534 struct notif_channel_result *x =
4535 &notif->u.channel_result;
4536
4537 if (notif->size == sizeof(*x)) {
4538 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4539 x->channel_num);
4540 } else {
4541 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4542 "(should be %zd)\n",
4543 notif->size, sizeof(*x));
4544 }
4545 break;
4546 }
4547
4548 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4549 struct notif_scan_complete *x = &notif->u.scan_complete;
4550 if (notif->size == sizeof(*x)) {
4551 IPW_DEBUG_SCAN
4552 ("Scan completed: type %d, %d channels, "
4553 "%d status\n", x->scan_type,
4554 x->num_channels, x->status);
4555 } else {
4556 IPW_ERROR("Scan completed of wrong size %d "
4557 "(should be %zd)\n",
4558 notif->size, sizeof(*x));
4559 }
4560
4561 priv->status &=
4562 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4563
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004564 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004565 cancel_delayed_work(&priv->scan_check);
4566
James Ketrenosb095c382005-08-24 22:04:42 -05004567 if (priv->status & STATUS_EXIT_PENDING)
4568 break;
4569
4570 priv->ieee->scans++;
4571
4572#ifdef CONFIG_IPW2200_MONITOR
4573 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004574 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004575 queue_work(priv->workqueue,
4576 &priv->request_scan);
4577 break;
4578 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004579 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004580#endif /* CONFIG_IPW2200_MONITOR */
4581
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004582 if (!(priv->status & (STATUS_ASSOCIATED |
4583 STATUS_ASSOCIATING |
4584 STATUS_ROAMING |
4585 STATUS_DISASSOCIATING)))
4586 queue_work(priv->workqueue, &priv->associate);
4587 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004588 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4589 /* If a scan completed and we are in roam mode, then
4590 * the scan that completed was the one requested as a
4591 * result of entering roam... so, schedule the
4592 * roam work */
4593 queue_work(priv->workqueue,
4594 &priv->roam);
4595 else
4596 /* Don't schedule if we aborted the scan */
4597 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004598 } else if (priv->status & STATUS_SCAN_PENDING)
4599 queue_work(priv->workqueue,
4600 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004601 else if (priv->config & CFG_BACKGROUND_SCAN
4602 && priv->status & STATUS_ASSOCIATED)
4603 queue_delayed_work(priv->workqueue,
4604 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004605
4606 /* Send an empty event to user space.
4607 * We don't send the received data on the event because
4608 * it would require us to do complex transcoding, and
4609 * we want to minimise the work done in the irq handler
4610 * Use a request to extract the data.
4611 * Also, we generate this even for any scan, regardless
4612 * on how the scan was initiated. User space can just
4613 * sync on periodic scan to get fresh data...
4614 * Jean II */
4615 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4616 union iwreq_data wrqu;
4617
4618 wrqu.data.length = 0;
4619 wrqu.data.flags = 0;
4620 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4621 &wrqu, NULL);
4622 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004623 break;
4624 }
4625
4626 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4627 struct notif_frag_length *x = &notif->u.frag_len;
4628
James Ketrenosa613bff2005-08-24 21:43:11 -05004629 if (notif->size == sizeof(*x))
4630 IPW_ERROR("Frag length: %d\n",
4631 le16_to_cpu(x->frag_length));
4632 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004633 IPW_ERROR("Frag length of wrong size %d "
4634 "(should be %zd)\n",
4635 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004636 break;
4637 }
4638
4639 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4640 struct notif_link_deterioration *x =
4641 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004642
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004643 if (notif->size == sizeof(*x)) {
4644 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004645 "link deterioration: type %d, cnt %d\n",
4646 x->silence_notification_type,
4647 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004648 memcpy(&priv->last_link_deterioration, x,
4649 sizeof(*x));
4650 } else {
4651 IPW_ERROR("Link Deterioration of wrong size %d "
4652 "(should be %zd)\n",
4653 notif->size, sizeof(*x));
4654 }
4655 break;
4656 }
4657
4658 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4659 IPW_ERROR("Dino config\n");
4660 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004661 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004662 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004663
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004664 break;
4665 }
4666
4667 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4668 struct notif_beacon_state *x = &notif->u.beacon_state;
4669 if (notif->size != sizeof(*x)) {
4670 IPW_ERROR
4671 ("Beacon state of wrong size %d (should "
4672 "be %zd)\n", notif->size, sizeof(*x));
4673 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004674 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004675
James Ketrenosa613bff2005-08-24 21:43:11 -05004676 if (le32_to_cpu(x->state) ==
4677 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4678 ipw_handle_missed_beacon(priv,
4679 le32_to_cpu(x->
4680 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004681
James Ketrenos43f66a62005-03-25 12:31:53 -06004682 break;
4683 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004684
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004685 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4686 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4687 if (notif->size == sizeof(*x)) {
4688 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4689 "0x%02x station %d\n",
4690 x->key_state, x->security_type,
4691 x->station_index);
4692 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004693 }
4694
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004695 IPW_ERROR
4696 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4697 notif->size, sizeof(*x));
4698 break;
4699 }
4700
4701 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4702 struct notif_calibration *x = &notif->u.calibration;
4703
4704 if (notif->size == sizeof(*x)) {
4705 memcpy(&priv->calib, x, sizeof(*x));
4706 IPW_DEBUG_INFO("TODO: Calibration\n");
4707 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004708 }
4709
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004710 IPW_ERROR
4711 ("Calibration of wrong size %d (should be %zd)\n",
4712 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004713 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004714 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004715
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004716 case HOST_NOTIFICATION_NOISE_STATS:{
4717 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004718 priv->exp_avg_noise =
4719 exponential_average(priv->exp_avg_noise,
4720 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4721 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004722 break;
4723 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004724
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004725 IPW_ERROR
4726 ("Noise stat is wrong size %d (should be %zd)\n",
4727 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004728 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004729 }
4730
James Ketrenos43f66a62005-03-25 12:31:53 -06004731 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004732 IPW_DEBUG_NOTIF("Unknown notification: "
4733 "subtype=%d,flags=0x%2x,size=%d\n",
4734 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004735 }
4736}
4737
4738/**
4739 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004740 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004741 * @param priv
4742 * @return error code
4743 */
4744static int ipw_queue_reset(struct ipw_priv *priv)
4745{
4746 int rc = 0;
4747 /** @todo customize queue sizes */
4748 int nTx = 64, nTxCmd = 8;
4749 ipw_tx_queue_free(priv);
4750 /* Tx CMD queue */
4751 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004752 IPW_TX_CMD_QUEUE_READ_INDEX,
4753 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4754 IPW_TX_CMD_QUEUE_BD_BASE,
4755 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004756 if (rc) {
4757 IPW_ERROR("Tx Cmd queue init failed\n");
4758 goto error;
4759 }
4760 /* Tx queue(s) */
4761 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004762 IPW_TX_QUEUE_0_READ_INDEX,
4763 IPW_TX_QUEUE_0_WRITE_INDEX,
4764 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004765 if (rc) {
4766 IPW_ERROR("Tx 0 queue init failed\n");
4767 goto error;
4768 }
4769 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004770 IPW_TX_QUEUE_1_READ_INDEX,
4771 IPW_TX_QUEUE_1_WRITE_INDEX,
4772 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004773 if (rc) {
4774 IPW_ERROR("Tx 1 queue init failed\n");
4775 goto error;
4776 }
4777 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004778 IPW_TX_QUEUE_2_READ_INDEX,
4779 IPW_TX_QUEUE_2_WRITE_INDEX,
4780 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004781 if (rc) {
4782 IPW_ERROR("Tx 2 queue init failed\n");
4783 goto error;
4784 }
4785 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004786 IPW_TX_QUEUE_3_READ_INDEX,
4787 IPW_TX_QUEUE_3_WRITE_INDEX,
4788 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004789 if (rc) {
4790 IPW_ERROR("Tx 3 queue init failed\n");
4791 goto error;
4792 }
4793 /* statistics */
4794 priv->rx_bufs_min = 0;
4795 priv->rx_pend_max = 0;
4796 return rc;
4797
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004798 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004799 ipw_tx_queue_free(priv);
4800 return rc;
4801}
4802
4803/**
4804 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004805 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004806 * When FW adwances 'R' index, all entries between old and
4807 * new 'R' index need to be reclaimed. As result, some free space
4808 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004809 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004810 * @note Need to protect against garbage in 'R' index
4811 * @param priv
4812 * @param txq
4813 * @param qindex
4814 * @return Number of used entries remains in the queue
4815 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004816static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004817 struct clx2_tx_queue *txq, int qindex)
4818{
4819 u32 hw_tail;
4820 int used;
4821 struct clx2_queue *q = &txq->q;
4822
4823 hw_tail = ipw_read32(priv, q->reg_r);
4824 if (hw_tail >= q->n_bd) {
4825 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004826 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4827 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004828 goto done;
4829 }
4830 for (; q->last_used != hw_tail;
4831 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4832 ipw_queue_tx_free_tfd(priv, txq);
4833 priv->tx_packets++;
4834 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004835 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004836 if ((ipw_queue_space(q) > q->low_mark) &&
4837 (qindex >= 0) &&
4838 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4839 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004840 used = q->first_empty - q->last_used;
4841 if (used < 0)
4842 used += q->n_bd;
4843
4844 return used;
4845}
4846
4847static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4848 int len, int sync)
4849{
4850 struct clx2_tx_queue *txq = &priv->txq_cmd;
4851 struct clx2_queue *q = &txq->q;
4852 struct tfd_frame *tfd;
4853
4854 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4855 IPW_ERROR("No space for Tx\n");
4856 return -EBUSY;
4857 }
4858
4859 tfd = &txq->bd[q->first_empty];
4860 txq->txb[q->first_empty] = NULL;
4861
4862 memset(tfd, 0, sizeof(*tfd));
4863 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4864 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4865 priv->hcmd_seq++;
4866 tfd->u.cmd.index = hcmd;
4867 tfd->u.cmd.length = len;
4868 memcpy(tfd->u.cmd.payload, buf, len);
4869 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4870 ipw_write32(priv, q->reg_w, q->first_empty);
4871 _ipw_read32(priv, 0x90);
4872
4873 return 0;
4874}
4875
Jeff Garzikbf794512005-07-31 13:07:26 -04004876/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004877 * Rx theory of operation
4878 *
4879 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004880 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004881 * 0 to 31
4882 *
4883 * Rx Queue Indexes
4884 * The host/firmware share two index registers for managing the Rx buffers.
4885 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004886 * The READ index maps to the first position that the firmware may be writing
4887 * to -- the driver can read up to (but not including) this position and get
4888 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004889 * The READ index is managed by the firmware once the card is enabled.
4890 *
4891 * The WRITE index maps to the last position the driver has read from -- the
4892 * position preceding WRITE is the last slot the firmware can place a packet.
4893 *
4894 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004895 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004896 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004897 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004898 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4899 *
4900 * When the firmware places a packet in a buffer it will advance the READ index
4901 * and fire the RX interrupt. The driver can then query the READ index and
4902 * process as many packets as possible, moving the WRITE index forward as it
4903 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004904 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004905 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004906 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004907 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004908 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004909 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4910 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4911 * 'processed' and 'read' driver indexes as well)
4912 * + A received packet is processed and handed to the kernel network stack,
4913 * detached from the ipw->rxq. The driver 'processed' index is updated.
4914 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004915 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4916 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004917 * were enough free buffers and RX_STALLED is set it is cleared.
4918 *
4919 *
4920 * Driver sequence:
4921 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004922 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004923 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4924 * ipw_rx_queue_restock
4925 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4926 * queue, updates firmware pointers, and updates
4927 * the WRITE index. If insufficient rx_free buffers
4928 * are available, schedules ipw_rx_queue_replenish
4929 *
4930 * -- enable interrupts --
4931 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004932 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004933 * Moves the packet buffer from queue to rx_used.
4934 * Calls ipw_rx_queue_restock to refill any empty
4935 * slots.
4936 * ...
4937 *
4938 */
4939
Jeff Garzikbf794512005-07-31 13:07:26 -04004940/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 * If there are slots in the RX queue that need to be restocked,
4942 * and we have free pre-allocated buffers, fill the ranks as much
4943 * as we can pulling from rx_free.
4944 *
4945 * This moves the 'write' index forward to catch up with 'processed', and
4946 * also updates the memory address in the firmware to reference the new
4947 * target buffer.
4948 */
4949static void ipw_rx_queue_restock(struct ipw_priv *priv)
4950{
4951 struct ipw_rx_queue *rxq = priv->rxq;
4952 struct list_head *element;
4953 struct ipw_rx_mem_buffer *rxb;
4954 unsigned long flags;
4955 int write;
4956
4957 spin_lock_irqsave(&rxq->lock, flags);
4958 write = rxq->write;
4959 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4960 element = rxq->rx_free.next;
4961 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4962 list_del(element);
4963
James Ketrenosb095c382005-08-24 22:04:42 -05004964 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004965 rxb->dma_addr);
4966 rxq->queue[rxq->write] = rxb;
4967 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4968 rxq->free_count--;
4969 }
4970 spin_unlock_irqrestore(&rxq->lock, flags);
4971
Jeff Garzikbf794512005-07-31 13:07:26 -04004972 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 * refill it */
4974 if (rxq->free_count <= RX_LOW_WATERMARK)
4975 queue_work(priv->workqueue, &priv->rx_replenish);
4976
4977 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004978 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004979 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004980}
4981
4982/*
4983 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004984 * Also restock the Rx queue via ipw_rx_queue_restock.
4985 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004986 * This is called as a scheduled work item (except for during intialization)
4987 */
4988static void ipw_rx_queue_replenish(void *data)
4989{
4990 struct ipw_priv *priv = data;
4991 struct ipw_rx_queue *rxq = priv->rxq;
4992 struct list_head *element;
4993 struct ipw_rx_mem_buffer *rxb;
4994 unsigned long flags;
4995
4996 spin_lock_irqsave(&rxq->lock, flags);
4997 while (!list_empty(&rxq->rx_used)) {
4998 element = rxq->rx_used.next;
4999 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005000 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005001 if (!rxb->skb) {
5002 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5003 priv->net_dev->name);
5004 /* We don't reschedule replenish work here -- we will
5005 * call the restock method and if it still needs
5006 * more buffers it will schedule replenish */
5007 break;
5008 }
5009 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005010
James Ketrenos43f66a62005-03-25 12:31:53 -06005011 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005012 rxb->dma_addr =
5013 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005014 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005015
James Ketrenos43f66a62005-03-25 12:31:53 -06005016 list_add_tail(&rxb->list, &rxq->rx_free);
5017 rxq->free_count++;
5018 }
5019 spin_unlock_irqrestore(&rxq->lock, flags);
5020
5021 ipw_rx_queue_restock(priv);
5022}
5023
James Ketrenosc848d0a2005-08-24 21:56:24 -05005024static void ipw_bg_rx_queue_replenish(void *data)
5025{
5026 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005027 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005028 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08005029 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005030}
5031
James Ketrenos43f66a62005-03-25 12:31:53 -06005032/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005033 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005034 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005035 * non NULL it is unmapped and freed
5036 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005037static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005038{
5039 int i;
5040
5041 if (!rxq)
5042 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005043
James Ketrenos43f66a62005-03-25 12:31:53 -06005044 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5045 if (rxq->pool[i].skb != NULL) {
5046 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005047 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 dev_kfree_skb(rxq->pool[i].skb);
5049 }
5050 }
5051
5052 kfree(rxq);
5053}
5054
5055static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5056{
5057 struct ipw_rx_queue *rxq;
5058 int i;
5059
Takisc75f4742005-12-01 01:41:45 -08005060 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005061 if (unlikely(!rxq)) {
5062 IPW_ERROR("memory allocation failed\n");
5063 return NULL;
5064 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005065 spin_lock_init(&rxq->lock);
5066 INIT_LIST_HEAD(&rxq->rx_free);
5067 INIT_LIST_HEAD(&rxq->rx_used);
5068
5069 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005070 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005071 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5072
5073 /* Set us so that we have processed and used all buffers, but have
5074 * not restocked the Rx queue with fresh buffers */
5075 rxq->read = rxq->write = 0;
5076 rxq->processed = RX_QUEUE_SIZE - 1;
5077 rxq->free_count = 0;
5078
5079 return rxq;
5080}
5081
5082static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5083{
5084 rate &= ~IEEE80211_BASIC_RATE_MASK;
5085 if (ieee_mode == IEEE_A) {
5086 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005087 case IEEE80211_OFDM_RATE_6MB:
5088 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005089 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005090 case IEEE80211_OFDM_RATE_9MB:
5091 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005092 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005093 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005094 return priv->
5095 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005096 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005097 return priv->
5098 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005099 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005100 return priv->
5101 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005102 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005103 return priv->
5104 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005105 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005106 return priv->
5107 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005108 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005109 return priv->
5110 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005111 default:
5112 return 0;
5113 }
5114 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005115
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 /* B and G mixed */
5117 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005118 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005119 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005120 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005121 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005122 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005123 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005124 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005125 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5126 }
5127
5128 /* If we are limited to B modulations, bail at this point */
5129 if (ieee_mode == IEEE_B)
5130 return 0;
5131
5132 /* G */
5133 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005134 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005135 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005136 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005137 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005138 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005139 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005140 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005141 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005142 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005143 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005144 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005145 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005146 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005147 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005148 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005149 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5150 }
5151
5152 return 0;
5153}
5154
Jeff Garzikbf794512005-07-31 13:07:26 -04005155static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005156 const struct ieee80211_network *network,
5157 struct ipw_supported_rates *rates)
5158{
5159 int num_rates, i;
5160
5161 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005162 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005163 rates->num_rates = 0;
5164 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005165 if (!ipw_is_rate_in_mask(priv, network->mode,
5166 network->rates[i])) {
5167
James Ketrenosea2b26e2005-08-24 21:25:16 -05005168 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005169 IPW_DEBUG_SCAN("Adding masked mandatory "
5170 "rate %02X\n",
5171 network->rates[i]);
5172 rates->supported_rates[rates->num_rates++] =
5173 network->rates[i];
5174 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005175 }
5176
James Ketrenos43f66a62005-03-25 12:31:53 -06005177 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5178 network->rates[i], priv->rates_mask);
5179 continue;
5180 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005181
James Ketrenos43f66a62005-03-25 12:31:53 -06005182 rates->supported_rates[rates->num_rates++] = network->rates[i];
5183 }
5184
James Ketrenosa613bff2005-08-24 21:43:11 -05005185 num_rates = min(network->rates_ex_len,
5186 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005187 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005188 if (!ipw_is_rate_in_mask(priv, network->mode,
5189 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005190 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005191 IPW_DEBUG_SCAN("Adding masked mandatory "
5192 "rate %02X\n",
5193 network->rates_ex[i]);
5194 rates->supported_rates[rates->num_rates++] =
5195 network->rates[i];
5196 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005197 }
5198
James Ketrenos43f66a62005-03-25 12:31:53 -06005199 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5200 network->rates_ex[i], priv->rates_mask);
5201 continue;
5202 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005203
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005204 rates->supported_rates[rates->num_rates++] =
5205 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005206 }
5207
James Ketrenosea2b26e2005-08-24 21:25:16 -05005208 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005209}
5210
Arjan van de Ven858119e2006-01-14 13:20:43 -08005211static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005212 const struct ipw_supported_rates *src)
5213{
5214 u8 i;
5215 for (i = 0; i < src->num_rates; i++)
5216 dest->supported_rates[i] = src->supported_rates[i];
5217 dest->num_rates = src->num_rates;
5218}
5219
5220/* TODO: Look at sniffed packets in the air to determine if the basic rate
5221 * mask should ever be used -- right now all callers to add the scan rates are
5222 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5223static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005224 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005225{
Jeff Garzikbf794512005-07-31 13:07:26 -04005226 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005227 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005228
James Ketrenos43f66a62005-03-25 12:31:53 -06005229 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005230 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005231 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005232
5233 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005234 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005235 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005236
5237 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005238 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005239 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005240
5241 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005242 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005243 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005244}
5245
5246static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005247 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005248{
Jeff Garzikbf794512005-07-31 13:07:26 -04005249 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005250 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005251
5252 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005253 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005254 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005255
5256 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005257 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005258 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005259
5260 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005261 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005262 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005263
5264 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005265 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005266 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005267
5268 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005269 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005270 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005271
5272 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005273 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005274 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005275
5276 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005277 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005278 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005279
5280 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005281 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005282 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283}
5284
5285struct ipw_network_match {
5286 struct ieee80211_network *network;
5287 struct ipw_supported_rates rates;
5288};
5289
James Ketrenosc848d0a2005-08-24 21:56:24 -05005290static int ipw_find_adhoc_network(struct ipw_priv *priv,
5291 struct ipw_network_match *match,
5292 struct ieee80211_network *network,
5293 int roaming)
5294{
5295 struct ipw_supported_rates rates;
5296
5297 /* Verify that this network's capability is compatible with the
5298 * current mode (AdHoc or Infrastructure) */
5299 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5300 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5301 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5302 "capability mismatch.\n",
5303 escape_essid(network->ssid, network->ssid_len),
5304 MAC_ARG(network->bssid));
5305 return 0;
5306 }
5307
5308 /* If we do not have an ESSID for this AP, we can not associate with
5309 * it */
5310 if (network->flags & NETWORK_EMPTY_ESSID) {
5311 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5312 "because of hidden ESSID.\n",
5313 escape_essid(network->ssid, network->ssid_len),
5314 MAC_ARG(network->bssid));
5315 return 0;
5316 }
5317
5318 if (unlikely(roaming)) {
5319 /* If we are roaming, then ensure check if this is a valid
5320 * network to try and roam to */
5321 if ((network->ssid_len != match->network->ssid_len) ||
5322 memcmp(network->ssid, match->network->ssid,
5323 network->ssid_len)) {
5324 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5325 "because of non-network ESSID.\n",
5326 escape_essid(network->ssid,
5327 network->ssid_len),
5328 MAC_ARG(network->bssid));
5329 return 0;
5330 }
5331 } else {
5332 /* If an ESSID has been configured then compare the broadcast
5333 * ESSID to ours */
5334 if ((priv->config & CFG_STATIC_ESSID) &&
5335 ((network->ssid_len != priv->essid_len) ||
5336 memcmp(network->ssid, priv->essid,
5337 min(network->ssid_len, priv->essid_len)))) {
5338 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005339
James Ketrenosc848d0a2005-08-24 21:56:24 -05005340 strncpy(escaped,
5341 escape_essid(network->ssid, network->ssid_len),
5342 sizeof(escaped));
5343 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5344 "because of ESSID mismatch: '%s'.\n",
5345 escaped, MAC_ARG(network->bssid),
5346 escape_essid(priv->essid,
5347 priv->essid_len));
5348 return 0;
5349 }
5350 }
5351
5352 /* If the old network rate is better than this one, don't bother
5353 * testing everything else. */
5354
5355 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005356 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5357 "current network.\n",
5358 escape_essid(match->network->ssid,
5359 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005360 return 0;
5361 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005362 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5363 "current network.\n",
5364 escape_essid(match->network->ssid,
5365 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005366 return 0;
5367 }
5368
5369 /* Now go through and see if the requested network is valid... */
5370 if (priv->ieee->scan_age != 0 &&
5371 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5372 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005373 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005374 escape_essid(network->ssid, network->ssid_len),
5375 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005376 jiffies_to_msecs(jiffies -
5377 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005378 return 0;
5379 }
5380
5381 if ((priv->config & CFG_STATIC_CHANNEL) &&
5382 (network->channel != priv->channel)) {
5383 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5384 "because of channel mismatch: %d != %d.\n",
5385 escape_essid(network->ssid, network->ssid_len),
5386 MAC_ARG(network->bssid),
5387 network->channel, priv->channel);
5388 return 0;
5389 }
5390
5391 /* Verify privacy compatability */
5392 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5393 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5394 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5395 "because of privacy mismatch: %s != %s.\n",
5396 escape_essid(network->ssid, network->ssid_len),
5397 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005398 priv->
5399 capability & CAP_PRIVACY_ON ? "on" : "off",
5400 network->
5401 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5402 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005403 return 0;
5404 }
5405
5406 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5407 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5408 "because of the same BSSID match: " MAC_FMT
5409 ".\n", escape_essid(network->ssid,
5410 network->ssid_len),
5411 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5412 return 0;
5413 }
5414
5415 /* Filter out any incompatible freq / mode combinations */
5416 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5417 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5418 "because of invalid frequency/mode "
5419 "combination.\n",
5420 escape_essid(network->ssid, network->ssid_len),
5421 MAC_ARG(network->bssid));
5422 return 0;
5423 }
5424
5425 /* Ensure that the rates supported by the driver are compatible with
5426 * this AP, including verification of basic rates (mandatory) */
5427 if (!ipw_compatible_rates(priv, network, &rates)) {
5428 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5429 "because configured rate mask excludes "
5430 "AP mandatory rate.\n",
5431 escape_essid(network->ssid, network->ssid_len),
5432 MAC_ARG(network->bssid));
5433 return 0;
5434 }
5435
5436 if (rates.num_rates == 0) {
5437 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5438 "because of no compatible rates.\n",
5439 escape_essid(network->ssid, network->ssid_len),
5440 MAC_ARG(network->bssid));
5441 return 0;
5442 }
5443
5444 /* TODO: Perform any further minimal comparititive tests. We do not
5445 * want to put too much policy logic here; intelligent scan selection
5446 * should occur within a generic IEEE 802.11 user space tool. */
5447
5448 /* Set up 'new' AP to this network */
5449 ipw_copy_rates(&match->rates, &rates);
5450 match->network = network;
5451 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5452 escape_essid(network->ssid, network->ssid_len),
5453 MAC_ARG(network->bssid));
5454
5455 return 1;
5456}
5457
5458static void ipw_merge_adhoc_network(void *data)
5459{
5460 struct ipw_priv *priv = data;
5461 struct ieee80211_network *network = NULL;
5462 struct ipw_network_match match = {
5463 .network = priv->assoc_network
5464 };
5465
James Ketrenosafbf30a2005-08-25 00:05:33 -05005466 if ((priv->status & STATUS_ASSOCIATED) &&
5467 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005468 /* First pass through ROAM process -- look for a better
5469 * network */
5470 unsigned long flags;
5471
5472 spin_lock_irqsave(&priv->ieee->lock, flags);
5473 list_for_each_entry(network, &priv->ieee->network_list, list) {
5474 if (network != priv->assoc_network)
5475 ipw_find_adhoc_network(priv, &match, network,
5476 1);
5477 }
5478 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5479
5480 if (match.network == priv->assoc_network) {
5481 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5482 "merge to.\n");
5483 return;
5484 }
5485
Zhu Yi46441512006-01-24 16:37:59 +08005486 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005487 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5488 IPW_DEBUG_MERGE("remove network %s\n",
5489 escape_essid(priv->essid,
5490 priv->essid_len));
5491 ipw_remove_current_network(priv);
5492 }
5493
5494 ipw_disassociate(priv);
5495 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005496 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005497 return;
5498 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005499}
5500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005501static int ipw_best_network(struct ipw_priv *priv,
5502 struct ipw_network_match *match,
5503 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005504{
5505 struct ipw_supported_rates rates;
5506
5507 /* Verify that this network's capability is compatible with the
5508 * current mode (AdHoc or Infrastructure) */
5509 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005510 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005511 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5512 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5513 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005514 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005515 escape_essid(network->ssid, network->ssid_len),
5516 MAC_ARG(network->bssid));
5517 return 0;
5518 }
5519
5520 /* If we do not have an ESSID for this AP, we can not associate with
5521 * it */
5522 if (network->flags & NETWORK_EMPTY_ESSID) {
5523 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5524 "because of hidden ESSID.\n",
5525 escape_essid(network->ssid, network->ssid_len),
5526 MAC_ARG(network->bssid));
5527 return 0;
5528 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005529
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 if (unlikely(roaming)) {
5531 /* If we are roaming, then ensure check if this is a valid
5532 * network to try and roam to */
5533 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005534 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005535 network->ssid_len)) {
5536 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5537 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005538 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005539 network->ssid_len),
5540 MAC_ARG(network->bssid));
5541 return 0;
5542 }
5543 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005544 /* If an ESSID has been configured then compare the broadcast
5545 * ESSID to ours */
5546 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005547 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005548 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005549 min(network->ssid_len, priv->essid_len)))) {
5550 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005551 strncpy(escaped,
5552 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005553 sizeof(escaped));
5554 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005555 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005556 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005557 escape_essid(priv->essid,
5558 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005559 return 0;
5560 }
5561 }
5562
5563 /* If the old network rate is better than this one, don't bother
5564 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005565 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005566 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005567 strncpy(escaped,
5568 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005569 sizeof(escaped));
5570 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5571 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5572 escaped, MAC_ARG(network->bssid),
5573 escape_essid(match->network->ssid,
5574 match->network->ssid_len),
5575 MAC_ARG(match->network->bssid));
5576 return 0;
5577 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005578
James Ketrenos43f66a62005-03-25 12:31:53 -06005579 /* If this network has already had an association attempt within the
5580 * last 3 seconds, do not try and associate again... */
5581 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005582 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005583 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005584 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005585 "assoc attempt).\n",
5586 escape_essid(network->ssid, network->ssid_len),
5587 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005588 jiffies_to_msecs(jiffies -
5589 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005590 return 0;
5591 }
5592
5593 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005594 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005595 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005596 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005597 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005598 escape_essid(network->ssid, network->ssid_len),
5599 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005600 jiffies_to_msecs(jiffies -
5601 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005602 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005603 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005604
Jeff Garzikbf794512005-07-31 13:07:26 -04005605 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005606 (network->channel != priv->channel)) {
5607 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5608 "because of channel mismatch: %d != %d.\n",
5609 escape_essid(network->ssid, network->ssid_len),
5610 MAC_ARG(network->bssid),
5611 network->channel, priv->channel);
5612 return 0;
5613 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005614
James Ketrenos43f66a62005-03-25 12:31:53 -06005615 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005616 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005617 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5618 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5619 "because of privacy mismatch: %s != %s.\n",
5620 escape_essid(network->ssid, network->ssid_len),
5621 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005622 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005623 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005624 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005625 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005626 return 0;
5627 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005628
5629 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005630 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5631 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5632 "because of BSSID mismatch: " MAC_FMT ".\n",
5633 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005634 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005635 return 0;
5636 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005637
James Ketrenos43f66a62005-03-25 12:31:53 -06005638 /* Filter out any incompatible freq / mode combinations */
5639 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5640 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5641 "because of invalid frequency/mode "
5642 "combination.\n",
5643 escape_essid(network->ssid, network->ssid_len),
5644 MAC_ARG(network->bssid));
5645 return 0;
5646 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005647
Liu Hong1fe0adb2005-08-19 09:33:10 -05005648 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005649 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005650 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5651 "because of invalid channel in current GEO\n",
5652 escape_essid(network->ssid, network->ssid_len),
5653 MAC_ARG(network->bssid));
5654 return 0;
5655 }
5656
James Ketrenosea2b26e2005-08-24 21:25:16 -05005657 /* Ensure that the rates supported by the driver are compatible with
5658 * this AP, including verification of basic rates (mandatory) */
5659 if (!ipw_compatible_rates(priv, network, &rates)) {
5660 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5661 "because configured rate mask excludes "
5662 "AP mandatory rate.\n",
5663 escape_essid(network->ssid, network->ssid_len),
5664 MAC_ARG(network->bssid));
5665 return 0;
5666 }
5667
James Ketrenos43f66a62005-03-25 12:31:53 -06005668 if (rates.num_rates == 0) {
5669 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5670 "because of no compatible rates.\n",
5671 escape_essid(network->ssid, network->ssid_len),
5672 MAC_ARG(network->bssid));
5673 return 0;
5674 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005675
James Ketrenos43f66a62005-03-25 12:31:53 -06005676 /* TODO: Perform any further minimal comparititive tests. We do not
5677 * want to put too much policy logic here; intelligent scan selection
5678 * should occur within a generic IEEE 802.11 user space tool. */
5679
5680 /* Set up 'new' AP to this network */
5681 ipw_copy_rates(&match->rates, &rates);
5682 match->network = network;
5683
5684 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5685 escape_essid(network->ssid, network->ssid_len),
5686 MAC_ARG(network->bssid));
5687
5688 return 1;
5689}
5690
Jeff Garzikbf794512005-07-31 13:07:26 -04005691static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005692 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005693{
Larry Finger1867b112006-02-28 09:48:28 -06005694 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005695 int i;
5696
James Ketrenos43f66a62005-03-25 12:31:53 -06005697 /*
5698 * For the purposes of scanning, we can set our wireless mode
5699 * to trigger scans across combinations of bands, but when it
5700 * comes to creating a new ad-hoc network, we have tell the FW
5701 * exactly which band to use.
5702 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005703 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005704 * chossen band. Attempting to create a new ad-hoc network
5705 * with an invalid channel for wireless mode will trigger a
5706 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005707 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005708 */
Larry Finger1867b112006-02-28 09:48:28 -06005709 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005710 case IEEE80211_52GHZ_BAND:
5711 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005712 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005713 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005714 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5715 IPW_WARNING("Overriding invalid channel\n");
5716 priv->channel = geo->a[0].channel;
5717 }
5718 break;
5719
5720 case IEEE80211_24GHZ_BAND:
5721 if (priv->ieee->mode & IEEE_G)
5722 network->mode = IEEE_G;
5723 else
5724 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005725 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005726 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005727 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5728 IPW_WARNING("Overriding invalid channel\n");
5729 priv->channel = geo->bg[0].channel;
5730 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005731 break;
5732
5733 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005734 IPW_WARNING("Overriding invalid channel\n");
5735 if (priv->ieee->mode & IEEE_A) {
5736 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005737 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005738 } else if (priv->ieee->mode & IEEE_G) {
5739 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005740 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005741 } else {
5742 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005743 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005744 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005745 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005746 }
5747
5748 network->channel = priv->channel;
5749 priv->config |= CFG_ADHOC_PERSIST;
5750 ipw_create_bssid(priv, network->bssid);
5751 network->ssid_len = priv->essid_len;
5752 memcpy(network->ssid, priv->essid, priv->essid_len);
5753 memset(&network->stats, 0, sizeof(network->stats));
5754 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005755 if (!(priv->config & CFG_PREAMBLE_LONG))
5756 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005757 if (priv->capability & CAP_PRIVACY_ON)
5758 network->capability |= WLAN_CAPABILITY_PRIVACY;
5759 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005760 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005761 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005762 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005763 &priv->rates.supported_rates[network->rates_len],
5764 network->rates_ex_len);
5765 network->last_scanned = 0;
5766 network->flags = 0;
5767 network->last_associate = 0;
5768 network->time_stamp[0] = 0;
5769 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005770 network->beacon_interval = 100; /* Default */
5771 network->listen_interval = 10; /* Default */
5772 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005773 network->wpa_ie_len = 0;
5774 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005775}
5776
James Ketrenosb095c382005-08-24 22:04:42 -05005777static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5778{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005779 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005780
5781 if (!(priv->ieee->sec.flags & (1 << index)))
5782 return;
5783
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005784 key.key_id = index;
5785 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5786 key.security_type = type;
5787 key.station_index = 0; /* always 0 for BSS */
5788 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005789 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005790 key.tx_counter[0] = 0;
5791 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005792
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005793 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005794}
5795
5796static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005797{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005798 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005799 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005800
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005801 key.cmd_id = DINO_CMD_WEP_KEY;
5802 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005803
James Ketrenosb095c382005-08-24 22:04:42 -05005804 /* Note: AES keys cannot be set for multiple times.
5805 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005806 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005807 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005808 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005809 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005810 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005811 }
5812
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005813 key.key_size = priv->ieee->sec.key_sizes[i];
5814 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005815
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005816 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005817 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005818}
5819
Zhu Yi1fbfea52005-08-05 17:22:56 +08005820static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5821{
5822 if (priv->ieee->host_encrypt)
5823 return;
5824
5825 switch (level) {
5826 case SEC_LEVEL_3:
5827 priv->sys_config.disable_unicast_decryption = 0;
5828 priv->ieee->host_decrypt = 0;
5829 break;
5830 case SEC_LEVEL_2:
5831 priv->sys_config.disable_unicast_decryption = 1;
5832 priv->ieee->host_decrypt = 1;
5833 break;
5834 case SEC_LEVEL_1:
5835 priv->sys_config.disable_unicast_decryption = 0;
5836 priv->ieee->host_decrypt = 0;
5837 break;
5838 case SEC_LEVEL_0:
5839 priv->sys_config.disable_unicast_decryption = 1;
5840 break;
5841 default:
5842 break;
5843 }
5844}
5845
5846static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5847{
5848 if (priv->ieee->host_encrypt)
5849 return;
5850
5851 switch (level) {
5852 case SEC_LEVEL_3:
5853 priv->sys_config.disable_multicast_decryption = 0;
5854 break;
5855 case SEC_LEVEL_2:
5856 priv->sys_config.disable_multicast_decryption = 1;
5857 break;
5858 case SEC_LEVEL_1:
5859 priv->sys_config.disable_multicast_decryption = 0;
5860 break;
5861 case SEC_LEVEL_0:
5862 priv->sys_config.disable_multicast_decryption = 1;
5863 break;
5864 default:
5865 break;
5866 }
5867}
5868
James Ketrenosb095c382005-08-24 22:04:42 -05005869static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5870{
5871 switch (priv->ieee->sec.level) {
5872 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005873 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5874 ipw_send_tgi_tx_key(priv,
5875 DCT_FLAG_EXT_SECURITY_CCM,
5876 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005877
Hong Liu567deaf2005-08-31 18:07:22 +08005878 if (!priv->ieee->host_mc_decrypt)
5879 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005880 break;
5881 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005882 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5883 ipw_send_tgi_tx_key(priv,
5884 DCT_FLAG_EXT_SECURITY_TKIP,
5885 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005886 break;
5887 case SEC_LEVEL_1:
5888 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005889 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5890 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005891 break;
5892 case SEC_LEVEL_0:
5893 default:
5894 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005895 }
5896}
5897
5898static void ipw_adhoc_check(void *data)
5899{
5900 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005901
James Ketrenosafbf30a2005-08-25 00:05:33 -05005902 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005903 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005904 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5905 IPW_DL_STATE | IPW_DL_ASSOC,
5906 "Missed beacon: %d - disassociate\n",
5907 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005908 ipw_remove_current_network(priv);
5909 ipw_disassociate(priv);
5910 return;
5911 }
5912
Jeff Garzikbf794512005-07-31 13:07:26 -04005913 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005914 priv->assoc_request.beacon_interval);
5915}
5916
James Ketrenosc848d0a2005-08-24 21:56:24 -05005917static void ipw_bg_adhoc_check(void *data)
5918{
5919 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005920 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005921 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005922 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005923}
5924
Brice Goglin0f52bf92005-12-01 01:41:46 -08005925#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005926static void ipw_debug_config(struct ipw_priv *priv)
5927{
5928 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5929 "[CFG 0x%08X]\n", priv->config);
5930 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005931 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005932 else
5933 IPW_DEBUG_INFO("Channel unlocked.\n");
5934 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005935 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005936 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005937 else
5938 IPW_DEBUG_INFO("ESSID unlocked.\n");
5939 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005940 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5941 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005942 else
5943 IPW_DEBUG_INFO("BSSID unlocked.\n");
5944 if (priv->capability & CAP_PRIVACY_ON)
5945 IPW_DEBUG_INFO("PRIVACY on\n");
5946 else
5947 IPW_DEBUG_INFO("PRIVACY off\n");
5948 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5949}
5950#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005951#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005952#endif
5953
Arjan van de Ven858119e2006-01-14 13:20:43 -08005954static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005955{
5956 /* TODO: Verify that this works... */
5957 struct ipw_fixed_rate fr = {
5958 .tx_rates = priv->rates_mask
5959 };
5960 u32 reg;
5961 u16 mask = 0;
5962
Jeff Garzikbf794512005-07-31 13:07:26 -04005963 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005964 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005965
James Ketrenos43f66a62005-03-25 12:31:53 -06005966 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005967 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005968 /* IEEE_A */
5969 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5970 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005971 IPW_DEBUG_WX
5972 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005973 fr.tx_rates = 0;
5974 break;
5975 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005976
James Ketrenos43f66a62005-03-25 12:31:53 -06005977 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5978 break;
5979
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005980 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005981 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005982 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005983 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5984 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005985 IPW_DEBUG_WX
5986 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005987 fr.tx_rates = 0;
5988 }
5989 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005990 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005991
5992 /* IEEE_G */
5993 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5994 IEEE80211_OFDM_RATES_MASK)) {
5995 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005996 IPW_DEBUG_WX
5997 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005998 fr.tx_rates = 0;
5999 break;
6000 }
6001
6002 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6003 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6004 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6005 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006006
James Ketrenos43f66a62005-03-25 12:31:53 -06006007 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6008 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6009 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6010 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006011
James Ketrenos43f66a62005-03-25 12:31:53 -06006012 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6013 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6014 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6015 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006016
James Ketrenos43f66a62005-03-25 12:31:53 -06006017 fr.tx_rates |= mask;
6018 break;
6019 }
6020
6021 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006022 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006023}
6024
James Ketrenosea2b26e2005-08-24 21:25:16 -05006025static void ipw_abort_scan(struct ipw_priv *priv)
6026{
6027 int err;
6028
6029 if (priv->status & STATUS_SCAN_ABORTING) {
6030 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6031 return;
6032 }
6033 priv->status |= STATUS_SCAN_ABORTING;
6034
6035 err = ipw_send_scan_abort(priv);
6036 if (err)
6037 IPW_DEBUG_HC("Request to abort scan failed.\n");
6038}
6039
James Ketrenosafbf30a2005-08-25 00:05:33 -05006040static void ipw_add_scan_channels(struct ipw_priv *priv,
6041 struct ipw_scan_request_ext *scan,
6042 int scan_type)
6043{
6044 int channel_index = 0;
6045 const struct ieee80211_geo *geo;
6046 int i;
6047
Larry Finger1867b112006-02-28 09:48:28 -06006048 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006049
6050 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6051 int start = channel_index;
6052 for (i = 0; i < geo->a_channels; i++) {
6053 if ((priv->status & STATUS_ASSOCIATED) &&
6054 geo->a[i].channel == priv->channel)
6055 continue;
6056 channel_index++;
6057 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006058 ipw_set_scan_type(scan, channel_index,
6059 geo->a[i].
6060 flags & IEEE80211_CH_PASSIVE_ONLY ?
6061 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6062 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006063 }
6064
6065 if (start != channel_index) {
6066 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6067 (channel_index - start);
6068 channel_index++;
6069 }
6070 }
6071
6072 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6073 int start = channel_index;
6074 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006075 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006076 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6077 /* nop out the list */
6078 [0] = 0
6079 };
6080
6081 u8 channel;
6082 while (channel_index < IPW_SCAN_CHANNELS) {
6083 channel =
6084 priv->speed_scan[priv->speed_scan_pos];
6085 if (channel == 0) {
6086 priv->speed_scan_pos = 0;
6087 channel = priv->speed_scan[0];
6088 }
6089 if ((priv->status & STATUS_ASSOCIATED) &&
6090 channel == priv->channel) {
6091 priv->speed_scan_pos++;
6092 continue;
6093 }
6094
6095 /* If this channel has already been
6096 * added in scan, break from loop
6097 * and this will be the first channel
6098 * in the next scan.
6099 */
6100 if (channels[channel - 1] != 0)
6101 break;
6102
6103 channels[channel - 1] = 1;
6104 priv->speed_scan_pos++;
6105 channel_index++;
6106 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006107 index =
Larry Finger1867b112006-02-28 09:48:28 -06006108 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006109 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006110 geo->bg[index].
6111 flags &
6112 IEEE80211_CH_PASSIVE_ONLY ?
6113 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6114 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006115 }
6116 } else {
6117 for (i = 0; i < geo->bg_channels; i++) {
6118 if ((priv->status & STATUS_ASSOCIATED) &&
6119 geo->bg[i].channel == priv->channel)
6120 continue;
6121 channel_index++;
6122 scan->channels_list[channel_index] =
6123 geo->bg[i].channel;
6124 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006125 geo->bg[i].
6126 flags &
6127 IEEE80211_CH_PASSIVE_ONLY ?
6128 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6129 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006130 }
6131 }
6132
6133 if (start != channel_index) {
6134 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6135 (channel_index - start);
6136 }
6137 }
6138}
6139
James Ketrenosea2b26e2005-08-24 21:25:16 -05006140static int ipw_request_scan(struct ipw_priv *priv)
6141{
6142 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006143 int err = 0, scan_type;
6144
6145 if (!(priv->status & STATUS_INIT) ||
6146 (priv->status & STATUS_EXIT_PENDING))
6147 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006148
Zhu Yi46441512006-01-24 16:37:59 +08006149 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006150
James Ketrenosea2b26e2005-08-24 21:25:16 -05006151 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006152 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006153 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006154 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006155 }
6156
James Ketrenosafbf30a2005-08-25 00:05:33 -05006157 if (!(priv->status & STATUS_SCAN_FORCED) &&
6158 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006159 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6160 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006161 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006162 }
6163
6164 if (priv->status & STATUS_RF_KILL_MASK) {
6165 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6166 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006167 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006168 }
6169
6170 memset(&scan, 0, sizeof(scan));
6171
James Ketrenosb095c382005-08-24 22:04:42 -05006172 if (priv->config & CFG_SPEED_SCAN)
6173 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6174 cpu_to_le16(30);
6175 else
6176 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6177 cpu_to_le16(20);
6178
James Ketrenosa613bff2005-08-24 21:43:11 -05006179 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6180 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006181 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006182
James Ketrenosa613bff2005-08-24 21:43:11 -05006183 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006184
James Ketrenosb095c382005-08-24 22:04:42 -05006185#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006186 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006187 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006188 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006189
Larry Finger1867b112006-02-28 09:48:28 -06006190 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006191 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006192 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006193 channel = priv->channel;
6194 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195
James Ketrenosb095c382005-08-24 22:04:42 -05006196 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006197 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006198 channel = priv->channel;
6199 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006200
James Ketrenosb095c382005-08-24 22:04:42 -05006201 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006202 band = (u8) (IPW_B_MODE << 6) | 1;
6203 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006204 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006205 }
6206
James Ketrenosb095c382005-08-24 22:04:42 -05006207 scan.channels_list[0] = band;
6208 scan.channels_list[1] = channel;
6209 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006210
James Ketrenosb095c382005-08-24 22:04:42 -05006211 /* NOTE: The card will sit on this channel for this time
6212 * period. Scan aborts are timing sensitive and frequently
6213 * result in firmware restarts. As such, it is best to
6214 * set a small dwell_time here and just keep re-issuing
6215 * scans. Otherwise fast channel hopping will not actually
6216 * hop channels.
6217 *
6218 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006219 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6220 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006221 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006222#endif /* CONFIG_IPW2200_MONITOR */
6223 /* If we are roaming, then make this a directed scan for the
6224 * current network. Otherwise, ensure that every other scan
6225 * is a fast channel hop scan */
6226 if ((priv->status & STATUS_ROAMING)
6227 || (!(priv->status & STATUS_ASSOCIATED)
6228 && (priv->config & CFG_STATIC_ESSID)
6229 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006230 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6231 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006232 IPW_DEBUG_HC("Attempt to send SSID command "
6233 "failed.\n");
6234 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006235 }
6236
6237 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006238 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006239 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006240
James Ketrenosafbf30a2005-08-25 00:05:33 -05006241 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006242#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006243 }
6244#endif
6245
6246 err = ipw_send_scan_request_ext(priv, &scan);
6247 if (err) {
6248 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006249 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006250 }
6251
6252 priv->status |= STATUS_SCANNING;
6253 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006254 queue_delayed_work(priv->workqueue, &priv->scan_check,
6255 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006256 done:
Zhu Yi46441512006-01-24 16:37:59 +08006257 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006258 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006259}
6260
6261static void ipw_bg_abort_scan(void *data)
6262{
6263 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006264 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006265 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006266 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006267}
6268
James Ketrenosea2b26e2005-08-24 21:25:16 -05006269static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6270{
James Ketrenosb095c382005-08-24 22:04:42 -05006271 /* This is called when wpa_supplicant loads and closes the driver
6272 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006273 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006274 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006275}
6276
James Ketrenosea2b26e2005-08-24 21:25:16 -05006277static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6278{
6279 struct ieee80211_device *ieee = priv->ieee;
6280 struct ieee80211_security sec = {
6281 .flags = SEC_AUTH_MODE,
6282 };
6283 int ret = 0;
6284
James Ketrenosafbf30a2005-08-25 00:05:33 -05006285 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006286 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6287 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006288 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006289 sec.auth_mode = WLAN_AUTH_OPEN;
6290 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006291 } else if (value & IW_AUTH_ALG_LEAP) {
6292 sec.auth_mode = WLAN_AUTH_LEAP;
6293 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006294 } else
6295 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006296
6297 if (ieee->set_security)
6298 ieee->set_security(ieee->dev, &sec);
6299 else
6300 ret = -EOPNOTSUPP;
6301
6302 return ret;
6303}
6304
Adrian Bunka73e22b2006-01-21 01:39:42 +01006305static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6306 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006307{
6308 /* make sure WPA is enabled */
6309 ipw_wpa_enable(priv, 1);
6310
6311 ipw_disassociate(priv);
6312}
6313
6314static int ipw_set_rsn_capa(struct ipw_priv *priv,
6315 char *capabilities, int length)
6316{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006317 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6318
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006319 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006320 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006321}
6322
James Ketrenosafbf30a2005-08-25 00:05:33 -05006323/*
6324 * WE-18 support
6325 */
6326
6327/* SIOCSIWGENIE */
6328static int ipw_wx_set_genie(struct net_device *dev,
6329 struct iw_request_info *info,
6330 union iwreq_data *wrqu, char *extra)
6331{
6332 struct ipw_priv *priv = ieee80211_priv(dev);
6333 struct ieee80211_device *ieee = priv->ieee;
6334 u8 *buf;
6335 int err = 0;
6336
6337 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6338 (wrqu->data.length && extra == NULL))
6339 return -EINVAL;
6340
Zhu Yi46441512006-01-24 16:37:59 +08006341 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006342
6343 //if (!ieee->wpa_enabled) {
6344 // err = -EOPNOTSUPP;
6345 // goto out;
6346 //}
6347
6348 if (wrqu->data.length) {
6349 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6350 if (buf == NULL) {
6351 err = -ENOMEM;
6352 goto out;
6353 }
6354
6355 memcpy(buf, extra, wrqu->data.length);
6356 kfree(ieee->wpa_ie);
6357 ieee->wpa_ie = buf;
6358 ieee->wpa_ie_len = wrqu->data.length;
6359 } else {
6360 kfree(ieee->wpa_ie);
6361 ieee->wpa_ie = NULL;
6362 ieee->wpa_ie_len = 0;
6363 }
6364
6365 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6366 out:
Zhu Yi46441512006-01-24 16:37:59 +08006367 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006368 return err;
6369}
6370
6371/* SIOCGIWGENIE */
6372static int ipw_wx_get_genie(struct net_device *dev,
6373 struct iw_request_info *info,
6374 union iwreq_data *wrqu, char *extra)
6375{
6376 struct ipw_priv *priv = ieee80211_priv(dev);
6377 struct ieee80211_device *ieee = priv->ieee;
6378 int err = 0;
6379
Zhu Yi46441512006-01-24 16:37:59 +08006380 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006381
6382 //if (!ieee->wpa_enabled) {
6383 // err = -EOPNOTSUPP;
6384 // goto out;
6385 //}
6386
6387 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6388 wrqu->data.length = 0;
6389 goto out;
6390 }
6391
6392 if (wrqu->data.length < ieee->wpa_ie_len) {
6393 err = -E2BIG;
6394 goto out;
6395 }
6396
6397 wrqu->data.length = ieee->wpa_ie_len;
6398 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6399
6400 out:
Zhu Yi46441512006-01-24 16:37:59 +08006401 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006402 return err;
6403}
6404
Zhu Yi1fbfea52005-08-05 17:22:56 +08006405static int wext_cipher2level(int cipher)
6406{
6407 switch (cipher) {
6408 case IW_AUTH_CIPHER_NONE:
6409 return SEC_LEVEL_0;
6410 case IW_AUTH_CIPHER_WEP40:
6411 case IW_AUTH_CIPHER_WEP104:
6412 return SEC_LEVEL_1;
6413 case IW_AUTH_CIPHER_TKIP:
6414 return SEC_LEVEL_2;
6415 case IW_AUTH_CIPHER_CCMP:
6416 return SEC_LEVEL_3;
6417 default:
6418 return -1;
6419 }
6420}
6421
James Ketrenosafbf30a2005-08-25 00:05:33 -05006422/* SIOCSIWAUTH */
6423static int ipw_wx_set_auth(struct net_device *dev,
6424 struct iw_request_info *info,
6425 union iwreq_data *wrqu, char *extra)
6426{
6427 struct ipw_priv *priv = ieee80211_priv(dev);
6428 struct ieee80211_device *ieee = priv->ieee;
6429 struct iw_param *param = &wrqu->param;
6430 struct ieee80211_crypt_data *crypt;
6431 unsigned long flags;
6432 int ret = 0;
6433
6434 switch (param->flags & IW_AUTH_INDEX) {
6435 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006436 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006437 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006438 ipw_set_hw_decrypt_unicast(priv,
6439 wext_cipher2level(param->value));
6440 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006441 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006442 ipw_set_hw_decrypt_multicast(priv,
6443 wext_cipher2level(param->value));
6444 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006445 case IW_AUTH_KEY_MGMT:
6446 /*
6447 * ipw2200 does not use these parameters
6448 */
6449 break;
6450
6451 case IW_AUTH_TKIP_COUNTERMEASURES:
6452 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006453 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006454 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006455
6456 flags = crypt->ops->get_flags(crypt->priv);
6457
6458 if (param->value)
6459 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6460 else
6461 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6462
6463 crypt->ops->set_flags(flags, crypt->priv);
6464
6465 break;
6466
6467 case IW_AUTH_DROP_UNENCRYPTED:{
6468 /* HACK:
6469 *
6470 * wpa_supplicant calls set_wpa_enabled when the driver
6471 * is loaded and unloaded, regardless of if WPA is being
6472 * used. No other calls are made which can be used to
6473 * determine if encryption will be used or not prior to
6474 * association being expected. If encryption is not being
6475 * used, drop_unencrypted is set to false, else true -- we
6476 * can use this to determine if the CAP_PRIVACY_ON bit should
6477 * be set.
6478 */
6479 struct ieee80211_security sec = {
6480 .flags = SEC_ENABLED,
6481 .enabled = param->value,
6482 };
6483 priv->ieee->drop_unencrypted = param->value;
6484 /* We only change SEC_LEVEL for open mode. Others
6485 * are set by ipw_wpa_set_encryption.
6486 */
6487 if (!param->value) {
6488 sec.flags |= SEC_LEVEL;
6489 sec.level = SEC_LEVEL_0;
6490 } else {
6491 sec.flags |= SEC_LEVEL;
6492 sec.level = SEC_LEVEL_1;
6493 }
6494 if (priv->ieee->set_security)
6495 priv->ieee->set_security(priv->ieee->dev, &sec);
6496 break;
6497 }
6498
6499 case IW_AUTH_80211_AUTH_ALG:
6500 ret = ipw_wpa_set_auth_algs(priv, param->value);
6501 break;
6502
6503 case IW_AUTH_WPA_ENABLED:
6504 ret = ipw_wpa_enable(priv, param->value);
6505 break;
6506
6507 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6508 ieee->ieee802_1x = param->value;
6509 break;
6510
6511 //case IW_AUTH_ROAMING_CONTROL:
6512 case IW_AUTH_PRIVACY_INVOKED:
6513 ieee->privacy_invoked = param->value;
6514 break;
6515
6516 default:
6517 return -EOPNOTSUPP;
6518 }
6519 return ret;
6520}
6521
6522/* SIOCGIWAUTH */
6523static int ipw_wx_get_auth(struct net_device *dev,
6524 struct iw_request_info *info,
6525 union iwreq_data *wrqu, char *extra)
6526{
6527 struct ipw_priv *priv = ieee80211_priv(dev);
6528 struct ieee80211_device *ieee = priv->ieee;
6529 struct ieee80211_crypt_data *crypt;
6530 struct iw_param *param = &wrqu->param;
6531 int ret = 0;
6532
6533 switch (param->flags & IW_AUTH_INDEX) {
6534 case IW_AUTH_WPA_VERSION:
6535 case IW_AUTH_CIPHER_PAIRWISE:
6536 case IW_AUTH_CIPHER_GROUP:
6537 case IW_AUTH_KEY_MGMT:
6538 /*
6539 * wpa_supplicant will control these internally
6540 */
6541 ret = -EOPNOTSUPP;
6542 break;
6543
6544 case IW_AUTH_TKIP_COUNTERMEASURES:
6545 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006546 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006547 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006548
6549 param->value = (crypt->ops->get_flags(crypt->priv) &
6550 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6551
6552 break;
6553
6554 case IW_AUTH_DROP_UNENCRYPTED:
6555 param->value = ieee->drop_unencrypted;
6556 break;
6557
6558 case IW_AUTH_80211_AUTH_ALG:
6559 param->value = ieee->sec.auth_mode;
6560 break;
6561
6562 case IW_AUTH_WPA_ENABLED:
6563 param->value = ieee->wpa_enabled;
6564 break;
6565
6566 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6567 param->value = ieee->ieee802_1x;
6568 break;
6569
6570 case IW_AUTH_ROAMING_CONTROL:
6571 case IW_AUTH_PRIVACY_INVOKED:
6572 param->value = ieee->privacy_invoked;
6573 break;
6574
6575 default:
6576 return -EOPNOTSUPP;
6577 }
6578 return 0;
6579}
6580
6581/* SIOCSIWENCODEEXT */
6582static int ipw_wx_set_encodeext(struct net_device *dev,
6583 struct iw_request_info *info,
6584 union iwreq_data *wrqu, char *extra)
6585{
6586 struct ipw_priv *priv = ieee80211_priv(dev);
6587 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6588
6589 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006590 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006591 /* IPW HW can't build TKIP MIC,
6592 host decryption still needed */
6593 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6594 priv->ieee->host_mc_decrypt = 1;
6595 else {
6596 priv->ieee->host_encrypt = 0;
6597 priv->ieee->host_encrypt_msdu = 1;
6598 priv->ieee->host_decrypt = 1;
6599 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006600 } else {
6601 priv->ieee->host_encrypt = 0;
6602 priv->ieee->host_encrypt_msdu = 0;
6603 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006604 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006605 }
6606 }
6607
6608 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6609}
6610
6611/* SIOCGIWENCODEEXT */
6612static int ipw_wx_get_encodeext(struct net_device *dev,
6613 struct iw_request_info *info,
6614 union iwreq_data *wrqu, char *extra)
6615{
6616 struct ipw_priv *priv = ieee80211_priv(dev);
6617 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6618}
6619
6620/* SIOCSIWMLME */
6621static int ipw_wx_set_mlme(struct net_device *dev,
6622 struct iw_request_info *info,
6623 union iwreq_data *wrqu, char *extra)
6624{
6625 struct ipw_priv *priv = ieee80211_priv(dev);
6626 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6627 u16 reason;
6628
6629 reason = cpu_to_le16(mlme->reason_code);
6630
6631 switch (mlme->cmd) {
6632 case IW_MLME_DEAUTH:
6633 // silently ignore
6634 break;
6635
6636 case IW_MLME_DISASSOC:
6637 ipw_disassociate(priv);
6638 break;
6639
6640 default:
6641 return -EOPNOTSUPP;
6642 }
6643 return 0;
6644}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006645
James Ketrenosb095c382005-08-24 22:04:42 -05006646#ifdef CONFIG_IPW_QOS
6647
6648/* QoS */
6649/*
6650* get the modulation type of the current network or
6651* the card current mode
6652*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006653static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006654{
6655 u8 mode = 0;
6656
6657 if (priv->status & STATUS_ASSOCIATED) {
6658 unsigned long flags;
6659
6660 spin_lock_irqsave(&priv->ieee->lock, flags);
6661 mode = priv->assoc_network->mode;
6662 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6663 } else {
6664 mode = priv->ieee->mode;
6665 }
6666 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6667 return mode;
6668}
6669
6670/*
6671* Handle management frame beacon and probe response
6672*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006673static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6674 int active_network,
6675 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006676{
6677 u32 size = sizeof(struct ieee80211_qos_parameters);
6678
James Ketrenosafbf30a2005-08-25 00:05:33 -05006679 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006680 network->qos_data.active = network->qos_data.supported;
6681
6682 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006683 if (active_network &&
6684 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006685 network->qos_data.active = network->qos_data.supported;
6686
6687 if ((network->qos_data.active == 1) && (active_network == 1) &&
6688 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6689 (network->qos_data.old_param_count !=
6690 network->qos_data.param_count)) {
6691 network->qos_data.old_param_count =
6692 network->qos_data.param_count;
6693 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006694 IPW_DEBUG_QOS("QoS parameters change call "
6695 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006696 }
6697 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006698 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6699 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006700 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006701 else
6702 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006703 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006704
James Ketrenosb095c382005-08-24 22:04:42 -05006705 if ((network->qos_data.active == 1) && (active_network == 1)) {
6706 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6707 schedule_work(&priv->qos_activate);
6708 }
6709
6710 network->qos_data.active = 0;
6711 network->qos_data.supported = 0;
6712 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006713 if ((priv->status & STATUS_ASSOCIATED) &&
6714 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6715 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6716 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6717 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006718 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006719 priv->assoc_network->ssid_len) &&
6720 !memcmp(network->ssid,
6721 priv->assoc_network->ssid,
6722 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006723 queue_work(priv->workqueue,
6724 &priv->merge_networks);
6725 }
James Ketrenosb095c382005-08-24 22:04:42 -05006726 }
6727
6728 return 0;
6729}
6730
6731/*
6732* This function set up the firmware to support QoS. It sends
6733* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6734*/
6735static int ipw_qos_activate(struct ipw_priv *priv,
6736 struct ieee80211_qos_data *qos_network_data)
6737{
6738 int err;
6739 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6740 struct ieee80211_qos_parameters *active_one = NULL;
6741 u32 size = sizeof(struct ieee80211_qos_parameters);
6742 u32 burst_duration;
6743 int i;
6744 u8 type;
6745
6746 type = ipw_qos_current_mode(priv);
6747
6748 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6749 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6750 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6751 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6752
6753 if (qos_network_data == NULL) {
6754 if (type == IEEE_B) {
6755 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6756 active_one = &def_parameters_CCK;
6757 } else
6758 active_one = &def_parameters_OFDM;
6759
James Ketrenosafbf30a2005-08-25 00:05:33 -05006760 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006761 burst_duration = ipw_qos_get_burst_duration(priv);
6762 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006763 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6764 (u16) burst_duration;
6765 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006766 if (type == IEEE_B) {
6767 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6768 type);
6769 if (priv->qos_data.qos_enable == 0)
6770 active_one = &def_parameters_CCK;
6771 else
6772 active_one = priv->qos_data.def_qos_parm_CCK;
6773 } else {
6774 if (priv->qos_data.qos_enable == 0)
6775 active_one = &def_parameters_OFDM;
6776 else
6777 active_one = priv->qos_data.def_qos_parm_OFDM;
6778 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006779 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006780 } else {
6781 unsigned long flags;
6782 int active;
6783
6784 spin_lock_irqsave(&priv->ieee->lock, flags);
6785 active_one = &(qos_network_data->parameters);
6786 qos_network_data->old_param_count =
6787 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006788 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006789 active = qos_network_data->supported;
6790 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6791
6792 if (active == 0) {
6793 burst_duration = ipw_qos_get_burst_duration(priv);
6794 for (i = 0; i < QOS_QUEUE_NUM; i++)
6795 qos_parameters[QOS_PARAM_SET_ACTIVE].
6796 tx_op_limit[i] = (u16) burst_duration;
6797 }
6798 }
6799
6800 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006801 err = ipw_send_qos_params_command(priv,
6802 (struct ieee80211_qos_parameters *)
6803 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006804 if (err)
6805 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6806
6807 return err;
6808}
6809
6810/*
6811* send IPW_CMD_WME_INFO to the firmware
6812*/
6813static int ipw_qos_set_info_element(struct ipw_priv *priv)
6814{
6815 int ret = 0;
6816 struct ieee80211_qos_information_element qos_info;
6817
6818 if (priv == NULL)
6819 return -1;
6820
6821 qos_info.elementID = QOS_ELEMENT_ID;
6822 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6823
6824 qos_info.version = QOS_VERSION_1;
6825 qos_info.ac_info = 0;
6826
6827 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6828 qos_info.qui_type = QOS_OUI_TYPE;
6829 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6830
6831 ret = ipw_send_qos_info_command(priv, &qos_info);
6832 if (ret != 0) {
6833 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6834 }
6835 return ret;
6836}
6837
6838/*
6839* Set the QoS parameter with the association request structure
6840*/
6841static int ipw_qos_association(struct ipw_priv *priv,
6842 struct ieee80211_network *network)
6843{
6844 int err = 0;
6845 struct ieee80211_qos_data *qos_data = NULL;
6846 struct ieee80211_qos_data ibss_data = {
6847 .supported = 1,
6848 .active = 1,
6849 };
6850
6851 switch (priv->ieee->iw_mode) {
6852 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006853 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006854
6855 qos_data = &ibss_data;
6856 break;
6857
6858 case IW_MODE_INFRA:
6859 qos_data = &network->qos_data;
6860 break;
6861
6862 default:
6863 BUG();
6864 break;
6865 }
6866
6867 err = ipw_qos_activate(priv, qos_data);
6868 if (err) {
6869 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6870 return err;
6871 }
6872
6873 if (priv->qos_data.qos_enable && qos_data->supported) {
6874 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6875 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6876 return ipw_qos_set_info_element(priv);
6877 }
6878
6879 return 0;
6880}
6881
6882/*
6883* handling the beaconing responces. if we get different QoS setting
6884* of the network from the the associated setting adjust the QoS
6885* setting
6886*/
6887static int ipw_qos_association_resp(struct ipw_priv *priv,
6888 struct ieee80211_network *network)
6889{
6890 int ret = 0;
6891 unsigned long flags;
6892 u32 size = sizeof(struct ieee80211_qos_parameters);
6893 int set_qos_param = 0;
6894
James Ketrenosafbf30a2005-08-25 00:05:33 -05006895 if ((priv == NULL) || (network == NULL) ||
6896 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006897 return ret;
6898
6899 if (!(priv->status & STATUS_ASSOCIATED))
6900 return ret;
6901
James Ketrenosafbf30a2005-08-25 00:05:33 -05006902 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006903 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006904
6905 spin_lock_irqsave(&priv->ieee->lock, flags);
6906 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006907 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006908 sizeof(struct ieee80211_qos_data));
6909 priv->assoc_network->qos_data.active = 1;
6910 if ((network->qos_data.old_param_count !=
6911 network->qos_data.param_count)) {
6912 set_qos_param = 1;
6913 network->qos_data.old_param_count =
6914 network->qos_data.param_count;
6915 }
6916
6917 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006918 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6919 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006920 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006921 else
6922 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006923 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006924 priv->assoc_network->qos_data.active = 0;
6925 priv->assoc_network->qos_data.supported = 0;
6926 set_qos_param = 1;
6927 }
6928
6929 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6930
6931 if (set_qos_param == 1)
6932 schedule_work(&priv->qos_activate);
6933
6934 return ret;
6935}
6936
6937static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6938{
6939 u32 ret = 0;
6940
6941 if ((priv == NULL))
6942 return 0;
6943
James Ketrenosafbf30a2005-08-25 00:05:33 -05006944 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006945 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006946 else
James Ketrenosb095c382005-08-24 22:04:42 -05006947 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006948
James Ketrenosb095c382005-08-24 22:04:42 -05006949 return ret;
6950}
6951
6952/*
6953* Initialize the setting of QoS global
6954*/
6955static void ipw_qos_init(struct ipw_priv *priv, int enable,
6956 int burst_enable, u32 burst_duration_CCK,
6957 u32 burst_duration_OFDM)
6958{
6959 priv->qos_data.qos_enable = enable;
6960
6961 if (priv->qos_data.qos_enable) {
6962 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6963 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6964 IPW_DEBUG_QOS("QoS is enabled\n");
6965 } else {
6966 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6967 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6968 IPW_DEBUG_QOS("QoS is not enabled\n");
6969 }
6970
6971 priv->qos_data.burst_enable = burst_enable;
6972
6973 if (burst_enable) {
6974 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6975 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6976 } else {
6977 priv->qos_data.burst_duration_CCK = 0;
6978 priv->qos_data.burst_duration_OFDM = 0;
6979 }
6980}
6981
6982/*
6983* map the packet priority to the right TX Queue
6984*/
6985static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6986{
6987 if (priority > 7 || !priv->qos_data.qos_enable)
6988 priority = 0;
6989
6990 return from_priority_to_tx_queue[priority] - 1;
6991}
6992
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006993static int ipw_is_qos_active(struct net_device *dev,
6994 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05006995{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006996 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05006997 struct ieee80211_qos_data *qos_data = NULL;
6998 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006999 u8 *daddr = skb->data + ETH_ALEN;
7000 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007001
7002 if (!(priv->status & STATUS_ASSOCIATED))
7003 return 0;
7004
7005 qos_data = &priv->assoc_network->qos_data;
7006
James Ketrenosb095c382005-08-24 22:04:42 -05007007 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7008 if (unicast == 0)
7009 qos_data->active = 0;
7010 else
7011 qos_data->active = qos_data->supported;
7012 }
James Ketrenosb095c382005-08-24 22:04:42 -05007013 active = qos_data->active;
7014 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007015 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7016 "unicast %d\n",
7017 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007018 if (active && priv->qos_data.qos_enable)
7019 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007020
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007021 return 0;
7022
7023}
7024/*
7025* add QoS parameter to the TX command
7026*/
7027static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7028 u16 priority,
7029 struct tfd_data *tfd)
7030{
7031 int tx_queue_id = 0;
7032
7033
7034 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7035 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7036
7037 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7038 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7039 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05007040 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007041 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007042}
7043
7044/*
7045* background support to run QoS activate functionality
7046*/
7047static void ipw_bg_qos_activate(void *data)
7048{
7049 struct ipw_priv *priv = data;
7050
7051 if (priv == NULL)
7052 return;
7053
Zhu Yi46441512006-01-24 16:37:59 +08007054 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007055
7056 if (priv->status & STATUS_ASSOCIATED)
7057 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7058
Zhu Yi46441512006-01-24 16:37:59 +08007059 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007060}
7061
James Ketrenos3b9990c2005-08-19 13:18:55 -05007062static int ipw_handle_probe_response(struct net_device *dev,
7063 struct ieee80211_probe_response *resp,
7064 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007065{
7066 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007067 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7068 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007069
James Ketrenos3b9990c2005-08-19 13:18:55 -05007070 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007071
James Ketrenos3b9990c2005-08-19 13:18:55 -05007072 return 0;
7073}
James Ketrenosb095c382005-08-24 22:04:42 -05007074
James Ketrenos3b9990c2005-08-19 13:18:55 -05007075static int ipw_handle_beacon(struct net_device *dev,
7076 struct ieee80211_beacon *resp,
7077 struct ieee80211_network *network)
7078{
7079 struct ipw_priv *priv = ieee80211_priv(dev);
7080 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7081 (network == priv->assoc_network));
7082
7083 ipw_qos_handle_probe_response(priv, active_network, network);
7084
7085 return 0;
7086}
7087
7088static int ipw_handle_assoc_response(struct net_device *dev,
7089 struct ieee80211_assoc_response *resp,
7090 struct ieee80211_network *network)
7091{
7092 struct ipw_priv *priv = ieee80211_priv(dev);
7093 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007094 return 0;
7095}
7096
7097static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7098 *qos_param)
7099{
Zhu Yi4e226992006-01-24 16:37:36 +08007100 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7101 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007102}
7103
7104static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7105 *qos_param)
7106{
Zhu Yi4e226992006-01-24 16:37:36 +08007107 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7108 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007109}
7110
7111#endif /* CONFIG_IPW_QOS */
7112
James Ketrenos43f66a62005-03-25 12:31:53 -06007113static int ipw_associate_network(struct ipw_priv *priv,
7114 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007115 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007116{
7117 int err;
7118
7119 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007120 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007121
7122 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007123 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007124 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007125 memcpy(priv->essid, network->ssid, priv->essid_len);
7126 }
7127
7128 network->last_associate = jiffies;
7129
7130 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7131 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007132 priv->assoc_request.auth_key = 0;
7133
James Ketrenos43f66a62005-03-25 12:31:53 -06007134 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007135 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007136 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007137 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7138
Zhu Yi1ba61e02006-02-15 13:00:55 +08007139 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007140 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007141
7142 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7143 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7144 priv->assoc_request.auth_type = AUTH_LEAP;
7145 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007146 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007147
James Ketrenosa613bff2005-08-24 21:43:11 -05007148 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007149 priv->assoc_request.policy_support = 0x02; /* RSN active */
7150 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7151 priv->ieee->wpa_ie_len);
7152 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007153
Jeff Garzikbf794512005-07-31 13:07:26 -04007154 /*
7155 * It is valid for our ieee device to support multiple modes, but
7156 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007157 * just one mode.
7158 */
7159 if (network->mode & priv->ieee->mode & IEEE_A)
7160 priv->assoc_request.ieee_mode = IPW_A_MODE;
7161 else if (network->mode & priv->ieee->mode & IEEE_G)
7162 priv->assoc_request.ieee_mode = IPW_G_MODE;
7163 else if (network->mode & priv->ieee->mode & IEEE_B)
7164 priv->assoc_request.ieee_mode = IPW_B_MODE;
7165
James Ketrenosea2b26e2005-08-24 21:25:16 -05007166 priv->assoc_request.capability = network->capability;
7167 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7168 && !(priv->config & CFG_PREAMBLE_LONG)) {
7169 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7170 } else {
7171 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7172
7173 /* Clear the short preamble if we won't be supporting it */
7174 priv->assoc_request.capability &=
7175 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7176 }
7177
James Ketrenosafbf30a2005-08-25 00:05:33 -05007178 /* Clear capability bits that aren't used in Ad Hoc */
7179 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7180 priv->assoc_request.capability &=
7181 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7182
James Ketrenos43f66a62005-03-25 12:31:53 -06007183 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007184 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007185 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007186 escape_essid(priv->essid, priv->essid_len),
7187 network->channel,
7188 ipw_modes[priv->assoc_request.ieee_mode],
7189 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007190 (priv->assoc_request.preamble_length ==
7191 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7192 network->capability &
7193 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007194 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007195 priv->capability & CAP_PRIVACY_ON ?
7196 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007197 "(open)") : "",
7198 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007199 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007200 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007201 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007202
7203 priv->assoc_request.beacon_interval = network->beacon_interval;
7204 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007205 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007206 priv->assoc_request.assoc_type = HC_IBSS_START;
7207 priv->assoc_request.assoc_tsf_msw = 0;
7208 priv->assoc_request.assoc_tsf_lsw = 0;
7209 } else {
7210 if (unlikely(roaming))
7211 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7212 else
7213 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7214 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7215 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7216 }
7217
James Ketrenosafbf30a2005-08-25 00:05:33 -05007218 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007219
7220 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7221 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7222 priv->assoc_request.atim_window = network->atim_window;
7223 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007224 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007225 priv->assoc_request.atim_window = 0;
7226 }
7227
James Ketrenos43f66a62005-03-25 12:31:53 -06007228 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007229
James Ketrenos43f66a62005-03-25 12:31:53 -06007230 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7231 if (err) {
7232 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7233 return err;
7234 }
7235
7236 rates->ieee_mode = priv->assoc_request.ieee_mode;
7237 rates->purpose = IPW_RATE_CONNECT;
7238 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007239
James Ketrenos43f66a62005-03-25 12:31:53 -06007240 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7241 priv->sys_config.dot11g_auto_detection = 1;
7242 else
7243 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007244
7245 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7246 priv->sys_config.answer_broadcast_ssid_probe = 1;
7247 else
7248 priv->sys_config.answer_broadcast_ssid_probe = 0;
7249
Zhu Yid685b8c2006-04-13 17:20:27 +08007250 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007251 if (err) {
7252 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7253 return err;
7254 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007255
James Ketrenos43f66a62005-03-25 12:31:53 -06007256 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007257 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007258 if (err) {
7259 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7260 return err;
7261 }
7262
7263 /*
7264 * If preemption is enabled, it is possible for the association
7265 * to complete before we return from ipw_send_associate. Therefore
7266 * we have to be sure and update our priviate data first.
7267 */
7268 priv->channel = network->channel;
7269 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007270 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007271 priv->status &= ~STATUS_SECURITY_UPDATED;
7272
7273 priv->assoc_network = network;
7274
James Ketrenosb095c382005-08-24 22:04:42 -05007275#ifdef CONFIG_IPW_QOS
7276 ipw_qos_association(priv, network);
7277#endif
7278
James Ketrenos43f66a62005-03-25 12:31:53 -06007279 err = ipw_send_associate(priv, &priv->assoc_request);
7280 if (err) {
7281 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7282 return err;
7283 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007284
7285 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007286 escape_essid(priv->essid, priv->essid_len),
7287 MAC_ARG(priv->bssid));
7288
7289 return 0;
7290}
7291
7292static void ipw_roam(void *data)
7293{
7294 struct ipw_priv *priv = data;
7295 struct ieee80211_network *network = NULL;
7296 struct ipw_network_match match = {
7297 .network = priv->assoc_network
7298 };
7299
7300 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007301 *
7302 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007303 * setting the status ROAM bit and requesting a scan.
7304 * 2. When the scan completes, it schedules the ROAM work
7305 * 3. The ROAM work looks at all of the known networks for one that
7306 * is a better network than the currently associated. If none
7307 * found, the ROAM process is over (ROAM bit cleared)
7308 * 4. If a better network is found, a disassociation request is
7309 * sent.
7310 * 5. When the disassociation completes, the roam work is again
7311 * scheduled. The second time through, the driver is no longer
7312 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007313 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007314 * 6. At this point ,the roaming process is complete and the ROAM
7315 * status bit is cleared.
7316 */
7317
7318 /* If we are no longer associated, and the roaming bit is no longer
7319 * set, then we are not actively roaming, so just return */
7320 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7321 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007322
James Ketrenos43f66a62005-03-25 12:31:53 -06007323 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007324 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007325 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007326 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007327 u8 rssi = priv->assoc_network->stats.rssi;
7328 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007329 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007330 list_for_each_entry(network, &priv->ieee->network_list, list) {
7331 if (network != priv->assoc_network)
7332 ipw_best_network(priv, &match, network, 1);
7333 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007334 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007335 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007336
James Ketrenos43f66a62005-03-25 12:31:53 -06007337 if (match.network == priv->assoc_network) {
7338 IPW_DEBUG_ASSOC("No better APs in this network to "
7339 "roam to.\n");
7340 priv->status &= ~STATUS_ROAMING;
7341 ipw_debug_config(priv);
7342 return;
7343 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007344
James Ketrenos43f66a62005-03-25 12:31:53 -06007345 ipw_send_disassociate(priv, 1);
7346 priv->assoc_network = match.network;
7347
7348 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007349 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007350
7351 /* Second pass through ROAM process -- request association */
7352 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7353 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7354 priv->status &= ~STATUS_ROAMING;
7355}
7356
James Ketrenosc848d0a2005-08-24 21:56:24 -05007357static void ipw_bg_roam(void *data)
7358{
7359 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007360 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007361 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007362 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007363}
7364
7365static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007366{
7367 struct ipw_priv *priv = data;
7368
7369 struct ieee80211_network *network = NULL;
7370 struct ipw_network_match match = {
7371 .network = NULL
7372 };
7373 struct ipw_supported_rates *rates;
7374 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007375 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007376
James Ketrenosb095c382005-08-24 22:04:42 -05007377 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7378 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7379 return 0;
7380 }
7381
James Ketrenosc848d0a2005-08-24 21:56:24 -05007382 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007383 IPW_DEBUG_ASSOC("Not attempting association (already in "
7384 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007385 return 0;
7386 }
7387
Hong Liue6324722005-09-14 21:04:15 -05007388 if (priv->status & STATUS_DISASSOCIATING) {
7389 IPW_DEBUG_ASSOC("Not attempting association (in "
7390 "disassociating)\n ");
7391 queue_work(priv->workqueue, &priv->associate);
7392 return 0;
7393 }
7394
James Ketrenosc848d0a2005-08-24 21:56:24 -05007395 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007396 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7397 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007398 return 0;
7399 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007400
7401 if (!(priv->config & CFG_ASSOCIATE) &&
7402 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007403 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007404 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007405 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007406 }
7407
James Ketrenosa613bff2005-08-24 21:43:11 -05007408 /* Protect our use of the network_list */
7409 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007410 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007411 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007412
7413 network = match.network;
7414 rates = &match.rates;
7415
7416 if (network == NULL &&
7417 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7418 priv->config & CFG_ADHOC_CREATE &&
7419 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007420 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007421 !list_empty(&priv->ieee->network_free_list)) {
7422 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007423 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007424 ipw_adhoc_create(priv, network);
7425 rates = &priv->rates;
7426 list_del(element);
7427 list_add_tail(&network->list, &priv->ieee->network_list);
7428 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007429 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007430
James Ketrenos43f66a62005-03-25 12:31:53 -06007431 /* If we reached the end of the list, then we don't have any valid
7432 * matching APs */
7433 if (!network) {
7434 ipw_debug_config(priv);
7435
James Ketrenosb095c382005-08-24 22:04:42 -05007436 if (!(priv->status & STATUS_SCANNING)) {
7437 if (!(priv->config & CFG_SPEED_SCAN))
7438 queue_delayed_work(priv->workqueue,
7439 &priv->request_scan,
7440 SCAN_INTERVAL);
7441 else
7442 queue_work(priv->workqueue,
7443 &priv->request_scan);
7444 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007445
James Ketrenosc848d0a2005-08-24 21:56:24 -05007446 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007447 }
7448
7449 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007450
7451 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007452}
Jeff Garzikbf794512005-07-31 13:07:26 -04007453
James Ketrenosc848d0a2005-08-24 21:56:24 -05007454static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007455{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007456 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007457 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007458 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007459 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007460}
7461
James Ketrenosb095c382005-08-24 22:04:42 -05007462static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7463 struct sk_buff *skb)
7464{
7465 struct ieee80211_hdr *hdr;
7466 u16 fc;
7467
7468 hdr = (struct ieee80211_hdr *)skb->data;
7469 fc = le16_to_cpu(hdr->frame_ctl);
7470 if (!(fc & IEEE80211_FCTL_PROTECTED))
7471 return;
7472
7473 fc &= ~IEEE80211_FCTL_PROTECTED;
7474 hdr->frame_ctl = cpu_to_le16(fc);
7475 switch (priv->ieee->sec.level) {
7476 case SEC_LEVEL_3:
7477 /* Remove CCMP HDR */
7478 memmove(skb->data + IEEE80211_3ADDR_LEN,
7479 skb->data + IEEE80211_3ADDR_LEN + 8,
7480 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007481 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007482 break;
7483 case SEC_LEVEL_2:
7484 break;
7485 case SEC_LEVEL_1:
7486 /* Remove IV */
7487 memmove(skb->data + IEEE80211_3ADDR_LEN,
7488 skb->data + IEEE80211_3ADDR_LEN + 4,
7489 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007490 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007491 break;
7492 case SEC_LEVEL_0:
7493 break;
7494 default:
7495 printk(KERN_ERR "Unknow security level %d\n",
7496 priv->ieee->sec.level);
7497 break;
7498 }
7499}
7500
7501static void ipw_handle_data_packet(struct ipw_priv *priv,
7502 struct ipw_rx_mem_buffer *rxb,
7503 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007504{
Hong Liu567deaf2005-08-31 18:07:22 +08007505 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007506 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7507
7508 /* We received data from the HW, so stop the watchdog */
7509 priv->net_dev->trans_start = jiffies;
7510
Jeff Garzikbf794512005-07-31 13:07:26 -04007511 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007512 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007513 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007514 skb_tailroom(rxb->skb))) {
7515 priv->ieee->stats.rx_errors++;
7516 priv->wstats.discard.misc++;
7517 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7518 return;
7519 } else if (unlikely(!netif_running(priv->net_dev))) {
7520 priv->ieee->stats.rx_dropped++;
7521 priv->wstats.discard.misc++;
7522 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7523 return;
7524 }
7525
7526 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007527 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007528
7529 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007530 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007531
7532 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7533
James Ketrenosb095c382005-08-24 22:04:42 -05007534 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007535 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7536 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007537 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007538 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007539 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7540
Jeff Garzikbf794512005-07-31 13:07:26 -04007541 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007542 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007543 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007544 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007545 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007546 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007547}
7548
Mike Kershaw24a47db2005-08-26 00:41:54 -05007549#ifdef CONFIG_IEEE80211_RADIOTAP
7550static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7551 struct ipw_rx_mem_buffer *rxb,
7552 struct ieee80211_rx_stats *stats)
7553{
7554 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7555 struct ipw_rx_frame *frame = &pkt->u.frame;
7556
7557 /* initial pull of some data */
7558 u16 received_channel = frame->received_channel;
7559 u8 antennaAndPhy = frame->antennaAndPhy;
7560 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7561 u16 pktrate = frame->rate;
7562
7563 /* Magic struct that slots into the radiotap header -- no reason
7564 * to build this manually element by element, we can write it much
7565 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007566 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007567
7568 short len = le16_to_cpu(pkt->u.frame.length);
7569
7570 /* We received data from the HW, so stop the watchdog */
7571 priv->net_dev->trans_start = jiffies;
7572
7573 /* We only process data packets if the
7574 * interface is open */
7575 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7576 skb_tailroom(rxb->skb))) {
7577 priv->ieee->stats.rx_errors++;
7578 priv->wstats.discard.misc++;
7579 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7580 return;
7581 } else if (unlikely(!netif_running(priv->net_dev))) {
7582 priv->ieee->stats.rx_dropped++;
7583 priv->wstats.discard.misc++;
7584 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7585 return;
7586 }
7587
7588 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7589 * that now */
7590 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7591 /* FIXME: Should alloc bigger skb instead */
7592 priv->ieee->stats.rx_dropped++;
7593 priv->wstats.discard.misc++;
7594 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7595 return;
7596 }
7597
7598 /* copy the frame itself */
7599 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7600 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7601
7602 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7603 * part of our real header, saves a little time.
7604 *
7605 * No longer necessary since we fill in all our data. Purge before merging
7606 * patch officially.
7607 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7608 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7609 */
7610
7611 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7612
7613 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7614 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7615 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7616
7617 /* Big bitfield of all the fields we provide in radiotap */
7618 ipw_rt->rt_hdr.it_present =
7619 ((1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007620 (1 << IEEE80211_RADIOTAP_TSFT) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007621 (1 << IEEE80211_RADIOTAP_RATE) |
7622 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7623 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007624 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007625 (1 << IEEE80211_RADIOTAP_ANTENNA));
7626
7627 /* Zero the flags, we'll add to them as we go */
7628 ipw_rt->rt_flags = 0;
7629
7630 /* Convert signal to DBM */
7631 ipw_rt->rt_dbmsignal = antsignal;
7632
7633 /* Convert the channel data and set the flags */
7634 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7635 if (received_channel > 14) { /* 802.11a */
7636 ipw_rt->rt_chbitmask =
7637 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7638 } else if (antennaAndPhy & 32) { /* 802.11b */
7639 ipw_rt->rt_chbitmask =
7640 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7641 } else { /* 802.11g */
7642 ipw_rt->rt_chbitmask =
7643 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7644 }
7645
7646 /* set the rate in multiples of 500k/s */
7647 switch (pktrate) {
7648 case IPW_TX_RATE_1MB:
7649 ipw_rt->rt_rate = 2;
7650 break;
7651 case IPW_TX_RATE_2MB:
7652 ipw_rt->rt_rate = 4;
7653 break;
7654 case IPW_TX_RATE_5MB:
7655 ipw_rt->rt_rate = 10;
7656 break;
7657 case IPW_TX_RATE_6MB:
7658 ipw_rt->rt_rate = 12;
7659 break;
7660 case IPW_TX_RATE_9MB:
7661 ipw_rt->rt_rate = 18;
7662 break;
7663 case IPW_TX_RATE_11MB:
7664 ipw_rt->rt_rate = 22;
7665 break;
7666 case IPW_TX_RATE_12MB:
7667 ipw_rt->rt_rate = 24;
7668 break;
7669 case IPW_TX_RATE_18MB:
7670 ipw_rt->rt_rate = 36;
7671 break;
7672 case IPW_TX_RATE_24MB:
7673 ipw_rt->rt_rate = 48;
7674 break;
7675 case IPW_TX_RATE_36MB:
7676 ipw_rt->rt_rate = 72;
7677 break;
7678 case IPW_TX_RATE_48MB:
7679 ipw_rt->rt_rate = 96;
7680 break;
7681 case IPW_TX_RATE_54MB:
7682 ipw_rt->rt_rate = 108;
7683 break;
7684 default:
7685 ipw_rt->rt_rate = 0;
7686 break;
7687 }
7688
7689 /* antenna number */
7690 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7691
7692 /* set the preamble flag if we have it */
7693 if ((antennaAndPhy & 64))
7694 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7695
7696 /* Set the size of the skb to the size of the frame */
7697 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007698
7699 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7700
7701 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7702 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007703 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007704 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007705 /* no LED during capture */
7706 }
7707}
7708#endif
7709
Zhu Yid685b8c2006-04-13 17:20:27 +08007710#ifdef CONFIG_IPW2200_PROMISCUOUS
7711#define ieee80211_is_probe_response(fc) \
7712 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7713 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7714
7715#define ieee80211_is_management(fc) \
7716 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7717
7718#define ieee80211_is_control(fc) \
7719 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7720
7721#define ieee80211_is_data(fc) \
7722 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7723
7724#define ieee80211_is_assoc_request(fc) \
7725 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7726
7727#define ieee80211_is_reassoc_request(fc) \
7728 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7729
7730static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7731 struct ipw_rx_mem_buffer *rxb,
7732 struct ieee80211_rx_stats *stats)
7733{
7734 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7735 struct ipw_rx_frame *frame = &pkt->u.frame;
7736 struct ipw_rt_hdr *ipw_rt;
7737
7738 /* First cache any information we need before we overwrite
7739 * the information provided in the skb from the hardware */
7740 struct ieee80211_hdr *hdr;
7741 u16 channel = frame->received_channel;
7742 u8 phy_flags = frame->antennaAndPhy;
7743 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7744 s8 noise = frame->noise;
7745 u8 rate = frame->rate;
7746 short len = le16_to_cpu(pkt->u.frame.length);
7747 u64 tsf = 0;
7748 struct sk_buff *skb;
7749 int hdr_only = 0;
7750 u16 filter = priv->prom_priv->filter;
7751
7752 /* If the filter is set to not include Rx frames then return */
7753 if (filter & IPW_PROM_NO_RX)
7754 return;
7755
7756 if (!noise)
7757 noise = priv->last_noise;
7758
7759 /* We received data from the HW, so stop the watchdog */
7760 priv->prom_net_dev->trans_start = jiffies;
7761
7762 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7763 priv->prom_priv->ieee->stats.rx_errors++;
7764 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7765 return;
7766 }
7767
7768 /* We only process data packets if the interface is open */
7769 if (unlikely(!netif_running(priv->prom_net_dev))) {
7770 priv->prom_priv->ieee->stats.rx_dropped++;
7771 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7772 return;
7773 }
7774
7775 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7776 * that now */
7777 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7778 /* FIXME: Should alloc bigger skb instead */
7779 priv->prom_priv->ieee->stats.rx_dropped++;
7780 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7781 return;
7782 }
7783
7784 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7785 if (ieee80211_is_management(hdr->frame_ctl)) {
7786 if (filter & IPW_PROM_NO_MGMT)
7787 return;
7788 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7789 hdr_only = 1;
7790 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7791 if (filter & IPW_PROM_NO_CTL)
7792 return;
7793 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7794 hdr_only = 1;
7795 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7796 if (filter & IPW_PROM_NO_DATA)
7797 return;
7798 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7799 hdr_only = 1;
7800 }
7801
7802 /* Copy the SKB since this is for the promiscuous side */
7803 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7804 if (skb == NULL) {
7805 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7806 return;
7807 }
7808
7809 /* copy the frame data to write after where the radiotap header goes */
7810 ipw_rt = (void *)skb->data;
7811
7812 if (hdr_only)
7813 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7814
7815 memcpy(ipw_rt->payload, hdr, len);
7816
7817 /* Zero the radiotap static buffer ... We only need to zero the bytes
7818 * NOT part of our real header, saves a little time.
7819 *
7820 * No longer necessary since we fill in all our data. Purge before
7821 * merging patch officially.
7822 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7823 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7824 */
7825
7826 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7827 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7828 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7829
7830 /* Set the size of the skb to the size of the frame */
7831 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7832
7833 /* Big bitfield of all the fields we provide in radiotap */
7834 ipw_rt->rt_hdr.it_present =
7835 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7836 (1 << IEEE80211_RADIOTAP_TSFT) |
7837 (1 << IEEE80211_RADIOTAP_RATE) |
7838 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7839 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7840 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7841 (1 << IEEE80211_RADIOTAP_ANTENNA));
7842
7843 /* Zero the flags, we'll add to them as we go */
7844 ipw_rt->rt_flags = 0;
7845
7846 ipw_rt->rt_tsf = tsf;
7847
7848 /* Convert to DBM */
7849 ipw_rt->rt_dbmsignal = signal;
7850 ipw_rt->rt_dbmnoise = noise;
7851
7852 /* Convert the channel data and set the flags */
7853 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7854 if (channel > 14) { /* 802.11a */
7855 ipw_rt->rt_chbitmask =
7856 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7857 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7858 ipw_rt->rt_chbitmask =
7859 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7860 } else { /* 802.11g */
7861 ipw_rt->rt_chbitmask =
7862 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7863 }
7864
7865 /* set the rate in multiples of 500k/s */
7866 switch (rate) {
7867 case IPW_TX_RATE_1MB:
7868 ipw_rt->rt_rate = 2;
7869 break;
7870 case IPW_TX_RATE_2MB:
7871 ipw_rt->rt_rate = 4;
7872 break;
7873 case IPW_TX_RATE_5MB:
7874 ipw_rt->rt_rate = 10;
7875 break;
7876 case IPW_TX_RATE_6MB:
7877 ipw_rt->rt_rate = 12;
7878 break;
7879 case IPW_TX_RATE_9MB:
7880 ipw_rt->rt_rate = 18;
7881 break;
7882 case IPW_TX_RATE_11MB:
7883 ipw_rt->rt_rate = 22;
7884 break;
7885 case IPW_TX_RATE_12MB:
7886 ipw_rt->rt_rate = 24;
7887 break;
7888 case IPW_TX_RATE_18MB:
7889 ipw_rt->rt_rate = 36;
7890 break;
7891 case IPW_TX_RATE_24MB:
7892 ipw_rt->rt_rate = 48;
7893 break;
7894 case IPW_TX_RATE_36MB:
7895 ipw_rt->rt_rate = 72;
7896 break;
7897 case IPW_TX_RATE_48MB:
7898 ipw_rt->rt_rate = 96;
7899 break;
7900 case IPW_TX_RATE_54MB:
7901 ipw_rt->rt_rate = 108;
7902 break;
7903 default:
7904 ipw_rt->rt_rate = 0;
7905 break;
7906 }
7907
7908 /* antenna number */
7909 ipw_rt->rt_antenna = (phy_flags & 3);
7910
7911 /* set the preamble flag if we have it */
7912 if (phy_flags & (1 << 6))
7913 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7914
7915 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7916
7917 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7918 priv->prom_priv->ieee->stats.rx_errors++;
7919 dev_kfree_skb_any(skb);
7920 }
7921}
7922#endif
7923
Arjan van de Ven858119e2006-01-14 13:20:43 -08007924static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007925 struct ieee80211_hdr_4addr *header)
7926{
7927 /* Filter incoming packets to determine if they are targetted toward
7928 * this network, discarding packets coming from ourselves */
7929 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007930 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007931 /* packets from our adapter are dropped (echo) */
7932 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7933 return 0;
7934
Peter Jones90700fd2005-08-26 16:51:06 -05007935 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007936 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007937 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007938
7939 /* packets to our adapter go through */
7940 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7941 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007942
Peter Jones90700fd2005-08-26 16:51:06 -05007943 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007944 /* packets from our adapter are dropped (echo) */
7945 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7946 return 0;
7947
Peter Jones90700fd2005-08-26 16:51:06 -05007948 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007949 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007950 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7951
7952 /* packets to our adapter go through */
7953 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7954 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007955 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007956
James Ketrenosea2b26e2005-08-24 21:25:16 -05007957 return 1;
7958}
7959
James Ketrenosafbf30a2005-08-25 00:05:33 -05007960#define IPW_PACKET_RETRY_TIME HZ
7961
Arjan van de Ven858119e2006-01-14 13:20:43 -08007962static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007963 struct ieee80211_hdr_4addr *header)
7964{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007965 u16 sc = le16_to_cpu(header->seq_ctl);
7966 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7967 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7968 u16 *last_seq, *last_frag;
7969 unsigned long *last_time;
7970
7971 switch (priv->ieee->iw_mode) {
7972 case IW_MODE_ADHOC:
7973 {
7974 struct list_head *p;
7975 struct ipw_ibss_seq *entry = NULL;
7976 u8 *mac = header->addr2;
7977 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7978
7979 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7980 entry =
7981 list_entry(p, struct ipw_ibss_seq, list);
7982 if (!memcmp(entry->mac, mac, ETH_ALEN))
7983 break;
7984 }
7985 if (p == &priv->ibss_mac_hash[index]) {
7986 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7987 if (!entry) {
7988 IPW_ERROR
7989 ("Cannot malloc new mac entry\n");
7990 return 0;
7991 }
7992 memcpy(entry->mac, mac, ETH_ALEN);
7993 entry->seq_num = seq;
7994 entry->frag_num = frag;
7995 entry->packet_time = jiffies;
7996 list_add(&entry->list,
7997 &priv->ibss_mac_hash[index]);
7998 return 0;
7999 }
8000 last_seq = &entry->seq_num;
8001 last_frag = &entry->frag_num;
8002 last_time = &entry->packet_time;
8003 break;
8004 }
8005 case IW_MODE_INFRA:
8006 last_seq = &priv->last_seq_num;
8007 last_frag = &priv->last_frag_num;
8008 last_time = &priv->last_packet_time;
8009 break;
8010 default:
8011 return 0;
8012 }
8013 if ((*last_seq == seq) &&
8014 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8015 if (*last_frag == frag)
8016 goto drop;
8017 if (*last_frag + 1 != frag)
8018 /* out-of-order fragment */
8019 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008020 } else
8021 *last_seq = seq;
8022
Zhu Yif57ce7c2005-07-13 12:22:15 -05008023 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008024 *last_time = jiffies;
8025 return 0;
8026
8027 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008028 /* Comment this line now since we observed the card receives
8029 * duplicate packets but the FCTL_RETRY bit is not set in the
8030 * IBSS mode with fragmentation enabled.
8031 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008032 return 1;
8033}
8034
James Ketrenosb095c382005-08-24 22:04:42 -05008035static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8036 struct ipw_rx_mem_buffer *rxb,
8037 struct ieee80211_rx_stats *stats)
8038{
8039 struct sk_buff *skb = rxb->skb;
8040 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8041 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8042 (skb->data + IPW_RX_FRAME_SIZE);
8043
8044 ieee80211_rx_mgt(priv->ieee, header, stats);
8045
8046 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8047 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8048 IEEE80211_STYPE_PROBE_RESP) ||
8049 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8050 IEEE80211_STYPE_BEACON))) {
8051 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8052 ipw_add_station(priv, header->addr2);
8053 }
8054
8055 if (priv->config & CFG_NET_STATS) {
8056 IPW_DEBUG_HC("sending stat packet\n");
8057
8058 /* Set the size of the skb to the size of the full
8059 * ipw header and 802.11 frame */
8060 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8061 IPW_RX_FRAME_SIZE);
8062
8063 /* Advance past the ipw packet header to the 802.11 frame */
8064 skb_pull(skb, IPW_RX_FRAME_SIZE);
8065
8066 /* Push the ieee80211_rx_stats before the 802.11 frame */
8067 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8068
8069 skb->dev = priv->ieee->dev;
8070
8071 /* Point raw at the ieee80211_stats */
8072 skb->mac.raw = skb->data;
8073
8074 skb->pkt_type = PACKET_OTHERHOST;
8075 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8076 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8077 netif_rx(skb);
8078 rxb->skb = NULL;
8079 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008080}
8081
James Ketrenos43f66a62005-03-25 12:31:53 -06008082/*
8083 * Main entry function for recieving a packet with 80211 headers. This
8084 * should be called when ever the FW has notified us that there is a new
8085 * skb in the recieve queue.
8086 */
8087static void ipw_rx(struct ipw_priv *priv)
8088{
8089 struct ipw_rx_mem_buffer *rxb;
8090 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008091 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008092 u32 r, w, i;
8093 u8 network_packet;
8094
James Ketrenosb095c382005-08-24 22:04:42 -05008095 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8096 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008097 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8098
8099 while (i != r) {
8100 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008101 if (unlikely(rxb == NULL)) {
8102 printk(KERN_CRIT "Queue not allocated!\n");
8103 break;
8104 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008105 priv->rxq->queue[i] = NULL;
8106
8107 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008108 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008109 PCI_DMA_FROMDEVICE);
8110
8111 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8112 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8113 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008114 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008115
8116 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008117 case RX_FRAME_TYPE: /* 802.11 frame */ {
8118 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008119 .rssi =
8120 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008121 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008122 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08008123 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8124 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008125 .noise =
8126 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008127 .rate = pkt->u.frame.rate,
8128 .mac_time = jiffies,
8129 .received_channel =
8130 pkt->u.frame.received_channel,
8131 .freq =
8132 (pkt->u.frame.
8133 control & (1 << 0)) ?
8134 IEEE80211_24GHZ_BAND :
8135 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008136 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008137 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008138
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008139 if (stats.rssi != 0)
8140 stats.mask |= IEEE80211_STATMASK_RSSI;
8141 if (stats.signal != 0)
8142 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008143 if (stats.noise != 0)
8144 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008145 if (stats.rate != 0)
8146 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008147
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008148 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008149
Zhu Yid685b8c2006-04-13 17:20:27 +08008150#ifdef CONFIG_IPW2200_PROMISCUOUS
8151 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8152 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8153#endif
8154
James Ketrenosb095c382005-08-24 22:04:42 -05008155#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008156 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05008157#ifdef CONFIG_IEEE80211_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008158
8159 ipw_handle_data_packet_monitor(priv,
8160 rxb,
8161 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008162#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008163 ipw_handle_data_packet(priv, rxb,
8164 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008165#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008166 break;
8167 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008168#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008169
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008170 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008171 (struct ieee80211_hdr_4addr *)(rxb->skb->
8172 data +
8173 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008174 /* TODO: Check Ad-Hoc dest/source and make sure
8175 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008176 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008177 * frame control of the packet and disregard
8178 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008179
James Ketrenosea2b26e2005-08-24 21:25:16 -05008180 network_packet =
8181 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008182 if (network_packet && priv->assoc_network) {
8183 priv->assoc_network->stats.rssi =
8184 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008185 priv->exp_avg_rssi =
8186 exponential_average(priv->exp_avg_rssi,
8187 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008188 }
8189
8190 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008191 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008192
James Ketrenosa613bff2005-08-24 21:43:11 -05008193 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08008194 ieee80211_get_hdrlen(le16_to_cpu(
8195 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008196 IPW_DEBUG_DROP
8197 ("Received packet is too small. "
8198 "Dropping.\n");
8199 priv->ieee->stats.rx_errors++;
8200 priv->wstats.discard.misc++;
8201 break;
8202 }
8203
James Ketrenosa613bff2005-08-24 21:43:11 -05008204 switch (WLAN_FC_GET_TYPE
8205 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008206
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008207 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008208 ipw_handle_mgmt_packet(priv, rxb,
8209 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008210 break;
8211
8212 case IEEE80211_FTYPE_CTL:
8213 break;
8214
8215 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008216 if (unlikely(!network_packet ||
8217 is_duplicate_packet(priv,
8218 header)))
8219 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008220 IPW_DEBUG_DROP("Dropping: "
8221 MAC_FMT ", "
8222 MAC_FMT ", "
8223 MAC_FMT "\n",
8224 MAC_ARG(header->
8225 addr1),
8226 MAC_ARG(header->
8227 addr2),
8228 MAC_ARG(header->
8229 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008230 break;
8231 }
8232
8233 ipw_handle_data_packet(priv, rxb,
8234 &stats);
8235
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008236 break;
8237 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008238 break;
8239 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008240
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008241 case RX_HOST_NOTIFICATION_TYPE:{
8242 IPW_DEBUG_RX
8243 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008244 pkt->u.notification.subtype,
8245 pkt->u.notification.flags,
8246 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008247 ipw_rx_notification(priv, &pkt->u.notification);
8248 break;
8249 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008250
8251 default:
8252 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8253 pkt->header.message_type);
8254 break;
8255 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008256
8257 /* For now we just don't re-use anything. We can tweak this
8258 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008259 * fail to Rx correctly */
8260 if (rxb->skb != NULL) {
8261 dev_kfree_skb_any(rxb->skb);
8262 rxb->skb = NULL;
8263 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008264
James Ketrenos43f66a62005-03-25 12:31:53 -06008265 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008266 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008267 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008268
James Ketrenos43f66a62005-03-25 12:31:53 -06008269 i = (i + 1) % RX_QUEUE_SIZE;
8270 }
8271
8272 /* Backtrack one entry */
8273 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8274
8275 ipw_rx_queue_restock(priv);
8276}
8277
James Ketrenosafbf30a2005-08-25 00:05:33 -05008278#define DEFAULT_RTS_THRESHOLD 2304U
8279#define MIN_RTS_THRESHOLD 1U
8280#define MAX_RTS_THRESHOLD 2304U
8281#define DEFAULT_BEACON_INTERVAL 100U
8282#define DEFAULT_SHORT_RETRY_LIMIT 7U
8283#define DEFAULT_LONG_RETRY_LIMIT 4U
8284
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008285/**
8286 * ipw_sw_reset
8287 * @option: options to control different reset behaviour
8288 * 0 = reset everything except the 'disable' module_param
8289 * 1 = reset everything and print out driver info (for probe only)
8290 * 2 = reset everything
8291 */
8292static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008293{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008294 int band, modulation;
8295 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008296
James Ketrenosafbf30a2005-08-25 00:05:33 -05008297 /* Initialize module parameter values here */
8298 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008299
James Ketrenosafbf30a2005-08-25 00:05:33 -05008300 /* We default to disabling the LED code as right now it causes
8301 * too many systems to lock up... */
8302 if (!led)
8303 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008304
James Ketrenosafbf30a2005-08-25 00:05:33 -05008305 if (associate)
8306 priv->config |= CFG_ASSOCIATE;
8307 else
8308 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008309
James Ketrenosafbf30a2005-08-25 00:05:33 -05008310 if (auto_create)
8311 priv->config |= CFG_ADHOC_CREATE;
8312 else
8313 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8314
Zhu Yi17ed0812006-01-24 16:36:31 +08008315 priv->config &= ~CFG_STATIC_ESSID;
8316 priv->essid_len = 0;
8317 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8318
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008319 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008320 priv->status |= STATUS_RF_KILL_SW;
8321 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008322 }
8323
James Ketrenosafbf30a2005-08-25 00:05:33 -05008324 if (channel != 0) {
8325 priv->config |= CFG_STATIC_CHANNEL;
8326 priv->channel = channel;
8327 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8328 /* TODO: Validate that provided channel is in range */
8329 }
8330#ifdef CONFIG_IPW_QOS
8331 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8332 burst_duration_CCK, burst_duration_OFDM);
8333#endif /* CONFIG_IPW_QOS */
8334
8335 switch (mode) {
8336 case 1:
8337 priv->ieee->iw_mode = IW_MODE_ADHOC;
8338 priv->net_dev->type = ARPHRD_ETHER;
8339
8340 break;
8341#ifdef CONFIG_IPW2200_MONITOR
8342 case 2:
8343 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008344#ifdef CONFIG_IEEE80211_RADIOTAP
8345 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8346#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008347 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008348#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008349 break;
8350#endif
8351 default:
8352 case 0:
8353 priv->net_dev->type = ARPHRD_ETHER;
8354 priv->ieee->iw_mode = IW_MODE_INFRA;
8355 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008356 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008357
James Ketrenosafbf30a2005-08-25 00:05:33 -05008358 if (hwcrypto) {
8359 priv->ieee->host_encrypt = 0;
8360 priv->ieee->host_encrypt_msdu = 0;
8361 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008362 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008363 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008364 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008365
Zhu Yie402c932005-08-05 17:20:40 +08008366 /* IPW2200/2915 is abled to do hardware fragmentation. */
8367 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008368
James Ketrenosafbf30a2005-08-25 00:05:33 -05008369 if ((priv->pci_dev->device == 0x4223) ||
8370 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008371 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008372 printk(KERN_INFO DRV_NAME
8373 ": Detected Intel PRO/Wireless 2915ABG Network "
8374 "Connection\n");
8375 priv->ieee->abg_true = 1;
8376 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8377 modulation = IEEE80211_OFDM_MODULATION |
8378 IEEE80211_CCK_MODULATION;
8379 priv->adapter = IPW_2915ABG;
8380 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008381 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008382 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008383 printk(KERN_INFO DRV_NAME
8384 ": Detected Intel PRO/Wireless 2200BG Network "
8385 "Connection\n");
8386
8387 priv->ieee->abg_true = 0;
8388 band = IEEE80211_24GHZ_BAND;
8389 modulation = IEEE80211_OFDM_MODULATION |
8390 IEEE80211_CCK_MODULATION;
8391 priv->adapter = IPW_2200BG;
8392 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008393 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008394
James Ketrenosafbf30a2005-08-25 00:05:33 -05008395 priv->ieee->freq_band = band;
8396 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008397
James Ketrenosafbf30a2005-08-25 00:05:33 -05008398 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008399
James Ketrenosafbf30a2005-08-25 00:05:33 -05008400 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8401 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008402
James Ketrenosafbf30a2005-08-25 00:05:33 -05008403 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8404 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8405 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008406
James Ketrenosafbf30a2005-08-25 00:05:33 -05008407 /* If power management is turned on, default to AC mode */
8408 priv->power_mode = IPW_POWER_AC;
8409 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008410
Zhu Yi0ece35b2005-08-05 17:26:51 +08008411 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008412}
8413
8414/*
8415 * This file defines the Wireless Extension handlers. It does not
8416 * define any methods of hardware manipulation and relies on the
8417 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008418 *
8419 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008420 * function used to poll the hardware vs. making unecessary calls.
8421 *
8422 */
8423
Jeff Garzikbf794512005-07-31 13:07:26 -04008424static int ipw_wx_get_name(struct net_device *dev,
8425 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008426 union iwreq_data *wrqu, char *extra)
8427{
8428 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008429 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008430 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008431 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008432 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008433 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008434 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008435 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8436 ipw_modes[priv->assoc_request.ieee_mode]);
8437 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008438 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008439 return 0;
8440}
8441
8442static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8443{
8444 if (channel == 0) {
8445 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8446 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008447 IPW_DEBUG_ASSOC("Attempting to associate with new "
8448 "parameters.\n");
8449 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008450 return 0;
8451 }
8452
8453 priv->config |= CFG_STATIC_CHANNEL;
8454
8455 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008456 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8457 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008458 return 0;
8459 }
8460
8461 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8462 priv->channel = channel;
8463
James Ketrenosb095c382005-08-24 22:04:42 -05008464#ifdef CONFIG_IPW2200_MONITOR
8465 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008466 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008467 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008468 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008469 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008470 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008471 }
8472
8473 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8474 udelay(10);
8475
8476 if (priv->status & STATUS_SCANNING)
8477 IPW_DEBUG_SCAN("Still scanning...\n");
8478 else
8479 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8480 1000 - i);
8481
8482 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008483 }
James Ketrenosb095c382005-08-24 22:04:42 -05008484#endif /* CONFIG_IPW2200_MONITOR */
8485
James Ketrenosc848d0a2005-08-24 21:56:24 -05008486 /* Network configuration changed -- force [re]association */
8487 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8488 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008489 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008490
8491 return 0;
8492}
8493
Jeff Garzikbf794512005-07-31 13:07:26 -04008494static int ipw_wx_set_freq(struct net_device *dev,
8495 struct iw_request_info *info,
8496 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008497{
8498 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008499 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008500 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008501 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008502 u8 channel, flags;
8503 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008504
James Ketrenosb095c382005-08-24 22:04:42 -05008505 if (fwrq->m == 0) {
8506 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008507 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008508 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008509 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008510 return ret;
8511 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008512 /* if setting by freq convert to channel */
8513 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008514 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008515 if (channel == 0)
8516 return -EINVAL;
8517 } else
8518 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008519
Larry Finger1867b112006-02-28 09:48:28 -06008520 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008521 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008522
Liu Hong1fe0adb2005-08-19 09:33:10 -05008523 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008524 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008525 if (i == -1)
8526 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008527
8528 flags = (band == IEEE80211_24GHZ_BAND) ?
8529 geo->bg[i].flags : geo->a[i].flags;
8530 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008531 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8532 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008533 }
8534 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008535
James Ketrenos43f66a62005-03-25 12:31:53 -06008536 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008537 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008538 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008539 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008540 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008541}
8542
Jeff Garzikbf794512005-07-31 13:07:26 -04008543static int ipw_wx_get_freq(struct net_device *dev,
8544 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 union iwreq_data *wrqu, char *extra)
8546{
8547 struct ipw_priv *priv = ieee80211_priv(dev);
8548
8549 wrqu->freq.e = 0;
8550
8551 /* If we are associated, trying to associate, or have a statically
8552 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008553 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008554 if (priv->config & CFG_STATIC_CHANNEL ||
8555 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8556 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008557 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008558 wrqu->freq.m = 0;
8559
Zhu Yi46441512006-01-24 16:37:59 +08008560 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008561 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8562 return 0;
8563}
8564
Jeff Garzikbf794512005-07-31 13:07:26 -04008565static int ipw_wx_set_mode(struct net_device *dev,
8566 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008567 union iwreq_data *wrqu, char *extra)
8568{
8569 struct ipw_priv *priv = ieee80211_priv(dev);
8570 int err = 0;
8571
8572 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8573
James Ketrenos43f66a62005-03-25 12:31:53 -06008574 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008575#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008576 case IW_MODE_MONITOR:
8577#endif
8578 case IW_MODE_ADHOC:
8579 case IW_MODE_INFRA:
8580 break;
8581 case IW_MODE_AUTO:
8582 wrqu->mode = IW_MODE_INFRA;
8583 break;
8584 default:
8585 return -EINVAL;
8586 }
James Ketrenosb095c382005-08-24 22:04:42 -05008587 if (wrqu->mode == priv->ieee->iw_mode)
8588 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008589
Zhu Yi46441512006-01-24 16:37:59 +08008590 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008591
8592 ipw_sw_reset(priv, 0);
8593
James Ketrenosb095c382005-08-24 22:04:42 -05008594#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008595 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008597
8598 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008599#ifdef CONFIG_IEEE80211_RADIOTAP
8600 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8601#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008603#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008604#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008605
Jeff Garzikbf794512005-07-31 13:07:26 -04008606 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008607 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008608 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008609
8610 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008611
James Ketrenosc848d0a2005-08-24 21:56:24 -05008612 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008613 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008614 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008615}
8616
Jeff Garzikbf794512005-07-31 13:07:26 -04008617static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008618 struct iw_request_info *info,
8619 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008620{
8621 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008622 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008623 wrqu->mode = priv->ieee->iw_mode;
8624 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008625 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008626 return 0;
8627}
8628
James Ketrenos43f66a62005-03-25 12:31:53 -06008629/* Values are in microsecond */
8630static const s32 timeout_duration[] = {
8631 350000,
8632 250000,
8633 75000,
8634 37000,
8635 25000,
8636};
8637
8638static const s32 period_duration[] = {
8639 400000,
8640 700000,
8641 1000000,
8642 1000000,
8643 1000000
8644};
8645
Jeff Garzikbf794512005-07-31 13:07:26 -04008646static int ipw_wx_get_range(struct net_device *dev,
8647 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008648 union iwreq_data *wrqu, char *extra)
8649{
8650 struct ipw_priv *priv = ieee80211_priv(dev);
8651 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008652 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008653 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008654
8655 wrqu->data.length = sizeof(*range);
8656 memset(range, 0, sizeof(*range));
8657
8658 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008659 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008660
8661 range->max_qual.qual = 100;
8662 /* TODO: Find real max RSSI and stick here */
8663 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008664 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008665 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008666
8667 range->avg_qual.qual = 70;
8668 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008669 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008670 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008671 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008672 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008673 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008674
Jeff Garzikbf794512005-07-31 13:07:26 -04008675 for (i = 0; i < range->num_bitrates; i++)
8676 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008677 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008678
James Ketrenos43f66a62005-03-25 12:31:53 -06008679 range->max_rts = DEFAULT_RTS_THRESHOLD;
8680 range->min_frag = MIN_FRAG_THRESHOLD;
8681 range->max_frag = MAX_FRAG_THRESHOLD;
8682
8683 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008684 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008685 range->num_encoding_sizes = 2;
8686 range->max_encoding_tokens = WEP_KEYS;
8687
8688 /* Set the Wireless Extension versions */
8689 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008690 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008691
James Ketrenosb095c382005-08-24 22:04:42 -05008692 i = 0;
8693 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008694 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8695 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8696 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8697 continue;
8698
James Ketrenosb095c382005-08-24 22:04:42 -05008699 range->freq[i].i = geo->bg[j].channel;
8700 range->freq[i].m = geo->bg[j].freq * 100000;
8701 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008702 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008703 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008704 }
James Ketrenosb095c382005-08-24 22:04:42 -05008705
8706 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008707 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8708 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8709 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8710 continue;
8711
James Ketrenosb095c382005-08-24 22:04:42 -05008712 range->freq[i].i = geo->a[j].channel;
8713 range->freq[i].m = geo->a[j].freq * 100000;
8714 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008715 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008716 }
8717 }
8718
8719 range->num_channels = i;
8720 range->num_frequency = i;
8721
Zhu Yi46441512006-01-24 16:37:59 +08008722 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008723
8724 /* Event capability (kernel + driver) */
8725 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8726 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008727 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8728 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008729 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008730
Dan Williamsf1b50862006-01-30 13:58:56 -05008731 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8732 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8733
James Ketrenos43f66a62005-03-25 12:31:53 -06008734 IPW_DEBUG_WX("GET Range\n");
8735 return 0;
8736}
8737
Jeff Garzikbf794512005-07-31 13:07:26 -04008738static int ipw_wx_set_wap(struct net_device *dev,
8739 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008740 union iwreq_data *wrqu, char *extra)
8741{
8742 struct ipw_priv *priv = ieee80211_priv(dev);
8743
8744 static const unsigned char any[] = {
8745 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8746 };
8747 static const unsigned char off[] = {
8748 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8749 };
8750
Jeff Garzikbf794512005-07-31 13:07:26 -04008751 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008752 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008753 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008754 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8755 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8756 /* we disable mandatory BSSID association */
8757 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8758 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008759 IPW_DEBUG_ASSOC("Attempting to associate with new "
8760 "parameters.\n");
8761 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008762 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008763 return 0;
8764 }
8765
8766 priv->config |= CFG_STATIC_BSSID;
8767 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8768 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008769 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008770 return 0;
8771 }
8772
8773 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8774 MAC_ARG(wrqu->ap_addr.sa_data));
8775
8776 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8777
James Ketrenosc848d0a2005-08-24 21:56:24 -05008778 /* Network configuration changed -- force [re]association */
8779 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8780 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008781 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008782
Zhu Yi46441512006-01-24 16:37:59 +08008783 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008784 return 0;
8785}
8786
Jeff Garzikbf794512005-07-31 13:07:26 -04008787static int ipw_wx_get_wap(struct net_device *dev,
8788 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 union iwreq_data *wrqu, char *extra)
8790{
8791 struct ipw_priv *priv = ieee80211_priv(dev);
8792 /* If we are associated, trying to associate, or have a statically
8793 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008794 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008795 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008796 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8797 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008798 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008799 } else
8800 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8801
8802 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8803 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008804 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008805 return 0;
8806}
8807
Jeff Garzikbf794512005-07-31 13:07:26 -04008808static int ipw_wx_set_essid(struct net_device *dev,
8809 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 union iwreq_data *wrqu, char *extra)
8811{
8812 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008813 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008814 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008815 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008816 if (wrqu->essid.flags && wrqu->essid.length) {
8817 length = wrqu->essid.length - 1;
8818 essid = extra;
8819 }
8820 if (length == 0) {
8821 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008822 if ((priv->config & CFG_STATIC_ESSID) &&
8823 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008824 STATUS_ASSOCIATING))) {
8825 IPW_DEBUG_ASSOC("Attempting to associate with new "
8826 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008827 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 ipw_associate(priv);
8829 }
Zhu Yi46441512006-01-24 16:37:59 +08008830 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 return 0;
8832 }
8833
8834 length = min(length, IW_ESSID_MAX_SIZE);
8835
8836 priv->config |= CFG_STATIC_ESSID;
8837
8838 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8839 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008840 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008841 return 0;
8842 }
8843
8844 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8845 length);
8846
8847 priv->essid_len = length;
8848 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008849
James Ketrenosc848d0a2005-08-24 21:56:24 -05008850 /* Network configuration changed -- force [re]association */
8851 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8852 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008853 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008854
Zhu Yi46441512006-01-24 16:37:59 +08008855 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008856 return 0;
8857}
8858
Jeff Garzikbf794512005-07-31 13:07:26 -04008859static int ipw_wx_get_essid(struct net_device *dev,
8860 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 union iwreq_data *wrqu, char *extra)
8862{
8863 struct ipw_priv *priv = ieee80211_priv(dev);
8864
8865 /* If we are associated, trying to associate, or have a statically
8866 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008867 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008869 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8870 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008871 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008872 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008873 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008874 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008875 } else {
8876 IPW_DEBUG_WX("Getting essid: ANY\n");
8877 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008878 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 }
Zhu Yi46441512006-01-24 16:37:59 +08008880 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008881 return 0;
8882}
8883
Jeff Garzikbf794512005-07-31 13:07:26 -04008884static int ipw_wx_set_nick(struct net_device *dev,
8885 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008886 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008887{
James Ketrenos43f66a62005-03-25 12:31:53 -06008888 struct ipw_priv *priv = ieee80211_priv(dev);
8889
8890 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8891 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8892 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008893 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008894 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008895 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008896 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008897 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008898 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008899 return 0;
8900
8901}
8902
Jeff Garzikbf794512005-07-31 13:07:26 -04008903static int ipw_wx_get_nick(struct net_device *dev,
8904 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008905 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008906{
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 struct ipw_priv *priv = ieee80211_priv(dev);
8908 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008909 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008910 wrqu->data.length = strlen(priv->nick) + 1;
8911 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008912 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008913 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008914 return 0;
8915}
8916
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008917static int ipw_wx_set_sens(struct net_device *dev,
8918 struct iw_request_info *info,
8919 union iwreq_data *wrqu, char *extra)
8920{
8921 struct ipw_priv *priv = ieee80211_priv(dev);
8922 int err = 0;
8923
8924 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8925 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8926 mutex_lock(&priv->mutex);
8927
8928 if (wrqu->sens.fixed == 0)
8929 {
8930 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8931 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8932 goto out;
8933 }
8934 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8935 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8936 err = -EINVAL;
8937 goto out;
8938 }
8939
8940 priv->roaming_threshold = wrqu->sens.value;
8941 priv->disassociate_threshold = 3*wrqu->sens.value;
8942 out:
8943 mutex_unlock(&priv->mutex);
8944 return err;
8945}
8946
8947static int ipw_wx_get_sens(struct net_device *dev,
8948 struct iw_request_info *info,
8949 union iwreq_data *wrqu, char *extra)
8950{
8951 struct ipw_priv *priv = ieee80211_priv(dev);
8952 mutex_lock(&priv->mutex);
8953 wrqu->sens.fixed = 1;
8954 wrqu->sens.value = priv->roaming_threshold;
8955 mutex_unlock(&priv->mutex);
8956
8957 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8958 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8959
8960 return 0;
8961}
8962
James Ketrenos43f66a62005-03-25 12:31:53 -06008963static int ipw_wx_set_rate(struct net_device *dev,
8964 struct iw_request_info *info,
8965 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008966{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008967 /* TODO: We should use semaphores or locks for access to priv */
8968 struct ipw_priv *priv = ieee80211_priv(dev);
8969 u32 target_rate = wrqu->bitrate.value;
8970 u32 fixed, mask;
8971
8972 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8973 /* value = X, fixed = 1 means only rate X */
8974 /* value = X, fixed = 0 means all rates lower equal X */
8975
8976 if (target_rate == -1) {
8977 fixed = 0;
8978 mask = IEEE80211_DEFAULT_RATES_MASK;
8979 /* Now we should reassociate */
8980 goto apply;
8981 }
8982
8983 mask = 0;
8984 fixed = wrqu->bitrate.fixed;
8985
8986 if (target_rate == 1000000 || !fixed)
8987 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8988 if (target_rate == 1000000)
8989 goto apply;
8990
8991 if (target_rate == 2000000 || !fixed)
8992 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8993 if (target_rate == 2000000)
8994 goto apply;
8995
8996 if (target_rate == 5500000 || !fixed)
8997 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8998 if (target_rate == 5500000)
8999 goto apply;
9000
9001 if (target_rate == 6000000 || !fixed)
9002 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9003 if (target_rate == 6000000)
9004 goto apply;
9005
9006 if (target_rate == 9000000 || !fixed)
9007 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9008 if (target_rate == 9000000)
9009 goto apply;
9010
9011 if (target_rate == 11000000 || !fixed)
9012 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9013 if (target_rate == 11000000)
9014 goto apply;
9015
9016 if (target_rate == 12000000 || !fixed)
9017 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9018 if (target_rate == 12000000)
9019 goto apply;
9020
9021 if (target_rate == 18000000 || !fixed)
9022 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9023 if (target_rate == 18000000)
9024 goto apply;
9025
9026 if (target_rate == 24000000 || !fixed)
9027 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9028 if (target_rate == 24000000)
9029 goto apply;
9030
9031 if (target_rate == 36000000 || !fixed)
9032 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9033 if (target_rate == 36000000)
9034 goto apply;
9035
9036 if (target_rate == 48000000 || !fixed)
9037 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9038 if (target_rate == 48000000)
9039 goto apply;
9040
9041 if (target_rate == 54000000 || !fixed)
9042 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9043 if (target_rate == 54000000)
9044 goto apply;
9045
9046 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9047 return -EINVAL;
9048
9049 apply:
9050 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9051 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009052 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009053 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009054 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009055 ipw_set_fixed_rate(priv, priv->ieee->mode);
9056 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009057 priv->config |= CFG_FIXED_RATE;
9058
James Ketrenosc848d0a2005-08-24 21:56:24 -05009059 if (priv->rates_mask == mask) {
9060 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009061 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009062 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009063 }
9064
James Ketrenosc848d0a2005-08-24 21:56:24 -05009065 priv->rates_mask = mask;
9066
9067 /* Network configuration changed -- force [re]association */
9068 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9069 if (!ipw_disassociate(priv))
9070 ipw_associate(priv);
9071
Zhu Yi46441512006-01-24 16:37:59 +08009072 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009073 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009074}
9075
Jeff Garzikbf794512005-07-31 13:07:26 -04009076static int ipw_wx_get_rate(struct net_device *dev,
9077 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009078 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009079{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009080 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009081 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009082 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009083 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009084 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009085 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9086 return 0;
9087}
9088
Jeff Garzikbf794512005-07-31 13:07:26 -04009089static int ipw_wx_set_rts(struct net_device *dev,
9090 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009091 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009092{
James Ketrenos43f66a62005-03-25 12:31:53 -06009093 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009094 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009095 if (wrqu->rts.disabled)
9096 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9097 else {
9098 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009099 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009100 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009101 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009102 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009103 priv->rts_threshold = wrqu->rts.value;
9104 }
9105
9106 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009107 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009108 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9109 return 0;
9110}
9111
Jeff Garzikbf794512005-07-31 13:07:26 -04009112static int ipw_wx_get_rts(struct net_device *dev,
9113 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009114 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009115{
James Ketrenos43f66a62005-03-25 12:31:53 -06009116 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009117 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009118 wrqu->rts.value = priv->rts_threshold;
9119 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009120 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009121 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009122 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9123 return 0;
9124}
9125
Jeff Garzikbf794512005-07-31 13:07:26 -04009126static int ipw_wx_set_txpow(struct net_device *dev,
9127 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009129{
James Ketrenos43f66a62005-03-25 12:31:53 -06009130 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009131 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009132
Zhu Yi46441512006-01-24 16:37:59 +08009133 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009134 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009135 err = -EINPROGRESS;
9136 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009137 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009138
James Ketrenosb095c382005-08-24 22:04:42 -05009139 if (!wrqu->power.fixed)
9140 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009141
James Ketrenosc848d0a2005-08-24 21:56:24 -05009142 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009143 err = -EINVAL;
9144 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009145 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009146
James Ketrenosb095c382005-08-24 22:04:42 -05009147 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009148 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009149 err = -EINVAL;
9150 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009151 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009152
9153 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009154 err = ipw_set_tx_power(priv);
9155 out:
Zhu Yi46441512006-01-24 16:37:59 +08009156 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009157 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009158}
9159
Jeff Garzikbf794512005-07-31 13:07:26 -04009160static int ipw_wx_get_txpow(struct net_device *dev,
9161 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009162 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009163{
James Ketrenos43f66a62005-03-25 12:31:53 -06009164 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009165 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009166 wrqu->power.value = priv->tx_power;
9167 wrqu->power.fixed = 1;
9168 wrqu->power.flags = IW_TXPOW_DBM;
9169 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009170 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009171
Jeff Garzikbf794512005-07-31 13:07:26 -04009172 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009173 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009174
9175 return 0;
9176}
9177
Jeff Garzikbf794512005-07-31 13:07:26 -04009178static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009179 struct iw_request_info *info,
9180 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009181{
9182 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009183 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 if (wrqu->frag.disabled)
9185 priv->ieee->fts = DEFAULT_FTS;
9186 else {
9187 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009188 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009189 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009190 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009191 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009192
James Ketrenos43f66a62005-03-25 12:31:53 -06009193 priv->ieee->fts = wrqu->frag.value & ~0x1;
9194 }
9195
9196 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009197 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009198 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9199 return 0;
9200}
9201
Jeff Garzikbf794512005-07-31 13:07:26 -04009202static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009203 struct iw_request_info *info,
9204 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009205{
9206 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009207 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009208 wrqu->frag.value = priv->ieee->fts;
9209 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009210 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009211 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009212 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9213
9214 return 0;
9215}
9216
Jeff Garzikbf794512005-07-31 13:07:26 -04009217static int ipw_wx_set_retry(struct net_device *dev,
9218 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009219 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009220{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009221 struct ipw_priv *priv = ieee80211_priv(dev);
9222
9223 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9224 return -EINVAL;
9225
9226 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9227 return 0;
9228
9229 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9230 return -EINVAL;
9231
Zhu Yi46441512006-01-24 16:37:59 +08009232 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009233 if (wrqu->retry.flags & IW_RETRY_MIN)
9234 priv->short_retry_limit = (u8) wrqu->retry.value;
9235 else if (wrqu->retry.flags & IW_RETRY_MAX)
9236 priv->long_retry_limit = (u8) wrqu->retry.value;
9237 else {
9238 priv->short_retry_limit = (u8) wrqu->retry.value;
9239 priv->long_retry_limit = (u8) wrqu->retry.value;
9240 }
9241
9242 ipw_send_retry_limit(priv, priv->short_retry_limit,
9243 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009244 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009245 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9246 priv->short_retry_limit, priv->long_retry_limit);
9247 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009248}
9249
Jeff Garzikbf794512005-07-31 13:07:26 -04009250static int ipw_wx_get_retry(struct net_device *dev,
9251 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009252 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009253{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009254 struct ipw_priv *priv = ieee80211_priv(dev);
9255
Zhu Yi46441512006-01-24 16:37:59 +08009256 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009257 wrqu->retry.disabled = 0;
9258
9259 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009260 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009261 return -EINVAL;
9262 }
9263
9264 if (wrqu->retry.flags & IW_RETRY_MAX) {
9265 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9266 wrqu->retry.value = priv->long_retry_limit;
9267 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9268 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9269 wrqu->retry.value = priv->short_retry_limit;
9270 } else {
9271 wrqu->retry.flags = IW_RETRY_LIMIT;
9272 wrqu->retry.value = priv->short_retry_limit;
9273 }
Zhu Yi46441512006-01-24 16:37:59 +08009274 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009275
9276 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9277
9278 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009279}
9280
James Ketrenosafbf30a2005-08-25 00:05:33 -05009281static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9282 int essid_len)
9283{
9284 struct ipw_scan_request_ext scan;
9285 int err = 0, scan_type;
9286
Pekka Enbergefb34422005-11-16 21:55:05 +02009287 if (!(priv->status & STATUS_INIT) ||
9288 (priv->status & STATUS_EXIT_PENDING))
9289 return 0;
9290
Zhu Yi46441512006-01-24 16:37:59 +08009291 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009292
9293 if (priv->status & STATUS_RF_KILL_MASK) {
9294 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9295 priv->status |= STATUS_SCAN_PENDING;
9296 goto done;
9297 }
9298
9299 IPW_DEBUG_HC("starting request direct scan!\n");
9300
9301 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009302 /* We should not sleep here; otherwise we will block most
9303 * of the system (for instance, we hold rtnl_lock when we
9304 * get here).
9305 */
9306 err = -EAGAIN;
9307 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009308 }
9309 memset(&scan, 0, sizeof(scan));
9310
9311 if (priv->config & CFG_SPEED_SCAN)
9312 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9313 cpu_to_le16(30);
9314 else
9315 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9316 cpu_to_le16(20);
9317
9318 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9319 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009320 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009321 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9322
9323 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9324
9325 err = ipw_send_ssid(priv, essid, essid_len);
9326 if (err) {
9327 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9328 goto done;
9329 }
9330 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9331
9332 ipw_add_scan_channels(priv, &scan, scan_type);
9333
9334 err = ipw_send_scan_request_ext(priv, &scan);
9335 if (err) {
9336 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9337 goto done;
9338 }
9339
9340 priv->status |= STATUS_SCANNING;
9341
9342 done:
Zhu Yi46441512006-01-24 16:37:59 +08009343 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009344 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009345}
9346
Jeff Garzikbf794512005-07-31 13:07:26 -04009347static int ipw_wx_set_scan(struct net_device *dev,
9348 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009349 union iwreq_data *wrqu, char *extra)
9350{
9351 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009352 struct iw_scan_req *req = NULL;
9353 if (wrqu->data.length
9354 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9355 req = (struct iw_scan_req *)extra;
9356 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9357 ipw_request_direct_scan(priv, req->essid,
9358 req->essid_len);
9359 return 0;
9360 }
9361 }
James Ketrenos8935f392005-10-05 15:59:08 -05009362
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009364
9365 queue_work(priv->workqueue, &priv->request_scan);
9366
James Ketrenos43f66a62005-03-25 12:31:53 -06009367 return 0;
9368}
9369
Jeff Garzikbf794512005-07-31 13:07:26 -04009370static int ipw_wx_get_scan(struct net_device *dev,
9371 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009372 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009373{
James Ketrenos43f66a62005-03-25 12:31:53 -06009374 struct ipw_priv *priv = ieee80211_priv(dev);
9375 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9376}
9377
Jeff Garzikbf794512005-07-31 13:07:26 -04009378static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009379 struct iw_request_info *info,
9380 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009381{
9382 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009383 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009384 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009385
Zhu Yi46441512006-01-24 16:37:59 +08009386 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009387 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009388
Hong Liucaeff812005-08-05 17:25:50 +08009389 /* In IBSS mode, we need to notify the firmware to update
9390 * the beacon info after we changed the capability. */
9391 if (cap != priv->capability &&
9392 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9393 priv->status & STATUS_ASSOCIATED)
9394 ipw_disassociate(priv);
9395
Zhu Yi46441512006-01-24 16:37:59 +08009396 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009397 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009398}
9399
Jeff Garzikbf794512005-07-31 13:07:26 -04009400static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009401 struct iw_request_info *info,
9402 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009403{
9404 struct ipw_priv *priv = ieee80211_priv(dev);
9405 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9406}
9407
Jeff Garzikbf794512005-07-31 13:07:26 -04009408static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009409 struct iw_request_info *info,
9410 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009411{
9412 struct ipw_priv *priv = ieee80211_priv(dev);
9413 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009414 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009415 if (wrqu->power.disabled) {
9416 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9417 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9418 if (err) {
9419 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009420 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 return err;
9422 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009423 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009424 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009425 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009426 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009427
9428 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009429 case IW_POWER_ON: /* If not specified */
9430 case IW_POWER_MODE: /* If set all mask */
9431 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009432 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009433 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009434 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9435 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009436 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009437 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009438 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009439
James Ketrenos43f66a62005-03-25 12:31:53 -06009440 /* If the user hasn't specified a power management mode yet, default
9441 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009442 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009443 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009444 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9446 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9447 if (err) {
9448 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009449 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009450 return err;
9451 }
9452
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009453 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009454 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009455 return 0;
9456}
9457
Jeff Garzikbf794512005-07-31 13:07:26 -04009458static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009459 struct iw_request_info *info,
9460 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009461{
9462 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009463 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009464 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009465 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009466 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009467 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009468
Zhu Yi46441512006-01-24 16:37:59 +08009469 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009470 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009471
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 return 0;
9473}
9474
Jeff Garzikbf794512005-07-31 13:07:26 -04009475static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009476 struct iw_request_info *info,
9477 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009478{
9479 struct ipw_priv *priv = ieee80211_priv(dev);
9480 int mode = *(int *)extra;
9481 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009482 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009483 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9484 mode = IPW_POWER_AC;
9485 priv->power_mode = mode;
9486 } else {
9487 priv->power_mode = IPW_POWER_ENABLED | mode;
9488 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009489
James Ketrenos43f66a62005-03-25 12:31:53 -06009490 if (priv->power_mode != mode) {
9491 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009492
James Ketrenos43f66a62005-03-25 12:31:53 -06009493 if (err) {
9494 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009495 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009496 return err;
9497 }
9498 }
Zhu Yi46441512006-01-24 16:37:59 +08009499 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009500 return 0;
9501}
9502
9503#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009504static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009505 struct iw_request_info *info,
9506 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009507{
9508 struct ipw_priv *priv = ieee80211_priv(dev);
9509 int level = IPW_POWER_LEVEL(priv->power_mode);
9510 char *p = extra;
9511
9512 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9513
9514 switch (level) {
9515 case IPW_POWER_AC:
9516 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9517 break;
9518 case IPW_POWER_BATTERY:
9519 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9520 break;
9521 default:
9522 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009523 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009524 timeout_duration[level - 1] / 1000,
9525 period_duration[level - 1] / 1000);
9526 }
9527
9528 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009529 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009530
9531 wrqu->data.length = p - extra + 1;
9532
9533 return 0;
9534}
9535
9536static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009537 struct iw_request_info *info,
9538 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009539{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009540 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009541 int mode = *(int *)extra;
9542 u8 band = 0, modulation = 0;
9543
9544 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009545 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009546 return -EINVAL;
9547 }
Zhu Yi46441512006-01-24 16:37:59 +08009548 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009549 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009550 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009551 if (mode & IEEE_A) {
9552 band |= IEEE80211_52GHZ_BAND;
9553 modulation |= IEEE80211_OFDM_MODULATION;
9554 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009555 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009556 } else {
9557 if (mode & IEEE_A) {
9558 IPW_WARNING("Attempt to set 2200BG into "
9559 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009560 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009561 return -EINVAL;
9562 }
9563
James Ketrenosa33a1982005-09-14 14:28:59 -05009564 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009565 }
9566
9567 if (mode & IEEE_B) {
9568 band |= IEEE80211_24GHZ_BAND;
9569 modulation |= IEEE80211_CCK_MODULATION;
9570 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009571 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009572
James Ketrenos43f66a62005-03-25 12:31:53 -06009573 if (mode & IEEE_G) {
9574 band |= IEEE80211_24GHZ_BAND;
9575 modulation |= IEEE80211_OFDM_MODULATION;
9576 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009577 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009578
9579 priv->ieee->mode = mode;
9580 priv->ieee->freq_band = band;
9581 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009582 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009583
James Ketrenosc848d0a2005-08-24 21:56:24 -05009584 /* Network configuration changed -- force [re]association */
9585 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9586 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009587 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009588 ipw_associate(priv);
9589 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009590
James Ketrenosa613bff2005-08-24 21:43:11 -05009591 /* Update the band LEDs */
9592 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009593
Jeff Garzikbf794512005-07-31 13:07:26 -04009594 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009595 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009596 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009597 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009598 return 0;
9599}
9600
9601static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009602 struct iw_request_info *info,
9603 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009604{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009605 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009606 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009607 switch (priv->ieee->mode) {
9608 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009609 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9610 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009611 case IEEE_B:
9612 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9613 break;
9614 case IEEE_A | IEEE_B:
9615 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9616 break;
9617 case IEEE_G:
9618 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9619 break;
9620 case IEEE_A | IEEE_G:
9621 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9622 break;
9623 case IEEE_B | IEEE_G:
9624 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9625 break;
9626 case IEEE_A | IEEE_B | IEEE_G:
9627 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9628 break;
9629 default:
9630 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009631 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009632 }
9633
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9635
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009636 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009637 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009638
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009639 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009640}
9641
James Ketrenosea2b26e2005-08-24 21:25:16 -05009642static int ipw_wx_set_preamble(struct net_device *dev,
9643 struct iw_request_info *info,
9644 union iwreq_data *wrqu, char *extra)
9645{
9646 struct ipw_priv *priv = ieee80211_priv(dev);
9647 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009648 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009649 /* Switching from SHORT -> LONG requires a disassociation */
9650 if (mode == 1) {
9651 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9652 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009653
9654 /* Network configuration changed -- force [re]association */
9655 IPW_DEBUG_ASSOC
9656 ("[re]association triggered due to preamble change.\n");
9657 if (!ipw_disassociate(priv))
9658 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009659 }
9660 goto done;
9661 }
9662
9663 if (mode == 0) {
9664 priv->config &= ~CFG_PREAMBLE_LONG;
9665 goto done;
9666 }
Zhu Yi46441512006-01-24 16:37:59 +08009667 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009668 return -EINVAL;
9669
9670 done:
Zhu Yi46441512006-01-24 16:37:59 +08009671 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009672 return 0;
9673}
9674
9675static int ipw_wx_get_preamble(struct net_device *dev,
9676 struct iw_request_info *info,
9677 union iwreq_data *wrqu, char *extra)
9678{
9679 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009680 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009681 if (priv->config & CFG_PREAMBLE_LONG)
9682 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9683 else
9684 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009685 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009686 return 0;
9687}
9688
James Ketrenosb095c382005-08-24 22:04:42 -05009689#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009690static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009691 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009693{
James Ketrenos43f66a62005-03-25 12:31:53 -06009694 struct ipw_priv *priv = ieee80211_priv(dev);
9695 int *parms = (int *)extra;
9696 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009697 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009698 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009699 if (enable) {
9700 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009701#ifdef CONFIG_IEEE80211_RADIOTAP
9702 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9703#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009704 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009705#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009706 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009707 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009708
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 ipw_set_channel(priv, parms[1]);
9710 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009711 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009712 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009713 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009714 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009715 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009716 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009717 }
Zhu Yi46441512006-01-24 16:37:59 +08009718 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009719 return 0;
9720}
9721
James Ketrenosb095c382005-08-24 22:04:42 -05009722#endif // CONFIG_IPW2200_MONITOR
9723
Jeff Garzikbf794512005-07-31 13:07:26 -04009724static int ipw_wx_reset(struct net_device *dev,
9725 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009727{
James Ketrenos43f66a62005-03-25 12:31:53 -06009728 struct ipw_priv *priv = ieee80211_priv(dev);
9729 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009730 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009731 return 0;
9732}
James Ketrenosb095c382005-08-24 22:04:42 -05009733
James Ketrenosb095c382005-08-24 22:04:42 -05009734static int ipw_wx_sw_reset(struct net_device *dev,
9735 struct iw_request_info *info,
9736 union iwreq_data *wrqu, char *extra)
9737{
9738 struct ipw_priv *priv = ieee80211_priv(dev);
9739 union iwreq_data wrqu_sec = {
9740 .encoding = {
9741 .flags = IW_ENCODE_DISABLED,
9742 },
9743 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009744 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009745
9746 IPW_DEBUG_WX("SW_RESET\n");
9747
Zhu Yi46441512006-01-24 16:37:59 +08009748 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009749
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009750 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009751 if (!ret) {
9752 free_firmware();
9753 ipw_adapter_restart(priv);
9754 }
James Ketrenosb095c382005-08-24 22:04:42 -05009755
9756 /* The SW reset bit might have been toggled on by the 'disable'
9757 * module parameter, so take appropriate action */
9758 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9759
Zhu Yi46441512006-01-24 16:37:59 +08009760 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009761 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009762 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009763
9764 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9765 /* Configuration likely changed -- force [re]association */
9766 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9767 "reset.\n");
9768 if (!ipw_disassociate(priv))
9769 ipw_associate(priv);
9770 }
9771
Zhu Yi46441512006-01-24 16:37:59 +08009772 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009773
9774 return 0;
9775}
James Ketrenos43f66a62005-03-25 12:31:53 -06009776
9777/* Rebase the WE IOCTLs to zero for the handler array */
9778#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009779static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009780 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9781 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9782 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9783 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9784 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009785 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9786 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009787 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9788 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9789 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9790 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9791 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9792 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9793 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9794 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9795 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9796 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9797 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9798 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9799 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9800 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9801 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9802 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9803 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9804 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9805 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9806 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9807 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9808 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9809 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009810 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9811 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9812 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9813 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009814 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9815 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9816 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9817 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9818 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9819 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9820 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009821};
9822
James Ketrenosb095c382005-08-24 22:04:42 -05009823enum {
9824 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9825 IPW_PRIV_GET_POWER,
9826 IPW_PRIV_SET_MODE,
9827 IPW_PRIV_GET_MODE,
9828 IPW_PRIV_SET_PREAMBLE,
9829 IPW_PRIV_GET_PREAMBLE,
9830 IPW_PRIV_RESET,
9831 IPW_PRIV_SW_RESET,
9832#ifdef CONFIG_IPW2200_MONITOR
9833 IPW_PRIV_SET_MONITOR,
9834#endif
9835};
James Ketrenos43f66a62005-03-25 12:31:53 -06009836
Jeff Garzikbf794512005-07-31 13:07:26 -04009837static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009838 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009839 .cmd = IPW_PRIV_SET_POWER,
9840 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9841 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009842 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009843 .cmd = IPW_PRIV_GET_POWER,
9844 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9845 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009846 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009847 .cmd = IPW_PRIV_SET_MODE,
9848 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9849 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009850 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009851 .cmd = IPW_PRIV_GET_MODE,
9852 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9853 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009854 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009855 .cmd = IPW_PRIV_SET_PREAMBLE,
9856 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9857 .name = "set_preamble"},
9858 {
9859 .cmd = IPW_PRIV_GET_PREAMBLE,
9860 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9861 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009862 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009863 IPW_PRIV_RESET,
9864 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009865 {
9866 IPW_PRIV_SW_RESET,
9867 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9868#ifdef CONFIG_IPW2200_MONITOR
9869 {
9870 IPW_PRIV_SET_MONITOR,
9871 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9872#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009873};
9874
9875static iw_handler ipw_priv_handler[] = {
9876 ipw_wx_set_powermode,
9877 ipw_wx_get_powermode,
9878 ipw_wx_set_wireless_mode,
9879 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009880 ipw_wx_set_preamble,
9881 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009882 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009883 ipw_wx_sw_reset,
9884#ifdef CONFIG_IPW2200_MONITOR
9885 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009886#endif
9887};
9888
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009889static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009890 .standard = ipw_wx_handlers,
9891 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9892 .num_private = ARRAY_SIZE(ipw_priv_handler),
9893 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9894 .private = ipw_priv_handler,
9895 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009896 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009897};
9898
James Ketrenos43f66a62005-03-25 12:31:53 -06009899/*
9900 * Get wireless statistics.
9901 * Called by /proc/net/wireless
9902 * Also called by SIOCGIWSTATS
9903 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009904static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009905{
9906 struct ipw_priv *priv = ieee80211_priv(dev);
9907 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009908
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 wstats = &priv->wstats;
9910
James Ketrenosea2b26e2005-08-24 21:25:16 -05009911 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009912 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9914 * and associated; if not associcated, the values are all meaningless
9915 * anyway, so set them all to NULL and INVALID */
9916 if (!(priv->status & STATUS_ASSOCIATED)) {
9917 wstats->miss.beacon = 0;
9918 wstats->discard.retries = 0;
9919 wstats->qual.qual = 0;
9920 wstats->qual.level = 0;
9921 wstats->qual.noise = 0;
9922 wstats->qual.updated = 7;
9923 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009924 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009926 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009927
9928 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009929 wstats->qual.level = priv->exp_avg_rssi;
9930 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009932 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009933
9934 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9935 wstats->discard.retries = priv->last_tx_failures;
9936 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009937
James Ketrenos43f66a62005-03-25 12:31:53 -06009938/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9939 goto fail_get_ordinal;
9940 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009941
James Ketrenos43f66a62005-03-25 12:31:53 -06009942 return wstats;
9943}
9944
James Ketrenos43f66a62005-03-25 12:31:53 -06009945/* net device stuff */
9946
Arjan van de Ven858119e2006-01-14 13:20:43 -08009947static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009948{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009949 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009950 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009951 sys_config->answer_broadcast_ssid_probe = 0;
9952 sys_config->accept_all_data_frames = 0;
9953 sys_config->accept_non_directed_frames = 1;
9954 sys_config->exclude_unicast_unencrypted = 0;
9955 sys_config->disable_unicast_decryption = 1;
9956 sys_config->exclude_multicast_unencrypted = 0;
9957 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +08009958 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9959 antenna = CFG_SYS_ANTENNA_BOTH;
9960 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009961 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009962 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009963 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009964 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009965 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
Cahill, Ben M12977152006-03-08 02:58:02 +08009966 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -06009967}
9968
9969static int ipw_net_open(struct net_device *dev)
9970{
9971 struct ipw_priv *priv = ieee80211_priv(dev);
9972 IPW_DEBUG_INFO("dev->open\n");
9973 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +08009974 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009975 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9976 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009977 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009978 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009979 return 0;
9980}
9981
9982static int ipw_net_stop(struct net_device *dev)
9983{
9984 IPW_DEBUG_INFO("dev->close\n");
9985 netif_stop_queue(dev);
9986 return 0;
9987}
9988
9989/*
9990todo:
9991
9992modify to send one tfd per fragment instead of using chunking. otherwise
9993we need to heavily modify the ieee80211_skb_to_txb.
9994*/
9995
Arjan van de Ven858119e2006-01-14 13:20:43 -08009996static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009997 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009998{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08009999 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010000 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010001 int i = 0;
10002 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -050010003#ifdef CONFIG_IPW_QOS
10004 int tx_id = ipw_get_tx_queue_number(priv, pri);
10005 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10006#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010007 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010008#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010009 struct clx2_queue *q = &txq->q;
10010 u8 id, hdr_len, unicast;
10011 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010012 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010013
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010014 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010015 switch (priv->ieee->iw_mode) {
10016 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010017 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010018 id = ipw_find_station(priv, hdr->addr1);
10019 if (id == IPW_INVALID_STATION) {
10020 id = ipw_add_station(priv, hdr->addr1);
10021 if (id == IPW_INVALID_STATION) {
10022 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -040010023 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010024 MAC_ARG(hdr->addr1));
10025 goto drop;
10026 }
10027 }
10028 break;
10029
10030 case IW_MODE_INFRA:
10031 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010032 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010033 id = 0;
10034 break;
10035 }
10036
10037 tfd = &txq->bd[q->first_empty];
10038 txq->txb[q->first_empty] = txb;
10039 memset(tfd, 0, sizeof(*tfd));
10040 tfd->u.data.station_number = id;
10041
10042 tfd->control_flags.message_type = TX_FRAME_TYPE;
10043 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10044
10045 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010046 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010047 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -040010048
James Ketrenos43f66a62005-03-25 12:31:53 -060010049 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010050 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010051 else
James Ketrenosb095c382005-08-24 22:04:42 -050010052 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010053
James Ketrenosea2b26e2005-08-24 21:25:16 -050010054 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10055 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010056
James Ketrenosc848d0a2005-08-24 21:56:24 -050010057 fc = le16_to_cpu(hdr->frame_ctl);
10058 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010059
10060 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10061
James Ketrenosb095c382005-08-24 22:04:42 -050010062 if (likely(unicast))
10063 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10064
10065 if (txb->encrypted && !priv->ieee->host_encrypt) {
10066 switch (priv->ieee->sec.level) {
10067 case SEC_LEVEL_3:
10068 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10069 IEEE80211_FCTL_PROTECTED;
10070 /* XXX: ACK flag must be set for CCMP even if it
10071 * is a multicast/broadcast packet, because CCMP
10072 * group communication encrypted by GTK is
10073 * actually done by the AP. */
10074 if (!unicast)
10075 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10076
10077 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10078 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10079 tfd->u.data.key_index = 0;
10080 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10081 break;
10082 case SEC_LEVEL_2:
10083 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10084 IEEE80211_FCTL_PROTECTED;
10085 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10086 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10087 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10088 break;
10089 case SEC_LEVEL_1:
10090 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10091 IEEE80211_FCTL_PROTECTED;
10092 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10093 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10094 40)
10095 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10096 else
10097 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10098 break;
10099 case SEC_LEVEL_0:
10100 break;
10101 default:
10102 printk(KERN_ERR "Unknow security level %d\n",
10103 priv->ieee->sec.level);
10104 break;
10105 }
10106 } else
10107 /* No hardware encryption */
10108 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10109
10110#ifdef CONFIG_IPW_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010111 if (fc & IEEE80211_STYPE_QOS_DATA)
10112 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
James Ketrenosb095c382005-08-24 22:04:42 -050010113#endif /* CONFIG_IPW_QOS */
10114
James Ketrenos43f66a62005-03-25 12:31:53 -060010115 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010116 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10117 txb->nr_frags));
10118 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10119 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10120 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10121 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10122 i, le32_to_cpu(tfd->u.data.num_chunks),
10123 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010124 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 i, tfd->u.data.num_chunks,
10126 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010127 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010128 txb->fragments[i]->len - hdr_len);
10129
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010130 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010131 cpu_to_le32(pci_map_single
10132 (priv->pci_dev,
10133 txb->fragments[i]->data + hdr_len,
10134 txb->fragments[i]->len - hdr_len,
10135 PCI_DMA_TODEVICE));
10136 tfd->u.data.chunk_len[i] =
10137 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 }
10139
10140 if (i != txb->nr_frags) {
10141 struct sk_buff *skb;
10142 u16 remaining_bytes = 0;
10143 int j;
10144
10145 for (j = i; j < txb->nr_frags; j++)
10146 remaining_bytes += txb->fragments[j]->len - hdr_len;
10147
10148 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10149 remaining_bytes);
10150 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10151 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010152 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010153 for (j = i; j < txb->nr_frags; j++) {
10154 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010155
James Ketrenos43f66a62005-03-25 12:31:53 -060010156 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010157 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010158 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010159 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010160 }
10161 dev_kfree_skb_any(txb->fragments[i]);
10162 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010163 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010164 cpu_to_le32(pci_map_single
10165 (priv->pci_dev, skb->data,
10166 tfd->u.data.chunk_len[i],
10167 PCI_DMA_TODEVICE));
10168
10169 tfd->u.data.num_chunks =
10170 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10171 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010172 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010173 }
10174
10175 /* kick DMA */
10176 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10177 ipw_write32(priv, q->reg_w, q->first_empty);
10178
James Ketrenosf6970142006-02-14 09:10:51 +080010179 if (ipw_queue_space(q) < q->high_mark)
10180 netif_stop_queue(priv->net_dev);
10181
James Ketrenos227d2dc2005-07-28 16:25:55 -050010182 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010183
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010184 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010185 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10186 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010187 return NETDEV_TX_OK;
10188}
10189
10190static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10191{
10192 struct ipw_priv *priv = ieee80211_priv(dev);
10193#ifdef CONFIG_IPW_QOS
10194 int tx_id = ipw_get_tx_queue_number(priv, pri);
10195 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10196#else
10197 struct clx2_tx_queue *txq = &priv->txq[0];
10198#endif /* CONFIG_IPW_QOS */
10199
10200 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10201 return 1;
10202
10203 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010204}
10205
Zhu Yid685b8c2006-04-13 17:20:27 +080010206#ifdef CONFIG_IPW2200_PROMISCUOUS
10207static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10208 struct ieee80211_txb *txb)
10209{
10210 struct ieee80211_rx_stats dummystats;
10211 struct ieee80211_hdr *hdr;
10212 u8 n;
10213 u16 filter = priv->prom_priv->filter;
10214 int hdr_only = 0;
10215
10216 if (filter & IPW_PROM_NO_TX)
10217 return;
10218
10219 memset(&dummystats, 0, sizeof(dummystats));
10220
10221 /* Filtering of fragment chains is done agains the first fragment */
10222 hdr = (void *)txb->fragments[0]->data;
10223 if (ieee80211_is_management(hdr->frame_ctl)) {
10224 if (filter & IPW_PROM_NO_MGMT)
10225 return;
10226 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10227 hdr_only = 1;
10228 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10229 if (filter & IPW_PROM_NO_CTL)
10230 return;
10231 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10232 hdr_only = 1;
10233 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10234 if (filter & IPW_PROM_NO_DATA)
10235 return;
10236 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10237 hdr_only = 1;
10238 }
10239
10240 for(n=0; n<txb->nr_frags; ++n) {
10241 struct sk_buff *src = txb->fragments[n];
10242 struct sk_buff *dst;
10243 struct ieee80211_radiotap_header *rt_hdr;
10244 int len;
10245
10246 if (hdr_only) {
10247 hdr = (void *)src->data;
10248 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10249 } else
10250 len = src->len;
10251
10252 dst = alloc_skb(
10253 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10254 if (!dst) continue;
10255
10256 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10257
10258 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10259 rt_hdr->it_pad = 0;
10260 rt_hdr->it_present = 0; /* after all, it's just an idea */
10261 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10262
10263 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10264 ieee80211chan2mhz(priv->channel));
10265 if (priv->channel > 14) /* 802.11a */
10266 *(u16*)skb_put(dst, sizeof(u16)) =
10267 cpu_to_le16(IEEE80211_CHAN_OFDM |
10268 IEEE80211_CHAN_5GHZ);
10269 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10270 *(u16*)skb_put(dst, sizeof(u16)) =
10271 cpu_to_le16(IEEE80211_CHAN_CCK |
10272 IEEE80211_CHAN_2GHZ);
10273 else /* 802.11g */
10274 *(u16*)skb_put(dst, sizeof(u16)) =
10275 cpu_to_le16(IEEE80211_CHAN_OFDM |
10276 IEEE80211_CHAN_2GHZ);
10277
10278 rt_hdr->it_len = dst->len;
10279
10280 memcpy(skb_put(dst, len), src->data, len);
10281
10282 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10283 dev_kfree_skb_any(dst);
10284 }
10285}
10286#endif
10287
James Ketrenos43f66a62005-03-25 12:31:53 -060010288static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010289 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010290{
10291 struct ipw_priv *priv = ieee80211_priv(dev);
10292 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010293 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010294
10295 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010296 spin_lock_irqsave(&priv->lock, flags);
10297
10298 if (!(priv->status & STATUS_ASSOCIATED)) {
10299 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10300 priv->ieee->stats.tx_carrier_errors++;
10301 netif_stop_queue(dev);
10302 goto fail_unlock;
10303 }
10304
Zhu Yid685b8c2006-04-13 17:20:27 +080010305#ifdef CONFIG_IPW2200_PROMISCUOUS
10306 if (rtap_iface && netif_running(priv->prom_net_dev))
10307 ipw_handle_promiscuous_tx(priv, txb);
10308#endif
10309
James Ketrenos227d2dc2005-07-28 16:25:55 -050010310 ret = ipw_tx_skb(priv, txb, pri);
10311 if (ret == NETDEV_TX_OK)
10312 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010313 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010314
James Ketrenos227d2dc2005-07-28 16:25:55 -050010315 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010316
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010317 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010318 spin_unlock_irqrestore(&priv->lock, flags);
10319 return 1;
10320}
10321
10322static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10323{
10324 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010325
James Ketrenos43f66a62005-03-25 12:31:53 -060010326 priv->ieee->stats.tx_packets = priv->tx_packets;
10327 priv->ieee->stats.rx_packets = priv->rx_packets;
10328 return &priv->ieee->stats;
10329}
10330
10331static void ipw_net_set_multicast_list(struct net_device *dev)
10332{
10333
10334}
10335
10336static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10337{
10338 struct ipw_priv *priv = ieee80211_priv(dev);
10339 struct sockaddr *addr = p;
10340 if (!is_valid_ether_addr(addr->sa_data))
10341 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010342 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010343 priv->config |= CFG_CUSTOM_MAC;
10344 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10345 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10346 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010347 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010348 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010349 return 0;
10350}
10351
Jeff Garzikbf794512005-07-31 13:07:26 -040010352static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010353 struct ethtool_drvinfo *info)
10354{
10355 struct ipw_priv *p = ieee80211_priv(dev);
10356 char vers[64];
10357 char date[32];
10358 u32 len;
10359
10360 strcpy(info->driver, DRV_NAME);
10361 strcpy(info->version, DRV_VERSION);
10362
10363 len = sizeof(vers);
10364 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10365 len = sizeof(date);
10366 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10367
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010368 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010369 vers, date);
10370 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010371 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010372}
10373
10374static u32 ipw_ethtool_get_link(struct net_device *dev)
10375{
10376 struct ipw_priv *priv = ieee80211_priv(dev);
10377 return (priv->status & STATUS_ASSOCIATED) != 0;
10378}
10379
10380static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10381{
James Ketrenosb095c382005-08-24 22:04:42 -050010382 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010383}
10384
10385static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010386 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010387{
10388 struct ipw_priv *p = ieee80211_priv(dev);
10389
James Ketrenosb095c382005-08-24 22:04:42 -050010390 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010391 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010392 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010393 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010394 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010395 return 0;
10396}
10397
10398static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010399 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010400{
10401 struct ipw_priv *p = ieee80211_priv(dev);
10402 int i;
10403
James Ketrenosb095c382005-08-24 22:04:42 -050010404 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010405 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010406 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010407 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010408 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10409 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010410 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010411 return 0;
10412}
10413
10414static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010415 .get_link = ipw_ethtool_get_link,
10416 .get_drvinfo = ipw_ethtool_get_drvinfo,
10417 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10418 .get_eeprom = ipw_ethtool_get_eeprom,
10419 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010420};
10421
10422static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10423{
10424 struct ipw_priv *priv = data;
10425 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010426
James Ketrenos43f66a62005-03-25 12:31:53 -060010427 if (!priv)
10428 return IRQ_NONE;
10429
10430 spin_lock(&priv->lock);
10431
10432 if (!(priv->status & STATUS_INT_ENABLED)) {
10433 /* Shared IRQ */
10434 goto none;
10435 }
10436
James Ketrenosb095c382005-08-24 22:04:42 -050010437 inta = ipw_read32(priv, IPW_INTA_RW);
10438 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010439
James Ketrenos43f66a62005-03-25 12:31:53 -060010440 if (inta == 0xFFFFFFFF) {
10441 /* Hardware disappeared */
10442 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10443 goto none;
10444 }
10445
James Ketrenosb095c382005-08-24 22:04:42 -050010446 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010447 /* Shared interrupt */
10448 goto none;
10449 }
10450
10451 /* tell the device to stop sending interrupts */
10452 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010453
James Ketrenos43f66a62005-03-25 12:31:53 -060010454 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010455 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10456 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010457
James Ketrenos43f66a62005-03-25 12:31:53 -060010458 /* Cache INTA value for our tasklet */
10459 priv->isr_inta = inta;
10460
10461 tasklet_schedule(&priv->irq_tasklet);
10462
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010463 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010464
10465 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010466 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010467 spin_unlock(&priv->lock);
10468 return IRQ_NONE;
10469}
10470
10471static void ipw_rf_kill(void *adapter)
10472{
10473 struct ipw_priv *priv = adapter;
10474 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010475
James Ketrenos43f66a62005-03-25 12:31:53 -060010476 spin_lock_irqsave(&priv->lock, flags);
10477
10478 if (rf_kill_active(priv)) {
10479 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10480 if (priv->workqueue)
10481 queue_delayed_work(priv->workqueue,
10482 &priv->rf_kill, 2 * HZ);
10483 goto exit_unlock;
10484 }
10485
10486 /* RF Kill is now disabled, so bring the device back up */
10487
10488 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10489 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10490 "device\n");
10491
10492 /* we can not do an adapter restart while inside an irq lock */
10493 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010494 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010495 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10496 "enabled\n");
10497
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010498 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010499 spin_unlock_irqrestore(&priv->lock, flags);
10500}
10501
James Ketrenosc848d0a2005-08-24 21:56:24 -050010502static void ipw_bg_rf_kill(void *data)
10503{
10504 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010505 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010506 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010507 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010508}
10509
Adrian Bunka73e22b2006-01-21 01:39:42 +010010510static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010511{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010512 priv->last_seq_num = -1;
10513 priv->last_frag_num = -1;
10514 priv->last_packet_time = 0;
10515
James Ketrenosa613bff2005-08-24 21:43:11 -050010516 netif_carrier_on(priv->net_dev);
10517 if (netif_queue_stopped(priv->net_dev)) {
10518 IPW_DEBUG_NOTIF("waking queue\n");
10519 netif_wake_queue(priv->net_dev);
10520 } else {
10521 IPW_DEBUG_NOTIF("starting queue\n");
10522 netif_start_queue(priv->net_dev);
10523 }
10524
James Ketrenosc848d0a2005-08-24 21:56:24 -050010525 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010526 ipw_reset_stats(priv);
10527 /* Ensure the rate is updated immediately */
10528 priv->last_rate = ipw_get_current_rate(priv);
10529 ipw_gather_stats(priv);
10530 ipw_led_link_up(priv);
10531 notify_wx_assoc_event(priv);
10532
10533 if (priv->config & CFG_BACKGROUND_SCAN)
10534 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10535}
10536
James Ketrenosc848d0a2005-08-24 21:56:24 -050010537static void ipw_bg_link_up(void *data)
10538{
10539 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010540 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010541 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010542 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010543}
10544
Adrian Bunka73e22b2006-01-21 01:39:42 +010010545static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010546{
10547 ipw_led_link_down(priv);
10548 netif_carrier_off(priv->net_dev);
10549 netif_stop_queue(priv->net_dev);
10550 notify_wx_assoc_event(priv);
10551
10552 /* Cancel any queued work ... */
10553 cancel_delayed_work(&priv->request_scan);
10554 cancel_delayed_work(&priv->adhoc_check);
10555 cancel_delayed_work(&priv->gather_stats);
10556
10557 ipw_reset_stats(priv);
10558
James Ketrenosafbf30a2005-08-25 00:05:33 -050010559 if (!(priv->status & STATUS_EXIT_PENDING)) {
10560 /* Queue up another scan... */
10561 queue_work(priv->workqueue, &priv->request_scan);
10562 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010563}
10564
James Ketrenosc848d0a2005-08-24 21:56:24 -050010565static void ipw_bg_link_down(void *data)
10566{
10567 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010568 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010569 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010570 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010571}
10572
James Ketrenos43f66a62005-03-25 12:31:53 -060010573static int ipw_setup_deferred_work(struct ipw_priv *priv)
10574{
10575 int ret = 0;
10576
James Ketrenos43f66a62005-03-25 12:31:53 -060010577 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010578 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010579 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010580
James Ketrenosc848d0a2005-08-24 21:56:24 -050010581 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10582 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10583 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010584 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010585 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10586 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10587 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10588 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10589 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010590 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010591 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010592 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010593 (void (*)(void *))ipw_bg_gather_stats, priv);
10594 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10595 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10596 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10597 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10598 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10599 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010600 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010601 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010602 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010603 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10604 priv);
10605 INIT_WORK(&priv->merge_networks,
10606 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010607
James Ketrenosb095c382005-08-24 22:04:42 -050010608#ifdef CONFIG_IPW_QOS
10609 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10610 priv);
10611#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010612
10613 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10614 ipw_irq_tasklet, (unsigned long)priv);
10615
10616 return ret;
10617}
10618
James Ketrenos43f66a62005-03-25 12:31:53 -060010619static void shim__set_security(struct net_device *dev,
10620 struct ieee80211_security *sec)
10621{
10622 struct ipw_priv *priv = ieee80211_priv(dev);
10623 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010624 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010625 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010626 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010627 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010628 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010629 priv->ieee->sec.flags &= ~(1 << i);
10630 else {
10631 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010632 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010633 priv->ieee->sec.flags |= (1 << i);
10634 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010635 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010636 } else if (sec->level != SEC_LEVEL_1)
10637 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010638 }
10639
James Ketrenosb095c382005-08-24 22:04:42 -050010640 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010641 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010642 priv->ieee->sec.active_key = sec->active_key;
10643 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010644 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010645 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010646 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010647 } else
10648 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010649
10650 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010651 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10652 priv->ieee->sec.auth_mode = sec->auth_mode;
10653 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010654 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10655 priv->capability |= CAP_SHARED_KEY;
10656 else
10657 priv->capability &= ~CAP_SHARED_KEY;
10658 priv->status |= STATUS_SECURITY_UPDATED;
10659 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010660
James Ketrenosb095c382005-08-24 22:04:42 -050010661 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10662 priv->ieee->sec.flags |= SEC_ENABLED;
10663 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010664 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010665 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010666 priv->capability |= CAP_PRIVACY_ON;
10667 else
10668 priv->capability &= ~CAP_PRIVACY_ON;
10669 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010670
James Ketrenosafbf30a2005-08-25 00:05:33 -050010671 if (sec->flags & SEC_ENCRYPT)
10672 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010673
James Ketrenosb095c382005-08-24 22:04:42 -050010674 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10675 priv->ieee->sec.level = sec->level;
10676 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010677 priv->status |= STATUS_SECURITY_UPDATED;
10678 }
10679
Zhu Yi1fbfea52005-08-05 17:22:56 +080010680 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10681 ipw_set_hwcrypto_keys(priv);
10682
Jeff Garzikbf794512005-07-31 13:07:26 -040010683 /* To match current functionality of ipw2100 (which works well w/
10684 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010685 * privacy capability changes ... */
10686#if 0
10687 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010688 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010689 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010690 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010691 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010692 IPW_DEBUG_ASSOC("Disassociating due to capability "
10693 "change.\n");
10694 ipw_disassociate(priv);
10695 }
10696#endif
10697}
10698
Jeff Garzikbf794512005-07-31 13:07:26 -040010699static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010700 struct ipw_supported_rates *rates)
10701{
10702 /* TODO: Mask out rates based on priv->rates_mask */
10703
10704 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010705 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010706 switch (priv->ieee->freq_band) {
10707 case IEEE80211_52GHZ_BAND:
10708 rates->ieee_mode = IPW_A_MODE;
10709 rates->purpose = IPW_RATE_CAPABILITIES;
10710 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10711 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10712 break;
10713
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010714 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010715 rates->ieee_mode = IPW_G_MODE;
10716 rates->purpose = IPW_RATE_CAPABILITIES;
10717 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10718 IEEE80211_CCK_DEFAULT_RATES_MASK);
10719 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10720 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10721 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10722 }
10723 break;
10724 }
10725
10726 return 0;
10727}
10728
Jeff Garzikbf794512005-07-31 13:07:26 -040010729static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010730{
James Ketrenos43f66a62005-03-25 12:31:53 -060010731 /* This is only called from ipw_up, which resets/reloads the firmware
10732 so, we don't need to first disable the card before we configure
10733 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010734 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010735 goto error;
10736
10737 /* initialize adapter address */
10738 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10739 goto error;
10740
10741 /* set basic system config settings */
10742 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010743
10744 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10745 * Does not support BT priority yet (don't abort or defer our Tx) */
10746 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010747 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010748
10749 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10750 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010751 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010752 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10753 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010754 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010755 }
10756
Zhu Yid685b8c2006-04-13 17:20:27 +080010757#ifdef CONFIG_IPW2200_PROMISCUOUS
10758 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10759 priv->sys_config.accept_all_data_frames = 1;
10760 priv->sys_config.accept_non_directed_frames = 1;
10761 priv->sys_config.accept_all_mgmt_bcpr = 1;
10762 priv->sys_config.accept_all_mgmt_frames = 1;
10763 }
10764#endif
10765
James Ketrenosc848d0a2005-08-24 21:56:24 -050010766 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10767 priv->sys_config.answer_broadcast_ssid_probe = 1;
10768 else
10769 priv->sys_config.answer_broadcast_ssid_probe = 0;
10770
Zhu Yid685b8c2006-04-13 17:20:27 +080010771 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010772 goto error;
10773
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010774 init_supported_rates(priv, &priv->rates);
10775 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010776 goto error;
10777
10778 /* Set request-to-send threshold */
10779 if (priv->rts_threshold) {
10780 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10781 goto error;
10782 }
James Ketrenosb095c382005-08-24 22:04:42 -050010783#ifdef CONFIG_IPW_QOS
10784 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10785 ipw_qos_activate(priv, NULL);
10786#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010787
10788 if (ipw_set_random_seed(priv))
10789 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010790
James Ketrenos43f66a62005-03-25 12:31:53 -060010791 /* final state transition to the RUN state */
10792 if (ipw_send_host_complete(priv))
10793 goto error;
10794
James Ketrenose6666192005-08-12 09:17:04 -050010795 priv->status |= STATUS_INIT;
10796
10797 ipw_led_init(priv);
10798 ipw_led_radio_on(priv);
10799 priv->notif_missed_beacons = 0;
10800
10801 /* Set hardware WEP key if it is configured. */
10802 if ((priv->capability & CAP_PRIVACY_ON) &&
10803 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10804 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10805 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010806
10807 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010808
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010809 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010810 return -EIO;
10811}
10812
James Ketrenos4f36f802005-08-03 20:36:56 -050010813/*
10814 * NOTE:
10815 *
10816 * These tables have been tested in conjunction with the
10817 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10818 *
10819 * Altering this values, using it on other hardware, or in geographies
10820 * not intended for resale of the above mentioned Intel adapters has
10821 * not been tested.
10822 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010823 * Remember to update the table in README.ipw2200 when changing this
10824 * table.
10825 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010826 */
10827static const struct ieee80211_geo ipw_geos[] = {
10828 { /* Restricted */
10829 "---",
10830 .bg_channels = 11,
10831 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10832 {2427, 4}, {2432, 5}, {2437, 6},
10833 {2442, 7}, {2447, 8}, {2452, 9},
10834 {2457, 10}, {2462, 11}},
10835 },
10836
10837 { /* Custom US/Canada */
10838 "ZZF",
10839 .bg_channels = 11,
10840 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10841 {2427, 4}, {2432, 5}, {2437, 6},
10842 {2442, 7}, {2447, 8}, {2452, 9},
10843 {2457, 10}, {2462, 11}},
10844 .a_channels = 8,
10845 .a = {{5180, 36},
10846 {5200, 40},
10847 {5220, 44},
10848 {5240, 48},
10849 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10850 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10851 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10852 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10853 },
10854
10855 { /* Rest of World */
10856 "ZZD",
10857 .bg_channels = 13,
10858 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10859 {2427, 4}, {2432, 5}, {2437, 6},
10860 {2442, 7}, {2447, 8}, {2452, 9},
10861 {2457, 10}, {2462, 11}, {2467, 12},
10862 {2472, 13}},
10863 },
10864
10865 { /* Custom USA & Europe & High */
10866 "ZZA",
10867 .bg_channels = 11,
10868 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10869 {2427, 4}, {2432, 5}, {2437, 6},
10870 {2442, 7}, {2447, 8}, {2452, 9},
10871 {2457, 10}, {2462, 11}},
10872 .a_channels = 13,
10873 .a = {{5180, 36},
10874 {5200, 40},
10875 {5220, 44},
10876 {5240, 48},
10877 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10878 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10879 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10880 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10881 {5745, 149},
10882 {5765, 153},
10883 {5785, 157},
10884 {5805, 161},
10885 {5825, 165}},
10886 },
10887
10888 { /* Custom NA & Europe */
10889 "ZZB",
10890 .bg_channels = 11,
10891 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10892 {2427, 4}, {2432, 5}, {2437, 6},
10893 {2442, 7}, {2447, 8}, {2452, 9},
10894 {2457, 10}, {2462, 11}},
10895 .a_channels = 13,
10896 .a = {{5180, 36},
10897 {5200, 40},
10898 {5220, 44},
10899 {5240, 48},
10900 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10901 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10902 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10903 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10904 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10905 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10906 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10907 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10908 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10909 },
10910
10911 { /* Custom Japan */
10912 "ZZC",
10913 .bg_channels = 11,
10914 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10915 {2427, 4}, {2432, 5}, {2437, 6},
10916 {2442, 7}, {2447, 8}, {2452, 9},
10917 {2457, 10}, {2462, 11}},
10918 .a_channels = 4,
10919 .a = {{5170, 34}, {5190, 38},
10920 {5210, 42}, {5230, 46}},
10921 },
10922
10923 { /* Custom */
10924 "ZZM",
10925 .bg_channels = 11,
10926 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10927 {2427, 4}, {2432, 5}, {2437, 6},
10928 {2442, 7}, {2447, 8}, {2452, 9},
10929 {2457, 10}, {2462, 11}},
10930 },
10931
10932 { /* Europe */
10933 "ZZE",
10934 .bg_channels = 13,
10935 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10936 {2427, 4}, {2432, 5}, {2437, 6},
10937 {2442, 7}, {2447, 8}, {2452, 9},
10938 {2457, 10}, {2462, 11}, {2467, 12},
10939 {2472, 13}},
10940 .a_channels = 19,
10941 .a = {{5180, 36},
10942 {5200, 40},
10943 {5220, 44},
10944 {5240, 48},
10945 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10946 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10947 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10948 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10949 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10950 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10951 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10952 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10953 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10954 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10955 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10956 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10957 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10958 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10959 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10960 },
10961
10962 { /* Custom Japan */
10963 "ZZJ",
10964 .bg_channels = 14,
10965 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10966 {2427, 4}, {2432, 5}, {2437, 6},
10967 {2442, 7}, {2447, 8}, {2452, 9},
10968 {2457, 10}, {2462, 11}, {2467, 12},
10969 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10970 .a_channels = 4,
10971 .a = {{5170, 34}, {5190, 38},
10972 {5210, 42}, {5230, 46}},
10973 },
10974
James Ketrenos03520572005-10-19 16:12:31 -050010975 { /* Rest of World */
10976 "ZZR",
10977 .bg_channels = 14,
10978 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10979 {2427, 4}, {2432, 5}, {2437, 6},
10980 {2442, 7}, {2447, 8}, {2452, 9},
10981 {2457, 10}, {2462, 11}, {2467, 12},
10982 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10983 IEEE80211_CH_PASSIVE_ONLY}},
10984 },
10985
James Ketrenos4f36f802005-08-03 20:36:56 -050010986 { /* High Band */
10987 "ZZH",
10988 .bg_channels = 13,
10989 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10990 {2427, 4}, {2432, 5}, {2437, 6},
10991 {2442, 7}, {2447, 8}, {2452, 9},
10992 {2457, 10}, {2462, 11},
10993 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10994 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10995 .a_channels = 4,
10996 .a = {{5745, 149}, {5765, 153},
10997 {5785, 157}, {5805, 161}},
10998 },
10999
11000 { /* Custom Europe */
11001 "ZZG",
11002 .bg_channels = 13,
11003 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11004 {2427, 4}, {2432, 5}, {2437, 6},
11005 {2442, 7}, {2447, 8}, {2452, 9},
11006 {2457, 10}, {2462, 11},
11007 {2467, 12}, {2472, 13}},
11008 .a_channels = 4,
11009 .a = {{5180, 36}, {5200, 40},
11010 {5220, 44}, {5240, 48}},
11011 },
11012
11013 { /* Europe */
11014 "ZZK",
11015 .bg_channels = 13,
11016 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11017 {2427, 4}, {2432, 5}, {2437, 6},
11018 {2442, 7}, {2447, 8}, {2452, 9},
11019 {2457, 10}, {2462, 11},
11020 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11021 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11022 .a_channels = 24,
11023 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11024 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11025 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11026 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11027 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11028 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11029 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11030 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11031 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11032 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11033 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11034 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11035 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11036 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11037 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11038 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11039 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11040 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11041 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11042 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11043 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11044 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11045 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11046 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11047 },
11048
11049 { /* Europe */
11050 "ZZL",
11051 .bg_channels = 11,
11052 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11053 {2427, 4}, {2432, 5}, {2437, 6},
11054 {2442, 7}, {2447, 8}, {2452, 9},
11055 {2457, 10}, {2462, 11}},
11056 .a_channels = 13,
11057 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11058 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11059 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11060 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11061 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11062 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11063 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11064 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11065 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11066 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11067 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11068 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11069 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11070 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011071};
11072
James Ketrenos43f66a62005-03-25 12:31:53 -060011073#define MAX_HW_RESTARTS 5
11074static int ipw_up(struct ipw_priv *priv)
11075{
James Ketrenos4f36f802005-08-03 20:36:56 -050011076 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011077
11078 if (priv->status & STATUS_EXIT_PENDING)
11079 return -EIO;
11080
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011081 if (cmdlog && !priv->cmdlog) {
11082 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11083 GFP_KERNEL);
11084 if (priv->cmdlog == NULL) {
11085 IPW_ERROR("Error allocating %d command log entries.\n",
11086 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011087 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011088 } else {
11089 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11090 priv->cmdlog_len = cmdlog;
11091 }
11092 }
11093
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011094 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011095 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011096 * Also start the clocks. */
11097 rc = ipw_load(priv);
11098 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011099 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011100 return rc;
11101 }
11102
11103 ipw_init_ordinals(priv);
11104 if (!(priv->config & CFG_CUSTOM_MAC))
11105 eeprom_parse_mac(priv, priv->mac_addr);
11106 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11107
James Ketrenos4f36f802005-08-03 20:36:56 -050011108 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11109 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11110 ipw_geos[j].name, 3))
11111 break;
11112 }
James Ketrenos03520572005-10-19 16:12:31 -050011113 if (j == ARRAY_SIZE(ipw_geos)) {
11114 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11115 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11116 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11117 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011118 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011119 }
Larry Finger1867b112006-02-28 09:48:28 -060011120 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011121 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011122 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011123 }
11124
James Ketrenosb095c382005-08-24 22:04:42 -050011125 if (priv->status & STATUS_RF_KILL_SW) {
11126 IPW_WARNING("Radio disabled by module parameter.\n");
11127 return 0;
11128 } else if (rf_kill_active(priv)) {
11129 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11130 "Kill switch must be turned off for "
11131 "wireless networking to work.\n");
11132 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11133 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011134 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011135 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011136
11137 rc = ipw_config(priv);
11138 if (!rc) {
11139 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011140
James Ketrenose6666192005-08-12 09:17:04 -050011141 /* If configure to try and auto-associate, kick
11142 * off a scan. */
11143 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011144
James Ketrenos43f66a62005-03-25 12:31:53 -060011145 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011146 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011147
James Ketrenosc848d0a2005-08-24 21:56:24 -050011148 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011149 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11150 i, MAX_HW_RESTARTS);
11151
11152 /* We had an error bringing up the hardware, so take it
11153 * all the way back down so we can try again */
11154 ipw_down(priv);
11155 }
11156
Jeff Garzikbf794512005-07-31 13:07:26 -040011157 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011158 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011159 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011160
James Ketrenos43f66a62005-03-25 12:31:53 -060011161 return -EIO;
11162}
11163
James Ketrenosc848d0a2005-08-24 21:56:24 -050011164static void ipw_bg_up(void *data)
11165{
11166 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011167 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011168 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080011169 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011170}
11171
James Ketrenosb095c382005-08-24 22:04:42 -050011172static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011173{
James Ketrenosb095c382005-08-24 22:04:42 -050011174 int i;
11175
11176 if (priv->status & STATUS_SCANNING) {
11177 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11178 ipw_abort_scan(priv);
11179 }
11180
11181 if (priv->status & STATUS_ASSOCIATED) {
11182 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11183 ipw_disassociate(priv);
11184 }
11185
11186 ipw_led_shutdown(priv);
11187
11188 /* Wait up to 1s for status to change to not scanning and not
11189 * associated (disassociation can take a while for a ful 802.11
11190 * exchange */
11191 for (i = 1000; i && (priv->status &
11192 (STATUS_DISASSOCIATING |
11193 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11194 udelay(10);
11195
11196 if (priv->status & (STATUS_DISASSOCIATING |
11197 STATUS_ASSOCIATED | STATUS_SCANNING))
11198 IPW_DEBUG_INFO("Still associated or scanning...\n");
11199 else
11200 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11201
James Ketrenosc848d0a2005-08-24 21:56:24 -050011202 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011203 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011204
11205 priv->status &= ~STATUS_INIT;
11206}
11207
James Ketrenos43f66a62005-03-25 12:31:53 -060011208static void ipw_down(struct ipw_priv *priv)
11209{
James Ketrenosb095c382005-08-24 22:04:42 -050011210 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11211
11212 priv->status |= STATUS_EXIT_PENDING;
11213
11214 if (ipw_is_init(priv))
11215 ipw_deinit(priv);
11216
11217 /* Wipe out the EXIT_PENDING status bit if we are not actually
11218 * exiting the module */
11219 if (!exit_pending)
11220 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011221
11222 /* tell the device to stop sending interrupts */
11223 ipw_disable_interrupts(priv);
11224
11225 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011226 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011227 netif_carrier_off(priv->net_dev);
11228 netif_stop_queue(priv->net_dev);
11229
11230 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011231
11232 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011233}
11234
James Ketrenosc848d0a2005-08-24 21:56:24 -050011235static void ipw_bg_down(void *data)
11236{
11237 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011238 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011239 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080011240 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011241}
11242
11243/* Called by register_netdev() */
11244static int ipw_net_init(struct net_device *dev)
11245{
11246 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011247 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011248
James Ketrenosc848d0a2005-08-24 21:56:24 -050011249 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080011250 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011251 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011252 }
11253
Zhu Yi46441512006-01-24 16:37:59 +080011254 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011255 return 0;
11256}
11257
11258/* PCI driver stuff */
11259static struct pci_device_id card_ids[] = {
11260 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11261 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11262 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11263 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11264 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11265 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11266 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11267 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11268 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11269 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11270 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11271 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11272 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11273 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11274 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11275 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11276 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11277 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011278 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011279 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011280 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11281 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011282
James Ketrenos43f66a62005-03-25 12:31:53 -060011283 /* required last entry */
11284 {0,}
11285};
11286
11287MODULE_DEVICE_TABLE(pci, card_ids);
11288
11289static struct attribute *ipw_sysfs_entries[] = {
11290 &dev_attr_rf_kill.attr,
11291 &dev_attr_direct_dword.attr,
11292 &dev_attr_indirect_byte.attr,
11293 &dev_attr_indirect_dword.attr,
11294 &dev_attr_mem_gpio_reg.attr,
11295 &dev_attr_command_event_reg.attr,
11296 &dev_attr_nic_type.attr,
11297 &dev_attr_status.attr,
11298 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011299 &dev_attr_error.attr,
11300 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011301 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011302 &dev_attr_eeprom_delay.attr,
11303 &dev_attr_ucode_version.attr,
11304 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011305 &dev_attr_scan_age.attr,
11306 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011307 &dev_attr_speed_scan.attr,
11308 &dev_attr_net_stats.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011309#ifdef CONFIG_IPW2200_PROMISCUOUS
11310 &dev_attr_rtap_iface.attr,
11311 &dev_attr_rtap_filter.attr,
11312#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011313 NULL
11314};
11315
11316static struct attribute_group ipw_attribute_group = {
11317 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011318 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011319};
11320
Zhu Yid685b8c2006-04-13 17:20:27 +080011321#ifdef CONFIG_IPW2200_PROMISCUOUS
11322static int ipw_prom_open(struct net_device *dev)
11323{
11324 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11325 struct ipw_priv *priv = prom_priv->priv;
11326
11327 IPW_DEBUG_INFO("prom dev->open\n");
11328 netif_carrier_off(dev);
11329 netif_stop_queue(dev);
11330
11331 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11332 priv->sys_config.accept_all_data_frames = 1;
11333 priv->sys_config.accept_non_directed_frames = 1;
11334 priv->sys_config.accept_all_mgmt_bcpr = 1;
11335 priv->sys_config.accept_all_mgmt_frames = 1;
11336
11337 ipw_send_system_config(priv);
11338 }
11339
11340 return 0;
11341}
11342
11343static int ipw_prom_stop(struct net_device *dev)
11344{
11345 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11346 struct ipw_priv *priv = prom_priv->priv;
11347
11348 IPW_DEBUG_INFO("prom dev->stop\n");
11349
11350 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11351 priv->sys_config.accept_all_data_frames = 0;
11352 priv->sys_config.accept_non_directed_frames = 0;
11353 priv->sys_config.accept_all_mgmt_bcpr = 0;
11354 priv->sys_config.accept_all_mgmt_frames = 0;
11355
11356 ipw_send_system_config(priv);
11357 }
11358
11359 return 0;
11360}
11361
11362static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11363{
11364 IPW_DEBUG_INFO("prom dev->xmit\n");
11365 netif_stop_queue(dev);
11366 return -EOPNOTSUPP;
11367}
11368
11369static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11370{
11371 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11372 return &prom_priv->ieee->stats;
11373}
11374
11375static int ipw_prom_alloc(struct ipw_priv *priv)
11376{
11377 int rc = 0;
11378
11379 if (priv->prom_net_dev)
11380 return -EPERM;
11381
11382 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11383 if (priv->prom_net_dev == NULL)
11384 return -ENOMEM;
11385
11386 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11387 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11388 priv->prom_priv->priv = priv;
11389
11390 strcpy(priv->prom_net_dev->name, "rtap%d");
11391
11392 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11393 priv->prom_net_dev->open = ipw_prom_open;
11394 priv->prom_net_dev->stop = ipw_prom_stop;
11395 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11396 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11397
11398 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11399
11400 rc = register_netdev(priv->prom_net_dev);
11401 if (rc) {
11402 free_ieee80211(priv->prom_net_dev);
11403 priv->prom_net_dev = NULL;
11404 return rc;
11405 }
11406
11407 return 0;
11408}
11409
11410static void ipw_prom_free(struct ipw_priv *priv)
11411{
11412 if (!priv->prom_net_dev)
11413 return;
11414
11415 unregister_netdev(priv->prom_net_dev);
11416 free_ieee80211(priv->prom_net_dev);
11417
11418 priv->prom_net_dev = NULL;
11419}
11420
11421#endif
11422
11423
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011424static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011425{
11426 int err = 0;
11427 struct net_device *net_dev;
11428 void __iomem *base;
11429 u32 length, val;
11430 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011431 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011432
11433 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11434 if (net_dev == NULL) {
11435 err = -ENOMEM;
11436 goto out;
11437 }
11438
11439 priv = ieee80211_priv(net_dev);
11440 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011441
James Ketrenos43f66a62005-03-25 12:31:53 -060011442 priv->net_dev = net_dev;
11443 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080011444#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011445 ipw_debug_level = debug;
11446#endif
11447 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011448 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11449 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011450
Zhu Yi46441512006-01-24 16:37:59 +080011451 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011452 if (pci_enable_device(pdev)) {
11453 err = -ENODEV;
11454 goto out_free_ieee80211;
11455 }
11456
11457 pci_set_master(pdev);
11458
Tobias Klauser0e08b442005-06-20 14:28:41 -070011459 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011460 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011461 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011462 if (err) {
11463 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11464 goto out_pci_disable_device;
11465 }
11466
11467 pci_set_drvdata(pdev, priv);
11468
11469 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011470 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011471 goto out_pci_disable_device;
11472
Jeff Garzikbf794512005-07-31 13:07:26 -040011473 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011474 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011475 pci_read_config_dword(pdev, 0x40, &val);
11476 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011477 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011478
James Ketrenos43f66a62005-03-25 12:31:53 -060011479 length = pci_resource_len(pdev, 0);
11480 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011481
James Ketrenos43f66a62005-03-25 12:31:53 -060011482 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11483 if (!base) {
11484 err = -ENODEV;
11485 goto out_pci_release_regions;
11486 }
11487
11488 priv->hw_base = base;
11489 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11490 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11491
11492 err = ipw_setup_deferred_work(priv);
11493 if (err) {
11494 IPW_ERROR("Unable to setup deferred work\n");
11495 goto out_iounmap;
11496 }
11497
James Ketrenosb095c382005-08-24 22:04:42 -050011498 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011499
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011500 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011501 if (err) {
11502 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11503 goto out_destroy_workqueue;
11504 }
11505
11506 SET_MODULE_OWNER(net_dev);
11507 SET_NETDEV_DEV(net_dev, &pdev->dev);
11508
Zhu Yi46441512006-01-24 16:37:59 +080011509 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011510
James Ketrenos43f66a62005-03-25 12:31:53 -060011511 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11512 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011513 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011514
James Ketrenosb095c382005-08-24 22:04:42 -050011515#ifdef CONFIG_IPW_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011516 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011517 priv->ieee->handle_probe_response = ipw_handle_beacon;
11518 priv->ieee->handle_beacon = ipw_handle_probe_response;
11519 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050011520#endif /* CONFIG_IPW_QOS */
11521
James Ketrenosc848d0a2005-08-24 21:56:24 -050011522 priv->ieee->perfect_rssi = -20;
11523 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011524
11525 net_dev->open = ipw_net_open;
11526 net_dev->stop = ipw_net_stop;
11527 net_dev->init = ipw_net_init;
11528 net_dev->get_stats = ipw_net_get_stats;
11529 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11530 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011531 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011532 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011533 net_dev->wireless_handlers = &ipw_wx_handler_def;
11534 net_dev->ethtool_ops = &ipw_ethtool_ops;
11535 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011536 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011537 net_dev->mem_start = pci_resource_start(pdev, 0);
11538 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11539
11540 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11541 if (err) {
11542 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011543 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011544 goto out_release_irq;
11545 }
11546
Zhu Yi46441512006-01-24 16:37:59 +080011547 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011548 err = register_netdev(net_dev);
11549 if (err) {
11550 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011551 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011552 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011553
Zhu Yid685b8c2006-04-13 17:20:27 +080011554#ifdef CONFIG_IPW2200_PROMISCUOUS
11555 if (rtap_iface) {
11556 err = ipw_prom_alloc(priv);
11557 if (err) {
11558 IPW_ERROR("Failed to register promiscuous network "
11559 "device (error %d).\n", err);
11560 unregister_netdev(priv->net_dev);
11561 goto out_remove_sysfs;
11562 }
11563 }
11564#endif
11565
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011566 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11567 "channels, %d 802.11a channels)\n",
11568 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11569 priv->ieee->geo.a_channels);
11570
James Ketrenos43f66a62005-03-25 12:31:53 -060011571 return 0;
11572
James Ketrenosa613bff2005-08-24 21:43:11 -050011573 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011574 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011575 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011576 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011577 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011578 destroy_workqueue(priv->workqueue);
11579 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011580 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011581 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011582 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011583 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011584 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011585 pci_disable_device(pdev);
11586 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011587 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011588 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011589 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011590 return err;
11591}
11592
11593static void ipw_pci_remove(struct pci_dev *pdev)
11594{
11595 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011596 struct list_head *p, *q;
11597 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011598
James Ketrenos43f66a62005-03-25 12:31:53 -060011599 if (!priv)
11600 return;
11601
Zhu Yi46441512006-01-24 16:37:59 +080011602 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011603
James Ketrenosafbf30a2005-08-25 00:05:33 -050011604 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011605 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011606 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11607
Zhu Yi46441512006-01-24 16:37:59 +080011608 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011609
11610 unregister_netdev(priv->net_dev);
11611
11612 if (priv->rxq) {
11613 ipw_rx_queue_free(priv, priv->rxq);
11614 priv->rxq = NULL;
11615 }
11616 ipw_tx_queue_free(priv);
11617
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011618 if (priv->cmdlog) {
11619 kfree(priv->cmdlog);
11620 priv->cmdlog = NULL;
11621 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011622 /* ipw_down will ensure that there is no more pending work
11623 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011624 cancel_delayed_work(&priv->adhoc_check);
11625 cancel_delayed_work(&priv->gather_stats);
11626 cancel_delayed_work(&priv->request_scan);
11627 cancel_delayed_work(&priv->rf_kill);
11628 cancel_delayed_work(&priv->scan_check);
11629 destroy_workqueue(priv->workqueue);
11630 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011631
James Ketrenosafbf30a2005-08-25 00:05:33 -050011632 /* Free MAC hash list for ADHOC */
11633 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11634 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011635 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011636 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011637 }
11638 }
11639
James Ketrenosb39860c2005-08-12 09:36:32 -050011640 if (priv->error) {
11641 ipw_free_error_log(priv->error);
11642 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011643 }
11644
Zhu Yid685b8c2006-04-13 17:20:27 +080011645#ifdef CONFIG_IPW2200_PROMISCUOUS
11646 ipw_prom_free(priv);
11647#endif
11648
James Ketrenos43f66a62005-03-25 12:31:53 -060011649 free_irq(pdev->irq, priv);
11650 iounmap(priv->hw_base);
11651 pci_release_regions(pdev);
11652 pci_disable_device(pdev);
11653 pci_set_drvdata(pdev, NULL);
11654 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011655 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011656}
11657
James Ketrenos43f66a62005-03-25 12:31:53 -060011658#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011659static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011660{
11661 struct ipw_priv *priv = pci_get_drvdata(pdev);
11662 struct net_device *dev = priv->net_dev;
11663
11664 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11665
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011666 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011667 ipw_down(priv);
11668
11669 /* Remove the PRESENT state of the device */
11670 netif_device_detach(dev);
11671
James Ketrenos43f66a62005-03-25 12:31:53 -060011672 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011673 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011674 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011675
James Ketrenos43f66a62005-03-25 12:31:53 -060011676 return 0;
11677}
11678
11679static int ipw_pci_resume(struct pci_dev *pdev)
11680{
11681 struct ipw_priv *priv = pci_get_drvdata(pdev);
11682 struct net_device *dev = priv->net_dev;
11683 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011684
James Ketrenos43f66a62005-03-25 12:31:53 -060011685 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11686
James Ketrenosea2b26e2005-08-24 21:25:16 -050011687 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011688 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011689 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011690
James Ketrenos43f66a62005-03-25 12:31:53 -060011691 /*
11692 * Suspend/Resume resets the PCI configuration space, so we have to
11693 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11694 * from interfering with C3 CPU state. pci_restore_state won't help
11695 * here since it only restores the first 64 bytes pci config header.
11696 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011697 pci_read_config_dword(pdev, 0x40, &val);
11698 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011699 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11700
11701 /* Set the device back into the PRESENT state; this will also wake
11702 * the queue of needed */
11703 netif_device_attach(dev);
11704
11705 /* Bring the device back up */
11706 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011707
James Ketrenos43f66a62005-03-25 12:31:53 -060011708 return 0;
11709}
11710#endif
11711
11712/* driver initialization stuff */
11713static struct pci_driver ipw_driver = {
11714 .name = DRV_NAME,
11715 .id_table = card_ids,
11716 .probe = ipw_pci_probe,
11717 .remove = __devexit_p(ipw_pci_remove),
11718#ifdef CONFIG_PM
11719 .suspend = ipw_pci_suspend,
11720 .resume = ipw_pci_resume,
11721#endif
11722};
11723
11724static int __init ipw_init(void)
11725{
11726 int ret;
11727
11728 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11729 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11730
11731 ret = pci_module_init(&ipw_driver);
11732 if (ret) {
11733 IPW_ERROR("Unable to initialize PCI module\n");
11734 return ret;
11735 }
11736
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011737 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011738 if (ret) {
11739 IPW_ERROR("Unable to create driver sysfs file\n");
11740 pci_unregister_driver(&ipw_driver);
11741 return ret;
11742 }
11743
11744 return ret;
11745}
11746
11747static void __exit ipw_exit(void)
11748{
11749 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11750 pci_unregister_driver(&ipw_driver);
11751}
11752
11753module_param(disable, int, 0444);
11754MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11755
11756module_param(associate, int, 0444);
11757MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11758
11759module_param(auto_create, int, 0444);
11760MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11761
James Ketrenosa613bff2005-08-24 21:43:11 -050011762module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011763MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011764
Zhu Yi3e1555b2006-03-06 05:48:37 +080011765#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011766module_param(debug, int, 0444);
11767MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011768#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011769
11770module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011771MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011772
Zhu Yid685b8c2006-04-13 17:20:27 +080011773#ifdef CONFIG_IPW2200_PROMISCUOUS
11774module_param(rtap_iface, int, 0444);
11775MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11776#endif
11777
James Ketrenosb095c382005-08-24 22:04:42 -050011778#ifdef CONFIG_IPW_QOS
11779module_param(qos_enable, int, 0444);
11780MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011781
James Ketrenosb095c382005-08-24 22:04:42 -050011782module_param(qos_burst_enable, int, 0444);
11783MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11784
11785module_param(qos_no_ack_mask, int, 0444);
11786MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11787
11788module_param(burst_duration_CCK, int, 0444);
11789MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11790
11791module_param(burst_duration_OFDM, int, 0444);
11792MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11793#endif /* CONFIG_IPW_QOS */
11794
11795#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011796module_param(mode, int, 0444);
11797MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11798#else
11799module_param(mode, int, 0444);
11800MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11801#endif
11802
Zhu Yi810dabd2006-01-24 16:36:59 +080011803module_param(bt_coexist, int, 0444);
11804MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11805
James Ketrenosb095c382005-08-24 22:04:42 -050011806module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011807MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011808
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011809module_param(cmdlog, int, 0444);
11810MODULE_PARM_DESC(cmdlog,
11811 "allocate a ring buffer for logging firmware commands");
11812
Zhu Yi4bfdb912006-01-24 16:37:16 +080011813module_param(roaming, int, 0444);
11814MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11815
Zhu Yid2b83e12006-04-13 17:19:36 +080011816module_param(antenna, int, 0444);
11817MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11818
James Ketrenos43f66a62005-03-25 12:31:53 -060011819module_exit(ipw_exit);
11820module_init(ipw_init);