blob: a3283caaa8729565dd1b03d06d077661e9ba87a7 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenosafbf30a2005-08-25 00:05:33 -05003 Copyright(c) 2003 - 2005 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"
34
James Ketrenosafbf30a2005-08-25 00:05:33 -050035#define IPW2200_VERSION "1.0.5"
James Ketrenos43f66a62005-03-25 12:31:53 -060036#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
James Ketrenos2b184d52005-08-03 20:33:14 -050037#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060038#define DRV_VERSION IPW2200_VERSION
39
James Ketrenosb095c382005-08-24 22:04:42 -050040#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
41
James Ketrenos43f66a62005-03-25 12:31:53 -060042MODULE_DESCRIPTION(DRV_DESCRIPTION);
43MODULE_VERSION(DRV_VERSION);
44MODULE_AUTHOR(DRV_COPYRIGHT);
45MODULE_LICENSE("GPL");
46
47static int debug = 0;
48static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060049static int mode = 0;
50
51static u32 ipw_debug_level;
52static int associate = 1;
53static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050054static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060055static int disable = 0;
James Ketrenosb095c382005-08-24 22:04:42 -050056static int hwcrypto = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060057static const char ipw_modes[] = {
58 'a', 'b', 'g', '?'
59};
60
James Ketrenosb095c382005-08-24 22:04:42 -050061#ifdef CONFIG_IPW_QOS
62static int qos_enable = 0;
63static int qos_burst_enable = 0;
64static int qos_no_ack_mask = 0;
65static int burst_duration_CCK = 0;
66static int burst_duration_OFDM = 0;
67
68static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
69 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
70 QOS_TX3_CW_MIN_OFDM},
71 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
72 QOS_TX3_CW_MAX_OFDM},
73 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
74 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
75 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
76 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
77};
78
79static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
80 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
81 QOS_TX3_CW_MIN_CCK},
82 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
83 QOS_TX3_CW_MAX_CCK},
84 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
85 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
86 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
87 QOS_TX3_TXOP_LIMIT_CCK}
88};
89
90static struct ieee80211_qos_parameters def_parameters_OFDM = {
91 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
92 DEF_TX3_CW_MIN_OFDM},
93 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
94 DEF_TX3_CW_MAX_OFDM},
95 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
96 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
97 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
98 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
99};
100
101static struct ieee80211_qos_parameters def_parameters_CCK = {
102 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
103 DEF_TX3_CW_MIN_CCK},
104 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
105 DEF_TX3_CW_MAX_CCK},
106 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
107 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
108 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
109 DEF_TX3_TXOP_LIMIT_CCK}
110};
111
112static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
113
114static int from_priority_to_tx_queue[] = {
115 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
116 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
117};
118
119static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
120
121static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
122 *qos_param);
123static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
124 *qos_param);
125#endif /* CONFIG_IPW_QOS */
126
127static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600128static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400129static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600130 struct clx2_tx_queue *txq, int qindex);
131static int ipw_queue_reset(struct ipw_priv *priv);
132
133static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
134 int len, int sync);
135
136static void ipw_tx_queue_free(struct ipw_priv *);
137
138static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
139static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
140static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600141static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500142static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600143static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500144static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600145static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400146static int init_supported_rates(struct ipw_priv *priv,
147 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500148static void ipw_set_hwcrypto_keys(struct ipw_priv *);
149static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600150
Jeff Garzikbf794512005-07-31 13:07:26 -0400151static char *snprint_line(char *buf, size_t count,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400152 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600153{
154 int out, i, j, l;
155 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400156
James Ketrenos43f66a62005-03-25 12:31:53 -0600157 out = snprintf(buf, count, "%08X", ofs);
158
159 for (l = 0, i = 0; i < 2; i++) {
160 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400161 for (j = 0; j < 8 && l < len; j++, l++)
162 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600163 data[(i * 8 + j)]);
164 for (; j < 8; j++)
165 out += snprintf(buf + out, count - out, " ");
166 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400167
James Ketrenos43f66a62005-03-25 12:31:53 -0600168 out += snprintf(buf + out, count - out, " ");
169 for (l = 0, i = 0; i < 2; i++) {
170 out += snprintf(buf + out, count - out, " ");
171 for (j = 0; j < 8 && l < len; j++, l++) {
172 c = data[(i * 8 + j)];
173 if (!isascii(c) || !isprint(c))
174 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400175
James Ketrenos43f66a62005-03-25 12:31:53 -0600176 out += snprintf(buf + out, count - out, "%c", c);
177 }
178
179 for (; j < 8; j++)
180 out += snprintf(buf + out, count - out, " ");
181 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400182
James Ketrenos43f66a62005-03-25 12:31:53 -0600183 return buf;
184}
185
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400186static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600187{
188 char line[81];
189 u32 ofs = 0;
190 if (!(ipw_debug_level & level))
191 return;
192
193 while (len) {
194 printk(KERN_DEBUG "%s\n",
Jeff Garzikbf794512005-07-31 13:07:26 -0400195 snprint_line(line, sizeof(line), &data[ofs],
James Ketrenos43f66a62005-03-25 12:31:53 -0600196 min(len, 16U), ofs));
197 ofs += 16;
198 len -= min(len, 16U);
199 }
200}
201
202static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
203#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
204
205static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
206#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
207
208static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
209static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
210{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400211 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
212 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600213 _ipw_write_reg8(a, b, c);
214}
215
216static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
217static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
218{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400219 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
220 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600221 _ipw_write_reg16(a, b, c);
222}
223
224static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
225static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
226{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400227 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
228 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600229 _ipw_write_reg32(a, b, c);
230}
231
232#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
233#define ipw_write8(ipw, ofs, val) \
234 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
235 _ipw_write8(ipw, ofs, val)
236
237#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
238#define ipw_write16(ipw, ofs, val) \
239 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
240 _ipw_write16(ipw, ofs, val)
241
242#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
243#define ipw_write32(ipw, ofs, val) \
244 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
245 _ipw_write32(ipw, ofs, val)
246
247#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400248static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
249{
250 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600251 return _ipw_read8(ipw, ofs);
252}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400253
James Ketrenos43f66a62005-03-25 12:31:53 -0600254#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
255
256#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400257static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
258{
259 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600260 return _ipw_read16(ipw, ofs);
261}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400262
James Ketrenos43f66a62005-03-25 12:31:53 -0600263#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
264
265#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400266static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
267{
268 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600269 return _ipw_read32(ipw, ofs);
270}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400271
James Ketrenos43f66a62005-03-25 12:31:53 -0600272#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
273
274static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
275#define ipw_read_indirect(a, b, c, d) \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500276 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenos43f66a62005-03-25 12:31:53 -0600277 _ipw_read_indirect(a, b, c, d)
278
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400279static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
280 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600281#define ipw_write_indirect(a, b, c, d) \
282 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500283 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600284
285/* indirect write s */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400286static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600287{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400288 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500289 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
290 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600291}
292
James Ketrenos43f66a62005-03-25 12:31:53 -0600293static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
294{
295 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500296 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
297 _ipw_write8(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600298}
299
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400300static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600301{
302 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500303 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
304 _ipw_write16(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600305}
306
307/* indirect read s */
308
309static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
310{
311 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500312 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600313 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500314 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600316}
317
318static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
319{
320 u32 value;
321
322 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
323
James Ketrenosb095c382005-08-24 22:04:42 -0500324 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
325 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
327 return value;
328}
329
330/* iterative/auto-increment 32 bit reads and writes */
331static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
332 int num)
333{
James Ketrenosb095c382005-08-24 22:04:42 -0500334 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -0600335 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600336 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400337
James Ketrenos43f66a62005-03-25 12:31:53 -0600338 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
339
James Ketrenosea2b26e2005-08-24 21:25:16 -0500340 if (num <= 0) {
341 return;
342 }
343
James Ketrenos43f66a62005-03-25 12:31:53 -0600344 /* Read the first nibble byte by byte */
345 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500346 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500347 /* Start reading at aligned_addr + dif_len */
348 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500349 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600350 aligned_addr += 4;
351 }
352
James Ketrenosb095c382005-08-24 22:04:42 -0500353 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500354 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500355 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400356
James Ketrenos43f66a62005-03-25 12:31:53 -0600357 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500358 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500359 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500360 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500361 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500362 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600363}
364
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400365static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600366 int num)
367{
James Ketrenosb095c382005-08-24 22:04:42 -0500368 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -0600369 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600370 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400371
James Ketrenos43f66a62005-03-25 12:31:53 -0600372 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400373
James Ketrenosea2b26e2005-08-24 21:25:16 -0500374 if (num <= 0) {
375 return;
376 }
377
James Ketrenos43f66a62005-03-25 12:31:53 -0600378 /* Write the first nibble byte by byte */
379 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500380 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500381 /* Start reading at aligned_addr + dif_len */
382 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500383 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600384 aligned_addr += 4;
385 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400386
James Ketrenosb095c382005-08-24 22:04:42 -0500387 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500388 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500389 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400390
James Ketrenos43f66a62005-03-25 12:31:53 -0600391 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500392 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500393 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500394 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500395 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500396 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600397}
398
Jeff Garzikbf794512005-07-31 13:07:26 -0400399static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600400 int num)
401{
402 memcpy_toio((priv->hw_base + addr), buf, num);
403}
404
405static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
406{
407 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
408}
409
410static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
411{
412 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
413}
414
415static inline void ipw_enable_interrupts(struct ipw_priv *priv)
416{
417 if (priv->status & STATUS_INT_ENABLED)
418 return;
419 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500420 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600421}
422
423static inline void ipw_disable_interrupts(struct ipw_priv *priv)
424{
425 if (!(priv->status & STATUS_INT_ENABLED))
426 return;
427 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500428 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600429}
430
James Ketrenosb39860c2005-08-12 09:36:32 -0500431#ifdef CONFIG_IPW_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600432static char *ipw_error_desc(u32 val)
433{
434 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400435 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600436 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400437 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600438 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400439 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600440 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400441 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600442 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400443 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500444 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400445 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500446 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400447 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500448 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400449 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500450 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400451 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500452 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400453 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500454 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400455 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500456 return "DMA_STATUS";
457 case IPW_FW_ERROR_DINO_ERROR:
458 return "DINO_ERROR";
459 case IPW_FW_ERROR_EEPROM_ERROR:
460 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400461 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500462 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400463 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500464 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400465 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500466 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600467 }
468}
469
James Ketrenosb39860c2005-08-12 09:36:32 -0500470static void ipw_dump_error_log(struct ipw_priv *priv,
471 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600472{
James Ketrenosb39860c2005-08-12 09:36:32 -0500473 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600474
James Ketrenosb39860c2005-08-12 09:36:32 -0500475 if (!error) {
476 IPW_ERROR("Error allocating and capturing error log. "
477 "Nothing to dump.\n");
478 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600479 }
480
James Ketrenosb39860c2005-08-12 09:36:32 -0500481 IPW_ERROR("Start IPW Error Log Dump:\n");
482 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
483 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600484
James Ketrenosb39860c2005-08-12 09:36:32 -0500485 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400486 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500487 ipw_error_desc(error->elem[i].desc),
488 error->elem[i].time,
489 error->elem[i].blink1,
490 error->elem[i].blink2,
491 error->elem[i].link1,
492 error->elem[i].link2, error->elem[i].data);
493 for (i = 0; i < error->log_len; i++)
494 IPW_ERROR("%i\t0x%08x\t%i\n",
495 error->log[i].time,
496 error->log[i].event, error->log[i].data);
James Ketrenos43f66a62005-03-25 12:31:53 -0600497}
James Ketrenos43f66a62005-03-25 12:31:53 -0600498#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600499
James Ketrenosc848d0a2005-08-24 21:56:24 -0500500static inline int ipw_is_init(struct ipw_priv *priv)
501{
502 return (priv->status & STATUS_INIT) ? 1 : 0;
503}
504
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400505static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600506{
507 u32 addr, field_info, field_len, field_count, total_len;
508
509 IPW_DEBUG_ORD("ordinal = %i\n", ord);
510
511 if (!priv || !val || !len) {
512 IPW_DEBUG_ORD("Invalid argument\n");
513 return -EINVAL;
514 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400515
James Ketrenos43f66a62005-03-25 12:31:53 -0600516 /* verify device ordinal tables have been initialized */
517 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
518 IPW_DEBUG_ORD("Access ordinals before initialization\n");
519 return -EINVAL;
520 }
521
522 switch (IPW_ORD_TABLE_ID_MASK & ord) {
523 case IPW_ORD_TABLE_0_MASK:
524 /*
525 * TABLE 0: Direct access to a table of 32 bit values
526 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400527 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600528 * read from the table
529 */
530
531 /* remove the table id from the ordinal */
532 ord &= IPW_ORD_TABLE_VALUE_MASK;
533
534 /* boundary check */
535 if (ord > priv->table0_len) {
536 IPW_DEBUG_ORD("ordinal value (%i) longer then "
537 "max (%i)\n", ord, priv->table0_len);
538 return -EINVAL;
539 }
540
541 /* verify we have enough room to store the value */
542 if (*len < sizeof(u32)) {
543 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200544 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600545 return -EINVAL;
546 }
547
548 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400549 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600550
551 *len = sizeof(u32);
552 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400553 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600554 break;
555
556 case IPW_ORD_TABLE_1_MASK:
557 /*
558 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400559 *
560 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600561 * representing starting addr for the data (which is
562 * also a u32)
563 */
564
565 /* remove the table id from the ordinal */
566 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400567
James Ketrenos43f66a62005-03-25 12:31:53 -0600568 /* boundary check */
569 if (ord > priv->table1_len) {
570 IPW_DEBUG_ORD("ordinal value too long\n");
571 return -EINVAL;
572 }
573
574 /* verify we have enough room to store the value */
575 if (*len < sizeof(u32)) {
576 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200577 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600578 return -EINVAL;
579 }
580
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400581 *((u32 *) val) =
582 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600583 *len = sizeof(u32);
584 break;
585
586 case IPW_ORD_TABLE_2_MASK:
587 /*
588 * TABLE 2: Indirect access to a table of variable sized values
589 *
590 * This table consist of six values, each containing
591 * - dword containing the starting offset of the data
592 * - dword containing the lengh in the first 16bits
593 * and the count in the second 16bits
594 */
595
596 /* remove the table id from the ordinal */
597 ord &= IPW_ORD_TABLE_VALUE_MASK;
598
599 /* boundary check */
600 if (ord > priv->table2_len) {
601 IPW_DEBUG_ORD("ordinal value too long\n");
602 return -EINVAL;
603 }
604
605 /* get the address of statistic */
606 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400607
608 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600609 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400610 field_info =
611 ipw_read_reg32(priv,
612 priv->table2_addr + (ord << 3) +
613 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400614
James Ketrenos43f66a62005-03-25 12:31:53 -0600615 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400616 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400617
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400619 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400620
James Ketrenos43f66a62005-03-25 12:31:53 -0600621 /* abort if not enought memory */
622 total_len = field_len * field_count;
623 if (total_len > *len) {
624 *len = total_len;
625 return -EINVAL;
626 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400627
James Ketrenos43f66a62005-03-25 12:31:53 -0600628 *len = total_len;
629 if (!total_len)
630 return 0;
631
632 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400633 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600634 addr, total_len, field_info);
635 ipw_read_indirect(priv, addr, val, total_len);
636 break;
637
638 default:
639 IPW_DEBUG_ORD("Invalid ordinal!\n");
640 return -EINVAL;
641
642 }
643
James Ketrenos43f66a62005-03-25 12:31:53 -0600644 return 0;
645}
646
647static void ipw_init_ordinals(struct ipw_priv *priv)
648{
649 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400650 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600651
652 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
653 priv->table0_addr, priv->table0_len);
654
655 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
656 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
657
658 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
659 priv->table1_addr, priv->table1_len);
660
661 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
662 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400663 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600664
665 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
666 priv->table2_addr, priv->table2_len);
667
668}
669
James Ketrenosa613bff2005-08-24 21:43:11 -0500670u32 ipw_register_toggle(u32 reg)
671{
James Ketrenosb095c382005-08-24 22:04:42 -0500672 reg &= ~IPW_START_STANDBY;
673 if (reg & IPW_GATE_ODMA)
674 reg &= ~IPW_GATE_ODMA;
675 if (reg & IPW_GATE_IDMA)
676 reg &= ~IPW_GATE_IDMA;
677 if (reg & IPW_GATE_ADMA)
678 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500679 return reg;
680}
681
682/*
683 * LED behavior:
684 * - On radio ON, turn on any LEDs that require to be on during start
685 * - On initialization, start unassociated blink
686 * - On association, disable unassociated blink
687 * - On disassociation, start unassociated blink
688 * - On radio OFF, turn off any LEDs started during radio on
689 *
690 */
691#define LD_TIME_LINK_ON 300
692#define LD_TIME_LINK_OFF 2700
693#define LD_TIME_ACT_ON 250
694
695void ipw_led_link_on(struct ipw_priv *priv)
696{
697 unsigned long flags;
698 u32 led;
699
700 /* If configured to not use LEDs, or nic_type is 1,
701 * then we don't toggle a LINK led */
702 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
703 return;
704
705 spin_lock_irqsave(&priv->lock, flags);
706
707 if (!(priv->status & STATUS_RF_KILL_MASK) &&
708 !(priv->status & STATUS_LED_LINK_ON)) {
709 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500710 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500711 led |= priv->led_association_on;
712
713 led = ipw_register_toggle(led);
714
715 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500716 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500717
718 priv->status |= STATUS_LED_LINK_ON;
719
720 /* If we aren't associated, schedule turning the LED off */
721 if (!(priv->status & STATUS_ASSOCIATED))
722 queue_delayed_work(priv->workqueue,
723 &priv->led_link_off,
724 LD_TIME_LINK_ON);
725 }
726
727 spin_unlock_irqrestore(&priv->lock, flags);
728}
729
James Ketrenosc848d0a2005-08-24 21:56:24 -0500730static void ipw_bg_led_link_on(void *data)
731{
732 struct ipw_priv *priv = data;
733 down(&priv->sem);
734 ipw_led_link_on(data);
735 up(&priv->sem);
736}
737
James Ketrenosa613bff2005-08-24 21:43:11 -0500738void ipw_led_link_off(struct ipw_priv *priv)
739{
740 unsigned long flags;
741 u32 led;
742
743 /* If configured not to use LEDs, or nic type is 1,
744 * then we don't goggle the LINK led. */
745 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
746 return;
747
748 spin_lock_irqsave(&priv->lock, flags);
749
750 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500751 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500752 led &= priv->led_association_off;
753 led = ipw_register_toggle(led);
754
755 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500756 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500757
758 IPW_DEBUG_LED("Link LED Off\n");
759
760 priv->status &= ~STATUS_LED_LINK_ON;
761
762 /* If we aren't associated and the radio is on, schedule
763 * turning the LED on (blink while unassociated) */
764 if (!(priv->status & STATUS_RF_KILL_MASK) &&
765 !(priv->status & STATUS_ASSOCIATED))
766 queue_delayed_work(priv->workqueue, &priv->led_link_on,
767 LD_TIME_LINK_OFF);
768
769 }
770
771 spin_unlock_irqrestore(&priv->lock, flags);
772}
773
James Ketrenosc848d0a2005-08-24 21:56:24 -0500774static void ipw_bg_led_link_off(void *data)
775{
776 struct ipw_priv *priv = data;
777 down(&priv->sem);
778 ipw_led_link_off(data);
779 up(&priv->sem);
780}
781
James Ketrenosb095c382005-08-24 22:04:42 -0500782static inline void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500783{
James Ketrenosa613bff2005-08-24 21:43:11 -0500784 u32 led;
785
786 if (priv->config & CFG_NO_LED)
787 return;
788
James Ketrenosb095c382005-08-24 22:04:42 -0500789 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500790 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500791
792 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500793 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500794 led |= priv->led_activity_on;
795
796 led = ipw_register_toggle(led);
797
798 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500799 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500800
801 IPW_DEBUG_LED("Activity LED On\n");
802
803 priv->status |= STATUS_LED_ACT_ON;
804
James Ketrenosc848d0a2005-08-24 21:56:24 -0500805 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500806 queue_delayed_work(priv->workqueue, &priv->led_act_off,
807 LD_TIME_ACT_ON);
808 } else {
809 /* Reschedule LED off for full time period */
810 cancel_delayed_work(&priv->led_act_off);
811 queue_delayed_work(priv->workqueue, &priv->led_act_off,
812 LD_TIME_ACT_ON);
813 }
James Ketrenosb095c382005-08-24 22:04:42 -0500814}
James Ketrenosa613bff2005-08-24 21:43:11 -0500815
James Ketrenosb095c382005-08-24 22:04:42 -0500816void ipw_led_activity_on(struct ipw_priv *priv)
817{
818 unsigned long flags;
819 spin_lock_irqsave(&priv->lock, flags);
820 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500821 spin_unlock_irqrestore(&priv->lock, flags);
822}
823
824void ipw_led_activity_off(struct ipw_priv *priv)
825{
826 unsigned long flags;
827 u32 led;
828
829 if (priv->config & CFG_NO_LED)
830 return;
831
832 spin_lock_irqsave(&priv->lock, flags);
833
834 if (priv->status & STATUS_LED_ACT_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_activity_off;
837
838 led = ipw_register_toggle(led);
839
840 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500841 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500842
843 IPW_DEBUG_LED("Activity LED Off\n");
844
845 priv->status &= ~STATUS_LED_ACT_ON;
846 }
847
848 spin_unlock_irqrestore(&priv->lock, flags);
849}
850
James Ketrenosc848d0a2005-08-24 21:56:24 -0500851static void ipw_bg_led_activity_off(void *data)
852{
853 struct ipw_priv *priv = data;
854 down(&priv->sem);
855 ipw_led_activity_off(data);
856 up(&priv->sem);
857}
858
James Ketrenosa613bff2005-08-24 21:43:11 -0500859void ipw_led_band_on(struct ipw_priv *priv)
860{
861 unsigned long flags;
862 u32 led;
863
864 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500865 if (priv->config & CFG_NO_LED ||
866 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500867 return;
868
869 spin_lock_irqsave(&priv->lock, flags);
870
James Ketrenosb095c382005-08-24 22:04:42 -0500871 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500872 if (priv->assoc_network->mode == IEEE_A) {
873 led |= priv->led_ofdm_on;
874 led &= priv->led_association_off;
875 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
876 } else if (priv->assoc_network->mode == IEEE_G) {
877 led |= priv->led_ofdm_on;
878 led |= priv->led_association_on;
879 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
880 } else {
881 led &= priv->led_ofdm_off;
882 led |= priv->led_association_on;
883 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
884 }
885
886 led = ipw_register_toggle(led);
887
888 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500889 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500890
891 spin_unlock_irqrestore(&priv->lock, flags);
892}
893
894void ipw_led_band_off(struct ipw_priv *priv)
895{
896 unsigned long flags;
897 u32 led;
898
899 /* Only nic type 1 supports mode LEDs */
900 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
901 return;
902
903 spin_lock_irqsave(&priv->lock, flags);
904
James Ketrenosb095c382005-08-24 22:04:42 -0500905 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500906 led &= priv->led_ofdm_off;
907 led &= priv->led_association_off;
908
909 led = ipw_register_toggle(led);
910
911 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500912 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500913
914 spin_unlock_irqrestore(&priv->lock, flags);
915}
916
917void ipw_led_radio_on(struct ipw_priv *priv)
918{
919 ipw_led_link_on(priv);
920}
921
922void ipw_led_radio_off(struct ipw_priv *priv)
923{
924 ipw_led_activity_off(priv);
925 ipw_led_link_off(priv);
926}
927
928void ipw_led_link_up(struct ipw_priv *priv)
929{
930 /* Set the Link Led on for all nic types */
931 ipw_led_link_on(priv);
932}
933
934void ipw_led_link_down(struct ipw_priv *priv)
935{
936 ipw_led_activity_off(priv);
937 ipw_led_link_off(priv);
938
939 if (priv->status & STATUS_RF_KILL_MASK)
940 ipw_led_radio_off(priv);
941}
942
943void ipw_led_init(struct ipw_priv *priv)
944{
945 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
946
947 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500948 priv->led_activity_on = IPW_ACTIVITY_LED;
949 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500950
James Ketrenosb095c382005-08-24 22:04:42 -0500951 priv->led_association_on = IPW_ASSOCIATED_LED;
952 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500953
954 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500955 priv->led_ofdm_on = IPW_OFDM_LED;
956 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500957
958 switch (priv->nic_type) {
959 case EEPROM_NIC_TYPE_1:
960 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -0500961 priv->led_activity_on = IPW_ASSOCIATED_LED;
962 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
963 priv->led_association_on = IPW_ACTIVITY_LED;
964 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500965
966 if (!(priv->config & CFG_NO_LED))
967 ipw_led_band_on(priv);
968
969 /* And we don't blink link LEDs for this nic, so
970 * just return here */
971 return;
972
973 case EEPROM_NIC_TYPE_3:
974 case EEPROM_NIC_TYPE_2:
975 case EEPROM_NIC_TYPE_4:
976 case EEPROM_NIC_TYPE_0:
977 break;
978
979 default:
980 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
981 priv->nic_type);
982 priv->nic_type = EEPROM_NIC_TYPE_0;
983 break;
984 }
985
986 if (!(priv->config & CFG_NO_LED)) {
987 if (priv->status & STATUS_ASSOCIATED)
988 ipw_led_link_on(priv);
989 else
990 ipw_led_link_off(priv);
991 }
992}
993
994void ipw_led_shutdown(struct ipw_priv *priv)
995{
James Ketrenosa613bff2005-08-24 21:43:11 -0500996 ipw_led_activity_off(priv);
997 ipw_led_link_off(priv);
998 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -0500999 cancel_delayed_work(&priv->led_link_on);
1000 cancel_delayed_work(&priv->led_link_off);
1001 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001002}
1003
James Ketrenos43f66a62005-03-25 12:31:53 -06001004/*
1005 * The following adds a new attribute to the sysfs representation
1006 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1007 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001008 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001009 * See the level definitions in ipw for details.
1010 */
1011static ssize_t show_debug_level(struct device_driver *d, char *buf)
1012{
1013 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1014}
James Ketrenosa613bff2005-08-24 21:43:11 -05001015
1016static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1017 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001018{
1019 char *p = (char *)buf;
1020 u32 val;
1021
1022 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1023 p++;
1024 if (p[0] == 'x' || p[0] == 'X')
1025 p++;
1026 val = simple_strtoul(p, &p, 16);
1027 } else
1028 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001029 if (p == buf)
1030 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001031 ": %s is not in hex or decimal form.\n", buf);
1032 else
1033 ipw_debug_level = val;
1034
1035 return strnlen(buf, count);
1036}
1037
Jeff Garzikbf794512005-07-31 13:07:26 -04001038static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001039 show_debug_level, store_debug_level);
1040
James Ketrenosb39860c2005-08-12 09:36:32 -05001041static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1042{
1043 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1044}
1045
1046static void ipw_capture_event_log(struct ipw_priv *priv,
1047 u32 log_len, struct ipw_event *log)
1048{
1049 u32 base;
1050
1051 if (log_len) {
1052 base = ipw_read32(priv, IPW_EVENT_LOG);
1053 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1054 (u8 *) log, sizeof(*log) * log_len);
1055 }
1056}
1057
1058static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1059{
1060 struct ipw_fw_error *error;
1061 u32 log_len = ipw_get_event_log_len(priv);
1062 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1063 u32 elem_len = ipw_read_reg32(priv, base);
1064
1065 error = kmalloc(sizeof(*error) +
1066 sizeof(*error->elem) * elem_len +
1067 sizeof(*error->log) * log_len, GFP_ATOMIC);
1068 if (!error) {
1069 IPW_ERROR("Memory allocation for firmware error log "
1070 "failed.\n");
1071 return NULL;
1072 }
1073 error->status = priv->status;
1074 error->config = priv->config;
1075 error->elem_len = elem_len;
1076 error->log_len = log_len;
1077 error->elem = (struct ipw_error_elem *)error->payload;
1078 error->log = (struct ipw_event *)(error->elem +
1079 (sizeof(*error->elem) * elem_len));
1080
1081 ipw_capture_event_log(priv, log_len, error->log);
1082
1083 if (elem_len)
1084 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1085 sizeof(*error->elem) * elem_len);
1086
1087 return error;
1088}
1089
1090static void ipw_free_error_log(struct ipw_fw_error *error)
1091{
1092 if (error)
1093 kfree(error);
1094}
1095
1096static ssize_t show_event_log(struct device *d,
1097 struct device_attribute *attr, char *buf)
1098{
1099 struct ipw_priv *priv = dev_get_drvdata(d);
1100 u32 log_len = ipw_get_event_log_len(priv);
1101 struct ipw_event log[log_len];
1102 u32 len = 0, i;
1103
1104 ipw_capture_event_log(priv, log_len, log);
1105
1106 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1107 for (i = 0; i < log_len; i++)
1108 len += snprintf(buf + len, PAGE_SIZE - len,
1109 "\n%08X%08X%08X",
1110 log[i].time, log[i].event, log[i].data);
1111 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1112 return len;
1113}
1114
1115static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1116
1117static ssize_t show_error(struct device *d,
1118 struct device_attribute *attr, char *buf)
1119{
1120 struct ipw_priv *priv = dev_get_drvdata(d);
1121 u32 len = 0, i;
1122 if (!priv->error)
1123 return 0;
1124 len += snprintf(buf + len, PAGE_SIZE - len,
1125 "%08X%08X%08X",
1126 priv->error->status,
1127 priv->error->config, priv->error->elem_len);
1128 for (i = 0; i < priv->error->elem_len; i++)
1129 len += snprintf(buf + len, PAGE_SIZE - len,
1130 "\n%08X%08X%08X%08X%08X%08X%08X",
1131 priv->error->elem[i].time,
1132 priv->error->elem[i].desc,
1133 priv->error->elem[i].blink1,
1134 priv->error->elem[i].blink2,
1135 priv->error->elem[i].link1,
1136 priv->error->elem[i].link2,
1137 priv->error->elem[i].data);
1138
1139 len += snprintf(buf + len, PAGE_SIZE - len,
1140 "\n%08X", priv->error->log_len);
1141 for (i = 0; i < priv->error->log_len; i++)
1142 len += snprintf(buf + len, PAGE_SIZE - len,
1143 "\n%08X%08X%08X",
1144 priv->error->log[i].time,
1145 priv->error->log[i].event,
1146 priv->error->log[i].data);
1147 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1148 return len;
1149}
1150
1151static ssize_t clear_error(struct device *d,
1152 struct device_attribute *attr,
1153 const char *buf, size_t count)
1154{
1155 struct ipw_priv *priv = dev_get_drvdata(d);
1156 if (priv->error) {
1157 ipw_free_error_log(priv->error);
1158 priv->error = NULL;
1159 }
1160 return count;
1161}
1162
1163static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1164
James Ketrenosa613bff2005-08-24 21:43:11 -05001165static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1166 char *buf)
1167{
1168 struct ipw_priv *priv = dev_get_drvdata(d);
1169 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1170}
1171
1172static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1173 const char *buf, size_t count)
1174{
1175 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001176#ifdef CONFIG_IPW_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001177 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001178#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001179 char buffer[] = "00000000";
1180 unsigned long len =
1181 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1182 unsigned long val;
1183 char *p = buffer;
1184
1185 IPW_DEBUG_INFO("enter\n");
1186
1187 strncpy(buffer, buf, len);
1188 buffer[len] = 0;
1189
1190 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1191 p++;
1192 if (p[0] == 'x' || p[0] == 'X')
1193 p++;
1194 val = simple_strtoul(p, &p, 16);
1195 } else
1196 val = simple_strtoul(p, &p, 10);
1197 if (p == buffer) {
1198 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1199 } else {
1200 priv->ieee->scan_age = val;
1201 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1202 }
1203
1204 IPW_DEBUG_INFO("exit\n");
1205 return len;
1206}
1207
1208static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1209
1210static ssize_t show_led(struct device *d, struct device_attribute *attr,
1211 char *buf)
1212{
1213 struct ipw_priv *priv = dev_get_drvdata(d);
1214 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1215}
1216
1217static ssize_t store_led(struct device *d, struct device_attribute *attr,
1218 const char *buf, size_t count)
1219{
1220 struct ipw_priv *priv = dev_get_drvdata(d);
1221
1222 IPW_DEBUG_INFO("enter\n");
1223
1224 if (count == 0)
1225 return 0;
1226
1227 if (*buf == 0) {
1228 IPW_DEBUG_LED("Disabling LED control.\n");
1229 priv->config |= CFG_NO_LED;
1230 ipw_led_shutdown(priv);
1231 } else {
1232 IPW_DEBUG_LED("Enabling LED control.\n");
1233 priv->config &= ~CFG_NO_LED;
1234 ipw_led_init(priv);
1235 }
1236
1237 IPW_DEBUG_INFO("exit\n");
1238 return count;
1239}
1240
1241static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1242
Andrew Mortonad3fee52005-06-20 14:30:36 -07001243static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001244 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001245{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001246 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001247 return sprintf(buf, "0x%08x\n", (int)p->status);
1248}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001249
James Ketrenos43f66a62005-03-25 12:31:53 -06001250static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1251
Andrew Mortonad3fee52005-06-20 14:30:36 -07001252static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1253 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001254{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001255 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001256 return sprintf(buf, "0x%08x\n", (int)p->config);
1257}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001258
James Ketrenos43f66a62005-03-25 12:31:53 -06001259static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1260
Andrew Mortonad3fee52005-06-20 14:30:36 -07001261static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001262 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001263{
James Ketrenosa613bff2005-08-24 21:43:11 -05001264 struct ipw_priv *priv = d->driver_data;
1265 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001266}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001267
James Ketrenos43f66a62005-03-25 12:31:53 -06001268static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1269
Andrew Mortonad3fee52005-06-20 14:30:36 -07001270static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001271 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001272{
1273 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001274 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001275
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001276 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001277 return 0;
1278
1279 return sprintf(buf, "0x%08x\n", tmp);
1280}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001281
1282static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001283
Andrew Mortonad3fee52005-06-20 14:30:36 -07001284static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1285 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001286{
1287 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001288 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001289
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001290 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001291 return 0;
1292
1293 return sprintf(buf, "0x%08x\n", tmp);
1294}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001295
1296static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001297
1298/*
1299 * Add a device attribute to view/control the delay between eeprom
1300 * operations.
1301 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001302static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001303 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001304{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001305 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001306 return sprintf(buf, "%i\n", n);
1307}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001308static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001309 struct device_attribute *attr,
1310 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001311{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001312 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001313 sscanf(buf, "%i", &p->eeprom_delay);
1314 return strnlen(buf, count);
1315}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001316
1317static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1318 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001319
Andrew Mortonad3fee52005-06-20 14:30:36 -07001320static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001321 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001322{
1323 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001324 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001325
James Ketrenosb095c382005-08-24 22:04:42 -05001326 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001327 return sprintf(buf, "0x%08x\n", reg);
1328}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001329static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001330 struct device_attribute *attr,
1331 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001332{
1333 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001334 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001335
1336 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001337 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001338 return strnlen(buf, count);
1339}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001340
1341static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1342 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001343
Andrew Mortonad3fee52005-06-20 14:30:36 -07001344static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001345 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001346{
1347 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001348 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001349
1350 reg = ipw_read_reg32(p, 0x301100);
1351 return sprintf(buf, "0x%08x\n", reg);
1352}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001353static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001354 struct device_attribute *attr,
1355 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001356{
1357 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001358 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001359
1360 sscanf(buf, "%x", &reg);
1361 ipw_write_reg32(p, 0x301100, reg);
1362 return strnlen(buf, count);
1363}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001364
1365static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1366 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001367
Andrew Mortonad3fee52005-06-20 14:30:36 -07001368static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001369 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001370{
1371 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001372 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001373
Jeff Garzikbf794512005-07-31 13:07:26 -04001374 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001375 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001376 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001377 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001378
James Ketrenos43f66a62005-03-25 12:31:53 -06001379 return sprintf(buf, "0x%08x\n", reg);
1380}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001381static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001382 struct device_attribute *attr,
1383 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001384{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001385 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001386
1387 sscanf(buf, "%x", &priv->indirect_dword);
1388 priv->status |= STATUS_INDIRECT_DWORD;
1389 return strnlen(buf, count);
1390}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001391
1392static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1393 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001394
Andrew Mortonad3fee52005-06-20 14:30:36 -07001395static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001396 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001397{
1398 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001399 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001400
Jeff Garzikbf794512005-07-31 13:07:26 -04001401 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001402 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001403 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001404 reg = 0;
1405
1406 return sprintf(buf, "0x%02x\n", reg);
1407}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001408static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001409 struct device_attribute *attr,
1410 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001411{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001412 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001413
1414 sscanf(buf, "%x", &priv->indirect_byte);
1415 priv->status |= STATUS_INDIRECT_BYTE;
1416 return strnlen(buf, count);
1417}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001418
1419static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001420 show_indirect_byte, store_indirect_byte);
1421
Andrew Mortonad3fee52005-06-20 14:30:36 -07001422static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001423 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001424{
1425 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001426 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001427
Jeff Garzikbf794512005-07-31 13:07:26 -04001428 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001429 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001430 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001431 reg = 0;
1432
1433 return sprintf(buf, "0x%08x\n", reg);
1434}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001435static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001436 struct device_attribute *attr,
1437 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001438{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001439 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001440
1441 sscanf(buf, "%x", &priv->direct_dword);
1442 priv->status |= STATUS_DIRECT_DWORD;
1443 return strnlen(buf, count);
1444}
James Ketrenos43f66a62005-03-25 12:31:53 -06001445
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001446static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1447 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001448
1449static inline int rf_kill_active(struct ipw_priv *priv)
1450{
1451 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1452 priv->status |= STATUS_RF_KILL_HW;
1453 else
1454 priv->status &= ~STATUS_RF_KILL_HW;
1455
1456 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1457}
1458
Andrew Mortonad3fee52005-06-20 14:30:36 -07001459static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001460 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001461{
1462 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001463 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001464 2 - HW based RF kill active
1465 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001466 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001467 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001468 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001469 return sprintf(buf, "%i\n", val);
1470}
1471
1472static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1473{
Jeff Garzikbf794512005-07-31 13:07:26 -04001474 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001475 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001476 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001477
1478 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1479 disable_radio ? "OFF" : "ON");
1480
1481 if (disable_radio) {
1482 priv->status |= STATUS_RF_KILL_SW;
1483
James Ketrenosa613bff2005-08-24 21:43:11 -05001484 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001485 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001486 queue_work(priv->workqueue, &priv->down);
1487 } else {
1488 priv->status &= ~STATUS_RF_KILL_SW;
1489 if (rf_kill_active(priv)) {
1490 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1491 "disabled by HW switch\n");
1492 /* Make sure the RF_KILL check timer is running */
1493 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001494 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001495 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001496 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001497 queue_work(priv->workqueue, &priv->up);
1498 }
1499
1500 return 1;
1501}
1502
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001503static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1504 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001505{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001506 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001507
James Ketrenos43f66a62005-03-25 12:31:53 -06001508 ipw_radio_kill_sw(priv, buf[0] == '1');
1509
1510 return count;
1511}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001512
1513static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001514
James Ketrenosb095c382005-08-24 22:04:42 -05001515static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1516 char *buf)
1517{
1518 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1519 int pos = 0, len = 0;
1520 if (priv->config & CFG_SPEED_SCAN) {
1521 while (priv->speed_scan[pos] != 0)
1522 len += sprintf(&buf[len], "%d ",
1523 priv->speed_scan[pos++]);
1524 return len + sprintf(&buf[len], "\n");
1525 }
1526
1527 return sprintf(buf, "0\n");
1528}
1529
1530static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1531 const char *buf, size_t count)
1532{
1533 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1534 int channel, pos = 0;
1535 const char *p = buf;
1536
1537 /* list of space separated channels to scan, optionally ending with 0 */
1538 while ((channel = simple_strtol(p, NULL, 0))) {
1539 if (pos == MAX_SPEED_SCAN - 1) {
1540 priv->speed_scan[pos] = 0;
1541 break;
1542 }
1543
1544 if (ieee80211_is_valid_channel(priv->ieee, channel))
1545 priv->speed_scan[pos++] = channel;
1546 else
1547 IPW_WARNING("Skipping invalid channel request: %d\n",
1548 channel);
1549 p = strchr(p, ' ');
1550 if (!p)
1551 break;
1552 while (*p == ' ' || *p == '\t')
1553 p++;
1554 }
1555
1556 if (pos == 0)
1557 priv->config &= ~CFG_SPEED_SCAN;
1558 else {
1559 priv->speed_scan_pos = 0;
1560 priv->config |= CFG_SPEED_SCAN;
1561 }
1562
1563 return count;
1564}
1565
1566static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1567 store_speed_scan);
1568
1569static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1570 char *buf)
1571{
1572 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1573 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1574}
1575
1576static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1577 const char *buf, size_t count)
1578{
1579 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1580 if (buf[0] == '1')
1581 priv->config |= CFG_NET_STATS;
1582 else
1583 priv->config &= ~CFG_NET_STATS;
1584
1585 return count;
1586}
1587
James Ketrenosafbf30a2005-08-25 00:05:33 -05001588static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1589 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001590
James Ketrenosea2b26e2005-08-24 21:25:16 -05001591static void notify_wx_assoc_event(struct ipw_priv *priv)
1592{
1593 union iwreq_data wrqu;
1594 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1595 if (priv->status & STATUS_ASSOCIATED)
1596 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1597 else
1598 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1599 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1600}
1601
James Ketrenos43f66a62005-03-25 12:31:53 -06001602static void ipw_irq_tasklet(struct ipw_priv *priv)
1603{
1604 u32 inta, inta_mask, handled = 0;
1605 unsigned long flags;
1606 int rc = 0;
1607
1608 spin_lock_irqsave(&priv->lock, flags);
1609
James Ketrenosb095c382005-08-24 22:04:42 -05001610 inta = ipw_read32(priv, IPW_INTA_RW);
1611 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1612 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001613
1614 /* Add any cached INTA values that need to be handled */
1615 inta |= priv->isr_inta;
1616
1617 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001618 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001619 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001620 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001621 }
1622
James Ketrenosb095c382005-08-24 22:04:42 -05001623 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001624 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001625 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001626 priv->status &= ~STATUS_HCMD_ACTIVE;
1627 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001628 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001629 }
1630
James Ketrenosb095c382005-08-24 22:04:42 -05001631 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001632 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001633 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001634 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001635 }
1636
James Ketrenosb095c382005-08-24 22:04:42 -05001637 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001638 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001639 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001640 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001641 }
1642
James Ketrenosb095c382005-08-24 22:04:42 -05001643 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001644 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001645 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001646 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001647 }
1648
James Ketrenosb095c382005-08-24 22:04:42 -05001649 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001650 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001651 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001652 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001653 }
1654
James Ketrenosb095c382005-08-24 22:04:42 -05001655 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001656 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001657 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001658 }
1659
James Ketrenosb095c382005-08-24 22:04:42 -05001660 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001661 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001662 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001663 }
1664
James Ketrenosb095c382005-08-24 22:04:42 -05001665 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001666 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001667 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001668 }
1669
James Ketrenosb095c382005-08-24 22:04:42 -05001670 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001671 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001672 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001673 }
1674
James Ketrenosb095c382005-08-24 22:04:42 -05001675 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001676 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001677 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001678 }
1679
James Ketrenosb095c382005-08-24 22:04:42 -05001680 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001681 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1682 priv->status |= STATUS_RF_KILL_HW;
1683 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001684 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001685 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001686 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001687 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001688 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001689 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001690
James Ketrenosb095c382005-08-24 22:04:42 -05001691 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001692 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001693 if (priv->error) {
1694 IPW_ERROR("Sysfs 'error' log already exists.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06001695#ifdef CONFIG_IPW_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001696 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1697 struct ipw_fw_error *error =
1698 ipw_alloc_error_log(priv);
1699 ipw_dump_error_log(priv, error);
1700 if (error)
1701 ipw_free_error_log(error);
1702 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001703#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001704 } else {
1705 priv->error = ipw_alloc_error_log(priv);
1706 if (priv->error)
1707 IPW_ERROR("Sysfs 'error' log captured.\n");
1708 else
1709 IPW_ERROR("Error allocating sysfs 'error' "
1710 "log.\n");
1711#ifdef CONFIG_IPW_DEBUG
1712 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1713 ipw_dump_error_log(priv, priv->error);
1714#endif
1715 }
1716
James Ketrenosb095c382005-08-24 22:04:42 -05001717 /* XXX: If hardware encryption is for WPA/WPA2,
1718 * we have to notify the supplicant. */
1719 if (priv->ieee->sec.encrypt) {
1720 priv->status &= ~STATUS_ASSOCIATED;
1721 notify_wx_assoc_event(priv);
1722 }
1723
1724 /* Keep the restart process from trying to send host
1725 * commands by clearing the INIT status bit */
1726 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001727
1728 /* Cancel currently queued command. */
1729 priv->status &= ~STATUS_HCMD_ACTIVE;
1730 wake_up_interruptible(&priv->wait_command_queue);
1731
James Ketrenos43f66a62005-03-25 12:31:53 -06001732 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001733 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001734 }
1735
James Ketrenosb095c382005-08-24 22:04:42 -05001736 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001737 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001738 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 }
1740
1741 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001742 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001743 }
1744
1745 /* enable all interrupts */
1746 ipw_enable_interrupts(priv);
1747
1748 spin_unlock_irqrestore(&priv->lock, flags);
1749}
Jeff Garzikbf794512005-07-31 13:07:26 -04001750
James Ketrenos43f66a62005-03-25 12:31:53 -06001751#ifdef CONFIG_IPW_DEBUG
1752#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1753static char *get_cmd_string(u8 cmd)
1754{
1755 switch (cmd) {
1756 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001757 IPW_CMD(POWER_DOWN);
1758 IPW_CMD(SYSTEM_CONFIG);
1759 IPW_CMD(MULTICAST_ADDRESS);
1760 IPW_CMD(SSID);
1761 IPW_CMD(ADAPTER_ADDRESS);
1762 IPW_CMD(PORT_TYPE);
1763 IPW_CMD(RTS_THRESHOLD);
1764 IPW_CMD(FRAG_THRESHOLD);
1765 IPW_CMD(POWER_MODE);
1766 IPW_CMD(WEP_KEY);
1767 IPW_CMD(TGI_TX_KEY);
1768 IPW_CMD(SCAN_REQUEST);
1769 IPW_CMD(SCAN_REQUEST_EXT);
1770 IPW_CMD(ASSOCIATE);
1771 IPW_CMD(SUPPORTED_RATES);
1772 IPW_CMD(SCAN_ABORT);
1773 IPW_CMD(TX_FLUSH);
1774 IPW_CMD(QOS_PARAMETERS);
1775 IPW_CMD(DINO_CONFIG);
1776 IPW_CMD(RSN_CAPABILITIES);
1777 IPW_CMD(RX_KEY);
1778 IPW_CMD(CARD_DISABLE);
1779 IPW_CMD(SEED_NUMBER);
1780 IPW_CMD(TX_POWER);
1781 IPW_CMD(COUNTRY_INFO);
1782 IPW_CMD(AIRONET_INFO);
1783 IPW_CMD(AP_TX_POWER);
1784 IPW_CMD(CCKM_INFO);
1785 IPW_CMD(CCX_VER_INFO);
1786 IPW_CMD(SET_CALIBRATION);
1787 IPW_CMD(SENSITIVITY_CALIB);
1788 IPW_CMD(RETRY_LIMIT);
1789 IPW_CMD(IPW_PRE_POWER_DOWN);
1790 IPW_CMD(VAP_BEACON_TEMPLATE);
1791 IPW_CMD(VAP_DTIM_PERIOD);
1792 IPW_CMD(EXT_SUPPORTED_RATES);
1793 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1794 IPW_CMD(VAP_QUIET_INTERVALS);
1795 IPW_CMD(VAP_CHANNEL_SWITCH);
1796 IPW_CMD(VAP_MANDATORY_CHANNELS);
1797 IPW_CMD(VAP_CELL_PWR_LIMIT);
1798 IPW_CMD(VAP_CF_PARAM_SET);
1799 IPW_CMD(VAP_SET_BEACONING_STATE);
1800 IPW_CMD(MEASUREMENT);
1801 IPW_CMD(POWER_CAPABILITY);
1802 IPW_CMD(SUPPORTED_CHANNELS);
1803 IPW_CMD(TPC_REPORT);
1804 IPW_CMD(WME_INFO);
1805 IPW_CMD(PRODUCTION_COMMAND);
1806 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001807 return "UNKNOWN";
1808 }
1809}
James Ketrenosea2b26e2005-08-24 21:25:16 -05001810#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06001811
1812#define HOST_COMPLETE_TIMEOUT HZ
1813static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1814{
1815 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001816 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001817
James Ketrenosa613bff2005-08-24 21:43:11 -05001818 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001819 if (priv->status & STATUS_HCMD_ACTIVE) {
1820 IPW_ERROR("Already sending a command\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05001821 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001822 return -1;
1823 }
1824
1825 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001826
James Ketrenosb095c382005-08-24 22:04:42 -05001827 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1828 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1829 priv->status);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001830 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001831
1832 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001833 if (rc) {
1834 priv->status &= ~STATUS_HCMD_ACTIVE;
1835 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001836 return rc;
James Ketrenosa613bff2005-08-24 21:43:11 -05001837 }
1838 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001839
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001840 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1841 !(priv->
1842 status & STATUS_HCMD_ACTIVE),
1843 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001844 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001845 spin_lock_irqsave(&priv->lock, flags);
1846 if (priv->status & STATUS_HCMD_ACTIVE) {
1847 IPW_DEBUG_INFO("Command completion failed out after "
1848 "%dms.\n",
1849 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
1850 priv->status &= ~STATUS_HCMD_ACTIVE;
1851 spin_unlock_irqrestore(&priv->lock, flags);
1852 return -EIO;
1853 }
1854 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001855 }
James Ketrenosa613bff2005-08-24 21:43:11 -05001856
James Ketrenosb095c382005-08-24 22:04:42 -05001857 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001858 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1859 return -EIO;
1860 }
1861
1862 return 0;
1863}
1864
1865static int ipw_send_host_complete(struct ipw_priv *priv)
1866{
1867 struct host_cmd cmd = {
1868 .cmd = IPW_CMD_HOST_COMPLETE,
1869 .len = 0
1870 };
1871
1872 if (!priv) {
1873 IPW_ERROR("Invalid args\n");
1874 return -1;
1875 }
1876
1877 if (ipw_send_cmd(priv, &cmd)) {
1878 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1879 return -1;
1880 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001881
James Ketrenos43f66a62005-03-25 12:31:53 -06001882 return 0;
1883}
1884
Jeff Garzikbf794512005-07-31 13:07:26 -04001885static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001886 struct ipw_sys_config *config)
1887{
1888 struct host_cmd cmd = {
1889 .cmd = IPW_CMD_SYSTEM_CONFIG,
1890 .len = sizeof(*config)
1891 };
1892
1893 if (!priv || !config) {
1894 IPW_ERROR("Invalid args\n");
1895 return -1;
1896 }
1897
James Ketrenosafbf30a2005-08-25 00:05:33 -05001898 memcpy(cmd.param, config, sizeof(*config));
James Ketrenos43f66a62005-03-25 12:31:53 -06001899 if (ipw_send_cmd(priv, &cmd)) {
1900 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1901 return -1;
1902 }
1903
1904 return 0;
1905}
1906
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001907static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001908{
1909 struct host_cmd cmd = {
1910 .cmd = IPW_CMD_SSID,
1911 .len = min(len, IW_ESSID_MAX_SIZE)
1912 };
1913
1914 if (!priv || !ssid) {
1915 IPW_ERROR("Invalid args\n");
1916 return -1;
1917 }
1918
James Ketrenosafbf30a2005-08-25 00:05:33 -05001919 memcpy(cmd.param, ssid, cmd.len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001920 if (ipw_send_cmd(priv, &cmd)) {
1921 IPW_ERROR("failed to send SSID command\n");
1922 return -1;
1923 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001924
James Ketrenos43f66a62005-03-25 12:31:53 -06001925 return 0;
1926}
1927
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001928static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001929{
1930 struct host_cmd cmd = {
1931 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1932 .len = ETH_ALEN
1933 };
1934
1935 if (!priv || !mac) {
1936 IPW_ERROR("Invalid args\n");
1937 return -1;
1938 }
1939
1940 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1941 priv->net_dev->name, MAC_ARG(mac));
1942
James Ketrenosafbf30a2005-08-25 00:05:33 -05001943 memcpy(cmd.param, mac, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06001944 if (ipw_send_cmd(priv, &cmd)) {
1945 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1946 return -1;
1947 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001948
James Ketrenos43f66a62005-03-25 12:31:53 -06001949 return 0;
1950}
1951
James Ketrenosa613bff2005-08-24 21:43:11 -05001952/*
1953 * NOTE: This must be executed from our workqueue as it results in udelay
1954 * being called which may corrupt the keyboard if executed on default
1955 * workqueue
1956 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001957static void ipw_adapter_restart(void *adapter)
1958{
1959 struct ipw_priv *priv = adapter;
1960
1961 if (priv->status & STATUS_RF_KILL_MASK)
1962 return;
1963
1964 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001965
1966 if (priv->assoc_network &&
1967 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
1968 ipw_remove_current_network(priv);
1969
James Ketrenos43f66a62005-03-25 12:31:53 -06001970 if (ipw_up(priv)) {
1971 IPW_ERROR("Failed to up device\n");
1972 return;
1973 }
1974}
1975
James Ketrenosc848d0a2005-08-24 21:56:24 -05001976static void ipw_bg_adapter_restart(void *data)
1977{
1978 struct ipw_priv *priv = data;
1979 down(&priv->sem);
1980 ipw_adapter_restart(data);
1981 up(&priv->sem);
1982}
1983
James Ketrenos43f66a62005-03-25 12:31:53 -06001984#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1985
1986static void ipw_scan_check(void *data)
1987{
1988 struct ipw_priv *priv = data;
1989 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1990 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001991 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 IPW_SCAN_CHECK_WATCHDOG / 100);
James Ketrenosa613bff2005-08-24 21:43:11 -05001993 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 }
1995}
1996
James Ketrenosc848d0a2005-08-24 21:56:24 -05001997static void ipw_bg_scan_check(void *data)
1998{
1999 struct ipw_priv *priv = data;
2000 down(&priv->sem);
2001 ipw_scan_check(data);
2002 up(&priv->sem);
2003}
2004
James Ketrenos43f66a62005-03-25 12:31:53 -06002005static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2006 struct ipw_scan_request_ext *request)
2007{
2008 struct host_cmd cmd = {
2009 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
2010 .len = sizeof(*request)
2011 };
2012
James Ketrenosafbf30a2005-08-25 00:05:33 -05002013 memcpy(cmd.param, request, sizeof(*request));
James Ketrenos43f66a62005-03-25 12:31:53 -06002014 if (ipw_send_cmd(priv, &cmd)) {
2015 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
2016 return -1;
2017 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002018
James Ketrenos43f66a62005-03-25 12:31:53 -06002019 return 0;
2020}
2021
2022static int ipw_send_scan_abort(struct ipw_priv *priv)
2023{
2024 struct host_cmd cmd = {
2025 .cmd = IPW_CMD_SCAN_ABORT,
2026 .len = 0
2027 };
2028
2029 if (!priv) {
2030 IPW_ERROR("Invalid args\n");
2031 return -1;
2032 }
2033
2034 if (ipw_send_cmd(priv, &cmd)) {
2035 IPW_ERROR("failed to send SCAN_ABORT command\n");
2036 return -1;
2037 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002038
James Ketrenos43f66a62005-03-25 12:31:53 -06002039 return 0;
2040}
2041
2042static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2043{
2044 struct host_cmd cmd = {
2045 .cmd = IPW_CMD_SENSITIVITY_CALIB,
2046 .len = sizeof(struct ipw_sensitivity_calib)
2047 };
2048 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002049 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002050 calib->beacon_rssi_raw = sens;
2051 if (ipw_send_cmd(priv, &cmd)) {
2052 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
2053 return -1;
2054 }
2055
2056 return 0;
2057}
2058
2059static int ipw_send_associate(struct ipw_priv *priv,
2060 struct ipw_associate *associate)
2061{
2062 struct host_cmd cmd = {
2063 .cmd = IPW_CMD_ASSOCIATE,
2064 .len = sizeof(*associate)
2065 };
2066
James Ketrenosa613bff2005-08-24 21:43:11 -05002067 struct ipw_associate tmp_associate;
2068 memcpy(&tmp_associate, associate, sizeof(*associate));
2069 tmp_associate.policy_support =
2070 cpu_to_le16(tmp_associate.policy_support);
2071 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2072 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2073 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2074 tmp_associate.listen_interval =
2075 cpu_to_le16(tmp_associate.listen_interval);
2076 tmp_associate.beacon_interval =
2077 cpu_to_le16(tmp_associate.beacon_interval);
2078 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2079
James Ketrenos43f66a62005-03-25 12:31:53 -06002080 if (!priv || !associate) {
2081 IPW_ERROR("Invalid args\n");
2082 return -1;
2083 }
2084
James Ketrenosafbf30a2005-08-25 00:05:33 -05002085 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06002086 if (ipw_send_cmd(priv, &cmd)) {
2087 IPW_ERROR("failed to send ASSOCIATE command\n");
2088 return -1;
2089 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002090
James Ketrenos43f66a62005-03-25 12:31:53 -06002091 return 0;
2092}
2093
2094static int ipw_send_supported_rates(struct ipw_priv *priv,
2095 struct ipw_supported_rates *rates)
2096{
2097 struct host_cmd cmd = {
2098 .cmd = IPW_CMD_SUPPORTED_RATES,
2099 .len = sizeof(*rates)
2100 };
2101
2102 if (!priv || !rates) {
2103 IPW_ERROR("Invalid args\n");
2104 return -1;
2105 }
2106
James Ketrenosafbf30a2005-08-25 00:05:33 -05002107 memcpy(cmd.param, rates, sizeof(*rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06002108 if (ipw_send_cmd(priv, &cmd)) {
2109 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
2110 return -1;
2111 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002112
James Ketrenos43f66a62005-03-25 12:31:53 -06002113 return 0;
2114}
2115
2116static int ipw_set_random_seed(struct ipw_priv *priv)
2117{
2118 struct host_cmd cmd = {
2119 .cmd = IPW_CMD_SEED_NUMBER,
2120 .len = sizeof(u32)
2121 };
2122
2123 if (!priv) {
2124 IPW_ERROR("Invalid args\n");
2125 return -1;
2126 }
2127
2128 get_random_bytes(&cmd.param, sizeof(u32));
2129
2130 if (ipw_send_cmd(priv, &cmd)) {
2131 IPW_ERROR("failed to send SEED_NUMBER command\n");
2132 return -1;
2133 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002134
James Ketrenos43f66a62005-03-25 12:31:53 -06002135 return 0;
2136}
2137
James Ketrenos43f66a62005-03-25 12:31:53 -06002138static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2139{
2140 struct host_cmd cmd = {
2141 .cmd = IPW_CMD_CARD_DISABLE,
2142 .len = sizeof(u32)
2143 };
2144
2145 if (!priv) {
2146 IPW_ERROR("Invalid args\n");
2147 return -1;
2148 }
2149
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002150 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06002151
2152 if (ipw_send_cmd(priv, &cmd)) {
2153 IPW_ERROR("failed to send CARD_DISABLE command\n");
2154 return -1;
2155 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002156
James Ketrenos43f66a62005-03-25 12:31:53 -06002157 return 0;
2158}
James Ketrenos43f66a62005-03-25 12:31:53 -06002159
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002160static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002161{
2162 struct host_cmd cmd = {
2163 .cmd = IPW_CMD_TX_POWER,
2164 .len = sizeof(*power)
2165 };
2166
2167 if (!priv || !power) {
2168 IPW_ERROR("Invalid args\n");
2169 return -1;
2170 }
2171
James Ketrenosafbf30a2005-08-25 00:05:33 -05002172 memcpy(cmd.param, power, sizeof(*power));
James Ketrenos43f66a62005-03-25 12:31:53 -06002173 if (ipw_send_cmd(priv, &cmd)) {
2174 IPW_ERROR("failed to send TX_POWER command\n");
2175 return -1;
2176 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002177
James Ketrenos43f66a62005-03-25 12:31:53 -06002178 return 0;
2179}
2180
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002181static int ipw_set_tx_power(struct ipw_priv *priv)
2182{
2183 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2184 struct ipw_tx_power tx_power;
2185 s8 max_power;
2186 int i;
2187
2188 memset(&tx_power, 0, sizeof(tx_power));
2189
2190 /* configure device for 'G' band */
2191 tx_power.ieee_mode = IPW_G_MODE;
2192 tx_power.num_channels = geo->bg_channels;
2193 for (i = 0; i < geo->bg_channels; i++) {
2194 max_power = geo->bg[i].max_power;
2195 tx_power.channels_tx_power[i].channel_number =
2196 geo->bg[i].channel;
2197 tx_power.channels_tx_power[i].tx_power = max_power ?
2198 min(max_power, priv->tx_power) : priv->tx_power;
2199 }
2200 if (ipw_send_tx_power(priv, &tx_power))
2201 return -EIO;
2202
2203 /* configure device to also handle 'B' band */
2204 tx_power.ieee_mode = IPW_B_MODE;
2205 if (ipw_send_tx_power(priv, &tx_power))
2206 return -EIO;
2207
2208 /* configure device to also handle 'A' band */
2209 if (priv->ieee->abg_true) {
2210 tx_power.ieee_mode = IPW_A_MODE;
2211 tx_power.num_channels = geo->a_channels;
2212 for (i = 0; i < tx_power.num_channels; i++) {
2213 max_power = geo->a[i].max_power;
2214 tx_power.channels_tx_power[i].channel_number =
2215 geo->a[i].channel;
2216 tx_power.channels_tx_power[i].tx_power = max_power ?
2217 min(max_power, priv->tx_power) : priv->tx_power;
2218 }
2219 if (ipw_send_tx_power(priv, &tx_power))
2220 return -EIO;
2221 }
2222 return 0;
2223}
2224
James Ketrenos43f66a62005-03-25 12:31:53 -06002225static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2226{
2227 struct ipw_rts_threshold rts_threshold = {
2228 .rts_threshold = rts,
2229 };
2230 struct host_cmd cmd = {
2231 .cmd = IPW_CMD_RTS_THRESHOLD,
2232 .len = sizeof(rts_threshold)
2233 };
2234
2235 if (!priv) {
2236 IPW_ERROR("Invalid args\n");
2237 return -1;
2238 }
2239
James Ketrenosafbf30a2005-08-25 00:05:33 -05002240 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002241 if (ipw_send_cmd(priv, &cmd)) {
2242 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
2243 return -1;
2244 }
2245
2246 return 0;
2247}
2248
2249static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2250{
2251 struct ipw_frag_threshold frag_threshold = {
2252 .frag_threshold = frag,
2253 };
2254 struct host_cmd cmd = {
2255 .cmd = IPW_CMD_FRAG_THRESHOLD,
2256 .len = sizeof(frag_threshold)
2257 };
2258
2259 if (!priv) {
2260 IPW_ERROR("Invalid args\n");
2261 return -1;
2262 }
2263
James Ketrenosafbf30a2005-08-25 00:05:33 -05002264 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002265 if (ipw_send_cmd(priv, &cmd)) {
2266 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
2267 return -1;
2268 }
2269
2270 return 0;
2271}
2272
2273static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2274{
2275 struct host_cmd cmd = {
2276 .cmd = IPW_CMD_POWER_MODE,
2277 .len = sizeof(u32)
2278 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002279 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002280
2281 if (!priv) {
2282 IPW_ERROR("Invalid args\n");
2283 return -1;
2284 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002285
James Ketrenos43f66a62005-03-25 12:31:53 -06002286 /* If on battery, set to 3, if AC set to CAM, else user
2287 * level */
2288 switch (mode) {
2289 case IPW_POWER_BATTERY:
2290 *param = IPW_POWER_INDEX_3;
2291 break;
2292 case IPW_POWER_AC:
2293 *param = IPW_POWER_MODE_CAM;
2294 break;
2295 default:
2296 *param = mode;
2297 break;
2298 }
2299
2300 if (ipw_send_cmd(priv, &cmd)) {
2301 IPW_ERROR("failed to send POWER_MODE command\n");
2302 return -1;
2303 }
2304
2305 return 0;
2306}
2307
James Ketrenosafbf30a2005-08-25 00:05:33 -05002308static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2309{
2310 struct ipw_retry_limit retry_limit = {
2311 .short_retry_limit = slimit,
2312 .long_retry_limit = llimit
2313 };
2314 struct host_cmd cmd = {
2315 .cmd = IPW_CMD_RETRY_LIMIT,
2316 .len = sizeof(retry_limit)
2317 };
2318
2319 if (!priv) {
2320 IPW_ERROR("Invalid args\n");
2321 return -1;
2322 }
2323
2324 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
2325 if (ipw_send_cmd(priv, &cmd)) {
2326 IPW_ERROR("failed to send RETRY_LIMIT command\n");
2327 return -1;
2328 }
2329
2330 return 0;
2331}
2332
James Ketrenos43f66a62005-03-25 12:31:53 -06002333/*
2334 * The IPW device contains a Microwire compatible EEPROM that stores
2335 * various data like the MAC address. Usually the firmware has exclusive
2336 * access to the eeprom, but during device initialization (before the
2337 * device driver has sent the HostComplete command to the firmware) the
2338 * device driver has read access to the EEPROM by way of indirect addressing
2339 * through a couple of memory mapped registers.
2340 *
2341 * The following is a simplified implementation for pulling data out of the
2342 * the eeprom, along with some helper functions to find information in
2343 * the per device private data's copy of the eeprom.
2344 *
2345 * NOTE: To better understand how these functions work (i.e what is a chip
2346 * select and why do have to keep driving the eeprom clock?), read
2347 * just about any data sheet for a Microwire compatible EEPROM.
2348 */
2349
2350/* write a 32 bit value into the indirect accessor register */
2351static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2352{
2353 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002354
James Ketrenos43f66a62005-03-25 12:31:53 -06002355 /* the eeprom requires some time to complete the operation */
2356 udelay(p->eeprom_delay);
2357
2358 return;
2359}
2360
2361/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002362static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002363{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002364 eeprom_write_reg(priv, 0);
2365 eeprom_write_reg(priv, EEPROM_BIT_CS);
2366 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2367 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002368}
2369
2370/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002371static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002372{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002373 eeprom_write_reg(priv, EEPROM_BIT_CS);
2374 eeprom_write_reg(priv, 0);
2375 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002376}
2377
2378/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002379static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002380{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002381 int d = (bit ? EEPROM_BIT_DI : 0);
2382 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2383 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002384}
2385
2386/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002387static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002388{
2389 int i;
2390
2391 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002392 eeprom_write_bit(priv, 1);
2393 eeprom_write_bit(priv, op & 2);
2394 eeprom_write_bit(priv, op & 1);
2395 for (i = 7; i >= 0; i--) {
2396 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002397 }
2398}
2399
2400/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002401static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002402{
2403 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002404 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002405
James Ketrenos43f66a62005-03-25 12:31:53 -06002406 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002407 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002408
2409 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002410 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002411
2412 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002413 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002414 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002415 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2416 eeprom_write_reg(priv, EEPROM_BIT_CS);
2417 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2418 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002419 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002420
James Ketrenos43f66a62005-03-25 12:31:53 -06002421 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002422 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002424
James Ketrenos43f66a62005-03-25 12:31:53 -06002425 return r;
2426}
2427
2428/* helper function for pulling the mac address out of the private */
2429/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002430static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002431{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002432 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002433}
2434
2435/*
2436 * Either the device driver (i.e. the host) or the firmware can
2437 * load eeprom data into the designated region in SRAM. If neither
2438 * happens then the FW will shutdown with a fatal error.
2439 *
2440 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2441 * bit needs region of shared SRAM needs to be non-zero.
2442 */
2443static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2444{
2445 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002446 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002447
James Ketrenos43f66a62005-03-25 12:31:53 -06002448 IPW_DEBUG_TRACE(">>\n");
2449
2450 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002451 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002452 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002453
Jeff Garzikbf794512005-07-31 13:07:26 -04002454 /*
2455 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002456 copy. Otherwise let the firmware know to perform the operation
2457 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002458 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002459 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2460 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2461
2462 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002463 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002464 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002465
2466 /* Do not load eeprom data on fatal error or suspend */
2467 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2468 } else {
2469 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2470
2471 /* Load eeprom data on fatal error or suspend */
2472 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2473 }
2474
2475 IPW_DEBUG_TRACE("<<\n");
2476}
2477
James Ketrenos43f66a62005-03-25 12:31:53 -06002478static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2479{
2480 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002481 if (!count)
2482 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002483 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002484 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002485 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002486}
2487
2488static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2489{
James Ketrenosb095c382005-08-24 22:04:42 -05002490 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002491 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002492 sizeof(struct command_block));
2493}
2494
2495static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002496{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002497
2498 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002499
James Ketrenos43f66a62005-03-25 12:31:53 -06002500 /* Start the dma */
2501 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002502
James Ketrenos43f66a62005-03-25 12:31:53 -06002503 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002504 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002505
2506 IPW_DEBUG_FW("<< : \n");
2507 return 0;
2508}
2509
2510static void ipw_fw_dma_abort(struct ipw_priv *priv)
2511{
2512 u32 control = 0;
2513
2514 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002515
2516 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002518 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002519 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002520
James Ketrenos43f66a62005-03-25 12:31:53 -06002521 IPW_DEBUG_FW("<< \n");
2522}
2523
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002524static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2525 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002526{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002527 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002528 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002529 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530 IPW_DEBUG_FW(">> :\n");
2531
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002532 ipw_write_indirect(priv, address, (u8 *) cb,
2533 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002534
2535 IPW_DEBUG_FW("<< :\n");
2536 return 0;
2537
2538}
2539
2540static int ipw_fw_dma_kick(struct ipw_priv *priv)
2541{
2542 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002543 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002544
2545 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002546
James Ketrenos43f66a62005-03-25 12:31:53 -06002547 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002548 ipw_fw_dma_write_command_block(priv, index,
2549 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002550
2551 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002552 ipw_clear_bit(priv, IPW_RESET_REG,
2553 IPW_RESET_REG_MASTER_DISABLED |
2554 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002555
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002556 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002557 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002558 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002559
2560 IPW_DEBUG_FW("<< :\n");
2561 return 0;
2562}
2563
2564static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2565{
2566 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002567 u32 register_value = 0;
2568 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002569
2570 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002571 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002572 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002573
2574 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002575 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2576 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002577
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002578 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002579 cb_fields_address = address;
2580 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002581 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002582
2583 cb_fields_address += sizeof(u32);
2584 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002585 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002586
2587 cb_fields_address += sizeof(u32);
2588 register_value = ipw_read_reg32(priv, cb_fields_address);
2589 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2590 register_value);
2591
2592 cb_fields_address += sizeof(u32);
2593 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002594 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002595
2596 IPW_DEBUG_FW(">> :\n");
2597}
2598
2599static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2600{
2601 u32 current_cb_address = 0;
2602 u32 current_cb_index = 0;
2603
2604 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002605 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002606
James Ketrenosb095c382005-08-24 22:04:42 -05002607 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002608 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002609
James Ketrenos43f66a62005-03-25 12:31:53 -06002610 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002611 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002612
2613 IPW_DEBUG_FW(">> :\n");
2614 return current_cb_index;
2615
2616}
2617
2618static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2619 u32 src_address,
2620 u32 dest_address,
2621 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002622 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002623{
2624
Jeff Garzikbf794512005-07-31 13:07:26 -04002625 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002626 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2627 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002628 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002629 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002630
2631 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2632 src_address, dest_address, length);
2633
2634 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2635 return -1;
2636
2637 last_cb_element = priv->sram_desc.last_cb_index;
2638 cb = &priv->sram_desc.cb_list[last_cb_element];
2639 priv->sram_desc.last_cb_index++;
2640
2641 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002642 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002643 control |= CB_INT_ENABLED;
2644
2645 if (is_last)
2646 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002647
James Ketrenos43f66a62005-03-25 12:31:53 -06002648 control |= length;
2649
2650 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002651 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002652
2653 /* Copy the Source and Destination addresses */
2654 cb->dest_addr = dest_address;
2655 cb->source_addr = src_address;
2656
2657 /* Copy the Control Word last */
2658 cb->control = control;
2659
2660 return 0;
2661}
2662
2663static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002664 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002665{
2666 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002667 u32 src_offset = 0;
2668 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002669 int status = 0;
2670 IPW_DEBUG_FW(">> \n");
2671 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2672 src_phys, dest_address, length);
2673 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002674 status = ipw_fw_dma_add_command_block(priv,
2675 src_phys + src_offset,
2676 dest_address +
2677 dest_offset,
2678 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002679 if (status) {
2680 IPW_DEBUG_FW_INFO(": Failed\n");
2681 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002682 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002683 IPW_DEBUG_FW_INFO(": Added new cb\n");
2684
2685 src_offset += CB_MAX_LENGTH;
2686 dest_offset += CB_MAX_LENGTH;
2687 bytes_left -= CB_MAX_LENGTH;
2688 }
2689
2690 /* add the buffer tail */
2691 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002692 status =
2693 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2694 dest_address + dest_offset,
2695 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002696 if (status) {
2697 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2698 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002699 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002700 IPW_DEBUG_FW_INFO
2701 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002702 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002703
James Ketrenos43f66a62005-03-25 12:31:53 -06002704 IPW_DEBUG_FW("<< \n");
2705 return 0;
2706}
2707
2708static int ipw_fw_dma_wait(struct ipw_priv *priv)
2709{
2710 u32 current_index = 0;
2711 u32 watchdog = 0;
2712
2713 IPW_DEBUG_FW(">> : \n");
2714
2715 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002716 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002717 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002718
2719 while (current_index < priv->sram_desc.last_cb_index) {
2720 udelay(50);
2721 current_index = ipw_fw_dma_command_block_index(priv);
2722
2723 watchdog++;
2724
2725 if (watchdog > 400) {
2726 IPW_DEBUG_FW_INFO("Timeout\n");
2727 ipw_fw_dma_dump_command_block(priv);
2728 ipw_fw_dma_abort(priv);
2729 return -1;
2730 }
2731 }
2732
2733 ipw_fw_dma_abort(priv);
2734
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002735 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002736 ipw_set_bit(priv, IPW_RESET_REG,
2737 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002738
2739 IPW_DEBUG_FW("<< dmaWaitSync \n");
2740 return 0;
2741}
2742
Jeff Garzikbf794512005-07-31 13:07:26 -04002743static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002744{
2745 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002746 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002747 unsigned long flags;
2748
2749 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002750 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2751 network = list_entry(element, struct ieee80211_network, list);
2752 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2753 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002754 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002755 &priv->ieee->network_free_list);
2756 }
2757 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002758 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002759}
2760
2761/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002762 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002763 * Reads debug register from domain0.
2764 * If card is present, pre-defined value should
2765 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002766 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 * @param priv
2768 * @return 1 if card is present, 0 otherwise
2769 */
2770static inline int ipw_alive(struct ipw_priv *priv)
2771{
2772 return ipw_read32(priv, 0x90) == 0xd55555d5;
2773}
2774
2775static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2776 int timeout)
2777{
2778 int i = 0;
2779
2780 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002781 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 return i;
2783 mdelay(10);
2784 i += 10;
2785 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002786
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 return -ETIME;
2788}
2789
Jeff Garzikbf794512005-07-31 13:07:26 -04002790/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002791 * the ipw hardware. It assumes the buffer has all the bits for the
2792 * image and the caller is handling the memory allocation and clean up.
2793 */
2794
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002795static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002796{
2797 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002798
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 IPW_DEBUG_TRACE(">> \n");
2800 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002801 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002802
James Ketrenosb095c382005-08-24 22:04:42 -05002803 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2804 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002805 if (rc < 0) {
2806 IPW_ERROR("stop master failed in 10ms\n");
2807 return -1;
2808 }
2809
2810 IPW_DEBUG_INFO("stop master %dms\n", rc);
2811
2812 return rc;
2813}
2814
2815static void ipw_arc_release(struct ipw_priv *priv)
2816{
2817 IPW_DEBUG_TRACE(">> \n");
2818 mdelay(5);
2819
James Ketrenosb095c382005-08-24 22:04:42 -05002820 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
2822 /* no one knows timing, for safety add some delay */
2823 mdelay(5);
2824}
2825
2826struct fw_header {
2827 u32 version;
2828 u32 mode;
2829};
2830
2831struct fw_chunk {
2832 u32 address;
2833 u32 length;
2834};
2835
2836#define IPW_FW_MAJOR_VERSION 2
James Ketrenosb095c382005-08-24 22:04:42 -05002837#define IPW_FW_MINOR_VERSION 3
James Ketrenos43f66a62005-03-25 12:31:53 -06002838
2839#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2840#define IPW_FW_MAJOR(x) (x & 0xff)
2841
James Ketrenosafbf30a2005-08-25 00:05:33 -05002842#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002843
2844#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2845"." __stringify(IPW_FW_MINOR_VERSION) "-"
2846
2847#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2848#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2849#else
2850#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2851#endif
2852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002853static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002854{
2855 int rc = 0, i, addr;
2856 u8 cr = 0;
2857 u16 *image;
2858
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002859 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002860
James Ketrenos43f66a62005-03-25 12:31:53 -06002861 IPW_DEBUG_TRACE(">> \n");
2862
2863 rc = ipw_stop_master(priv);
2864
2865 if (rc < 0)
2866 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002867
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002868// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002869
James Ketrenosb095c382005-08-24 22:04:42 -05002870 for (addr = IPW_SHARED_LOWER_BOUND;
2871 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002872 ipw_write32(priv, addr, 0);
2873 }
2874
2875 /* no ucode (yet) */
2876 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2877 /* destroy DMA queues */
2878 /* reset sequence */
2879
James Ketrenosb095c382005-08-24 22:04:42 -05002880 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002881 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002882 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 mdelay(1);
2884
2885 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002886 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002888
James Ketrenosb095c382005-08-24 22:04:42 -05002889 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002890 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002891
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 /* enable ucode store */
2893 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2894 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2895 mdelay(1);
2896
2897 /* write ucode */
2898 /**
2899 * @bug
2900 * Do NOT set indirect address register once and then
2901 * store data to indirect data register in the loop.
2902 * It seems very reasonable, but in this case DINO do not
2903 * accept ucode. It is essential to set address each time.
2904 */
2905 /* load new ipw uCode */
2906 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002907 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002908 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002909
James Ketrenos43f66a62005-03-25 12:31:53 -06002910 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002911 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2912 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002913
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002914 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002915
2916 /* wait for alive response */
2917 for (i = 0; i < 100; i++) {
2918 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002919 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 if (cr & DINO_RXFIFO_DATA)
2921 break;
2922 mdelay(1);
2923 }
2924
2925 if (cr & DINO_RXFIFO_DATA) {
2926 /* alive_command_responce size is NOT multiple of 4 */
2927 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002928
2929 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002930 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002931 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002932 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002933 memcpy(&priv->dino_alive, response_buffer,
2934 sizeof(priv->dino_alive));
2935 if (priv->dino_alive.alive_command == 1
2936 && priv->dino_alive.ucode_valid == 1) {
2937 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002938 IPW_DEBUG_INFO
2939 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2940 "of %02d/%02d/%02d %02d:%02d\n",
2941 priv->dino_alive.software_revision,
2942 priv->dino_alive.software_revision,
2943 priv->dino_alive.device_identifier,
2944 priv->dino_alive.device_identifier,
2945 priv->dino_alive.time_stamp[0],
2946 priv->dino_alive.time_stamp[1],
2947 priv->dino_alive.time_stamp[2],
2948 priv->dino_alive.time_stamp[3],
2949 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002950 } else {
2951 IPW_DEBUG_INFO("Microcode is not alive\n");
2952 rc = -EINVAL;
2953 }
2954 } else {
2955 IPW_DEBUG_INFO("No alive response from DINO\n");
2956 rc = -ETIME;
2957 }
2958
2959 /* disable DINO, otherwise for some reason
2960 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002961 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002962
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002963// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002964
2965 return rc;
2966}
2967
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002968static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002969{
2970 int rc = -1;
2971 int offset = 0;
2972 struct fw_chunk *chunk;
2973 dma_addr_t shared_phys;
2974 u8 *shared_virt;
2975
2976 IPW_DEBUG_TRACE("<< : \n");
2977 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2978
2979 if (!shared_virt)
2980 return -ENOMEM;
2981
2982 memmove(shared_virt, data, len);
2983
2984 /* Start the Dma */
2985 rc = ipw_fw_dma_enable(priv);
2986
2987 if (priv->sram_desc.last_cb_index > 0) {
2988 /* the DMA is already ready this would be a bug. */
2989 BUG();
2990 goto out;
2991 }
2992
2993 do {
2994 chunk = (struct fw_chunk *)(data + offset);
2995 offset += sizeof(struct fw_chunk);
2996 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002997 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002998 * offeset*/
2999 /* Dma loading */
3000 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003001 le32_to_cpu(chunk->address),
3002 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003003 if (rc) {
3004 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3005 goto out;
3006 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003007
James Ketrenosa613bff2005-08-24 21:43:11 -05003008 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 } while (offset < len);
3010
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003011 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003012 rc = ipw_fw_dma_kick(priv);
3013 if (rc) {
3014 IPW_ERROR("dmaKick Failed\n");
3015 goto out;
3016 }
3017
3018 rc = ipw_fw_dma_wait(priv);
3019 if (rc) {
3020 IPW_ERROR("dmaWaitSync Failed\n");
3021 goto out;
3022 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003023 out:
3024 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 return rc;
3026}
3027
3028/* stop nic */
3029static int ipw_stop_nic(struct ipw_priv *priv)
3030{
3031 int rc = 0;
3032
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003033 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003034 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003035
James Ketrenosb095c382005-08-24 22:04:42 -05003036 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3037 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003038 if (rc < 0) {
3039 IPW_ERROR("wait for reg master disabled failed\n");
3040 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003041 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003042
James Ketrenosb095c382005-08-24 22:04:42 -05003043 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003044
James Ketrenos43f66a62005-03-25 12:31:53 -06003045 return rc;
3046}
3047
3048static void ipw_start_nic(struct ipw_priv *priv)
3049{
3050 IPW_DEBUG_TRACE(">>\n");
3051
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003052 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003053 ipw_clear_bit(priv, IPW_RESET_REG,
3054 IPW_RESET_REG_MASTER_DISABLED |
3055 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003056 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003057
James Ketrenos43f66a62005-03-25 12:31:53 -06003058 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003059 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3060 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003061
3062 IPW_DEBUG_TRACE("<<\n");
3063}
Jeff Garzikbf794512005-07-31 13:07:26 -04003064
James Ketrenos43f66a62005-03-25 12:31:53 -06003065static int ipw_init_nic(struct ipw_priv *priv)
3066{
3067 int rc;
3068
3069 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003070 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003071 /*prvHwInitNic */
3072 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003073 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003074
3075 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003076 ipw_write32(priv, IPW_READ_INT_REGISTER,
3077 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003078
3079 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003080 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3081 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003082 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003083 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3084
3085 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003086 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003087
3088 udelay(10);
3089
3090 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003091 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003092
3093 IPW_DEBUG_TRACE(">>\n");
3094 return 0;
3095}
3096
Jeff Garzikbf794512005-07-31 13:07:26 -04003097/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 * Probe is an ok place to call this from.
3099 */
3100static int ipw_reset_nic(struct ipw_priv *priv)
3101{
3102 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003103 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003104
3105 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003106
James Ketrenos43f66a62005-03-25 12:31:53 -06003107 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003108
James Ketrenosa613bff2005-08-24 21:43:11 -05003109 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003110 /* Clear the 'host command active' bit... */
3111 priv->status &= ~STATUS_HCMD_ACTIVE;
3112 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003113 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3114 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003115 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003116
3117 IPW_DEBUG_TRACE("<<\n");
3118 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003119}
James Ketrenos43f66a62005-03-25 12:31:53 -06003120
Jeff Garzikbf794512005-07-31 13:07:26 -04003121static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003122 const struct firmware **fw, const char *name)
3123{
3124 struct fw_header *header;
3125 int rc;
3126
3127 /* ask firmware_class module to get the boot firmware off disk */
3128 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3129 if (rc < 0) {
3130 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3131 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003132 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003133
3134 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003135 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003136 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3137 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003138 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3139 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003140 return -EINVAL;
3141 }
3142
Jiri Bencaaa4d302005-06-07 14:58:41 +02003143 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003144 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003145 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3146 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003147 (*fw)->size - sizeof(struct fw_header));
3148 return 0;
3149}
3150
James Ketrenosb095c382005-08-24 22:04:42 -05003151#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003152
3153static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
3154 struct ipw_rx_queue *rxq)
3155{
3156 unsigned long flags;
3157 int i;
3158
3159 spin_lock_irqsave(&rxq->lock, flags);
3160
3161 INIT_LIST_HEAD(&rxq->rx_free);
3162 INIT_LIST_HEAD(&rxq->rx_used);
3163
3164 /* Fill the rx_used queue with _all_ of the Rx buffers */
3165 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3166 /* In the reset function, these buffers may have been allocated
3167 * to an SKB, so we need to unmap and free potential storage */
3168 if (rxq->pool[i].skb != NULL) {
3169 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003170 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003171 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003172 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003173 }
3174 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3175 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003176
James Ketrenos43f66a62005-03-25 12:31:53 -06003177 /* Set us so that we have processed and used all buffers, but have
3178 * not restocked the Rx queue with fresh buffers */
3179 rxq->read = rxq->write = 0;
3180 rxq->processed = RX_QUEUE_SIZE - 1;
3181 rxq->free_count = 0;
3182 spin_unlock_irqrestore(&rxq->lock, flags);
3183}
3184
3185#ifdef CONFIG_PM
3186static int fw_loaded = 0;
3187static const struct firmware *bootfw = NULL;
3188static const struct firmware *firmware = NULL;
3189static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003190
3191static void free_firmware(void)
3192{
3193 if (fw_loaded) {
3194 release_firmware(bootfw);
3195 release_firmware(ucode);
3196 release_firmware(firmware);
3197 bootfw = ucode = firmware = NULL;
3198 fw_loaded = 0;
3199 }
3200}
3201#else
3202#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003203#endif
3204
3205static int ipw_load(struct ipw_priv *priv)
3206{
3207#ifndef CONFIG_PM
3208 const struct firmware *bootfw = NULL;
3209 const struct firmware *firmware = NULL;
3210 const struct firmware *ucode = NULL;
3211#endif
3212 int rc = 0, retries = 3;
3213
3214#ifdef CONFIG_PM
3215 if (!fw_loaded) {
3216#endif
3217 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003218 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003219 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003220
James Ketrenos43f66a62005-03-25 12:31:53 -06003221 switch (priv->ieee->iw_mode) {
3222 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003223 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003224 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003225 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003227
James Ketrenos43f66a62005-03-25 12:31:53 -06003228 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3229 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003230
James Ketrenosb095c382005-08-24 22:04:42 -05003231#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003232 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003233 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003234 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003235 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003236 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003237
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003238 rc = ipw_get_fw(priv, &firmware,
3239 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003240 break;
3241#endif
3242 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003243 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003244 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003245 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003246
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3248 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003249
James Ketrenos43f66a62005-03-25 12:31:53 -06003250 default:
3251 rc = -EINVAL;
3252 }
3253
Jeff Garzikbf794512005-07-31 13:07:26 -04003254 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003255 goto error;
3256
3257#ifdef CONFIG_PM
3258 fw_loaded = 1;
3259 }
3260#endif
3261
3262 if (!priv->rxq)
3263 priv->rxq = ipw_rx_queue_alloc(priv);
3264 else
3265 ipw_rx_queue_reset(priv, priv->rxq);
3266 if (!priv->rxq) {
3267 IPW_ERROR("Unable to initialize Rx queue\n");
3268 goto error;
3269 }
3270
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003271 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003272 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003273 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003274 priv->status &= ~STATUS_INT_ENABLED;
3275
3276 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003277 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003278
James Ketrenos43f66a62005-03-25 12:31:53 -06003279 ipw_stop_nic(priv);
3280
3281 rc = ipw_reset_nic(priv);
3282 if (rc) {
3283 IPW_ERROR("Unable to reset NIC\n");
3284 goto error;
3285 }
3286
James Ketrenosb095c382005-08-24 22:04:42 -05003287 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3288 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003289
3290 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003291 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003292 bootfw->size - sizeof(struct fw_header));
3293 if (rc < 0) {
3294 IPW_ERROR("Unable to load boot firmware\n");
3295 goto error;
3296 }
3297
3298 /* kick start the device */
3299 ipw_start_nic(priv);
3300
3301 /* wait for the device to finish it's initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003302 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3303 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003304 if (rc < 0) {
3305 IPW_ERROR("device failed to boot initial fw image\n");
3306 goto error;
3307 }
3308 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3309
Jeff Garzikbf794512005-07-31 13:07:26 -04003310 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003311 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003312
3313 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003314 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003315 ucode->size - sizeof(struct fw_header));
3316 if (rc < 0) {
3317 IPW_ERROR("Unable to load ucode\n");
3318 goto error;
3319 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003320
James Ketrenos43f66a62005-03-25 12:31:53 -06003321 /* stop nic */
3322 ipw_stop_nic(priv);
3323
3324 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003325 rc = ipw_load_firmware(priv, firmware->data +
3326 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003327 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003328 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003329 IPW_ERROR("Unable to load firmware\n");
3330 goto error;
3331 }
3332
3333 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3334
3335 rc = ipw_queue_reset(priv);
3336 if (rc) {
3337 IPW_ERROR("Unable to initialize queues\n");
3338 goto error;
3339 }
3340
3341 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003342 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003343 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003344 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003345
James Ketrenos43f66a62005-03-25 12:31:53 -06003346 /* kick start the device */
3347 ipw_start_nic(priv);
3348
James Ketrenosb095c382005-08-24 22:04:42 -05003349 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003350 if (retries > 0) {
3351 IPW_WARNING("Parity error. Retrying init.\n");
3352 retries--;
3353 goto retry;
3354 }
3355
3356 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3357 rc = -EIO;
3358 goto error;
3359 }
3360
3361 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003362 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3363 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003364 if (rc < 0) {
3365 IPW_ERROR("device failed to start after 500ms\n");
3366 goto error;
3367 }
3368 IPW_DEBUG_INFO("device response after %dms\n", rc);
3369
3370 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003371 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003372
3373 /* read eeprom data and initialize the eeprom region of sram */
3374 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003375 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003376
3377 /* enable interrupts */
3378 ipw_enable_interrupts(priv);
3379
3380 /* Ensure our queue has valid packets */
3381 ipw_rx_queue_replenish(priv);
3382
James Ketrenosb095c382005-08-24 22:04:42 -05003383 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003384
3385 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003386 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003387
3388#ifndef CONFIG_PM
3389 release_firmware(bootfw);
3390 release_firmware(ucode);
3391 release_firmware(firmware);
3392#endif
3393 return 0;
3394
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003395 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 if (priv->rxq) {
3397 ipw_rx_queue_free(priv, priv->rxq);
3398 priv->rxq = NULL;
3399 }
3400 ipw_tx_queue_free(priv);
3401 if (bootfw)
3402 release_firmware(bootfw);
3403 if (ucode)
3404 release_firmware(ucode);
3405 if (firmware)
3406 release_firmware(firmware);
3407#ifdef CONFIG_PM
3408 fw_loaded = 0;
3409 bootfw = ucode = firmware = NULL;
3410#endif
3411
3412 return rc;
3413}
3414
Jeff Garzikbf794512005-07-31 13:07:26 -04003415/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003416 * DMA services
3417 *
3418 * Theory of operation
3419 *
3420 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3421 * 2 empty entries always kept in the buffer to protect from overflow.
3422 *
3423 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003424 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3425 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003426 * Tx queue resumed.
3427 *
3428 * The IPW operates with six queues, one receive queue in the device's
3429 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003430 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003431 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003432 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003433 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003434 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003435 * we only utilize the first data transmit queue (queue1).
3436 */
3437
3438/**
3439 * Driver allocates buffers of this size for Rx
3440 */
3441
3442static inline int ipw_queue_space(const struct clx2_queue *q)
3443{
3444 int s = q->last_used - q->first_empty;
3445 if (s <= 0)
3446 s += q->n_bd;
3447 s -= 2; /* keep some reserve to not confuse empty and full situations */
3448 if (s < 0)
3449 s = 0;
3450 return s;
3451}
3452
3453static inline int ipw_queue_inc_wrap(int index, int n_bd)
3454{
3455 return (++index == n_bd) ? 0 : index;
3456}
3457
3458/**
3459 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003460 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003461 * @param q queue to init
3462 * @param count Number of BD's to allocate. Should be power of 2
3463 * @param read_register Address for 'read' register
3464 * (not offset within BAR, full address)
3465 * @param write_register Address for 'write' register
3466 * (not offset within BAR, full address)
3467 * @param base_register Address for 'base' register
3468 * (not offset within BAR, full address)
3469 * @param size Address for 'size' register
3470 * (not offset within BAR, full address)
3471 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003472static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003473 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003474{
3475 q->n_bd = count;
3476
3477 q->low_mark = q->n_bd / 4;
3478 if (q->low_mark < 4)
3479 q->low_mark = 4;
3480
3481 q->high_mark = q->n_bd / 8;
3482 if (q->high_mark < 2)
3483 q->high_mark = 2;
3484
3485 q->first_empty = q->last_used = 0;
3486 q->reg_r = read;
3487 q->reg_w = write;
3488
3489 ipw_write32(priv, base, q->dma_addr);
3490 ipw_write32(priv, size, count);
3491 ipw_write32(priv, read, 0);
3492 ipw_write32(priv, write, 0);
3493
3494 _ipw_read32(priv, 0x90);
3495}
3496
Jeff Garzikbf794512005-07-31 13:07:26 -04003497static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003498 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003499 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003500{
3501 struct pci_dev *dev = priv->pci_dev;
3502
3503 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3504 if (!q->txb) {
3505 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3506 return -ENOMEM;
3507 }
3508
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003509 q->bd =
3510 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003511 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003512 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003513 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003514 kfree(q->txb);
3515 q->txb = NULL;
3516 return -ENOMEM;
3517 }
3518
3519 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3520 return 0;
3521}
3522
3523/**
3524 * Free one TFD, those at index [txq->q.last_used].
3525 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003526 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003527 * @param dev
3528 * @param txq
3529 */
3530static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3531 struct clx2_tx_queue *txq)
3532{
3533 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3534 struct pci_dev *dev = priv->pci_dev;
3535 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003536
James Ketrenos43f66a62005-03-25 12:31:53 -06003537 /* classify bd */
3538 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3539 /* nothing to cleanup after for host commands */
3540 return;
3541
3542 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003543 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3544 IPW_ERROR("Too many chunks: %i\n",
3545 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003546 /** @todo issue fatal error, it is quite serious situation */
3547 return;
3548 }
3549
3550 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003551 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3552 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3553 le16_to_cpu(bd->u.data.chunk_len[i]),
3554 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003555 if (txq->txb[txq->q.last_used]) {
3556 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3557 txq->txb[txq->q.last_used] = NULL;
3558 }
3559 }
3560}
3561
3562/**
3563 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003564 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003565 * Empty queue by removing and destroying all BD's.
3566 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003567 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003568 * @param dev
3569 * @param q
3570 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003571static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003572{
3573 struct clx2_queue *q = &txq->q;
3574 struct pci_dev *dev = priv->pci_dev;
3575
Jeff Garzikbf794512005-07-31 13:07:26 -04003576 if (q->n_bd == 0)
3577 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003578
3579 /* first, empty all BD's */
3580 for (; q->first_empty != q->last_used;
3581 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3582 ipw_queue_tx_free_tfd(priv, txq);
3583 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003584
James Ketrenos43f66a62005-03-25 12:31:53 -06003585 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003586 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003587 q->dma_addr);
3588 kfree(txq->txb);
3589
3590 /* 0 fill whole structure */
3591 memset(txq, 0, sizeof(*txq));
3592}
3593
James Ketrenos43f66a62005-03-25 12:31:53 -06003594/**
3595 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003596 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003597 * @param priv
3598 */
3599static void ipw_tx_queue_free(struct ipw_priv *priv)
3600{
3601 /* Tx CMD queue */
3602 ipw_queue_tx_free(priv, &priv->txq_cmd);
3603
3604 /* Tx queues */
3605 ipw_queue_tx_free(priv, &priv->txq[0]);
3606 ipw_queue_tx_free(priv, &priv->txq[1]);
3607 ipw_queue_tx_free(priv, &priv->txq[2]);
3608 ipw_queue_tx_free(priv, &priv->txq[3]);
3609}
3610
3611static void inline __maybe_wake_tx(struct ipw_priv *priv)
3612{
3613 if (netif_running(priv->net_dev)) {
3614 switch (priv->port_type) {
3615 case DCR_TYPE_MU_BSS:
3616 case DCR_TYPE_MU_IBSS:
James Ketrenosa613bff2005-08-24 21:43:11 -05003617 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003618 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003619 }
3620 netif_wake_queue(priv->net_dev);
3621 }
3622
3623}
3624
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003625static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003626{
3627 /* First 3 bytes are manufacturer */
3628 bssid[0] = priv->mac_addr[0];
3629 bssid[1] = priv->mac_addr[1];
3630 bssid[2] = priv->mac_addr[2];
3631
3632 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003633 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003635 bssid[0] &= 0xfe; /* clear multicast bit */
3636 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003637}
3638
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003639static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003640{
3641 struct ipw_station_entry entry;
3642 int i;
3643
3644 for (i = 0; i < priv->num_stations; i++) {
3645 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3646 /* Another node is active in network */
3647 priv->missed_adhoc_beacons = 0;
3648 if (!(priv->config & CFG_STATIC_CHANNEL))
3649 /* when other nodes drop out, we drop out */
3650 priv->config &= ~CFG_ADHOC_PERSIST;
3651
3652 return i;
3653 }
3654 }
3655
3656 if (i == MAX_STATIONS)
3657 return IPW_INVALID_STATION;
3658
3659 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3660
3661 entry.reserved = 0;
3662 entry.support_mode = 0;
3663 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3664 memcpy(priv->stations[i], bssid, ETH_ALEN);
3665 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003666 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003667 priv->num_stations++;
3668
3669 return i;
3670}
3671
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003672static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003673{
3674 int i;
3675
Jeff Garzikbf794512005-07-31 13:07:26 -04003676 for (i = 0; i < priv->num_stations; i++)
3677 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003678 return i;
3679
3680 return IPW_INVALID_STATION;
3681}
3682
3683static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3684{
3685 int err;
3686
3687 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3688 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3689 return;
3690 }
3691
3692 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3693 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003694 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003695 priv->assoc_request.channel);
3696
3697 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3698 priv->status |= STATUS_DISASSOCIATING;
3699
3700 if (quiet)
3701 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3702 else
3703 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3704 err = ipw_send_associate(priv, &priv->assoc_request);
3705 if (err) {
3706 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3707 "failed.\n");
3708 return;
3709 }
3710
3711}
3712
James Ketrenosc848d0a2005-08-24 21:56:24 -05003713static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003714{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003715 struct ipw_priv *priv = data;
3716 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3717 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003718 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003719 return 1;
3720}
3721
3722static void ipw_bg_disassociate(void *data)
3723{
3724 struct ipw_priv *priv = data;
3725 down(&priv->sem);
3726 ipw_disassociate(data);
3727 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003728}
3729
Zhu Yid8bad6d2005-07-13 12:25:38 -05003730static void ipw_system_config(void *data)
3731{
3732 struct ipw_priv *priv = data;
3733 ipw_send_system_config(priv, &priv->sys_config);
3734}
3735
James Ketrenos43f66a62005-03-25 12:31:53 -06003736struct ipw_status_code {
3737 u16 status;
3738 const char *reason;
3739};
3740
3741static const struct ipw_status_code ipw_status_codes[] = {
3742 {0x00, "Successful"},
3743 {0x01, "Unspecified failure"},
3744 {0x0A, "Cannot support all requested capabilities in the "
3745 "Capability information field"},
3746 {0x0B, "Reassociation denied due to inability to confirm that "
3747 "association exists"},
3748 {0x0C, "Association denied due to reason outside the scope of this "
3749 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003750 {0x0D,
3751 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003752 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003753 {0x0E,
3754 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003755 "transaction sequence number out of expected sequence"},
3756 {0x0F, "Authentication rejected because of challenge failure"},
3757 {0x10, "Authentication rejected due to timeout waiting for next "
3758 "frame in sequence"},
3759 {0x11, "Association denied because AP is unable to handle additional "
3760 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003761 {0x12,
3762 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003763 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003764 {0x13,
3765 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003766 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003767 {0x14,
3768 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003769 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003770 {0x15,
3771 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003772 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003773 {0x19,
3774 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003775 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003776 {0x1A,
3777 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003778 "DSSS-OFDM operation"},
3779 {0x28, "Invalid Information Element"},
3780 {0x29, "Group Cipher is not valid"},
3781 {0x2A, "Pairwise Cipher is not valid"},
3782 {0x2B, "AKMP is not valid"},
3783 {0x2C, "Unsupported RSN IE version"},
3784 {0x2D, "Invalid RSN IE Capabilities"},
3785 {0x2E, "Cipher suite is rejected per security policy"},
3786};
3787
3788#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003789static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003790{
3791 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003792 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003793 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003794 return ipw_status_codes[i].reason;
3795 return "Unknown status value.";
3796}
3797#endif
3798
3799static void inline average_init(struct average *avg)
3800{
3801 memset(avg, 0, sizeof(*avg));
3802}
3803
3804static void inline average_add(struct average *avg, s16 val)
3805{
3806 avg->sum -= avg->entries[avg->pos];
3807 avg->sum += val;
3808 avg->entries[avg->pos++] = val;
3809 if (unlikely(avg->pos == AVG_ENTRIES)) {
3810 avg->init = 1;
3811 avg->pos = 0;
3812 }
3813}
3814
3815static s16 inline average_value(struct average *avg)
3816{
3817 if (!unlikely(avg->init)) {
3818 if (avg->pos)
3819 return avg->sum / avg->pos;
3820 return 0;
3821 }
3822
3823 return avg->sum / AVG_ENTRIES;
3824}
3825
3826static void ipw_reset_stats(struct ipw_priv *priv)
3827{
3828 u32 len = sizeof(u32);
3829
3830 priv->quality = 0;
3831
3832 average_init(&priv->average_missed_beacons);
3833 average_init(&priv->average_rssi);
3834 average_init(&priv->average_noise);
3835
3836 priv->last_rate = 0;
3837 priv->last_missed_beacons = 0;
3838 priv->last_rx_packets = 0;
3839 priv->last_tx_packets = 0;
3840 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003841
James Ketrenos43f66a62005-03-25 12:31:53 -06003842 /* Firmware managed, reset only when NIC is restarted, so we have to
3843 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003844 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003845 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003846 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003847 &priv->last_tx_failures, &len);
3848
3849 /* Driver managed, reset with each association */
3850 priv->missed_adhoc_beacons = 0;
3851 priv->missed_beacons = 0;
3852 priv->tx_packets = 0;
3853 priv->rx_packets = 0;
3854
3855}
3856
James Ketrenos43f66a62005-03-25 12:31:53 -06003857static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3858{
3859 u32 i = 0x80000000;
3860 u32 mask = priv->rates_mask;
3861 /* If currently associated in B mode, restrict the maximum
3862 * rate match to B rates */
3863 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3864 mask &= IEEE80211_CCK_RATES_MASK;
3865
3866 /* TODO: Verify that the rate is supported by the current rates
3867 * list. */
3868
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003869 while (i && !(mask & i))
3870 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003871 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003872 case IEEE80211_CCK_RATE_1MB_MASK:
3873 return 1000000;
3874 case IEEE80211_CCK_RATE_2MB_MASK:
3875 return 2000000;
3876 case IEEE80211_CCK_RATE_5MB_MASK:
3877 return 5500000;
3878 case IEEE80211_OFDM_RATE_6MB_MASK:
3879 return 6000000;
3880 case IEEE80211_OFDM_RATE_9MB_MASK:
3881 return 9000000;
3882 case IEEE80211_CCK_RATE_11MB_MASK:
3883 return 11000000;
3884 case IEEE80211_OFDM_RATE_12MB_MASK:
3885 return 12000000;
3886 case IEEE80211_OFDM_RATE_18MB_MASK:
3887 return 18000000;
3888 case IEEE80211_OFDM_RATE_24MB_MASK:
3889 return 24000000;
3890 case IEEE80211_OFDM_RATE_36MB_MASK:
3891 return 36000000;
3892 case IEEE80211_OFDM_RATE_48MB_MASK:
3893 return 48000000;
3894 case IEEE80211_OFDM_RATE_54MB_MASK:
3895 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003896 }
3897
Jeff Garzikbf794512005-07-31 13:07:26 -04003898 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003899 return 11000000;
3900 else
3901 return 54000000;
3902}
3903
3904static u32 ipw_get_current_rate(struct ipw_priv *priv)
3905{
3906 u32 rate, len = sizeof(rate);
3907 int err;
3908
Jeff Garzikbf794512005-07-31 13:07:26 -04003909 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003910 return 0;
3911
3912 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003913 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003914 &len);
3915 if (err) {
3916 IPW_DEBUG_INFO("failed querying ordinals.\n");
3917 return 0;
3918 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003919 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003920 return ipw_get_max_rate(priv);
3921
3922 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003923 case IPW_TX_RATE_1MB:
3924 return 1000000;
3925 case IPW_TX_RATE_2MB:
3926 return 2000000;
3927 case IPW_TX_RATE_5MB:
3928 return 5500000;
3929 case IPW_TX_RATE_6MB:
3930 return 6000000;
3931 case IPW_TX_RATE_9MB:
3932 return 9000000;
3933 case IPW_TX_RATE_11MB:
3934 return 11000000;
3935 case IPW_TX_RATE_12MB:
3936 return 12000000;
3937 case IPW_TX_RATE_18MB:
3938 return 18000000;
3939 case IPW_TX_RATE_24MB:
3940 return 24000000;
3941 case IPW_TX_RATE_36MB:
3942 return 36000000;
3943 case IPW_TX_RATE_48MB:
3944 return 48000000;
3945 case IPW_TX_RATE_54MB:
3946 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003947 }
3948
3949 return 0;
3950}
3951
James Ketrenos43f66a62005-03-25 12:31:53 -06003952#define IPW_STATS_INTERVAL (2 * HZ)
3953static void ipw_gather_stats(struct ipw_priv *priv)
3954{
3955 u32 rx_err, rx_err_delta, rx_packets_delta;
3956 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3957 u32 missed_beacons_percent, missed_beacons_delta;
3958 u32 quality = 0;
3959 u32 len = sizeof(u32);
3960 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003961 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003962 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003963 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003964
3965 if (!(priv->status & STATUS_ASSOCIATED)) {
3966 priv->quality = 0;
3967 return;
3968 }
3969
3970 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003971 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003972 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003973 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 priv->last_missed_beacons = priv->missed_beacons;
3975 if (priv->assoc_request.beacon_interval) {
3976 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003977 (HZ * priv->assoc_request.beacon_interval) /
3978 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 } else {
3980 missed_beacons_percent = 0;
3981 }
3982 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3983
3984 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3985 rx_err_delta = rx_err - priv->last_rx_err;
3986 priv->last_rx_err = rx_err;
3987
3988 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3989 tx_failures_delta = tx_failures - priv->last_tx_failures;
3990 priv->last_tx_failures = tx_failures;
3991
3992 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3993 priv->last_rx_packets = priv->rx_packets;
3994
3995 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3996 priv->last_tx_packets = priv->tx_packets;
3997
3998 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003999 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004000 * Missed beacon: 100% = 0, 0% = 70% missed
4001 * Rate: 60% = 1Mbs, 100% = Max
4002 * Rx and Tx errors represent a straight % of total Rx/Tx
4003 * RSSI: 100% = > -50, 0% = < -80
4004 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004005 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004006 * The lowest computed quality is used.
4007 *
4008 */
4009#define BEACON_THRESHOLD 5
4010 beacon_quality = 100 - missed_beacons_percent;
4011 if (beacon_quality < BEACON_THRESHOLD)
4012 beacon_quality = 0;
4013 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004014 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004015 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004016 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004017 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004018
James Ketrenos43f66a62005-03-25 12:31:53 -06004019 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004020 max_rate = ipw_get_max_rate(priv);
4021 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004022 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4023 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004024
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004025 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004026 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004027 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004028 else
4029 rx_quality = 100;
4030 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4031 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004032
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004033 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004034 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004035 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004036 else
4037 tx_quality = 100;
4038 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4039 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004040
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004042 signal_quality =
4043 (100 *
4044 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4045 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4046 (priv->ieee->perfect_rssi - rssi) *
4047 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4048 62 * (priv->ieee->perfect_rssi - rssi))) /
4049 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4050 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4051 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004052 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004053 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004054 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004055
James Ketrenos43f66a62005-03-25 12:31:53 -06004056 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4057 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004058
4059 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004060 min(rate_quality,
4061 min(tx_quality, min(rx_quality, signal_quality))));
4062 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004063 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4064 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004065 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004066 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4067 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004068 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004069 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4070 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004071 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004072 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4073 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004074 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004075 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4076 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004077
4078 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004079
4080 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004081 IPW_STATS_INTERVAL);
4082}
4083
James Ketrenosc848d0a2005-08-24 21:56:24 -05004084static void ipw_bg_gather_stats(void *data)
4085{
4086 struct ipw_priv *priv = data;
4087 down(&priv->sem);
4088 ipw_gather_stats(data);
4089 up(&priv->sem);
4090}
4091
James Ketrenosea2b26e2005-08-24 21:25:16 -05004092static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
4093 int missed_count)
4094{
4095 priv->notif_missed_beacons = missed_count;
4096
James Ketrenosafbf30a2005-08-25 00:05:33 -05004097 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004098 priv->status & STATUS_ASSOCIATED) {
4099 /* If associated and we've hit the missed
4100 * beacon threshold, disassociate, turn
4101 * off roaming, and abort any active scans */
4102 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004103 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004104 "Missed beacon: %d - disassociate\n", missed_count);
4105 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004106 if (priv->status & STATUS_SCANNING) {
4107 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4108 IPW_DL_STATE,
4109 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004110 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004111 }
4112
James Ketrenosea2b26e2005-08-24 21:25:16 -05004113 queue_work(priv->workqueue, &priv->disassociate);
4114 return;
4115 }
4116
4117 if (priv->status & STATUS_ROAMING) {
4118 /* If we are currently roaming, then just
4119 * print a debug statement... */
4120 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4121 "Missed beacon: %d - roam in progress\n",
4122 missed_count);
4123 return;
4124 }
4125
4126 if (missed_count > priv->roaming_threshold) {
4127 /* If we are not already roaming, set the ROAM
4128 * bit in the status and kick off a scan */
4129 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4130 "Missed beacon: %d - initiate "
4131 "roaming\n", missed_count);
4132 if (!(priv->status & STATUS_ROAMING)) {
4133 priv->status |= STATUS_ROAMING;
4134 if (!(priv->status & STATUS_SCANNING))
4135 queue_work(priv->workqueue,
4136 &priv->request_scan);
4137 }
4138 return;
4139 }
4140
4141 if (priv->status & STATUS_SCANNING) {
4142 /* Stop scan to keep fw from getting
4143 * stuck (only if we aren't roaming --
4144 * otherwise we'll never scan more than 2 or 3
4145 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004146 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4147 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004148 queue_work(priv->workqueue, &priv->abort_scan);
4149 }
4150
4151 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4152
4153}
4154
James Ketrenos43f66a62005-03-25 12:31:53 -06004155/**
4156 * Handle host notification packet.
4157 * Called from interrupt routine
4158 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004159static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004160 struct ipw_rx_notification *notif)
4161{
James Ketrenosa613bff2005-08-24 21:43:11 -05004162 notif->size = le16_to_cpu(notif->size);
4163
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004164 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004165
James Ketrenos43f66a62005-03-25 12:31:53 -06004166 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004167 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4168 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004169
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004170 switch (assoc->state) {
4171 case CMAS_ASSOCIATED:{
4172 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4173 IPW_DL_ASSOC,
4174 "associated: '%s' " MAC_FMT
4175 " \n",
4176 escape_essid(priv->essid,
4177 priv->essid_len),
4178 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004179
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004180 switch (priv->ieee->iw_mode) {
4181 case IW_MODE_INFRA:
4182 memcpy(priv->ieee->bssid,
4183 priv->bssid, ETH_ALEN);
4184 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004185
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004186 case IW_MODE_ADHOC:
4187 memcpy(priv->ieee->bssid,
4188 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004189
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004190 /* clear out the station table */
4191 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 IPW_DEBUG_ASSOC
4194 ("queueing adhoc check\n");
4195 queue_delayed_work(priv->
4196 workqueue,
4197 &priv->
4198 adhoc_check,
4199 priv->
4200 assoc_request.
4201 beacon_interval);
4202 break;
4203 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004204
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004205 priv->status &= ~STATUS_ASSOCIATING;
4206 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004207 queue_work(priv->workqueue,
4208 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004209
James Ketrenosb095c382005-08-24 22:04:42 -05004210#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004211#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4212 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4213 if ((priv->status & STATUS_AUTH) &&
4214 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4215 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004216 if ((sizeof
4217 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004218 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004219 <= notif->size)
4220 && (notif->size <= 2314)) {
4221 struct
4222 ieee80211_rx_stats
4223 stats = {
4224 .len =
4225 notif->
4226 size - 1,
4227 };
4228
4229 IPW_DEBUG_QOS
4230 ("QoS Associate "
4231 "size %d\n",
4232 notif->size);
4233 ieee80211_rx_mgt(priv->
4234 ieee,
4235 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004236 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004237 *)
4238 &notif->u.raw, &stats);
4239 }
4240 }
4241#endif
4242
James Ketrenosa613bff2005-08-24 21:43:11 -05004243 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004244
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004245 break;
4246 }
4247
4248 case CMAS_AUTHENTICATED:{
4249 if (priv->
4250 status & (STATUS_ASSOCIATED |
4251 STATUS_AUTH)) {
4252#ifdef CONFIG_IPW_DEBUG
4253 struct notif_authenticate *auth
4254 = &notif->u.auth;
4255 IPW_DEBUG(IPW_DL_NOTIF |
4256 IPW_DL_STATE |
4257 IPW_DL_ASSOC,
4258 "deauthenticated: '%s' "
4259 MAC_FMT
4260 ": (0x%04X) - %s \n",
4261 escape_essid(priv->
4262 essid,
4263 priv->
4264 essid_len),
4265 MAC_ARG(priv->bssid),
4266 ntohs(auth->status),
4267 ipw_get_status_code
4268 (ntohs
4269 (auth->status)));
4270#endif
4271
4272 priv->status &=
4273 ~(STATUS_ASSOCIATING |
4274 STATUS_AUTH |
4275 STATUS_ASSOCIATED);
4276
James Ketrenosa613bff2005-08-24 21:43:11 -05004277 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004278 break;
4279 }
4280
4281 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4282 IPW_DL_ASSOC,
4283 "authenticated: '%s' " MAC_FMT
4284 "\n",
4285 escape_essid(priv->essid,
4286 priv->essid_len),
4287 MAC_ARG(priv->bssid));
4288 break;
4289 }
4290
4291 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004292 if (priv->status & STATUS_AUTH) {
4293 struct
4294 ieee80211_assoc_response
4295 *resp;
4296 resp =
4297 (struct
4298 ieee80211_assoc_response
4299 *)&notif->u.raw;
4300 IPW_DEBUG(IPW_DL_NOTIF |
4301 IPW_DL_STATE |
4302 IPW_DL_ASSOC,
4303 "association failed (0x%04X): %s\n",
4304 ntohs(resp->status),
4305 ipw_get_status_code
4306 (ntohs
4307 (resp->status)));
4308 }
4309
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004310 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4311 IPW_DL_ASSOC,
4312 "disassociated: '%s' " MAC_FMT
4313 " \n",
4314 escape_essid(priv->essid,
4315 priv->essid_len),
4316 MAC_ARG(priv->bssid));
4317
4318 priv->status &=
4319 ~(STATUS_DISASSOCIATING |
4320 STATUS_ASSOCIATING |
4321 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004322 if (priv->assoc_network
4323 && (priv->assoc_network->
4324 capability &
4325 WLAN_CAPABILITY_IBSS))
4326 ipw_remove_current_network
4327 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004328
James Ketrenosa613bff2005-08-24 21:43:11 -05004329 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004330
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331 break;
4332 }
4333
James Ketrenosb095c382005-08-24 22:04:42 -05004334 case CMAS_RX_ASSOC_RESP:
4335 break;
4336
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004337 default:
4338 IPW_ERROR("assoc: unknown (%d)\n",
4339 assoc->state);
4340 break;
4341 }
4342
James Ketrenos43f66a62005-03-25 12:31:53 -06004343 break;
4344 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004345
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004346 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4347 struct notif_authenticate *auth = &notif->u.auth;
4348 switch (auth->state) {
4349 case CMAS_AUTHENTICATED:
4350 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4351 "authenticated: '%s' " MAC_FMT " \n",
4352 escape_essid(priv->essid,
4353 priv->essid_len),
4354 MAC_ARG(priv->bssid));
4355 priv->status |= STATUS_AUTH;
4356 break;
4357
4358 case CMAS_INIT:
4359 if (priv->status & STATUS_AUTH) {
4360 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4361 IPW_DL_ASSOC,
4362 "authentication failed (0x%04X): %s\n",
4363 ntohs(auth->status),
4364 ipw_get_status_code(ntohs
4365 (auth->
4366 status)));
4367 }
4368 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4369 IPW_DL_ASSOC,
4370 "deauthenticated: '%s' " MAC_FMT "\n",
4371 escape_essid(priv->essid,
4372 priv->essid_len),
4373 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004374
4375 priv->status &= ~(STATUS_ASSOCIATING |
4376 STATUS_AUTH |
4377 STATUS_ASSOCIATED);
4378
James Ketrenosa613bff2005-08-24 21:43:11 -05004379 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004380 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004381
4382 case CMAS_TX_AUTH_SEQ_1:
4383 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4384 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4385 break;
4386 case CMAS_RX_AUTH_SEQ_2:
4387 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4388 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4389 break;
4390 case CMAS_AUTH_SEQ_1_PASS:
4391 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4392 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4393 break;
4394 case CMAS_AUTH_SEQ_1_FAIL:
4395 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4396 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4397 break;
4398 case CMAS_TX_AUTH_SEQ_3:
4399 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4400 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4401 break;
4402 case CMAS_RX_AUTH_SEQ_4:
4403 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4404 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4405 break;
4406 case CMAS_AUTH_SEQ_2_PASS:
4407 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4408 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4409 break;
4410 case CMAS_AUTH_SEQ_2_FAIL:
4411 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4412 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4413 break;
4414 case CMAS_TX_ASSOC:
4415 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4416 IPW_DL_ASSOC, "TX_ASSOC\n");
4417 break;
4418 case CMAS_RX_ASSOC_RESP:
4419 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4420 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004421
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004422 break;
4423 case CMAS_ASSOCIATED:
4424 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4425 IPW_DL_ASSOC, "ASSOCIATED\n");
4426 break;
4427 default:
4428 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4429 auth->state);
4430 break;
4431 }
4432 break;
4433 }
4434
4435 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4436 struct notif_channel_result *x =
4437 &notif->u.channel_result;
4438
4439 if (notif->size == sizeof(*x)) {
4440 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4441 x->channel_num);
4442 } else {
4443 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4444 "(should be %zd)\n",
4445 notif->size, sizeof(*x));
4446 }
4447 break;
4448 }
4449
4450 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4451 struct notif_scan_complete *x = &notif->u.scan_complete;
4452 if (notif->size == sizeof(*x)) {
4453 IPW_DEBUG_SCAN
4454 ("Scan completed: type %d, %d channels, "
4455 "%d status\n", x->scan_type,
4456 x->num_channels, x->status);
4457 } else {
4458 IPW_ERROR("Scan completed of wrong size %d "
4459 "(should be %zd)\n",
4460 notif->size, sizeof(*x));
4461 }
4462
4463 priv->status &=
4464 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4465
4466 cancel_delayed_work(&priv->scan_check);
4467
James Ketrenosb095c382005-08-24 22:04:42 -05004468 if (priv->status & STATUS_EXIT_PENDING)
4469 break;
4470
4471 priv->ieee->scans++;
4472
4473#ifdef CONFIG_IPW2200_MONITOR
4474 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004475 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004476 queue_work(priv->workqueue,
4477 &priv->request_scan);
4478 break;
4479 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004480 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004481#endif /* CONFIG_IPW2200_MONITOR */
4482
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004483 if (!(priv->status & (STATUS_ASSOCIATED |
4484 STATUS_ASSOCIATING |
4485 STATUS_ROAMING |
4486 STATUS_DISASSOCIATING)))
4487 queue_work(priv->workqueue, &priv->associate);
4488 else if (priv->status & STATUS_ROAMING) {
4489 /* If a scan completed and we are in roam mode, then
4490 * the scan that completed was the one requested as a
4491 * result of entering roam... so, schedule the
4492 * roam work */
4493 queue_work(priv->workqueue, &priv->roam);
4494 } else if (priv->status & STATUS_SCAN_PENDING)
4495 queue_work(priv->workqueue,
4496 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004497 else if (priv->config & CFG_BACKGROUND_SCAN
4498 && priv->status & STATUS_ASSOCIATED)
4499 queue_delayed_work(priv->workqueue,
4500 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004501 break;
4502 }
4503
4504 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4505 struct notif_frag_length *x = &notif->u.frag_len;
4506
James Ketrenosa613bff2005-08-24 21:43:11 -05004507 if (notif->size == sizeof(*x))
4508 IPW_ERROR("Frag length: %d\n",
4509 le16_to_cpu(x->frag_length));
4510 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004511 IPW_ERROR("Frag length of wrong size %d "
4512 "(should be %zd)\n",
4513 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004514 break;
4515 }
4516
4517 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4518 struct notif_link_deterioration *x =
4519 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004520
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004521 if (notif->size == sizeof(*x)) {
4522 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4523 "link deterioration: '%s' " MAC_FMT
4524 " \n", escape_essid(priv->essid,
4525 priv->essid_len),
4526 MAC_ARG(priv->bssid));
4527 memcpy(&priv->last_link_deterioration, x,
4528 sizeof(*x));
4529 } else {
4530 IPW_ERROR("Link Deterioration of wrong size %d "
4531 "(should be %zd)\n",
4532 notif->size, sizeof(*x));
4533 }
4534 break;
4535 }
4536
4537 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4538 IPW_ERROR("Dino config\n");
4539 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004540 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004541 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004542
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004543 break;
4544 }
4545
4546 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4547 struct notif_beacon_state *x = &notif->u.beacon_state;
4548 if (notif->size != sizeof(*x)) {
4549 IPW_ERROR
4550 ("Beacon state of wrong size %d (should "
4551 "be %zd)\n", notif->size, sizeof(*x));
4552 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004553 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004554
James Ketrenosa613bff2005-08-24 21:43:11 -05004555 if (le32_to_cpu(x->state) ==
4556 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4557 ipw_handle_missed_beacon(priv,
4558 le32_to_cpu(x->
4559 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004560
James Ketrenos43f66a62005-03-25 12:31:53 -06004561 break;
4562 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004563
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004564 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4565 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4566 if (notif->size == sizeof(*x)) {
4567 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4568 "0x%02x station %d\n",
4569 x->key_state, x->security_type,
4570 x->station_index);
4571 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004572 }
4573
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004574 IPW_ERROR
4575 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4576 notif->size, sizeof(*x));
4577 break;
4578 }
4579
4580 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4581 struct notif_calibration *x = &notif->u.calibration;
4582
4583 if (notif->size == sizeof(*x)) {
4584 memcpy(&priv->calib, x, sizeof(*x));
4585 IPW_DEBUG_INFO("TODO: Calibration\n");
4586 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004587 }
4588
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004589 IPW_ERROR
4590 ("Calibration of wrong size %d (should be %zd)\n",
4591 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004592 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004593 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004594
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004595 case HOST_NOTIFICATION_NOISE_STATS:{
4596 if (notif->size == sizeof(u32)) {
4597 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004598 (u8) (le32_to_cpu(notif->u.noise.value) &
4599 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004600 average_add(&priv->average_noise,
4601 priv->last_noise);
4602 break;
4603 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004604
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004605 IPW_ERROR
4606 ("Noise stat is wrong size %d (should be %zd)\n",
4607 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004608 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004609 }
4610
James Ketrenos43f66a62005-03-25 12:31:53 -06004611 default:
4612 IPW_ERROR("Unknown notification: "
4613 "subtype=%d,flags=0x%2x,size=%d\n",
4614 notif->subtype, notif->flags, notif->size);
4615 }
4616}
4617
4618/**
4619 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004620 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004621 * @param priv
4622 * @return error code
4623 */
4624static int ipw_queue_reset(struct ipw_priv *priv)
4625{
4626 int rc = 0;
4627 /** @todo customize queue sizes */
4628 int nTx = 64, nTxCmd = 8;
4629 ipw_tx_queue_free(priv);
4630 /* Tx CMD queue */
4631 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004632 IPW_TX_CMD_QUEUE_READ_INDEX,
4633 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4634 IPW_TX_CMD_QUEUE_BD_BASE,
4635 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004636 if (rc) {
4637 IPW_ERROR("Tx Cmd queue init failed\n");
4638 goto error;
4639 }
4640 /* Tx queue(s) */
4641 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004642 IPW_TX_QUEUE_0_READ_INDEX,
4643 IPW_TX_QUEUE_0_WRITE_INDEX,
4644 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004645 if (rc) {
4646 IPW_ERROR("Tx 0 queue init failed\n");
4647 goto error;
4648 }
4649 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004650 IPW_TX_QUEUE_1_READ_INDEX,
4651 IPW_TX_QUEUE_1_WRITE_INDEX,
4652 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004653 if (rc) {
4654 IPW_ERROR("Tx 1 queue init failed\n");
4655 goto error;
4656 }
4657 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004658 IPW_TX_QUEUE_2_READ_INDEX,
4659 IPW_TX_QUEUE_2_WRITE_INDEX,
4660 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004661 if (rc) {
4662 IPW_ERROR("Tx 2 queue init failed\n");
4663 goto error;
4664 }
4665 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004666 IPW_TX_QUEUE_3_READ_INDEX,
4667 IPW_TX_QUEUE_3_WRITE_INDEX,
4668 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004669 if (rc) {
4670 IPW_ERROR("Tx 3 queue init failed\n");
4671 goto error;
4672 }
4673 /* statistics */
4674 priv->rx_bufs_min = 0;
4675 priv->rx_pend_max = 0;
4676 return rc;
4677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004678 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004679 ipw_tx_queue_free(priv);
4680 return rc;
4681}
4682
4683/**
4684 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004685 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004686 * When FW adwances 'R' index, all entries between old and
4687 * new 'R' index need to be reclaimed. As result, some free space
4688 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004689 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004690 * @note Need to protect against garbage in 'R' index
4691 * @param priv
4692 * @param txq
4693 * @param qindex
4694 * @return Number of used entries remains in the queue
4695 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004696static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004697 struct clx2_tx_queue *txq, int qindex)
4698{
4699 u32 hw_tail;
4700 int used;
4701 struct clx2_queue *q = &txq->q;
4702
4703 hw_tail = ipw_read32(priv, q->reg_r);
4704 if (hw_tail >= q->n_bd) {
4705 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004706 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4707 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004708 goto done;
4709 }
4710 for (; q->last_used != hw_tail;
4711 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4712 ipw_queue_tx_free_tfd(priv, txq);
4713 priv->tx_packets++;
4714 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004715 done:
James Ketrenosa613bff2005-08-24 21:43:11 -05004716 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 __maybe_wake_tx(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004718 used = q->first_empty - q->last_used;
4719 if (used < 0)
4720 used += q->n_bd;
4721
4722 return used;
4723}
4724
4725static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4726 int len, int sync)
4727{
4728 struct clx2_tx_queue *txq = &priv->txq_cmd;
4729 struct clx2_queue *q = &txq->q;
4730 struct tfd_frame *tfd;
4731
4732 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4733 IPW_ERROR("No space for Tx\n");
4734 return -EBUSY;
4735 }
4736
4737 tfd = &txq->bd[q->first_empty];
4738 txq->txb[q->first_empty] = NULL;
4739
4740 memset(tfd, 0, sizeof(*tfd));
4741 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4742 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4743 priv->hcmd_seq++;
4744 tfd->u.cmd.index = hcmd;
4745 tfd->u.cmd.length = len;
4746 memcpy(tfd->u.cmd.payload, buf, len);
4747 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4748 ipw_write32(priv, q->reg_w, q->first_empty);
4749 _ipw_read32(priv, 0x90);
4750
4751 return 0;
4752}
4753
Jeff Garzikbf794512005-07-31 13:07:26 -04004754/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004755 * Rx theory of operation
4756 *
4757 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004758 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004759 * 0 to 31
4760 *
4761 * Rx Queue Indexes
4762 * The host/firmware share two index registers for managing the Rx buffers.
4763 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004764 * The READ index maps to the first position that the firmware may be writing
4765 * to -- the driver can read up to (but not including) this position and get
4766 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004767 * The READ index is managed by the firmware once the card is enabled.
4768 *
4769 * The WRITE index maps to the last position the driver has read from -- the
4770 * position preceding WRITE is the last slot the firmware can place a packet.
4771 *
4772 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004773 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004774 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004775 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004776 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4777 *
4778 * When the firmware places a packet in a buffer it will advance the READ index
4779 * and fire the RX interrupt. The driver can then query the READ index and
4780 * process as many packets as possible, moving the WRITE index forward as it
4781 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004782 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004783 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004784 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004785 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004786 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004787 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4788 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4789 * 'processed' and 'read' driver indexes as well)
4790 * + A received packet is processed and handed to the kernel network stack,
4791 * detached from the ipw->rxq. The driver 'processed' index is updated.
4792 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004793 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4794 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004795 * were enough free buffers and RX_STALLED is set it is cleared.
4796 *
4797 *
4798 * Driver sequence:
4799 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004800 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004801 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4802 * ipw_rx_queue_restock
4803 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4804 * queue, updates firmware pointers, and updates
4805 * the WRITE index. If insufficient rx_free buffers
4806 * are available, schedules ipw_rx_queue_replenish
4807 *
4808 * -- enable interrupts --
4809 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004810 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004811 * Moves the packet buffer from queue to rx_used.
4812 * Calls ipw_rx_queue_restock to refill any empty
4813 * slots.
4814 * ...
4815 *
4816 */
4817
Jeff Garzikbf794512005-07-31 13:07:26 -04004818/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004819 * If there are slots in the RX queue that need to be restocked,
4820 * and we have free pre-allocated buffers, fill the ranks as much
4821 * as we can pulling from rx_free.
4822 *
4823 * This moves the 'write' index forward to catch up with 'processed', and
4824 * also updates the memory address in the firmware to reference the new
4825 * target buffer.
4826 */
4827static void ipw_rx_queue_restock(struct ipw_priv *priv)
4828{
4829 struct ipw_rx_queue *rxq = priv->rxq;
4830 struct list_head *element;
4831 struct ipw_rx_mem_buffer *rxb;
4832 unsigned long flags;
4833 int write;
4834
4835 spin_lock_irqsave(&rxq->lock, flags);
4836 write = rxq->write;
4837 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4838 element = rxq->rx_free.next;
4839 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4840 list_del(element);
4841
James Ketrenosb095c382005-08-24 22:04:42 -05004842 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004843 rxb->dma_addr);
4844 rxq->queue[rxq->write] = rxb;
4845 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4846 rxq->free_count--;
4847 }
4848 spin_unlock_irqrestore(&rxq->lock, flags);
4849
Jeff Garzikbf794512005-07-31 13:07:26 -04004850 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004851 * refill it */
4852 if (rxq->free_count <= RX_LOW_WATERMARK)
4853 queue_work(priv->workqueue, &priv->rx_replenish);
4854
4855 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004856 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004857 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004858}
4859
4860/*
4861 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004862 * Also restock the Rx queue via ipw_rx_queue_restock.
4863 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004864 * This is called as a scheduled work item (except for during intialization)
4865 */
4866static void ipw_rx_queue_replenish(void *data)
4867{
4868 struct ipw_priv *priv = data;
4869 struct ipw_rx_queue *rxq = priv->rxq;
4870 struct list_head *element;
4871 struct ipw_rx_mem_buffer *rxb;
4872 unsigned long flags;
4873
4874 spin_lock_irqsave(&rxq->lock, flags);
4875 while (!list_empty(&rxq->rx_used)) {
4876 element = rxq->rx_used.next;
4877 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004878 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004879 if (!rxb->skb) {
4880 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4881 priv->net_dev->name);
4882 /* We don't reschedule replenish work here -- we will
4883 * call the restock method and if it still needs
4884 * more buffers it will schedule replenish */
4885 break;
4886 }
4887 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004888
James Ketrenos43f66a62005-03-25 12:31:53 -06004889 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004890 rxb->dma_addr =
4891 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004892 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004893
James Ketrenos43f66a62005-03-25 12:31:53 -06004894 list_add_tail(&rxb->list, &rxq->rx_free);
4895 rxq->free_count++;
4896 }
4897 spin_unlock_irqrestore(&rxq->lock, flags);
4898
4899 ipw_rx_queue_restock(priv);
4900}
4901
James Ketrenosc848d0a2005-08-24 21:56:24 -05004902static void ipw_bg_rx_queue_replenish(void *data)
4903{
4904 struct ipw_priv *priv = data;
4905 down(&priv->sem);
4906 ipw_rx_queue_replenish(data);
4907 up(&priv->sem);
4908}
4909
James Ketrenos43f66a62005-03-25 12:31:53 -06004910/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4911 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004912 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004913 * non NULL it is unmapped and freed
4914 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004915static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004916{
4917 int i;
4918
4919 if (!rxq)
4920 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004921
James Ketrenos43f66a62005-03-25 12:31:53 -06004922 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4923 if (rxq->pool[i].skb != NULL) {
4924 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004925 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004926 dev_kfree_skb(rxq->pool[i].skb);
4927 }
4928 }
4929
4930 kfree(rxq);
4931}
4932
4933static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4934{
4935 struct ipw_rx_queue *rxq;
4936 int i;
4937
4938 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004939 if (unlikely(!rxq)) {
4940 IPW_ERROR("memory allocation failed\n");
4941 return NULL;
4942 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004943 memset(rxq, 0, sizeof(*rxq));
4944 spin_lock_init(&rxq->lock);
4945 INIT_LIST_HEAD(&rxq->rx_free);
4946 INIT_LIST_HEAD(&rxq->rx_used);
4947
4948 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004949 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004950 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4951
4952 /* Set us so that we have processed and used all buffers, but have
4953 * not restocked the Rx queue with fresh buffers */
4954 rxq->read = rxq->write = 0;
4955 rxq->processed = RX_QUEUE_SIZE - 1;
4956 rxq->free_count = 0;
4957
4958 return rxq;
4959}
4960
4961static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4962{
4963 rate &= ~IEEE80211_BASIC_RATE_MASK;
4964 if (ieee_mode == IEEE_A) {
4965 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004966 case IEEE80211_OFDM_RATE_6MB:
4967 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004968 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004969 case IEEE80211_OFDM_RATE_9MB:
4970 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004971 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004972 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004973 return priv->
4974 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004975 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004976 return priv->
4977 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004978 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004979 return priv->
4980 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004981 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004982 return priv->
4983 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004984 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004985 return priv->
4986 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004987 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004988 return priv->
4989 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004990 default:
4991 return 0;
4992 }
4993 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004994
James Ketrenos43f66a62005-03-25 12:31:53 -06004995 /* B and G mixed */
4996 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004997 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004998 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004999 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005000 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005001 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005002 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005003 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005004 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5005 }
5006
5007 /* If we are limited to B modulations, bail at this point */
5008 if (ieee_mode == IEEE_B)
5009 return 0;
5010
5011 /* G */
5012 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005013 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005014 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005015 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005016 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005017 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005018 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005019 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005020 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005021 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005022 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005025 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005026 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005027 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005028 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5029 }
5030
5031 return 0;
5032}
5033
Jeff Garzikbf794512005-07-31 13:07:26 -04005034static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005035 const struct ieee80211_network *network,
5036 struct ipw_supported_rates *rates)
5037{
5038 int num_rates, i;
5039
5040 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005041 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005042 rates->num_rates = 0;
5043 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005044 if (!ipw_is_rate_in_mask(priv, network->mode,
5045 network->rates[i])) {
5046
James Ketrenosea2b26e2005-08-24 21:25:16 -05005047 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005048 IPW_DEBUG_SCAN("Adding masked mandatory "
5049 "rate %02X\n",
5050 network->rates[i]);
5051 rates->supported_rates[rates->num_rates++] =
5052 network->rates[i];
5053 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005054 }
5055
James Ketrenos43f66a62005-03-25 12:31:53 -06005056 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5057 network->rates[i], priv->rates_mask);
5058 continue;
5059 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005060
James Ketrenos43f66a62005-03-25 12:31:53 -06005061 rates->supported_rates[rates->num_rates++] = network->rates[i];
5062 }
5063
James Ketrenosa613bff2005-08-24 21:43:11 -05005064 num_rates = min(network->rates_ex_len,
5065 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005066 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005067 if (!ipw_is_rate_in_mask(priv, network->mode,
5068 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005069 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005070 IPW_DEBUG_SCAN("Adding masked mandatory "
5071 "rate %02X\n",
5072 network->rates_ex[i]);
5073 rates->supported_rates[rates->num_rates++] =
5074 network->rates[i];
5075 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005076 }
5077
James Ketrenos43f66a62005-03-25 12:31:53 -06005078 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5079 network->rates_ex[i], priv->rates_mask);
5080 continue;
5081 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005082
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005083 rates->supported_rates[rates->num_rates++] =
5084 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005085 }
5086
James Ketrenosea2b26e2005-08-24 21:25:16 -05005087 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005088}
5089
5090static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
5091 const struct ipw_supported_rates *src)
5092{
5093 u8 i;
5094 for (i = 0; i < src->num_rates; i++)
5095 dest->supported_rates[i] = src->supported_rates[i];
5096 dest->num_rates = src->num_rates;
5097}
5098
5099/* TODO: Look at sniffed packets in the air to determine if the basic rate
5100 * mask should ever be used -- right now all callers to add the scan rates are
5101 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5102static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005103 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005104{
Jeff Garzikbf794512005-07-31 13:07:26 -04005105 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005106 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005107
James Ketrenos43f66a62005-03-25 12:31:53 -06005108 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005109 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005110 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005111
5112 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005113 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005114 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005115
5116 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005117 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005118 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005119
5120 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005122 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005123}
5124
5125static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005126 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005127{
Jeff Garzikbf794512005-07-31 13:07:26 -04005128 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005129 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005130
5131 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005132 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005133 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005134
5135 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005136 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005137 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005138
5139 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005140 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005141 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005142
5143 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005144 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005145 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005146
5147 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005148 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005149 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005150
5151 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005153 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005154
5155 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005156 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005157 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005158
5159 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005160 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005161 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005162}
5163
5164struct ipw_network_match {
5165 struct ieee80211_network *network;
5166 struct ipw_supported_rates rates;
5167};
5168
James Ketrenosc848d0a2005-08-24 21:56:24 -05005169static int ipw_find_adhoc_network(struct ipw_priv *priv,
5170 struct ipw_network_match *match,
5171 struct ieee80211_network *network,
5172 int roaming)
5173{
5174 struct ipw_supported_rates rates;
5175
5176 /* Verify that this network's capability is compatible with the
5177 * current mode (AdHoc or Infrastructure) */
5178 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5179 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5180 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5181 "capability mismatch.\n",
5182 escape_essid(network->ssid, network->ssid_len),
5183 MAC_ARG(network->bssid));
5184 return 0;
5185 }
5186
5187 /* If we do not have an ESSID for this AP, we can not associate with
5188 * it */
5189 if (network->flags & NETWORK_EMPTY_ESSID) {
5190 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5191 "because of hidden ESSID.\n",
5192 escape_essid(network->ssid, network->ssid_len),
5193 MAC_ARG(network->bssid));
5194 return 0;
5195 }
5196
5197 if (unlikely(roaming)) {
5198 /* If we are roaming, then ensure check if this is a valid
5199 * network to try and roam to */
5200 if ((network->ssid_len != match->network->ssid_len) ||
5201 memcmp(network->ssid, match->network->ssid,
5202 network->ssid_len)) {
5203 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5204 "because of non-network ESSID.\n",
5205 escape_essid(network->ssid,
5206 network->ssid_len),
5207 MAC_ARG(network->bssid));
5208 return 0;
5209 }
5210 } else {
5211 /* If an ESSID has been configured then compare the broadcast
5212 * ESSID to ours */
5213 if ((priv->config & CFG_STATIC_ESSID) &&
5214 ((network->ssid_len != priv->essid_len) ||
5215 memcmp(network->ssid, priv->essid,
5216 min(network->ssid_len, priv->essid_len)))) {
5217 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005218
James Ketrenosc848d0a2005-08-24 21:56:24 -05005219 strncpy(escaped,
5220 escape_essid(network->ssid, network->ssid_len),
5221 sizeof(escaped));
5222 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5223 "because of ESSID mismatch: '%s'.\n",
5224 escaped, MAC_ARG(network->bssid),
5225 escape_essid(priv->essid,
5226 priv->essid_len));
5227 return 0;
5228 }
5229 }
5230
5231 /* If the old network rate is better than this one, don't bother
5232 * testing everything else. */
5233
5234 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005235 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5236 "current network.\n",
5237 escape_essid(match->network->ssid,
5238 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005239 return 0;
5240 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005241 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5242 "current network.\n",
5243 escape_essid(match->network->ssid,
5244 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005245 return 0;
5246 }
5247
5248 /* Now go through and see if the requested network is valid... */
5249 if (priv->ieee->scan_age != 0 &&
5250 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5251 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5252 "because of age: %lums.\n",
5253 escape_essid(network->ssid, network->ssid_len),
5254 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005255 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005256 return 0;
5257 }
5258
5259 if ((priv->config & CFG_STATIC_CHANNEL) &&
5260 (network->channel != priv->channel)) {
5261 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5262 "because of channel mismatch: %d != %d.\n",
5263 escape_essid(network->ssid, network->ssid_len),
5264 MAC_ARG(network->bssid),
5265 network->channel, priv->channel);
5266 return 0;
5267 }
5268
5269 /* Verify privacy compatability */
5270 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5271 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5272 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5273 "because of privacy mismatch: %s != %s.\n",
5274 escape_essid(network->ssid, network->ssid_len),
5275 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005276 priv->
5277 capability & CAP_PRIVACY_ON ? "on" : "off",
5278 network->
5279 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5280 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005281 return 0;
5282 }
5283
5284 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5285 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5286 "because of the same BSSID match: " MAC_FMT
5287 ".\n", escape_essid(network->ssid,
5288 network->ssid_len),
5289 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5290 return 0;
5291 }
5292
5293 /* Filter out any incompatible freq / mode combinations */
5294 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5295 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5296 "because of invalid frequency/mode "
5297 "combination.\n",
5298 escape_essid(network->ssid, network->ssid_len),
5299 MAC_ARG(network->bssid));
5300 return 0;
5301 }
5302
5303 /* Ensure that the rates supported by the driver are compatible with
5304 * this AP, including verification of basic rates (mandatory) */
5305 if (!ipw_compatible_rates(priv, network, &rates)) {
5306 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5307 "because configured rate mask excludes "
5308 "AP mandatory rate.\n",
5309 escape_essid(network->ssid, network->ssid_len),
5310 MAC_ARG(network->bssid));
5311 return 0;
5312 }
5313
5314 if (rates.num_rates == 0) {
5315 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5316 "because of no compatible rates.\n",
5317 escape_essid(network->ssid, network->ssid_len),
5318 MAC_ARG(network->bssid));
5319 return 0;
5320 }
5321
5322 /* TODO: Perform any further minimal comparititive tests. We do not
5323 * want to put too much policy logic here; intelligent scan selection
5324 * should occur within a generic IEEE 802.11 user space tool. */
5325
5326 /* Set up 'new' AP to this network */
5327 ipw_copy_rates(&match->rates, &rates);
5328 match->network = network;
5329 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5330 escape_essid(network->ssid, network->ssid_len),
5331 MAC_ARG(network->bssid));
5332
5333 return 1;
5334}
5335
5336static void ipw_merge_adhoc_network(void *data)
5337{
5338 struct ipw_priv *priv = data;
5339 struct ieee80211_network *network = NULL;
5340 struct ipw_network_match match = {
5341 .network = priv->assoc_network
5342 };
5343
James Ketrenosafbf30a2005-08-25 00:05:33 -05005344 if ((priv->status & STATUS_ASSOCIATED) &&
5345 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005346 /* First pass through ROAM process -- look for a better
5347 * network */
5348 unsigned long flags;
5349
5350 spin_lock_irqsave(&priv->ieee->lock, flags);
5351 list_for_each_entry(network, &priv->ieee->network_list, list) {
5352 if (network != priv->assoc_network)
5353 ipw_find_adhoc_network(priv, &match, network,
5354 1);
5355 }
5356 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5357
5358 if (match.network == priv->assoc_network) {
5359 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5360 "merge to.\n");
5361 return;
5362 }
5363
5364 down(&priv->sem);
5365 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5366 IPW_DEBUG_MERGE("remove network %s\n",
5367 escape_essid(priv->essid,
5368 priv->essid_len));
5369 ipw_remove_current_network(priv);
5370 }
5371
5372 ipw_disassociate(priv);
5373 priv->assoc_network = match.network;
5374 up(&priv->sem);
5375 return;
5376 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005377}
5378
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005379static int ipw_best_network(struct ipw_priv *priv,
5380 struct ipw_network_match *match,
5381 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005382{
5383 struct ipw_supported_rates rates;
5384
5385 /* Verify that this network's capability is compatible with the
5386 * current mode (AdHoc or Infrastructure) */
5387 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005388 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005389 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5390 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5391 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005392 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005393 escape_essid(network->ssid, network->ssid_len),
5394 MAC_ARG(network->bssid));
5395 return 0;
5396 }
5397
5398 /* If we do not have an ESSID for this AP, we can not associate with
5399 * it */
5400 if (network->flags & NETWORK_EMPTY_ESSID) {
5401 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5402 "because of hidden ESSID.\n",
5403 escape_essid(network->ssid, network->ssid_len),
5404 MAC_ARG(network->bssid));
5405 return 0;
5406 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005407
James Ketrenos43f66a62005-03-25 12:31:53 -06005408 if (unlikely(roaming)) {
5409 /* If we are roaming, then ensure check if this is a valid
5410 * network to try and roam to */
5411 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005412 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005413 network->ssid_len)) {
5414 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5415 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005416 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005417 network->ssid_len),
5418 MAC_ARG(network->bssid));
5419 return 0;
5420 }
5421 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005422 /* If an ESSID has been configured then compare the broadcast
5423 * ESSID to ours */
5424 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005425 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005426 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005427 min(network->ssid_len, priv->essid_len)))) {
5428 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005429 strncpy(escaped,
5430 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005431 sizeof(escaped));
5432 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005433 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005434 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005435 escape_essid(priv->essid,
5436 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005437 return 0;
5438 }
5439 }
5440
5441 /* If the old network rate is better than this one, don't bother
5442 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005443 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005444 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 strncpy(escaped,
5446 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005447 sizeof(escaped));
5448 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5449 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5450 escaped, MAC_ARG(network->bssid),
5451 escape_essid(match->network->ssid,
5452 match->network->ssid_len),
5453 MAC_ARG(match->network->bssid));
5454 return 0;
5455 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005456
James Ketrenos43f66a62005-03-25 12:31:53 -06005457 /* If this network has already had an association attempt within the
5458 * last 3 seconds, do not try and associate again... */
5459 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005460 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005461 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
James Ketrenosafbf30a2005-08-25 00:05:33 -05005462 "because of storming (%lus since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005463 "assoc attempt).\n",
5464 escape_essid(network->ssid, network->ssid_len),
5465 MAC_ARG(network->bssid),
5466 (jiffies - network->last_associate) / HZ);
5467 return 0;
5468 }
5469
5470 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005471 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005472 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005473 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5474 "because of age: %lums.\n",
5475 escape_essid(network->ssid, network->ssid_len),
5476 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005477 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06005478 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005479 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005480
Jeff Garzikbf794512005-07-31 13:07:26 -04005481 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005482 (network->channel != priv->channel)) {
5483 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5484 "because of channel mismatch: %d != %d.\n",
5485 escape_essid(network->ssid, network->ssid_len),
5486 MAC_ARG(network->bssid),
5487 network->channel, priv->channel);
5488 return 0;
5489 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005490
James Ketrenos43f66a62005-03-25 12:31:53 -06005491 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005492 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005493 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5494 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5495 "because of privacy mismatch: %s != %s.\n",
5496 escape_essid(network->ssid, network->ssid_len),
5497 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005498 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005499 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005500 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005501 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005502 return 0;
5503 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005504
5505 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005506 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5507 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5508 "because of BSSID mismatch: " MAC_FMT ".\n",
5509 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005510 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005511 return 0;
5512 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005513
James Ketrenos43f66a62005-03-25 12:31:53 -06005514 /* Filter out any incompatible freq / mode combinations */
5515 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5516 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5517 "because of invalid frequency/mode "
5518 "combination.\n",
5519 escape_essid(network->ssid, network->ssid_len),
5520 MAC_ARG(network->bssid));
5521 return 0;
5522 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005523
James Ketrenosea2b26e2005-08-24 21:25:16 -05005524 /* Ensure that the rates supported by the driver are compatible with
5525 * this AP, including verification of basic rates (mandatory) */
5526 if (!ipw_compatible_rates(priv, network, &rates)) {
5527 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5528 "because configured rate mask excludes "
5529 "AP mandatory rate.\n",
5530 escape_essid(network->ssid, network->ssid_len),
5531 MAC_ARG(network->bssid));
5532 return 0;
5533 }
5534
James Ketrenos43f66a62005-03-25 12:31:53 -06005535 if (rates.num_rates == 0) {
5536 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5537 "because of no compatible rates.\n",
5538 escape_essid(network->ssid, network->ssid_len),
5539 MAC_ARG(network->bssid));
5540 return 0;
5541 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005542
James Ketrenos43f66a62005-03-25 12:31:53 -06005543 /* TODO: Perform any further minimal comparititive tests. We do not
5544 * want to put too much policy logic here; intelligent scan selection
5545 * should occur within a generic IEEE 802.11 user space tool. */
5546
5547 /* Set up 'new' AP to this network */
5548 ipw_copy_rates(&match->rates, &rates);
5549 match->network = network;
5550
5551 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5552 escape_essid(network->ssid, network->ssid_len),
5553 MAC_ARG(network->bssid));
5554
5555 return 1;
5556}
5557
Jeff Garzikbf794512005-07-31 13:07:26 -04005558static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005559 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005560{
James Ketrenosafbf30a2005-08-25 00:05:33 -05005561 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5562 int i;
5563
James Ketrenos43f66a62005-03-25 12:31:53 -06005564 /*
5565 * For the purposes of scanning, we can set our wireless mode
5566 * to trigger scans across combinations of bands, but when it
5567 * comes to creating a new ad-hoc network, we have tell the FW
5568 * exactly which band to use.
5569 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005570 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005571 * chossen band. Attempting to create a new ad-hoc network
5572 * with an invalid channel for wireless mode will trigger a
5573 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005574 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005575 */
James Ketrenosafbf30a2005-08-25 00:05:33 -05005576 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5577 case IEEE80211_52GHZ_BAND:
5578 network->mode = IEEE_A;
5579 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5580 if (i == -1)
5581 BUG();
5582 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5583 IPW_WARNING("Overriding invalid channel\n");
5584 priv->channel = geo->a[0].channel;
5585 }
5586 break;
5587
5588 case IEEE80211_24GHZ_BAND:
5589 if (priv->ieee->mode & IEEE_G)
5590 network->mode = IEEE_G;
5591 else
5592 network->mode = IEEE_B;
5593 break;
5594
5595 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005596 IPW_WARNING("Overriding invalid channel\n");
5597 if (priv->ieee->mode & IEEE_A) {
5598 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005599 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005600 } else if (priv->ieee->mode & IEEE_G) {
5601 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005602 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005603 } else {
5604 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005605 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005606 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005607 break;
5608 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005609
5610 network->channel = priv->channel;
5611 priv->config |= CFG_ADHOC_PERSIST;
5612 ipw_create_bssid(priv, network->bssid);
5613 network->ssid_len = priv->essid_len;
5614 memcpy(network->ssid, priv->essid, priv->essid_len);
5615 memset(&network->stats, 0, sizeof(network->stats));
5616 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005617 if (!(priv->config & CFG_PREAMBLE_LONG))
5618 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005619 if (priv->capability & CAP_PRIVACY_ON)
5620 network->capability |= WLAN_CAPABILITY_PRIVACY;
5621 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005622 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005623 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005624 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005625 &priv->rates.supported_rates[network->rates_len],
5626 network->rates_ex_len);
5627 network->last_scanned = 0;
5628 network->flags = 0;
5629 network->last_associate = 0;
5630 network->time_stamp[0] = 0;
5631 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005632 network->beacon_interval = 100; /* Default */
5633 network->listen_interval = 10; /* Default */
5634 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005635 network->wpa_ie_len = 0;
5636 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005637}
5638
James Ketrenosb095c382005-08-24 22:04:42 -05005639static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5640{
5641 struct ipw_tgi_tx_key *key;
5642 struct host_cmd cmd = {
5643 .cmd = IPW_CMD_TGI_TX_KEY,
5644 .len = sizeof(*key)
5645 };
5646
5647 if (!(priv->ieee->sec.flags & (1 << index)))
5648 return;
5649
5650 key = (struct ipw_tgi_tx_key *)&cmd.param;
5651 key->key_id = index;
5652 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5653 key->security_type = type;
5654 key->station_index = 0; /* always 0 for BSS */
5655 key->flags = 0;
5656 /* 0 for new key; previous value of counter (after fatal error) */
5657 key->tx_counter[0] = 0;
5658 key->tx_counter[1] = 0;
5659
5660 if (ipw_send_cmd(priv, &cmd)) {
5661 IPW_ERROR("failed to send TGI_TX_KEY command\n");
5662 return;
5663 }
5664}
5665
5666static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005667{
5668 struct ipw_wep_key *key;
5669 int i;
5670 struct host_cmd cmd = {
5671 .cmd = IPW_CMD_WEP_KEY,
5672 .len = sizeof(*key)
5673 };
5674
5675 key = (struct ipw_wep_key *)&cmd.param;
5676 key->cmd_id = DINO_CMD_WEP_KEY;
5677 key->seq_num = 0;
5678
James Ketrenosb095c382005-08-24 22:04:42 -05005679 /* Note: AES keys cannot be set for multiple times.
5680 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005681 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005682 key->key_index = i | type;
5683 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005684 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005685 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005686 }
5687
James Ketrenosb095c382005-08-24 22:04:42 -05005688 key->key_size = priv->ieee->sec.key_sizes[i];
5689 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5690
James Ketrenos43f66a62005-03-25 12:31:53 -06005691 if (ipw_send_cmd(priv, &cmd)) {
5692 IPW_ERROR("failed to send WEP_KEY command\n");
5693 return;
5694 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005695 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005696}
5697
Zhu Yi1fbfea52005-08-05 17:22:56 +08005698static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5699{
5700 if (priv->ieee->host_encrypt)
5701 return;
5702
5703 switch (level) {
5704 case SEC_LEVEL_3:
5705 priv->sys_config.disable_unicast_decryption = 0;
5706 priv->ieee->host_decrypt = 0;
5707 break;
5708 case SEC_LEVEL_2:
5709 priv->sys_config.disable_unicast_decryption = 1;
5710 priv->ieee->host_decrypt = 1;
5711 break;
5712 case SEC_LEVEL_1:
5713 priv->sys_config.disable_unicast_decryption = 0;
5714 priv->ieee->host_decrypt = 0;
5715 break;
5716 case SEC_LEVEL_0:
5717 priv->sys_config.disable_unicast_decryption = 1;
5718 break;
5719 default:
5720 break;
5721 }
5722}
5723
5724static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5725{
5726 if (priv->ieee->host_encrypt)
5727 return;
5728
5729 switch (level) {
5730 case SEC_LEVEL_3:
5731 priv->sys_config.disable_multicast_decryption = 0;
5732 break;
5733 case SEC_LEVEL_2:
5734 priv->sys_config.disable_multicast_decryption = 1;
5735 break;
5736 case SEC_LEVEL_1:
5737 priv->sys_config.disable_multicast_decryption = 0;
5738 break;
5739 case SEC_LEVEL_0:
5740 priv->sys_config.disable_multicast_decryption = 1;
5741 break;
5742 default:
5743 break;
5744 }
5745}
5746
James Ketrenosb095c382005-08-24 22:04:42 -05005747static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5748{
5749 switch (priv->ieee->sec.level) {
5750 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005751 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5752 ipw_send_tgi_tx_key(priv,
5753 DCT_FLAG_EXT_SECURITY_CCM,
5754 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005755
James Ketrenosb095c382005-08-24 22:04:42 -05005756 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005757 break;
5758 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005759 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5760 ipw_send_tgi_tx_key(priv,
5761 DCT_FLAG_EXT_SECURITY_TKIP,
5762 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005763 break;
5764 case SEC_LEVEL_1:
5765 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenosb095c382005-08-24 22:04:42 -05005766 break;
5767 case SEC_LEVEL_0:
5768 default:
5769 break;
5770 }
Zhu Yi1fbfea52005-08-05 17:22:56 +08005771
5772 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5773 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005774}
5775
James Ketrenos43f66a62005-03-25 12:31:53 -06005776static void ipw_adhoc_check(void *data)
5777{
5778 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005779
James Ketrenosafbf30a2005-08-25 00:05:33 -05005780 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005781 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005782 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5783 IPW_DL_STATE | IPW_DL_ASSOC,
5784 "Missed beacon: %d - disassociate\n",
5785 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005786 ipw_remove_current_network(priv);
5787 ipw_disassociate(priv);
5788 return;
5789 }
5790
Jeff Garzikbf794512005-07-31 13:07:26 -04005791 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005792 priv->assoc_request.beacon_interval);
5793}
5794
James Ketrenosc848d0a2005-08-24 21:56:24 -05005795static void ipw_bg_adhoc_check(void *data)
5796{
5797 struct ipw_priv *priv = data;
5798 down(&priv->sem);
5799 ipw_adhoc_check(data);
5800 up(&priv->sem);
5801}
5802
James Ketrenos43f66a62005-03-25 12:31:53 -06005803#ifdef CONFIG_IPW_DEBUG
5804static void ipw_debug_config(struct ipw_priv *priv)
5805{
5806 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5807 "[CFG 0x%08X]\n", priv->config);
5808 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005809 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005810 else
5811 IPW_DEBUG_INFO("Channel unlocked.\n");
5812 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005813 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005814 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 else
5816 IPW_DEBUG_INFO("ESSID unlocked.\n");
5817 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005818 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5819 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 else
5821 IPW_DEBUG_INFO("BSSID unlocked.\n");
5822 if (priv->capability & CAP_PRIVACY_ON)
5823 IPW_DEBUG_INFO("PRIVACY on\n");
5824 else
5825 IPW_DEBUG_INFO("PRIVACY off\n");
5826 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5827}
5828#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005829#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005830#endif
5831
James Ketrenosb095c382005-08-24 22:04:42 -05005832static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005833{
5834 /* TODO: Verify that this works... */
5835 struct ipw_fixed_rate fr = {
5836 .tx_rates = priv->rates_mask
5837 };
5838 u32 reg;
5839 u16 mask = 0;
5840
Jeff Garzikbf794512005-07-31 13:07:26 -04005841 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005842 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005843
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005845 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005846 /* IEEE_A */
5847 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5848 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005849 IPW_DEBUG_WX
5850 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005851 fr.tx_rates = 0;
5852 break;
5853 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005854
James Ketrenos43f66a62005-03-25 12:31:53 -06005855 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5856 break;
5857
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005858 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005859 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005860 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005861 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5862 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005863 IPW_DEBUG_WX
5864 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005865 fr.tx_rates = 0;
5866 }
5867 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005868 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005869
5870 /* IEEE_G */
5871 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5872 IEEE80211_OFDM_RATES_MASK)) {
5873 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005874 IPW_DEBUG_WX
5875 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005876 fr.tx_rates = 0;
5877 break;
5878 }
5879
5880 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5881 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5882 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5883 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005884
James Ketrenos43f66a62005-03-25 12:31:53 -06005885 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5886 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5887 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5888 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005889
James Ketrenos43f66a62005-03-25 12:31:53 -06005890 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5891 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5892 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5893 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005894
James Ketrenos43f66a62005-03-25 12:31:53 -06005895 fr.tx_rates |= mask;
5896 break;
5897 }
5898
5899 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005900 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005901}
5902
James Ketrenosea2b26e2005-08-24 21:25:16 -05005903static void ipw_abort_scan(struct ipw_priv *priv)
5904{
5905 int err;
5906
5907 if (priv->status & STATUS_SCAN_ABORTING) {
5908 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5909 return;
5910 }
5911 priv->status |= STATUS_SCAN_ABORTING;
5912
5913 err = ipw_send_scan_abort(priv);
5914 if (err)
5915 IPW_DEBUG_HC("Request to abort scan failed.\n");
5916}
5917
James Ketrenosafbf30a2005-08-25 00:05:33 -05005918static void ipw_add_scan_channels(struct ipw_priv *priv,
5919 struct ipw_scan_request_ext *scan,
5920 int scan_type)
5921{
5922 int channel_index = 0;
5923 const struct ieee80211_geo *geo;
5924 int i;
5925
5926 geo = ieee80211_get_geo(priv->ieee);
5927
5928 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5929 int start = channel_index;
5930 for (i = 0; i < geo->a_channels; i++) {
5931 if ((priv->status & STATUS_ASSOCIATED) &&
5932 geo->a[i].channel == priv->channel)
5933 continue;
5934 channel_index++;
5935 scan->channels_list[channel_index] = geo->a[i].channel;
5936 ipw_set_scan_type(scan, channel_index, scan_type);
5937 }
5938
5939 if (start != channel_index) {
5940 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5941 (channel_index - start);
5942 channel_index++;
5943 }
5944 }
5945
5946 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5947 int start = channel_index;
5948 if (priv->config & CFG_SPEED_SCAN) {
5949 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5950 /* nop out the list */
5951 [0] = 0
5952 };
5953
5954 u8 channel;
5955 while (channel_index < IPW_SCAN_CHANNELS) {
5956 channel =
5957 priv->speed_scan[priv->speed_scan_pos];
5958 if (channel == 0) {
5959 priv->speed_scan_pos = 0;
5960 channel = priv->speed_scan[0];
5961 }
5962 if ((priv->status & STATUS_ASSOCIATED) &&
5963 channel == priv->channel) {
5964 priv->speed_scan_pos++;
5965 continue;
5966 }
5967
5968 /* If this channel has already been
5969 * added in scan, break from loop
5970 * and this will be the first channel
5971 * in the next scan.
5972 */
5973 if (channels[channel - 1] != 0)
5974 break;
5975
5976 channels[channel - 1] = 1;
5977 priv->speed_scan_pos++;
5978 channel_index++;
5979 scan->channels_list[channel_index] = channel;
5980 ipw_set_scan_type(scan, channel_index,
5981 scan_type);
5982 }
5983 } else {
5984 for (i = 0; i < geo->bg_channels; i++) {
5985 if ((priv->status & STATUS_ASSOCIATED) &&
5986 geo->bg[i].channel == priv->channel)
5987 continue;
5988 channel_index++;
5989 scan->channels_list[channel_index] =
5990 geo->bg[i].channel;
5991 ipw_set_scan_type(scan, channel_index,
5992 scan_type);
5993 }
5994 }
5995
5996 if (start != channel_index) {
5997 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
5998 (channel_index - start);
5999 }
6000 }
6001}
6002
James Ketrenosea2b26e2005-08-24 21:25:16 -05006003static int ipw_request_scan(struct ipw_priv *priv)
6004{
6005 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006006 int err = 0, scan_type;
6007
6008 if (!(priv->status & STATUS_INIT) ||
6009 (priv->status & STATUS_EXIT_PENDING))
6010 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006011
James Ketrenosb095c382005-08-24 22:04:42 -05006012 down(&priv->sem);
6013
James Ketrenosea2b26e2005-08-24 21:25:16 -05006014 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006015 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006016 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006017 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006018 }
6019
James Ketrenosafbf30a2005-08-25 00:05:33 -05006020 if (!(priv->status & STATUS_SCAN_FORCED) &&
6021 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006022 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6023 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006024 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006025 }
6026
6027 if (priv->status & STATUS_RF_KILL_MASK) {
6028 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6029 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006030 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006031 }
6032
6033 memset(&scan, 0, sizeof(scan));
6034
James Ketrenosb095c382005-08-24 22:04:42 -05006035 if (priv->config & CFG_SPEED_SCAN)
6036 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6037 cpu_to_le16(30);
6038 else
6039 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6040 cpu_to_le16(20);
6041
James Ketrenosa613bff2005-08-24 21:43:11 -05006042 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6043 cpu_to_le16(20);
6044 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006045
James Ketrenosa613bff2005-08-24 21:43:11 -05006046 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006047
James Ketrenosb095c382005-08-24 22:04:42 -05006048#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006049 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006050 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006051 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006052
James Ketrenosb095c382005-08-24 22:04:42 -05006053 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
6054 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006055 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006056 channel = priv->channel;
6057 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006058
James Ketrenosb095c382005-08-24 22:04:42 -05006059 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006060 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006061 channel = priv->channel;
6062 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006063
James Ketrenosb095c382005-08-24 22:04:42 -05006064 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006065 band = (u8) (IPW_B_MODE << 6) | 1;
6066 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006067 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006068 }
6069
James Ketrenosb095c382005-08-24 22:04:42 -05006070 scan.channels_list[0] = band;
6071 scan.channels_list[1] = channel;
6072 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006073
James Ketrenosb095c382005-08-24 22:04:42 -05006074 /* NOTE: The card will sit on this channel for this time
6075 * period. Scan aborts are timing sensitive and frequently
6076 * result in firmware restarts. As such, it is best to
6077 * set a small dwell_time here and just keep re-issuing
6078 * scans. Otherwise fast channel hopping will not actually
6079 * hop channels.
6080 *
6081 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006082 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6083 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006084 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006085#endif /* CONFIG_IPW2200_MONITOR */
6086 /* If we are roaming, then make this a directed scan for the
6087 * current network. Otherwise, ensure that every other scan
6088 * is a fast channel hop scan */
6089 if ((priv->status & STATUS_ROAMING)
6090 || (!(priv->status & STATUS_ASSOCIATED)
6091 && (priv->config & CFG_STATIC_ESSID)
6092 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006093 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6094 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006095 IPW_DEBUG_HC("Attempt to send SSID command "
6096 "failed.\n");
6097 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006098 }
6099
6100 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006101 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006102 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006103
James Ketrenosafbf30a2005-08-25 00:05:33 -05006104 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006105#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006106 }
6107#endif
6108
6109 err = ipw_send_scan_request_ext(priv, &scan);
6110 if (err) {
6111 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006112 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006113 }
6114
6115 priv->status |= STATUS_SCANNING;
6116 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006117 queue_delayed_work(priv->workqueue, &priv->scan_check,
6118 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006119 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006120 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006121 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006122}
6123
6124static void ipw_bg_abort_scan(void *data)
6125{
6126 struct ipw_priv *priv = data;
6127 down(&priv->sem);
6128 ipw_abort_scan(data);
6129 up(&priv->sem);
6130}
6131
James Ketrenosafbf30a2005-08-25 00:05:33 -05006132#if WIRELESS_EXT < 18
6133/* Support for wpa_supplicant before WE-18, deprecated. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006134
6135/* following definitions must match definitions in driver_ipw.c */
6136
6137#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
6138
6139#define IPW_CMD_SET_WPA_PARAM 1
6140#define IPW_CMD_SET_WPA_IE 2
6141#define IPW_CMD_SET_ENCRYPTION 3
6142#define IPW_CMD_MLME 4
6143
6144#define IPW_PARAM_WPA_ENABLED 1
6145#define IPW_PARAM_TKIP_COUNTERMEASURES 2
6146#define IPW_PARAM_DROP_UNENCRYPTED 3
6147#define IPW_PARAM_PRIVACY_INVOKED 4
6148#define IPW_PARAM_AUTH_ALGS 5
6149#define IPW_PARAM_IEEE_802_1X 6
6150
6151#define IPW_MLME_STA_DEAUTH 1
6152#define IPW_MLME_STA_DISASSOC 2
6153
6154#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
6155#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
6156#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
6157#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
6158#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
6159#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
6160
6161#define IPW_CRYPT_ALG_NAME_LEN 16
6162
6163struct ipw_param {
6164 u32 cmd;
6165 u8 sta_addr[ETH_ALEN];
6166 union {
6167 struct {
6168 u8 name;
6169 u32 value;
6170 } wpa_param;
6171 struct {
6172 u32 len;
James Ketrenosb095c382005-08-24 22:04:42 -05006173 u8 reserved[32];
6174 u8 data[0];
James Ketrenosea2b26e2005-08-24 21:25:16 -05006175 } wpa_ie;
6176 struct {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006177 u32 command;
6178 u32 reason_code;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006179 } mlme;
6180 struct {
6181 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
6182 u8 set_tx;
6183 u32 err;
6184 u8 idx;
6185 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
6186 u16 key_len;
6187 u8 key[0];
6188 } crypt;
6189
6190 } u;
6191};
6192
6193/* end of driver_ipw.c code */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006194#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195
6196static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6197{
James Ketrenosb095c382005-08-24 22:04:42 -05006198 /* This is called when wpa_supplicant loads and closes the driver
6199 * interface. */
6200 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006201}
6202
James Ketrenosafbf30a2005-08-25 00:05:33 -05006203#if WIRELESS_EXT < 18
6204#define IW_AUTH_ALG_OPEN_SYSTEM 0x1
6205#define IW_AUTH_ALG_SHARED_KEY 0x2
6206#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006207
6208static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6209{
6210 struct ieee80211_device *ieee = priv->ieee;
6211 struct ieee80211_security sec = {
6212 .flags = SEC_AUTH_MODE,
6213 };
6214 int ret = 0;
6215
James Ketrenosafbf30a2005-08-25 00:05:33 -05006216 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006217 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6218 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006219 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006220 sec.auth_mode = WLAN_AUTH_OPEN;
6221 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006222 } else
6223 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006224
6225 if (ieee->set_security)
6226 ieee->set_security(ieee->dev, &sec);
6227 else
6228 ret = -EOPNOTSUPP;
6229
6230 return ret;
6231}
6232
James Ketrenosafbf30a2005-08-25 00:05:33 -05006233void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6234{
6235 /* make sure WPA is enabled */
6236 ipw_wpa_enable(priv, 1);
6237
6238 ipw_disassociate(priv);
6239}
6240
6241static int ipw_set_rsn_capa(struct ipw_priv *priv,
6242 char *capabilities, int length)
6243{
6244 struct host_cmd cmd = {
6245 .cmd = IPW_CMD_RSN_CAPABILITIES,
6246 .len = length,
6247 };
6248
6249 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6250
6251 memcpy(cmd.param, capabilities, length);
6252 if (ipw_send_cmd(priv, &cmd)) {
6253 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
6254 return -1;
6255 }
6256 return 0;
6257}
6258
6259#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -05006260static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
6261{
6262 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05006263 struct ieee80211_crypt_data *crypt;
6264 unsigned long flags;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006265 int ret = 0;
6266
6267 switch (name) {
6268 case IPW_PARAM_WPA_ENABLED:
6269 ret = ipw_wpa_enable(priv, value);
6270 break;
6271
6272 case IPW_PARAM_TKIP_COUNTERMEASURES:
James Ketrenosa613bff2005-08-24 21:43:11 -05006273 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6274 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6275 IPW_WARNING("Can't set TKIP countermeasures: "
6276 "crypt not set!\n");
6277 break;
6278 }
6279
6280 flags = crypt->ops->get_flags(crypt->priv);
6281
6282 if (value)
6283 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6284 else
6285 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6286
6287 crypt->ops->set_flags(flags, crypt->priv);
6288
James Ketrenosea2b26e2005-08-24 21:25:16 -05006289 break;
6290
James Ketrenosb095c382005-08-24 22:04:42 -05006291 case IPW_PARAM_DROP_UNENCRYPTED:{
6292 /* HACK:
6293 *
6294 * wpa_supplicant calls set_wpa_enabled when the driver
6295 * is loaded and unloaded, regardless of if WPA is being
6296 * used. No other calls are made which can be used to
6297 * determine if encryption will be used or not prior to
6298 * association being expected. If encryption is not being
6299 * used, drop_unencrypted is set to false, else true -- we
6300 * can use this to determine if the CAP_PRIVACY_ON bit should
6301 * be set.
6302 */
6303 struct ieee80211_security sec = {
6304 .flags = SEC_ENABLED,
6305 .enabled = value,
6306 };
6307 priv->ieee->drop_unencrypted = value;
6308 /* We only change SEC_LEVEL for open mode. Others
6309 * are set by ipw_wpa_set_encryption.
6310 */
6311 if (!value) {
6312 sec.flags |= SEC_LEVEL;
6313 sec.level = SEC_LEVEL_0;
6314 } else {
6315 sec.flags |= SEC_LEVEL;
6316 sec.level = SEC_LEVEL_1;
6317 }
6318 if (priv->ieee->set_security)
6319 priv->ieee->set_security(priv->ieee->dev, &sec);
6320 break;
6321 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05006322
6323 case IPW_PARAM_PRIVACY_INVOKED:
6324 priv->ieee->privacy_invoked = value;
6325 break;
6326
6327 case IPW_PARAM_AUTH_ALGS:
6328 ret = ipw_wpa_set_auth_algs(priv, value);
6329 break;
6330
6331 case IPW_PARAM_IEEE_802_1X:
6332 priv->ieee->ieee802_1x = value;
6333 break;
6334
6335 default:
6336 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
6337 ret = -EOPNOTSUPP;
6338 }
6339
6340 return ret;
6341}
6342
6343static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
6344{
6345 struct ipw_priv *priv = ieee80211_priv(dev);
6346 int ret = 0;
6347
6348 switch (command) {
6349 case IPW_MLME_STA_DEAUTH:
6350 // silently ignore
6351 break;
6352
6353 case IPW_MLME_STA_DISASSOC:
6354 ipw_disassociate(priv);
6355 break;
6356
6357 default:
6358 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
6359 ret = -EOPNOTSUPP;
6360 }
6361
6362 return ret;
6363}
6364
Zhu Yi1fbfea52005-08-05 17:22:56 +08006365static int ipw_wpa_ie_cipher2level(u8 cipher)
6366{
6367 switch (cipher) {
6368 case 4: /* CCMP */
6369 return SEC_LEVEL_3;
6370 case 2: /* TKIP */
6371 return SEC_LEVEL_2;
6372 case 5: /* WEP104 */
6373 case 1: /* WEP40 */
6374 return SEC_LEVEL_1;
6375 case 0: /* NONE */
6376 return SEC_LEVEL_0;
6377 default:
6378 return -1;
6379 }
6380}
6381
James Ketrenosea2b26e2005-08-24 21:25:16 -05006382static int ipw_wpa_set_wpa_ie(struct net_device *dev,
6383 struct ipw_param *param, int plen)
6384{
6385 struct ipw_priv *priv = ieee80211_priv(dev);
6386 struct ieee80211_device *ieee = priv->ieee;
6387 u8 *buf;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006388 u8 *ptk, *gtk;
6389 int level;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006390
James Ketrenosea2b26e2005-08-24 21:25:16 -05006391 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
6392 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
6393 return -EINVAL;
6394
6395 if (param->u.wpa_ie.len) {
6396 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
6397 if (buf == NULL)
6398 return -ENOMEM;
6399
6400 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
6401 kfree(ieee->wpa_ie);
6402 ieee->wpa_ie = buf;
6403 ieee->wpa_ie_len = param->u.wpa_ie.len;
6404 } else {
6405 kfree(ieee->wpa_ie);
6406 ieee->wpa_ie = NULL;
6407 ieee->wpa_ie_len = 0;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006408 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006409 }
6410
Zhu Yi1fbfea52005-08-05 17:22:56 +08006411 if (priv->ieee->host_encrypt)
6412 goto done;
6413
6414 /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
6415 * we need to change driver_ipw.c from wpa_supplicant. This
6416 * is OK since -Dipw is deprecated. The -Dwext driver has a
6417 * clean way to handle this. */
6418 gtk = ptk = (u8 *) ieee->wpa_ie;
6419 if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
6420 gtk += 4 + 3;
6421 ptk += 4 + 4 + 2 + 3;
6422 } else { /* WPA IE */
6423 gtk += 8 + 3;
6424 ptk += 8 + 4 + 2 + 3;
6425 }
6426
6427 if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
6428 return -EINVAL;
6429
6430 level = ipw_wpa_ie_cipher2level(*gtk);
6431 ipw_set_hw_decrypt_multicast(priv, level);
6432
6433 level = ipw_wpa_ie_cipher2level(*ptk);
6434 ipw_set_hw_decrypt_unicast(priv, level);
6435
6436 done:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006437 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6438 return 0;
6439}
6440
6441/* implementation borrowed from hostap driver */
6442
6443static int ipw_wpa_set_encryption(struct net_device *dev,
6444 struct ipw_param *param, int param_len)
6445{
6446 int ret = 0;
6447 struct ipw_priv *priv = ieee80211_priv(dev);
6448 struct ieee80211_device *ieee = priv->ieee;
6449 struct ieee80211_crypto_ops *ops;
6450 struct ieee80211_crypt_data **crypt;
6451
6452 struct ieee80211_security sec = {
6453 .flags = 0,
6454 };
6455
6456 param->u.crypt.err = 0;
6457 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
6458
6459 if (param_len !=
6460 (int)((char *)param->u.crypt.key - (char *)param) +
6461 param->u.crypt.key_len) {
6462 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
6463 param->u.crypt.key_len);
6464 return -EINVAL;
6465 }
6466 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6467 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6468 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6469 if (param->u.crypt.idx >= WEP_KEYS)
6470 return -EINVAL;
6471 crypt = &ieee->crypt[param->u.crypt.idx];
6472 } else {
6473 return -EINVAL;
6474 }
6475
James Ketrenosafbf30a2005-08-25 00:05:33 -05006476 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006477 if (strcmp(param->u.crypt.alg, "none") == 0) {
6478 if (crypt) {
6479 sec.enabled = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006480 sec.encrypt = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006481 sec.level = SEC_LEVEL_0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006482 sec.flags |= SEC_LEVEL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006483 ieee80211_crypt_delayed_deinit(ieee, crypt);
6484 }
6485 goto done;
6486 }
6487 sec.enabled = 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006488 sec.encrypt = 1;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006489
James Ketrenosb095c382005-08-24 22:04:42 -05006490 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006491 if (strcmp(param->u.crypt.alg, "TKIP") == 0)
6492 ieee->host_encrypt_msdu = 1;
6493
6494 if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
6495 ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05006496 goto skip_host_crypt;
6497
James Ketrenosea2b26e2005-08-24 21:25:16 -05006498 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6499 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6500 request_module("ieee80211_crypt_wep");
6501 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6502 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6503 request_module("ieee80211_crypt_tkip");
6504 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6505 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6506 request_module("ieee80211_crypt_ccmp");
6507 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6508 }
6509 if (ops == NULL) {
6510 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6511 dev->name, param->u.crypt.alg);
6512 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
6513 ret = -EINVAL;
6514 goto done;
6515 }
6516
6517 if (*crypt == NULL || (*crypt)->ops != ops) {
6518 struct ieee80211_crypt_data *new_crypt;
6519
6520 ieee80211_crypt_delayed_deinit(ieee, crypt);
6521
6522 new_crypt = (struct ieee80211_crypt_data *)
6523 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
6524 if (new_crypt == NULL) {
6525 ret = -ENOMEM;
6526 goto done;
6527 }
6528 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6529 new_crypt->ops = ops;
6530 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6531 new_crypt->priv =
6532 new_crypt->ops->init(param->u.crypt.idx);
6533
6534 if (new_crypt->priv == NULL) {
6535 kfree(new_crypt);
6536 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
6537 ret = -EINVAL;
6538 goto done;
6539 }
6540
6541 *crypt = new_crypt;
6542 }
6543
6544 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6545 (*crypt)->ops->set_key(param->u.crypt.key,
6546 param->u.crypt.key_len, param->u.crypt.seq,
6547 (*crypt)->priv) < 0) {
6548 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
6549 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
6550 ret = -EINVAL;
6551 goto done;
6552 }
6553
James Ketrenosb095c382005-08-24 22:04:42 -05006554 skip_host_crypt:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006555 if (param->u.crypt.set_tx) {
6556 ieee->tx_keyidx = param->u.crypt.idx;
6557 sec.active_key = param->u.crypt.idx;
6558 sec.flags |= SEC_ACTIVE_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05006559 } else
6560 sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006561
James Ketrenosb095c382005-08-24 22:04:42 -05006562 if (param->u.crypt.alg != NULL) {
6563 memcpy(sec.keys[param->u.crypt.idx],
6564 param->u.crypt.key, param->u.crypt.key_len);
6565 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6566 sec.flags |= (1 << param->u.crypt.idx);
6567
6568 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006569 sec.flags |= SEC_LEVEL;
6570 sec.level = SEC_LEVEL_1;
James Ketrenosb095c382005-08-24 22:04:42 -05006571 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006572 sec.flags |= SEC_LEVEL;
6573 sec.level = SEC_LEVEL_2;
James Ketrenosb095c382005-08-24 22:04:42 -05006574 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006575 sec.flags |= SEC_LEVEL;
6576 sec.level = SEC_LEVEL_3;
6577 }
6578 }
6579 done:
6580 if (ieee->set_security)
6581 ieee->set_security(ieee->dev, &sec);
6582
6583 /* Do not reset port if card is in Managed mode since resetting will
6584 * generate new IEEE 802.11 authentication which may end up in looping
6585 * with IEEE 802.1X. If your hardware requires a reset after WEP
6586 * configuration (for example... Prism2), implement the reset_port in
6587 * the callbacks structures used to initialize the 802.11 stack. */
6588 if (ieee->reset_on_keychange &&
6589 ieee->iw_mode != IW_MODE_INFRA &&
6590 ieee->reset_port && ieee->reset_port(dev)) {
6591 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6592 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
6593 return -EINVAL;
6594 }
6595
6596 return ret;
6597}
6598
6599static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
6600{
6601 struct ipw_param *param;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006602 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006603 int ret = 0;
6604
6605 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
6606
6607 if (p->length < sizeof(struct ipw_param) || !p->pointer)
6608 return -EINVAL;
6609
6610 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
6611 if (param == NULL)
6612 return -ENOMEM;
6613
6614 if (copy_from_user(param, p->pointer, p->length)) {
6615 kfree(param);
6616 return -EFAULT;
6617 }
6618
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006620 switch (param->cmd) {
6621
6622 case IPW_CMD_SET_WPA_PARAM:
6623 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
6624 param->u.wpa_param.value);
6625 break;
6626
6627 case IPW_CMD_SET_WPA_IE:
6628 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
6629 break;
6630
6631 case IPW_CMD_SET_ENCRYPTION:
6632 ret = ipw_wpa_set_encryption(dev, param, p->length);
6633 break;
6634
6635 case IPW_CMD_MLME:
6636 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
6637 param->u.mlme.reason_code);
6638 break;
6639
6640 default:
6641 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6642 dev->name, param->cmd);
6643 ret = -EOPNOTSUPP;
6644 }
6645
James Ketrenosafbf30a2005-08-25 00:05:33 -05006646 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006647 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6648 ret = -EFAULT;
6649
6650 kfree(param);
6651 return ret;
6652}
James Ketrenosafbf30a2005-08-25 00:05:33 -05006653#else
6654/*
6655 * WE-18 support
6656 */
6657
6658/* SIOCSIWGENIE */
6659static int ipw_wx_set_genie(struct net_device *dev,
6660 struct iw_request_info *info,
6661 union iwreq_data *wrqu, char *extra)
6662{
6663 struct ipw_priv *priv = ieee80211_priv(dev);
6664 struct ieee80211_device *ieee = priv->ieee;
6665 u8 *buf;
6666 int err = 0;
6667
6668 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6669 (wrqu->data.length && extra == NULL))
6670 return -EINVAL;
6671
6672 //down(&priv->sem);
6673
6674 //if (!ieee->wpa_enabled) {
6675 // err = -EOPNOTSUPP;
6676 // goto out;
6677 //}
6678
6679 if (wrqu->data.length) {
6680 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6681 if (buf == NULL) {
6682 err = -ENOMEM;
6683 goto out;
6684 }
6685
6686 memcpy(buf, extra, wrqu->data.length);
6687 kfree(ieee->wpa_ie);
6688 ieee->wpa_ie = buf;
6689 ieee->wpa_ie_len = wrqu->data.length;
6690 } else {
6691 kfree(ieee->wpa_ie);
6692 ieee->wpa_ie = NULL;
6693 ieee->wpa_ie_len = 0;
6694 }
6695
6696 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6697 out:
6698 //up(&priv->sem);
6699 return err;
6700}
6701
6702/* SIOCGIWGENIE */
6703static int ipw_wx_get_genie(struct net_device *dev,
6704 struct iw_request_info *info,
6705 union iwreq_data *wrqu, char *extra)
6706{
6707 struct ipw_priv *priv = ieee80211_priv(dev);
6708 struct ieee80211_device *ieee = priv->ieee;
6709 int err = 0;
6710
6711 //down(&priv->sem);
6712
6713 //if (!ieee->wpa_enabled) {
6714 // err = -EOPNOTSUPP;
6715 // goto out;
6716 //}
6717
6718 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6719 wrqu->data.length = 0;
6720 goto out;
6721 }
6722
6723 if (wrqu->data.length < ieee->wpa_ie_len) {
6724 err = -E2BIG;
6725 goto out;
6726 }
6727
6728 wrqu->data.length = ieee->wpa_ie_len;
6729 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6730
6731 out:
6732 //up(&priv->sem);
6733 return err;
6734}
6735
Zhu Yi1fbfea52005-08-05 17:22:56 +08006736static int wext_cipher2level(int cipher)
6737{
6738 switch (cipher) {
6739 case IW_AUTH_CIPHER_NONE:
6740 return SEC_LEVEL_0;
6741 case IW_AUTH_CIPHER_WEP40:
6742 case IW_AUTH_CIPHER_WEP104:
6743 return SEC_LEVEL_1;
6744 case IW_AUTH_CIPHER_TKIP:
6745 return SEC_LEVEL_2;
6746 case IW_AUTH_CIPHER_CCMP:
6747 return SEC_LEVEL_3;
6748 default:
6749 return -1;
6750 }
6751}
6752
James Ketrenosafbf30a2005-08-25 00:05:33 -05006753/* SIOCSIWAUTH */
6754static int ipw_wx_set_auth(struct net_device *dev,
6755 struct iw_request_info *info,
6756 union iwreq_data *wrqu, char *extra)
6757{
6758 struct ipw_priv *priv = ieee80211_priv(dev);
6759 struct ieee80211_device *ieee = priv->ieee;
6760 struct iw_param *param = &wrqu->param;
6761 struct ieee80211_crypt_data *crypt;
6762 unsigned long flags;
6763 int ret = 0;
6764
6765 switch (param->flags & IW_AUTH_INDEX) {
6766 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006767 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006768 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006769 ipw_set_hw_decrypt_unicast(priv,
6770 wext_cipher2level(param->value));
6771 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006772 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006773 ipw_set_hw_decrypt_multicast(priv,
6774 wext_cipher2level(param->value));
6775 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006776 case IW_AUTH_KEY_MGMT:
6777 /*
6778 * ipw2200 does not use these parameters
6779 */
6780 break;
6781
6782 case IW_AUTH_TKIP_COUNTERMEASURES:
6783 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6784 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6785 IPW_WARNING("Can't set TKIP countermeasures: "
6786 "crypt not set!\n");
6787 break;
6788 }
6789
6790 flags = crypt->ops->get_flags(crypt->priv);
6791
6792 if (param->value)
6793 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6794 else
6795 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6796
6797 crypt->ops->set_flags(flags, crypt->priv);
6798
6799 break;
6800
6801 case IW_AUTH_DROP_UNENCRYPTED:{
6802 /* HACK:
6803 *
6804 * wpa_supplicant calls set_wpa_enabled when the driver
6805 * is loaded and unloaded, regardless of if WPA is being
6806 * used. No other calls are made which can be used to
6807 * determine if encryption will be used or not prior to
6808 * association being expected. If encryption is not being
6809 * used, drop_unencrypted is set to false, else true -- we
6810 * can use this to determine if the CAP_PRIVACY_ON bit should
6811 * be set.
6812 */
6813 struct ieee80211_security sec = {
6814 .flags = SEC_ENABLED,
6815 .enabled = param->value,
6816 };
6817 priv->ieee->drop_unencrypted = param->value;
6818 /* We only change SEC_LEVEL for open mode. Others
6819 * are set by ipw_wpa_set_encryption.
6820 */
6821 if (!param->value) {
6822 sec.flags |= SEC_LEVEL;
6823 sec.level = SEC_LEVEL_0;
6824 } else {
6825 sec.flags |= SEC_LEVEL;
6826 sec.level = SEC_LEVEL_1;
6827 }
6828 if (priv->ieee->set_security)
6829 priv->ieee->set_security(priv->ieee->dev, &sec);
6830 break;
6831 }
6832
6833 case IW_AUTH_80211_AUTH_ALG:
6834 ret = ipw_wpa_set_auth_algs(priv, param->value);
6835 break;
6836
6837 case IW_AUTH_WPA_ENABLED:
6838 ret = ipw_wpa_enable(priv, param->value);
6839 break;
6840
6841 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6842 ieee->ieee802_1x = param->value;
6843 break;
6844
6845 //case IW_AUTH_ROAMING_CONTROL:
6846 case IW_AUTH_PRIVACY_INVOKED:
6847 ieee->privacy_invoked = param->value;
6848 break;
6849
6850 default:
6851 return -EOPNOTSUPP;
6852 }
6853 return ret;
6854}
6855
6856/* SIOCGIWAUTH */
6857static int ipw_wx_get_auth(struct net_device *dev,
6858 struct iw_request_info *info,
6859 union iwreq_data *wrqu, char *extra)
6860{
6861 struct ipw_priv *priv = ieee80211_priv(dev);
6862 struct ieee80211_device *ieee = priv->ieee;
6863 struct ieee80211_crypt_data *crypt;
6864 struct iw_param *param = &wrqu->param;
6865 int ret = 0;
6866
6867 switch (param->flags & IW_AUTH_INDEX) {
6868 case IW_AUTH_WPA_VERSION:
6869 case IW_AUTH_CIPHER_PAIRWISE:
6870 case IW_AUTH_CIPHER_GROUP:
6871 case IW_AUTH_KEY_MGMT:
6872 /*
6873 * wpa_supplicant will control these internally
6874 */
6875 ret = -EOPNOTSUPP;
6876 break;
6877
6878 case IW_AUTH_TKIP_COUNTERMEASURES:
6879 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6880 if (!crypt || !crypt->ops->get_flags) {
6881 IPW_WARNING("Can't get TKIP countermeasures: "
6882 "crypt not set!\n");
6883 break;
6884 }
6885
6886 param->value = (crypt->ops->get_flags(crypt->priv) &
6887 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6888
6889 break;
6890
6891 case IW_AUTH_DROP_UNENCRYPTED:
6892 param->value = ieee->drop_unencrypted;
6893 break;
6894
6895 case IW_AUTH_80211_AUTH_ALG:
6896 param->value = ieee->sec.auth_mode;
6897 break;
6898
6899 case IW_AUTH_WPA_ENABLED:
6900 param->value = ieee->wpa_enabled;
6901 break;
6902
6903 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6904 param->value = ieee->ieee802_1x;
6905 break;
6906
6907 case IW_AUTH_ROAMING_CONTROL:
6908 case IW_AUTH_PRIVACY_INVOKED:
6909 param->value = ieee->privacy_invoked;
6910 break;
6911
6912 default:
6913 return -EOPNOTSUPP;
6914 }
6915 return 0;
6916}
6917
6918/* SIOCSIWENCODEEXT */
6919static int ipw_wx_set_encodeext(struct net_device *dev,
6920 struct iw_request_info *info,
6921 union iwreq_data *wrqu, char *extra)
6922{
6923 struct ipw_priv *priv = ieee80211_priv(dev);
6924 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6925
6926 if (hwcrypto) {
6927 /* IPW HW can't build TKIP MIC, host decryption still needed */
6928 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6929 priv->ieee->host_encrypt = 0;
6930 priv->ieee->host_encrypt_msdu = 1;
6931 priv->ieee->host_decrypt = 1;
6932 } else {
6933 priv->ieee->host_encrypt = 0;
6934 priv->ieee->host_encrypt_msdu = 0;
6935 priv->ieee->host_decrypt = 0;
6936 }
6937 }
6938
6939 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6940}
6941
6942/* SIOCGIWENCODEEXT */
6943static int ipw_wx_get_encodeext(struct net_device *dev,
6944 struct iw_request_info *info,
6945 union iwreq_data *wrqu, char *extra)
6946{
6947 struct ipw_priv *priv = ieee80211_priv(dev);
6948 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6949}
6950
6951/* SIOCSIWMLME */
6952static int ipw_wx_set_mlme(struct net_device *dev,
6953 struct iw_request_info *info,
6954 union iwreq_data *wrqu, char *extra)
6955{
6956 struct ipw_priv *priv = ieee80211_priv(dev);
6957 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6958 u16 reason;
6959
6960 reason = cpu_to_le16(mlme->reason_code);
6961
6962 switch (mlme->cmd) {
6963 case IW_MLME_DEAUTH:
6964 // silently ignore
6965 break;
6966
6967 case IW_MLME_DISASSOC:
6968 ipw_disassociate(priv);
6969 break;
6970
6971 default:
6972 return -EOPNOTSUPP;
6973 }
6974 return 0;
6975}
6976#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006977
James Ketrenosb095c382005-08-24 22:04:42 -05006978#ifdef CONFIG_IPW_QOS
6979
6980/* QoS */
6981/*
6982* get the modulation type of the current network or
6983* the card current mode
6984*/
6985u8 ipw_qos_current_mode(struct ipw_priv * priv)
6986{
6987 u8 mode = 0;
6988
6989 if (priv->status & STATUS_ASSOCIATED) {
6990 unsigned long flags;
6991
6992 spin_lock_irqsave(&priv->ieee->lock, flags);
6993 mode = priv->assoc_network->mode;
6994 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6995 } else {
6996 mode = priv->ieee->mode;
6997 }
6998 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6999 return mode;
7000}
7001
7002/*
7003* Handle management frame beacon and probe response
7004*/
7005static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
7006 int active_network,
7007 struct ieee80211_network *network)
7008{
7009 u32 size = sizeof(struct ieee80211_qos_parameters);
7010
James Ketrenosafbf30a2005-08-25 00:05:33 -05007011 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05007012 network->qos_data.active = network->qos_data.supported;
7013
7014 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007015 if (active_network &&
7016 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05007017 network->qos_data.active = network->qos_data.supported;
7018
7019 if ((network->qos_data.active == 1) && (active_network == 1) &&
7020 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
7021 (network->qos_data.old_param_count !=
7022 network->qos_data.param_count)) {
7023 network->qos_data.old_param_count =
7024 network->qos_data.param_count;
7025 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007026 IPW_DEBUG_QOS("QoS parameters change call "
7027 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05007028 }
7029 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007030 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
7031 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007032 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007033 else
7034 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007035 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007036
James Ketrenosb095c382005-08-24 22:04:42 -05007037 if ((network->qos_data.active == 1) && (active_network == 1)) {
7038 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
7039 schedule_work(&priv->qos_activate);
7040 }
7041
7042 network->qos_data.active = 0;
7043 network->qos_data.supported = 0;
7044 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007045 if ((priv->status & STATUS_ASSOCIATED) &&
7046 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
7047 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
7048 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
7049 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05007050 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05007051 priv->assoc_network->ssid_len) &&
7052 !memcmp(network->ssid,
7053 priv->assoc_network->ssid,
7054 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05007055 queue_work(priv->workqueue,
7056 &priv->merge_networks);
7057 }
James Ketrenosb095c382005-08-24 22:04:42 -05007058 }
7059
7060 return 0;
7061}
7062
7063/*
7064* This function set up the firmware to support QoS. It sends
7065* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
7066*/
7067static int ipw_qos_activate(struct ipw_priv *priv,
7068 struct ieee80211_qos_data *qos_network_data)
7069{
7070 int err;
7071 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
7072 struct ieee80211_qos_parameters *active_one = NULL;
7073 u32 size = sizeof(struct ieee80211_qos_parameters);
7074 u32 burst_duration;
7075 int i;
7076 u8 type;
7077
7078 type = ipw_qos_current_mode(priv);
7079
7080 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7081 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7082 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7083 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7084
7085 if (qos_network_data == NULL) {
7086 if (type == IEEE_B) {
7087 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7088 active_one = &def_parameters_CCK;
7089 } else
7090 active_one = &def_parameters_OFDM;
7091
James Ketrenosafbf30a2005-08-25 00:05:33 -05007092 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007093 burst_duration = ipw_qos_get_burst_duration(priv);
7094 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007095 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
7096 (u16) burst_duration;
7097 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007098 if (type == IEEE_B) {
7099 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7100 type);
7101 if (priv->qos_data.qos_enable == 0)
7102 active_one = &def_parameters_CCK;
7103 else
7104 active_one = priv->qos_data.def_qos_parm_CCK;
7105 } else {
7106 if (priv->qos_data.qos_enable == 0)
7107 active_one = &def_parameters_OFDM;
7108 else
7109 active_one = priv->qos_data.def_qos_parm_OFDM;
7110 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007111 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007112 } else {
7113 unsigned long flags;
7114 int active;
7115
7116 spin_lock_irqsave(&priv->ieee->lock, flags);
7117 active_one = &(qos_network_data->parameters);
7118 qos_network_data->old_param_count =
7119 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007120 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007121 active = qos_network_data->supported;
7122 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7123
7124 if (active == 0) {
7125 burst_duration = ipw_qos_get_burst_duration(priv);
7126 for (i = 0; i < QOS_QUEUE_NUM; i++)
7127 qos_parameters[QOS_PARAM_SET_ACTIVE].
7128 tx_op_limit[i] = (u16) burst_duration;
7129 }
7130 }
7131
7132 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007133 err = ipw_send_qos_params_command(priv,
7134 (struct ieee80211_qos_parameters *)
7135 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007136 if (err)
7137 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7138
7139 return err;
7140}
7141
7142/*
7143* send IPW_CMD_WME_INFO to the firmware
7144*/
7145static int ipw_qos_set_info_element(struct ipw_priv *priv)
7146{
7147 int ret = 0;
7148 struct ieee80211_qos_information_element qos_info;
7149
7150 if (priv == NULL)
7151 return -1;
7152
7153 qos_info.elementID = QOS_ELEMENT_ID;
7154 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
7155
7156 qos_info.version = QOS_VERSION_1;
7157 qos_info.ac_info = 0;
7158
7159 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7160 qos_info.qui_type = QOS_OUI_TYPE;
7161 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7162
7163 ret = ipw_send_qos_info_command(priv, &qos_info);
7164 if (ret != 0) {
7165 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7166 }
7167 return ret;
7168}
7169
7170/*
7171* Set the QoS parameter with the association request structure
7172*/
7173static int ipw_qos_association(struct ipw_priv *priv,
7174 struct ieee80211_network *network)
7175{
7176 int err = 0;
7177 struct ieee80211_qos_data *qos_data = NULL;
7178 struct ieee80211_qos_data ibss_data = {
7179 .supported = 1,
7180 .active = 1,
7181 };
7182
7183 switch (priv->ieee->iw_mode) {
7184 case IW_MODE_ADHOC:
7185 if (!(network->capability & WLAN_CAPABILITY_IBSS))
7186 BUG();
7187
7188 qos_data = &ibss_data;
7189 break;
7190
7191 case IW_MODE_INFRA:
7192 qos_data = &network->qos_data;
7193 break;
7194
7195 default:
7196 BUG();
7197 break;
7198 }
7199
7200 err = ipw_qos_activate(priv, qos_data);
7201 if (err) {
7202 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7203 return err;
7204 }
7205
7206 if (priv->qos_data.qos_enable && qos_data->supported) {
7207 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7208 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7209 return ipw_qos_set_info_element(priv);
7210 }
7211
7212 return 0;
7213}
7214
7215/*
7216* handling the beaconing responces. if we get different QoS setting
7217* of the network from the the associated setting adjust the QoS
7218* setting
7219*/
7220static int ipw_qos_association_resp(struct ipw_priv *priv,
7221 struct ieee80211_network *network)
7222{
7223 int ret = 0;
7224 unsigned long flags;
7225 u32 size = sizeof(struct ieee80211_qos_parameters);
7226 int set_qos_param = 0;
7227
James Ketrenosafbf30a2005-08-25 00:05:33 -05007228 if ((priv == NULL) || (network == NULL) ||
7229 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007230 return ret;
7231
7232 if (!(priv->status & STATUS_ASSOCIATED))
7233 return ret;
7234
James Ketrenosafbf30a2005-08-25 00:05:33 -05007235 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007236 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007237
7238 spin_lock_irqsave(&priv->ieee->lock, flags);
7239 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007240 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05007241 sizeof(struct ieee80211_qos_data));
7242 priv->assoc_network->qos_data.active = 1;
7243 if ((network->qos_data.old_param_count !=
7244 network->qos_data.param_count)) {
7245 set_qos_param = 1;
7246 network->qos_data.old_param_count =
7247 network->qos_data.param_count;
7248 }
7249
7250 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007251 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7252 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007253 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007254 else
7255 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007256 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007257 priv->assoc_network->qos_data.active = 0;
7258 priv->assoc_network->qos_data.supported = 0;
7259 set_qos_param = 1;
7260 }
7261
7262 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7263
7264 if (set_qos_param == 1)
7265 schedule_work(&priv->qos_activate);
7266
7267 return ret;
7268}
7269
7270static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7271{
7272 u32 ret = 0;
7273
7274 if ((priv == NULL))
7275 return 0;
7276
James Ketrenosafbf30a2005-08-25 00:05:33 -05007277 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007278 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007279 else
James Ketrenosb095c382005-08-24 22:04:42 -05007280 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007281
James Ketrenosb095c382005-08-24 22:04:42 -05007282 return ret;
7283}
7284
7285/*
7286* Initialize the setting of QoS global
7287*/
7288static void ipw_qos_init(struct ipw_priv *priv, int enable,
7289 int burst_enable, u32 burst_duration_CCK,
7290 u32 burst_duration_OFDM)
7291{
7292 priv->qos_data.qos_enable = enable;
7293
7294 if (priv->qos_data.qos_enable) {
7295 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7296 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7297 IPW_DEBUG_QOS("QoS is enabled\n");
7298 } else {
7299 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7300 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7301 IPW_DEBUG_QOS("QoS is not enabled\n");
7302 }
7303
7304 priv->qos_data.burst_enable = burst_enable;
7305
7306 if (burst_enable) {
7307 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7308 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7309 } else {
7310 priv->qos_data.burst_duration_CCK = 0;
7311 priv->qos_data.burst_duration_OFDM = 0;
7312 }
7313}
7314
7315/*
7316* map the packet priority to the right TX Queue
7317*/
7318static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7319{
7320 if (priority > 7 || !priv->qos_data.qos_enable)
7321 priority = 0;
7322
7323 return from_priority_to_tx_queue[priority] - 1;
7324}
7325
7326/*
7327* add QoS parameter to the TX command
7328*/
7329static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7330 u16 priority,
7331 struct tfd_data *tfd, u8 unicast)
7332{
7333 int ret = 0;
7334 int tx_queue_id = 0;
7335 struct ieee80211_qos_data *qos_data = NULL;
7336 int active, supported;
7337 unsigned long flags;
7338
7339 if (!(priv->status & STATUS_ASSOCIATED))
7340 return 0;
7341
7342 qos_data = &priv->assoc_network->qos_data;
7343
7344 spin_lock_irqsave(&priv->ieee->lock, flags);
7345
7346 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7347 if (unicast == 0)
7348 qos_data->active = 0;
7349 else
7350 qos_data->active = qos_data->supported;
7351 }
7352
7353 active = qos_data->active;
7354 supported = qos_data->supported;
7355
7356 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7357
James Ketrenosafbf30a2005-08-25 00:05:33 -05007358 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7359 "unicast %d\n",
7360 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05007361 if (active && priv->qos_data.qos_enable) {
7362 ret = from_priority_to_tx_queue[priority];
7363 tx_queue_id = ret - 1;
7364 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
7365 if (priority <= 7) {
7366 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7367 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
7368 tfd->tfd.tfd_26.mchdr.frame_ctl |=
7369 IEEE80211_STYPE_QOS_DATA;
7370
7371 if (priv->qos_data.qos_no_ack_mask &
7372 (1UL << tx_queue_id)) {
7373 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7374 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
7375 CTRL_QOS_NO_ACK;
7376 }
7377 }
7378 }
7379
7380 return ret;
7381}
7382
7383/*
7384* background support to run QoS activate functionality
7385*/
7386static void ipw_bg_qos_activate(void *data)
7387{
7388 struct ipw_priv *priv = data;
7389
7390 if (priv == NULL)
7391 return;
7392
7393 down(&priv->sem);
7394
7395 if (priv->status & STATUS_ASSOCIATED)
7396 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7397
7398 up(&priv->sem);
7399}
7400
7401/*
7402* Handler for probe responce and beacon frame
7403*/
James Ketrenos2b184d52005-08-03 20:33:14 -05007404static int ipw_handle_management(struct net_device *dev,
7405 struct ieee80211_network *network, u16 type)
James Ketrenosb095c382005-08-24 22:04:42 -05007406{
7407 struct ipw_priv *priv = ieee80211_priv(dev);
7408 int active_network;
7409
7410 if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
7411 active_network = 1;
7412 else
7413 active_network = 0;
7414
7415 switch (type) {
7416 case IEEE80211_STYPE_PROBE_RESP:
7417 case IEEE80211_STYPE_BEACON:
7418 ipw_qos_handle_probe_reponse(priv, active_network, network);
7419 break;
7420 case IEEE80211_STYPE_ASSOC_RESP:
7421 ipw_qos_association_resp(priv, network);
7422 break;
7423 default:
7424 break;
7425 }
7426
7427 return 0;
7428}
7429
7430static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7431 *qos_param)
7432{
7433 struct host_cmd cmd = {
7434 .cmd = IPW_CMD_QOS_PARAMETERS,
7435 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7436 };
7437
7438 if (!priv || !qos_param) {
7439 IPW_ERROR("Invalid args\n");
7440 return -1;
7441 }
7442
James Ketrenosafbf30a2005-08-25 00:05:33 -05007443 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenosb095c382005-08-24 22:04:42 -05007444 if (ipw_send_cmd(priv, &cmd)) {
7445 IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
7446 return -1;
7447 }
7448
7449 return 0;
7450}
7451
7452static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7453 *qos_param)
7454{
7455 struct host_cmd cmd = {
7456 .cmd = IPW_CMD_WME_INFO,
7457 .len = sizeof(*qos_param)
7458 };
7459
7460 if (!priv || !qos_param) {
7461 IPW_ERROR("Invalid args\n");
7462 return -1;
7463 }
7464
James Ketrenosafbf30a2005-08-25 00:05:33 -05007465 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenosb095c382005-08-24 22:04:42 -05007466 if (ipw_send_cmd(priv, &cmd)) {
7467 IPW_ERROR("failed to send CMD_QOS_INFO command\n");
7468 return -1;
7469 }
7470
7471 return 0;
7472}
7473
7474#endif /* CONFIG_IPW_QOS */
7475
James Ketrenos43f66a62005-03-25 12:31:53 -06007476static int ipw_associate_network(struct ipw_priv *priv,
7477 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007478 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007479{
7480 int err;
7481
7482 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007483 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007484
7485 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007486 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007487 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007488 memcpy(priv->essid, network->ssid, priv->essid_len);
7489 }
7490
7491 network->last_associate = jiffies;
7492
7493 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7494 priv->assoc_request.channel = network->channel;
7495 if ((priv->capability & CAP_PRIVACY_ON) &&
7496 (priv->capability & CAP_SHARED_KEY)) {
7497 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007498 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7499
7500 if ((priv->capability & CAP_PRIVACY_ON) &&
7501 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7502 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7503 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenos43f66a62005-03-25 12:31:53 -06007504 } else {
7505 priv->assoc_request.auth_type = AUTH_OPEN;
7506 priv->assoc_request.auth_key = 0;
7507 }
7508
James Ketrenosa613bff2005-08-24 21:43:11 -05007509 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007510 priv->assoc_request.policy_support = 0x02; /* RSN active */
7511 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7512 priv->ieee->wpa_ie_len);
7513 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05007514
Jeff Garzikbf794512005-07-31 13:07:26 -04007515 /*
7516 * It is valid for our ieee device to support multiple modes, but
7517 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007518 * just one mode.
7519 */
7520 if (network->mode & priv->ieee->mode & IEEE_A)
7521 priv->assoc_request.ieee_mode = IPW_A_MODE;
7522 else if (network->mode & priv->ieee->mode & IEEE_G)
7523 priv->assoc_request.ieee_mode = IPW_G_MODE;
7524 else if (network->mode & priv->ieee->mode & IEEE_B)
7525 priv->assoc_request.ieee_mode = IPW_B_MODE;
7526
James Ketrenosea2b26e2005-08-24 21:25:16 -05007527 priv->assoc_request.capability = network->capability;
7528 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7529 && !(priv->config & CFG_PREAMBLE_LONG)) {
7530 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7531 } else {
7532 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7533
7534 /* Clear the short preamble if we won't be supporting it */
7535 priv->assoc_request.capability &=
7536 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7537 }
7538
James Ketrenosafbf30a2005-08-25 00:05:33 -05007539 /* Clear capability bits that aren't used in Ad Hoc */
7540 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7541 priv->assoc_request.capability &=
7542 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7543
James Ketrenos43f66a62005-03-25 12:31:53 -06007544 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007545 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007547 escape_essid(priv->essid, priv->essid_len),
7548 network->channel,
7549 ipw_modes[priv->assoc_request.ieee_mode],
7550 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007551 (priv->assoc_request.preamble_length ==
7552 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7553 network->capability &
7554 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007555 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007556 priv->capability & CAP_PRIVACY_ON ?
7557 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007558 "(open)") : "",
7559 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007560 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007561 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007562 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007563
7564 priv->assoc_request.beacon_interval = network->beacon_interval;
7565 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007566 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007567 priv->assoc_request.assoc_type = HC_IBSS_START;
7568 priv->assoc_request.assoc_tsf_msw = 0;
7569 priv->assoc_request.assoc_tsf_lsw = 0;
7570 } else {
7571 if (unlikely(roaming))
7572 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7573 else
7574 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7575 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7576 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7577 }
7578
James Ketrenosafbf30a2005-08-25 00:05:33 -05007579 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007580
7581 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7582 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7583 priv->assoc_request.atim_window = network->atim_window;
7584 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007585 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007586 priv->assoc_request.atim_window = 0;
7587 }
7588
James Ketrenos43f66a62005-03-25 12:31:53 -06007589 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007590
James Ketrenos43f66a62005-03-25 12:31:53 -06007591 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7592 if (err) {
7593 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7594 return err;
7595 }
7596
7597 rates->ieee_mode = priv->assoc_request.ieee_mode;
7598 rates->purpose = IPW_RATE_CONNECT;
7599 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007600
James Ketrenos43f66a62005-03-25 12:31:53 -06007601 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7602 priv->sys_config.dot11g_auto_detection = 1;
7603 else
7604 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007605
7606 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7607 priv->sys_config.answer_broadcast_ssid_probe = 1;
7608 else
7609 priv->sys_config.answer_broadcast_ssid_probe = 0;
7610
James Ketrenos43f66a62005-03-25 12:31:53 -06007611 err = ipw_send_system_config(priv, &priv->sys_config);
7612 if (err) {
7613 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7614 return err;
7615 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007616
James Ketrenos43f66a62005-03-25 12:31:53 -06007617 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007618 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007619 if (err) {
7620 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7621 return err;
7622 }
7623
7624 /*
7625 * If preemption is enabled, it is possible for the association
7626 * to complete before we return from ipw_send_associate. Therefore
7627 * we have to be sure and update our priviate data first.
7628 */
7629 priv->channel = network->channel;
7630 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007631 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007632 priv->status &= ~STATUS_SECURITY_UPDATED;
7633
7634 priv->assoc_network = network;
7635
James Ketrenosb095c382005-08-24 22:04:42 -05007636#ifdef CONFIG_IPW_QOS
7637 ipw_qos_association(priv, network);
7638#endif
7639
James Ketrenos43f66a62005-03-25 12:31:53 -06007640 err = ipw_send_associate(priv, &priv->assoc_request);
7641 if (err) {
7642 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7643 return err;
7644 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007645
7646 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007647 escape_essid(priv->essid, priv->essid_len),
7648 MAC_ARG(priv->bssid));
7649
7650 return 0;
7651}
7652
7653static void ipw_roam(void *data)
7654{
7655 struct ipw_priv *priv = data;
7656 struct ieee80211_network *network = NULL;
7657 struct ipw_network_match match = {
7658 .network = priv->assoc_network
7659 };
7660
7661 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007662 *
7663 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007664 * setting the status ROAM bit and requesting a scan.
7665 * 2. When the scan completes, it schedules the ROAM work
7666 * 3. The ROAM work looks at all of the known networks for one that
7667 * is a better network than the currently associated. If none
7668 * found, the ROAM process is over (ROAM bit cleared)
7669 * 4. If a better network is found, a disassociation request is
7670 * sent.
7671 * 5. When the disassociation completes, the roam work is again
7672 * scheduled. The second time through, the driver is no longer
7673 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007674 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007675 * 6. At this point ,the roaming process is complete and the ROAM
7676 * status bit is cleared.
7677 */
7678
7679 /* If we are no longer associated, and the roaming bit is no longer
7680 * set, then we are not actively roaming, so just return */
7681 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7682 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007683
James Ketrenos43f66a62005-03-25 12:31:53 -06007684 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007685 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007686 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007687 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007688 u8 rssi = priv->assoc_network->stats.rssi;
7689 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007690 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007691 list_for_each_entry(network, &priv->ieee->network_list, list) {
7692 if (network != priv->assoc_network)
7693 ipw_best_network(priv, &match, network, 1);
7694 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007695 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007696 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007697
James Ketrenos43f66a62005-03-25 12:31:53 -06007698 if (match.network == priv->assoc_network) {
7699 IPW_DEBUG_ASSOC("No better APs in this network to "
7700 "roam to.\n");
7701 priv->status &= ~STATUS_ROAMING;
7702 ipw_debug_config(priv);
7703 return;
7704 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007705
James Ketrenos43f66a62005-03-25 12:31:53 -06007706 ipw_send_disassociate(priv, 1);
7707 priv->assoc_network = match.network;
7708
7709 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007710 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007711
7712 /* Second pass through ROAM process -- request association */
7713 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7714 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7715 priv->status &= ~STATUS_ROAMING;
7716}
7717
James Ketrenosc848d0a2005-08-24 21:56:24 -05007718static void ipw_bg_roam(void *data)
7719{
7720 struct ipw_priv *priv = data;
7721 down(&priv->sem);
7722 ipw_roam(data);
7723 up(&priv->sem);
7724}
7725
7726static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007727{
7728 struct ipw_priv *priv = data;
7729
7730 struct ieee80211_network *network = NULL;
7731 struct ipw_network_match match = {
7732 .network = NULL
7733 };
7734 struct ipw_supported_rates *rates;
7735 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007736 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007737
James Ketrenosb095c382005-08-24 22:04:42 -05007738 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7739 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7740 return 0;
7741 }
7742
James Ketrenosc848d0a2005-08-24 21:56:24 -05007743 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007744 IPW_DEBUG_ASSOC("Not attempting association (already in "
7745 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007746 return 0;
7747 }
7748
7749 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007750 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7751 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007752 return 0;
7753 }
7754
James Ketrenos43f66a62005-03-25 12:31:53 -06007755 if (!(priv->config & CFG_ASSOCIATE) &&
7756 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007757 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007758 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007759 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007760 }
7761
James Ketrenosa613bff2005-08-24 21:43:11 -05007762 /* Protect our use of the network_list */
7763 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007764 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007765 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007766
7767 network = match.network;
7768 rates = &match.rates;
7769
7770 if (network == NULL &&
7771 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7772 priv->config & CFG_ADHOC_CREATE &&
7773 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007774 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007775 !list_empty(&priv->ieee->network_free_list)) {
7776 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007777 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007778 ipw_adhoc_create(priv, network);
7779 rates = &priv->rates;
7780 list_del(element);
7781 list_add_tail(&network->list, &priv->ieee->network_list);
7782 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007783 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007784
James Ketrenos43f66a62005-03-25 12:31:53 -06007785 /* If we reached the end of the list, then we don't have any valid
7786 * matching APs */
7787 if (!network) {
7788 ipw_debug_config(priv);
7789
James Ketrenosb095c382005-08-24 22:04:42 -05007790 if (!(priv->status & STATUS_SCANNING)) {
7791 if (!(priv->config & CFG_SPEED_SCAN))
7792 queue_delayed_work(priv->workqueue,
7793 &priv->request_scan,
7794 SCAN_INTERVAL);
7795 else
7796 queue_work(priv->workqueue,
7797 &priv->request_scan);
7798 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007799
James Ketrenosc848d0a2005-08-24 21:56:24 -05007800 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007801 }
7802
7803 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007804
7805 return 1;
7806}
7807
7808static void ipw_bg_associate(void *data)
7809{
7810 struct ipw_priv *priv = data;
7811 down(&priv->sem);
7812 ipw_associate(data);
7813 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007814}
Jeff Garzikbf794512005-07-31 13:07:26 -04007815
James Ketrenosb095c382005-08-24 22:04:42 -05007816static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7817 struct sk_buff *skb)
7818{
7819 struct ieee80211_hdr *hdr;
7820 u16 fc;
7821
7822 hdr = (struct ieee80211_hdr *)skb->data;
7823 fc = le16_to_cpu(hdr->frame_ctl);
7824 if (!(fc & IEEE80211_FCTL_PROTECTED))
7825 return;
7826
7827 fc &= ~IEEE80211_FCTL_PROTECTED;
7828 hdr->frame_ctl = cpu_to_le16(fc);
7829 switch (priv->ieee->sec.level) {
7830 case SEC_LEVEL_3:
7831 /* Remove CCMP HDR */
7832 memmove(skb->data + IEEE80211_3ADDR_LEN,
7833 skb->data + IEEE80211_3ADDR_LEN + 8,
7834 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yia2d73e62005-07-13 12:24:51 -05007835 if (fc & IEEE80211_FCTL_MOREFRAGS)
7836 skb_trim(skb, skb->len - 16); /* 2*MIC */
7837 else
7838 skb_trim(skb, skb->len - 8); /* MIC */
James Ketrenosb095c382005-08-24 22:04:42 -05007839 break;
7840 case SEC_LEVEL_2:
7841 break;
7842 case SEC_LEVEL_1:
7843 /* Remove IV */
7844 memmove(skb->data + IEEE80211_3ADDR_LEN,
7845 skb->data + IEEE80211_3ADDR_LEN + 4,
7846 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yia2d73e62005-07-13 12:24:51 -05007847 if (fc & IEEE80211_FCTL_MOREFRAGS)
7848 skb_trim(skb, skb->len - 8); /* 2*ICV */
7849 else
7850 skb_trim(skb, skb->len - 4); /* ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007851 break;
7852 case SEC_LEVEL_0:
7853 break;
7854 default:
7855 printk(KERN_ERR "Unknow security level %d\n",
7856 priv->ieee->sec.level);
7857 break;
7858 }
7859}
7860
7861static void ipw_handle_data_packet(struct ipw_priv *priv,
7862 struct ipw_rx_mem_buffer *rxb,
7863 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007864{
7865 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7866
7867 /* We received data from the HW, so stop the watchdog */
7868 priv->net_dev->trans_start = jiffies;
7869
Jeff Garzikbf794512005-07-31 13:07:26 -04007870 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007871 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007872 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007873 skb_tailroom(rxb->skb))) {
7874 priv->ieee->stats.rx_errors++;
7875 priv->wstats.discard.misc++;
7876 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7877 return;
7878 } else if (unlikely(!netif_running(priv->net_dev))) {
7879 priv->ieee->stats.rx_dropped++;
7880 priv->wstats.discard.misc++;
7881 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7882 return;
7883 }
7884
7885 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007886 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007887
7888 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007889 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007890
7891 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7892
James Ketrenosb095c382005-08-24 22:04:42 -05007893 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7894 if (!priv->ieee->host_decrypt)
7895 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7896
Jeff Garzikbf794512005-07-31 13:07:26 -04007897 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007898 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007899 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007900 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007901 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007902 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007903}
7904
James Ketrenosea2b26e2005-08-24 21:25:16 -05007905static inline int is_network_packet(struct ipw_priv *priv,
7906 struct ieee80211_hdr_4addr *header)
7907{
7908 /* Filter incoming packets to determine if they are targetted toward
7909 * this network, discarding packets coming from ourselves */
7910 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007911 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007912 /* packets from our adapter are dropped (echo) */
7913 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7914 return 0;
7915
James Ketrenosafbf30a2005-08-25 00:05:33 -05007916 /* multicast packets to our IBSS go through */
7917 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007918 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007919
7920 /* packets to our adapter go through */
7921 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7922 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007923
7924 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007925 /* packets from our adapter are dropped (echo) */
7926 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7927 return 0;
7928
James Ketrenosa613bff2005-08-24 21:43:11 -05007929 /* {broad,multi}cast packets to our IBSS go through */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007930 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007931 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7932
7933 /* packets to our adapter go through */
7934 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7935 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007936 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007937
James Ketrenosea2b26e2005-08-24 21:25:16 -05007938 return 1;
7939}
7940
James Ketrenosafbf30a2005-08-25 00:05:33 -05007941#define IPW_PACKET_RETRY_TIME HZ
7942
7943static inline int is_duplicate_packet(struct ipw_priv *priv,
7944 struct ieee80211_hdr_4addr *header)
7945{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007946 u16 sc = le16_to_cpu(header->seq_ctl);
7947 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7948 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7949 u16 *last_seq, *last_frag;
7950 unsigned long *last_time;
7951
7952 switch (priv->ieee->iw_mode) {
7953 case IW_MODE_ADHOC:
7954 {
7955 struct list_head *p;
7956 struct ipw_ibss_seq *entry = NULL;
7957 u8 *mac = header->addr2;
7958 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7959
7960 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7961 entry =
7962 list_entry(p, struct ipw_ibss_seq, list);
7963 if (!memcmp(entry->mac, mac, ETH_ALEN))
7964 break;
7965 }
7966 if (p == &priv->ibss_mac_hash[index]) {
7967 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7968 if (!entry) {
7969 IPW_ERROR
7970 ("Cannot malloc new mac entry\n");
7971 return 0;
7972 }
7973 memcpy(entry->mac, mac, ETH_ALEN);
7974 entry->seq_num = seq;
7975 entry->frag_num = frag;
7976 entry->packet_time = jiffies;
7977 list_add(&entry->list,
7978 &priv->ibss_mac_hash[index]);
7979 return 0;
7980 }
7981 last_seq = &entry->seq_num;
7982 last_frag = &entry->frag_num;
7983 last_time = &entry->packet_time;
7984 break;
7985 }
7986 case IW_MODE_INFRA:
7987 last_seq = &priv->last_seq_num;
7988 last_frag = &priv->last_frag_num;
7989 last_time = &priv->last_packet_time;
7990 break;
7991 default:
7992 return 0;
7993 }
7994 if ((*last_seq == seq) &&
7995 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7996 if (*last_frag == frag)
7997 goto drop;
7998 if (*last_frag + 1 != frag)
7999 /* out-of-order fragment */
8000 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008001 } else
8002 *last_seq = seq;
8003
Zhu Yif57ce7c2005-07-13 12:22:15 -05008004 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008005 *last_time = jiffies;
8006 return 0;
8007
8008 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008009 /* Comment this line now since we observed the card receives
8010 * duplicate packets but the FCTL_RETRY bit is not set in the
8011 * IBSS mode with fragmentation enabled.
8012 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008013 return 1;
8014}
8015
James Ketrenosb095c382005-08-24 22:04:42 -05008016static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8017 struct ipw_rx_mem_buffer *rxb,
8018 struct ieee80211_rx_stats *stats)
8019{
8020 struct sk_buff *skb = rxb->skb;
8021 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8022 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8023 (skb->data + IPW_RX_FRAME_SIZE);
8024
8025 ieee80211_rx_mgt(priv->ieee, header, stats);
8026
8027 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8028 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8029 IEEE80211_STYPE_PROBE_RESP) ||
8030 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8031 IEEE80211_STYPE_BEACON))) {
8032 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8033 ipw_add_station(priv, header->addr2);
8034 }
8035
8036 if (priv->config & CFG_NET_STATS) {
8037 IPW_DEBUG_HC("sending stat packet\n");
8038
8039 /* Set the size of the skb to the size of the full
8040 * ipw header and 802.11 frame */
8041 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8042 IPW_RX_FRAME_SIZE);
8043
8044 /* Advance past the ipw packet header to the 802.11 frame */
8045 skb_pull(skb, IPW_RX_FRAME_SIZE);
8046
8047 /* Push the ieee80211_rx_stats before the 802.11 frame */
8048 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8049
8050 skb->dev = priv->ieee->dev;
8051
8052 /* Point raw at the ieee80211_stats */
8053 skb->mac.raw = skb->data;
8054
8055 skb->pkt_type = PACKET_OTHERHOST;
8056 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8057 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8058 netif_rx(skb);
8059 rxb->skb = NULL;
8060 }
8061}
8062
James Ketrenos43f66a62005-03-25 12:31:53 -06008063/*
8064 * Main entry function for recieving a packet with 80211 headers. This
8065 * should be called when ever the FW has notified us that there is a new
8066 * skb in the recieve queue.
8067 */
8068static void ipw_rx(struct ipw_priv *priv)
8069{
8070 struct ipw_rx_mem_buffer *rxb;
8071 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008072 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008073 u32 r, w, i;
8074 u8 network_packet;
8075
James Ketrenosb095c382005-08-24 22:04:42 -05008076 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8077 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008078 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8079
8080 while (i != r) {
8081 rxb = priv->rxq->queue[i];
8082#ifdef CONFIG_IPW_DEBUG
8083 if (unlikely(rxb == NULL)) {
8084 printk(KERN_CRIT "Queue not allocated!\n");
8085 break;
8086 }
8087#endif
8088 priv->rxq->queue[i] = NULL;
8089
8090 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008091 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008092 PCI_DMA_FROMDEVICE);
8093
8094 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8095 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8096 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008097 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008098
8099 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008100 case RX_FRAME_TYPE: /* 802.11 frame */ {
8101 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008102 .rssi =
8103 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008104 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008105 .signal =
8106 le16_to_cpu(pkt->u.frame.signal),
8107 .noise =
8108 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008109 .rate = pkt->u.frame.rate,
8110 .mac_time = jiffies,
8111 .received_channel =
8112 pkt->u.frame.received_channel,
8113 .freq =
8114 (pkt->u.frame.
8115 control & (1 << 0)) ?
8116 IEEE80211_24GHZ_BAND :
8117 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008118 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008119 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008120
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008121 if (stats.rssi != 0)
8122 stats.mask |= IEEE80211_STATMASK_RSSI;
8123 if (stats.signal != 0)
8124 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008125 if (stats.noise != 0)
8126 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008127 if (stats.rate != 0)
8128 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008129
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008130 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008131
James Ketrenosb095c382005-08-24 22:04:42 -05008132#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008133 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8134 ipw_handle_data_packet(priv, rxb,
8135 &stats);
8136 break;
8137 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008138#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008139
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008140 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008141 (struct ieee80211_hdr_4addr *)(rxb->skb->
8142 data +
8143 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008144 /* TODO: Check Ad-Hoc dest/source and make sure
8145 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008146 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008147 * frame control of the packet and disregard
8148 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008149
James Ketrenosea2b26e2005-08-24 21:25:16 -05008150 network_packet =
8151 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008152 if (network_packet && priv->assoc_network) {
8153 priv->assoc_network->stats.rssi =
8154 stats.rssi;
8155 average_add(&priv->average_rssi,
8156 stats.rssi);
8157 priv->last_rx_rssi = stats.rssi;
8158 }
8159
8160 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008161 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008162
James Ketrenosa613bff2005-08-24 21:43:11 -05008163 if (le16_to_cpu(pkt->u.frame.length) <
8164 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008165 IPW_DEBUG_DROP
8166 ("Received packet is too small. "
8167 "Dropping.\n");
8168 priv->ieee->stats.rx_errors++;
8169 priv->wstats.discard.misc++;
8170 break;
8171 }
8172
James Ketrenosa613bff2005-08-24 21:43:11 -05008173 switch (WLAN_FC_GET_TYPE
8174 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008175
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008176 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008177 ipw_handle_mgmt_packet(priv, rxb,
8178 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008179 break;
8180
8181 case IEEE80211_FTYPE_CTL:
8182 break;
8183
8184 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008185 if (unlikely(!network_packet ||
8186 is_duplicate_packet(priv,
8187 header)))
8188 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008189 IPW_DEBUG_DROP("Dropping: "
8190 MAC_FMT ", "
8191 MAC_FMT ", "
8192 MAC_FMT "\n",
8193 MAC_ARG(header->
8194 addr1),
8195 MAC_ARG(header->
8196 addr2),
8197 MAC_ARG(header->
8198 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008199 break;
8200 }
8201
8202 ipw_handle_data_packet(priv, rxb,
8203 &stats);
8204
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008205 break;
8206 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008207 break;
8208 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008209
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008210 case RX_HOST_NOTIFICATION_TYPE:{
8211 IPW_DEBUG_RX
8212 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008213 pkt->u.notification.subtype,
8214 pkt->u.notification.flags,
8215 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008216 ipw_rx_notification(priv, &pkt->u.notification);
8217 break;
8218 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008219
8220 default:
8221 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8222 pkt->header.message_type);
8223 break;
8224 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008225
8226 /* For now we just don't re-use anything. We can tweak this
8227 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008228 * fail to Rx correctly */
8229 if (rxb->skb != NULL) {
8230 dev_kfree_skb_any(rxb->skb);
8231 rxb->skb = NULL;
8232 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008233
James Ketrenos43f66a62005-03-25 12:31:53 -06008234 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008235 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008236 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008237
James Ketrenos43f66a62005-03-25 12:31:53 -06008238 i = (i + 1) % RX_QUEUE_SIZE;
8239 }
8240
8241 /* Backtrack one entry */
8242 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8243
8244 ipw_rx_queue_restock(priv);
8245}
8246
James Ketrenosafbf30a2005-08-25 00:05:33 -05008247#define DEFAULT_RTS_THRESHOLD 2304U
8248#define MIN_RTS_THRESHOLD 1U
8249#define MAX_RTS_THRESHOLD 2304U
8250#define DEFAULT_BEACON_INTERVAL 100U
8251#define DEFAULT_SHORT_RETRY_LIMIT 7U
8252#define DEFAULT_LONG_RETRY_LIMIT 4U
8253
8254static int ipw_sw_reset(struct ipw_priv *priv, int init)
8255{
8256 int band, modulation;
8257 int old_mode = priv->ieee->iw_mode;
8258
8259 /* Initialize module parameter values here */
8260 priv->config = 0;
8261
8262 /* We default to disabling the LED code as right now it causes
8263 * too many systems to lock up... */
8264 if (!led)
8265 priv->config |= CFG_NO_LED;
8266
8267 if (associate)
8268 priv->config |= CFG_ASSOCIATE;
8269 else
8270 IPW_DEBUG_INFO("Auto associate disabled.\n");
8271
8272 if (auto_create)
8273 priv->config |= CFG_ADHOC_CREATE;
8274 else
8275 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8276
8277 if (disable) {
8278 priv->status |= STATUS_RF_KILL_SW;
8279 IPW_DEBUG_INFO("Radio disabled.\n");
8280 }
8281
8282 if (channel != 0) {
8283 priv->config |= CFG_STATIC_CHANNEL;
8284 priv->channel = channel;
8285 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8286 /* TODO: Validate that provided channel is in range */
8287 }
8288#ifdef CONFIG_IPW_QOS
8289 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8290 burst_duration_CCK, burst_duration_OFDM);
8291#endif /* CONFIG_IPW_QOS */
8292
8293 switch (mode) {
8294 case 1:
8295 priv->ieee->iw_mode = IW_MODE_ADHOC;
8296 priv->net_dev->type = ARPHRD_ETHER;
8297
8298 break;
8299#ifdef CONFIG_IPW2200_MONITOR
8300 case 2:
8301 priv->ieee->iw_mode = IW_MODE_MONITOR;
8302 priv->net_dev->type = ARPHRD_IEEE80211;
8303 break;
8304#endif
8305 default:
8306 case 0:
8307 priv->net_dev->type = ARPHRD_ETHER;
8308 priv->ieee->iw_mode = IW_MODE_INFRA;
8309 break;
8310 }
8311
8312 if (hwcrypto) {
8313 priv->ieee->host_encrypt = 0;
8314 priv->ieee->host_encrypt_msdu = 0;
8315 priv->ieee->host_decrypt = 0;
8316 }
8317 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8318
Zhu Yie402c932005-08-05 17:20:40 +08008319 /* IPW2200/2915 is abled to do hardware fragmentation. */
8320 priv->ieee->host_open_frag = 0;
8321
James Ketrenosafbf30a2005-08-25 00:05:33 -05008322 if ((priv->pci_dev->device == 0x4223) ||
8323 (priv->pci_dev->device == 0x4224)) {
8324 if (init)
8325 printk(KERN_INFO DRV_NAME
8326 ": Detected Intel PRO/Wireless 2915ABG Network "
8327 "Connection\n");
8328 priv->ieee->abg_true = 1;
8329 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8330 modulation = IEEE80211_OFDM_MODULATION |
8331 IEEE80211_CCK_MODULATION;
8332 priv->adapter = IPW_2915ABG;
8333 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8334 } else {
8335 if (init)
8336 printk(KERN_INFO DRV_NAME
8337 ": Detected Intel PRO/Wireless 2200BG Network "
8338 "Connection\n");
8339
8340 priv->ieee->abg_true = 0;
8341 band = IEEE80211_24GHZ_BAND;
8342 modulation = IEEE80211_OFDM_MODULATION |
8343 IEEE80211_CCK_MODULATION;
8344 priv->adapter = IPW_2200BG;
8345 priv->ieee->mode = IEEE_G | IEEE_B;
8346 }
8347
8348 priv->ieee->freq_band = band;
8349 priv->ieee->modulation = modulation;
8350
8351 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8352
8353 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8354 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8355
8356 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8357 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8358 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8359
8360 /* If power management is turned on, default to AC mode */
8361 priv->power_mode = IPW_POWER_AC;
8362 priv->tx_power = IPW_TX_POWER_DEFAULT;
8363
Zhu Yi0ece35b2005-08-05 17:26:51 +08008364 return old_mode == priv->ieee->iw_mode;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008365}
8366
James Ketrenos43f66a62005-03-25 12:31:53 -06008367/*
8368 * This file defines the Wireless Extension handlers. It does not
8369 * define any methods of hardware manipulation and relies on the
8370 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008371 *
8372 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008373 * function used to poll the hardware vs. making unecessary calls.
8374 *
8375 */
8376
Jeff Garzikbf794512005-07-31 13:07:26 -04008377static int ipw_wx_get_name(struct net_device *dev,
8378 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008379 union iwreq_data *wrqu, char *extra)
8380{
8381 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008382 down(&priv->sem);
8383 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008384 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008385 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008386 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008387 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008388 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8389 ipw_modes[priv->assoc_request.ieee_mode]);
8390 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008391 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008392 return 0;
8393}
8394
8395static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8396{
8397 if (channel == 0) {
8398 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8399 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008400 IPW_DEBUG_ASSOC("Attempting to associate with new "
8401 "parameters.\n");
8402 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008403 return 0;
8404 }
8405
8406 priv->config |= CFG_STATIC_CHANNEL;
8407
8408 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008409 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8410 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008411 return 0;
8412 }
8413
8414 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8415 priv->channel = channel;
8416
James Ketrenosb095c382005-08-24 22:04:42 -05008417#ifdef CONFIG_IPW2200_MONITOR
8418 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008419 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008420 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008421 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008422 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008423 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008424 }
8425
8426 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8427 udelay(10);
8428
8429 if (priv->status & STATUS_SCANNING)
8430 IPW_DEBUG_SCAN("Still scanning...\n");
8431 else
8432 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8433 1000 - i);
8434
8435 return 0;
8436 }
8437#endif /* CONFIG_IPW2200_MONITOR */
8438
James Ketrenosc848d0a2005-08-24 21:56:24 -05008439 /* Network configuration changed -- force [re]association */
8440 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8441 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008442 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008443
8444 return 0;
8445}
8446
Jeff Garzikbf794512005-07-31 13:07:26 -04008447static int ipw_wx_set_freq(struct net_device *dev,
8448 struct iw_request_info *info,
8449 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008450{
8451 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008452 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008453 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008454 int ret = 0, i;
James Ketrenosb095c382005-08-24 22:04:42 -05008455 u8 channel;
8456
8457 if (fwrq->m == 0) {
8458 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8459 down(&priv->sem);
8460 ret = ipw_set_channel(priv, 0);
8461 up(&priv->sem);
8462 return ret;
8463 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008464 /* if setting by freq convert to channel */
8465 if (fwrq->e == 1) {
James Ketrenosb095c382005-08-24 22:04:42 -05008466 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8467 if (channel == 0)
8468 return -EINVAL;
8469 } else
8470 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008471
James Ketrenosb095c382005-08-24 22:04:42 -05008472 if (!ieee80211_is_valid_channel(priv->ieee, channel))
8473 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008474
James Ketrenosafbf30a2005-08-25 00:05:33 -05008475 if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
8476 i = ieee80211_channel_to_index(priv->ieee, channel);
8477 if (i == -1)
8478 return -EINVAL;
8479 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
8480 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8481 return -EINVAL;
8482 }
8483 }
8484
James Ketrenos43f66a62005-03-25 12:31:53 -06008485 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008486 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008487 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008488 up(&priv->sem);
8489 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008490}
8491
Jeff Garzikbf794512005-07-31 13:07:26 -04008492static int ipw_wx_get_freq(struct net_device *dev,
8493 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008494 union iwreq_data *wrqu, char *extra)
8495{
8496 struct ipw_priv *priv = ieee80211_priv(dev);
8497
8498 wrqu->freq.e = 0;
8499
8500 /* If we are associated, trying to associate, or have a statically
8501 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008502 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008503 if (priv->config & CFG_STATIC_CHANNEL ||
8504 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8505 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008506 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008507 wrqu->freq.m = 0;
8508
James Ketrenosc848d0a2005-08-24 21:56:24 -05008509 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008510 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8511 return 0;
8512}
8513
Jeff Garzikbf794512005-07-31 13:07:26 -04008514static int ipw_wx_set_mode(struct net_device *dev,
8515 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008516 union iwreq_data *wrqu, char *extra)
8517{
8518 struct ipw_priv *priv = ieee80211_priv(dev);
8519 int err = 0;
8520
8521 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06008522
8523 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008524#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008525 case IW_MODE_MONITOR:
8526#endif
8527 case IW_MODE_ADHOC:
8528 case IW_MODE_INFRA:
8529 break;
8530 case IW_MODE_AUTO:
8531 wrqu->mode = IW_MODE_INFRA;
8532 break;
8533 default:
8534 return -EINVAL;
8535 }
James Ketrenosb095c382005-08-24 22:04:42 -05008536 if (wrqu->mode == priv->ieee->iw_mode)
8537 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008538
James Ketrenosb095c382005-08-24 22:04:42 -05008539 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008540
8541 ipw_sw_reset(priv, 0);
8542
James Ketrenosb095c382005-08-24 22:04:42 -05008543#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008544 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008546
8547 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008548 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosb095c382005-08-24 22:04:42 -05008549#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008550
Jeff Garzikbf794512005-07-31 13:07:26 -04008551 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008552 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008553 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008554
8555 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008556
James Ketrenosc848d0a2005-08-24 21:56:24 -05008557 queue_work(priv->workqueue, &priv->adapter_restart);
8558 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008559 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008560}
8561
Jeff Garzikbf794512005-07-31 13:07:26 -04008562static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008563 struct iw_request_info *info,
8564 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008565{
8566 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008567 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008568 wrqu->mode = priv->ieee->iw_mode;
8569 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008570 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 return 0;
8572}
8573
James Ketrenos43f66a62005-03-25 12:31:53 -06008574/* Values are in microsecond */
8575static const s32 timeout_duration[] = {
8576 350000,
8577 250000,
8578 75000,
8579 37000,
8580 25000,
8581};
8582
8583static const s32 period_duration[] = {
8584 400000,
8585 700000,
8586 1000000,
8587 1000000,
8588 1000000
8589};
8590
Jeff Garzikbf794512005-07-31 13:07:26 -04008591static int ipw_wx_get_range(struct net_device *dev,
8592 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 union iwreq_data *wrqu, char *extra)
8594{
8595 struct ipw_priv *priv = ieee80211_priv(dev);
8596 struct iw_range *range = (struct iw_range *)extra;
James Ketrenosb095c382005-08-24 22:04:42 -05008597 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8598 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008599
8600 wrqu->data.length = sizeof(*range);
8601 memset(range, 0, sizeof(*range));
8602
8603 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008604 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008605
8606 range->max_qual.qual = 100;
8607 /* TODO: Find real max RSSI and stick here */
8608 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008609 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008610 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008611
8612 range->avg_qual.qual = 70;
8613 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008614 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008615 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008616 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008617 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008618 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008619
Jeff Garzikbf794512005-07-31 13:07:26 -04008620 for (i = 0; i < range->num_bitrates; i++)
8621 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008622 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008623
James Ketrenos43f66a62005-03-25 12:31:53 -06008624 range->max_rts = DEFAULT_RTS_THRESHOLD;
8625 range->min_frag = MIN_FRAG_THRESHOLD;
8626 range->max_frag = MAX_FRAG_THRESHOLD;
8627
8628 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008629 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008630 range->num_encoding_sizes = 2;
8631 range->max_encoding_tokens = WEP_KEYS;
8632
8633 /* Set the Wireless Extension versions */
8634 range->we_version_compiled = WIRELESS_EXT;
8635 range->we_version_source = 16;
8636
James Ketrenosb095c382005-08-24 22:04:42 -05008637 i = 0;
8638 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8639 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8640 i++, j++) {
8641 range->freq[i].i = geo->bg[j].channel;
8642 range->freq[i].m = geo->bg[j].freq * 100000;
8643 range->freq[i].e = 1;
8644 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008645 }
James Ketrenosb095c382005-08-24 22:04:42 -05008646
8647 if (priv->ieee->mode & IEEE_A) {
8648 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8649 i++, j++) {
8650 range->freq[i].i = geo->a[j].channel;
8651 range->freq[i].m = geo->a[j].freq * 100000;
8652 range->freq[i].e = 1;
8653 }
8654 }
8655
8656 range->num_channels = i;
8657 range->num_frequency = i;
8658
James Ketrenosc848d0a2005-08-24 21:56:24 -05008659 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008660 IPW_DEBUG_WX("GET Range\n");
8661 return 0;
8662}
8663
Jeff Garzikbf794512005-07-31 13:07:26 -04008664static int ipw_wx_set_wap(struct net_device *dev,
8665 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008666 union iwreq_data *wrqu, char *extra)
8667{
8668 struct ipw_priv *priv = ieee80211_priv(dev);
8669
8670 static const unsigned char any[] = {
8671 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8672 };
8673 static const unsigned char off[] = {
8674 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8675 };
8676
Jeff Garzikbf794512005-07-31 13:07:26 -04008677 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008678 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008679 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008680 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8681 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8682 /* we disable mandatory BSSID association */
8683 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8684 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008685 IPW_DEBUG_ASSOC("Attempting to associate with new "
8686 "parameters.\n");
8687 ipw_associate(priv);
8688 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008689 return 0;
8690 }
8691
8692 priv->config |= CFG_STATIC_BSSID;
8693 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8694 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008695 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008696 return 0;
8697 }
8698
8699 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8700 MAC_ARG(wrqu->ap_addr.sa_data));
8701
8702 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8703
James Ketrenosc848d0a2005-08-24 21:56:24 -05008704 /* Network configuration changed -- force [re]association */
8705 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8706 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008707 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008708
James Ketrenosc848d0a2005-08-24 21:56:24 -05008709 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008710 return 0;
8711}
8712
Jeff Garzikbf794512005-07-31 13:07:26 -04008713static int ipw_wx_get_wap(struct net_device *dev,
8714 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008715 union iwreq_data *wrqu, char *extra)
8716{
8717 struct ipw_priv *priv = ieee80211_priv(dev);
8718 /* If we are associated, trying to associate, or have a statically
8719 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008720 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008721 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008722 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8723 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008724 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008725 } else
8726 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8727
8728 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8729 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008730 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008731 return 0;
8732}
8733
Jeff Garzikbf794512005-07-31 13:07:26 -04008734static int ipw_wx_set_essid(struct net_device *dev,
8735 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008736 union iwreq_data *wrqu, char *extra)
8737{
8738 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008739 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008740 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008741 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008742 if (wrqu->essid.flags && wrqu->essid.length) {
8743 length = wrqu->essid.length - 1;
8744 essid = extra;
8745 }
8746 if (length == 0) {
8747 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008748 if ((priv->config & CFG_STATIC_ESSID) &&
8749 !(priv->status & (STATUS_ASSOCIATED |
8750 STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008751 IPW_DEBUG_ASSOC("Attempting to associate with new "
8752 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008753 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008754 ipw_associate(priv);
8755 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008756 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008757 return 0;
8758 }
8759
8760 length = min(length, IW_ESSID_MAX_SIZE);
8761
8762 priv->config |= CFG_STATIC_ESSID;
8763
8764 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8765 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008766 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008767 return 0;
8768 }
8769
8770 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8771 length);
8772
8773 priv->essid_len = length;
8774 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008775
James Ketrenosc848d0a2005-08-24 21:56:24 -05008776 /* Network configuration changed -- force [re]association */
8777 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8778 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008779 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008780
James Ketrenosc848d0a2005-08-24 21:56:24 -05008781 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008782 return 0;
8783}
8784
Jeff Garzikbf794512005-07-31 13:07:26 -04008785static int ipw_wx_get_essid(struct net_device *dev,
8786 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008787 union iwreq_data *wrqu, char *extra)
8788{
8789 struct ipw_priv *priv = ieee80211_priv(dev);
8790
8791 /* If we are associated, trying to associate, or have a statically
8792 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008793 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008794 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008795 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8796 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008797 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008798 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008799 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008800 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008801 } else {
8802 IPW_DEBUG_WX("Getting essid: ANY\n");
8803 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008804 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008805 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008806 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 return 0;
8808}
8809
Jeff Garzikbf794512005-07-31 13:07:26 -04008810static int ipw_wx_set_nick(struct net_device *dev,
8811 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008812 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008813{
James Ketrenos43f66a62005-03-25 12:31:53 -06008814 struct ipw_priv *priv = ieee80211_priv(dev);
8815
8816 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8817 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8818 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008819 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008820 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008821 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008822 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008823 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008824 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008825 return 0;
8826
8827}
8828
Jeff Garzikbf794512005-07-31 13:07:26 -04008829static int ipw_wx_get_nick(struct net_device *dev,
8830 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008832{
James Ketrenos43f66a62005-03-25 12:31:53 -06008833 struct ipw_priv *priv = ieee80211_priv(dev);
8834 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008835 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 wrqu->data.length = strlen(priv->nick) + 1;
8837 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008838 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008839 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 return 0;
8841}
8842
James Ketrenos43f66a62005-03-25 12:31:53 -06008843static int ipw_wx_set_rate(struct net_device *dev,
8844 struct iw_request_info *info,
8845 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008846{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008847 /* TODO: We should use semaphores or locks for access to priv */
8848 struct ipw_priv *priv = ieee80211_priv(dev);
8849 u32 target_rate = wrqu->bitrate.value;
8850 u32 fixed, mask;
8851
8852 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8853 /* value = X, fixed = 1 means only rate X */
8854 /* value = X, fixed = 0 means all rates lower equal X */
8855
8856 if (target_rate == -1) {
8857 fixed = 0;
8858 mask = IEEE80211_DEFAULT_RATES_MASK;
8859 /* Now we should reassociate */
8860 goto apply;
8861 }
8862
8863 mask = 0;
8864 fixed = wrqu->bitrate.fixed;
8865
8866 if (target_rate == 1000000 || !fixed)
8867 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8868 if (target_rate == 1000000)
8869 goto apply;
8870
8871 if (target_rate == 2000000 || !fixed)
8872 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8873 if (target_rate == 2000000)
8874 goto apply;
8875
8876 if (target_rate == 5500000 || !fixed)
8877 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8878 if (target_rate == 5500000)
8879 goto apply;
8880
8881 if (target_rate == 6000000 || !fixed)
8882 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8883 if (target_rate == 6000000)
8884 goto apply;
8885
8886 if (target_rate == 9000000 || !fixed)
8887 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8888 if (target_rate == 9000000)
8889 goto apply;
8890
8891 if (target_rate == 11000000 || !fixed)
8892 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8893 if (target_rate == 11000000)
8894 goto apply;
8895
8896 if (target_rate == 12000000 || !fixed)
8897 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8898 if (target_rate == 12000000)
8899 goto apply;
8900
8901 if (target_rate == 18000000 || !fixed)
8902 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8903 if (target_rate == 18000000)
8904 goto apply;
8905
8906 if (target_rate == 24000000 || !fixed)
8907 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8908 if (target_rate == 24000000)
8909 goto apply;
8910
8911 if (target_rate == 36000000 || !fixed)
8912 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8913 if (target_rate == 36000000)
8914 goto apply;
8915
8916 if (target_rate == 48000000 || !fixed)
8917 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8918 if (target_rate == 48000000)
8919 goto apply;
8920
8921 if (target_rate == 54000000 || !fixed)
8922 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8923 if (target_rate == 54000000)
8924 goto apply;
8925
8926 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8927 return -EINVAL;
8928
8929 apply:
8930 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8931 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008932 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008933 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008934 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008935 ipw_set_fixed_rate(priv, priv->ieee->mode);
8936 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008937 priv->config |= CFG_FIXED_RATE;
8938
James Ketrenosc848d0a2005-08-24 21:56:24 -05008939 if (priv->rates_mask == mask) {
8940 IPW_DEBUG_WX("Mask set to current mask.\n");
8941 up(&priv->sem);
8942 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008943 }
8944
James Ketrenosc848d0a2005-08-24 21:56:24 -05008945 priv->rates_mask = mask;
8946
8947 /* Network configuration changed -- force [re]association */
8948 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8949 if (!ipw_disassociate(priv))
8950 ipw_associate(priv);
8951
8952 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008953 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008954}
8955
Jeff Garzikbf794512005-07-31 13:07:26 -04008956static int ipw_wx_get_rate(struct net_device *dev,
8957 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008958 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008959{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008960 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008961 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008962 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008963 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008964 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8965 return 0;
8966}
8967
Jeff Garzikbf794512005-07-31 13:07:26 -04008968static int ipw_wx_set_rts(struct net_device *dev,
8969 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008970 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008971{
James Ketrenos43f66a62005-03-25 12:31:53 -06008972 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008973 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008974 if (wrqu->rts.disabled)
8975 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8976 else {
8977 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008978 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8979 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008980 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008981 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008982 priv->rts_threshold = wrqu->rts.value;
8983 }
8984
8985 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008986 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008987 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8988 return 0;
8989}
8990
Jeff Garzikbf794512005-07-31 13:07:26 -04008991static int ipw_wx_get_rts(struct net_device *dev,
8992 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008993 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008994{
James Ketrenos43f66a62005-03-25 12:31:53 -06008995 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008996 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008997 wrqu->rts.value = priv->rts_threshold;
8998 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008999 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009000 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009001 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9002 return 0;
9003}
9004
Jeff Garzikbf794512005-07-31 13:07:26 -04009005static int ipw_wx_set_txpow(struct net_device *dev,
9006 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009007 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009008{
James Ketrenos43f66a62005-03-25 12:31:53 -06009009 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009010 int err = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05009011
James Ketrenosc848d0a2005-08-24 21:56:24 -05009012 down(&priv->sem);
9013 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009014 err = -EINPROGRESS;
9015 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009016 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009017
James Ketrenosb095c382005-08-24 22:04:42 -05009018 if (!wrqu->power.fixed)
9019 wrqu->power.value = IPW_TX_POWER_DEFAULT;
9020
James Ketrenosc848d0a2005-08-24 21:56:24 -05009021 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009022 err = -EINVAL;
9023 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009024 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009025
James Ketrenosb095c382005-08-24 22:04:42 -05009026 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009027 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009028 err = -EINVAL;
9029 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009030 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009031
9032 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009033 err = ipw_set_tx_power(priv);
9034 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009035 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009036 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009037}
9038
Jeff Garzikbf794512005-07-31 13:07:26 -04009039static int ipw_wx_get_txpow(struct net_device *dev,
9040 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009041 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009042{
James Ketrenos43f66a62005-03-25 12:31:53 -06009043 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009044 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009045 wrqu->power.value = priv->tx_power;
9046 wrqu->power.fixed = 1;
9047 wrqu->power.flags = IW_TXPOW_DBM;
9048 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009049 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009050
Jeff Garzikbf794512005-07-31 13:07:26 -04009051 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009052 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009053
9054 return 0;
9055}
9056
Jeff Garzikbf794512005-07-31 13:07:26 -04009057static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009058 struct iw_request_info *info,
9059 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009060{
9061 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009062 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009063 if (wrqu->frag.disabled)
9064 priv->ieee->fts = DEFAULT_FTS;
9065 else {
9066 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009067 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9068 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009069 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009070 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009071
James Ketrenos43f66a62005-03-25 12:31:53 -06009072 priv->ieee->fts = wrqu->frag.value & ~0x1;
9073 }
9074
9075 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009076 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009077 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9078 return 0;
9079}
9080
Jeff Garzikbf794512005-07-31 13:07:26 -04009081static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009082 struct iw_request_info *info,
9083 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009084{
9085 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009086 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009087 wrqu->frag.value = priv->ieee->fts;
9088 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009089 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009090 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009091 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9092
9093 return 0;
9094}
9095
Jeff Garzikbf794512005-07-31 13:07:26 -04009096static int ipw_wx_set_retry(struct net_device *dev,
9097 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009098 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009099{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009100 struct ipw_priv *priv = ieee80211_priv(dev);
9101
9102 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9103 return -EINVAL;
9104
9105 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9106 return 0;
9107
9108 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9109 return -EINVAL;
9110
9111 down(&priv->sem);
9112 if (wrqu->retry.flags & IW_RETRY_MIN)
9113 priv->short_retry_limit = (u8) wrqu->retry.value;
9114 else if (wrqu->retry.flags & IW_RETRY_MAX)
9115 priv->long_retry_limit = (u8) wrqu->retry.value;
9116 else {
9117 priv->short_retry_limit = (u8) wrqu->retry.value;
9118 priv->long_retry_limit = (u8) wrqu->retry.value;
9119 }
9120
9121 ipw_send_retry_limit(priv, priv->short_retry_limit,
9122 priv->long_retry_limit);
9123 up(&priv->sem);
9124 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9125 priv->short_retry_limit, priv->long_retry_limit);
9126 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009127}
9128
Jeff Garzikbf794512005-07-31 13:07:26 -04009129static int ipw_wx_get_retry(struct net_device *dev,
9130 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009131 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009132{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009133 struct ipw_priv *priv = ieee80211_priv(dev);
9134
9135 down(&priv->sem);
9136 wrqu->retry.disabled = 0;
9137
9138 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9139 up(&priv->sem);
9140 return -EINVAL;
9141 }
9142
9143 if (wrqu->retry.flags & IW_RETRY_MAX) {
9144 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9145 wrqu->retry.value = priv->long_retry_limit;
9146 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9147 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9148 wrqu->retry.value = priv->short_retry_limit;
9149 } else {
9150 wrqu->retry.flags = IW_RETRY_LIMIT;
9151 wrqu->retry.value = priv->short_retry_limit;
9152 }
9153 up(&priv->sem);
9154
9155 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9156
9157 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009158}
9159
James Ketrenosafbf30a2005-08-25 00:05:33 -05009160#if WIRELESS_EXT > 17
9161static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9162 int essid_len)
9163{
9164 struct ipw_scan_request_ext scan;
9165 int err = 0, scan_type;
9166
9167 down(&priv->sem);
9168
9169 if (priv->status & STATUS_RF_KILL_MASK) {
9170 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9171 priv->status |= STATUS_SCAN_PENDING;
9172 goto done;
9173 }
9174
9175 IPW_DEBUG_HC("starting request direct scan!\n");
9176
9177 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9178 err = wait_event_interruptible(priv->wait_state,
9179 !(priv->
9180 status & (STATUS_SCANNING |
9181 STATUS_SCAN_ABORTING)));
9182 if (err) {
9183 IPW_DEBUG_HC("aborting direct scan");
9184 goto done;
9185 }
9186 }
9187 memset(&scan, 0, sizeof(scan));
9188
9189 if (priv->config & CFG_SPEED_SCAN)
9190 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9191 cpu_to_le16(30);
9192 else
9193 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9194 cpu_to_le16(20);
9195
9196 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9197 cpu_to_le16(20);
9198 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
9199 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9200
9201 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9202
9203 err = ipw_send_ssid(priv, essid, essid_len);
9204 if (err) {
9205 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9206 goto done;
9207 }
9208 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9209
9210 ipw_add_scan_channels(priv, &scan, scan_type);
9211
9212 err = ipw_send_scan_request_ext(priv, &scan);
9213 if (err) {
9214 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9215 goto done;
9216 }
9217
9218 priv->status |= STATUS_SCANNING;
9219
9220 done:
9221 up(&priv->sem);
9222 return err;
9223}
9224#endif /* WIRELESS_EXT > 17 */
9225
Jeff Garzikbf794512005-07-31 13:07:26 -04009226static int ipw_wx_set_scan(struct net_device *dev,
9227 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009228 union iwreq_data *wrqu, char *extra)
9229{
9230 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009231#if WIRELESS_EXT > 17
9232 struct iw_scan_req *req = NULL;
9233 if (wrqu->data.length
9234 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9235 req = (struct iw_scan_req *)extra;
9236 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9237 ipw_request_direct_scan(priv, req->essid,
9238 req->essid_len);
9239 return 0;
9240 }
9241 }
9242#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009243 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009244
9245 queue_work(priv->workqueue, &priv->request_scan);
9246
James Ketrenos43f66a62005-03-25 12:31:53 -06009247 return 0;
9248}
9249
Jeff Garzikbf794512005-07-31 13:07:26 -04009250static int ipw_wx_get_scan(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 Ketrenos43f66a62005-03-25 12:31:53 -06009254 struct ipw_priv *priv = ieee80211_priv(dev);
9255 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9256}
9257
Jeff Garzikbf794512005-07-31 13:07:26 -04009258static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009259 struct iw_request_info *info,
9260 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009261{
9262 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009263 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009264 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009265
9266 down(&priv->sem);
9267 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009268
Hong Liucaeff812005-08-05 17:25:50 +08009269 /* In IBSS mode, we need to notify the firmware to update
9270 * the beacon info after we changed the capability. */
9271 if (cap != priv->capability &&
9272 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9273 priv->status & STATUS_ASSOCIATED)
9274 ipw_disassociate(priv);
9275
9276 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009277 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009278}
9279
Jeff Garzikbf794512005-07-31 13:07:26 -04009280static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009281 struct iw_request_info *info,
9282 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009283{
9284 struct ipw_priv *priv = ieee80211_priv(dev);
9285 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9286}
9287
Jeff Garzikbf794512005-07-31 13:07:26 -04009288static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009289 struct iw_request_info *info,
9290 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009291{
9292 struct ipw_priv *priv = ieee80211_priv(dev);
9293 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009294 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009295 if (wrqu->power.disabled) {
9296 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9297 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9298 if (err) {
9299 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009300 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009301 return err;
9302 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009303 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009304 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009305 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009306 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009307
9308 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009309 case IW_POWER_ON: /* If not specified */
9310 case IW_POWER_MODE: /* If set all mask */
9311 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009312 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009313 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009314 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9315 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009316 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009317 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009318 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009319
James Ketrenos43f66a62005-03-25 12:31:53 -06009320 /* If the user hasn't specified a power management mode yet, default
9321 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009322 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009323 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009324 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009325 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9326 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9327 if (err) {
9328 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009329 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009330 return err;
9331 }
9332
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009333 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009334 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009335 return 0;
9336}
9337
Jeff Garzikbf794512005-07-31 13:07:26 -04009338static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009339 struct iw_request_info *info,
9340 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009341{
9342 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009343 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009344 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009345 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009346 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009347 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009348
James Ketrenosc848d0a2005-08-24 21:56:24 -05009349 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009350 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009351
James Ketrenos43f66a62005-03-25 12:31:53 -06009352 return 0;
9353}
9354
Jeff Garzikbf794512005-07-31 13:07:26 -04009355static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009356 struct iw_request_info *info,
9357 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009358{
9359 struct ipw_priv *priv = ieee80211_priv(dev);
9360 int mode = *(int *)extra;
9361 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009362 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009363 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9364 mode = IPW_POWER_AC;
9365 priv->power_mode = mode;
9366 } else {
9367 priv->power_mode = IPW_POWER_ENABLED | mode;
9368 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009369
James Ketrenos43f66a62005-03-25 12:31:53 -06009370 if (priv->power_mode != mode) {
9371 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009372
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 if (err) {
9374 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009375 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009376 return err;
9377 }
9378 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009379 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009380 return 0;
9381}
9382
9383#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009384static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009385 struct iw_request_info *info,
9386 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009387{
9388 struct ipw_priv *priv = ieee80211_priv(dev);
9389 int level = IPW_POWER_LEVEL(priv->power_mode);
9390 char *p = extra;
9391
9392 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9393
9394 switch (level) {
9395 case IPW_POWER_AC:
9396 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9397 break;
9398 case IPW_POWER_BATTERY:
9399 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9400 break;
9401 default:
9402 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009403 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009404 timeout_duration[level - 1] / 1000,
9405 period_duration[level - 1] / 1000);
9406 }
9407
9408 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009409 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009410
9411 wrqu->data.length = p - extra + 1;
9412
9413 return 0;
9414}
9415
9416static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009417 struct iw_request_info *info,
9418 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009419{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009420 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 int mode = *(int *)extra;
9422 u8 band = 0, modulation = 0;
9423
9424 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009425 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009426 return -EINVAL;
9427 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009428 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009429 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009430 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009431 if (mode & IEEE_A) {
9432 band |= IEEE80211_52GHZ_BAND;
9433 modulation |= IEEE80211_OFDM_MODULATION;
9434 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009435 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009436 } else {
9437 if (mode & IEEE_A) {
9438 IPW_WARNING("Attempt to set 2200BG into "
9439 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009440 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009441 return -EINVAL;
9442 }
9443
James Ketrenosa33a1982005-09-14 14:28:59 -05009444 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 }
9446
9447 if (mode & IEEE_B) {
9448 band |= IEEE80211_24GHZ_BAND;
9449 modulation |= IEEE80211_CCK_MODULATION;
9450 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009451 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009452
James Ketrenos43f66a62005-03-25 12:31:53 -06009453 if (mode & IEEE_G) {
9454 band |= IEEE80211_24GHZ_BAND;
9455 modulation |= IEEE80211_OFDM_MODULATION;
9456 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009457 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009458
9459 priv->ieee->mode = mode;
9460 priv->ieee->freq_band = band;
9461 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009462 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009463
James Ketrenosc848d0a2005-08-24 21:56:24 -05009464 /* Network configuration changed -- force [re]association */
9465 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9466 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009467 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009468 ipw_associate(priv);
9469 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009470
James Ketrenosa613bff2005-08-24 21:43:11 -05009471 /* Update the band LEDs */
9472 ipw_led_band_on(priv);
9473
Jeff Garzikbf794512005-07-31 13:07:26 -04009474 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009475 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009476 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009477 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009478 return 0;
9479}
9480
9481static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009482 struct iw_request_info *info,
9483 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009484{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009485 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009486 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009487 switch (priv->ieee->mode) {
9488 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009489 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9490 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009491 case IEEE_B:
9492 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9493 break;
9494 case IEEE_A | IEEE_B:
9495 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9496 break;
9497 case IEEE_G:
9498 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9499 break;
9500 case IEEE_A | IEEE_G:
9501 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9502 break;
9503 case IEEE_B | IEEE_G:
9504 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9505 break;
9506 case IEEE_A | IEEE_B | IEEE_G:
9507 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9508 break;
9509 default:
9510 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009511 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009512 }
9513
James Ketrenos43f66a62005-03-25 12:31:53 -06009514 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9515
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009516 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009517 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009518
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009519 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009520}
9521
James Ketrenosea2b26e2005-08-24 21:25:16 -05009522static int ipw_wx_set_preamble(struct net_device *dev,
9523 struct iw_request_info *info,
9524 union iwreq_data *wrqu, char *extra)
9525{
9526 struct ipw_priv *priv = ieee80211_priv(dev);
9527 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009528 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009529 /* Switching from SHORT -> LONG requires a disassociation */
9530 if (mode == 1) {
9531 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9532 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009533
9534 /* Network configuration changed -- force [re]association */
9535 IPW_DEBUG_ASSOC
9536 ("[re]association triggered due to preamble change.\n");
9537 if (!ipw_disassociate(priv))
9538 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009539 }
9540 goto done;
9541 }
9542
9543 if (mode == 0) {
9544 priv->config &= ~CFG_PREAMBLE_LONG;
9545 goto done;
9546 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009547 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009548 return -EINVAL;
9549
9550 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009551 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009552 return 0;
9553}
9554
9555static int ipw_wx_get_preamble(struct net_device *dev,
9556 struct iw_request_info *info,
9557 union iwreq_data *wrqu, char *extra)
9558{
9559 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009560 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009561 if (priv->config & CFG_PREAMBLE_LONG)
9562 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9563 else
9564 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009565 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009566 return 0;
9567}
9568
James Ketrenosb095c382005-08-24 22:04:42 -05009569#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009570static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009571 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009572 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009573{
James Ketrenos43f66a62005-03-25 12:31:53 -06009574 struct ipw_priv *priv = ieee80211_priv(dev);
9575 int *parms = (int *)extra;
9576 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009577 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009578 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009579 if (enable) {
9580 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9581 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosa613bff2005-08-24 21:43:11 -05009582 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009583 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009584
James Ketrenos43f66a62005-03-25 12:31:53 -06009585 ipw_set_channel(priv, parms[1]);
9586 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009587 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9588 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009589 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009590 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009591 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009592 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009593 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009594 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009595 return 0;
9596}
9597
James Ketrenosb095c382005-08-24 22:04:42 -05009598#endif // CONFIG_IPW2200_MONITOR
9599
Jeff Garzikbf794512005-07-31 13:07:26 -04009600static int ipw_wx_reset(struct net_device *dev,
9601 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009602 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009603{
James Ketrenos43f66a62005-03-25 12:31:53 -06009604 struct ipw_priv *priv = ieee80211_priv(dev);
9605 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009606 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009607 return 0;
9608}
James Ketrenosb095c382005-08-24 22:04:42 -05009609
James Ketrenosb095c382005-08-24 22:04:42 -05009610static int ipw_wx_sw_reset(struct net_device *dev,
9611 struct iw_request_info *info,
9612 union iwreq_data *wrqu, char *extra)
9613{
9614 struct ipw_priv *priv = ieee80211_priv(dev);
9615 union iwreq_data wrqu_sec = {
9616 .encoding = {
9617 .flags = IW_ENCODE_DISABLED,
9618 },
9619 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009620 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009621
9622 IPW_DEBUG_WX("SW_RESET\n");
9623
9624 down(&priv->sem);
9625
James Ketrenosafbf30a2005-08-25 00:05:33 -05009626 ret = ipw_sw_reset(priv, 0);
9627 if (!ret) {
9628 free_firmware();
9629 ipw_adapter_restart(priv);
9630 }
James Ketrenosb095c382005-08-24 22:04:42 -05009631
9632 /* The SW reset bit might have been toggled on by the 'disable'
9633 * module parameter, so take appropriate action */
9634 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9635
9636 up(&priv->sem);
9637 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9638 down(&priv->sem);
9639
9640 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9641 /* Configuration likely changed -- force [re]association */
9642 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9643 "reset.\n");
9644 if (!ipw_disassociate(priv))
9645 ipw_associate(priv);
9646 }
9647
9648 up(&priv->sem);
9649
9650 return 0;
9651}
James Ketrenos43f66a62005-03-25 12:31:53 -06009652
9653/* Rebase the WE IOCTLs to zero for the handler array */
9654#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009655static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009656 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9657 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9658 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9659 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9660 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9661 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9662 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9663 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9664 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9665 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9666 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9667 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9668 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9669 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9670 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9671 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9672 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9673 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9674 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9675 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9676 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9677 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9678 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9679 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9680 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9681 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9682 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9683 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009684 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9685 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9686 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9687 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009688#if WIRELESS_EXT > 17
9689 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9690 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9691 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9692 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9693 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9694 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9695 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9696#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009697};
9698
James Ketrenosb095c382005-08-24 22:04:42 -05009699enum {
9700 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9701 IPW_PRIV_GET_POWER,
9702 IPW_PRIV_SET_MODE,
9703 IPW_PRIV_GET_MODE,
9704 IPW_PRIV_SET_PREAMBLE,
9705 IPW_PRIV_GET_PREAMBLE,
9706 IPW_PRIV_RESET,
9707 IPW_PRIV_SW_RESET,
9708#ifdef CONFIG_IPW2200_MONITOR
9709 IPW_PRIV_SET_MONITOR,
9710#endif
9711};
James Ketrenos43f66a62005-03-25 12:31:53 -06009712
Jeff Garzikbf794512005-07-31 13:07:26 -04009713static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009714 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009715 .cmd = IPW_PRIV_SET_POWER,
9716 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9717 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009719 .cmd = IPW_PRIV_GET_POWER,
9720 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9721 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009722 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009723 .cmd = IPW_PRIV_SET_MODE,
9724 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9725 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009727 .cmd = IPW_PRIV_GET_MODE,
9728 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9729 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009730 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009731 .cmd = IPW_PRIV_SET_PREAMBLE,
9732 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9733 .name = "set_preamble"},
9734 {
9735 .cmd = IPW_PRIV_GET_PREAMBLE,
9736 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9737 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009738 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009739 IPW_PRIV_RESET,
9740 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009741 {
9742 IPW_PRIV_SW_RESET,
9743 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9744#ifdef CONFIG_IPW2200_MONITOR
9745 {
9746 IPW_PRIV_SET_MONITOR,
9747 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9748#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009749};
9750
9751static iw_handler ipw_priv_handler[] = {
9752 ipw_wx_set_powermode,
9753 ipw_wx_get_powermode,
9754 ipw_wx_set_wireless_mode,
9755 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009756 ipw_wx_set_preamble,
9757 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009758 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009759 ipw_wx_sw_reset,
9760#ifdef CONFIG_IPW2200_MONITOR
9761 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009762#endif
9763};
9764
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009765static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009766 .standard = ipw_wx_handlers,
9767 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9768 .num_private = ARRAY_SIZE(ipw_priv_handler),
9769 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9770 .private = ipw_priv_handler,
9771 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06009772};
9773
James Ketrenosa613bff2005-08-24 21:43:11 -05009774static struct iw_public_data ipw_wx_data;
9775
James Ketrenos43f66a62005-03-25 12:31:53 -06009776/*
9777 * Get wireless statistics.
9778 * Called by /proc/net/wireless
9779 * Also called by SIOCGIWSTATS
9780 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009781static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009782{
9783 struct ipw_priv *priv = ieee80211_priv(dev);
9784 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009785
James Ketrenos43f66a62005-03-25 12:31:53 -06009786 wstats = &priv->wstats;
9787
James Ketrenosea2b26e2005-08-24 21:25:16 -05009788 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009789 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9791 * and associated; if not associcated, the values are all meaningless
9792 * anyway, so set them all to NULL and INVALID */
9793 if (!(priv->status & STATUS_ASSOCIATED)) {
9794 wstats->miss.beacon = 0;
9795 wstats->discard.retries = 0;
9796 wstats->qual.qual = 0;
9797 wstats->qual.level = 0;
9798 wstats->qual.noise = 0;
9799 wstats->qual.updated = 7;
9800 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009801 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009802 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009803 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009804
9805 wstats->qual.qual = priv->quality;
9806 wstats->qual.level = average_value(&priv->average_rssi);
9807 wstats->qual.noise = average_value(&priv->average_noise);
9808 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009809 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009810
9811 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9812 wstats->discard.retries = priv->last_tx_failures;
9813 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009814
James Ketrenos43f66a62005-03-25 12:31:53 -06009815/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9816 goto fail_get_ordinal;
9817 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009818
James Ketrenos43f66a62005-03-25 12:31:53 -06009819 return wstats;
9820}
9821
James Ketrenos43f66a62005-03-25 12:31:53 -06009822/* net device stuff */
9823
9824static inline void init_sys_config(struct ipw_sys_config *sys_config)
9825{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009826 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9827 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06009828 sys_config->answer_broadcast_ssid_probe = 0;
9829 sys_config->accept_all_data_frames = 0;
9830 sys_config->accept_non_directed_frames = 1;
9831 sys_config->exclude_unicast_unencrypted = 0;
9832 sys_config->disable_unicast_decryption = 1;
9833 sys_config->exclude_multicast_unencrypted = 0;
9834 sys_config->disable_multicast_decryption = 1;
9835 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009836 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009837 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009838 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009839 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009840 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009841}
9842
9843static int ipw_net_open(struct net_device *dev)
9844{
9845 struct ipw_priv *priv = ieee80211_priv(dev);
9846 IPW_DEBUG_INFO("dev->open\n");
9847 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009848 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009849 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9850 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009851 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009852 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009853 return 0;
9854}
9855
9856static int ipw_net_stop(struct net_device *dev)
9857{
9858 IPW_DEBUG_INFO("dev->close\n");
9859 netif_stop_queue(dev);
9860 return 0;
9861}
9862
9863/*
9864todo:
9865
9866modify to send one tfd per fragment instead of using chunking. otherwise
9867we need to heavily modify the ieee80211_skb_to_txb.
9868*/
9869
James Ketrenos227d2dc2005-07-28 16:25:55 -05009870static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9871 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009872{
James Ketrenos0dacca12005-09-21 12:23:41 -05009873 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009874 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009875 int i = 0;
9876 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009877#ifdef CONFIG_IPW_QOS
9878 int tx_id = ipw_get_tx_queue_number(priv, pri);
9879 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9880#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009881 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009882#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009883 struct clx2_queue *q = &txq->q;
9884 u8 id, hdr_len, unicast;
9885 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009886 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009887
James Ketrenos227d2dc2005-07-28 16:25:55 -05009888 /* If there isn't room in the queue, we return busy and let the
9889 * network stack requeue the packet for us */
9890 if (ipw_queue_space(q) < q->high_mark)
9891 return NETDEV_TX_BUSY;
9892
James Ketrenos43f66a62005-03-25 12:31:53 -06009893 switch (priv->ieee->iw_mode) {
9894 case IW_MODE_ADHOC:
9895 hdr_len = IEEE80211_3ADDR_LEN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009896 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009897 id = ipw_find_station(priv, hdr->addr1);
9898 if (id == IPW_INVALID_STATION) {
9899 id = ipw_add_station(priv, hdr->addr1);
9900 if (id == IPW_INVALID_STATION) {
9901 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009902 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009903 MAC_ARG(hdr->addr1));
9904 goto drop;
9905 }
9906 }
9907 break;
9908
9909 case IW_MODE_INFRA:
9910 default:
James Ketrenosafbf30a2005-08-25 00:05:33 -05009911 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009912 hdr_len = IEEE80211_3ADDR_LEN;
9913 id = 0;
9914 break;
9915 }
9916
9917 tfd = &txq->bd[q->first_empty];
9918 txq->txb[q->first_empty] = txb;
9919 memset(tfd, 0, sizeof(*tfd));
9920 tfd->u.data.station_number = id;
9921
9922 tfd->control_flags.message_type = TX_FRAME_TYPE;
9923 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9924
9925 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009926 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009927 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009928
James Ketrenos43f66a62005-03-25 12:31:53 -06009929 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009930 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 else
James Ketrenosb095c382005-08-24 22:04:42 -05009932 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009933
James Ketrenosea2b26e2005-08-24 21:25:16 -05009934 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9935 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009936
James Ketrenosc848d0a2005-08-24 21:56:24 -05009937 fc = le16_to_cpu(hdr->frame_ctl);
9938 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9939
James Ketrenos43f66a62005-03-25 12:31:53 -06009940 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9941
James Ketrenosb095c382005-08-24 22:04:42 -05009942 if (likely(unicast))
9943 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9944
9945 if (txb->encrypted && !priv->ieee->host_encrypt) {
9946 switch (priv->ieee->sec.level) {
9947 case SEC_LEVEL_3:
9948 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9949 IEEE80211_FCTL_PROTECTED;
9950 /* XXX: ACK flag must be set for CCMP even if it
9951 * is a multicast/broadcast packet, because CCMP
9952 * group communication encrypted by GTK is
9953 * actually done by the AP. */
9954 if (!unicast)
9955 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9956
9957 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9958 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9959 tfd->u.data.key_index = 0;
9960 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9961 break;
9962 case SEC_LEVEL_2:
9963 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9964 IEEE80211_FCTL_PROTECTED;
9965 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9966 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9967 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9968 break;
9969 case SEC_LEVEL_1:
9970 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9971 IEEE80211_FCTL_PROTECTED;
9972 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9973 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9974 40)
9975 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9976 else
9977 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9978 break;
9979 case SEC_LEVEL_0:
9980 break;
9981 default:
9982 printk(KERN_ERR "Unknow security level %d\n",
9983 priv->ieee->sec.level);
9984 break;
9985 }
9986 } else
9987 /* No hardware encryption */
9988 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9989
9990#ifdef CONFIG_IPW_QOS
9991 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9992#endif /* CONFIG_IPW_QOS */
9993
James Ketrenos43f66a62005-03-25 12:31:53 -06009994 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009995 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9996 txb->nr_frags));
9997 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9998 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9999 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10000 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10001 i, le32_to_cpu(tfd->u.data.num_chunks),
10002 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010003 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010004 i, tfd->u.data.num_chunks,
10005 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010006 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010007 txb->fragments[i]->len - hdr_len);
10008
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010009 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010010 cpu_to_le32(pci_map_single
10011 (priv->pci_dev,
10012 txb->fragments[i]->data + hdr_len,
10013 txb->fragments[i]->len - hdr_len,
10014 PCI_DMA_TODEVICE));
10015 tfd->u.data.chunk_len[i] =
10016 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010017 }
10018
10019 if (i != txb->nr_frags) {
10020 struct sk_buff *skb;
10021 u16 remaining_bytes = 0;
10022 int j;
10023
10024 for (j = i; j < txb->nr_frags; j++)
10025 remaining_bytes += txb->fragments[j]->len - hdr_len;
10026
10027 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10028 remaining_bytes);
10029 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10030 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010031 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010032 for (j = i; j < txb->nr_frags; j++) {
10033 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010034
James Ketrenos43f66a62005-03-25 12:31:53 -060010035 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010036 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010037 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010038 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010039 }
10040 dev_kfree_skb_any(txb->fragments[i]);
10041 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010042 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010043 cpu_to_le32(pci_map_single
10044 (priv->pci_dev, skb->data,
10045 tfd->u.data.chunk_len[i],
10046 PCI_DMA_TODEVICE));
10047
10048 tfd->u.data.num_chunks =
10049 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10050 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010051 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010052 }
10053
10054 /* kick DMA */
10055 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10056 ipw_write32(priv, q->reg_w, q->first_empty);
10057
James Ketrenos227d2dc2005-07-28 16:25:55 -050010058 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010059
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010060 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010061 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10062 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010063 return NETDEV_TX_OK;
10064}
10065
10066static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10067{
10068 struct ipw_priv *priv = ieee80211_priv(dev);
10069#ifdef CONFIG_IPW_QOS
10070 int tx_id = ipw_get_tx_queue_number(priv, pri);
10071 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10072#else
10073 struct clx2_tx_queue *txq = &priv->txq[0];
10074#endif /* CONFIG_IPW_QOS */
10075
10076 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10077 return 1;
10078
10079 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010080}
10081
10082static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010083 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010084{
10085 struct ipw_priv *priv = ieee80211_priv(dev);
10086 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010087 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010088
10089 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010090 spin_lock_irqsave(&priv->lock, flags);
10091
10092 if (!(priv->status & STATUS_ASSOCIATED)) {
10093 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10094 priv->ieee->stats.tx_carrier_errors++;
10095 netif_stop_queue(dev);
10096 goto fail_unlock;
10097 }
10098
James Ketrenos227d2dc2005-07-28 16:25:55 -050010099 ret = ipw_tx_skb(priv, txb, pri);
10100 if (ret == NETDEV_TX_OK)
10101 __ipw_led_activity_on(priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010102 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010103
James Ketrenos227d2dc2005-07-28 16:25:55 -050010104 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010105
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010106 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010107 spin_unlock_irqrestore(&priv->lock, flags);
10108 return 1;
10109}
10110
10111static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10112{
10113 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010114
James Ketrenos43f66a62005-03-25 12:31:53 -060010115 priv->ieee->stats.tx_packets = priv->tx_packets;
10116 priv->ieee->stats.rx_packets = priv->rx_packets;
10117 return &priv->ieee->stats;
10118}
10119
10120static void ipw_net_set_multicast_list(struct net_device *dev)
10121{
10122
10123}
10124
10125static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10126{
10127 struct ipw_priv *priv = ieee80211_priv(dev);
10128 struct sockaddr *addr = p;
10129 if (!is_valid_ether_addr(addr->sa_data))
10130 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010131 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010132 priv->config |= CFG_CUSTOM_MAC;
10133 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10134 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10135 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010136 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010137 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 return 0;
10139}
10140
Jeff Garzikbf794512005-07-31 13:07:26 -040010141static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 struct ethtool_drvinfo *info)
10143{
10144 struct ipw_priv *p = ieee80211_priv(dev);
10145 char vers[64];
10146 char date[32];
10147 u32 len;
10148
10149 strcpy(info->driver, DRV_NAME);
10150 strcpy(info->version, DRV_VERSION);
10151
10152 len = sizeof(vers);
10153 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10154 len = sizeof(date);
10155 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10156
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010157 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010158 vers, date);
10159 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010160 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010161}
10162
10163static u32 ipw_ethtool_get_link(struct net_device *dev)
10164{
10165 struct ipw_priv *priv = ieee80211_priv(dev);
10166 return (priv->status & STATUS_ASSOCIATED) != 0;
10167}
10168
10169static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10170{
James Ketrenosb095c382005-08-24 22:04:42 -050010171 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010172}
10173
10174static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010175 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010176{
10177 struct ipw_priv *p = ieee80211_priv(dev);
10178
James Ketrenosb095c382005-08-24 22:04:42 -050010179 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010181 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010182 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010183 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010184 return 0;
10185}
10186
10187static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010188 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010189{
10190 struct ipw_priv *p = ieee80211_priv(dev);
10191 int i;
10192
James Ketrenosb095c382005-08-24 22:04:42 -050010193 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010194 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010195 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010196 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010197 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -050010198 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -060010199 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010200 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010201 return 0;
10202}
10203
10204static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010205 .get_link = ipw_ethtool_get_link,
10206 .get_drvinfo = ipw_ethtool_get_drvinfo,
10207 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10208 .get_eeprom = ipw_ethtool_get_eeprom,
10209 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010210};
10211
10212static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10213{
10214 struct ipw_priv *priv = data;
10215 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010216
James Ketrenos43f66a62005-03-25 12:31:53 -060010217 if (!priv)
10218 return IRQ_NONE;
10219
10220 spin_lock(&priv->lock);
10221
10222 if (!(priv->status & STATUS_INT_ENABLED)) {
10223 /* Shared IRQ */
10224 goto none;
10225 }
10226
James Ketrenosb095c382005-08-24 22:04:42 -050010227 inta = ipw_read32(priv, IPW_INTA_RW);
10228 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010229
James Ketrenos43f66a62005-03-25 12:31:53 -060010230 if (inta == 0xFFFFFFFF) {
10231 /* Hardware disappeared */
10232 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10233 goto none;
10234 }
10235
James Ketrenosb095c382005-08-24 22:04:42 -050010236 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010237 /* Shared interrupt */
10238 goto none;
10239 }
10240
10241 /* tell the device to stop sending interrupts */
10242 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010243
James Ketrenos43f66a62005-03-25 12:31:53 -060010244 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010245 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10246 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010247
James Ketrenos43f66a62005-03-25 12:31:53 -060010248 /* Cache INTA value for our tasklet */
10249 priv->isr_inta = inta;
10250
10251 tasklet_schedule(&priv->irq_tasklet);
10252
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010253 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010254
10255 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010256 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010257 spin_unlock(&priv->lock);
10258 return IRQ_NONE;
10259}
10260
10261static void ipw_rf_kill(void *adapter)
10262{
10263 struct ipw_priv *priv = adapter;
10264 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010265
James Ketrenos43f66a62005-03-25 12:31:53 -060010266 spin_lock_irqsave(&priv->lock, flags);
10267
10268 if (rf_kill_active(priv)) {
10269 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10270 if (priv->workqueue)
10271 queue_delayed_work(priv->workqueue,
10272 &priv->rf_kill, 2 * HZ);
10273 goto exit_unlock;
10274 }
10275
10276 /* RF Kill is now disabled, so bring the device back up */
10277
10278 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10279 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10280 "device\n");
10281
10282 /* we can not do an adapter restart while inside an irq lock */
10283 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010284 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010285 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10286 "enabled\n");
10287
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010288 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010289 spin_unlock_irqrestore(&priv->lock, flags);
10290}
10291
James Ketrenosc848d0a2005-08-24 21:56:24 -050010292static void ipw_bg_rf_kill(void *data)
10293{
10294 struct ipw_priv *priv = data;
10295 down(&priv->sem);
10296 ipw_rf_kill(data);
10297 up(&priv->sem);
10298}
10299
James Ketrenosa613bff2005-08-24 21:43:11 -050010300void ipw_link_up(struct ipw_priv *priv)
10301{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010302 priv->last_seq_num = -1;
10303 priv->last_frag_num = -1;
10304 priv->last_packet_time = 0;
10305
James Ketrenosa613bff2005-08-24 21:43:11 -050010306 netif_carrier_on(priv->net_dev);
10307 if (netif_queue_stopped(priv->net_dev)) {
10308 IPW_DEBUG_NOTIF("waking queue\n");
10309 netif_wake_queue(priv->net_dev);
10310 } else {
10311 IPW_DEBUG_NOTIF("starting queue\n");
10312 netif_start_queue(priv->net_dev);
10313 }
10314
James Ketrenosc848d0a2005-08-24 21:56:24 -050010315 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010316 ipw_reset_stats(priv);
10317 /* Ensure the rate is updated immediately */
10318 priv->last_rate = ipw_get_current_rate(priv);
10319 ipw_gather_stats(priv);
10320 ipw_led_link_up(priv);
10321 notify_wx_assoc_event(priv);
10322
10323 if (priv->config & CFG_BACKGROUND_SCAN)
10324 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10325}
10326
James Ketrenosc848d0a2005-08-24 21:56:24 -050010327static void ipw_bg_link_up(void *data)
10328{
10329 struct ipw_priv *priv = data;
10330 down(&priv->sem);
10331 ipw_link_up(data);
10332 up(&priv->sem);
10333}
10334
James Ketrenosa613bff2005-08-24 21:43:11 -050010335void ipw_link_down(struct ipw_priv *priv)
10336{
10337 ipw_led_link_down(priv);
10338 netif_carrier_off(priv->net_dev);
10339 netif_stop_queue(priv->net_dev);
10340 notify_wx_assoc_event(priv);
10341
10342 /* Cancel any queued work ... */
10343 cancel_delayed_work(&priv->request_scan);
10344 cancel_delayed_work(&priv->adhoc_check);
10345 cancel_delayed_work(&priv->gather_stats);
10346
10347 ipw_reset_stats(priv);
10348
James Ketrenosafbf30a2005-08-25 00:05:33 -050010349 if (!(priv->status & STATUS_EXIT_PENDING)) {
10350 /* Queue up another scan... */
10351 queue_work(priv->workqueue, &priv->request_scan);
10352 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010353}
10354
James Ketrenosc848d0a2005-08-24 21:56:24 -050010355static void ipw_bg_link_down(void *data)
10356{
10357 struct ipw_priv *priv = data;
10358 down(&priv->sem);
10359 ipw_link_down(data);
10360 up(&priv->sem);
10361}
10362
James Ketrenos43f66a62005-03-25 12:31:53 -060010363static int ipw_setup_deferred_work(struct ipw_priv *priv)
10364{
10365 int ret = 0;
10366
James Ketrenos43f66a62005-03-25 12:31:53 -060010367 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010368 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010369 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010370
James Ketrenosc848d0a2005-08-24 21:56:24 -050010371 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10372 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10373 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010374 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010375 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10376 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10377 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10378 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10379 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010380 INIT_WORK(&priv->request_scan,
James Ketrenosb095c382005-08-24 22:04:42 -050010381 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010382 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010383 (void (*)(void *))ipw_bg_gather_stats, priv);
10384 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10385 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10386 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10387 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10388 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10389 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010390 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010391 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010392 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010393 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10394 priv);
10395 INIT_WORK(&priv->merge_networks,
10396 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010397
James Ketrenosb095c382005-08-24 22:04:42 -050010398#ifdef CONFIG_IPW_QOS
10399 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10400 priv);
10401#endif /* CONFIG_IPW_QOS */
10402
James Ketrenos43f66a62005-03-25 12:31:53 -060010403 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10404 ipw_irq_tasklet, (unsigned long)priv);
10405
10406 return ret;
10407}
10408
James Ketrenos43f66a62005-03-25 12:31:53 -060010409static void shim__set_security(struct net_device *dev,
10410 struct ieee80211_security *sec)
10411{
10412 struct ipw_priv *priv = ieee80211_priv(dev);
10413 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010414 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010415 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010416 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010417 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010418 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010419 priv->ieee->sec.flags &= ~(1 << i);
10420 else {
10421 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010422 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010423 priv->ieee->sec.flags |= (1 << i);
10424 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010425 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010426 } else if (sec->level != SEC_LEVEL_1)
10427 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010428 }
10429
James Ketrenosb095c382005-08-24 22:04:42 -050010430 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010431 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010432 priv->ieee->sec.active_key = sec->active_key;
10433 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010434 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010435 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010436 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010437 } else
10438 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010439
10440 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010441 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10442 priv->ieee->sec.auth_mode = sec->auth_mode;
10443 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010444 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10445 priv->capability |= CAP_SHARED_KEY;
10446 else
10447 priv->capability &= ~CAP_SHARED_KEY;
10448 priv->status |= STATUS_SECURITY_UPDATED;
10449 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010450
James Ketrenosb095c382005-08-24 22:04:42 -050010451 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10452 priv->ieee->sec.flags |= SEC_ENABLED;
10453 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010454 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010455 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010456 priv->capability |= CAP_PRIVACY_ON;
10457 else
10458 priv->capability &= ~CAP_PRIVACY_ON;
10459 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010460
10461 if (sec->flags & SEC_ENCRYPT)
10462 priv->ieee->sec.encrypt = sec->encrypt;
Jeff Garzikbf794512005-07-31 13:07:26 -040010463
James Ketrenosb095c382005-08-24 22:04:42 -050010464 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10465 priv->ieee->sec.level = sec->level;
10466 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010467 priv->status |= STATUS_SECURITY_UPDATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -050010468 }
James Ketrenosb095c382005-08-24 22:04:42 -050010469
Zhu Yi1fbfea52005-08-05 17:22:56 +080010470 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10471 ipw_set_hwcrypto_keys(priv);
10472
Jeff Garzikbf794512005-07-31 13:07:26 -040010473 /* To match current functionality of ipw2100 (which works well w/
10474 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010475 * privacy capability changes ... */
10476#if 0
10477 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010478 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010479 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010480 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010481 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010482 IPW_DEBUG_ASSOC("Disassociating due to capability "
10483 "change.\n");
10484 ipw_disassociate(priv);
10485 }
10486#endif
10487}
10488
Jeff Garzikbf794512005-07-31 13:07:26 -040010489static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010490 struct ipw_supported_rates *rates)
10491{
10492 /* TODO: Mask out rates based on priv->rates_mask */
10493
10494 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010495 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010496 switch (priv->ieee->freq_band) {
10497 case IEEE80211_52GHZ_BAND:
10498 rates->ieee_mode = IPW_A_MODE;
10499 rates->purpose = IPW_RATE_CAPABILITIES;
10500 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10501 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10502 break;
10503
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010504 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010505 rates->ieee_mode = IPW_G_MODE;
10506 rates->purpose = IPW_RATE_CAPABILITIES;
10507 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10508 IEEE80211_CCK_DEFAULT_RATES_MASK);
10509 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10510 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10511 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10512 }
10513 break;
10514 }
10515
10516 return 0;
10517}
10518
Jeff Garzikbf794512005-07-31 13:07:26 -040010519static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010520{
James Ketrenos43f66a62005-03-25 12:31:53 -060010521 /* This is only called from ipw_up, which resets/reloads the firmware
10522 so, we don't need to first disable the card before we configure
10523 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010524 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010525 goto error;
10526
10527 /* initialize adapter address */
10528 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10529 goto error;
10530
10531 /* set basic system config settings */
10532 init_sys_config(&priv->sys_config);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010533 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10534 priv->sys_config.answer_broadcast_ssid_probe = 1;
10535 else
10536 priv->sys_config.answer_broadcast_ssid_probe = 0;
10537
James Ketrenos43f66a62005-03-25 12:31:53 -060010538 if (ipw_send_system_config(priv, &priv->sys_config))
10539 goto error;
10540
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010541 init_supported_rates(priv, &priv->rates);
10542 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010543 goto error;
10544
10545 /* Set request-to-send threshold */
10546 if (priv->rts_threshold) {
10547 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10548 goto error;
10549 }
James Ketrenosb095c382005-08-24 22:04:42 -050010550#ifdef CONFIG_IPW_QOS
10551 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10552 ipw_qos_activate(priv, NULL);
10553#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010554
10555 if (ipw_set_random_seed(priv))
10556 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010557
James Ketrenos43f66a62005-03-25 12:31:53 -060010558 /* final state transition to the RUN state */
10559 if (ipw_send_host_complete(priv))
10560 goto error;
10561
James Ketrenose6666192005-08-12 09:17:04 -050010562 priv->status |= STATUS_INIT;
10563
10564 ipw_led_init(priv);
10565 ipw_led_radio_on(priv);
10566 priv->notif_missed_beacons = 0;
10567
10568 /* Set hardware WEP key if it is configured. */
10569 if ((priv->capability & CAP_PRIVACY_ON) &&
10570 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10571 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10572 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010573
10574 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010575
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010576 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010577 return -EIO;
10578}
10579
James Ketrenos4f36f802005-08-03 20:36:56 -050010580/*
10581 * NOTE:
10582 *
10583 * These tables have been tested in conjunction with the
10584 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10585 *
10586 * Altering this values, using it on other hardware, or in geographies
10587 * not intended for resale of the above mentioned Intel adapters has
10588 * not been tested.
10589 *
10590 */
10591static const struct ieee80211_geo ipw_geos[] = {
10592 { /* Restricted */
10593 "---",
10594 .bg_channels = 11,
10595 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10596 {2427, 4}, {2432, 5}, {2437, 6},
10597 {2442, 7}, {2447, 8}, {2452, 9},
10598 {2457, 10}, {2462, 11}},
10599 },
10600
10601 { /* Custom US/Canada */
10602 "ZZF",
10603 .bg_channels = 11,
10604 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10605 {2427, 4}, {2432, 5}, {2437, 6},
10606 {2442, 7}, {2447, 8}, {2452, 9},
10607 {2457, 10}, {2462, 11}},
10608 .a_channels = 8,
10609 .a = {{5180, 36},
10610 {5200, 40},
10611 {5220, 44},
10612 {5240, 48},
10613 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10614 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10615 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10616 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10617 },
10618
10619 { /* Rest of World */
10620 "ZZD",
10621 .bg_channels = 13,
10622 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10623 {2427, 4}, {2432, 5}, {2437, 6},
10624 {2442, 7}, {2447, 8}, {2452, 9},
10625 {2457, 10}, {2462, 11}, {2467, 12},
10626 {2472, 13}},
10627 },
10628
10629 { /* Custom USA & Europe & High */
10630 "ZZA",
10631 .bg_channels = 11,
10632 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10633 {2427, 4}, {2432, 5}, {2437, 6},
10634 {2442, 7}, {2447, 8}, {2452, 9},
10635 {2457, 10}, {2462, 11}},
10636 .a_channels = 13,
10637 .a = {{5180, 36},
10638 {5200, 40},
10639 {5220, 44},
10640 {5240, 48},
10641 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10642 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10643 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10644 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10645 {5745, 149},
10646 {5765, 153},
10647 {5785, 157},
10648 {5805, 161},
10649 {5825, 165}},
10650 },
10651
10652 { /* Custom NA & Europe */
10653 "ZZB",
10654 .bg_channels = 11,
10655 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10656 {2427, 4}, {2432, 5}, {2437, 6},
10657 {2442, 7}, {2447, 8}, {2452, 9},
10658 {2457, 10}, {2462, 11}},
10659 .a_channels = 13,
10660 .a = {{5180, 36},
10661 {5200, 40},
10662 {5220, 44},
10663 {5240, 48},
10664 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10665 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10666 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10667 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10668 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10669 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10670 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10671 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10672 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10673 },
10674
10675 { /* Custom Japan */
10676 "ZZC",
10677 .bg_channels = 11,
10678 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10679 {2427, 4}, {2432, 5}, {2437, 6},
10680 {2442, 7}, {2447, 8}, {2452, 9},
10681 {2457, 10}, {2462, 11}},
10682 .a_channels = 4,
10683 .a = {{5170, 34}, {5190, 38},
10684 {5210, 42}, {5230, 46}},
10685 },
10686
10687 { /* Custom */
10688 "ZZM",
10689 .bg_channels = 11,
10690 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10691 {2427, 4}, {2432, 5}, {2437, 6},
10692 {2442, 7}, {2447, 8}, {2452, 9},
10693 {2457, 10}, {2462, 11}},
10694 },
10695
10696 { /* Europe */
10697 "ZZE",
10698 .bg_channels = 13,
10699 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10700 {2427, 4}, {2432, 5}, {2437, 6},
10701 {2442, 7}, {2447, 8}, {2452, 9},
10702 {2457, 10}, {2462, 11}, {2467, 12},
10703 {2472, 13}},
10704 .a_channels = 19,
10705 .a = {{5180, 36},
10706 {5200, 40},
10707 {5220, 44},
10708 {5240, 48},
10709 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10710 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10711 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10712 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10713 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10714 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10715 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10716 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10717 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10718 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10719 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10720 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10721 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10722 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10723 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10724 },
10725
10726 { /* Custom Japan */
10727 "ZZJ",
10728 .bg_channels = 14,
10729 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10730 {2427, 4}, {2432, 5}, {2437, 6},
10731 {2442, 7}, {2447, 8}, {2452, 9},
10732 {2457, 10}, {2462, 11}, {2467, 12},
10733 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10734 .a_channels = 4,
10735 .a = {{5170, 34}, {5190, 38},
10736 {5210, 42}, {5230, 46}},
10737 },
10738
10739 { /* High Band */
10740 "ZZH",
10741 .bg_channels = 13,
10742 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10743 {2427, 4}, {2432, 5}, {2437, 6},
10744 {2442, 7}, {2447, 8}, {2452, 9},
10745 {2457, 10}, {2462, 11},
10746 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10747 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10748 .a_channels = 4,
10749 .a = {{5745, 149}, {5765, 153},
10750 {5785, 157}, {5805, 161}},
10751 },
10752
10753 { /* Custom Europe */
10754 "ZZG",
10755 .bg_channels = 13,
10756 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10757 {2427, 4}, {2432, 5}, {2437, 6},
10758 {2442, 7}, {2447, 8}, {2452, 9},
10759 {2457, 10}, {2462, 11},
10760 {2467, 12}, {2472, 13}},
10761 .a_channels = 4,
10762 .a = {{5180, 36}, {5200, 40},
10763 {5220, 44}, {5240, 48}},
10764 },
10765
10766 { /* Europe */
10767 "ZZK",
10768 .bg_channels = 13,
10769 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10770 {2427, 4}, {2432, 5}, {2437, 6},
10771 {2442, 7}, {2447, 8}, {2452, 9},
10772 {2457, 10}, {2462, 11},
10773 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10774 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10775 .a_channels = 24,
10776 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10777 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10778 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10779 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10780 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10781 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10782 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10783 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10784 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10785 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10786 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10787 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10788 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10789 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10790 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10791 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10792 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10793 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10794 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10795 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10796 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10797 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10798 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10799 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10800 },
10801
10802 { /* Europe */
10803 "ZZL",
10804 .bg_channels = 11,
10805 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10806 {2427, 4}, {2432, 5}, {2437, 6},
10807 {2442, 7}, {2447, 8}, {2452, 9},
10808 {2457, 10}, {2462, 11}},
10809 .a_channels = 13,
10810 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10811 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10812 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10813 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10814 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10815 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10816 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10817 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10818 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10819 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10820 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10821 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10822 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10823 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010824};
10825
James Ketrenos43f66a62005-03-25 12:31:53 -060010826#define MAX_HW_RESTARTS 5
10827static int ipw_up(struct ipw_priv *priv)
10828{
James Ketrenos4f36f802005-08-03 20:36:56 -050010829 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010830
10831 if (priv->status & STATUS_EXIT_PENDING)
10832 return -EIO;
10833
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010834 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010835 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010836 * Also start the clocks. */
10837 rc = ipw_load(priv);
10838 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010839 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010840 return rc;
10841 }
10842
10843 ipw_init_ordinals(priv);
10844 if (!(priv->config & CFG_CUSTOM_MAC))
10845 eeprom_parse_mac(priv, priv->mac_addr);
10846 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10847
James Ketrenos4f36f802005-08-03 20:36:56 -050010848 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10849 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10850 ipw_geos[j].name, 3))
10851 break;
10852 }
10853 if (j == ARRAY_SIZE(ipw_geos))
10854 j = 0;
10855 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10856 IPW_WARNING("Could not set geography.");
10857 return 0;
10858 }
10859
10860 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10861 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010862
James Ketrenosb095c382005-08-24 22:04:42 -050010863 if (priv->status & STATUS_RF_KILL_SW) {
10864 IPW_WARNING("Radio disabled by module parameter.\n");
10865 return 0;
10866 } else if (rf_kill_active(priv)) {
10867 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10868 "Kill switch must be turned off for "
10869 "wireless networking to work.\n");
10870 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10871 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010872 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010873 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010874
10875 rc = ipw_config(priv);
10876 if (!rc) {
10877 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010878
James Ketrenose6666192005-08-12 09:17:04 -050010879 /* If configure to try and auto-associate, kick
10880 * off a scan. */
10881 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010882
James Ketrenos43f66a62005-03-25 12:31:53 -060010883 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010884 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010885
James Ketrenosc848d0a2005-08-24 21:56:24 -050010886 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010887 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10888 i, MAX_HW_RESTARTS);
10889
10890 /* We had an error bringing up the hardware, so take it
10891 * all the way back down so we can try again */
10892 ipw_down(priv);
10893 }
10894
Jeff Garzikbf794512005-07-31 13:07:26 -040010895 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010896 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010897 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010898
James Ketrenos43f66a62005-03-25 12:31:53 -060010899 return -EIO;
10900}
10901
James Ketrenosc848d0a2005-08-24 21:56:24 -050010902static void ipw_bg_up(void *data)
10903{
10904 struct ipw_priv *priv = data;
10905 down(&priv->sem);
10906 ipw_up(data);
10907 up(&priv->sem);
10908}
10909
James Ketrenosb095c382005-08-24 22:04:42 -050010910static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010911{
James Ketrenosb095c382005-08-24 22:04:42 -050010912 int i;
10913
10914 if (priv->status & STATUS_SCANNING) {
10915 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10916 ipw_abort_scan(priv);
10917 }
10918
10919 if (priv->status & STATUS_ASSOCIATED) {
10920 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10921 ipw_disassociate(priv);
10922 }
10923
10924 ipw_led_shutdown(priv);
10925
10926 /* Wait up to 1s for status to change to not scanning and not
10927 * associated (disassociation can take a while for a ful 802.11
10928 * exchange */
10929 for (i = 1000; i && (priv->status &
10930 (STATUS_DISASSOCIATING |
10931 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10932 udelay(10);
10933
10934 if (priv->status & (STATUS_DISASSOCIATING |
10935 STATUS_ASSOCIATED | STATUS_SCANNING))
10936 IPW_DEBUG_INFO("Still associated or scanning...\n");
10937 else
10938 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10939
James Ketrenosc848d0a2005-08-24 21:56:24 -050010940 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010941 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010942
10943 priv->status &= ~STATUS_INIT;
10944}
10945
10946static void ipw_down(struct ipw_priv *priv)
10947{
10948 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10949
10950 priv->status |= STATUS_EXIT_PENDING;
10951
10952 if (ipw_is_init(priv))
10953 ipw_deinit(priv);
10954
10955 /* Wipe out the EXIT_PENDING status bit if we are not actually
10956 * exiting the module */
10957 if (!exit_pending)
10958 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010959
10960 /* tell the device to stop sending interrupts */
10961 ipw_disable_interrupts(priv);
10962
10963 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010964 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010965 netif_carrier_off(priv->net_dev);
10966 netif_stop_queue(priv->net_dev);
10967
10968 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010969
10970 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010971}
10972
James Ketrenosc848d0a2005-08-24 21:56:24 -050010973static void ipw_bg_down(void *data)
10974{
10975 struct ipw_priv *priv = data;
10976 down(&priv->sem);
10977 ipw_down(data);
10978 up(&priv->sem);
10979}
10980
James Ketrenosafbf30a2005-08-25 00:05:33 -050010981#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050010982static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
10983{
James Ketrenosea2b26e2005-08-24 21:25:16 -050010984 struct iwreq *wrq = (struct iwreq *)rq;
10985 int ret = -1;
10986 switch (cmd) {
10987 case IPW_IOCTL_WPA_SUPPLICANT:
10988 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
10989 return ret;
10990
10991 default:
10992 return -EOPNOTSUPP;
10993 }
10994
James Ketrenosea2b26e2005-08-24 21:25:16 -050010995 return -EOPNOTSUPP;
10996}
James Ketrenosafbf30a2005-08-25 00:05:33 -050010997#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -050010998
James Ketrenos43f66a62005-03-25 12:31:53 -060010999/* Called by register_netdev() */
11000static int ipw_net_init(struct net_device *dev)
11001{
11002 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011003 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011004
James Ketrenosc848d0a2005-08-24 21:56:24 -050011005 if (ipw_up(priv)) {
11006 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011007 return -EIO;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011008 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011009
James Ketrenosc848d0a2005-08-24 21:56:24 -050011010 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011011 return 0;
11012}
11013
11014/* PCI driver stuff */
11015static struct pci_device_id card_ids[] = {
11016 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11017 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11018 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11019 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11020 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11021 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11022 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11023 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11024 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11025 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11026 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11027 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11028 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11029 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11030 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11031 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11032 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11033 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011034 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011035 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011036 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11037 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011038
James Ketrenos43f66a62005-03-25 12:31:53 -060011039 /* required last entry */
11040 {0,}
11041};
11042
11043MODULE_DEVICE_TABLE(pci, card_ids);
11044
11045static struct attribute *ipw_sysfs_entries[] = {
11046 &dev_attr_rf_kill.attr,
11047 &dev_attr_direct_dword.attr,
11048 &dev_attr_indirect_byte.attr,
11049 &dev_attr_indirect_dword.attr,
11050 &dev_attr_mem_gpio_reg.attr,
11051 &dev_attr_command_event_reg.attr,
11052 &dev_attr_nic_type.attr,
11053 &dev_attr_status.attr,
11054 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011055 &dev_attr_error.attr,
11056 &dev_attr_event_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011057 &dev_attr_eeprom_delay.attr,
11058 &dev_attr_ucode_version.attr,
11059 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011060 &dev_attr_scan_age.attr,
11061 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011062 &dev_attr_speed_scan.attr,
11063 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011064 NULL
11065};
11066
11067static struct attribute_group ipw_attribute_group = {
11068 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011069 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011070};
11071
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011072static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011073{
11074 int err = 0;
11075 struct net_device *net_dev;
11076 void __iomem *base;
11077 u32 length, val;
11078 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011079 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011080
11081 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11082 if (net_dev == NULL) {
11083 err = -ENOMEM;
11084 goto out;
11085 }
11086
11087 priv = ieee80211_priv(net_dev);
11088 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011089
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 priv->net_dev = net_dev;
11091 priv->pci_dev = pdev;
11092#ifdef CONFIG_IPW_DEBUG
11093 ipw_debug_level = debug;
11094#endif
11095 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011096 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11097 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011098
James Ketrenosc848d0a2005-08-24 21:56:24 -050011099 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011100 if (pci_enable_device(pdev)) {
11101 err = -ENODEV;
11102 goto out_free_ieee80211;
11103 }
11104
11105 pci_set_master(pdev);
11106
Tobias Klauser0e08b442005-06-20 14:28:41 -070011107 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011108 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011109 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011110 if (err) {
11111 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11112 goto out_pci_disable_device;
11113 }
11114
11115 pci_set_drvdata(pdev, priv);
11116
11117 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011118 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011119 goto out_pci_disable_device;
11120
Jeff Garzikbf794512005-07-31 13:07:26 -040011121 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011122 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011123 pci_read_config_dword(pdev, 0x40, &val);
11124 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011125 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011126
James Ketrenos43f66a62005-03-25 12:31:53 -060011127 length = pci_resource_len(pdev, 0);
11128 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011129
James Ketrenos43f66a62005-03-25 12:31:53 -060011130 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11131 if (!base) {
11132 err = -ENODEV;
11133 goto out_pci_release_regions;
11134 }
11135
11136 priv->hw_base = base;
11137 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11138 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11139
11140 err = ipw_setup_deferred_work(priv);
11141 if (err) {
11142 IPW_ERROR("Unable to setup deferred work\n");
11143 goto out_iounmap;
11144 }
11145
James Ketrenosb095c382005-08-24 22:04:42 -050011146 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011147
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011148 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011149 if (err) {
11150 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11151 goto out_destroy_workqueue;
11152 }
11153
11154 SET_MODULE_OWNER(net_dev);
11155 SET_NETDEV_DEV(net_dev, &pdev->dev);
11156
James Ketrenosa613bff2005-08-24 21:43:11 -050011157 ipw_wx_data.spy_data = &priv->ieee->spy_data;
11158 ipw_wx_data.ieee80211 = priv->ieee;
11159
James Ketrenosc848d0a2005-08-24 21:56:24 -050011160 down(&priv->sem);
11161
James Ketrenos43f66a62005-03-25 12:31:53 -060011162 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11163 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011164 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011165
James Ketrenosb095c382005-08-24 22:04:42 -050011166#ifdef CONFIG_IPW_QOS
James Ketrenos2b184d52005-08-03 20:33:14 -050011167 priv->ieee->handle_management = ipw_handle_management;
James Ketrenosb095c382005-08-24 22:04:42 -050011168#endif /* CONFIG_IPW_QOS */
11169
James Ketrenosc848d0a2005-08-24 21:56:24 -050011170 priv->ieee->perfect_rssi = -20;
11171 priv->ieee->worst_rssi = -85;
11172
James Ketrenos43f66a62005-03-25 12:31:53 -060011173 net_dev->open = ipw_net_open;
11174 net_dev->stop = ipw_net_stop;
11175 net_dev->init = ipw_net_init;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011176#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050011177 net_dev->do_ioctl = ipw_ioctl;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011178#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011179 net_dev->get_stats = ipw_net_get_stats;
11180 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11181 net_dev->set_mac_address = ipw_net_set_mac_address;
11182 net_dev->get_wireless_stats = ipw_get_wireless_stats;
James Ketrenosa613bff2005-08-24 21:43:11 -050011183 net_dev->wireless_data = &ipw_wx_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011184 net_dev->wireless_handlers = &ipw_wx_handler_def;
11185 net_dev->ethtool_ops = &ipw_ethtool_ops;
11186 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011187 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011188 net_dev->mem_start = pci_resource_start(pdev, 0);
11189 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11190
11191 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11192 if (err) {
11193 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011194 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011195 goto out_release_irq;
11196 }
11197
James Ketrenosc848d0a2005-08-24 21:56:24 -050011198 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011199 err = register_netdev(net_dev);
11200 if (err) {
11201 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011202 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011203 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011204 return 0;
11205
James Ketrenosa613bff2005-08-24 21:43:11 -050011206 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011207 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011208 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011209 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011210 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011211 destroy_workqueue(priv->workqueue);
11212 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011213 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011214 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011215 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011216 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011217 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011218 pci_disable_device(pdev);
11219 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011220 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011221 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011222 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011223 return err;
11224}
11225
11226static void ipw_pci_remove(struct pci_dev *pdev)
11227{
11228 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011229 struct list_head *p, *q;
11230 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011231
James Ketrenos43f66a62005-03-25 12:31:53 -060011232 if (!priv)
11233 return;
11234
James Ketrenosb095c382005-08-24 22:04:42 -050011235 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011236
11237 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011238 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -050011239 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011240
James Ketrenosb095c382005-08-24 22:04:42 -050011241 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011242
11243 unregister_netdev(priv->net_dev);
11244
11245 if (priv->rxq) {
11246 ipw_rx_queue_free(priv, priv->rxq);
11247 priv->rxq = NULL;
11248 }
11249 ipw_tx_queue_free(priv);
11250
11251 /* ipw_down will ensure that there is no more pending work
11252 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011253 cancel_delayed_work(&priv->adhoc_check);
11254 cancel_delayed_work(&priv->gather_stats);
11255 cancel_delayed_work(&priv->request_scan);
11256 cancel_delayed_work(&priv->rf_kill);
11257 cancel_delayed_work(&priv->scan_check);
11258 destroy_workqueue(priv->workqueue);
11259 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011260
James Ketrenosafbf30a2005-08-25 00:05:33 -050011261 /* Free MAC hash list for ADHOC */
11262 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11263 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11264 kfree(list_entry(p, struct ipw_ibss_seq, list));
11265 list_del(p);
11266 }
11267 }
11268
James Ketrenosb39860c2005-08-12 09:36:32 -050011269 if (priv->error) {
11270 ipw_free_error_log(priv->error);
11271 priv->error = NULL;
11272 }
11273
James Ketrenos43f66a62005-03-25 12:31:53 -060011274 free_irq(pdev->irq, priv);
11275 iounmap(priv->hw_base);
11276 pci_release_regions(pdev);
11277 pci_disable_device(pdev);
11278 pci_set_drvdata(pdev, NULL);
11279 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011280 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011281}
11282
James Ketrenos43f66a62005-03-25 12:31:53 -060011283#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011284static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011285{
11286 struct ipw_priv *priv = pci_get_drvdata(pdev);
11287 struct net_device *dev = priv->net_dev;
11288
11289 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11290
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011291 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011292 ipw_down(priv);
11293
11294 /* Remove the PRESENT state of the device */
11295 netif_device_detach(dev);
11296
James Ketrenos43f66a62005-03-25 12:31:53 -060011297 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011298 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011299 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011300
James Ketrenos43f66a62005-03-25 12:31:53 -060011301 return 0;
11302}
11303
11304static int ipw_pci_resume(struct pci_dev *pdev)
11305{
11306 struct ipw_priv *priv = pci_get_drvdata(pdev);
11307 struct net_device *dev = priv->net_dev;
11308 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011309
James Ketrenos43f66a62005-03-25 12:31:53 -060011310 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11311
James Ketrenosea2b26e2005-08-24 21:25:16 -050011312 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011313 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011314 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011315
James Ketrenos43f66a62005-03-25 12:31:53 -060011316 /*
11317 * Suspend/Resume resets the PCI configuration space, so we have to
11318 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11319 * from interfering with C3 CPU state. pci_restore_state won't help
11320 * here since it only restores the first 64 bytes pci config header.
11321 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011322 pci_read_config_dword(pdev, 0x40, &val);
11323 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011324 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11325
11326 /* Set the device back into the PRESENT state; this will also wake
11327 * the queue of needed */
11328 netif_device_attach(dev);
11329
11330 /* Bring the device back up */
11331 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011332
James Ketrenos43f66a62005-03-25 12:31:53 -060011333 return 0;
11334}
11335#endif
11336
11337/* driver initialization stuff */
11338static struct pci_driver ipw_driver = {
11339 .name = DRV_NAME,
11340 .id_table = card_ids,
11341 .probe = ipw_pci_probe,
11342 .remove = __devexit_p(ipw_pci_remove),
11343#ifdef CONFIG_PM
11344 .suspend = ipw_pci_suspend,
11345 .resume = ipw_pci_resume,
11346#endif
11347};
11348
11349static int __init ipw_init(void)
11350{
11351 int ret;
11352
11353 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11354 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11355
11356 ret = pci_module_init(&ipw_driver);
11357 if (ret) {
11358 IPW_ERROR("Unable to initialize PCI module\n");
11359 return ret;
11360 }
11361
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011362 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011363 if (ret) {
11364 IPW_ERROR("Unable to create driver sysfs file\n");
11365 pci_unregister_driver(&ipw_driver);
11366 return ret;
11367 }
11368
11369 return ret;
11370}
11371
11372static void __exit ipw_exit(void)
11373{
11374 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11375 pci_unregister_driver(&ipw_driver);
11376}
11377
11378module_param(disable, int, 0444);
11379MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11380
11381module_param(associate, int, 0444);
11382MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11383
11384module_param(auto_create, int, 0444);
11385MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11386
James Ketrenosa613bff2005-08-24 21:43:11 -050011387module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011388MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011389
James Ketrenos43f66a62005-03-25 12:31:53 -060011390module_param(debug, int, 0444);
11391MODULE_PARM_DESC(debug, "debug output mask");
11392
11393module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011394MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011395
James Ketrenosb095c382005-08-24 22:04:42 -050011396#ifdef CONFIG_IPW_QOS
11397module_param(qos_enable, int, 0444);
11398MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11399
11400module_param(qos_burst_enable, int, 0444);
11401MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11402
11403module_param(qos_no_ack_mask, int, 0444);
11404MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11405
11406module_param(burst_duration_CCK, int, 0444);
11407MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11408
11409module_param(burst_duration_OFDM, int, 0444);
11410MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11411#endif /* CONFIG_IPW_QOS */
11412
11413#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011414module_param(mode, int, 0444);
11415MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11416#else
11417module_param(mode, int, 0444);
11418MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11419#endif
11420
James Ketrenosb095c382005-08-24 22:04:42 -050011421module_param(hwcrypto, int, 0444);
11422MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11423
James Ketrenos43f66a62005-03-25 12:31:53 -060011424module_exit(ipw_exit);
11425module_init(ipw_init);