blob: ef1007785030e6ac6fa7cabb95dab5d53f22afc3 [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) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001820 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1821 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001822 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001823 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001824 }
1825
1826 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001827
James Ketrenosb095c382005-08-24 22:04:42 -05001828 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1829 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1830 priv->status);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001831 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001832
1833 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001834 if (rc) {
1835 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001836 IPW_ERROR("Failed to send %s: Reason %d\n",
1837 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001838 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001839 return rc;
James Ketrenosa613bff2005-08-24 21:43:11 -05001840 }
1841 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001842
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001843 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1844 !(priv->
1845 status & STATUS_HCMD_ACTIVE),
1846 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001847 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001848 spin_lock_irqsave(&priv->lock, flags);
1849 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001850 IPW_ERROR("Failed to send %s: Command timed out.\n",
1851 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001852 priv->status &= ~STATUS_HCMD_ACTIVE;
1853 spin_unlock_irqrestore(&priv->lock, flags);
1854 return -EIO;
1855 }
1856 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001857 }
James Ketrenosa613bff2005-08-24 21:43:11 -05001858
James Ketrenosb095c382005-08-24 22:04:42 -05001859 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001860 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1861 get_cmd_string(cmd->cmd));
James Ketrenos43f66a62005-03-25 12:31:53 -06001862 return -EIO;
1863 }
1864
1865 return 0;
1866}
1867
1868static int ipw_send_host_complete(struct ipw_priv *priv)
1869{
1870 struct host_cmd cmd = {
1871 .cmd = IPW_CMD_HOST_COMPLETE,
1872 .len = 0
1873 };
1874
1875 if (!priv) {
1876 IPW_ERROR("Invalid args\n");
1877 return -1;
1878 }
1879
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001880 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001881}
1882
Jeff Garzikbf794512005-07-31 13:07:26 -04001883static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001884 struct ipw_sys_config *config)
1885{
1886 struct host_cmd cmd = {
1887 .cmd = IPW_CMD_SYSTEM_CONFIG,
1888 .len = sizeof(*config)
1889 };
1890
1891 if (!priv || !config) {
1892 IPW_ERROR("Invalid args\n");
1893 return -1;
1894 }
1895
James Ketrenosafbf30a2005-08-25 00:05:33 -05001896 memcpy(cmd.param, config, sizeof(*config));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001897 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001898}
1899
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001900static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001901{
1902 struct host_cmd cmd = {
1903 .cmd = IPW_CMD_SSID,
1904 .len = min(len, IW_ESSID_MAX_SIZE)
1905 };
1906
1907 if (!priv || !ssid) {
1908 IPW_ERROR("Invalid args\n");
1909 return -1;
1910 }
1911
James Ketrenosafbf30a2005-08-25 00:05:33 -05001912 memcpy(cmd.param, ssid, cmd.len);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001913 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001914}
1915
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001916static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001917{
1918 struct host_cmd cmd = {
1919 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1920 .len = ETH_ALEN
1921 };
1922
1923 if (!priv || !mac) {
1924 IPW_ERROR("Invalid args\n");
1925 return -1;
1926 }
1927
1928 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1929 priv->net_dev->name, MAC_ARG(mac));
1930
James Ketrenosafbf30a2005-08-25 00:05:33 -05001931 memcpy(cmd.param, mac, ETH_ALEN);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001932 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001933}
1934
James Ketrenosa613bff2005-08-24 21:43:11 -05001935/*
1936 * NOTE: This must be executed from our workqueue as it results in udelay
1937 * being called which may corrupt the keyboard if executed on default
1938 * workqueue
1939 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001940static void ipw_adapter_restart(void *adapter)
1941{
1942 struct ipw_priv *priv = adapter;
1943
1944 if (priv->status & STATUS_RF_KILL_MASK)
1945 return;
1946
1947 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001948
1949 if (priv->assoc_network &&
1950 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
1951 ipw_remove_current_network(priv);
1952
James Ketrenos43f66a62005-03-25 12:31:53 -06001953 if (ipw_up(priv)) {
1954 IPW_ERROR("Failed to up device\n");
1955 return;
1956 }
1957}
1958
James Ketrenosc848d0a2005-08-24 21:56:24 -05001959static void ipw_bg_adapter_restart(void *data)
1960{
1961 struct ipw_priv *priv = data;
1962 down(&priv->sem);
1963 ipw_adapter_restart(data);
1964 up(&priv->sem);
1965}
1966
James Ketrenos43f66a62005-03-25 12:31:53 -06001967#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1968
1969static void ipw_scan_check(void *data)
1970{
1971 struct ipw_priv *priv = data;
1972 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1973 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001974 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001975 IPW_SCAN_CHECK_WATCHDOG / 100);
James Ketrenosa613bff2005-08-24 21:43:11 -05001976 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06001977 }
1978}
1979
James Ketrenosc848d0a2005-08-24 21:56:24 -05001980static void ipw_bg_scan_check(void *data)
1981{
1982 struct ipw_priv *priv = data;
1983 down(&priv->sem);
1984 ipw_scan_check(data);
1985 up(&priv->sem);
1986}
1987
James Ketrenos43f66a62005-03-25 12:31:53 -06001988static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1989 struct ipw_scan_request_ext *request)
1990{
1991 struct host_cmd cmd = {
1992 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1993 .len = sizeof(*request)
1994 };
1995
James Ketrenosafbf30a2005-08-25 00:05:33 -05001996 memcpy(cmd.param, request, sizeof(*request));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001997 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06001998}
1999
2000static int ipw_send_scan_abort(struct ipw_priv *priv)
2001{
2002 struct host_cmd cmd = {
2003 .cmd = IPW_CMD_SCAN_ABORT,
2004 .len = 0
2005 };
2006
2007 if (!priv) {
2008 IPW_ERROR("Invalid args\n");
2009 return -1;
2010 }
2011
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002012 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002013}
2014
2015static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2016{
2017 struct host_cmd cmd = {
2018 .cmd = IPW_CMD_SENSITIVITY_CALIB,
2019 .len = sizeof(struct ipw_sensitivity_calib)
2020 };
2021 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002022 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 calib->beacon_rssi_raw = sens;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002024 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002025}
2026
2027static int ipw_send_associate(struct ipw_priv *priv,
2028 struct ipw_associate *associate)
2029{
2030 struct host_cmd cmd = {
2031 .cmd = IPW_CMD_ASSOCIATE,
2032 .len = sizeof(*associate)
2033 };
2034
James Ketrenosa613bff2005-08-24 21:43:11 -05002035 struct ipw_associate tmp_associate;
2036 memcpy(&tmp_associate, associate, sizeof(*associate));
2037 tmp_associate.policy_support =
2038 cpu_to_le16(tmp_associate.policy_support);
2039 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2040 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2041 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2042 tmp_associate.listen_interval =
2043 cpu_to_le16(tmp_associate.listen_interval);
2044 tmp_associate.beacon_interval =
2045 cpu_to_le16(tmp_associate.beacon_interval);
2046 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2047
James Ketrenos43f66a62005-03-25 12:31:53 -06002048 if (!priv || !associate) {
2049 IPW_ERROR("Invalid args\n");
2050 return -1;
2051 }
2052
James Ketrenosafbf30a2005-08-25 00:05:33 -05002053 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002054 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002055}
2056
2057static int ipw_send_supported_rates(struct ipw_priv *priv,
2058 struct ipw_supported_rates *rates)
2059{
2060 struct host_cmd cmd = {
2061 .cmd = IPW_CMD_SUPPORTED_RATES,
2062 .len = sizeof(*rates)
2063 };
2064
2065 if (!priv || !rates) {
2066 IPW_ERROR("Invalid args\n");
2067 return -1;
2068 }
2069
James Ketrenosafbf30a2005-08-25 00:05:33 -05002070 memcpy(cmd.param, rates, sizeof(*rates));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002071 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002072}
2073
2074static int ipw_set_random_seed(struct ipw_priv *priv)
2075{
2076 struct host_cmd cmd = {
2077 .cmd = IPW_CMD_SEED_NUMBER,
2078 .len = sizeof(u32)
2079 };
2080
2081 if (!priv) {
2082 IPW_ERROR("Invalid args\n");
2083 return -1;
2084 }
2085
2086 get_random_bytes(&cmd.param, sizeof(u32));
2087
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002088 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002089}
2090
James Ketrenos43f66a62005-03-25 12:31:53 -06002091static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2092{
2093 struct host_cmd cmd = {
2094 .cmd = IPW_CMD_CARD_DISABLE,
2095 .len = sizeof(u32)
2096 };
2097
2098 if (!priv) {
2099 IPW_ERROR("Invalid args\n");
2100 return -1;
2101 }
2102
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002103 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06002104
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002105 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002106}
James Ketrenos43f66a62005-03-25 12:31:53 -06002107
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002108static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002109{
2110 struct host_cmd cmd = {
2111 .cmd = IPW_CMD_TX_POWER,
2112 .len = sizeof(*power)
2113 };
2114
2115 if (!priv || !power) {
2116 IPW_ERROR("Invalid args\n");
2117 return -1;
2118 }
2119
James Ketrenosafbf30a2005-08-25 00:05:33 -05002120 memcpy(cmd.param, power, sizeof(*power));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002121 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002122}
2123
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002124static int ipw_set_tx_power(struct ipw_priv *priv)
2125{
2126 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2127 struct ipw_tx_power tx_power;
2128 s8 max_power;
2129 int i;
2130
2131 memset(&tx_power, 0, sizeof(tx_power));
2132
2133 /* configure device for 'G' band */
2134 tx_power.ieee_mode = IPW_G_MODE;
2135 tx_power.num_channels = geo->bg_channels;
2136 for (i = 0; i < geo->bg_channels; i++) {
2137 max_power = geo->bg[i].max_power;
2138 tx_power.channels_tx_power[i].channel_number =
2139 geo->bg[i].channel;
2140 tx_power.channels_tx_power[i].tx_power = max_power ?
2141 min(max_power, priv->tx_power) : priv->tx_power;
2142 }
2143 if (ipw_send_tx_power(priv, &tx_power))
2144 return -EIO;
2145
2146 /* configure device to also handle 'B' band */
2147 tx_power.ieee_mode = IPW_B_MODE;
2148 if (ipw_send_tx_power(priv, &tx_power))
2149 return -EIO;
2150
2151 /* configure device to also handle 'A' band */
2152 if (priv->ieee->abg_true) {
2153 tx_power.ieee_mode = IPW_A_MODE;
2154 tx_power.num_channels = geo->a_channels;
2155 for (i = 0; i < tx_power.num_channels; i++) {
2156 max_power = geo->a[i].max_power;
2157 tx_power.channels_tx_power[i].channel_number =
2158 geo->a[i].channel;
2159 tx_power.channels_tx_power[i].tx_power = max_power ?
2160 min(max_power, priv->tx_power) : priv->tx_power;
2161 }
2162 if (ipw_send_tx_power(priv, &tx_power))
2163 return -EIO;
2164 }
2165 return 0;
2166}
2167
James Ketrenos43f66a62005-03-25 12:31:53 -06002168static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2169{
2170 struct ipw_rts_threshold rts_threshold = {
2171 .rts_threshold = rts,
2172 };
2173 struct host_cmd cmd = {
2174 .cmd = IPW_CMD_RTS_THRESHOLD,
2175 .len = sizeof(rts_threshold)
2176 };
2177
2178 if (!priv) {
2179 IPW_ERROR("Invalid args\n");
2180 return -1;
2181 }
2182
James Ketrenosafbf30a2005-08-25 00:05:33 -05002183 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002184 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002185}
2186
2187static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2188{
2189 struct ipw_frag_threshold frag_threshold = {
2190 .frag_threshold = frag,
2191 };
2192 struct host_cmd cmd = {
2193 .cmd = IPW_CMD_FRAG_THRESHOLD,
2194 .len = sizeof(frag_threshold)
2195 };
2196
2197 if (!priv) {
2198 IPW_ERROR("Invalid args\n");
2199 return -1;
2200 }
2201
James Ketrenosafbf30a2005-08-25 00:05:33 -05002202 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002203 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002204}
2205
2206static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2207{
2208 struct host_cmd cmd = {
2209 .cmd = IPW_CMD_POWER_MODE,
2210 .len = sizeof(u32)
2211 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002212 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002213
2214 if (!priv) {
2215 IPW_ERROR("Invalid args\n");
2216 return -1;
2217 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002218
James Ketrenos43f66a62005-03-25 12:31:53 -06002219 /* If on battery, set to 3, if AC set to CAM, else user
2220 * level */
2221 switch (mode) {
2222 case IPW_POWER_BATTERY:
2223 *param = IPW_POWER_INDEX_3;
2224 break;
2225 case IPW_POWER_AC:
2226 *param = IPW_POWER_MODE_CAM;
2227 break;
2228 default:
2229 *param = mode;
2230 break;
2231 }
2232
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002233 return ipw_send_cmd(priv, &cmd);
James Ketrenos43f66a62005-03-25 12:31:53 -06002234}
2235
James Ketrenosafbf30a2005-08-25 00:05:33 -05002236static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2237{
2238 struct ipw_retry_limit retry_limit = {
2239 .short_retry_limit = slimit,
2240 .long_retry_limit = llimit
2241 };
2242 struct host_cmd cmd = {
2243 .cmd = IPW_CMD_RETRY_LIMIT,
2244 .len = sizeof(retry_limit)
2245 };
2246
2247 if (!priv) {
2248 IPW_ERROR("Invalid args\n");
2249 return -1;
2250 }
2251
2252 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002253 return ipw_send_cmd(priv, &cmd);
James Ketrenosafbf30a2005-08-25 00:05:33 -05002254}
2255
James Ketrenos43f66a62005-03-25 12:31:53 -06002256/*
2257 * The IPW device contains a Microwire compatible EEPROM that stores
2258 * various data like the MAC address. Usually the firmware has exclusive
2259 * access to the eeprom, but during device initialization (before the
2260 * device driver has sent the HostComplete command to the firmware) the
2261 * device driver has read access to the EEPROM by way of indirect addressing
2262 * through a couple of memory mapped registers.
2263 *
2264 * The following is a simplified implementation for pulling data out of the
2265 * the eeprom, along with some helper functions to find information in
2266 * the per device private data's copy of the eeprom.
2267 *
2268 * NOTE: To better understand how these functions work (i.e what is a chip
2269 * select and why do have to keep driving the eeprom clock?), read
2270 * just about any data sheet for a Microwire compatible EEPROM.
2271 */
2272
2273/* write a 32 bit value into the indirect accessor register */
2274static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2275{
2276 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002277
James Ketrenos43f66a62005-03-25 12:31:53 -06002278 /* the eeprom requires some time to complete the operation */
2279 udelay(p->eeprom_delay);
2280
2281 return;
2282}
2283
2284/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002285static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002286{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002287 eeprom_write_reg(priv, 0);
2288 eeprom_write_reg(priv, EEPROM_BIT_CS);
2289 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2290 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002291}
2292
2293/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002294static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002295{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002296 eeprom_write_reg(priv, EEPROM_BIT_CS);
2297 eeprom_write_reg(priv, 0);
2298 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002299}
2300
2301/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002302static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002303{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002304 int d = (bit ? EEPROM_BIT_DI : 0);
2305 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2306 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002307}
2308
2309/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002310static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002311{
2312 int i;
2313
2314 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002315 eeprom_write_bit(priv, 1);
2316 eeprom_write_bit(priv, op & 2);
2317 eeprom_write_bit(priv, op & 1);
2318 for (i = 7; i >= 0; i--) {
2319 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002320 }
2321}
2322
2323/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002324static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002325{
2326 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002327 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002328
James Ketrenos43f66a62005-03-25 12:31:53 -06002329 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002330 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002331
2332 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002333 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002334
2335 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002336 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002337 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002338 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2339 eeprom_write_reg(priv, EEPROM_BIT_CS);
2340 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2341 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002342 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002343
James Ketrenos43f66a62005-03-25 12:31:53 -06002344 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002345 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002346 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002347
James Ketrenos43f66a62005-03-25 12:31:53 -06002348 return r;
2349}
2350
2351/* helper function for pulling the mac address out of the private */
2352/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002353static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002354{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002355 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002356}
2357
2358/*
2359 * Either the device driver (i.e. the host) or the firmware can
2360 * load eeprom data into the designated region in SRAM. If neither
2361 * happens then the FW will shutdown with a fatal error.
2362 *
2363 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2364 * bit needs region of shared SRAM needs to be non-zero.
2365 */
2366static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2367{
2368 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002369 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002370
James Ketrenos43f66a62005-03-25 12:31:53 -06002371 IPW_DEBUG_TRACE(">>\n");
2372
2373 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002374 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002375 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002376
Jeff Garzikbf794512005-07-31 13:07:26 -04002377 /*
2378 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002379 copy. Otherwise let the firmware know to perform the operation
2380 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002381 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002382 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2383 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2384
2385 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002386 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002387 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002388
2389 /* Do not load eeprom data on fatal error or suspend */
2390 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2391 } else {
2392 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2393
2394 /* Load eeprom data on fatal error or suspend */
2395 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2396 }
2397
2398 IPW_DEBUG_TRACE("<<\n");
2399}
2400
James Ketrenos43f66a62005-03-25 12:31:53 -06002401static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2402{
2403 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002404 if (!count)
2405 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002406 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002407 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002408 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002409}
2410
2411static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2412{
James Ketrenosb095c382005-08-24 22:04:42 -05002413 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002414 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002415 sizeof(struct command_block));
2416}
2417
2418static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002419{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002420
2421 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002422
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 /* Start the dma */
2424 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002425
James Ketrenos43f66a62005-03-25 12:31:53 -06002426 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002427 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002428
2429 IPW_DEBUG_FW("<< : \n");
2430 return 0;
2431}
2432
2433static void ipw_fw_dma_abort(struct ipw_priv *priv)
2434{
2435 u32 control = 0;
2436
2437 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002438
2439 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002440 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002441 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002442 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002443
James Ketrenos43f66a62005-03-25 12:31:53 -06002444 IPW_DEBUG_FW("<< \n");
2445}
2446
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002447static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2448 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002449{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002450 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002451 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002452 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 IPW_DEBUG_FW(">> :\n");
2454
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002455 ipw_write_indirect(priv, address, (u8 *) cb,
2456 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002457
2458 IPW_DEBUG_FW("<< :\n");
2459 return 0;
2460
2461}
2462
2463static int ipw_fw_dma_kick(struct ipw_priv *priv)
2464{
2465 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002466 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002467
2468 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002469
James Ketrenos43f66a62005-03-25 12:31:53 -06002470 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002471 ipw_fw_dma_write_command_block(priv, index,
2472 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002473
2474 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002475 ipw_clear_bit(priv, IPW_RESET_REG,
2476 IPW_RESET_REG_MASTER_DISABLED |
2477 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002479 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002480 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002481 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002482
2483 IPW_DEBUG_FW("<< :\n");
2484 return 0;
2485}
2486
2487static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2488{
2489 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002490 u32 register_value = 0;
2491 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002492
2493 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002494 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002495 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002496
2497 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002498 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2499 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002501 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002502 cb_fields_address = address;
2503 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002504 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002505
2506 cb_fields_address += sizeof(u32);
2507 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002508 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002509
2510 cb_fields_address += sizeof(u32);
2511 register_value = ipw_read_reg32(priv, cb_fields_address);
2512 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2513 register_value);
2514
2515 cb_fields_address += sizeof(u32);
2516 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002517 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002518
2519 IPW_DEBUG_FW(">> :\n");
2520}
2521
2522static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2523{
2524 u32 current_cb_address = 0;
2525 u32 current_cb_index = 0;
2526
2527 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002528 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002529
James Ketrenosb095c382005-08-24 22:04:42 -05002530 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002531 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002532
James Ketrenos43f66a62005-03-25 12:31:53 -06002533 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002534 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002535
2536 IPW_DEBUG_FW(">> :\n");
2537 return current_cb_index;
2538
2539}
2540
2541static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2542 u32 src_address,
2543 u32 dest_address,
2544 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002545 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002546{
2547
Jeff Garzikbf794512005-07-31 13:07:26 -04002548 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002549 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2550 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002552 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002553
2554 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2555 src_address, dest_address, length);
2556
2557 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2558 return -1;
2559
2560 last_cb_element = priv->sram_desc.last_cb_index;
2561 cb = &priv->sram_desc.cb_list[last_cb_element];
2562 priv->sram_desc.last_cb_index++;
2563
2564 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002565 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002566 control |= CB_INT_ENABLED;
2567
2568 if (is_last)
2569 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002570
James Ketrenos43f66a62005-03-25 12:31:53 -06002571 control |= length;
2572
2573 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002574 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002575
2576 /* Copy the Source and Destination addresses */
2577 cb->dest_addr = dest_address;
2578 cb->source_addr = src_address;
2579
2580 /* Copy the Control Word last */
2581 cb->control = control;
2582
2583 return 0;
2584}
2585
2586static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002587 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002588{
2589 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002590 u32 src_offset = 0;
2591 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002592 int status = 0;
2593 IPW_DEBUG_FW(">> \n");
2594 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2595 src_phys, dest_address, length);
2596 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002597 status = ipw_fw_dma_add_command_block(priv,
2598 src_phys + src_offset,
2599 dest_address +
2600 dest_offset,
2601 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002602 if (status) {
2603 IPW_DEBUG_FW_INFO(": Failed\n");
2604 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002605 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002606 IPW_DEBUG_FW_INFO(": Added new cb\n");
2607
2608 src_offset += CB_MAX_LENGTH;
2609 dest_offset += CB_MAX_LENGTH;
2610 bytes_left -= CB_MAX_LENGTH;
2611 }
2612
2613 /* add the buffer tail */
2614 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002615 status =
2616 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2617 dest_address + dest_offset,
2618 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002619 if (status) {
2620 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2621 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002622 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002623 IPW_DEBUG_FW_INFO
2624 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002625 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002626
James Ketrenos43f66a62005-03-25 12:31:53 -06002627 IPW_DEBUG_FW("<< \n");
2628 return 0;
2629}
2630
2631static int ipw_fw_dma_wait(struct ipw_priv *priv)
2632{
2633 u32 current_index = 0;
2634 u32 watchdog = 0;
2635
2636 IPW_DEBUG_FW(">> : \n");
2637
2638 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002639 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002640 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002641
2642 while (current_index < priv->sram_desc.last_cb_index) {
2643 udelay(50);
2644 current_index = ipw_fw_dma_command_block_index(priv);
2645
2646 watchdog++;
2647
2648 if (watchdog > 400) {
2649 IPW_DEBUG_FW_INFO("Timeout\n");
2650 ipw_fw_dma_dump_command_block(priv);
2651 ipw_fw_dma_abort(priv);
2652 return -1;
2653 }
2654 }
2655
2656 ipw_fw_dma_abort(priv);
2657
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002659 ipw_set_bit(priv, IPW_RESET_REG,
2660 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002661
2662 IPW_DEBUG_FW("<< dmaWaitSync \n");
2663 return 0;
2664}
2665
Jeff Garzikbf794512005-07-31 13:07:26 -04002666static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002667{
2668 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002669 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002670 unsigned long flags;
2671
2672 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2674 network = list_entry(element, struct ieee80211_network, list);
2675 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2676 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002677 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002678 &priv->ieee->network_free_list);
2679 }
2680 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002681 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002682}
2683
2684/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002685 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002686 * Reads debug register from domain0.
2687 * If card is present, pre-defined value should
2688 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002689 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002690 * @param priv
2691 * @return 1 if card is present, 0 otherwise
2692 */
2693static inline int ipw_alive(struct ipw_priv *priv)
2694{
2695 return ipw_read32(priv, 0x90) == 0xd55555d5;
2696}
2697
2698static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2699 int timeout)
2700{
2701 int i = 0;
2702
2703 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002704 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002705 return i;
2706 mdelay(10);
2707 i += 10;
2708 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002709
James Ketrenos43f66a62005-03-25 12:31:53 -06002710 return -ETIME;
2711}
2712
Jeff Garzikbf794512005-07-31 13:07:26 -04002713/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002714 * the ipw hardware. It assumes the buffer has all the bits for the
2715 * image and the caller is handling the memory allocation and clean up.
2716 */
2717
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002718static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002719{
2720 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002721
James Ketrenos43f66a62005-03-25 12:31:53 -06002722 IPW_DEBUG_TRACE(">> \n");
2723 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002724 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002725
James Ketrenosb095c382005-08-24 22:04:42 -05002726 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2727 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002728 if (rc < 0) {
2729 IPW_ERROR("stop master failed in 10ms\n");
2730 return -1;
2731 }
2732
2733 IPW_DEBUG_INFO("stop master %dms\n", rc);
2734
2735 return rc;
2736}
2737
2738static void ipw_arc_release(struct ipw_priv *priv)
2739{
2740 IPW_DEBUG_TRACE(">> \n");
2741 mdelay(5);
2742
James Ketrenosb095c382005-08-24 22:04:42 -05002743 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002744
2745 /* no one knows timing, for safety add some delay */
2746 mdelay(5);
2747}
2748
2749struct fw_header {
2750 u32 version;
2751 u32 mode;
2752};
2753
2754struct fw_chunk {
2755 u32 address;
2756 u32 length;
2757};
2758
2759#define IPW_FW_MAJOR_VERSION 2
James Ketrenosb095c382005-08-24 22:04:42 -05002760#define IPW_FW_MINOR_VERSION 3
James Ketrenos43f66a62005-03-25 12:31:53 -06002761
2762#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2763#define IPW_FW_MAJOR(x) (x & 0xff)
2764
James Ketrenosafbf30a2005-08-25 00:05:33 -05002765#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002766
2767#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2768"." __stringify(IPW_FW_MINOR_VERSION) "-"
2769
2770#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2771#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2772#else
2773#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2774#endif
2775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002777{
2778 int rc = 0, i, addr;
2779 u8 cr = 0;
2780 u16 *image;
2781
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002782 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002783
James Ketrenos43f66a62005-03-25 12:31:53 -06002784 IPW_DEBUG_TRACE(">> \n");
2785
2786 rc = ipw_stop_master(priv);
2787
2788 if (rc < 0)
2789 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002790
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002791// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002792
James Ketrenosb095c382005-08-24 22:04:42 -05002793 for (addr = IPW_SHARED_LOWER_BOUND;
2794 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 ipw_write32(priv, addr, 0);
2796 }
2797
2798 /* no ucode (yet) */
2799 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2800 /* destroy DMA queues */
2801 /* reset sequence */
2802
James Ketrenosb095c382005-08-24 22:04:42 -05002803 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002804 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002805 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002806 mdelay(1);
2807
2808 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002809 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002810 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002811
James Ketrenosb095c382005-08-24 22:04:42 -05002812 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002813 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002814
James Ketrenos43f66a62005-03-25 12:31:53 -06002815 /* enable ucode store */
2816 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2817 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2818 mdelay(1);
2819
2820 /* write ucode */
2821 /**
2822 * @bug
2823 * Do NOT set indirect address register once and then
2824 * store data to indirect data register in the loop.
2825 * It seems very reasonable, but in this case DINO do not
2826 * accept ucode. It is essential to set address each time.
2827 */
2828 /* load new ipw uCode */
2829 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002830 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002831 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002832
James Ketrenos43f66a62005-03-25 12:31:53 -06002833 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002834 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2835 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002836
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002837 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002838
2839 /* wait for alive response */
2840 for (i = 0; i < 100; i++) {
2841 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002842 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002843 if (cr & DINO_RXFIFO_DATA)
2844 break;
2845 mdelay(1);
2846 }
2847
2848 if (cr & DINO_RXFIFO_DATA) {
2849 /* alive_command_responce size is NOT multiple of 4 */
2850 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002851
2852 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002853 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002854 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002855 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 memcpy(&priv->dino_alive, response_buffer,
2857 sizeof(priv->dino_alive));
2858 if (priv->dino_alive.alive_command == 1
2859 && priv->dino_alive.ucode_valid == 1) {
2860 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002861 IPW_DEBUG_INFO
2862 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2863 "of %02d/%02d/%02d %02d:%02d\n",
2864 priv->dino_alive.software_revision,
2865 priv->dino_alive.software_revision,
2866 priv->dino_alive.device_identifier,
2867 priv->dino_alive.device_identifier,
2868 priv->dino_alive.time_stamp[0],
2869 priv->dino_alive.time_stamp[1],
2870 priv->dino_alive.time_stamp[2],
2871 priv->dino_alive.time_stamp[3],
2872 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002873 } else {
2874 IPW_DEBUG_INFO("Microcode is not alive\n");
2875 rc = -EINVAL;
2876 }
2877 } else {
2878 IPW_DEBUG_INFO("No alive response from DINO\n");
2879 rc = -ETIME;
2880 }
2881
2882 /* disable DINO, otherwise for some reason
2883 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002884 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002885
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002886// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887
2888 return rc;
2889}
2890
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002891static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002892{
2893 int rc = -1;
2894 int offset = 0;
2895 struct fw_chunk *chunk;
2896 dma_addr_t shared_phys;
2897 u8 *shared_virt;
2898
2899 IPW_DEBUG_TRACE("<< : \n");
2900 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2901
2902 if (!shared_virt)
2903 return -ENOMEM;
2904
2905 memmove(shared_virt, data, len);
2906
2907 /* Start the Dma */
2908 rc = ipw_fw_dma_enable(priv);
2909
2910 if (priv->sram_desc.last_cb_index > 0) {
2911 /* the DMA is already ready this would be a bug. */
2912 BUG();
2913 goto out;
2914 }
2915
2916 do {
2917 chunk = (struct fw_chunk *)(data + offset);
2918 offset += sizeof(struct fw_chunk);
2919 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002920 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002921 * offeset*/
2922 /* Dma loading */
2923 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05002924 le32_to_cpu(chunk->address),
2925 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06002926 if (rc) {
2927 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2928 goto out;
2929 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002930
James Ketrenosa613bff2005-08-24 21:43:11 -05002931 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 } while (offset < len);
2933
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002934 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002935 rc = ipw_fw_dma_kick(priv);
2936 if (rc) {
2937 IPW_ERROR("dmaKick Failed\n");
2938 goto out;
2939 }
2940
2941 rc = ipw_fw_dma_wait(priv);
2942 if (rc) {
2943 IPW_ERROR("dmaWaitSync Failed\n");
2944 goto out;
2945 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002946 out:
2947 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002948 return rc;
2949}
2950
2951/* stop nic */
2952static int ipw_stop_nic(struct ipw_priv *priv)
2953{
2954 int rc = 0;
2955
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002956 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05002957 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002958
James Ketrenosb095c382005-08-24 22:04:42 -05002959 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2960 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002961 if (rc < 0) {
2962 IPW_ERROR("wait for reg master disabled failed\n");
2963 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002964 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002965
James Ketrenosb095c382005-08-24 22:04:42 -05002966 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002967
James Ketrenos43f66a62005-03-25 12:31:53 -06002968 return rc;
2969}
2970
2971static void ipw_start_nic(struct ipw_priv *priv)
2972{
2973 IPW_DEBUG_TRACE(">>\n");
2974
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002975 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05002976 ipw_clear_bit(priv, IPW_RESET_REG,
2977 IPW_RESET_REG_MASTER_DISABLED |
2978 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002979 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002980
James Ketrenos43f66a62005-03-25 12:31:53 -06002981 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05002982 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
2983 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002984
2985 IPW_DEBUG_TRACE("<<\n");
2986}
Jeff Garzikbf794512005-07-31 13:07:26 -04002987
James Ketrenos43f66a62005-03-25 12:31:53 -06002988static int ipw_init_nic(struct ipw_priv *priv)
2989{
2990 int rc;
2991
2992 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002993 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002994 /*prvHwInitNic */
2995 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05002996 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002997
2998 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05002999 ipw_write32(priv, IPW_READ_INT_REGISTER,
3000 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003001
3002 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003003 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3004 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003005 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3007
3008 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003009 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003010
3011 udelay(10);
3012
3013 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003014 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003015
3016 IPW_DEBUG_TRACE(">>\n");
3017 return 0;
3018}
3019
Jeff Garzikbf794512005-07-31 13:07:26 -04003020/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003021 * Probe is an ok place to call this from.
3022 */
3023static int ipw_reset_nic(struct ipw_priv *priv)
3024{
3025 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003026 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003027
3028 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003029
James Ketrenos43f66a62005-03-25 12:31:53 -06003030 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003031
James Ketrenosa613bff2005-08-24 21:43:11 -05003032 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003033 /* Clear the 'host command active' bit... */
3034 priv->status &= ~STATUS_HCMD_ACTIVE;
3035 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003036 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3037 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003038 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003039
3040 IPW_DEBUG_TRACE("<<\n");
3041 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003042}
James Ketrenos43f66a62005-03-25 12:31:53 -06003043
Jeff Garzikbf794512005-07-31 13:07:26 -04003044static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003045 const struct firmware **fw, const char *name)
3046{
3047 struct fw_header *header;
3048 int rc;
3049
3050 /* ask firmware_class module to get the boot firmware off disk */
3051 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3052 if (rc < 0) {
3053 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3054 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003055 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003056
3057 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003058 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003059 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3060 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003061 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3062 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003063 return -EINVAL;
3064 }
3065
Jiri Bencaaa4d302005-06-07 14:58:41 +02003066 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003067 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003068 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3069 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 (*fw)->size - sizeof(struct fw_header));
3071 return 0;
3072}
3073
James Ketrenosb095c382005-08-24 22:04:42 -05003074#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003075
3076static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
3077 struct ipw_rx_queue *rxq)
3078{
3079 unsigned long flags;
3080 int i;
3081
3082 spin_lock_irqsave(&rxq->lock, flags);
3083
3084 INIT_LIST_HEAD(&rxq->rx_free);
3085 INIT_LIST_HEAD(&rxq->rx_used);
3086
3087 /* Fill the rx_used queue with _all_ of the Rx buffers */
3088 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3089 /* In the reset function, these buffers may have been allocated
3090 * to an SKB, so we need to unmap and free potential storage */
3091 if (rxq->pool[i].skb != NULL) {
3092 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003093 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003095 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003096 }
3097 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3098 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003099
James Ketrenos43f66a62005-03-25 12:31:53 -06003100 /* Set us so that we have processed and used all buffers, but have
3101 * not restocked the Rx queue with fresh buffers */
3102 rxq->read = rxq->write = 0;
3103 rxq->processed = RX_QUEUE_SIZE - 1;
3104 rxq->free_count = 0;
3105 spin_unlock_irqrestore(&rxq->lock, flags);
3106}
3107
3108#ifdef CONFIG_PM
3109static int fw_loaded = 0;
3110static const struct firmware *bootfw = NULL;
3111static const struct firmware *firmware = NULL;
3112static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003113
3114static void free_firmware(void)
3115{
3116 if (fw_loaded) {
3117 release_firmware(bootfw);
3118 release_firmware(ucode);
3119 release_firmware(firmware);
3120 bootfw = ucode = firmware = NULL;
3121 fw_loaded = 0;
3122 }
3123}
3124#else
3125#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003126#endif
3127
3128static int ipw_load(struct ipw_priv *priv)
3129{
3130#ifndef CONFIG_PM
3131 const struct firmware *bootfw = NULL;
3132 const struct firmware *firmware = NULL;
3133 const struct firmware *ucode = NULL;
3134#endif
3135 int rc = 0, retries = 3;
3136
3137#ifdef CONFIG_PM
3138 if (!fw_loaded) {
3139#endif
3140 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003141 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003143
James Ketrenos43f66a62005-03-25 12:31:53 -06003144 switch (priv->ieee->iw_mode) {
3145 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003146 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003147 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003148 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003149 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003150
James Ketrenos43f66a62005-03-25 12:31:53 -06003151 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3152 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003153
James Ketrenosb095c382005-08-24 22:04:42 -05003154#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003155 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003156 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003157 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003158 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003159 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003160
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003161 rc = ipw_get_fw(priv, &firmware,
3162 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003163 break;
3164#endif
3165 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003166 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003167 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003168 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003169
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3171 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003172
James Ketrenos43f66a62005-03-25 12:31:53 -06003173 default:
3174 rc = -EINVAL;
3175 }
3176
Jeff Garzikbf794512005-07-31 13:07:26 -04003177 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003178 goto error;
3179
3180#ifdef CONFIG_PM
3181 fw_loaded = 1;
3182 }
3183#endif
3184
3185 if (!priv->rxq)
3186 priv->rxq = ipw_rx_queue_alloc(priv);
3187 else
3188 ipw_rx_queue_reset(priv, priv->rxq);
3189 if (!priv->rxq) {
3190 IPW_ERROR("Unable to initialize Rx queue\n");
3191 goto error;
3192 }
3193
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003194 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003195 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003196 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003197 priv->status &= ~STATUS_INT_ENABLED;
3198
3199 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003200 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003201
James Ketrenos43f66a62005-03-25 12:31:53 -06003202 ipw_stop_nic(priv);
3203
3204 rc = ipw_reset_nic(priv);
3205 if (rc) {
3206 IPW_ERROR("Unable to reset NIC\n");
3207 goto error;
3208 }
3209
James Ketrenosb095c382005-08-24 22:04:42 -05003210 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3211 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003212
3213 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003214 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003215 bootfw->size - sizeof(struct fw_header));
3216 if (rc < 0) {
3217 IPW_ERROR("Unable to load boot firmware\n");
3218 goto error;
3219 }
3220
3221 /* kick start the device */
3222 ipw_start_nic(priv);
3223
3224 /* wait for the device to finish it's initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003225 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3226 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003227 if (rc < 0) {
3228 IPW_ERROR("device failed to boot initial fw image\n");
3229 goto error;
3230 }
3231 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3232
Jeff Garzikbf794512005-07-31 13:07:26 -04003233 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003234 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003235
3236 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003237 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003238 ucode->size - sizeof(struct fw_header));
3239 if (rc < 0) {
3240 IPW_ERROR("Unable to load ucode\n");
3241 goto error;
3242 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003243
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 /* stop nic */
3245 ipw_stop_nic(priv);
3246
3247 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003248 rc = ipw_load_firmware(priv, firmware->data +
3249 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003250 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003251 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 IPW_ERROR("Unable to load firmware\n");
3253 goto error;
3254 }
3255
3256 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3257
3258 rc = ipw_queue_reset(priv);
3259 if (rc) {
3260 IPW_ERROR("Unable to initialize queues\n");
3261 goto error;
3262 }
3263
3264 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003265 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003266 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003267 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003268
James Ketrenos43f66a62005-03-25 12:31:53 -06003269 /* kick start the device */
3270 ipw_start_nic(priv);
3271
James Ketrenosb095c382005-08-24 22:04:42 -05003272 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003273 if (retries > 0) {
3274 IPW_WARNING("Parity error. Retrying init.\n");
3275 retries--;
3276 goto retry;
3277 }
3278
3279 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3280 rc = -EIO;
3281 goto error;
3282 }
3283
3284 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003285 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3286 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 if (rc < 0) {
3288 IPW_ERROR("device failed to start after 500ms\n");
3289 goto error;
3290 }
3291 IPW_DEBUG_INFO("device response after %dms\n", rc);
3292
3293 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003294 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003295
3296 /* read eeprom data and initialize the eeprom region of sram */
3297 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003298 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003299
3300 /* enable interrupts */
3301 ipw_enable_interrupts(priv);
3302
3303 /* Ensure our queue has valid packets */
3304 ipw_rx_queue_replenish(priv);
3305
James Ketrenosb095c382005-08-24 22:04:42 -05003306 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003307
3308 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003309 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003310
3311#ifndef CONFIG_PM
3312 release_firmware(bootfw);
3313 release_firmware(ucode);
3314 release_firmware(firmware);
3315#endif
3316 return 0;
3317
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003318 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003319 if (priv->rxq) {
3320 ipw_rx_queue_free(priv, priv->rxq);
3321 priv->rxq = NULL;
3322 }
3323 ipw_tx_queue_free(priv);
3324 if (bootfw)
3325 release_firmware(bootfw);
3326 if (ucode)
3327 release_firmware(ucode);
3328 if (firmware)
3329 release_firmware(firmware);
3330#ifdef CONFIG_PM
3331 fw_loaded = 0;
3332 bootfw = ucode = firmware = NULL;
3333#endif
3334
3335 return rc;
3336}
3337
Jeff Garzikbf794512005-07-31 13:07:26 -04003338/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003339 * DMA services
3340 *
3341 * Theory of operation
3342 *
3343 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3344 * 2 empty entries always kept in the buffer to protect from overflow.
3345 *
3346 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003347 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3348 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003349 * Tx queue resumed.
3350 *
3351 * The IPW operates with six queues, one receive queue in the device's
3352 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003353 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003354 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003355 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003356 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003357 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003358 * we only utilize the first data transmit queue (queue1).
3359 */
3360
3361/**
3362 * Driver allocates buffers of this size for Rx
3363 */
3364
3365static inline int ipw_queue_space(const struct clx2_queue *q)
3366{
3367 int s = q->last_used - q->first_empty;
3368 if (s <= 0)
3369 s += q->n_bd;
3370 s -= 2; /* keep some reserve to not confuse empty and full situations */
3371 if (s < 0)
3372 s = 0;
3373 return s;
3374}
3375
3376static inline int ipw_queue_inc_wrap(int index, int n_bd)
3377{
3378 return (++index == n_bd) ? 0 : index;
3379}
3380
3381/**
3382 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003383 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003384 * @param q queue to init
3385 * @param count Number of BD's to allocate. Should be power of 2
3386 * @param read_register Address for 'read' register
3387 * (not offset within BAR, full address)
3388 * @param write_register Address for 'write' register
3389 * (not offset within BAR, full address)
3390 * @param base_register Address for 'base' register
3391 * (not offset within BAR, full address)
3392 * @param size Address for 'size' register
3393 * (not offset within BAR, full address)
3394 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003395static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003396 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003397{
3398 q->n_bd = count;
3399
3400 q->low_mark = q->n_bd / 4;
3401 if (q->low_mark < 4)
3402 q->low_mark = 4;
3403
3404 q->high_mark = q->n_bd / 8;
3405 if (q->high_mark < 2)
3406 q->high_mark = 2;
3407
3408 q->first_empty = q->last_used = 0;
3409 q->reg_r = read;
3410 q->reg_w = write;
3411
3412 ipw_write32(priv, base, q->dma_addr);
3413 ipw_write32(priv, size, count);
3414 ipw_write32(priv, read, 0);
3415 ipw_write32(priv, write, 0);
3416
3417 _ipw_read32(priv, 0x90);
3418}
3419
Jeff Garzikbf794512005-07-31 13:07:26 -04003420static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003421 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003422 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003423{
3424 struct pci_dev *dev = priv->pci_dev;
3425
3426 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3427 if (!q->txb) {
3428 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3429 return -ENOMEM;
3430 }
3431
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003432 q->bd =
3433 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003434 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003435 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003436 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003437 kfree(q->txb);
3438 q->txb = NULL;
3439 return -ENOMEM;
3440 }
3441
3442 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3443 return 0;
3444}
3445
3446/**
3447 * Free one TFD, those at index [txq->q.last_used].
3448 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003449 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003450 * @param dev
3451 * @param txq
3452 */
3453static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3454 struct clx2_tx_queue *txq)
3455{
3456 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3457 struct pci_dev *dev = priv->pci_dev;
3458 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003459
James Ketrenos43f66a62005-03-25 12:31:53 -06003460 /* classify bd */
3461 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3462 /* nothing to cleanup after for host commands */
3463 return;
3464
3465 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003466 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3467 IPW_ERROR("Too many chunks: %i\n",
3468 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003469 /** @todo issue fatal error, it is quite serious situation */
3470 return;
3471 }
3472
3473 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003474 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3475 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3476 le16_to_cpu(bd->u.data.chunk_len[i]),
3477 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003478 if (txq->txb[txq->q.last_used]) {
3479 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3480 txq->txb[txq->q.last_used] = NULL;
3481 }
3482 }
3483}
3484
3485/**
3486 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003487 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003488 * Empty queue by removing and destroying all BD's.
3489 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003490 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003491 * @param dev
3492 * @param q
3493 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003494static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003495{
3496 struct clx2_queue *q = &txq->q;
3497 struct pci_dev *dev = priv->pci_dev;
3498
Jeff Garzikbf794512005-07-31 13:07:26 -04003499 if (q->n_bd == 0)
3500 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003501
3502 /* first, empty all BD's */
3503 for (; q->first_empty != q->last_used;
3504 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3505 ipw_queue_tx_free_tfd(priv, txq);
3506 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003507
James Ketrenos43f66a62005-03-25 12:31:53 -06003508 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003509 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003510 q->dma_addr);
3511 kfree(txq->txb);
3512
3513 /* 0 fill whole structure */
3514 memset(txq, 0, sizeof(*txq));
3515}
3516
James Ketrenos43f66a62005-03-25 12:31:53 -06003517/**
3518 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003519 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003520 * @param priv
3521 */
3522static void ipw_tx_queue_free(struct ipw_priv *priv)
3523{
3524 /* Tx CMD queue */
3525 ipw_queue_tx_free(priv, &priv->txq_cmd);
3526
3527 /* Tx queues */
3528 ipw_queue_tx_free(priv, &priv->txq[0]);
3529 ipw_queue_tx_free(priv, &priv->txq[1]);
3530 ipw_queue_tx_free(priv, &priv->txq[2]);
3531 ipw_queue_tx_free(priv, &priv->txq[3]);
3532}
3533
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003534static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003535{
3536 /* First 3 bytes are manufacturer */
3537 bssid[0] = priv->mac_addr[0];
3538 bssid[1] = priv->mac_addr[1];
3539 bssid[2] = priv->mac_addr[2];
3540
3541 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003542 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003543
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003544 bssid[0] &= 0xfe; /* clear multicast bit */
3545 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003546}
3547
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003548static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003549{
3550 struct ipw_station_entry entry;
3551 int i;
3552
3553 for (i = 0; i < priv->num_stations; i++) {
3554 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3555 /* Another node is active in network */
3556 priv->missed_adhoc_beacons = 0;
3557 if (!(priv->config & CFG_STATIC_CHANNEL))
3558 /* when other nodes drop out, we drop out */
3559 priv->config &= ~CFG_ADHOC_PERSIST;
3560
3561 return i;
3562 }
3563 }
3564
3565 if (i == MAX_STATIONS)
3566 return IPW_INVALID_STATION;
3567
3568 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3569
3570 entry.reserved = 0;
3571 entry.support_mode = 0;
3572 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3573 memcpy(priv->stations[i], bssid, ETH_ALEN);
3574 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003575 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003576 priv->num_stations++;
3577
3578 return i;
3579}
3580
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003581static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003582{
3583 int i;
3584
Jeff Garzikbf794512005-07-31 13:07:26 -04003585 for (i = 0; i < priv->num_stations; i++)
3586 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003587 return i;
3588
3589 return IPW_INVALID_STATION;
3590}
3591
3592static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3593{
3594 int err;
3595
3596 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3597 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3598 return;
3599 }
3600
3601 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3602 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003603 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003604 priv->assoc_request.channel);
3605
3606 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3607 priv->status |= STATUS_DISASSOCIATING;
3608
3609 if (quiet)
3610 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3611 else
3612 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3613 err = ipw_send_associate(priv, &priv->assoc_request);
3614 if (err) {
3615 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3616 "failed.\n");
3617 return;
3618 }
3619
3620}
3621
James Ketrenosc848d0a2005-08-24 21:56:24 -05003622static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003623{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003624 struct ipw_priv *priv = data;
3625 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3626 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003627 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003628 return 1;
3629}
3630
3631static void ipw_bg_disassociate(void *data)
3632{
3633 struct ipw_priv *priv = data;
3634 down(&priv->sem);
3635 ipw_disassociate(data);
3636 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003637}
3638
Zhu Yid8bad6d2005-07-13 12:25:38 -05003639static void ipw_system_config(void *data)
3640{
3641 struct ipw_priv *priv = data;
3642 ipw_send_system_config(priv, &priv->sys_config);
3643}
3644
James Ketrenos43f66a62005-03-25 12:31:53 -06003645struct ipw_status_code {
3646 u16 status;
3647 const char *reason;
3648};
3649
3650static const struct ipw_status_code ipw_status_codes[] = {
3651 {0x00, "Successful"},
3652 {0x01, "Unspecified failure"},
3653 {0x0A, "Cannot support all requested capabilities in the "
3654 "Capability information field"},
3655 {0x0B, "Reassociation denied due to inability to confirm that "
3656 "association exists"},
3657 {0x0C, "Association denied due to reason outside the scope of this "
3658 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003659 {0x0D,
3660 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003661 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003662 {0x0E,
3663 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003664 "transaction sequence number out of expected sequence"},
3665 {0x0F, "Authentication rejected because of challenge failure"},
3666 {0x10, "Authentication rejected due to timeout waiting for next "
3667 "frame in sequence"},
3668 {0x11, "Association denied because AP is unable to handle additional "
3669 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003670 {0x12,
3671 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003672 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003673 {0x13,
3674 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003675 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003676 {0x14,
3677 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003678 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003679 {0x15,
3680 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003681 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003682 {0x19,
3683 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003685 {0x1A,
3686 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003687 "DSSS-OFDM operation"},
3688 {0x28, "Invalid Information Element"},
3689 {0x29, "Group Cipher is not valid"},
3690 {0x2A, "Pairwise Cipher is not valid"},
3691 {0x2B, "AKMP is not valid"},
3692 {0x2C, "Unsupported RSN IE version"},
3693 {0x2D, "Invalid RSN IE Capabilities"},
3694 {0x2E, "Cipher suite is rejected per security policy"},
3695};
3696
3697#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003698static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003699{
3700 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003701 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003702 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003703 return ipw_status_codes[i].reason;
3704 return "Unknown status value.";
3705}
3706#endif
3707
3708static void inline average_init(struct average *avg)
3709{
3710 memset(avg, 0, sizeof(*avg));
3711}
3712
3713static void inline average_add(struct average *avg, s16 val)
3714{
3715 avg->sum -= avg->entries[avg->pos];
3716 avg->sum += val;
3717 avg->entries[avg->pos++] = val;
3718 if (unlikely(avg->pos == AVG_ENTRIES)) {
3719 avg->init = 1;
3720 avg->pos = 0;
3721 }
3722}
3723
3724static s16 inline average_value(struct average *avg)
3725{
3726 if (!unlikely(avg->init)) {
3727 if (avg->pos)
3728 return avg->sum / avg->pos;
3729 return 0;
3730 }
3731
3732 return avg->sum / AVG_ENTRIES;
3733}
3734
3735static void ipw_reset_stats(struct ipw_priv *priv)
3736{
3737 u32 len = sizeof(u32);
3738
3739 priv->quality = 0;
3740
3741 average_init(&priv->average_missed_beacons);
3742 average_init(&priv->average_rssi);
3743 average_init(&priv->average_noise);
3744
3745 priv->last_rate = 0;
3746 priv->last_missed_beacons = 0;
3747 priv->last_rx_packets = 0;
3748 priv->last_tx_packets = 0;
3749 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003750
James Ketrenos43f66a62005-03-25 12:31:53 -06003751 /* Firmware managed, reset only when NIC is restarted, so we have to
3752 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003753 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003754 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003755 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003756 &priv->last_tx_failures, &len);
3757
3758 /* Driver managed, reset with each association */
3759 priv->missed_adhoc_beacons = 0;
3760 priv->missed_beacons = 0;
3761 priv->tx_packets = 0;
3762 priv->rx_packets = 0;
3763
3764}
3765
James Ketrenos43f66a62005-03-25 12:31:53 -06003766static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3767{
3768 u32 i = 0x80000000;
3769 u32 mask = priv->rates_mask;
3770 /* If currently associated in B mode, restrict the maximum
3771 * rate match to B rates */
3772 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3773 mask &= IEEE80211_CCK_RATES_MASK;
3774
3775 /* TODO: Verify that the rate is supported by the current rates
3776 * list. */
3777
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003778 while (i && !(mask & i))
3779 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003780 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003781 case IEEE80211_CCK_RATE_1MB_MASK:
3782 return 1000000;
3783 case IEEE80211_CCK_RATE_2MB_MASK:
3784 return 2000000;
3785 case IEEE80211_CCK_RATE_5MB_MASK:
3786 return 5500000;
3787 case IEEE80211_OFDM_RATE_6MB_MASK:
3788 return 6000000;
3789 case IEEE80211_OFDM_RATE_9MB_MASK:
3790 return 9000000;
3791 case IEEE80211_CCK_RATE_11MB_MASK:
3792 return 11000000;
3793 case IEEE80211_OFDM_RATE_12MB_MASK:
3794 return 12000000;
3795 case IEEE80211_OFDM_RATE_18MB_MASK:
3796 return 18000000;
3797 case IEEE80211_OFDM_RATE_24MB_MASK:
3798 return 24000000;
3799 case IEEE80211_OFDM_RATE_36MB_MASK:
3800 return 36000000;
3801 case IEEE80211_OFDM_RATE_48MB_MASK:
3802 return 48000000;
3803 case IEEE80211_OFDM_RATE_54MB_MASK:
3804 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003805 }
3806
Jeff Garzikbf794512005-07-31 13:07:26 -04003807 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003808 return 11000000;
3809 else
3810 return 54000000;
3811}
3812
3813static u32 ipw_get_current_rate(struct ipw_priv *priv)
3814{
3815 u32 rate, len = sizeof(rate);
3816 int err;
3817
Jeff Garzikbf794512005-07-31 13:07:26 -04003818 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003819 return 0;
3820
3821 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003822 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003823 &len);
3824 if (err) {
3825 IPW_DEBUG_INFO("failed querying ordinals.\n");
3826 return 0;
3827 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003828 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003829 return ipw_get_max_rate(priv);
3830
3831 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003832 case IPW_TX_RATE_1MB:
3833 return 1000000;
3834 case IPW_TX_RATE_2MB:
3835 return 2000000;
3836 case IPW_TX_RATE_5MB:
3837 return 5500000;
3838 case IPW_TX_RATE_6MB:
3839 return 6000000;
3840 case IPW_TX_RATE_9MB:
3841 return 9000000;
3842 case IPW_TX_RATE_11MB:
3843 return 11000000;
3844 case IPW_TX_RATE_12MB:
3845 return 12000000;
3846 case IPW_TX_RATE_18MB:
3847 return 18000000;
3848 case IPW_TX_RATE_24MB:
3849 return 24000000;
3850 case IPW_TX_RATE_36MB:
3851 return 36000000;
3852 case IPW_TX_RATE_48MB:
3853 return 48000000;
3854 case IPW_TX_RATE_54MB:
3855 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003856 }
3857
3858 return 0;
3859}
3860
James Ketrenos43f66a62005-03-25 12:31:53 -06003861#define IPW_STATS_INTERVAL (2 * HZ)
3862static void ipw_gather_stats(struct ipw_priv *priv)
3863{
3864 u32 rx_err, rx_err_delta, rx_packets_delta;
3865 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3866 u32 missed_beacons_percent, missed_beacons_delta;
3867 u32 quality = 0;
3868 u32 len = sizeof(u32);
3869 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003870 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003871 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003872 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003873
3874 if (!(priv->status & STATUS_ASSOCIATED)) {
3875 priv->quality = 0;
3876 return;
3877 }
3878
3879 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003880 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003881 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003882 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003883 priv->last_missed_beacons = priv->missed_beacons;
3884 if (priv->assoc_request.beacon_interval) {
3885 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003886 (HZ * priv->assoc_request.beacon_interval) /
3887 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003888 } else {
3889 missed_beacons_percent = 0;
3890 }
3891 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3892
3893 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3894 rx_err_delta = rx_err - priv->last_rx_err;
3895 priv->last_rx_err = rx_err;
3896
3897 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3898 tx_failures_delta = tx_failures - priv->last_tx_failures;
3899 priv->last_tx_failures = tx_failures;
3900
3901 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3902 priv->last_rx_packets = priv->rx_packets;
3903
3904 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3905 priv->last_tx_packets = priv->tx_packets;
3906
3907 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003908 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003909 * Missed beacon: 100% = 0, 0% = 70% missed
3910 * Rate: 60% = 1Mbs, 100% = Max
3911 * Rx and Tx errors represent a straight % of total Rx/Tx
3912 * RSSI: 100% = > -50, 0% = < -80
3913 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003914 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 * The lowest computed quality is used.
3916 *
3917 */
3918#define BEACON_THRESHOLD 5
3919 beacon_quality = 100 - missed_beacons_percent;
3920 if (beacon_quality < BEACON_THRESHOLD)
3921 beacon_quality = 0;
3922 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003923 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003924 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003925 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003926 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003927
James Ketrenos43f66a62005-03-25 12:31:53 -06003928 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05003929 max_rate = ipw_get_max_rate(priv);
3930 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003931 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3932 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003933
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003934 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003935 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003936 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003937 else
3938 rx_quality = 100;
3939 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3940 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003941
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003942 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003943 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003944 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003945 else
3946 tx_quality = 100;
3947 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3948 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003949
James Ketrenos43f66a62005-03-25 12:31:53 -06003950 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003951 signal_quality =
3952 (100 *
3953 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3954 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
3955 (priv->ieee->perfect_rssi - rssi) *
3956 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
3957 62 * (priv->ieee->perfect_rssi - rssi))) /
3958 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3959 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
3960 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06003961 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05003962 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06003963 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003964
James Ketrenos43f66a62005-03-25 12:31:53 -06003965 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3966 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003967
3968 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003969 min(rate_quality,
3970 min(tx_quality, min(rx_quality, signal_quality))));
3971 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003972 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3973 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003975 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3976 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003977 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003978 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3979 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003980 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003981 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3982 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003983 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003984 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3985 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003986
3987 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003988
3989 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003990 IPW_STATS_INTERVAL);
3991}
3992
James Ketrenosc848d0a2005-08-24 21:56:24 -05003993static void ipw_bg_gather_stats(void *data)
3994{
3995 struct ipw_priv *priv = data;
3996 down(&priv->sem);
3997 ipw_gather_stats(data);
3998 up(&priv->sem);
3999}
4000
James Ketrenosea2b26e2005-08-24 21:25:16 -05004001static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
4002 int missed_count)
4003{
4004 priv->notif_missed_beacons = missed_count;
4005
James Ketrenosafbf30a2005-08-25 00:05:33 -05004006 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004007 priv->status & STATUS_ASSOCIATED) {
4008 /* If associated and we've hit the missed
4009 * beacon threshold, disassociate, turn
4010 * off roaming, and abort any active scans */
4011 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004012 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004013 "Missed beacon: %d - disassociate\n", missed_count);
4014 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004015 if (priv->status & STATUS_SCANNING) {
4016 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4017 IPW_DL_STATE,
4018 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004019 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004020 }
4021
James Ketrenosea2b26e2005-08-24 21:25:16 -05004022 queue_work(priv->workqueue, &priv->disassociate);
4023 return;
4024 }
4025
4026 if (priv->status & STATUS_ROAMING) {
4027 /* If we are currently roaming, then just
4028 * print a debug statement... */
4029 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4030 "Missed beacon: %d - roam in progress\n",
4031 missed_count);
4032 return;
4033 }
4034
4035 if (missed_count > priv->roaming_threshold) {
4036 /* If we are not already roaming, set the ROAM
4037 * bit in the status and kick off a scan */
4038 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4039 "Missed beacon: %d - initiate "
4040 "roaming\n", missed_count);
4041 if (!(priv->status & STATUS_ROAMING)) {
4042 priv->status |= STATUS_ROAMING;
4043 if (!(priv->status & STATUS_SCANNING))
4044 queue_work(priv->workqueue,
4045 &priv->request_scan);
4046 }
4047 return;
4048 }
4049
4050 if (priv->status & STATUS_SCANNING) {
4051 /* Stop scan to keep fw from getting
4052 * stuck (only if we aren't roaming --
4053 * otherwise we'll never scan more than 2 or 3
4054 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004055 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4056 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004057 queue_work(priv->workqueue, &priv->abort_scan);
4058 }
4059
4060 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4061
4062}
4063
James Ketrenos43f66a62005-03-25 12:31:53 -06004064/**
4065 * Handle host notification packet.
4066 * Called from interrupt routine
4067 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004068static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 struct ipw_rx_notification *notif)
4070{
James Ketrenosa613bff2005-08-24 21:43:11 -05004071 notif->size = le16_to_cpu(notif->size);
4072
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004073 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004074
James Ketrenos43f66a62005-03-25 12:31:53 -06004075 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004076 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4077 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004078
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004079 switch (assoc->state) {
4080 case CMAS_ASSOCIATED:{
4081 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4082 IPW_DL_ASSOC,
4083 "associated: '%s' " MAC_FMT
4084 " \n",
4085 escape_essid(priv->essid,
4086 priv->essid_len),
4087 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004088
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004089 switch (priv->ieee->iw_mode) {
4090 case IW_MODE_INFRA:
4091 memcpy(priv->ieee->bssid,
4092 priv->bssid, ETH_ALEN);
4093 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004094
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004095 case IW_MODE_ADHOC:
4096 memcpy(priv->ieee->bssid,
4097 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004098
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004099 /* clear out the station table */
4100 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004101
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004102 IPW_DEBUG_ASSOC
4103 ("queueing adhoc check\n");
4104 queue_delayed_work(priv->
4105 workqueue,
4106 &priv->
4107 adhoc_check,
4108 priv->
4109 assoc_request.
4110 beacon_interval);
4111 break;
4112 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004113
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004114 priv->status &= ~STATUS_ASSOCIATING;
4115 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004116 queue_work(priv->workqueue,
4117 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004118
James Ketrenosb095c382005-08-24 22:04:42 -05004119#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004120#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4121 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4122 if ((priv->status & STATUS_AUTH) &&
4123 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4124 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004125 if ((sizeof
4126 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004127 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004128 <= notif->size)
4129 && (notif->size <= 2314)) {
4130 struct
4131 ieee80211_rx_stats
4132 stats = {
4133 .len =
4134 notif->
4135 size - 1,
4136 };
4137
4138 IPW_DEBUG_QOS
4139 ("QoS Associate "
4140 "size %d\n",
4141 notif->size);
4142 ieee80211_rx_mgt(priv->
4143 ieee,
4144 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004145 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004146 *)
4147 &notif->u.raw, &stats);
4148 }
4149 }
4150#endif
4151
James Ketrenosa613bff2005-08-24 21:43:11 -05004152 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004153
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004154 break;
4155 }
4156
4157 case CMAS_AUTHENTICATED:{
4158 if (priv->
4159 status & (STATUS_ASSOCIATED |
4160 STATUS_AUTH)) {
4161#ifdef CONFIG_IPW_DEBUG
4162 struct notif_authenticate *auth
4163 = &notif->u.auth;
4164 IPW_DEBUG(IPW_DL_NOTIF |
4165 IPW_DL_STATE |
4166 IPW_DL_ASSOC,
4167 "deauthenticated: '%s' "
4168 MAC_FMT
4169 ": (0x%04X) - %s \n",
4170 escape_essid(priv->
4171 essid,
4172 priv->
4173 essid_len),
4174 MAC_ARG(priv->bssid),
4175 ntohs(auth->status),
4176 ipw_get_status_code
4177 (ntohs
4178 (auth->status)));
4179#endif
4180
4181 priv->status &=
4182 ~(STATUS_ASSOCIATING |
4183 STATUS_AUTH |
4184 STATUS_ASSOCIATED);
4185
James Ketrenosa613bff2005-08-24 21:43:11 -05004186 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004187 break;
4188 }
4189
4190 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4191 IPW_DL_ASSOC,
4192 "authenticated: '%s' " MAC_FMT
4193 "\n",
4194 escape_essid(priv->essid,
4195 priv->essid_len),
4196 MAC_ARG(priv->bssid));
4197 break;
4198 }
4199
4200 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004201 if (priv->status & STATUS_AUTH) {
4202 struct
4203 ieee80211_assoc_response
4204 *resp;
4205 resp =
4206 (struct
4207 ieee80211_assoc_response
4208 *)&notif->u.raw;
4209 IPW_DEBUG(IPW_DL_NOTIF |
4210 IPW_DL_STATE |
4211 IPW_DL_ASSOC,
4212 "association failed (0x%04X): %s\n",
4213 ntohs(resp->status),
4214 ipw_get_status_code
4215 (ntohs
4216 (resp->status)));
4217 }
4218
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004219 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4220 IPW_DL_ASSOC,
4221 "disassociated: '%s' " MAC_FMT
4222 " \n",
4223 escape_essid(priv->essid,
4224 priv->essid_len),
4225 MAC_ARG(priv->bssid));
4226
4227 priv->status &=
4228 ~(STATUS_DISASSOCIATING |
4229 STATUS_ASSOCIATING |
4230 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004231 if (priv->assoc_network
4232 && (priv->assoc_network->
4233 capability &
4234 WLAN_CAPABILITY_IBSS))
4235 ipw_remove_current_network
4236 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004237
James Ketrenosa613bff2005-08-24 21:43:11 -05004238 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004239
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004240 break;
4241 }
4242
James Ketrenosb095c382005-08-24 22:04:42 -05004243 case CMAS_RX_ASSOC_RESP:
4244 break;
4245
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004246 default:
4247 IPW_ERROR("assoc: unknown (%d)\n",
4248 assoc->state);
4249 break;
4250 }
4251
James Ketrenos43f66a62005-03-25 12:31:53 -06004252 break;
4253 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004254
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004255 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4256 struct notif_authenticate *auth = &notif->u.auth;
4257 switch (auth->state) {
4258 case CMAS_AUTHENTICATED:
4259 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4260 "authenticated: '%s' " MAC_FMT " \n",
4261 escape_essid(priv->essid,
4262 priv->essid_len),
4263 MAC_ARG(priv->bssid));
4264 priv->status |= STATUS_AUTH;
4265 break;
4266
4267 case CMAS_INIT:
4268 if (priv->status & STATUS_AUTH) {
4269 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4270 IPW_DL_ASSOC,
4271 "authentication failed (0x%04X): %s\n",
4272 ntohs(auth->status),
4273 ipw_get_status_code(ntohs
4274 (auth->
4275 status)));
4276 }
4277 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4278 IPW_DL_ASSOC,
4279 "deauthenticated: '%s' " MAC_FMT "\n",
4280 escape_essid(priv->essid,
4281 priv->essid_len),
4282 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004283
4284 priv->status &= ~(STATUS_ASSOCIATING |
4285 STATUS_AUTH |
4286 STATUS_ASSOCIATED);
4287
James Ketrenosa613bff2005-08-24 21:43:11 -05004288 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004289 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004290
4291 case CMAS_TX_AUTH_SEQ_1:
4292 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4293 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4294 break;
4295 case CMAS_RX_AUTH_SEQ_2:
4296 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4297 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4298 break;
4299 case CMAS_AUTH_SEQ_1_PASS:
4300 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4301 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4302 break;
4303 case CMAS_AUTH_SEQ_1_FAIL:
4304 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4305 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4306 break;
4307 case CMAS_TX_AUTH_SEQ_3:
4308 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4309 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4310 break;
4311 case CMAS_RX_AUTH_SEQ_4:
4312 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4313 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4314 break;
4315 case CMAS_AUTH_SEQ_2_PASS:
4316 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4317 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4318 break;
4319 case CMAS_AUTH_SEQ_2_FAIL:
4320 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4321 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4322 break;
4323 case CMAS_TX_ASSOC:
4324 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4325 IPW_DL_ASSOC, "TX_ASSOC\n");
4326 break;
4327 case CMAS_RX_ASSOC_RESP:
4328 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4329 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004330
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331 break;
4332 case CMAS_ASSOCIATED:
4333 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4334 IPW_DL_ASSOC, "ASSOCIATED\n");
4335 break;
4336 default:
4337 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4338 auth->state);
4339 break;
4340 }
4341 break;
4342 }
4343
4344 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4345 struct notif_channel_result *x =
4346 &notif->u.channel_result;
4347
4348 if (notif->size == sizeof(*x)) {
4349 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4350 x->channel_num);
4351 } else {
4352 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4353 "(should be %zd)\n",
4354 notif->size, sizeof(*x));
4355 }
4356 break;
4357 }
4358
4359 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4360 struct notif_scan_complete *x = &notif->u.scan_complete;
4361 if (notif->size == sizeof(*x)) {
4362 IPW_DEBUG_SCAN
4363 ("Scan completed: type %d, %d channels, "
4364 "%d status\n", x->scan_type,
4365 x->num_channels, x->status);
4366 } else {
4367 IPW_ERROR("Scan completed of wrong size %d "
4368 "(should be %zd)\n",
4369 notif->size, sizeof(*x));
4370 }
4371
4372 priv->status &=
4373 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4374
4375 cancel_delayed_work(&priv->scan_check);
4376
James Ketrenosb095c382005-08-24 22:04:42 -05004377 if (priv->status & STATUS_EXIT_PENDING)
4378 break;
4379
4380 priv->ieee->scans++;
4381
4382#ifdef CONFIG_IPW2200_MONITOR
4383 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004384 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004385 queue_work(priv->workqueue,
4386 &priv->request_scan);
4387 break;
4388 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004389 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004390#endif /* CONFIG_IPW2200_MONITOR */
4391
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004392 if (!(priv->status & (STATUS_ASSOCIATED |
4393 STATUS_ASSOCIATING |
4394 STATUS_ROAMING |
4395 STATUS_DISASSOCIATING)))
4396 queue_work(priv->workqueue, &priv->associate);
4397 else if (priv->status & STATUS_ROAMING) {
4398 /* If a scan completed and we are in roam mode, then
4399 * the scan that completed was the one requested as a
4400 * result of entering roam... so, schedule the
4401 * roam work */
4402 queue_work(priv->workqueue, &priv->roam);
4403 } else if (priv->status & STATUS_SCAN_PENDING)
4404 queue_work(priv->workqueue,
4405 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004406 else if (priv->config & CFG_BACKGROUND_SCAN
4407 && priv->status & STATUS_ASSOCIATED)
4408 queue_delayed_work(priv->workqueue,
4409 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004410 break;
4411 }
4412
4413 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4414 struct notif_frag_length *x = &notif->u.frag_len;
4415
James Ketrenosa613bff2005-08-24 21:43:11 -05004416 if (notif->size == sizeof(*x))
4417 IPW_ERROR("Frag length: %d\n",
4418 le16_to_cpu(x->frag_length));
4419 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004420 IPW_ERROR("Frag length of wrong size %d "
4421 "(should be %zd)\n",
4422 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004423 break;
4424 }
4425
4426 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4427 struct notif_link_deterioration *x =
4428 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004429
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004430 if (notif->size == sizeof(*x)) {
4431 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4432 "link deterioration: '%s' " MAC_FMT
4433 " \n", escape_essid(priv->essid,
4434 priv->essid_len),
4435 MAC_ARG(priv->bssid));
4436 memcpy(&priv->last_link_deterioration, x,
4437 sizeof(*x));
4438 } else {
4439 IPW_ERROR("Link Deterioration of wrong size %d "
4440 "(should be %zd)\n",
4441 notif->size, sizeof(*x));
4442 }
4443 break;
4444 }
4445
4446 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4447 IPW_ERROR("Dino config\n");
4448 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004449 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004450 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004451
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004452 break;
4453 }
4454
4455 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4456 struct notif_beacon_state *x = &notif->u.beacon_state;
4457 if (notif->size != sizeof(*x)) {
4458 IPW_ERROR
4459 ("Beacon state of wrong size %d (should "
4460 "be %zd)\n", notif->size, sizeof(*x));
4461 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004462 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004463
James Ketrenosa613bff2005-08-24 21:43:11 -05004464 if (le32_to_cpu(x->state) ==
4465 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4466 ipw_handle_missed_beacon(priv,
4467 le32_to_cpu(x->
4468 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004469
James Ketrenos43f66a62005-03-25 12:31:53 -06004470 break;
4471 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004472
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004473 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4474 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4475 if (notif->size == sizeof(*x)) {
4476 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4477 "0x%02x station %d\n",
4478 x->key_state, x->security_type,
4479 x->station_index);
4480 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004481 }
4482
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004483 IPW_ERROR
4484 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4485 notif->size, sizeof(*x));
4486 break;
4487 }
4488
4489 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4490 struct notif_calibration *x = &notif->u.calibration;
4491
4492 if (notif->size == sizeof(*x)) {
4493 memcpy(&priv->calib, x, sizeof(*x));
4494 IPW_DEBUG_INFO("TODO: Calibration\n");
4495 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004496 }
4497
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004498 IPW_ERROR
4499 ("Calibration of wrong size %d (should be %zd)\n",
4500 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004501 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004502 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004503
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004504 case HOST_NOTIFICATION_NOISE_STATS:{
4505 if (notif->size == sizeof(u32)) {
4506 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004507 (u8) (le32_to_cpu(notif->u.noise.value) &
4508 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004509 average_add(&priv->average_noise,
4510 priv->last_noise);
4511 break;
4512 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004513
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004514 IPW_ERROR
4515 ("Noise stat is wrong size %d (should be %zd)\n",
4516 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004517 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004518 }
4519
James Ketrenos43f66a62005-03-25 12:31:53 -06004520 default:
4521 IPW_ERROR("Unknown notification: "
4522 "subtype=%d,flags=0x%2x,size=%d\n",
4523 notif->subtype, notif->flags, notif->size);
4524 }
4525}
4526
4527/**
4528 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004529 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004530 * @param priv
4531 * @return error code
4532 */
4533static int ipw_queue_reset(struct ipw_priv *priv)
4534{
4535 int rc = 0;
4536 /** @todo customize queue sizes */
4537 int nTx = 64, nTxCmd = 8;
4538 ipw_tx_queue_free(priv);
4539 /* Tx CMD queue */
4540 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004541 IPW_TX_CMD_QUEUE_READ_INDEX,
4542 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4543 IPW_TX_CMD_QUEUE_BD_BASE,
4544 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004545 if (rc) {
4546 IPW_ERROR("Tx Cmd queue init failed\n");
4547 goto error;
4548 }
4549 /* Tx queue(s) */
4550 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004551 IPW_TX_QUEUE_0_READ_INDEX,
4552 IPW_TX_QUEUE_0_WRITE_INDEX,
4553 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004554 if (rc) {
4555 IPW_ERROR("Tx 0 queue init failed\n");
4556 goto error;
4557 }
4558 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004559 IPW_TX_QUEUE_1_READ_INDEX,
4560 IPW_TX_QUEUE_1_WRITE_INDEX,
4561 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004562 if (rc) {
4563 IPW_ERROR("Tx 1 queue init failed\n");
4564 goto error;
4565 }
4566 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004567 IPW_TX_QUEUE_2_READ_INDEX,
4568 IPW_TX_QUEUE_2_WRITE_INDEX,
4569 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004570 if (rc) {
4571 IPW_ERROR("Tx 2 queue init failed\n");
4572 goto error;
4573 }
4574 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004575 IPW_TX_QUEUE_3_READ_INDEX,
4576 IPW_TX_QUEUE_3_WRITE_INDEX,
4577 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004578 if (rc) {
4579 IPW_ERROR("Tx 3 queue init failed\n");
4580 goto error;
4581 }
4582 /* statistics */
4583 priv->rx_bufs_min = 0;
4584 priv->rx_pend_max = 0;
4585 return rc;
4586
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004587 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004588 ipw_tx_queue_free(priv);
4589 return rc;
4590}
4591
4592/**
4593 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004594 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004595 * When FW adwances 'R' index, all entries between old and
4596 * new 'R' index need to be reclaimed. As result, some free space
4597 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004598 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004599 * @note Need to protect against garbage in 'R' index
4600 * @param priv
4601 * @param txq
4602 * @param qindex
4603 * @return Number of used entries remains in the queue
4604 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004605static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004606 struct clx2_tx_queue *txq, int qindex)
4607{
4608 u32 hw_tail;
4609 int used;
4610 struct clx2_queue *q = &txq->q;
4611
4612 hw_tail = ipw_read32(priv, q->reg_r);
4613 if (hw_tail >= q->n_bd) {
4614 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004615 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4616 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004617 goto done;
4618 }
4619 for (; q->last_used != hw_tail;
4620 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4621 ipw_queue_tx_free_tfd(priv, txq);
4622 priv->tx_packets++;
4623 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004624 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004625 if ((ipw_queue_space(q) > q->low_mark) &&
4626 (qindex >= 0) &&
4627 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4628 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004629 used = q->first_empty - q->last_used;
4630 if (used < 0)
4631 used += q->n_bd;
4632
4633 return used;
4634}
4635
4636static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4637 int len, int sync)
4638{
4639 struct clx2_tx_queue *txq = &priv->txq_cmd;
4640 struct clx2_queue *q = &txq->q;
4641 struct tfd_frame *tfd;
4642
4643 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4644 IPW_ERROR("No space for Tx\n");
4645 return -EBUSY;
4646 }
4647
4648 tfd = &txq->bd[q->first_empty];
4649 txq->txb[q->first_empty] = NULL;
4650
4651 memset(tfd, 0, sizeof(*tfd));
4652 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4653 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4654 priv->hcmd_seq++;
4655 tfd->u.cmd.index = hcmd;
4656 tfd->u.cmd.length = len;
4657 memcpy(tfd->u.cmd.payload, buf, len);
4658 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4659 ipw_write32(priv, q->reg_w, q->first_empty);
4660 _ipw_read32(priv, 0x90);
4661
4662 return 0;
4663}
4664
Jeff Garzikbf794512005-07-31 13:07:26 -04004665/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004666 * Rx theory of operation
4667 *
4668 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004669 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004670 * 0 to 31
4671 *
4672 * Rx Queue Indexes
4673 * The host/firmware share two index registers for managing the Rx buffers.
4674 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004675 * The READ index maps to the first position that the firmware may be writing
4676 * to -- the driver can read up to (but not including) this position and get
4677 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004678 * The READ index is managed by the firmware once the card is enabled.
4679 *
4680 * The WRITE index maps to the last position the driver has read from -- the
4681 * position preceding WRITE is the last slot the firmware can place a packet.
4682 *
4683 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004684 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004685 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004686 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004687 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4688 *
4689 * When the firmware places a packet in a buffer it will advance the READ index
4690 * and fire the RX interrupt. The driver can then query the READ index and
4691 * process as many packets as possible, moving the WRITE index forward as it
4692 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004693 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004694 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004695 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004696 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004697 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004698 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4699 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4700 * 'processed' and 'read' driver indexes as well)
4701 * + A received packet is processed and handed to the kernel network stack,
4702 * detached from the ipw->rxq. The driver 'processed' index is updated.
4703 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004704 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4705 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004706 * were enough free buffers and RX_STALLED is set it is cleared.
4707 *
4708 *
4709 * Driver sequence:
4710 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004711 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004712 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4713 * ipw_rx_queue_restock
4714 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4715 * queue, updates firmware pointers, and updates
4716 * the WRITE index. If insufficient rx_free buffers
4717 * are available, schedules ipw_rx_queue_replenish
4718 *
4719 * -- enable interrupts --
4720 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004721 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004722 * Moves the packet buffer from queue to rx_used.
4723 * Calls ipw_rx_queue_restock to refill any empty
4724 * slots.
4725 * ...
4726 *
4727 */
4728
Jeff Garzikbf794512005-07-31 13:07:26 -04004729/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004730 * If there are slots in the RX queue that need to be restocked,
4731 * and we have free pre-allocated buffers, fill the ranks as much
4732 * as we can pulling from rx_free.
4733 *
4734 * This moves the 'write' index forward to catch up with 'processed', and
4735 * also updates the memory address in the firmware to reference the new
4736 * target buffer.
4737 */
4738static void ipw_rx_queue_restock(struct ipw_priv *priv)
4739{
4740 struct ipw_rx_queue *rxq = priv->rxq;
4741 struct list_head *element;
4742 struct ipw_rx_mem_buffer *rxb;
4743 unsigned long flags;
4744 int write;
4745
4746 spin_lock_irqsave(&rxq->lock, flags);
4747 write = rxq->write;
4748 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4749 element = rxq->rx_free.next;
4750 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4751 list_del(element);
4752
James Ketrenosb095c382005-08-24 22:04:42 -05004753 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004754 rxb->dma_addr);
4755 rxq->queue[rxq->write] = rxb;
4756 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4757 rxq->free_count--;
4758 }
4759 spin_unlock_irqrestore(&rxq->lock, flags);
4760
Jeff Garzikbf794512005-07-31 13:07:26 -04004761 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004762 * refill it */
4763 if (rxq->free_count <= RX_LOW_WATERMARK)
4764 queue_work(priv->workqueue, &priv->rx_replenish);
4765
4766 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004767 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004768 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004769}
4770
4771/*
4772 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004773 * Also restock the Rx queue via ipw_rx_queue_restock.
4774 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004775 * This is called as a scheduled work item (except for during intialization)
4776 */
4777static void ipw_rx_queue_replenish(void *data)
4778{
4779 struct ipw_priv *priv = data;
4780 struct ipw_rx_queue *rxq = priv->rxq;
4781 struct list_head *element;
4782 struct ipw_rx_mem_buffer *rxb;
4783 unsigned long flags;
4784
4785 spin_lock_irqsave(&rxq->lock, flags);
4786 while (!list_empty(&rxq->rx_used)) {
4787 element = rxq->rx_used.next;
4788 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004789 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004790 if (!rxb->skb) {
4791 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4792 priv->net_dev->name);
4793 /* We don't reschedule replenish work here -- we will
4794 * call the restock method and if it still needs
4795 * more buffers it will schedule replenish */
4796 break;
4797 }
4798 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004799
James Ketrenos43f66a62005-03-25 12:31:53 -06004800 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004801 rxb->dma_addr =
4802 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004803 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004804
James Ketrenos43f66a62005-03-25 12:31:53 -06004805 list_add_tail(&rxb->list, &rxq->rx_free);
4806 rxq->free_count++;
4807 }
4808 spin_unlock_irqrestore(&rxq->lock, flags);
4809
4810 ipw_rx_queue_restock(priv);
4811}
4812
James Ketrenosc848d0a2005-08-24 21:56:24 -05004813static void ipw_bg_rx_queue_replenish(void *data)
4814{
4815 struct ipw_priv *priv = data;
4816 down(&priv->sem);
4817 ipw_rx_queue_replenish(data);
4818 up(&priv->sem);
4819}
4820
James Ketrenos43f66a62005-03-25 12:31:53 -06004821/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4822 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004823 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 * non NULL it is unmapped and freed
4825 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004826static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004827{
4828 int i;
4829
4830 if (!rxq)
4831 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004832
James Ketrenos43f66a62005-03-25 12:31:53 -06004833 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4834 if (rxq->pool[i].skb != NULL) {
4835 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004836 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004837 dev_kfree_skb(rxq->pool[i].skb);
4838 }
4839 }
4840
4841 kfree(rxq);
4842}
4843
4844static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4845{
4846 struct ipw_rx_queue *rxq;
4847 int i;
4848
4849 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004850 if (unlikely(!rxq)) {
4851 IPW_ERROR("memory allocation failed\n");
4852 return NULL;
4853 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004854 memset(rxq, 0, sizeof(*rxq));
4855 spin_lock_init(&rxq->lock);
4856 INIT_LIST_HEAD(&rxq->rx_free);
4857 INIT_LIST_HEAD(&rxq->rx_used);
4858
4859 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004860 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004861 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4862
4863 /* Set us so that we have processed and used all buffers, but have
4864 * not restocked the Rx queue with fresh buffers */
4865 rxq->read = rxq->write = 0;
4866 rxq->processed = RX_QUEUE_SIZE - 1;
4867 rxq->free_count = 0;
4868
4869 return rxq;
4870}
4871
4872static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4873{
4874 rate &= ~IEEE80211_BASIC_RATE_MASK;
4875 if (ieee_mode == IEEE_A) {
4876 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004877 case IEEE80211_OFDM_RATE_6MB:
4878 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004879 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004880 case IEEE80211_OFDM_RATE_9MB:
4881 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004882 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004883 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004884 return priv->
4885 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004886 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004887 return priv->
4888 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004889 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004890 return priv->
4891 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004892 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004893 return priv->
4894 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004895 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004896 return priv->
4897 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004898 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004899 return priv->
4900 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004901 default:
4902 return 0;
4903 }
4904 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004905
James Ketrenos43f66a62005-03-25 12:31:53 -06004906 /* B and G mixed */
4907 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004908 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004909 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004910 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004911 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004912 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004913 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004914 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004915 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4916 }
4917
4918 /* If we are limited to B modulations, bail at this point */
4919 if (ieee_mode == IEEE_B)
4920 return 0;
4921
4922 /* G */
4923 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004924 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004925 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004926 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004927 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004928 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004929 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004930 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004931 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004932 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004933 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004934 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004935 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004936 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004937 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004938 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004939 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4940 }
4941
4942 return 0;
4943}
4944
Jeff Garzikbf794512005-07-31 13:07:26 -04004945static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004946 const struct ieee80211_network *network,
4947 struct ipw_supported_rates *rates)
4948{
4949 int num_rates, i;
4950
4951 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004952 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004953 rates->num_rates = 0;
4954 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004955 if (!ipw_is_rate_in_mask(priv, network->mode,
4956 network->rates[i])) {
4957
James Ketrenosea2b26e2005-08-24 21:25:16 -05004958 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004959 IPW_DEBUG_SCAN("Adding masked mandatory "
4960 "rate %02X\n",
4961 network->rates[i]);
4962 rates->supported_rates[rates->num_rates++] =
4963 network->rates[i];
4964 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004965 }
4966
James Ketrenos43f66a62005-03-25 12:31:53 -06004967 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4968 network->rates[i], priv->rates_mask);
4969 continue;
4970 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004971
James Ketrenos43f66a62005-03-25 12:31:53 -06004972 rates->supported_rates[rates->num_rates++] = network->rates[i];
4973 }
4974
James Ketrenosa613bff2005-08-24 21:43:11 -05004975 num_rates = min(network->rates_ex_len,
4976 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004977 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004978 if (!ipw_is_rate_in_mask(priv, network->mode,
4979 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004980 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004981 IPW_DEBUG_SCAN("Adding masked mandatory "
4982 "rate %02X\n",
4983 network->rates_ex[i]);
4984 rates->supported_rates[rates->num_rates++] =
4985 network->rates[i];
4986 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004987 }
4988
James Ketrenos43f66a62005-03-25 12:31:53 -06004989 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4990 network->rates_ex[i], priv->rates_mask);
4991 continue;
4992 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004993
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004994 rates->supported_rates[rates->num_rates++] =
4995 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004996 }
4997
James Ketrenosea2b26e2005-08-24 21:25:16 -05004998 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004999}
5000
5001static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
5002 const struct ipw_supported_rates *src)
5003{
5004 u8 i;
5005 for (i = 0; i < src->num_rates; i++)
5006 dest->supported_rates[i] = src->supported_rates[i];
5007 dest->num_rates = src->num_rates;
5008}
5009
5010/* TODO: Look at sniffed packets in the air to determine if the basic rate
5011 * mask should ever be used -- right now all callers to add the scan rates are
5012 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5013static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005014 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005015{
Jeff Garzikbf794512005-07-31 13:07:26 -04005016 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005017 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005018
James Ketrenos43f66a62005-03-25 12:31:53 -06005019 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005020 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005021 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005022
5023 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005024 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005025 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005026
5027 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005028 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005029 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005030
5031 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005032 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005033 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005034}
5035
5036static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005037 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005038{
Jeff Garzikbf794512005-07-31 13:07:26 -04005039 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005040 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005041
5042 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005043 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005044 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005045
5046 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005047 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005048 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005049
5050 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005051 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005052 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005053
5054 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005055 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005056 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005057
5058 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005059 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005060 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005061
5062 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005063 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005064 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005065
5066 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005067 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005068 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005069
5070 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005071 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005072 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005073}
5074
5075struct ipw_network_match {
5076 struct ieee80211_network *network;
5077 struct ipw_supported_rates rates;
5078};
5079
James Ketrenosc848d0a2005-08-24 21:56:24 -05005080static int ipw_find_adhoc_network(struct ipw_priv *priv,
5081 struct ipw_network_match *match,
5082 struct ieee80211_network *network,
5083 int roaming)
5084{
5085 struct ipw_supported_rates rates;
5086
5087 /* Verify that this network's capability is compatible with the
5088 * current mode (AdHoc or Infrastructure) */
5089 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5090 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5091 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5092 "capability mismatch.\n",
5093 escape_essid(network->ssid, network->ssid_len),
5094 MAC_ARG(network->bssid));
5095 return 0;
5096 }
5097
5098 /* If we do not have an ESSID for this AP, we can not associate with
5099 * it */
5100 if (network->flags & NETWORK_EMPTY_ESSID) {
5101 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5102 "because of hidden ESSID.\n",
5103 escape_essid(network->ssid, network->ssid_len),
5104 MAC_ARG(network->bssid));
5105 return 0;
5106 }
5107
5108 if (unlikely(roaming)) {
5109 /* If we are roaming, then ensure check if this is a valid
5110 * network to try and roam to */
5111 if ((network->ssid_len != match->network->ssid_len) ||
5112 memcmp(network->ssid, match->network->ssid,
5113 network->ssid_len)) {
5114 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5115 "because of non-network ESSID.\n",
5116 escape_essid(network->ssid,
5117 network->ssid_len),
5118 MAC_ARG(network->bssid));
5119 return 0;
5120 }
5121 } else {
5122 /* If an ESSID has been configured then compare the broadcast
5123 * ESSID to ours */
5124 if ((priv->config & CFG_STATIC_ESSID) &&
5125 ((network->ssid_len != priv->essid_len) ||
5126 memcmp(network->ssid, priv->essid,
5127 min(network->ssid_len, priv->essid_len)))) {
5128 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005129
James Ketrenosc848d0a2005-08-24 21:56:24 -05005130 strncpy(escaped,
5131 escape_essid(network->ssid, network->ssid_len),
5132 sizeof(escaped));
5133 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5134 "because of ESSID mismatch: '%s'.\n",
5135 escaped, MAC_ARG(network->bssid),
5136 escape_essid(priv->essid,
5137 priv->essid_len));
5138 return 0;
5139 }
5140 }
5141
5142 /* If the old network rate is better than this one, don't bother
5143 * testing everything else. */
5144
5145 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005146 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5147 "current network.\n",
5148 escape_essid(match->network->ssid,
5149 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005150 return 0;
5151 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005152 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5153 "current network.\n",
5154 escape_essid(match->network->ssid,
5155 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005156 return 0;
5157 }
5158
5159 /* Now go through and see if the requested network is valid... */
5160 if (priv->ieee->scan_age != 0 &&
5161 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5162 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5163 "because of age: %lums.\n",
5164 escape_essid(network->ssid, network->ssid_len),
5165 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005166 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005167 return 0;
5168 }
5169
5170 if ((priv->config & CFG_STATIC_CHANNEL) &&
5171 (network->channel != priv->channel)) {
5172 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5173 "because of channel mismatch: %d != %d.\n",
5174 escape_essid(network->ssid, network->ssid_len),
5175 MAC_ARG(network->bssid),
5176 network->channel, priv->channel);
5177 return 0;
5178 }
5179
5180 /* Verify privacy compatability */
5181 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5182 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5183 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5184 "because of privacy mismatch: %s != %s.\n",
5185 escape_essid(network->ssid, network->ssid_len),
5186 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005187 priv->
5188 capability & CAP_PRIVACY_ON ? "on" : "off",
5189 network->
5190 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5191 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005192 return 0;
5193 }
5194
5195 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5196 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5197 "because of the same BSSID match: " MAC_FMT
5198 ".\n", escape_essid(network->ssid,
5199 network->ssid_len),
5200 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5201 return 0;
5202 }
5203
5204 /* Filter out any incompatible freq / mode combinations */
5205 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5206 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5207 "because of invalid frequency/mode "
5208 "combination.\n",
5209 escape_essid(network->ssid, network->ssid_len),
5210 MAC_ARG(network->bssid));
5211 return 0;
5212 }
5213
5214 /* Ensure that the rates supported by the driver are compatible with
5215 * this AP, including verification of basic rates (mandatory) */
5216 if (!ipw_compatible_rates(priv, network, &rates)) {
5217 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5218 "because configured rate mask excludes "
5219 "AP mandatory rate.\n",
5220 escape_essid(network->ssid, network->ssid_len),
5221 MAC_ARG(network->bssid));
5222 return 0;
5223 }
5224
5225 if (rates.num_rates == 0) {
5226 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5227 "because of no compatible rates.\n",
5228 escape_essid(network->ssid, network->ssid_len),
5229 MAC_ARG(network->bssid));
5230 return 0;
5231 }
5232
5233 /* TODO: Perform any further minimal comparititive tests. We do not
5234 * want to put too much policy logic here; intelligent scan selection
5235 * should occur within a generic IEEE 802.11 user space tool. */
5236
5237 /* Set up 'new' AP to this network */
5238 ipw_copy_rates(&match->rates, &rates);
5239 match->network = network;
5240 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5241 escape_essid(network->ssid, network->ssid_len),
5242 MAC_ARG(network->bssid));
5243
5244 return 1;
5245}
5246
5247static void ipw_merge_adhoc_network(void *data)
5248{
5249 struct ipw_priv *priv = data;
5250 struct ieee80211_network *network = NULL;
5251 struct ipw_network_match match = {
5252 .network = priv->assoc_network
5253 };
5254
James Ketrenosafbf30a2005-08-25 00:05:33 -05005255 if ((priv->status & STATUS_ASSOCIATED) &&
5256 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005257 /* First pass through ROAM process -- look for a better
5258 * network */
5259 unsigned long flags;
5260
5261 spin_lock_irqsave(&priv->ieee->lock, flags);
5262 list_for_each_entry(network, &priv->ieee->network_list, list) {
5263 if (network != priv->assoc_network)
5264 ipw_find_adhoc_network(priv, &match, network,
5265 1);
5266 }
5267 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5268
5269 if (match.network == priv->assoc_network) {
5270 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5271 "merge to.\n");
5272 return;
5273 }
5274
5275 down(&priv->sem);
5276 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5277 IPW_DEBUG_MERGE("remove network %s\n",
5278 escape_essid(priv->essid,
5279 priv->essid_len));
5280 ipw_remove_current_network(priv);
5281 }
5282
5283 ipw_disassociate(priv);
5284 priv->assoc_network = match.network;
5285 up(&priv->sem);
5286 return;
5287 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005288}
5289
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290static int ipw_best_network(struct ipw_priv *priv,
5291 struct ipw_network_match *match,
5292 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005293{
5294 struct ipw_supported_rates rates;
5295
5296 /* Verify that this network's capability is compatible with the
5297 * current mode (AdHoc or Infrastructure) */
5298 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005299 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005300 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5301 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5302 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005303 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005304 escape_essid(network->ssid, network->ssid_len),
5305 MAC_ARG(network->bssid));
5306 return 0;
5307 }
5308
5309 /* If we do not have an ESSID for this AP, we can not associate with
5310 * it */
5311 if (network->flags & NETWORK_EMPTY_ESSID) {
5312 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5313 "because of hidden ESSID.\n",
5314 escape_essid(network->ssid, network->ssid_len),
5315 MAC_ARG(network->bssid));
5316 return 0;
5317 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005318
James Ketrenos43f66a62005-03-25 12:31:53 -06005319 if (unlikely(roaming)) {
5320 /* If we are roaming, then ensure check if this is a valid
5321 * network to try and roam to */
5322 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005323 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005324 network->ssid_len)) {
5325 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5326 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005327 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005328 network->ssid_len),
5329 MAC_ARG(network->bssid));
5330 return 0;
5331 }
5332 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005333 /* If an ESSID has been configured then compare the broadcast
5334 * ESSID to ours */
5335 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005336 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005337 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005338 min(network->ssid_len, priv->essid_len)))) {
5339 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005340 strncpy(escaped,
5341 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005342 sizeof(escaped));
5343 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005344 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005345 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005346 escape_essid(priv->essid,
5347 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005348 return 0;
5349 }
5350 }
5351
5352 /* If the old network rate is better than this one, don't bother
5353 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005354 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005355 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005356 strncpy(escaped,
5357 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005358 sizeof(escaped));
5359 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5360 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5361 escaped, MAC_ARG(network->bssid),
5362 escape_essid(match->network->ssid,
5363 match->network->ssid_len),
5364 MAC_ARG(match->network->bssid));
5365 return 0;
5366 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005367
James Ketrenos43f66a62005-03-25 12:31:53 -06005368 /* If this network has already had an association attempt within the
5369 * last 3 seconds, do not try and associate again... */
5370 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005371 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005372 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
James Ketrenosafbf30a2005-08-25 00:05:33 -05005373 "because of storming (%lus since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005374 "assoc attempt).\n",
5375 escape_essid(network->ssid, network->ssid_len),
5376 MAC_ARG(network->bssid),
5377 (jiffies - network->last_associate) / HZ);
5378 return 0;
5379 }
5380
5381 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005382 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005383 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005384 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5385 "because of age: %lums.\n",
5386 escape_essid(network->ssid, network->ssid_len),
5387 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005388 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06005389 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005390 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005391
Jeff Garzikbf794512005-07-31 13:07:26 -04005392 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005393 (network->channel != priv->channel)) {
5394 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5395 "because of channel mismatch: %d != %d.\n",
5396 escape_essid(network->ssid, network->ssid_len),
5397 MAC_ARG(network->bssid),
5398 network->channel, priv->channel);
5399 return 0;
5400 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005401
James Ketrenos43f66a62005-03-25 12:31:53 -06005402 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005403 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005404 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5405 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5406 "because of privacy mismatch: %s != %s.\n",
5407 escape_essid(network->ssid, network->ssid_len),
5408 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005409 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005410 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005411 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005412 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005413 return 0;
5414 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005415
5416 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005417 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5418 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5419 "because of BSSID mismatch: " MAC_FMT ".\n",
5420 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005421 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005422 return 0;
5423 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005424
James Ketrenos43f66a62005-03-25 12:31:53 -06005425 /* Filter out any incompatible freq / mode combinations */
5426 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5427 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5428 "because of invalid frequency/mode "
5429 "combination.\n",
5430 escape_essid(network->ssid, network->ssid_len),
5431 MAC_ARG(network->bssid));
5432 return 0;
5433 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005434
James Ketrenosea2b26e2005-08-24 21:25:16 -05005435 /* Ensure that the rates supported by the driver are compatible with
5436 * this AP, including verification of basic rates (mandatory) */
5437 if (!ipw_compatible_rates(priv, network, &rates)) {
5438 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5439 "because configured rate mask excludes "
5440 "AP mandatory rate.\n",
5441 escape_essid(network->ssid, network->ssid_len),
5442 MAC_ARG(network->bssid));
5443 return 0;
5444 }
5445
James Ketrenos43f66a62005-03-25 12:31:53 -06005446 if (rates.num_rates == 0) {
5447 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5448 "because of no compatible rates.\n",
5449 escape_essid(network->ssid, network->ssid_len),
5450 MAC_ARG(network->bssid));
5451 return 0;
5452 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005453
James Ketrenos43f66a62005-03-25 12:31:53 -06005454 /* TODO: Perform any further minimal comparititive tests. We do not
5455 * want to put too much policy logic here; intelligent scan selection
5456 * should occur within a generic IEEE 802.11 user space tool. */
5457
5458 /* Set up 'new' AP to this network */
5459 ipw_copy_rates(&match->rates, &rates);
5460 match->network = network;
5461
5462 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5463 escape_essid(network->ssid, network->ssid_len),
5464 MAC_ARG(network->bssid));
5465
5466 return 1;
5467}
5468
Jeff Garzikbf794512005-07-31 13:07:26 -04005469static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005470 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005471{
James Ketrenosafbf30a2005-08-25 00:05:33 -05005472 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5473 int i;
5474
James Ketrenos43f66a62005-03-25 12:31:53 -06005475 /*
5476 * For the purposes of scanning, we can set our wireless mode
5477 * to trigger scans across combinations of bands, but when it
5478 * comes to creating a new ad-hoc network, we have tell the FW
5479 * exactly which band to use.
5480 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005481 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005482 * chossen band. Attempting to create a new ad-hoc network
5483 * with an invalid channel for wireless mode will trigger a
5484 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005485 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 */
James Ketrenosafbf30a2005-08-25 00:05:33 -05005487 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5488 case IEEE80211_52GHZ_BAND:
5489 network->mode = IEEE_A;
5490 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5491 if (i == -1)
5492 BUG();
5493 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5494 IPW_WARNING("Overriding invalid channel\n");
5495 priv->channel = geo->a[0].channel;
5496 }
5497 break;
5498
5499 case IEEE80211_24GHZ_BAND:
5500 if (priv->ieee->mode & IEEE_G)
5501 network->mode = IEEE_G;
5502 else
5503 network->mode = IEEE_B;
5504 break;
5505
5506 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005507 IPW_WARNING("Overriding invalid channel\n");
5508 if (priv->ieee->mode & IEEE_A) {
5509 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005510 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005511 } else if (priv->ieee->mode & IEEE_G) {
5512 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005513 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005514 } else {
5515 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005516 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005517 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005518 break;
5519 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005520
5521 network->channel = priv->channel;
5522 priv->config |= CFG_ADHOC_PERSIST;
5523 ipw_create_bssid(priv, network->bssid);
5524 network->ssid_len = priv->essid_len;
5525 memcpy(network->ssid, priv->essid, priv->essid_len);
5526 memset(&network->stats, 0, sizeof(network->stats));
5527 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005528 if (!(priv->config & CFG_PREAMBLE_LONG))
5529 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 if (priv->capability & CAP_PRIVACY_ON)
5531 network->capability |= WLAN_CAPABILITY_PRIVACY;
5532 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005533 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005534 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005535 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005536 &priv->rates.supported_rates[network->rates_len],
5537 network->rates_ex_len);
5538 network->last_scanned = 0;
5539 network->flags = 0;
5540 network->last_associate = 0;
5541 network->time_stamp[0] = 0;
5542 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005543 network->beacon_interval = 100; /* Default */
5544 network->listen_interval = 10; /* Default */
5545 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005546 network->wpa_ie_len = 0;
5547 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005548}
5549
James Ketrenosb095c382005-08-24 22:04:42 -05005550static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5551{
5552 struct ipw_tgi_tx_key *key;
5553 struct host_cmd cmd = {
5554 .cmd = IPW_CMD_TGI_TX_KEY,
5555 .len = sizeof(*key)
5556 };
5557
5558 if (!(priv->ieee->sec.flags & (1 << index)))
5559 return;
5560
5561 key = (struct ipw_tgi_tx_key *)&cmd.param;
5562 key->key_id = index;
5563 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5564 key->security_type = type;
5565 key->station_index = 0; /* always 0 for BSS */
5566 key->flags = 0;
5567 /* 0 for new key; previous value of counter (after fatal error) */
5568 key->tx_counter[0] = 0;
5569 key->tx_counter[1] = 0;
5570
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005571 ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05005572}
5573
5574static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005575{
5576 struct ipw_wep_key *key;
5577 int i;
5578 struct host_cmd cmd = {
5579 .cmd = IPW_CMD_WEP_KEY,
5580 .len = sizeof(*key)
5581 };
5582
5583 key = (struct ipw_wep_key *)&cmd.param;
5584 key->cmd_id = DINO_CMD_WEP_KEY;
5585 key->seq_num = 0;
5586
James Ketrenosb095c382005-08-24 22:04:42 -05005587 /* Note: AES keys cannot be set for multiple times.
5588 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005589 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005590 key->key_index = i | type;
5591 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005592 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005593 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005594 }
5595
James Ketrenosb095c382005-08-24 22:04:42 -05005596 key->key_size = priv->ieee->sec.key_sizes[i];
5597 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5598
James Ketrenos9ddf84f2005-08-16 17:07:11 -05005599 ipw_send_cmd(priv, &cmd);
Jeff Garzikbf794512005-07-31 13:07:26 -04005600 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005601}
5602
Zhu Yi1fbfea52005-08-05 17:22:56 +08005603static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5604{
5605 if (priv->ieee->host_encrypt)
5606 return;
5607
5608 switch (level) {
5609 case SEC_LEVEL_3:
5610 priv->sys_config.disable_unicast_decryption = 0;
5611 priv->ieee->host_decrypt = 0;
5612 break;
5613 case SEC_LEVEL_2:
5614 priv->sys_config.disable_unicast_decryption = 1;
5615 priv->ieee->host_decrypt = 1;
5616 break;
5617 case SEC_LEVEL_1:
5618 priv->sys_config.disable_unicast_decryption = 0;
5619 priv->ieee->host_decrypt = 0;
5620 break;
5621 case SEC_LEVEL_0:
5622 priv->sys_config.disable_unicast_decryption = 1;
5623 break;
5624 default:
5625 break;
5626 }
5627}
5628
5629static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5630{
5631 if (priv->ieee->host_encrypt)
5632 return;
5633
5634 switch (level) {
5635 case SEC_LEVEL_3:
5636 priv->sys_config.disable_multicast_decryption = 0;
5637 break;
5638 case SEC_LEVEL_2:
5639 priv->sys_config.disable_multicast_decryption = 1;
5640 break;
5641 case SEC_LEVEL_1:
5642 priv->sys_config.disable_multicast_decryption = 0;
5643 break;
5644 case SEC_LEVEL_0:
5645 priv->sys_config.disable_multicast_decryption = 1;
5646 break;
5647 default:
5648 break;
5649 }
5650}
5651
James Ketrenosb095c382005-08-24 22:04:42 -05005652static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5653{
5654 switch (priv->ieee->sec.level) {
5655 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005656 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5657 ipw_send_tgi_tx_key(priv,
5658 DCT_FLAG_EXT_SECURITY_CCM,
5659 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005660
James Ketrenosb095c382005-08-24 22:04:42 -05005661 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005662 break;
5663 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005664 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5665 ipw_send_tgi_tx_key(priv,
5666 DCT_FLAG_EXT_SECURITY_TKIP,
5667 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005668 break;
5669 case SEC_LEVEL_1:
5670 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenosb095c382005-08-24 22:04:42 -05005671 break;
5672 case SEC_LEVEL_0:
5673 default:
5674 break;
5675 }
Zhu Yi1fbfea52005-08-05 17:22:56 +08005676
5677 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5678 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005679}
5680
James Ketrenos43f66a62005-03-25 12:31:53 -06005681static void ipw_adhoc_check(void *data)
5682{
5683 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005684
James Ketrenosafbf30a2005-08-25 00:05:33 -05005685 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005686 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005687 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5688 IPW_DL_STATE | IPW_DL_ASSOC,
5689 "Missed beacon: %d - disassociate\n",
5690 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005691 ipw_remove_current_network(priv);
5692 ipw_disassociate(priv);
5693 return;
5694 }
5695
Jeff Garzikbf794512005-07-31 13:07:26 -04005696 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005697 priv->assoc_request.beacon_interval);
5698}
5699
James Ketrenosc848d0a2005-08-24 21:56:24 -05005700static void ipw_bg_adhoc_check(void *data)
5701{
5702 struct ipw_priv *priv = data;
5703 down(&priv->sem);
5704 ipw_adhoc_check(data);
5705 up(&priv->sem);
5706}
5707
James Ketrenos43f66a62005-03-25 12:31:53 -06005708#ifdef CONFIG_IPW_DEBUG
5709static void ipw_debug_config(struct ipw_priv *priv)
5710{
5711 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5712 "[CFG 0x%08X]\n", priv->config);
5713 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005714 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005715 else
5716 IPW_DEBUG_INFO("Channel unlocked.\n");
5717 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005718 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005719 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005720 else
5721 IPW_DEBUG_INFO("ESSID unlocked.\n");
5722 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005723 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5724 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005725 else
5726 IPW_DEBUG_INFO("BSSID unlocked.\n");
5727 if (priv->capability & CAP_PRIVACY_ON)
5728 IPW_DEBUG_INFO("PRIVACY on\n");
5729 else
5730 IPW_DEBUG_INFO("PRIVACY off\n");
5731 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5732}
5733#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005734#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005735#endif
5736
James Ketrenosb095c382005-08-24 22:04:42 -05005737static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005738{
5739 /* TODO: Verify that this works... */
5740 struct ipw_fixed_rate fr = {
5741 .tx_rates = priv->rates_mask
5742 };
5743 u32 reg;
5744 u16 mask = 0;
5745
Jeff Garzikbf794512005-07-31 13:07:26 -04005746 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005748
James Ketrenos43f66a62005-03-25 12:31:53 -06005749 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005750 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005751 /* IEEE_A */
5752 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5753 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005754 IPW_DEBUG_WX
5755 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005756 fr.tx_rates = 0;
5757 break;
5758 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005759
James Ketrenos43f66a62005-03-25 12:31:53 -06005760 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5761 break;
5762
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005763 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005764 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005765 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005766 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5767 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005768 IPW_DEBUG_WX
5769 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005770 fr.tx_rates = 0;
5771 }
5772 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005773 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005774
5775 /* IEEE_G */
5776 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5777 IEEE80211_OFDM_RATES_MASK)) {
5778 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005779 IPW_DEBUG_WX
5780 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005781 fr.tx_rates = 0;
5782 break;
5783 }
5784
5785 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5786 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5787 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5788 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005789
James Ketrenos43f66a62005-03-25 12:31:53 -06005790 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5791 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5792 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5793 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005794
James Ketrenos43f66a62005-03-25 12:31:53 -06005795 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5796 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5797 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5798 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005799
James Ketrenos43f66a62005-03-25 12:31:53 -06005800 fr.tx_rates |= mask;
5801 break;
5802 }
5803
5804 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005805 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005806}
5807
James Ketrenosea2b26e2005-08-24 21:25:16 -05005808static void ipw_abort_scan(struct ipw_priv *priv)
5809{
5810 int err;
5811
5812 if (priv->status & STATUS_SCAN_ABORTING) {
5813 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5814 return;
5815 }
5816 priv->status |= STATUS_SCAN_ABORTING;
5817
5818 err = ipw_send_scan_abort(priv);
5819 if (err)
5820 IPW_DEBUG_HC("Request to abort scan failed.\n");
5821}
5822
James Ketrenosafbf30a2005-08-25 00:05:33 -05005823static void ipw_add_scan_channels(struct ipw_priv *priv,
5824 struct ipw_scan_request_ext *scan,
5825 int scan_type)
5826{
5827 int channel_index = 0;
5828 const struct ieee80211_geo *geo;
5829 int i;
5830
5831 geo = ieee80211_get_geo(priv->ieee);
5832
5833 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5834 int start = channel_index;
5835 for (i = 0; i < geo->a_channels; i++) {
5836 if ((priv->status & STATUS_ASSOCIATED) &&
5837 geo->a[i].channel == priv->channel)
5838 continue;
5839 channel_index++;
5840 scan->channels_list[channel_index] = geo->a[i].channel;
5841 ipw_set_scan_type(scan, channel_index, scan_type);
5842 }
5843
5844 if (start != channel_index) {
5845 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5846 (channel_index - start);
5847 channel_index++;
5848 }
5849 }
5850
5851 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5852 int start = channel_index;
5853 if (priv->config & CFG_SPEED_SCAN) {
5854 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5855 /* nop out the list */
5856 [0] = 0
5857 };
5858
5859 u8 channel;
5860 while (channel_index < IPW_SCAN_CHANNELS) {
5861 channel =
5862 priv->speed_scan[priv->speed_scan_pos];
5863 if (channel == 0) {
5864 priv->speed_scan_pos = 0;
5865 channel = priv->speed_scan[0];
5866 }
5867 if ((priv->status & STATUS_ASSOCIATED) &&
5868 channel == priv->channel) {
5869 priv->speed_scan_pos++;
5870 continue;
5871 }
5872
5873 /* If this channel has already been
5874 * added in scan, break from loop
5875 * and this will be the first channel
5876 * in the next scan.
5877 */
5878 if (channels[channel - 1] != 0)
5879 break;
5880
5881 channels[channel - 1] = 1;
5882 priv->speed_scan_pos++;
5883 channel_index++;
5884 scan->channels_list[channel_index] = channel;
5885 ipw_set_scan_type(scan, channel_index,
5886 scan_type);
5887 }
5888 } else {
5889 for (i = 0; i < geo->bg_channels; i++) {
5890 if ((priv->status & STATUS_ASSOCIATED) &&
5891 geo->bg[i].channel == priv->channel)
5892 continue;
5893 channel_index++;
5894 scan->channels_list[channel_index] =
5895 geo->bg[i].channel;
5896 ipw_set_scan_type(scan, channel_index,
5897 scan_type);
5898 }
5899 }
5900
5901 if (start != channel_index) {
5902 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
5903 (channel_index - start);
5904 }
5905 }
5906}
5907
James Ketrenosea2b26e2005-08-24 21:25:16 -05005908static int ipw_request_scan(struct ipw_priv *priv)
5909{
5910 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005911 int err = 0, scan_type;
5912
5913 if (!(priv->status & STATUS_INIT) ||
5914 (priv->status & STATUS_EXIT_PENDING))
5915 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005916
James Ketrenosb095c382005-08-24 22:04:42 -05005917 down(&priv->sem);
5918
James Ketrenosea2b26e2005-08-24 21:25:16 -05005919 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005920 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05005921 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005922 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005923 }
5924
James Ketrenosafbf30a2005-08-25 00:05:33 -05005925 if (!(priv->status & STATUS_SCAN_FORCED) &&
5926 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005927 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5928 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005929 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005930 }
5931
5932 if (priv->status & STATUS_RF_KILL_MASK) {
5933 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5934 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005935 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005936 }
5937
5938 memset(&scan, 0, sizeof(scan));
5939
James Ketrenosb095c382005-08-24 22:04:42 -05005940 if (priv->config & CFG_SPEED_SCAN)
5941 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5942 cpu_to_le16(30);
5943 else
5944 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5945 cpu_to_le16(20);
5946
James Ketrenosa613bff2005-08-24 21:43:11 -05005947 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5948 cpu_to_le16(20);
5949 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005950
James Ketrenosa613bff2005-08-24 21:43:11 -05005951 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05005952
James Ketrenosb095c382005-08-24 22:04:42 -05005953#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05005954 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005955 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05005956 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005957
James Ketrenosb095c382005-08-24 22:04:42 -05005958 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5959 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005960 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005961 channel = priv->channel;
5962 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005963
James Ketrenosb095c382005-08-24 22:04:42 -05005964 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005965 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005966 channel = priv->channel;
5967 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005968
James Ketrenosb095c382005-08-24 22:04:42 -05005969 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005970 band = (u8) (IPW_B_MODE << 6) | 1;
5971 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05005972 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005973 }
5974
James Ketrenosb095c382005-08-24 22:04:42 -05005975 scan.channels_list[0] = band;
5976 scan.channels_list[1] = channel;
5977 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005978
James Ketrenosb095c382005-08-24 22:04:42 -05005979 /* NOTE: The card will sit on this channel for this time
5980 * period. Scan aborts are timing sensitive and frequently
5981 * result in firmware restarts. As such, it is best to
5982 * set a small dwell_time here and just keep re-issuing
5983 * scans. Otherwise fast channel hopping will not actually
5984 * hop channels.
5985 *
5986 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05005987 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5988 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005989 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05005990#endif /* CONFIG_IPW2200_MONITOR */
5991 /* If we are roaming, then make this a directed scan for the
5992 * current network. Otherwise, ensure that every other scan
5993 * is a fast channel hop scan */
5994 if ((priv->status & STATUS_ROAMING)
5995 || (!(priv->status & STATUS_ASSOCIATED)
5996 && (priv->config & CFG_STATIC_ESSID)
5997 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005998 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5999 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006000 IPW_DEBUG_HC("Attempt to send SSID command "
6001 "failed.\n");
6002 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006003 }
6004
6005 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006006 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006007 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006008
James Ketrenosafbf30a2005-08-25 00:05:33 -05006009 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006010#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006011 }
6012#endif
6013
6014 err = ipw_send_scan_request_ext(priv, &scan);
6015 if (err) {
6016 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006017 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006018 }
6019
6020 priv->status |= STATUS_SCANNING;
6021 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006022 queue_delayed_work(priv->workqueue, &priv->scan_check,
6023 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006024 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006025 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006026 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006027}
6028
6029static void ipw_bg_abort_scan(void *data)
6030{
6031 struct ipw_priv *priv = data;
6032 down(&priv->sem);
6033 ipw_abort_scan(data);
6034 up(&priv->sem);
6035}
6036
James Ketrenosafbf30a2005-08-25 00:05:33 -05006037#if WIRELESS_EXT < 18
6038/* Support for wpa_supplicant before WE-18, deprecated. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006039
6040/* following definitions must match definitions in driver_ipw.c */
6041
6042#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
6043
6044#define IPW_CMD_SET_WPA_PARAM 1
6045#define IPW_CMD_SET_WPA_IE 2
6046#define IPW_CMD_SET_ENCRYPTION 3
6047#define IPW_CMD_MLME 4
6048
6049#define IPW_PARAM_WPA_ENABLED 1
6050#define IPW_PARAM_TKIP_COUNTERMEASURES 2
6051#define IPW_PARAM_DROP_UNENCRYPTED 3
6052#define IPW_PARAM_PRIVACY_INVOKED 4
6053#define IPW_PARAM_AUTH_ALGS 5
6054#define IPW_PARAM_IEEE_802_1X 6
6055
6056#define IPW_MLME_STA_DEAUTH 1
6057#define IPW_MLME_STA_DISASSOC 2
6058
6059#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
6060#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
6061#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
6062#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
6063#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
6064#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
6065
6066#define IPW_CRYPT_ALG_NAME_LEN 16
6067
6068struct ipw_param {
6069 u32 cmd;
6070 u8 sta_addr[ETH_ALEN];
6071 union {
6072 struct {
6073 u8 name;
6074 u32 value;
6075 } wpa_param;
6076 struct {
6077 u32 len;
James Ketrenosb095c382005-08-24 22:04:42 -05006078 u8 reserved[32];
6079 u8 data[0];
James Ketrenosea2b26e2005-08-24 21:25:16 -05006080 } wpa_ie;
6081 struct {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006082 u32 command;
6083 u32 reason_code;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006084 } mlme;
6085 struct {
6086 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
6087 u8 set_tx;
6088 u32 err;
6089 u8 idx;
6090 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
6091 u16 key_len;
6092 u8 key[0];
6093 } crypt;
6094
6095 } u;
6096};
6097
6098/* end of driver_ipw.c code */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006099#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006100
6101static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6102{
James Ketrenosb095c382005-08-24 22:04:42 -05006103 /* This is called when wpa_supplicant loads and closes the driver
6104 * interface. */
6105 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006106}
6107
James Ketrenosafbf30a2005-08-25 00:05:33 -05006108#if WIRELESS_EXT < 18
6109#define IW_AUTH_ALG_OPEN_SYSTEM 0x1
6110#define IW_AUTH_ALG_SHARED_KEY 0x2
6111#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006112
6113static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6114{
6115 struct ieee80211_device *ieee = priv->ieee;
6116 struct ieee80211_security sec = {
6117 .flags = SEC_AUTH_MODE,
6118 };
6119 int ret = 0;
6120
James Ketrenosafbf30a2005-08-25 00:05:33 -05006121 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006122 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6123 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006124 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006125 sec.auth_mode = WLAN_AUTH_OPEN;
6126 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006127 } else
6128 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006129
6130 if (ieee->set_security)
6131 ieee->set_security(ieee->dev, &sec);
6132 else
6133 ret = -EOPNOTSUPP;
6134
6135 return ret;
6136}
6137
James Ketrenosafbf30a2005-08-25 00:05:33 -05006138void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6139{
6140 /* make sure WPA is enabled */
6141 ipw_wpa_enable(priv, 1);
6142
6143 ipw_disassociate(priv);
6144}
6145
6146static int ipw_set_rsn_capa(struct ipw_priv *priv,
6147 char *capabilities, int length)
6148{
6149 struct host_cmd cmd = {
6150 .cmd = IPW_CMD_RSN_CAPABILITIES,
6151 .len = length,
6152 };
6153
6154 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6155
6156 memcpy(cmd.param, capabilities, length);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05006157 return ipw_send_cmd(priv, &cmd);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006158}
6159
6160#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -05006161static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
6162{
6163 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05006164 struct ieee80211_crypt_data *crypt;
6165 unsigned long flags;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006166 int ret = 0;
6167
6168 switch (name) {
6169 case IPW_PARAM_WPA_ENABLED:
6170 ret = ipw_wpa_enable(priv, value);
6171 break;
6172
6173 case IPW_PARAM_TKIP_COUNTERMEASURES:
James Ketrenosa613bff2005-08-24 21:43:11 -05006174 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6175 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6176 IPW_WARNING("Can't set TKIP countermeasures: "
6177 "crypt not set!\n");
6178 break;
6179 }
6180
6181 flags = crypt->ops->get_flags(crypt->priv);
6182
6183 if (value)
6184 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6185 else
6186 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6187
6188 crypt->ops->set_flags(flags, crypt->priv);
6189
James Ketrenosea2b26e2005-08-24 21:25:16 -05006190 break;
6191
James Ketrenosb095c382005-08-24 22:04:42 -05006192 case IPW_PARAM_DROP_UNENCRYPTED:{
6193 /* HACK:
6194 *
6195 * wpa_supplicant calls set_wpa_enabled when the driver
6196 * is loaded and unloaded, regardless of if WPA is being
6197 * used. No other calls are made which can be used to
6198 * determine if encryption will be used or not prior to
6199 * association being expected. If encryption is not being
6200 * used, drop_unencrypted is set to false, else true -- we
6201 * can use this to determine if the CAP_PRIVACY_ON bit should
6202 * be set.
6203 */
6204 struct ieee80211_security sec = {
6205 .flags = SEC_ENABLED,
6206 .enabled = value,
6207 };
6208 priv->ieee->drop_unencrypted = value;
6209 /* We only change SEC_LEVEL for open mode. Others
6210 * are set by ipw_wpa_set_encryption.
6211 */
6212 if (!value) {
6213 sec.flags |= SEC_LEVEL;
6214 sec.level = SEC_LEVEL_0;
6215 } else {
6216 sec.flags |= SEC_LEVEL;
6217 sec.level = SEC_LEVEL_1;
6218 }
6219 if (priv->ieee->set_security)
6220 priv->ieee->set_security(priv->ieee->dev, &sec);
6221 break;
6222 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05006223
6224 case IPW_PARAM_PRIVACY_INVOKED:
6225 priv->ieee->privacy_invoked = value;
6226 break;
6227
6228 case IPW_PARAM_AUTH_ALGS:
6229 ret = ipw_wpa_set_auth_algs(priv, value);
6230 break;
6231
6232 case IPW_PARAM_IEEE_802_1X:
6233 priv->ieee->ieee802_1x = value;
6234 break;
6235
6236 default:
6237 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
6238 ret = -EOPNOTSUPP;
6239 }
6240
6241 return ret;
6242}
6243
6244static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
6245{
6246 struct ipw_priv *priv = ieee80211_priv(dev);
6247 int ret = 0;
6248
6249 switch (command) {
6250 case IPW_MLME_STA_DEAUTH:
6251 // silently ignore
6252 break;
6253
6254 case IPW_MLME_STA_DISASSOC:
6255 ipw_disassociate(priv);
6256 break;
6257
6258 default:
6259 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
6260 ret = -EOPNOTSUPP;
6261 }
6262
6263 return ret;
6264}
6265
Zhu Yi1fbfea52005-08-05 17:22:56 +08006266static int ipw_wpa_ie_cipher2level(u8 cipher)
6267{
6268 switch (cipher) {
6269 case 4: /* CCMP */
6270 return SEC_LEVEL_3;
6271 case 2: /* TKIP */
6272 return SEC_LEVEL_2;
6273 case 5: /* WEP104 */
6274 case 1: /* WEP40 */
6275 return SEC_LEVEL_1;
6276 case 0: /* NONE */
6277 return SEC_LEVEL_0;
6278 default:
6279 return -1;
6280 }
6281}
6282
James Ketrenosea2b26e2005-08-24 21:25:16 -05006283static int ipw_wpa_set_wpa_ie(struct net_device *dev,
6284 struct ipw_param *param, int plen)
6285{
6286 struct ipw_priv *priv = ieee80211_priv(dev);
6287 struct ieee80211_device *ieee = priv->ieee;
6288 u8 *buf;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006289 u8 *ptk, *gtk;
6290 int level;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006291
James Ketrenosea2b26e2005-08-24 21:25:16 -05006292 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
6293 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
6294 return -EINVAL;
6295
6296 if (param->u.wpa_ie.len) {
6297 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
6298 if (buf == NULL)
6299 return -ENOMEM;
6300
6301 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
6302 kfree(ieee->wpa_ie);
6303 ieee->wpa_ie = buf;
6304 ieee->wpa_ie_len = param->u.wpa_ie.len;
6305 } else {
6306 kfree(ieee->wpa_ie);
6307 ieee->wpa_ie = NULL;
6308 ieee->wpa_ie_len = 0;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006309 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006310 }
6311
Zhu Yi1fbfea52005-08-05 17:22:56 +08006312 if (priv->ieee->host_encrypt)
6313 goto done;
6314
6315 /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
6316 * we need to change driver_ipw.c from wpa_supplicant. This
6317 * is OK since -Dipw is deprecated. The -Dwext driver has a
6318 * clean way to handle this. */
6319 gtk = ptk = (u8 *) ieee->wpa_ie;
6320 if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
6321 gtk += 4 + 3;
6322 ptk += 4 + 4 + 2 + 3;
6323 } else { /* WPA IE */
6324 gtk += 8 + 3;
6325 ptk += 8 + 4 + 2 + 3;
6326 }
6327
6328 if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
6329 return -EINVAL;
6330
6331 level = ipw_wpa_ie_cipher2level(*gtk);
6332 ipw_set_hw_decrypt_multicast(priv, level);
6333
6334 level = ipw_wpa_ie_cipher2level(*ptk);
6335 ipw_set_hw_decrypt_unicast(priv, level);
6336
6337 done:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006338 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6339 return 0;
6340}
6341
6342/* implementation borrowed from hostap driver */
6343
6344static int ipw_wpa_set_encryption(struct net_device *dev,
6345 struct ipw_param *param, int param_len)
6346{
6347 int ret = 0;
6348 struct ipw_priv *priv = ieee80211_priv(dev);
6349 struct ieee80211_device *ieee = priv->ieee;
6350 struct ieee80211_crypto_ops *ops;
6351 struct ieee80211_crypt_data **crypt;
6352
6353 struct ieee80211_security sec = {
6354 .flags = 0,
6355 };
6356
6357 param->u.crypt.err = 0;
6358 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
6359
6360 if (param_len !=
6361 (int)((char *)param->u.crypt.key - (char *)param) +
6362 param->u.crypt.key_len) {
6363 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
6364 param->u.crypt.key_len);
6365 return -EINVAL;
6366 }
6367 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6368 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6369 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6370 if (param->u.crypt.idx >= WEP_KEYS)
6371 return -EINVAL;
6372 crypt = &ieee->crypt[param->u.crypt.idx];
6373 } else {
6374 return -EINVAL;
6375 }
6376
James Ketrenosafbf30a2005-08-25 00:05:33 -05006377 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006378 if (strcmp(param->u.crypt.alg, "none") == 0) {
6379 if (crypt) {
6380 sec.enabled = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006381 sec.encrypt = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006382 sec.level = SEC_LEVEL_0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006383 sec.flags |= SEC_LEVEL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006384 ieee80211_crypt_delayed_deinit(ieee, crypt);
6385 }
6386 goto done;
6387 }
6388 sec.enabled = 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006389 sec.encrypt = 1;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006390
James Ketrenosb095c382005-08-24 22:04:42 -05006391 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006392 if (strcmp(param->u.crypt.alg, "TKIP") == 0)
6393 ieee->host_encrypt_msdu = 1;
6394
6395 if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
6396 ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05006397 goto skip_host_crypt;
6398
James Ketrenosea2b26e2005-08-24 21:25:16 -05006399 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6400 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6401 request_module("ieee80211_crypt_wep");
6402 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6403 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6404 request_module("ieee80211_crypt_tkip");
6405 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6406 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6407 request_module("ieee80211_crypt_ccmp");
6408 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6409 }
6410 if (ops == NULL) {
6411 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6412 dev->name, param->u.crypt.alg);
6413 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
6414 ret = -EINVAL;
6415 goto done;
6416 }
6417
6418 if (*crypt == NULL || (*crypt)->ops != ops) {
6419 struct ieee80211_crypt_data *new_crypt;
6420
6421 ieee80211_crypt_delayed_deinit(ieee, crypt);
6422
6423 new_crypt = (struct ieee80211_crypt_data *)
6424 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
6425 if (new_crypt == NULL) {
6426 ret = -ENOMEM;
6427 goto done;
6428 }
6429 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6430 new_crypt->ops = ops;
6431 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6432 new_crypt->priv =
6433 new_crypt->ops->init(param->u.crypt.idx);
6434
6435 if (new_crypt->priv == NULL) {
6436 kfree(new_crypt);
6437 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
6438 ret = -EINVAL;
6439 goto done;
6440 }
6441
6442 *crypt = new_crypt;
6443 }
6444
6445 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6446 (*crypt)->ops->set_key(param->u.crypt.key,
6447 param->u.crypt.key_len, param->u.crypt.seq,
6448 (*crypt)->priv) < 0) {
6449 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
6450 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
6451 ret = -EINVAL;
6452 goto done;
6453 }
6454
James Ketrenosb095c382005-08-24 22:04:42 -05006455 skip_host_crypt:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006456 if (param->u.crypt.set_tx) {
6457 ieee->tx_keyidx = param->u.crypt.idx;
6458 sec.active_key = param->u.crypt.idx;
6459 sec.flags |= SEC_ACTIVE_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05006460 } else
6461 sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006462
James Ketrenosb095c382005-08-24 22:04:42 -05006463 if (param->u.crypt.alg != NULL) {
6464 memcpy(sec.keys[param->u.crypt.idx],
6465 param->u.crypt.key, param->u.crypt.key_len);
6466 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6467 sec.flags |= (1 << param->u.crypt.idx);
6468
6469 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006470 sec.flags |= SEC_LEVEL;
6471 sec.level = SEC_LEVEL_1;
James Ketrenosb095c382005-08-24 22:04:42 -05006472 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006473 sec.flags |= SEC_LEVEL;
6474 sec.level = SEC_LEVEL_2;
James Ketrenosb095c382005-08-24 22:04:42 -05006475 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006476 sec.flags |= SEC_LEVEL;
6477 sec.level = SEC_LEVEL_3;
6478 }
6479 }
6480 done:
6481 if (ieee->set_security)
6482 ieee->set_security(ieee->dev, &sec);
6483
6484 /* Do not reset port if card is in Managed mode since resetting will
6485 * generate new IEEE 802.11 authentication which may end up in looping
6486 * with IEEE 802.1X. If your hardware requires a reset after WEP
6487 * configuration (for example... Prism2), implement the reset_port in
6488 * the callbacks structures used to initialize the 802.11 stack. */
6489 if (ieee->reset_on_keychange &&
6490 ieee->iw_mode != IW_MODE_INFRA &&
6491 ieee->reset_port && ieee->reset_port(dev)) {
6492 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6493 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
6494 return -EINVAL;
6495 }
6496
6497 return ret;
6498}
6499
6500static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
6501{
6502 struct ipw_param *param;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006503 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006504 int ret = 0;
6505
6506 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
6507
6508 if (p->length < sizeof(struct ipw_param) || !p->pointer)
6509 return -EINVAL;
6510
6511 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
6512 if (param == NULL)
6513 return -ENOMEM;
6514
6515 if (copy_from_user(param, p->pointer, p->length)) {
6516 kfree(param);
6517 return -EFAULT;
6518 }
6519
James Ketrenosafbf30a2005-08-25 00:05:33 -05006520 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006521 switch (param->cmd) {
6522
6523 case IPW_CMD_SET_WPA_PARAM:
6524 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
6525 param->u.wpa_param.value);
6526 break;
6527
6528 case IPW_CMD_SET_WPA_IE:
6529 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
6530 break;
6531
6532 case IPW_CMD_SET_ENCRYPTION:
6533 ret = ipw_wpa_set_encryption(dev, param, p->length);
6534 break;
6535
6536 case IPW_CMD_MLME:
6537 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
6538 param->u.mlme.reason_code);
6539 break;
6540
6541 default:
6542 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6543 dev->name, param->cmd);
6544 ret = -EOPNOTSUPP;
6545 }
6546
James Ketrenosafbf30a2005-08-25 00:05:33 -05006547 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006548 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6549 ret = -EFAULT;
6550
6551 kfree(param);
6552 return ret;
6553}
James Ketrenosafbf30a2005-08-25 00:05:33 -05006554#else
6555/*
6556 * WE-18 support
6557 */
6558
6559/* SIOCSIWGENIE */
6560static int ipw_wx_set_genie(struct net_device *dev,
6561 struct iw_request_info *info,
6562 union iwreq_data *wrqu, char *extra)
6563{
6564 struct ipw_priv *priv = ieee80211_priv(dev);
6565 struct ieee80211_device *ieee = priv->ieee;
6566 u8 *buf;
6567 int err = 0;
6568
6569 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6570 (wrqu->data.length && extra == NULL))
6571 return -EINVAL;
6572
6573 //down(&priv->sem);
6574
6575 //if (!ieee->wpa_enabled) {
6576 // err = -EOPNOTSUPP;
6577 // goto out;
6578 //}
6579
6580 if (wrqu->data.length) {
6581 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6582 if (buf == NULL) {
6583 err = -ENOMEM;
6584 goto out;
6585 }
6586
6587 memcpy(buf, extra, wrqu->data.length);
6588 kfree(ieee->wpa_ie);
6589 ieee->wpa_ie = buf;
6590 ieee->wpa_ie_len = wrqu->data.length;
6591 } else {
6592 kfree(ieee->wpa_ie);
6593 ieee->wpa_ie = NULL;
6594 ieee->wpa_ie_len = 0;
6595 }
6596
6597 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6598 out:
6599 //up(&priv->sem);
6600 return err;
6601}
6602
6603/* SIOCGIWGENIE */
6604static int ipw_wx_get_genie(struct net_device *dev,
6605 struct iw_request_info *info,
6606 union iwreq_data *wrqu, char *extra)
6607{
6608 struct ipw_priv *priv = ieee80211_priv(dev);
6609 struct ieee80211_device *ieee = priv->ieee;
6610 int err = 0;
6611
6612 //down(&priv->sem);
6613
6614 //if (!ieee->wpa_enabled) {
6615 // err = -EOPNOTSUPP;
6616 // goto out;
6617 //}
6618
6619 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6620 wrqu->data.length = 0;
6621 goto out;
6622 }
6623
6624 if (wrqu->data.length < ieee->wpa_ie_len) {
6625 err = -E2BIG;
6626 goto out;
6627 }
6628
6629 wrqu->data.length = ieee->wpa_ie_len;
6630 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6631
6632 out:
6633 //up(&priv->sem);
6634 return err;
6635}
6636
Zhu Yi1fbfea52005-08-05 17:22:56 +08006637static int wext_cipher2level(int cipher)
6638{
6639 switch (cipher) {
6640 case IW_AUTH_CIPHER_NONE:
6641 return SEC_LEVEL_0;
6642 case IW_AUTH_CIPHER_WEP40:
6643 case IW_AUTH_CIPHER_WEP104:
6644 return SEC_LEVEL_1;
6645 case IW_AUTH_CIPHER_TKIP:
6646 return SEC_LEVEL_2;
6647 case IW_AUTH_CIPHER_CCMP:
6648 return SEC_LEVEL_3;
6649 default:
6650 return -1;
6651 }
6652}
6653
James Ketrenosafbf30a2005-08-25 00:05:33 -05006654/* SIOCSIWAUTH */
6655static int ipw_wx_set_auth(struct net_device *dev,
6656 struct iw_request_info *info,
6657 union iwreq_data *wrqu, char *extra)
6658{
6659 struct ipw_priv *priv = ieee80211_priv(dev);
6660 struct ieee80211_device *ieee = priv->ieee;
6661 struct iw_param *param = &wrqu->param;
6662 struct ieee80211_crypt_data *crypt;
6663 unsigned long flags;
6664 int ret = 0;
6665
6666 switch (param->flags & IW_AUTH_INDEX) {
6667 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006668 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006669 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006670 ipw_set_hw_decrypt_unicast(priv,
6671 wext_cipher2level(param->value));
6672 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006673 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006674 ipw_set_hw_decrypt_multicast(priv,
6675 wext_cipher2level(param->value));
6676 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006677 case IW_AUTH_KEY_MGMT:
6678 /*
6679 * ipw2200 does not use these parameters
6680 */
6681 break;
6682
6683 case IW_AUTH_TKIP_COUNTERMEASURES:
6684 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6685 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6686 IPW_WARNING("Can't set TKIP countermeasures: "
6687 "crypt not set!\n");
6688 break;
6689 }
6690
6691 flags = crypt->ops->get_flags(crypt->priv);
6692
6693 if (param->value)
6694 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6695 else
6696 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6697
6698 crypt->ops->set_flags(flags, crypt->priv);
6699
6700 break;
6701
6702 case IW_AUTH_DROP_UNENCRYPTED:{
6703 /* HACK:
6704 *
6705 * wpa_supplicant calls set_wpa_enabled when the driver
6706 * is loaded and unloaded, regardless of if WPA is being
6707 * used. No other calls are made which can be used to
6708 * determine if encryption will be used or not prior to
6709 * association being expected. If encryption is not being
6710 * used, drop_unencrypted is set to false, else true -- we
6711 * can use this to determine if the CAP_PRIVACY_ON bit should
6712 * be set.
6713 */
6714 struct ieee80211_security sec = {
6715 .flags = SEC_ENABLED,
6716 .enabled = param->value,
6717 };
6718 priv->ieee->drop_unencrypted = param->value;
6719 /* We only change SEC_LEVEL for open mode. Others
6720 * are set by ipw_wpa_set_encryption.
6721 */
6722 if (!param->value) {
6723 sec.flags |= SEC_LEVEL;
6724 sec.level = SEC_LEVEL_0;
6725 } else {
6726 sec.flags |= SEC_LEVEL;
6727 sec.level = SEC_LEVEL_1;
6728 }
6729 if (priv->ieee->set_security)
6730 priv->ieee->set_security(priv->ieee->dev, &sec);
6731 break;
6732 }
6733
6734 case IW_AUTH_80211_AUTH_ALG:
6735 ret = ipw_wpa_set_auth_algs(priv, param->value);
6736 break;
6737
6738 case IW_AUTH_WPA_ENABLED:
6739 ret = ipw_wpa_enable(priv, param->value);
6740 break;
6741
6742 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6743 ieee->ieee802_1x = param->value;
6744 break;
6745
6746 //case IW_AUTH_ROAMING_CONTROL:
6747 case IW_AUTH_PRIVACY_INVOKED:
6748 ieee->privacy_invoked = param->value;
6749 break;
6750
6751 default:
6752 return -EOPNOTSUPP;
6753 }
6754 return ret;
6755}
6756
6757/* SIOCGIWAUTH */
6758static int ipw_wx_get_auth(struct net_device *dev,
6759 struct iw_request_info *info,
6760 union iwreq_data *wrqu, char *extra)
6761{
6762 struct ipw_priv *priv = ieee80211_priv(dev);
6763 struct ieee80211_device *ieee = priv->ieee;
6764 struct ieee80211_crypt_data *crypt;
6765 struct iw_param *param = &wrqu->param;
6766 int ret = 0;
6767
6768 switch (param->flags & IW_AUTH_INDEX) {
6769 case IW_AUTH_WPA_VERSION:
6770 case IW_AUTH_CIPHER_PAIRWISE:
6771 case IW_AUTH_CIPHER_GROUP:
6772 case IW_AUTH_KEY_MGMT:
6773 /*
6774 * wpa_supplicant will control these internally
6775 */
6776 ret = -EOPNOTSUPP;
6777 break;
6778
6779 case IW_AUTH_TKIP_COUNTERMEASURES:
6780 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6781 if (!crypt || !crypt->ops->get_flags) {
6782 IPW_WARNING("Can't get TKIP countermeasures: "
6783 "crypt not set!\n");
6784 break;
6785 }
6786
6787 param->value = (crypt->ops->get_flags(crypt->priv) &
6788 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6789
6790 break;
6791
6792 case IW_AUTH_DROP_UNENCRYPTED:
6793 param->value = ieee->drop_unencrypted;
6794 break;
6795
6796 case IW_AUTH_80211_AUTH_ALG:
6797 param->value = ieee->sec.auth_mode;
6798 break;
6799
6800 case IW_AUTH_WPA_ENABLED:
6801 param->value = ieee->wpa_enabled;
6802 break;
6803
6804 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6805 param->value = ieee->ieee802_1x;
6806 break;
6807
6808 case IW_AUTH_ROAMING_CONTROL:
6809 case IW_AUTH_PRIVACY_INVOKED:
6810 param->value = ieee->privacy_invoked;
6811 break;
6812
6813 default:
6814 return -EOPNOTSUPP;
6815 }
6816 return 0;
6817}
6818
6819/* SIOCSIWENCODEEXT */
6820static int ipw_wx_set_encodeext(struct net_device *dev,
6821 struct iw_request_info *info,
6822 union iwreq_data *wrqu, char *extra)
6823{
6824 struct ipw_priv *priv = ieee80211_priv(dev);
6825 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6826
6827 if (hwcrypto) {
6828 /* IPW HW can't build TKIP MIC, host decryption still needed */
6829 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6830 priv->ieee->host_encrypt = 0;
6831 priv->ieee->host_encrypt_msdu = 1;
6832 priv->ieee->host_decrypt = 1;
6833 } else {
6834 priv->ieee->host_encrypt = 0;
6835 priv->ieee->host_encrypt_msdu = 0;
6836 priv->ieee->host_decrypt = 0;
6837 }
6838 }
6839
6840 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6841}
6842
6843/* SIOCGIWENCODEEXT */
6844static int ipw_wx_get_encodeext(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6847{
6848 struct ipw_priv *priv = ieee80211_priv(dev);
6849 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6850}
6851
6852/* SIOCSIWMLME */
6853static int ipw_wx_set_mlme(struct net_device *dev,
6854 struct iw_request_info *info,
6855 union iwreq_data *wrqu, char *extra)
6856{
6857 struct ipw_priv *priv = ieee80211_priv(dev);
6858 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6859 u16 reason;
6860
6861 reason = cpu_to_le16(mlme->reason_code);
6862
6863 switch (mlme->cmd) {
6864 case IW_MLME_DEAUTH:
6865 // silently ignore
6866 break;
6867
6868 case IW_MLME_DISASSOC:
6869 ipw_disassociate(priv);
6870 break;
6871
6872 default:
6873 return -EOPNOTSUPP;
6874 }
6875 return 0;
6876}
6877#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006878
James Ketrenosb095c382005-08-24 22:04:42 -05006879#ifdef CONFIG_IPW_QOS
6880
6881/* QoS */
6882/*
6883* get the modulation type of the current network or
6884* the card current mode
6885*/
6886u8 ipw_qos_current_mode(struct ipw_priv * priv)
6887{
6888 u8 mode = 0;
6889
6890 if (priv->status & STATUS_ASSOCIATED) {
6891 unsigned long flags;
6892
6893 spin_lock_irqsave(&priv->ieee->lock, flags);
6894 mode = priv->assoc_network->mode;
6895 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6896 } else {
6897 mode = priv->ieee->mode;
6898 }
6899 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6900 return mode;
6901}
6902
6903/*
6904* Handle management frame beacon and probe response
6905*/
6906static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
6907 int active_network,
6908 struct ieee80211_network *network)
6909{
6910 u32 size = sizeof(struct ieee80211_qos_parameters);
6911
James Ketrenosafbf30a2005-08-25 00:05:33 -05006912 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006913 network->qos_data.active = network->qos_data.supported;
6914
6915 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006916 if (active_network &&
6917 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006918 network->qos_data.active = network->qos_data.supported;
6919
6920 if ((network->qos_data.active == 1) && (active_network == 1) &&
6921 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6922 (network->qos_data.old_param_count !=
6923 network->qos_data.param_count)) {
6924 network->qos_data.old_param_count =
6925 network->qos_data.param_count;
6926 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006927 IPW_DEBUG_QOS("QoS parameters change call "
6928 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006929 }
6930 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006931 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6932 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006933 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006934 else
6935 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006936 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006937
James Ketrenosb095c382005-08-24 22:04:42 -05006938 if ((network->qos_data.active == 1) && (active_network == 1)) {
6939 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6940 schedule_work(&priv->qos_activate);
6941 }
6942
6943 network->qos_data.active = 0;
6944 network->qos_data.supported = 0;
6945 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006946 if ((priv->status & STATUS_ASSOCIATED) &&
6947 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6948 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6949 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6950 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006951 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006952 priv->assoc_network->ssid_len) &&
6953 !memcmp(network->ssid,
6954 priv->assoc_network->ssid,
6955 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006956 queue_work(priv->workqueue,
6957 &priv->merge_networks);
6958 }
James Ketrenosb095c382005-08-24 22:04:42 -05006959 }
6960
6961 return 0;
6962}
6963
6964/*
6965* This function set up the firmware to support QoS. It sends
6966* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6967*/
6968static int ipw_qos_activate(struct ipw_priv *priv,
6969 struct ieee80211_qos_data *qos_network_data)
6970{
6971 int err;
6972 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6973 struct ieee80211_qos_parameters *active_one = NULL;
6974 u32 size = sizeof(struct ieee80211_qos_parameters);
6975 u32 burst_duration;
6976 int i;
6977 u8 type;
6978
6979 type = ipw_qos_current_mode(priv);
6980
6981 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6982 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6983 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6984 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6985
6986 if (qos_network_data == NULL) {
6987 if (type == IEEE_B) {
6988 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6989 active_one = &def_parameters_CCK;
6990 } else
6991 active_one = &def_parameters_OFDM;
6992
James Ketrenosafbf30a2005-08-25 00:05:33 -05006993 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006994 burst_duration = ipw_qos_get_burst_duration(priv);
6995 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006996 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6997 (u16) burst_duration;
6998 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006999 if (type == IEEE_B) {
7000 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7001 type);
7002 if (priv->qos_data.qos_enable == 0)
7003 active_one = &def_parameters_CCK;
7004 else
7005 active_one = priv->qos_data.def_qos_parm_CCK;
7006 } else {
7007 if (priv->qos_data.qos_enable == 0)
7008 active_one = &def_parameters_OFDM;
7009 else
7010 active_one = priv->qos_data.def_qos_parm_OFDM;
7011 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007012 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007013 } else {
7014 unsigned long flags;
7015 int active;
7016
7017 spin_lock_irqsave(&priv->ieee->lock, flags);
7018 active_one = &(qos_network_data->parameters);
7019 qos_network_data->old_param_count =
7020 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007021 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007022 active = qos_network_data->supported;
7023 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7024
7025 if (active == 0) {
7026 burst_duration = ipw_qos_get_burst_duration(priv);
7027 for (i = 0; i < QOS_QUEUE_NUM; i++)
7028 qos_parameters[QOS_PARAM_SET_ACTIVE].
7029 tx_op_limit[i] = (u16) burst_duration;
7030 }
7031 }
7032
7033 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007034 err = ipw_send_qos_params_command(priv,
7035 (struct ieee80211_qos_parameters *)
7036 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007037 if (err)
7038 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7039
7040 return err;
7041}
7042
7043/*
7044* send IPW_CMD_WME_INFO to the firmware
7045*/
7046static int ipw_qos_set_info_element(struct ipw_priv *priv)
7047{
7048 int ret = 0;
7049 struct ieee80211_qos_information_element qos_info;
7050
7051 if (priv == NULL)
7052 return -1;
7053
7054 qos_info.elementID = QOS_ELEMENT_ID;
7055 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
7056
7057 qos_info.version = QOS_VERSION_1;
7058 qos_info.ac_info = 0;
7059
7060 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7061 qos_info.qui_type = QOS_OUI_TYPE;
7062 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7063
7064 ret = ipw_send_qos_info_command(priv, &qos_info);
7065 if (ret != 0) {
7066 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7067 }
7068 return ret;
7069}
7070
7071/*
7072* Set the QoS parameter with the association request structure
7073*/
7074static int ipw_qos_association(struct ipw_priv *priv,
7075 struct ieee80211_network *network)
7076{
7077 int err = 0;
7078 struct ieee80211_qos_data *qos_data = NULL;
7079 struct ieee80211_qos_data ibss_data = {
7080 .supported = 1,
7081 .active = 1,
7082 };
7083
7084 switch (priv->ieee->iw_mode) {
7085 case IW_MODE_ADHOC:
7086 if (!(network->capability & WLAN_CAPABILITY_IBSS))
7087 BUG();
7088
7089 qos_data = &ibss_data;
7090 break;
7091
7092 case IW_MODE_INFRA:
7093 qos_data = &network->qos_data;
7094 break;
7095
7096 default:
7097 BUG();
7098 break;
7099 }
7100
7101 err = ipw_qos_activate(priv, qos_data);
7102 if (err) {
7103 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7104 return err;
7105 }
7106
7107 if (priv->qos_data.qos_enable && qos_data->supported) {
7108 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7109 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7110 return ipw_qos_set_info_element(priv);
7111 }
7112
7113 return 0;
7114}
7115
7116/*
7117* handling the beaconing responces. if we get different QoS setting
7118* of the network from the the associated setting adjust the QoS
7119* setting
7120*/
7121static int ipw_qos_association_resp(struct ipw_priv *priv,
7122 struct ieee80211_network *network)
7123{
7124 int ret = 0;
7125 unsigned long flags;
7126 u32 size = sizeof(struct ieee80211_qos_parameters);
7127 int set_qos_param = 0;
7128
James Ketrenosafbf30a2005-08-25 00:05:33 -05007129 if ((priv == NULL) || (network == NULL) ||
7130 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007131 return ret;
7132
7133 if (!(priv->status & STATUS_ASSOCIATED))
7134 return ret;
7135
James Ketrenosafbf30a2005-08-25 00:05:33 -05007136 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007137 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007138
7139 spin_lock_irqsave(&priv->ieee->lock, flags);
7140 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007141 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05007142 sizeof(struct ieee80211_qos_data));
7143 priv->assoc_network->qos_data.active = 1;
7144 if ((network->qos_data.old_param_count !=
7145 network->qos_data.param_count)) {
7146 set_qos_param = 1;
7147 network->qos_data.old_param_count =
7148 network->qos_data.param_count;
7149 }
7150
7151 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007152 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7153 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007154 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007155 else
7156 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007157 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007158 priv->assoc_network->qos_data.active = 0;
7159 priv->assoc_network->qos_data.supported = 0;
7160 set_qos_param = 1;
7161 }
7162
7163 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7164
7165 if (set_qos_param == 1)
7166 schedule_work(&priv->qos_activate);
7167
7168 return ret;
7169}
7170
7171static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7172{
7173 u32 ret = 0;
7174
7175 if ((priv == NULL))
7176 return 0;
7177
James Ketrenosafbf30a2005-08-25 00:05:33 -05007178 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007179 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007180 else
James Ketrenosb095c382005-08-24 22:04:42 -05007181 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007182
James Ketrenosb095c382005-08-24 22:04:42 -05007183 return ret;
7184}
7185
7186/*
7187* Initialize the setting of QoS global
7188*/
7189static void ipw_qos_init(struct ipw_priv *priv, int enable,
7190 int burst_enable, u32 burst_duration_CCK,
7191 u32 burst_duration_OFDM)
7192{
7193 priv->qos_data.qos_enable = enable;
7194
7195 if (priv->qos_data.qos_enable) {
7196 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7197 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7198 IPW_DEBUG_QOS("QoS is enabled\n");
7199 } else {
7200 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7201 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7202 IPW_DEBUG_QOS("QoS is not enabled\n");
7203 }
7204
7205 priv->qos_data.burst_enable = burst_enable;
7206
7207 if (burst_enable) {
7208 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7209 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7210 } else {
7211 priv->qos_data.burst_duration_CCK = 0;
7212 priv->qos_data.burst_duration_OFDM = 0;
7213 }
7214}
7215
7216/*
7217* map the packet priority to the right TX Queue
7218*/
7219static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7220{
7221 if (priority > 7 || !priv->qos_data.qos_enable)
7222 priority = 0;
7223
7224 return from_priority_to_tx_queue[priority] - 1;
7225}
7226
7227/*
7228* add QoS parameter to the TX command
7229*/
7230static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7231 u16 priority,
7232 struct tfd_data *tfd, u8 unicast)
7233{
7234 int ret = 0;
7235 int tx_queue_id = 0;
7236 struct ieee80211_qos_data *qos_data = NULL;
7237 int active, supported;
7238 unsigned long flags;
7239
7240 if (!(priv->status & STATUS_ASSOCIATED))
7241 return 0;
7242
7243 qos_data = &priv->assoc_network->qos_data;
7244
7245 spin_lock_irqsave(&priv->ieee->lock, flags);
7246
7247 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7248 if (unicast == 0)
7249 qos_data->active = 0;
7250 else
7251 qos_data->active = qos_data->supported;
7252 }
7253
7254 active = qos_data->active;
7255 supported = qos_data->supported;
7256
7257 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7258
James Ketrenosafbf30a2005-08-25 00:05:33 -05007259 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7260 "unicast %d\n",
7261 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05007262 if (active && priv->qos_data.qos_enable) {
7263 ret = from_priority_to_tx_queue[priority];
7264 tx_queue_id = ret - 1;
7265 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
7266 if (priority <= 7) {
7267 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7268 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
7269 tfd->tfd.tfd_26.mchdr.frame_ctl |=
7270 IEEE80211_STYPE_QOS_DATA;
7271
7272 if (priv->qos_data.qos_no_ack_mask &
7273 (1UL << tx_queue_id)) {
7274 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7275 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
7276 CTRL_QOS_NO_ACK;
7277 }
7278 }
7279 }
7280
7281 return ret;
7282}
7283
7284/*
7285* background support to run QoS activate functionality
7286*/
7287static void ipw_bg_qos_activate(void *data)
7288{
7289 struct ipw_priv *priv = data;
7290
7291 if (priv == NULL)
7292 return;
7293
7294 down(&priv->sem);
7295
7296 if (priv->status & STATUS_ASSOCIATED)
7297 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7298
7299 up(&priv->sem);
7300}
7301
7302/*
7303* Handler for probe responce and beacon frame
7304*/
James Ketrenos2b184d52005-08-03 20:33:14 -05007305static int ipw_handle_management(struct net_device *dev,
7306 struct ieee80211_network *network, u16 type)
James Ketrenosb095c382005-08-24 22:04:42 -05007307{
7308 struct ipw_priv *priv = ieee80211_priv(dev);
7309 int active_network;
7310
7311 if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
7312 active_network = 1;
7313 else
7314 active_network = 0;
7315
7316 switch (type) {
7317 case IEEE80211_STYPE_PROBE_RESP:
7318 case IEEE80211_STYPE_BEACON:
7319 ipw_qos_handle_probe_reponse(priv, active_network, network);
7320 break;
7321 case IEEE80211_STYPE_ASSOC_RESP:
7322 ipw_qos_association_resp(priv, network);
7323 break;
7324 default:
7325 break;
7326 }
7327
7328 return 0;
7329}
7330
7331static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7332 *qos_param)
7333{
7334 struct host_cmd cmd = {
7335 .cmd = IPW_CMD_QOS_PARAMETERS,
7336 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7337 };
7338
James Ketrenosafbf30a2005-08-25 00:05:33 -05007339 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007340 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007341}
7342
7343static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7344 *qos_param)
7345{
7346 struct host_cmd cmd = {
7347 .cmd = IPW_CMD_WME_INFO,
7348 .len = sizeof(*qos_param)
7349 };
7350
James Ketrenosafbf30a2005-08-25 00:05:33 -05007351 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenos9ddf84f2005-08-16 17:07:11 -05007352 return ipw_send_cmd(priv, &cmd);
James Ketrenosb095c382005-08-24 22:04:42 -05007353}
7354
7355#endif /* CONFIG_IPW_QOS */
7356
James Ketrenos43f66a62005-03-25 12:31:53 -06007357static int ipw_associate_network(struct ipw_priv *priv,
7358 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007359 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007360{
7361 int err;
7362
7363 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007364 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007365
7366 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007367 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007368 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007369 memcpy(priv->essid, network->ssid, priv->essid_len);
7370 }
7371
7372 network->last_associate = jiffies;
7373
7374 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7375 priv->assoc_request.channel = network->channel;
7376 if ((priv->capability & CAP_PRIVACY_ON) &&
7377 (priv->capability & CAP_SHARED_KEY)) {
7378 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007379 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7380
7381 if ((priv->capability & CAP_PRIVACY_ON) &&
7382 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7383 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7384 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 } else {
7386 priv->assoc_request.auth_type = AUTH_OPEN;
7387 priv->assoc_request.auth_key = 0;
7388 }
7389
James Ketrenosa613bff2005-08-24 21:43:11 -05007390 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007391 priv->assoc_request.policy_support = 0x02; /* RSN active */
7392 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7393 priv->ieee->wpa_ie_len);
7394 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05007395
Jeff Garzikbf794512005-07-31 13:07:26 -04007396 /*
7397 * It is valid for our ieee device to support multiple modes, but
7398 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007399 * just one mode.
7400 */
7401 if (network->mode & priv->ieee->mode & IEEE_A)
7402 priv->assoc_request.ieee_mode = IPW_A_MODE;
7403 else if (network->mode & priv->ieee->mode & IEEE_G)
7404 priv->assoc_request.ieee_mode = IPW_G_MODE;
7405 else if (network->mode & priv->ieee->mode & IEEE_B)
7406 priv->assoc_request.ieee_mode = IPW_B_MODE;
7407
James Ketrenosea2b26e2005-08-24 21:25:16 -05007408 priv->assoc_request.capability = network->capability;
7409 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7410 && !(priv->config & CFG_PREAMBLE_LONG)) {
7411 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7412 } else {
7413 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7414
7415 /* Clear the short preamble if we won't be supporting it */
7416 priv->assoc_request.capability &=
7417 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7418 }
7419
James Ketrenosafbf30a2005-08-25 00:05:33 -05007420 /* Clear capability bits that aren't used in Ad Hoc */
7421 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7422 priv->assoc_request.capability &=
7423 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7424
James Ketrenos43f66a62005-03-25 12:31:53 -06007425 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007426 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007427 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007428 escape_essid(priv->essid, priv->essid_len),
7429 network->channel,
7430 ipw_modes[priv->assoc_request.ieee_mode],
7431 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007432 (priv->assoc_request.preamble_length ==
7433 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7434 network->capability &
7435 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007437 priv->capability & CAP_PRIVACY_ON ?
7438 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007439 "(open)") : "",
7440 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007441 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007442 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007443 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007444
7445 priv->assoc_request.beacon_interval = network->beacon_interval;
7446 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007447 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007448 priv->assoc_request.assoc_type = HC_IBSS_START;
7449 priv->assoc_request.assoc_tsf_msw = 0;
7450 priv->assoc_request.assoc_tsf_lsw = 0;
7451 } else {
7452 if (unlikely(roaming))
7453 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7454 else
7455 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7456 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7457 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7458 }
7459
James Ketrenosafbf30a2005-08-25 00:05:33 -05007460 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007461
7462 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7463 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7464 priv->assoc_request.atim_window = network->atim_window;
7465 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007466 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007467 priv->assoc_request.atim_window = 0;
7468 }
7469
James Ketrenos43f66a62005-03-25 12:31:53 -06007470 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007471
James Ketrenos43f66a62005-03-25 12:31:53 -06007472 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7473 if (err) {
7474 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7475 return err;
7476 }
7477
7478 rates->ieee_mode = priv->assoc_request.ieee_mode;
7479 rates->purpose = IPW_RATE_CONNECT;
7480 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007481
James Ketrenos43f66a62005-03-25 12:31:53 -06007482 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7483 priv->sys_config.dot11g_auto_detection = 1;
7484 else
7485 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007486
7487 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7488 priv->sys_config.answer_broadcast_ssid_probe = 1;
7489 else
7490 priv->sys_config.answer_broadcast_ssid_probe = 0;
7491
James Ketrenos43f66a62005-03-25 12:31:53 -06007492 err = ipw_send_system_config(priv, &priv->sys_config);
7493 if (err) {
7494 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7495 return err;
7496 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007497
James Ketrenos43f66a62005-03-25 12:31:53 -06007498 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007499 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007500 if (err) {
7501 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7502 return err;
7503 }
7504
7505 /*
7506 * If preemption is enabled, it is possible for the association
7507 * to complete before we return from ipw_send_associate. Therefore
7508 * we have to be sure and update our priviate data first.
7509 */
7510 priv->channel = network->channel;
7511 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007512 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007513 priv->status &= ~STATUS_SECURITY_UPDATED;
7514
7515 priv->assoc_network = network;
7516
James Ketrenosb095c382005-08-24 22:04:42 -05007517#ifdef CONFIG_IPW_QOS
7518 ipw_qos_association(priv, network);
7519#endif
7520
James Ketrenos43f66a62005-03-25 12:31:53 -06007521 err = ipw_send_associate(priv, &priv->assoc_request);
7522 if (err) {
7523 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7524 return err;
7525 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007526
7527 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007528 escape_essid(priv->essid, priv->essid_len),
7529 MAC_ARG(priv->bssid));
7530
7531 return 0;
7532}
7533
7534static void ipw_roam(void *data)
7535{
7536 struct ipw_priv *priv = data;
7537 struct ieee80211_network *network = NULL;
7538 struct ipw_network_match match = {
7539 .network = priv->assoc_network
7540 };
7541
7542 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007543 *
7544 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007545 * setting the status ROAM bit and requesting a scan.
7546 * 2. When the scan completes, it schedules the ROAM work
7547 * 3. The ROAM work looks at all of the known networks for one that
7548 * is a better network than the currently associated. If none
7549 * found, the ROAM process is over (ROAM bit cleared)
7550 * 4. If a better network is found, a disassociation request is
7551 * sent.
7552 * 5. When the disassociation completes, the roam work is again
7553 * scheduled. The second time through, the driver is no longer
7554 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007555 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 * 6. At this point ,the roaming process is complete and the ROAM
7557 * status bit is cleared.
7558 */
7559
7560 /* If we are no longer associated, and the roaming bit is no longer
7561 * set, then we are not actively roaming, so just return */
7562 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7563 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007564
James Ketrenos43f66a62005-03-25 12:31:53 -06007565 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007566 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007567 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007568 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007569 u8 rssi = priv->assoc_network->stats.rssi;
7570 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007571 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007572 list_for_each_entry(network, &priv->ieee->network_list, list) {
7573 if (network != priv->assoc_network)
7574 ipw_best_network(priv, &match, network, 1);
7575 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007576 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007577 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007578
James Ketrenos43f66a62005-03-25 12:31:53 -06007579 if (match.network == priv->assoc_network) {
7580 IPW_DEBUG_ASSOC("No better APs in this network to "
7581 "roam to.\n");
7582 priv->status &= ~STATUS_ROAMING;
7583 ipw_debug_config(priv);
7584 return;
7585 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007586
James Ketrenos43f66a62005-03-25 12:31:53 -06007587 ipw_send_disassociate(priv, 1);
7588 priv->assoc_network = match.network;
7589
7590 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007591 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007592
7593 /* Second pass through ROAM process -- request association */
7594 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7595 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7596 priv->status &= ~STATUS_ROAMING;
7597}
7598
James Ketrenosc848d0a2005-08-24 21:56:24 -05007599static void ipw_bg_roam(void *data)
7600{
7601 struct ipw_priv *priv = data;
7602 down(&priv->sem);
7603 ipw_roam(data);
7604 up(&priv->sem);
7605}
7606
7607static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007608{
7609 struct ipw_priv *priv = data;
7610
7611 struct ieee80211_network *network = NULL;
7612 struct ipw_network_match match = {
7613 .network = NULL
7614 };
7615 struct ipw_supported_rates *rates;
7616 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007617 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007618
James Ketrenosb095c382005-08-24 22:04:42 -05007619 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7620 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7621 return 0;
7622 }
7623
James Ketrenosc848d0a2005-08-24 21:56:24 -05007624 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007625 IPW_DEBUG_ASSOC("Not attempting association (already in "
7626 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007627 return 0;
7628 }
7629
7630 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007631 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7632 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007633 return 0;
7634 }
7635
James Ketrenos43f66a62005-03-25 12:31:53 -06007636 if (!(priv->config & CFG_ASSOCIATE) &&
7637 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007638 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007639 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007640 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007641 }
7642
James Ketrenosa613bff2005-08-24 21:43:11 -05007643 /* Protect our use of the network_list */
7644 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007645 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007646 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007647
7648 network = match.network;
7649 rates = &match.rates;
7650
7651 if (network == NULL &&
7652 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7653 priv->config & CFG_ADHOC_CREATE &&
7654 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007655 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007656 !list_empty(&priv->ieee->network_free_list)) {
7657 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007658 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007659 ipw_adhoc_create(priv, network);
7660 rates = &priv->rates;
7661 list_del(element);
7662 list_add_tail(&network->list, &priv->ieee->network_list);
7663 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007664 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007665
James Ketrenos43f66a62005-03-25 12:31:53 -06007666 /* If we reached the end of the list, then we don't have any valid
7667 * matching APs */
7668 if (!network) {
7669 ipw_debug_config(priv);
7670
James Ketrenosb095c382005-08-24 22:04:42 -05007671 if (!(priv->status & STATUS_SCANNING)) {
7672 if (!(priv->config & CFG_SPEED_SCAN))
7673 queue_delayed_work(priv->workqueue,
7674 &priv->request_scan,
7675 SCAN_INTERVAL);
7676 else
7677 queue_work(priv->workqueue,
7678 &priv->request_scan);
7679 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007680
James Ketrenosc848d0a2005-08-24 21:56:24 -05007681 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007682 }
7683
7684 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007685
7686 return 1;
7687}
7688
7689static void ipw_bg_associate(void *data)
7690{
7691 struct ipw_priv *priv = data;
7692 down(&priv->sem);
7693 ipw_associate(data);
7694 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007695}
Jeff Garzikbf794512005-07-31 13:07:26 -04007696
James Ketrenosb095c382005-08-24 22:04:42 -05007697static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7698 struct sk_buff *skb)
7699{
7700 struct ieee80211_hdr *hdr;
7701 u16 fc;
7702
7703 hdr = (struct ieee80211_hdr *)skb->data;
7704 fc = le16_to_cpu(hdr->frame_ctl);
7705 if (!(fc & IEEE80211_FCTL_PROTECTED))
7706 return;
7707
7708 fc &= ~IEEE80211_FCTL_PROTECTED;
7709 hdr->frame_ctl = cpu_to_le16(fc);
7710 switch (priv->ieee->sec.level) {
7711 case SEC_LEVEL_3:
7712 /* Remove CCMP HDR */
7713 memmove(skb->data + IEEE80211_3ADDR_LEN,
7714 skb->data + IEEE80211_3ADDR_LEN + 8,
7715 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yia2d73e62005-07-13 12:24:51 -05007716 if (fc & IEEE80211_FCTL_MOREFRAGS)
7717 skb_trim(skb, skb->len - 16); /* 2*MIC */
7718 else
7719 skb_trim(skb, skb->len - 8); /* MIC */
James Ketrenosb095c382005-08-24 22:04:42 -05007720 break;
7721 case SEC_LEVEL_2:
7722 break;
7723 case SEC_LEVEL_1:
7724 /* Remove IV */
7725 memmove(skb->data + IEEE80211_3ADDR_LEN,
7726 skb->data + IEEE80211_3ADDR_LEN + 4,
7727 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yia2d73e62005-07-13 12:24:51 -05007728 if (fc & IEEE80211_FCTL_MOREFRAGS)
7729 skb_trim(skb, skb->len - 8); /* 2*ICV */
7730 else
7731 skb_trim(skb, skb->len - 4); /* ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007732 break;
7733 case SEC_LEVEL_0:
7734 break;
7735 default:
7736 printk(KERN_ERR "Unknow security level %d\n",
7737 priv->ieee->sec.level);
7738 break;
7739 }
7740}
7741
7742static void ipw_handle_data_packet(struct ipw_priv *priv,
7743 struct ipw_rx_mem_buffer *rxb,
7744 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007745{
7746 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7747
7748 /* We received data from the HW, so stop the watchdog */
7749 priv->net_dev->trans_start = jiffies;
7750
Jeff Garzikbf794512005-07-31 13:07:26 -04007751 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007752 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007753 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007754 skb_tailroom(rxb->skb))) {
7755 priv->ieee->stats.rx_errors++;
7756 priv->wstats.discard.misc++;
7757 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7758 return;
7759 } else if (unlikely(!netif_running(priv->net_dev))) {
7760 priv->ieee->stats.rx_dropped++;
7761 priv->wstats.discard.misc++;
7762 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7763 return;
7764 }
7765
7766 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007767 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007768
7769 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007770 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007771
7772 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7773
James Ketrenosb095c382005-08-24 22:04:42 -05007774 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7775 if (!priv->ieee->host_decrypt)
7776 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7777
Jeff Garzikbf794512005-07-31 13:07:26 -04007778 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007779 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007780 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007781 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007782 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007783 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007784}
7785
James Ketrenosea2b26e2005-08-24 21:25:16 -05007786static inline int is_network_packet(struct ipw_priv *priv,
7787 struct ieee80211_hdr_4addr *header)
7788{
7789 /* Filter incoming packets to determine if they are targetted toward
7790 * this network, discarding packets coming from ourselves */
7791 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007792 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007793 /* packets from our adapter are dropped (echo) */
7794 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7795 return 0;
7796
James Ketrenosafbf30a2005-08-25 00:05:33 -05007797 /* multicast packets to our IBSS go through */
7798 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007799 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007800
7801 /* packets to our adapter go through */
7802 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7803 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007804
7805 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007806 /* packets from our adapter are dropped (echo) */
7807 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7808 return 0;
7809
James Ketrenosa613bff2005-08-24 21:43:11 -05007810 /* {broad,multi}cast packets to our IBSS go through */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007811 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007812 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7813
7814 /* packets to our adapter go through */
7815 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7816 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007817 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007818
James Ketrenosea2b26e2005-08-24 21:25:16 -05007819 return 1;
7820}
7821
James Ketrenosafbf30a2005-08-25 00:05:33 -05007822#define IPW_PACKET_RETRY_TIME HZ
7823
7824static inline int is_duplicate_packet(struct ipw_priv *priv,
7825 struct ieee80211_hdr_4addr *header)
7826{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007827 u16 sc = le16_to_cpu(header->seq_ctl);
7828 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7829 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7830 u16 *last_seq, *last_frag;
7831 unsigned long *last_time;
7832
7833 switch (priv->ieee->iw_mode) {
7834 case IW_MODE_ADHOC:
7835 {
7836 struct list_head *p;
7837 struct ipw_ibss_seq *entry = NULL;
7838 u8 *mac = header->addr2;
7839 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7840
7841 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7842 entry =
7843 list_entry(p, struct ipw_ibss_seq, list);
7844 if (!memcmp(entry->mac, mac, ETH_ALEN))
7845 break;
7846 }
7847 if (p == &priv->ibss_mac_hash[index]) {
7848 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7849 if (!entry) {
7850 IPW_ERROR
7851 ("Cannot malloc new mac entry\n");
7852 return 0;
7853 }
7854 memcpy(entry->mac, mac, ETH_ALEN);
7855 entry->seq_num = seq;
7856 entry->frag_num = frag;
7857 entry->packet_time = jiffies;
7858 list_add(&entry->list,
7859 &priv->ibss_mac_hash[index]);
7860 return 0;
7861 }
7862 last_seq = &entry->seq_num;
7863 last_frag = &entry->frag_num;
7864 last_time = &entry->packet_time;
7865 break;
7866 }
7867 case IW_MODE_INFRA:
7868 last_seq = &priv->last_seq_num;
7869 last_frag = &priv->last_frag_num;
7870 last_time = &priv->last_packet_time;
7871 break;
7872 default:
7873 return 0;
7874 }
7875 if ((*last_seq == seq) &&
7876 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7877 if (*last_frag == frag)
7878 goto drop;
7879 if (*last_frag + 1 != frag)
7880 /* out-of-order fragment */
7881 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007882 } else
7883 *last_seq = seq;
7884
Zhu Yif57ce7c2005-07-13 12:22:15 -05007885 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007886 *last_time = jiffies;
7887 return 0;
7888
7889 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007890 /* Comment this line now since we observed the card receives
7891 * duplicate packets but the FCTL_RETRY bit is not set in the
7892 * IBSS mode with fragmentation enabled.
7893 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007894 return 1;
7895}
7896
James Ketrenosb095c382005-08-24 22:04:42 -05007897static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7898 struct ipw_rx_mem_buffer *rxb,
7899 struct ieee80211_rx_stats *stats)
7900{
7901 struct sk_buff *skb = rxb->skb;
7902 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7903 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7904 (skb->data + IPW_RX_FRAME_SIZE);
7905
7906 ieee80211_rx_mgt(priv->ieee, header, stats);
7907
7908 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7909 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7910 IEEE80211_STYPE_PROBE_RESP) ||
7911 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7912 IEEE80211_STYPE_BEACON))) {
7913 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7914 ipw_add_station(priv, header->addr2);
7915 }
7916
7917 if (priv->config & CFG_NET_STATS) {
7918 IPW_DEBUG_HC("sending stat packet\n");
7919
7920 /* Set the size of the skb to the size of the full
7921 * ipw header and 802.11 frame */
7922 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7923 IPW_RX_FRAME_SIZE);
7924
7925 /* Advance past the ipw packet header to the 802.11 frame */
7926 skb_pull(skb, IPW_RX_FRAME_SIZE);
7927
7928 /* Push the ieee80211_rx_stats before the 802.11 frame */
7929 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7930
7931 skb->dev = priv->ieee->dev;
7932
7933 /* Point raw at the ieee80211_stats */
7934 skb->mac.raw = skb->data;
7935
7936 skb->pkt_type = PACKET_OTHERHOST;
7937 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7938 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7939 netif_rx(skb);
7940 rxb->skb = NULL;
7941 }
7942}
7943
James Ketrenos43f66a62005-03-25 12:31:53 -06007944/*
7945 * Main entry function for recieving a packet with 80211 headers. This
7946 * should be called when ever the FW has notified us that there is a new
7947 * skb in the recieve queue.
7948 */
7949static void ipw_rx(struct ipw_priv *priv)
7950{
7951 struct ipw_rx_mem_buffer *rxb;
7952 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007953 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007954 u32 r, w, i;
7955 u8 network_packet;
7956
James Ketrenosb095c382005-08-24 22:04:42 -05007957 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7958 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007959 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7960
7961 while (i != r) {
7962 rxb = priv->rxq->queue[i];
7963#ifdef CONFIG_IPW_DEBUG
7964 if (unlikely(rxb == NULL)) {
7965 printk(KERN_CRIT "Queue not allocated!\n");
7966 break;
7967 }
7968#endif
7969 priv->rxq->queue[i] = NULL;
7970
7971 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007972 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007973 PCI_DMA_FROMDEVICE);
7974
7975 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7976 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7977 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007978 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007979
7980 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007981 case RX_FRAME_TYPE: /* 802.11 frame */ {
7982 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007983 .rssi =
7984 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007985 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007986 .signal =
7987 le16_to_cpu(pkt->u.frame.signal),
7988 .noise =
7989 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007990 .rate = pkt->u.frame.rate,
7991 .mac_time = jiffies,
7992 .received_channel =
7993 pkt->u.frame.received_channel,
7994 .freq =
7995 (pkt->u.frame.
7996 control & (1 << 0)) ?
7997 IEEE80211_24GHZ_BAND :
7998 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007999 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008000 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008001
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008002 if (stats.rssi != 0)
8003 stats.mask |= IEEE80211_STATMASK_RSSI;
8004 if (stats.signal != 0)
8005 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008006 if (stats.noise != 0)
8007 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008008 if (stats.rate != 0)
8009 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008010
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008011 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008012
James Ketrenosb095c382005-08-24 22:04:42 -05008013#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008014 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8015 ipw_handle_data_packet(priv, rxb,
8016 &stats);
8017 break;
8018 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008019#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008020
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008021 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008022 (struct ieee80211_hdr_4addr *)(rxb->skb->
8023 data +
8024 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008025 /* TODO: Check Ad-Hoc dest/source and make sure
8026 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008027 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008028 * frame control of the packet and disregard
8029 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008030
James Ketrenosea2b26e2005-08-24 21:25:16 -05008031 network_packet =
8032 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008033 if (network_packet && priv->assoc_network) {
8034 priv->assoc_network->stats.rssi =
8035 stats.rssi;
8036 average_add(&priv->average_rssi,
8037 stats.rssi);
8038 priv->last_rx_rssi = stats.rssi;
8039 }
8040
8041 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008042 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008043
James Ketrenosa613bff2005-08-24 21:43:11 -05008044 if (le16_to_cpu(pkt->u.frame.length) <
8045 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008046 IPW_DEBUG_DROP
8047 ("Received packet is too small. "
8048 "Dropping.\n");
8049 priv->ieee->stats.rx_errors++;
8050 priv->wstats.discard.misc++;
8051 break;
8052 }
8053
James Ketrenosa613bff2005-08-24 21:43:11 -05008054 switch (WLAN_FC_GET_TYPE
8055 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008056
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008057 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008058 ipw_handle_mgmt_packet(priv, rxb,
8059 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008060 break;
8061
8062 case IEEE80211_FTYPE_CTL:
8063 break;
8064
8065 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008066 if (unlikely(!network_packet ||
8067 is_duplicate_packet(priv,
8068 header)))
8069 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008070 IPW_DEBUG_DROP("Dropping: "
8071 MAC_FMT ", "
8072 MAC_FMT ", "
8073 MAC_FMT "\n",
8074 MAC_ARG(header->
8075 addr1),
8076 MAC_ARG(header->
8077 addr2),
8078 MAC_ARG(header->
8079 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008080 break;
8081 }
8082
8083 ipw_handle_data_packet(priv, rxb,
8084 &stats);
8085
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008086 break;
8087 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008088 break;
8089 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008090
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008091 case RX_HOST_NOTIFICATION_TYPE:{
8092 IPW_DEBUG_RX
8093 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008094 pkt->u.notification.subtype,
8095 pkt->u.notification.flags,
8096 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008097 ipw_rx_notification(priv, &pkt->u.notification);
8098 break;
8099 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008100
8101 default:
8102 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8103 pkt->header.message_type);
8104 break;
8105 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008106
8107 /* For now we just don't re-use anything. We can tweak this
8108 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008109 * fail to Rx correctly */
8110 if (rxb->skb != NULL) {
8111 dev_kfree_skb_any(rxb->skb);
8112 rxb->skb = NULL;
8113 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008114
James Ketrenos43f66a62005-03-25 12:31:53 -06008115 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008116 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008117 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008118
James Ketrenos43f66a62005-03-25 12:31:53 -06008119 i = (i + 1) % RX_QUEUE_SIZE;
8120 }
8121
8122 /* Backtrack one entry */
8123 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8124
8125 ipw_rx_queue_restock(priv);
8126}
8127
James Ketrenosafbf30a2005-08-25 00:05:33 -05008128#define DEFAULT_RTS_THRESHOLD 2304U
8129#define MIN_RTS_THRESHOLD 1U
8130#define MAX_RTS_THRESHOLD 2304U
8131#define DEFAULT_BEACON_INTERVAL 100U
8132#define DEFAULT_SHORT_RETRY_LIMIT 7U
8133#define DEFAULT_LONG_RETRY_LIMIT 4U
8134
8135static int ipw_sw_reset(struct ipw_priv *priv, int init)
8136{
8137 int band, modulation;
8138 int old_mode = priv->ieee->iw_mode;
8139
8140 /* Initialize module parameter values here */
8141 priv->config = 0;
8142
8143 /* We default to disabling the LED code as right now it causes
8144 * too many systems to lock up... */
8145 if (!led)
8146 priv->config |= CFG_NO_LED;
8147
8148 if (associate)
8149 priv->config |= CFG_ASSOCIATE;
8150 else
8151 IPW_DEBUG_INFO("Auto associate disabled.\n");
8152
8153 if (auto_create)
8154 priv->config |= CFG_ADHOC_CREATE;
8155 else
8156 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8157
8158 if (disable) {
8159 priv->status |= STATUS_RF_KILL_SW;
8160 IPW_DEBUG_INFO("Radio disabled.\n");
8161 }
8162
8163 if (channel != 0) {
8164 priv->config |= CFG_STATIC_CHANNEL;
8165 priv->channel = channel;
8166 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8167 /* TODO: Validate that provided channel is in range */
8168 }
8169#ifdef CONFIG_IPW_QOS
8170 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8171 burst_duration_CCK, burst_duration_OFDM);
8172#endif /* CONFIG_IPW_QOS */
8173
8174 switch (mode) {
8175 case 1:
8176 priv->ieee->iw_mode = IW_MODE_ADHOC;
8177 priv->net_dev->type = ARPHRD_ETHER;
8178
8179 break;
8180#ifdef CONFIG_IPW2200_MONITOR
8181 case 2:
8182 priv->ieee->iw_mode = IW_MODE_MONITOR;
8183 priv->net_dev->type = ARPHRD_IEEE80211;
8184 break;
8185#endif
8186 default:
8187 case 0:
8188 priv->net_dev->type = ARPHRD_ETHER;
8189 priv->ieee->iw_mode = IW_MODE_INFRA;
8190 break;
8191 }
8192
8193 if (hwcrypto) {
8194 priv->ieee->host_encrypt = 0;
8195 priv->ieee->host_encrypt_msdu = 0;
8196 priv->ieee->host_decrypt = 0;
8197 }
8198 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8199
Zhu Yie402c932005-08-05 17:20:40 +08008200 /* IPW2200/2915 is abled to do hardware fragmentation. */
8201 priv->ieee->host_open_frag = 0;
8202
James Ketrenosafbf30a2005-08-25 00:05:33 -05008203 if ((priv->pci_dev->device == 0x4223) ||
8204 (priv->pci_dev->device == 0x4224)) {
8205 if (init)
8206 printk(KERN_INFO DRV_NAME
8207 ": Detected Intel PRO/Wireless 2915ABG Network "
8208 "Connection\n");
8209 priv->ieee->abg_true = 1;
8210 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8211 modulation = IEEE80211_OFDM_MODULATION |
8212 IEEE80211_CCK_MODULATION;
8213 priv->adapter = IPW_2915ABG;
8214 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8215 } else {
8216 if (init)
8217 printk(KERN_INFO DRV_NAME
8218 ": Detected Intel PRO/Wireless 2200BG Network "
8219 "Connection\n");
8220
8221 priv->ieee->abg_true = 0;
8222 band = IEEE80211_24GHZ_BAND;
8223 modulation = IEEE80211_OFDM_MODULATION |
8224 IEEE80211_CCK_MODULATION;
8225 priv->adapter = IPW_2200BG;
8226 priv->ieee->mode = IEEE_G | IEEE_B;
8227 }
8228
8229 priv->ieee->freq_band = band;
8230 priv->ieee->modulation = modulation;
8231
8232 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8233
8234 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8235 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8236
8237 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8238 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8239 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8240
8241 /* If power management is turned on, default to AC mode */
8242 priv->power_mode = IPW_POWER_AC;
8243 priv->tx_power = IPW_TX_POWER_DEFAULT;
8244
Zhu Yi0ece35b2005-08-05 17:26:51 +08008245 return old_mode == priv->ieee->iw_mode;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008246}
8247
James Ketrenos43f66a62005-03-25 12:31:53 -06008248/*
8249 * This file defines the Wireless Extension handlers. It does not
8250 * define any methods of hardware manipulation and relies on the
8251 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008252 *
8253 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008254 * function used to poll the hardware vs. making unecessary calls.
8255 *
8256 */
8257
Jeff Garzikbf794512005-07-31 13:07:26 -04008258static int ipw_wx_get_name(struct net_device *dev,
8259 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008260 union iwreq_data *wrqu, char *extra)
8261{
8262 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008263 down(&priv->sem);
8264 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008265 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008266 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008267 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008268 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008269 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8270 ipw_modes[priv->assoc_request.ieee_mode]);
8271 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008272 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008273 return 0;
8274}
8275
8276static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8277{
8278 if (channel == 0) {
8279 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8280 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008281 IPW_DEBUG_ASSOC("Attempting to associate with new "
8282 "parameters.\n");
8283 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008284 return 0;
8285 }
8286
8287 priv->config |= CFG_STATIC_CHANNEL;
8288
8289 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008290 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8291 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008292 return 0;
8293 }
8294
8295 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8296 priv->channel = channel;
8297
James Ketrenosb095c382005-08-24 22:04:42 -05008298#ifdef CONFIG_IPW2200_MONITOR
8299 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008300 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008301 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008302 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008303 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008304 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008305 }
8306
8307 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8308 udelay(10);
8309
8310 if (priv->status & STATUS_SCANNING)
8311 IPW_DEBUG_SCAN("Still scanning...\n");
8312 else
8313 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8314 1000 - i);
8315
8316 return 0;
8317 }
8318#endif /* CONFIG_IPW2200_MONITOR */
8319
James Ketrenosc848d0a2005-08-24 21:56:24 -05008320 /* Network configuration changed -- force [re]association */
8321 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8322 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008323 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008324
8325 return 0;
8326}
8327
Jeff Garzikbf794512005-07-31 13:07:26 -04008328static int ipw_wx_set_freq(struct net_device *dev,
8329 struct iw_request_info *info,
8330 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008331{
8332 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008333 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008334 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008335 int ret = 0, i;
James Ketrenosb095c382005-08-24 22:04:42 -05008336 u8 channel;
8337
8338 if (fwrq->m == 0) {
8339 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8340 down(&priv->sem);
8341 ret = ipw_set_channel(priv, 0);
8342 up(&priv->sem);
8343 return ret;
8344 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008345 /* if setting by freq convert to channel */
8346 if (fwrq->e == 1) {
James Ketrenosb095c382005-08-24 22:04:42 -05008347 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8348 if (channel == 0)
8349 return -EINVAL;
8350 } else
8351 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008352
James Ketrenosb095c382005-08-24 22:04:42 -05008353 if (!ieee80211_is_valid_channel(priv->ieee, channel))
8354 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008355
James Ketrenosafbf30a2005-08-25 00:05:33 -05008356 if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
8357 i = ieee80211_channel_to_index(priv->ieee, channel);
8358 if (i == -1)
8359 return -EINVAL;
8360 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
8361 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8362 return -EINVAL;
8363 }
8364 }
8365
James Ketrenos43f66a62005-03-25 12:31:53 -06008366 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008367 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008368 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008369 up(&priv->sem);
8370 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008371}
8372
Jeff Garzikbf794512005-07-31 13:07:26 -04008373static int ipw_wx_get_freq(struct net_device *dev,
8374 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008375 union iwreq_data *wrqu, char *extra)
8376{
8377 struct ipw_priv *priv = ieee80211_priv(dev);
8378
8379 wrqu->freq.e = 0;
8380
8381 /* If we are associated, trying to associate, or have a statically
8382 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008383 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008384 if (priv->config & CFG_STATIC_CHANNEL ||
8385 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8386 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008387 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008388 wrqu->freq.m = 0;
8389
James Ketrenosc848d0a2005-08-24 21:56:24 -05008390 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008391 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8392 return 0;
8393}
8394
Jeff Garzikbf794512005-07-31 13:07:26 -04008395static int ipw_wx_set_mode(struct net_device *dev,
8396 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008397 union iwreq_data *wrqu, char *extra)
8398{
8399 struct ipw_priv *priv = ieee80211_priv(dev);
8400 int err = 0;
8401
8402 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06008403
8404 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008405#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008406 case IW_MODE_MONITOR:
8407#endif
8408 case IW_MODE_ADHOC:
8409 case IW_MODE_INFRA:
8410 break;
8411 case IW_MODE_AUTO:
8412 wrqu->mode = IW_MODE_INFRA;
8413 break;
8414 default:
8415 return -EINVAL;
8416 }
James Ketrenosb095c382005-08-24 22:04:42 -05008417 if (wrqu->mode == priv->ieee->iw_mode)
8418 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008419
James Ketrenosb095c382005-08-24 22:04:42 -05008420 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008421
8422 ipw_sw_reset(priv, 0);
8423
James Ketrenosb095c382005-08-24 22:04:42 -05008424#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008425 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008426 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008427
8428 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008429 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosb095c382005-08-24 22:04:42 -05008430#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008431
Jeff Garzikbf794512005-07-31 13:07:26 -04008432 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008433 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008434 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008435
8436 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008437
James Ketrenosc848d0a2005-08-24 21:56:24 -05008438 queue_work(priv->workqueue, &priv->adapter_restart);
8439 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008440 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008441}
8442
Jeff Garzikbf794512005-07-31 13:07:26 -04008443static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008444 struct iw_request_info *info,
8445 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008446{
8447 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008448 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008449 wrqu->mode = priv->ieee->iw_mode;
8450 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008451 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008452 return 0;
8453}
8454
James Ketrenos43f66a62005-03-25 12:31:53 -06008455/* Values are in microsecond */
8456static const s32 timeout_duration[] = {
8457 350000,
8458 250000,
8459 75000,
8460 37000,
8461 25000,
8462};
8463
8464static const s32 period_duration[] = {
8465 400000,
8466 700000,
8467 1000000,
8468 1000000,
8469 1000000
8470};
8471
Jeff Garzikbf794512005-07-31 13:07:26 -04008472static int ipw_wx_get_range(struct net_device *dev,
8473 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008474 union iwreq_data *wrqu, char *extra)
8475{
8476 struct ipw_priv *priv = ieee80211_priv(dev);
8477 struct iw_range *range = (struct iw_range *)extra;
James Ketrenosb095c382005-08-24 22:04:42 -05008478 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8479 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008480
8481 wrqu->data.length = sizeof(*range);
8482 memset(range, 0, sizeof(*range));
8483
8484 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008485 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008486
8487 range->max_qual.qual = 100;
8488 /* TODO: Find real max RSSI and stick here */
8489 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008490 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008491 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008492
8493 range->avg_qual.qual = 70;
8494 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008495 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008496 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008497 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008498 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008499 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008500
Jeff Garzikbf794512005-07-31 13:07:26 -04008501 for (i = 0; i < range->num_bitrates; i++)
8502 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008503 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008504
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 range->max_rts = DEFAULT_RTS_THRESHOLD;
8506 range->min_frag = MIN_FRAG_THRESHOLD;
8507 range->max_frag = MAX_FRAG_THRESHOLD;
8508
8509 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008510 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008511 range->num_encoding_sizes = 2;
8512 range->max_encoding_tokens = WEP_KEYS;
8513
8514 /* Set the Wireless Extension versions */
8515 range->we_version_compiled = WIRELESS_EXT;
8516 range->we_version_source = 16;
8517
James Ketrenosb095c382005-08-24 22:04:42 -05008518 i = 0;
8519 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8520 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8521 i++, j++) {
8522 range->freq[i].i = geo->bg[j].channel;
8523 range->freq[i].m = geo->bg[j].freq * 100000;
8524 range->freq[i].e = 1;
8525 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008526 }
James Ketrenosb095c382005-08-24 22:04:42 -05008527
8528 if (priv->ieee->mode & IEEE_A) {
8529 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8530 i++, j++) {
8531 range->freq[i].i = geo->a[j].channel;
8532 range->freq[i].m = geo->a[j].freq * 100000;
8533 range->freq[i].e = 1;
8534 }
8535 }
8536
8537 range->num_channels = i;
8538 range->num_frequency = i;
8539
James Ketrenosc848d0a2005-08-24 21:56:24 -05008540 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008541 IPW_DEBUG_WX("GET Range\n");
8542 return 0;
8543}
8544
Jeff Garzikbf794512005-07-31 13:07:26 -04008545static int ipw_wx_set_wap(struct net_device *dev,
8546 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008547 union iwreq_data *wrqu, char *extra)
8548{
8549 struct ipw_priv *priv = ieee80211_priv(dev);
8550
8551 static const unsigned char any[] = {
8552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8553 };
8554 static const unsigned char off[] = {
8555 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8556 };
8557
Jeff Garzikbf794512005-07-31 13:07:26 -04008558 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008559 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008560 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008561 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8562 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8563 /* we disable mandatory BSSID association */
8564 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8565 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008566 IPW_DEBUG_ASSOC("Attempting to associate with new "
8567 "parameters.\n");
8568 ipw_associate(priv);
8569 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008570 return 0;
8571 }
8572
8573 priv->config |= CFG_STATIC_BSSID;
8574 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8575 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008576 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 return 0;
8578 }
8579
8580 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8581 MAC_ARG(wrqu->ap_addr.sa_data));
8582
8583 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8584
James Ketrenosc848d0a2005-08-24 21:56:24 -05008585 /* Network configuration changed -- force [re]association */
8586 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8587 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008588 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008589
James Ketrenosc848d0a2005-08-24 21:56:24 -05008590 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008591 return 0;
8592}
8593
Jeff Garzikbf794512005-07-31 13:07:26 -04008594static int ipw_wx_get_wap(struct net_device *dev,
8595 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 union iwreq_data *wrqu, char *extra)
8597{
8598 struct ipw_priv *priv = ieee80211_priv(dev);
8599 /* If we are associated, trying to associate, or have a statically
8600 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008601 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008602 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008603 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8604 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008605 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008606 } else
8607 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8608
8609 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8610 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008611 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008612 return 0;
8613}
8614
Jeff Garzikbf794512005-07-31 13:07:26 -04008615static int ipw_wx_set_essid(struct net_device *dev,
8616 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008617 union iwreq_data *wrqu, char *extra)
8618{
8619 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008620 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008621 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008622 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008623 if (wrqu->essid.flags && wrqu->essid.length) {
8624 length = wrqu->essid.length - 1;
8625 essid = extra;
8626 }
8627 if (length == 0) {
8628 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008629 if ((priv->config & CFG_STATIC_ESSID) &&
8630 !(priv->status & (STATUS_ASSOCIATED |
8631 STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008632 IPW_DEBUG_ASSOC("Attempting to associate with new "
8633 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008634 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008635 ipw_associate(priv);
8636 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008637 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008638 return 0;
8639 }
8640
8641 length = min(length, IW_ESSID_MAX_SIZE);
8642
8643 priv->config |= CFG_STATIC_ESSID;
8644
8645 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8646 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008647 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008648 return 0;
8649 }
8650
8651 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8652 length);
8653
8654 priv->essid_len = length;
8655 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008656
James Ketrenosc848d0a2005-08-24 21:56:24 -05008657 /* Network configuration changed -- force [re]association */
8658 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8659 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008660 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008661
James Ketrenosc848d0a2005-08-24 21:56:24 -05008662 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008663 return 0;
8664}
8665
Jeff Garzikbf794512005-07-31 13:07:26 -04008666static int ipw_wx_get_essid(struct net_device *dev,
8667 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008668 union iwreq_data *wrqu, char *extra)
8669{
8670 struct ipw_priv *priv = ieee80211_priv(dev);
8671
8672 /* If we are associated, trying to associate, or have a statically
8673 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008674 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008675 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008676 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8677 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008678 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008679 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008680 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008681 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008682 } else {
8683 IPW_DEBUG_WX("Getting essid: ANY\n");
8684 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008685 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008686 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008687 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008688 return 0;
8689}
8690
Jeff Garzikbf794512005-07-31 13:07:26 -04008691static int ipw_wx_set_nick(struct net_device *dev,
8692 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008693 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008694{
James Ketrenos43f66a62005-03-25 12:31:53 -06008695 struct ipw_priv *priv = ieee80211_priv(dev);
8696
8697 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8698 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8699 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008700 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008701 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008702 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008703 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008704 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008705 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008706 return 0;
8707
8708}
8709
Jeff Garzikbf794512005-07-31 13:07:26 -04008710static int ipw_wx_get_nick(struct net_device *dev,
8711 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008712 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008713{
James Ketrenos43f66a62005-03-25 12:31:53 -06008714 struct ipw_priv *priv = ieee80211_priv(dev);
8715 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008716 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008717 wrqu->data.length = strlen(priv->nick) + 1;
8718 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008719 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008720 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008721 return 0;
8722}
8723
James Ketrenos43f66a62005-03-25 12:31:53 -06008724static int ipw_wx_set_rate(struct net_device *dev,
8725 struct iw_request_info *info,
8726 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008727{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008728 /* TODO: We should use semaphores or locks for access to priv */
8729 struct ipw_priv *priv = ieee80211_priv(dev);
8730 u32 target_rate = wrqu->bitrate.value;
8731 u32 fixed, mask;
8732
8733 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8734 /* value = X, fixed = 1 means only rate X */
8735 /* value = X, fixed = 0 means all rates lower equal X */
8736
8737 if (target_rate == -1) {
8738 fixed = 0;
8739 mask = IEEE80211_DEFAULT_RATES_MASK;
8740 /* Now we should reassociate */
8741 goto apply;
8742 }
8743
8744 mask = 0;
8745 fixed = wrqu->bitrate.fixed;
8746
8747 if (target_rate == 1000000 || !fixed)
8748 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8749 if (target_rate == 1000000)
8750 goto apply;
8751
8752 if (target_rate == 2000000 || !fixed)
8753 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8754 if (target_rate == 2000000)
8755 goto apply;
8756
8757 if (target_rate == 5500000 || !fixed)
8758 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8759 if (target_rate == 5500000)
8760 goto apply;
8761
8762 if (target_rate == 6000000 || !fixed)
8763 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8764 if (target_rate == 6000000)
8765 goto apply;
8766
8767 if (target_rate == 9000000 || !fixed)
8768 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8769 if (target_rate == 9000000)
8770 goto apply;
8771
8772 if (target_rate == 11000000 || !fixed)
8773 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8774 if (target_rate == 11000000)
8775 goto apply;
8776
8777 if (target_rate == 12000000 || !fixed)
8778 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8779 if (target_rate == 12000000)
8780 goto apply;
8781
8782 if (target_rate == 18000000 || !fixed)
8783 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8784 if (target_rate == 18000000)
8785 goto apply;
8786
8787 if (target_rate == 24000000 || !fixed)
8788 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8789 if (target_rate == 24000000)
8790 goto apply;
8791
8792 if (target_rate == 36000000 || !fixed)
8793 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8794 if (target_rate == 36000000)
8795 goto apply;
8796
8797 if (target_rate == 48000000 || !fixed)
8798 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8799 if (target_rate == 48000000)
8800 goto apply;
8801
8802 if (target_rate == 54000000 || !fixed)
8803 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8804 if (target_rate == 54000000)
8805 goto apply;
8806
8807 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8808 return -EINVAL;
8809
8810 apply:
8811 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8812 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008813 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008814 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008815 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008816 ipw_set_fixed_rate(priv, priv->ieee->mode);
8817 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008818 priv->config |= CFG_FIXED_RATE;
8819
James Ketrenosc848d0a2005-08-24 21:56:24 -05008820 if (priv->rates_mask == mask) {
8821 IPW_DEBUG_WX("Mask set to current mask.\n");
8822 up(&priv->sem);
8823 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008824 }
8825
James Ketrenosc848d0a2005-08-24 21:56:24 -05008826 priv->rates_mask = mask;
8827
8828 /* Network configuration changed -- force [re]association */
8829 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8830 if (!ipw_disassociate(priv))
8831 ipw_associate(priv);
8832
8833 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008834 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008835}
8836
Jeff Garzikbf794512005-07-31 13:07:26 -04008837static int ipw_wx_get_rate(struct net_device *dev,
8838 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008839 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008840{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008841 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008842 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008843 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008844 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008845 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8846 return 0;
8847}
8848
Jeff Garzikbf794512005-07-31 13:07:26 -04008849static int ipw_wx_set_rts(struct net_device *dev,
8850 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008851 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008852{
James Ketrenos43f66a62005-03-25 12:31:53 -06008853 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008854 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008855 if (wrqu->rts.disabled)
8856 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8857 else {
8858 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008859 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8860 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008862 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008863 priv->rts_threshold = wrqu->rts.value;
8864 }
8865
8866 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008867 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8869 return 0;
8870}
8871
Jeff Garzikbf794512005-07-31 13:07:26 -04008872static int ipw_wx_get_rts(struct net_device *dev,
8873 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008874 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008875{
James Ketrenos43f66a62005-03-25 12:31:53 -06008876 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008877 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008878 wrqu->rts.value = priv->rts_threshold;
8879 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008880 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008881 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008882 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8883 return 0;
8884}
8885
Jeff Garzikbf794512005-07-31 13:07:26 -04008886static int ipw_wx_set_txpow(struct net_device *dev,
8887 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008888 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008889{
James Ketrenos43f66a62005-03-25 12:31:53 -06008890 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008891 int err = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05008892
James Ketrenosc848d0a2005-08-24 21:56:24 -05008893 down(&priv->sem);
8894 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008895 err = -EINPROGRESS;
8896 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008897 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008898
James Ketrenosb095c382005-08-24 22:04:42 -05008899 if (!wrqu->power.fixed)
8900 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8901
James Ketrenosc848d0a2005-08-24 21:56:24 -05008902 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008903 err = -EINVAL;
8904 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008905 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008906
James Ketrenosb095c382005-08-24 22:04:42 -05008907 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008908 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008909 err = -EINVAL;
8910 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008911 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008912
8913 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008914 err = ipw_set_tx_power(priv);
8915 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008916 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008917 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008918}
8919
Jeff Garzikbf794512005-07-31 13:07:26 -04008920static int ipw_wx_get_txpow(struct net_device *dev,
8921 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008922 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008923{
James Ketrenos43f66a62005-03-25 12:31:53 -06008924 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008925 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 wrqu->power.value = priv->tx_power;
8927 wrqu->power.fixed = 1;
8928 wrqu->power.flags = IW_TXPOW_DBM;
8929 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008930 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008931
Jeff Garzikbf794512005-07-31 13:07:26 -04008932 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008933 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008934
8935 return 0;
8936}
8937
Jeff Garzikbf794512005-07-31 13:07:26 -04008938static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008939 struct iw_request_info *info,
8940 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008941{
8942 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008943 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008944 if (wrqu->frag.disabled)
8945 priv->ieee->fts = DEFAULT_FTS;
8946 else {
8947 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008948 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8949 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008950 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008951 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008952
James Ketrenos43f66a62005-03-25 12:31:53 -06008953 priv->ieee->fts = wrqu->frag.value & ~0x1;
8954 }
8955
8956 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008957 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008958 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8959 return 0;
8960}
8961
Jeff Garzikbf794512005-07-31 13:07:26 -04008962static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008963 struct iw_request_info *info,
8964 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008965{
8966 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008967 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008968 wrqu->frag.value = priv->ieee->fts;
8969 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008970 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008971 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008972 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8973
8974 return 0;
8975}
8976
Jeff Garzikbf794512005-07-31 13:07:26 -04008977static int ipw_wx_set_retry(struct net_device *dev,
8978 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008979 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008980{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008981 struct ipw_priv *priv = ieee80211_priv(dev);
8982
8983 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8984 return -EINVAL;
8985
8986 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8987 return 0;
8988
8989 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8990 return -EINVAL;
8991
8992 down(&priv->sem);
8993 if (wrqu->retry.flags & IW_RETRY_MIN)
8994 priv->short_retry_limit = (u8) wrqu->retry.value;
8995 else if (wrqu->retry.flags & IW_RETRY_MAX)
8996 priv->long_retry_limit = (u8) wrqu->retry.value;
8997 else {
8998 priv->short_retry_limit = (u8) wrqu->retry.value;
8999 priv->long_retry_limit = (u8) wrqu->retry.value;
9000 }
9001
9002 ipw_send_retry_limit(priv, priv->short_retry_limit,
9003 priv->long_retry_limit);
9004 up(&priv->sem);
9005 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9006 priv->short_retry_limit, priv->long_retry_limit);
9007 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009008}
9009
Jeff Garzikbf794512005-07-31 13:07:26 -04009010static int ipw_wx_get_retry(struct net_device *dev,
9011 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009012 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009013{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009014 struct ipw_priv *priv = ieee80211_priv(dev);
9015
9016 down(&priv->sem);
9017 wrqu->retry.disabled = 0;
9018
9019 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9020 up(&priv->sem);
9021 return -EINVAL;
9022 }
9023
9024 if (wrqu->retry.flags & IW_RETRY_MAX) {
9025 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9026 wrqu->retry.value = priv->long_retry_limit;
9027 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9028 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9029 wrqu->retry.value = priv->short_retry_limit;
9030 } else {
9031 wrqu->retry.flags = IW_RETRY_LIMIT;
9032 wrqu->retry.value = priv->short_retry_limit;
9033 }
9034 up(&priv->sem);
9035
9036 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9037
9038 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009039}
9040
James Ketrenosafbf30a2005-08-25 00:05:33 -05009041#if WIRELESS_EXT > 17
9042static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9043 int essid_len)
9044{
9045 struct ipw_scan_request_ext scan;
9046 int err = 0, scan_type;
9047
9048 down(&priv->sem);
9049
9050 if (priv->status & STATUS_RF_KILL_MASK) {
9051 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9052 priv->status |= STATUS_SCAN_PENDING;
9053 goto done;
9054 }
9055
9056 IPW_DEBUG_HC("starting request direct scan!\n");
9057
9058 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9059 err = wait_event_interruptible(priv->wait_state,
9060 !(priv->
9061 status & (STATUS_SCANNING |
9062 STATUS_SCAN_ABORTING)));
9063 if (err) {
9064 IPW_DEBUG_HC("aborting direct scan");
9065 goto done;
9066 }
9067 }
9068 memset(&scan, 0, sizeof(scan));
9069
9070 if (priv->config & CFG_SPEED_SCAN)
9071 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9072 cpu_to_le16(30);
9073 else
9074 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9075 cpu_to_le16(20);
9076
9077 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9078 cpu_to_le16(20);
9079 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
9080 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9081
9082 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9083
9084 err = ipw_send_ssid(priv, essid, essid_len);
9085 if (err) {
9086 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9087 goto done;
9088 }
9089 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9090
9091 ipw_add_scan_channels(priv, &scan, scan_type);
9092
9093 err = ipw_send_scan_request_ext(priv, &scan);
9094 if (err) {
9095 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9096 goto done;
9097 }
9098
9099 priv->status |= STATUS_SCANNING;
9100
9101 done:
9102 up(&priv->sem);
9103 return err;
9104}
9105#endif /* WIRELESS_EXT > 17 */
9106
Jeff Garzikbf794512005-07-31 13:07:26 -04009107static int ipw_wx_set_scan(struct net_device *dev,
9108 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 union iwreq_data *wrqu, char *extra)
9110{
9111 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009112#if WIRELESS_EXT > 17
9113 struct iw_scan_req *req = NULL;
9114 if (wrqu->data.length
9115 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9116 req = (struct iw_scan_req *)extra;
9117 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9118 ipw_request_direct_scan(priv, req->essid,
9119 req->essid_len);
9120 return 0;
9121 }
9122 }
9123#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009124 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009125
9126 queue_work(priv->workqueue, &priv->request_scan);
9127
James Ketrenos43f66a62005-03-25 12:31:53 -06009128 return 0;
9129}
9130
Jeff Garzikbf794512005-07-31 13:07:26 -04009131static int ipw_wx_get_scan(struct net_device *dev,
9132 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009133 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009134{
James Ketrenos43f66a62005-03-25 12:31:53 -06009135 struct ipw_priv *priv = ieee80211_priv(dev);
9136 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9137}
9138
Jeff Garzikbf794512005-07-31 13:07:26 -04009139static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009140 struct iw_request_info *info,
9141 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009142{
9143 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009144 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009145 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009146
9147 down(&priv->sem);
9148 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009149
Hong Liucaeff812005-08-05 17:25:50 +08009150 /* In IBSS mode, we need to notify the firmware to update
9151 * the beacon info after we changed the capability. */
9152 if (cap != priv->capability &&
9153 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9154 priv->status & STATUS_ASSOCIATED)
9155 ipw_disassociate(priv);
9156
9157 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009158 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009159}
9160
Jeff Garzikbf794512005-07-31 13:07:26 -04009161static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009162 struct iw_request_info *info,
9163 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009164{
9165 struct ipw_priv *priv = ieee80211_priv(dev);
9166 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9167}
9168
Jeff Garzikbf794512005-07-31 13:07:26 -04009169static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009170 struct iw_request_info *info,
9171 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009172{
9173 struct ipw_priv *priv = ieee80211_priv(dev);
9174 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009175 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009176 if (wrqu->power.disabled) {
9177 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9178 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9179 if (err) {
9180 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009181 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009182 return err;
9183 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009185 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009186 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009187 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009188
9189 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009190 case IW_POWER_ON: /* If not specified */
9191 case IW_POWER_MODE: /* If set all mask */
9192 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009193 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009194 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009195 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9196 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009197 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009198 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009199 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009200
James Ketrenos43f66a62005-03-25 12:31:53 -06009201 /* If the user hasn't specified a power management mode yet, default
9202 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009203 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009204 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009205 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009206 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9207 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9208 if (err) {
9209 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009210 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009211 return err;
9212 }
9213
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009214 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009215 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009216 return 0;
9217}
9218
Jeff Garzikbf794512005-07-31 13:07:26 -04009219static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009220 struct iw_request_info *info,
9221 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009222{
9223 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009224 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009225 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009226 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009227 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009228 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009229
James Ketrenosc848d0a2005-08-24 21:56:24 -05009230 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009232
James Ketrenos43f66a62005-03-25 12:31:53 -06009233 return 0;
9234}
9235
Jeff Garzikbf794512005-07-31 13:07:26 -04009236static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009237 struct iw_request_info *info,
9238 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009239{
9240 struct ipw_priv *priv = ieee80211_priv(dev);
9241 int mode = *(int *)extra;
9242 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009243 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009244 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9245 mode = IPW_POWER_AC;
9246 priv->power_mode = mode;
9247 } else {
9248 priv->power_mode = IPW_POWER_ENABLED | mode;
9249 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009250
James Ketrenos43f66a62005-03-25 12:31:53 -06009251 if (priv->power_mode != mode) {
9252 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009253
James Ketrenos43f66a62005-03-25 12:31:53 -06009254 if (err) {
9255 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009256 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009257 return err;
9258 }
9259 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009260 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009261 return 0;
9262}
9263
9264#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009265static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009266 struct iw_request_info *info,
9267 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009268{
9269 struct ipw_priv *priv = ieee80211_priv(dev);
9270 int level = IPW_POWER_LEVEL(priv->power_mode);
9271 char *p = extra;
9272
9273 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9274
9275 switch (level) {
9276 case IPW_POWER_AC:
9277 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9278 break;
9279 case IPW_POWER_BATTERY:
9280 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9281 break;
9282 default:
9283 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009284 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009285 timeout_duration[level - 1] / 1000,
9286 period_duration[level - 1] / 1000);
9287 }
9288
9289 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009290 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009291
9292 wrqu->data.length = p - extra + 1;
9293
9294 return 0;
9295}
9296
9297static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009298 struct iw_request_info *info,
9299 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009300{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009301 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009302 int mode = *(int *)extra;
9303 u8 band = 0, modulation = 0;
9304
9305 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009306 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009307 return -EINVAL;
9308 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009309 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009310 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009311 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009312 if (mode & IEEE_A) {
9313 band |= IEEE80211_52GHZ_BAND;
9314 modulation |= IEEE80211_OFDM_MODULATION;
9315 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009316 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009317 } else {
9318 if (mode & IEEE_A) {
9319 IPW_WARNING("Attempt to set 2200BG into "
9320 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009321 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009322 return -EINVAL;
9323 }
9324
James Ketrenosa33a1982005-09-14 14:28:59 -05009325 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009326 }
9327
9328 if (mode & IEEE_B) {
9329 band |= IEEE80211_24GHZ_BAND;
9330 modulation |= IEEE80211_CCK_MODULATION;
9331 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009332 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009333
James Ketrenos43f66a62005-03-25 12:31:53 -06009334 if (mode & IEEE_G) {
9335 band |= IEEE80211_24GHZ_BAND;
9336 modulation |= IEEE80211_OFDM_MODULATION;
9337 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009338 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009339
9340 priv->ieee->mode = mode;
9341 priv->ieee->freq_band = band;
9342 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009343 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009344
James Ketrenosc848d0a2005-08-24 21:56:24 -05009345 /* Network configuration changed -- force [re]association */
9346 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9347 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009348 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009349 ipw_associate(priv);
9350 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009351
James Ketrenosa613bff2005-08-24 21:43:11 -05009352 /* Update the band LEDs */
9353 ipw_led_band_on(priv);
9354
Jeff Garzikbf794512005-07-31 13:07:26 -04009355 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009356 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009357 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009358 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009359 return 0;
9360}
9361
9362static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009363 struct iw_request_info *info,
9364 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009365{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009366 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009367 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009368 switch (priv->ieee->mode) {
9369 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009370 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9371 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009372 case IEEE_B:
9373 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9374 break;
9375 case IEEE_A | IEEE_B:
9376 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9377 break;
9378 case IEEE_G:
9379 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9380 break;
9381 case IEEE_A | IEEE_G:
9382 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9383 break;
9384 case IEEE_B | IEEE_G:
9385 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9386 break;
9387 case IEEE_A | IEEE_B | IEEE_G:
9388 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9389 break;
9390 default:
9391 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009392 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009393 }
9394
James Ketrenos43f66a62005-03-25 12:31:53 -06009395 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9396
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009397 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009398 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009399
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009400 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009401}
9402
James Ketrenosea2b26e2005-08-24 21:25:16 -05009403static int ipw_wx_set_preamble(struct net_device *dev,
9404 struct iw_request_info *info,
9405 union iwreq_data *wrqu, char *extra)
9406{
9407 struct ipw_priv *priv = ieee80211_priv(dev);
9408 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009409 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009410 /* Switching from SHORT -> LONG requires a disassociation */
9411 if (mode == 1) {
9412 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9413 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009414
9415 /* Network configuration changed -- force [re]association */
9416 IPW_DEBUG_ASSOC
9417 ("[re]association triggered due to preamble change.\n");
9418 if (!ipw_disassociate(priv))
9419 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009420 }
9421 goto done;
9422 }
9423
9424 if (mode == 0) {
9425 priv->config &= ~CFG_PREAMBLE_LONG;
9426 goto done;
9427 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009428 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009429 return -EINVAL;
9430
9431 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009432 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009433 return 0;
9434}
9435
9436static int ipw_wx_get_preamble(struct net_device *dev,
9437 struct iw_request_info *info,
9438 union iwreq_data *wrqu, char *extra)
9439{
9440 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009441 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009442 if (priv->config & CFG_PREAMBLE_LONG)
9443 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9444 else
9445 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009446 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009447 return 0;
9448}
9449
James Ketrenosb095c382005-08-24 22:04:42 -05009450#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009451static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009452 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009453 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009454{
James Ketrenos43f66a62005-03-25 12:31:53 -06009455 struct ipw_priv *priv = ieee80211_priv(dev);
9456 int *parms = (int *)extra;
9457 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009458 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009459 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009460 if (enable) {
9461 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9462 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosa613bff2005-08-24 21:43:11 -05009463 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009464 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009465
James Ketrenos43f66a62005-03-25 12:31:53 -06009466 ipw_set_channel(priv, parms[1]);
9467 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009468 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9469 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009470 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009471 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009473 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009474 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009475 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009476 return 0;
9477}
9478
James Ketrenosb095c382005-08-24 22:04:42 -05009479#endif // CONFIG_IPW2200_MONITOR
9480
Jeff Garzikbf794512005-07-31 13:07:26 -04009481static int ipw_wx_reset(struct net_device *dev,
9482 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009483 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009484{
James Ketrenos43f66a62005-03-25 12:31:53 -06009485 struct ipw_priv *priv = ieee80211_priv(dev);
9486 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009487 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009488 return 0;
9489}
James Ketrenosb095c382005-08-24 22:04:42 -05009490
James Ketrenosb095c382005-08-24 22:04:42 -05009491static int ipw_wx_sw_reset(struct net_device *dev,
9492 struct iw_request_info *info,
9493 union iwreq_data *wrqu, char *extra)
9494{
9495 struct ipw_priv *priv = ieee80211_priv(dev);
9496 union iwreq_data wrqu_sec = {
9497 .encoding = {
9498 .flags = IW_ENCODE_DISABLED,
9499 },
9500 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009501 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009502
9503 IPW_DEBUG_WX("SW_RESET\n");
9504
9505 down(&priv->sem);
9506
James Ketrenosafbf30a2005-08-25 00:05:33 -05009507 ret = ipw_sw_reset(priv, 0);
9508 if (!ret) {
9509 free_firmware();
9510 ipw_adapter_restart(priv);
9511 }
James Ketrenosb095c382005-08-24 22:04:42 -05009512
9513 /* The SW reset bit might have been toggled on by the 'disable'
9514 * module parameter, so take appropriate action */
9515 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9516
9517 up(&priv->sem);
9518 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9519 down(&priv->sem);
9520
9521 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9522 /* Configuration likely changed -- force [re]association */
9523 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9524 "reset.\n");
9525 if (!ipw_disassociate(priv))
9526 ipw_associate(priv);
9527 }
9528
9529 up(&priv->sem);
9530
9531 return 0;
9532}
James Ketrenos43f66a62005-03-25 12:31:53 -06009533
9534/* Rebase the WE IOCTLs to zero for the handler array */
9535#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009536static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009537 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9538 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9539 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9540 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9541 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9542 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9543 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9544 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9545 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9546 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9547 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9548 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9549 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9550 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9551 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9552 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9553 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9554 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9555 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9556 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9557 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9558 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9559 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9560 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9561 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9562 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9563 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9564 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009565 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9566 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9567 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9568 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009569#if WIRELESS_EXT > 17
9570 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9571 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9572 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9573 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9574 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9575 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9576 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9577#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009578};
9579
James Ketrenosb095c382005-08-24 22:04:42 -05009580enum {
9581 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9582 IPW_PRIV_GET_POWER,
9583 IPW_PRIV_SET_MODE,
9584 IPW_PRIV_GET_MODE,
9585 IPW_PRIV_SET_PREAMBLE,
9586 IPW_PRIV_GET_PREAMBLE,
9587 IPW_PRIV_RESET,
9588 IPW_PRIV_SW_RESET,
9589#ifdef CONFIG_IPW2200_MONITOR
9590 IPW_PRIV_SET_MONITOR,
9591#endif
9592};
James Ketrenos43f66a62005-03-25 12:31:53 -06009593
Jeff Garzikbf794512005-07-31 13:07:26 -04009594static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009595 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009596 .cmd = IPW_PRIV_SET_POWER,
9597 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9598 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009599 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009600 .cmd = IPW_PRIV_GET_POWER,
9601 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9602 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009603 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009604 .cmd = IPW_PRIV_SET_MODE,
9605 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9606 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009607 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009608 .cmd = IPW_PRIV_GET_MODE,
9609 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9610 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009611 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009612 .cmd = IPW_PRIV_SET_PREAMBLE,
9613 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9614 .name = "set_preamble"},
9615 {
9616 .cmd = IPW_PRIV_GET_PREAMBLE,
9617 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9618 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009619 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009620 IPW_PRIV_RESET,
9621 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009622 {
9623 IPW_PRIV_SW_RESET,
9624 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9625#ifdef CONFIG_IPW2200_MONITOR
9626 {
9627 IPW_PRIV_SET_MONITOR,
9628 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9629#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009630};
9631
9632static iw_handler ipw_priv_handler[] = {
9633 ipw_wx_set_powermode,
9634 ipw_wx_get_powermode,
9635 ipw_wx_set_wireless_mode,
9636 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009637 ipw_wx_set_preamble,
9638 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009639 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009640 ipw_wx_sw_reset,
9641#ifdef CONFIG_IPW2200_MONITOR
9642 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009643#endif
9644};
9645
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009646static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009647 .standard = ipw_wx_handlers,
9648 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9649 .num_private = ARRAY_SIZE(ipw_priv_handler),
9650 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9651 .private = ipw_priv_handler,
9652 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06009653};
9654
James Ketrenosa613bff2005-08-24 21:43:11 -05009655static struct iw_public_data ipw_wx_data;
9656
James Ketrenos43f66a62005-03-25 12:31:53 -06009657/*
9658 * Get wireless statistics.
9659 * Called by /proc/net/wireless
9660 * Also called by SIOCGIWSTATS
9661 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009662static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009663{
9664 struct ipw_priv *priv = ieee80211_priv(dev);
9665 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009666
James Ketrenos43f66a62005-03-25 12:31:53 -06009667 wstats = &priv->wstats;
9668
James Ketrenosea2b26e2005-08-24 21:25:16 -05009669 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009670 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009671 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9672 * and associated; if not associcated, the values are all meaningless
9673 * anyway, so set them all to NULL and INVALID */
9674 if (!(priv->status & STATUS_ASSOCIATED)) {
9675 wstats->miss.beacon = 0;
9676 wstats->discard.retries = 0;
9677 wstats->qual.qual = 0;
9678 wstats->qual.level = 0;
9679 wstats->qual.noise = 0;
9680 wstats->qual.updated = 7;
9681 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009682 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009683 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009684 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009685
9686 wstats->qual.qual = priv->quality;
9687 wstats->qual.level = average_value(&priv->average_rssi);
9688 wstats->qual.noise = average_value(&priv->average_noise);
9689 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009690 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009691
9692 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9693 wstats->discard.retries = priv->last_tx_failures;
9694 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009695
James Ketrenos43f66a62005-03-25 12:31:53 -06009696/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9697 goto fail_get_ordinal;
9698 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009699
James Ketrenos43f66a62005-03-25 12:31:53 -06009700 return wstats;
9701}
9702
James Ketrenos43f66a62005-03-25 12:31:53 -06009703/* net device stuff */
9704
9705static inline void init_sys_config(struct ipw_sys_config *sys_config)
9706{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009707 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9708 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06009709 sys_config->answer_broadcast_ssid_probe = 0;
9710 sys_config->accept_all_data_frames = 0;
9711 sys_config->accept_non_directed_frames = 1;
9712 sys_config->exclude_unicast_unencrypted = 0;
9713 sys_config->disable_unicast_decryption = 1;
9714 sys_config->exclude_multicast_unencrypted = 0;
9715 sys_config->disable_multicast_decryption = 1;
9716 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009717 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009719 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009720 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009721 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009722}
9723
9724static int ipw_net_open(struct net_device *dev)
9725{
9726 struct ipw_priv *priv = ieee80211_priv(dev);
9727 IPW_DEBUG_INFO("dev->open\n");
9728 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009729 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009730 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9731 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009732 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009733 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009734 return 0;
9735}
9736
9737static int ipw_net_stop(struct net_device *dev)
9738{
9739 IPW_DEBUG_INFO("dev->close\n");
9740 netif_stop_queue(dev);
9741 return 0;
9742}
9743
9744/*
9745todo:
9746
9747modify to send one tfd per fragment instead of using chunking. otherwise
9748we need to heavily modify the ieee80211_skb_to_txb.
9749*/
9750
James Ketrenos227d2dc2005-07-28 16:25:55 -05009751static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9752 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009753{
James Ketrenos0dacca12005-09-21 12:23:41 -05009754 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009755 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 int i = 0;
9757 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009758#ifdef CONFIG_IPW_QOS
9759 int tx_id = ipw_get_tx_queue_number(priv, pri);
9760 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9761#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009763#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 struct clx2_queue *q = &txq->q;
9765 u8 id, hdr_len, unicast;
9766 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009767 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009768
James Ketrenos227d2dc2005-07-28 16:25:55 -05009769 /* If there isn't room in the queue, we return busy and let the
9770 * network stack requeue the packet for us */
9771 if (ipw_queue_space(q) < q->high_mark)
9772 return NETDEV_TX_BUSY;
9773
James Ketrenos43f66a62005-03-25 12:31:53 -06009774 switch (priv->ieee->iw_mode) {
9775 case IW_MODE_ADHOC:
9776 hdr_len = IEEE80211_3ADDR_LEN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009777 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009778 id = ipw_find_station(priv, hdr->addr1);
9779 if (id == IPW_INVALID_STATION) {
9780 id = ipw_add_station(priv, hdr->addr1);
9781 if (id == IPW_INVALID_STATION) {
9782 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009783 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009784 MAC_ARG(hdr->addr1));
9785 goto drop;
9786 }
9787 }
9788 break;
9789
9790 case IW_MODE_INFRA:
9791 default:
James Ketrenosafbf30a2005-08-25 00:05:33 -05009792 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009793 hdr_len = IEEE80211_3ADDR_LEN;
9794 id = 0;
9795 break;
9796 }
9797
9798 tfd = &txq->bd[q->first_empty];
9799 txq->txb[q->first_empty] = txb;
9800 memset(tfd, 0, sizeof(*tfd));
9801 tfd->u.data.station_number = id;
9802
9803 tfd->control_flags.message_type = TX_FRAME_TYPE;
9804 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9805
9806 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009807 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009808 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009809
James Ketrenos43f66a62005-03-25 12:31:53 -06009810 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009811 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009812 else
James Ketrenosb095c382005-08-24 22:04:42 -05009813 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009814
James Ketrenosea2b26e2005-08-24 21:25:16 -05009815 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9816 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009817
James Ketrenosc848d0a2005-08-24 21:56:24 -05009818 fc = le16_to_cpu(hdr->frame_ctl);
9819 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9820
James Ketrenos43f66a62005-03-25 12:31:53 -06009821 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9822
James Ketrenosb095c382005-08-24 22:04:42 -05009823 if (likely(unicast))
9824 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9825
9826 if (txb->encrypted && !priv->ieee->host_encrypt) {
9827 switch (priv->ieee->sec.level) {
9828 case SEC_LEVEL_3:
9829 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9830 IEEE80211_FCTL_PROTECTED;
9831 /* XXX: ACK flag must be set for CCMP even if it
9832 * is a multicast/broadcast packet, because CCMP
9833 * group communication encrypted by GTK is
9834 * actually done by the AP. */
9835 if (!unicast)
9836 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9837
9838 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9839 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9840 tfd->u.data.key_index = 0;
9841 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9842 break;
9843 case SEC_LEVEL_2:
9844 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9845 IEEE80211_FCTL_PROTECTED;
9846 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9847 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9848 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9849 break;
9850 case SEC_LEVEL_1:
9851 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9852 IEEE80211_FCTL_PROTECTED;
9853 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9854 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9855 40)
9856 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9857 else
9858 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9859 break;
9860 case SEC_LEVEL_0:
9861 break;
9862 default:
9863 printk(KERN_ERR "Unknow security level %d\n",
9864 priv->ieee->sec.level);
9865 break;
9866 }
9867 } else
9868 /* No hardware encryption */
9869 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9870
9871#ifdef CONFIG_IPW_QOS
9872 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9873#endif /* CONFIG_IPW_QOS */
9874
James Ketrenos43f66a62005-03-25 12:31:53 -06009875 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009876 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9877 txb->nr_frags));
9878 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9879 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9880 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9881 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9882 i, le32_to_cpu(tfd->u.data.num_chunks),
9883 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009884 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009885 i, tfd->u.data.num_chunks,
9886 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009887 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009888 txb->fragments[i]->len - hdr_len);
9889
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009890 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009891 cpu_to_le32(pci_map_single
9892 (priv->pci_dev,
9893 txb->fragments[i]->data + hdr_len,
9894 txb->fragments[i]->len - hdr_len,
9895 PCI_DMA_TODEVICE));
9896 tfd->u.data.chunk_len[i] =
9897 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009898 }
9899
9900 if (i != txb->nr_frags) {
9901 struct sk_buff *skb;
9902 u16 remaining_bytes = 0;
9903 int j;
9904
9905 for (j = i; j < txb->nr_frags; j++)
9906 remaining_bytes += txb->fragments[j]->len - hdr_len;
9907
9908 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9909 remaining_bytes);
9910 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9911 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009912 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 for (j = i; j < txb->nr_frags; j++) {
9914 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009915
James Ketrenos43f66a62005-03-25 12:31:53 -06009916 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009917 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009918 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009919 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009920 }
9921 dev_kfree_skb_any(txb->fragments[i]);
9922 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009923 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009924 cpu_to_le32(pci_map_single
9925 (priv->pci_dev, skb->data,
9926 tfd->u.data.chunk_len[i],
9927 PCI_DMA_TODEVICE));
9928
9929 tfd->u.data.num_chunks =
9930 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9931 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009932 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009933 }
9934
9935 /* kick DMA */
9936 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9937 ipw_write32(priv, q->reg_w, q->first_empty);
9938
James Ketrenos227d2dc2005-07-28 16:25:55 -05009939 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009940
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009941 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009942 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9943 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009944 return NETDEV_TX_OK;
9945}
9946
9947static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9948{
9949 struct ipw_priv *priv = ieee80211_priv(dev);
9950#ifdef CONFIG_IPW_QOS
9951 int tx_id = ipw_get_tx_queue_number(priv, pri);
9952 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9953#else
9954 struct clx2_tx_queue *txq = &priv->txq[0];
9955#endif /* CONFIG_IPW_QOS */
9956
9957 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9958 return 1;
9959
9960 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009961}
9962
9963static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009964 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009965{
9966 struct ipw_priv *priv = ieee80211_priv(dev);
9967 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009968 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009969
9970 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009971 spin_lock_irqsave(&priv->lock, flags);
9972
9973 if (!(priv->status & STATUS_ASSOCIATED)) {
9974 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9975 priv->ieee->stats.tx_carrier_errors++;
9976 netif_stop_queue(dev);
9977 goto fail_unlock;
9978 }
9979
James Ketrenos227d2dc2005-07-28 16:25:55 -05009980 ret = ipw_tx_skb(priv, txb, pri);
9981 if (ret == NETDEV_TX_OK)
9982 __ipw_led_activity_on(priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009983 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009984
James Ketrenos227d2dc2005-07-28 16:25:55 -05009985 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009986
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009987 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009988 spin_unlock_irqrestore(&priv->lock, flags);
9989 return 1;
9990}
9991
9992static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9993{
9994 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009995
James Ketrenos43f66a62005-03-25 12:31:53 -06009996 priv->ieee->stats.tx_packets = priv->tx_packets;
9997 priv->ieee->stats.rx_packets = priv->rx_packets;
9998 return &priv->ieee->stats;
9999}
10000
10001static void ipw_net_set_multicast_list(struct net_device *dev)
10002{
10003
10004}
10005
10006static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10007{
10008 struct ipw_priv *priv = ieee80211_priv(dev);
10009 struct sockaddr *addr = p;
10010 if (!is_valid_ether_addr(addr->sa_data))
10011 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010012 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010013 priv->config |= CFG_CUSTOM_MAC;
10014 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10015 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10016 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010017 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010018 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010019 return 0;
10020}
10021
Jeff Garzikbf794512005-07-31 13:07:26 -040010022static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010023 struct ethtool_drvinfo *info)
10024{
10025 struct ipw_priv *p = ieee80211_priv(dev);
10026 char vers[64];
10027 char date[32];
10028 u32 len;
10029
10030 strcpy(info->driver, DRV_NAME);
10031 strcpy(info->version, DRV_VERSION);
10032
10033 len = sizeof(vers);
10034 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10035 len = sizeof(date);
10036 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10037
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010038 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010039 vers, date);
10040 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010041 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010042}
10043
10044static u32 ipw_ethtool_get_link(struct net_device *dev)
10045{
10046 struct ipw_priv *priv = ieee80211_priv(dev);
10047 return (priv->status & STATUS_ASSOCIATED) != 0;
10048}
10049
10050static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10051{
James Ketrenosb095c382005-08-24 22:04:42 -050010052 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010053}
10054
10055static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010056 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010057{
10058 struct ipw_priv *p = ieee80211_priv(dev);
10059
James Ketrenosb095c382005-08-24 22:04:42 -050010060 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010061 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010062 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010063 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010064 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010065 return 0;
10066}
10067
10068static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010069 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010070{
10071 struct ipw_priv *p = ieee80211_priv(dev);
10072 int i;
10073
James Ketrenosb095c382005-08-24 22:04:42 -050010074 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010075 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010076 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010077 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010078 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -050010079 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -060010080 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010081 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010082 return 0;
10083}
10084
10085static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010086 .get_link = ipw_ethtool_get_link,
10087 .get_drvinfo = ipw_ethtool_get_drvinfo,
10088 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10089 .get_eeprom = ipw_ethtool_get_eeprom,
10090 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010091};
10092
10093static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10094{
10095 struct ipw_priv *priv = data;
10096 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010097
James Ketrenos43f66a62005-03-25 12:31:53 -060010098 if (!priv)
10099 return IRQ_NONE;
10100
10101 spin_lock(&priv->lock);
10102
10103 if (!(priv->status & STATUS_INT_ENABLED)) {
10104 /* Shared IRQ */
10105 goto none;
10106 }
10107
James Ketrenosb095c382005-08-24 22:04:42 -050010108 inta = ipw_read32(priv, IPW_INTA_RW);
10109 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010110
James Ketrenos43f66a62005-03-25 12:31:53 -060010111 if (inta == 0xFFFFFFFF) {
10112 /* Hardware disappeared */
10113 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10114 goto none;
10115 }
10116
James Ketrenosb095c382005-08-24 22:04:42 -050010117 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010118 /* Shared interrupt */
10119 goto none;
10120 }
10121
10122 /* tell the device to stop sending interrupts */
10123 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010124
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010126 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10127 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010128
James Ketrenos43f66a62005-03-25 12:31:53 -060010129 /* Cache INTA value for our tasklet */
10130 priv->isr_inta = inta;
10131
10132 tasklet_schedule(&priv->irq_tasklet);
10133
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010134 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010135
10136 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010137 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 spin_unlock(&priv->lock);
10139 return IRQ_NONE;
10140}
10141
10142static void ipw_rf_kill(void *adapter)
10143{
10144 struct ipw_priv *priv = adapter;
10145 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010146
James Ketrenos43f66a62005-03-25 12:31:53 -060010147 spin_lock_irqsave(&priv->lock, flags);
10148
10149 if (rf_kill_active(priv)) {
10150 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10151 if (priv->workqueue)
10152 queue_delayed_work(priv->workqueue,
10153 &priv->rf_kill, 2 * HZ);
10154 goto exit_unlock;
10155 }
10156
10157 /* RF Kill is now disabled, so bring the device back up */
10158
10159 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10160 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10161 "device\n");
10162
10163 /* we can not do an adapter restart while inside an irq lock */
10164 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010165 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010166 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10167 "enabled\n");
10168
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010169 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010170 spin_unlock_irqrestore(&priv->lock, flags);
10171}
10172
James Ketrenosc848d0a2005-08-24 21:56:24 -050010173static void ipw_bg_rf_kill(void *data)
10174{
10175 struct ipw_priv *priv = data;
10176 down(&priv->sem);
10177 ipw_rf_kill(data);
10178 up(&priv->sem);
10179}
10180
James Ketrenosa613bff2005-08-24 21:43:11 -050010181void ipw_link_up(struct ipw_priv *priv)
10182{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010183 priv->last_seq_num = -1;
10184 priv->last_frag_num = -1;
10185 priv->last_packet_time = 0;
10186
James Ketrenosa613bff2005-08-24 21:43:11 -050010187 netif_carrier_on(priv->net_dev);
10188 if (netif_queue_stopped(priv->net_dev)) {
10189 IPW_DEBUG_NOTIF("waking queue\n");
10190 netif_wake_queue(priv->net_dev);
10191 } else {
10192 IPW_DEBUG_NOTIF("starting queue\n");
10193 netif_start_queue(priv->net_dev);
10194 }
10195
James Ketrenosc848d0a2005-08-24 21:56:24 -050010196 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010197 ipw_reset_stats(priv);
10198 /* Ensure the rate is updated immediately */
10199 priv->last_rate = ipw_get_current_rate(priv);
10200 ipw_gather_stats(priv);
10201 ipw_led_link_up(priv);
10202 notify_wx_assoc_event(priv);
10203
10204 if (priv->config & CFG_BACKGROUND_SCAN)
10205 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10206}
10207
James Ketrenosc848d0a2005-08-24 21:56:24 -050010208static void ipw_bg_link_up(void *data)
10209{
10210 struct ipw_priv *priv = data;
10211 down(&priv->sem);
10212 ipw_link_up(data);
10213 up(&priv->sem);
10214}
10215
James Ketrenosa613bff2005-08-24 21:43:11 -050010216void ipw_link_down(struct ipw_priv *priv)
10217{
10218 ipw_led_link_down(priv);
10219 netif_carrier_off(priv->net_dev);
10220 netif_stop_queue(priv->net_dev);
10221 notify_wx_assoc_event(priv);
10222
10223 /* Cancel any queued work ... */
10224 cancel_delayed_work(&priv->request_scan);
10225 cancel_delayed_work(&priv->adhoc_check);
10226 cancel_delayed_work(&priv->gather_stats);
10227
10228 ipw_reset_stats(priv);
10229
James Ketrenosafbf30a2005-08-25 00:05:33 -050010230 if (!(priv->status & STATUS_EXIT_PENDING)) {
10231 /* Queue up another scan... */
10232 queue_work(priv->workqueue, &priv->request_scan);
10233 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010234}
10235
James Ketrenosc848d0a2005-08-24 21:56:24 -050010236static void ipw_bg_link_down(void *data)
10237{
10238 struct ipw_priv *priv = data;
10239 down(&priv->sem);
10240 ipw_link_down(data);
10241 up(&priv->sem);
10242}
10243
James Ketrenos43f66a62005-03-25 12:31:53 -060010244static int ipw_setup_deferred_work(struct ipw_priv *priv)
10245{
10246 int ret = 0;
10247
James Ketrenos43f66a62005-03-25 12:31:53 -060010248 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010249 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010250 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010251
James Ketrenosc848d0a2005-08-24 21:56:24 -050010252 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10253 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10254 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010255 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010256 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10257 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10258 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10259 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10260 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010261 INIT_WORK(&priv->request_scan,
James Ketrenosb095c382005-08-24 22:04:42 -050010262 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010263 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010264 (void (*)(void *))ipw_bg_gather_stats, priv);
10265 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10266 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10267 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10268 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10269 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10270 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010271 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010272 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010273 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010274 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10275 priv);
10276 INIT_WORK(&priv->merge_networks,
10277 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010278
James Ketrenosb095c382005-08-24 22:04:42 -050010279#ifdef CONFIG_IPW_QOS
10280 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10281 priv);
10282#endif /* CONFIG_IPW_QOS */
10283
James Ketrenos43f66a62005-03-25 12:31:53 -060010284 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10285 ipw_irq_tasklet, (unsigned long)priv);
10286
10287 return ret;
10288}
10289
James Ketrenos43f66a62005-03-25 12:31:53 -060010290static void shim__set_security(struct net_device *dev,
10291 struct ieee80211_security *sec)
10292{
10293 struct ipw_priv *priv = ieee80211_priv(dev);
10294 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010295 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010296 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010297 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010298 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010299 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010300 priv->ieee->sec.flags &= ~(1 << i);
10301 else {
10302 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010303 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010304 priv->ieee->sec.flags |= (1 << i);
10305 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010306 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010307 } else if (sec->level != SEC_LEVEL_1)
10308 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010309 }
10310
James Ketrenosb095c382005-08-24 22:04:42 -050010311 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010312 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010313 priv->ieee->sec.active_key = sec->active_key;
10314 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010315 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010316 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010317 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010318 } else
10319 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010320
10321 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010322 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10323 priv->ieee->sec.auth_mode = sec->auth_mode;
10324 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010325 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10326 priv->capability |= CAP_SHARED_KEY;
10327 else
10328 priv->capability &= ~CAP_SHARED_KEY;
10329 priv->status |= STATUS_SECURITY_UPDATED;
10330 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010331
James Ketrenosb095c382005-08-24 22:04:42 -050010332 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10333 priv->ieee->sec.flags |= SEC_ENABLED;
10334 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010335 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010336 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010337 priv->capability |= CAP_PRIVACY_ON;
10338 else
10339 priv->capability &= ~CAP_PRIVACY_ON;
10340 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010341
10342 if (sec->flags & SEC_ENCRYPT)
10343 priv->ieee->sec.encrypt = sec->encrypt;
Jeff Garzikbf794512005-07-31 13:07:26 -040010344
James Ketrenosb095c382005-08-24 22:04:42 -050010345 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10346 priv->ieee->sec.level = sec->level;
10347 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010348 priv->status |= STATUS_SECURITY_UPDATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -050010349 }
James Ketrenosb095c382005-08-24 22:04:42 -050010350
Zhu Yi1fbfea52005-08-05 17:22:56 +080010351 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10352 ipw_set_hwcrypto_keys(priv);
10353
Jeff Garzikbf794512005-07-31 13:07:26 -040010354 /* To match current functionality of ipw2100 (which works well w/
10355 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010356 * privacy capability changes ... */
10357#if 0
10358 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010359 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010360 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010361 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010362 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010363 IPW_DEBUG_ASSOC("Disassociating due to capability "
10364 "change.\n");
10365 ipw_disassociate(priv);
10366 }
10367#endif
10368}
10369
Jeff Garzikbf794512005-07-31 13:07:26 -040010370static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010371 struct ipw_supported_rates *rates)
10372{
10373 /* TODO: Mask out rates based on priv->rates_mask */
10374
10375 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010376 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010377 switch (priv->ieee->freq_band) {
10378 case IEEE80211_52GHZ_BAND:
10379 rates->ieee_mode = IPW_A_MODE;
10380 rates->purpose = IPW_RATE_CAPABILITIES;
10381 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10382 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10383 break;
10384
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010385 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010386 rates->ieee_mode = IPW_G_MODE;
10387 rates->purpose = IPW_RATE_CAPABILITIES;
10388 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10389 IEEE80211_CCK_DEFAULT_RATES_MASK);
10390 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10391 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10392 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10393 }
10394 break;
10395 }
10396
10397 return 0;
10398}
10399
Jeff Garzikbf794512005-07-31 13:07:26 -040010400static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010401{
James Ketrenos43f66a62005-03-25 12:31:53 -060010402 /* This is only called from ipw_up, which resets/reloads the firmware
10403 so, we don't need to first disable the card before we configure
10404 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010405 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010406 goto error;
10407
10408 /* initialize adapter address */
10409 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10410 goto error;
10411
10412 /* set basic system config settings */
10413 init_sys_config(&priv->sys_config);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010414 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10415 priv->sys_config.answer_broadcast_ssid_probe = 1;
10416 else
10417 priv->sys_config.answer_broadcast_ssid_probe = 0;
10418
James Ketrenos43f66a62005-03-25 12:31:53 -060010419 if (ipw_send_system_config(priv, &priv->sys_config))
10420 goto error;
10421
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010422 init_supported_rates(priv, &priv->rates);
10423 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010424 goto error;
10425
10426 /* Set request-to-send threshold */
10427 if (priv->rts_threshold) {
10428 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10429 goto error;
10430 }
James Ketrenosb095c382005-08-24 22:04:42 -050010431#ifdef CONFIG_IPW_QOS
10432 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10433 ipw_qos_activate(priv, NULL);
10434#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010435
10436 if (ipw_set_random_seed(priv))
10437 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010438
James Ketrenos43f66a62005-03-25 12:31:53 -060010439 /* final state transition to the RUN state */
10440 if (ipw_send_host_complete(priv))
10441 goto error;
10442
James Ketrenose6666192005-08-12 09:17:04 -050010443 priv->status |= STATUS_INIT;
10444
10445 ipw_led_init(priv);
10446 ipw_led_radio_on(priv);
10447 priv->notif_missed_beacons = 0;
10448
10449 /* Set hardware WEP key if it is configured. */
10450 if ((priv->capability & CAP_PRIVACY_ON) &&
10451 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10452 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10453 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010454
10455 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010456
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010457 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010458 return -EIO;
10459}
10460
James Ketrenos4f36f802005-08-03 20:36:56 -050010461/*
10462 * NOTE:
10463 *
10464 * These tables have been tested in conjunction with the
10465 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10466 *
10467 * Altering this values, using it on other hardware, or in geographies
10468 * not intended for resale of the above mentioned Intel adapters has
10469 * not been tested.
10470 *
10471 */
10472static const struct ieee80211_geo ipw_geos[] = {
10473 { /* Restricted */
10474 "---",
10475 .bg_channels = 11,
10476 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10477 {2427, 4}, {2432, 5}, {2437, 6},
10478 {2442, 7}, {2447, 8}, {2452, 9},
10479 {2457, 10}, {2462, 11}},
10480 },
10481
10482 { /* Custom US/Canada */
10483 "ZZF",
10484 .bg_channels = 11,
10485 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10486 {2427, 4}, {2432, 5}, {2437, 6},
10487 {2442, 7}, {2447, 8}, {2452, 9},
10488 {2457, 10}, {2462, 11}},
10489 .a_channels = 8,
10490 .a = {{5180, 36},
10491 {5200, 40},
10492 {5220, 44},
10493 {5240, 48},
10494 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10495 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10496 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10497 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10498 },
10499
10500 { /* Rest of World */
10501 "ZZD",
10502 .bg_channels = 13,
10503 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10504 {2427, 4}, {2432, 5}, {2437, 6},
10505 {2442, 7}, {2447, 8}, {2452, 9},
10506 {2457, 10}, {2462, 11}, {2467, 12},
10507 {2472, 13}},
10508 },
10509
10510 { /* Custom USA & Europe & High */
10511 "ZZA",
10512 .bg_channels = 11,
10513 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10514 {2427, 4}, {2432, 5}, {2437, 6},
10515 {2442, 7}, {2447, 8}, {2452, 9},
10516 {2457, 10}, {2462, 11}},
10517 .a_channels = 13,
10518 .a = {{5180, 36},
10519 {5200, 40},
10520 {5220, 44},
10521 {5240, 48},
10522 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10523 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10524 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10525 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10526 {5745, 149},
10527 {5765, 153},
10528 {5785, 157},
10529 {5805, 161},
10530 {5825, 165}},
10531 },
10532
10533 { /* Custom NA & Europe */
10534 "ZZB",
10535 .bg_channels = 11,
10536 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10537 {2427, 4}, {2432, 5}, {2437, 6},
10538 {2442, 7}, {2447, 8}, {2452, 9},
10539 {2457, 10}, {2462, 11}},
10540 .a_channels = 13,
10541 .a = {{5180, 36},
10542 {5200, 40},
10543 {5220, 44},
10544 {5240, 48},
10545 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10546 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10547 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10548 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10549 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10550 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10551 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10552 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10553 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10554 },
10555
10556 { /* Custom Japan */
10557 "ZZC",
10558 .bg_channels = 11,
10559 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10560 {2427, 4}, {2432, 5}, {2437, 6},
10561 {2442, 7}, {2447, 8}, {2452, 9},
10562 {2457, 10}, {2462, 11}},
10563 .a_channels = 4,
10564 .a = {{5170, 34}, {5190, 38},
10565 {5210, 42}, {5230, 46}},
10566 },
10567
10568 { /* Custom */
10569 "ZZM",
10570 .bg_channels = 11,
10571 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10572 {2427, 4}, {2432, 5}, {2437, 6},
10573 {2442, 7}, {2447, 8}, {2452, 9},
10574 {2457, 10}, {2462, 11}},
10575 },
10576
10577 { /* Europe */
10578 "ZZE",
10579 .bg_channels = 13,
10580 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10581 {2427, 4}, {2432, 5}, {2437, 6},
10582 {2442, 7}, {2447, 8}, {2452, 9},
10583 {2457, 10}, {2462, 11}, {2467, 12},
10584 {2472, 13}},
10585 .a_channels = 19,
10586 .a = {{5180, 36},
10587 {5200, 40},
10588 {5220, 44},
10589 {5240, 48},
10590 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10591 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10592 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10593 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10594 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10595 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10596 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10597 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10598 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10599 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10600 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10601 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10602 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10603 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10604 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10605 },
10606
10607 { /* Custom Japan */
10608 "ZZJ",
10609 .bg_channels = 14,
10610 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10611 {2427, 4}, {2432, 5}, {2437, 6},
10612 {2442, 7}, {2447, 8}, {2452, 9},
10613 {2457, 10}, {2462, 11}, {2467, 12},
10614 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10615 .a_channels = 4,
10616 .a = {{5170, 34}, {5190, 38},
10617 {5210, 42}, {5230, 46}},
10618 },
10619
10620 { /* High Band */
10621 "ZZH",
10622 .bg_channels = 13,
10623 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10624 {2427, 4}, {2432, 5}, {2437, 6},
10625 {2442, 7}, {2447, 8}, {2452, 9},
10626 {2457, 10}, {2462, 11},
10627 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10628 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10629 .a_channels = 4,
10630 .a = {{5745, 149}, {5765, 153},
10631 {5785, 157}, {5805, 161}},
10632 },
10633
10634 { /* Custom Europe */
10635 "ZZG",
10636 .bg_channels = 13,
10637 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10638 {2427, 4}, {2432, 5}, {2437, 6},
10639 {2442, 7}, {2447, 8}, {2452, 9},
10640 {2457, 10}, {2462, 11},
10641 {2467, 12}, {2472, 13}},
10642 .a_channels = 4,
10643 .a = {{5180, 36}, {5200, 40},
10644 {5220, 44}, {5240, 48}},
10645 },
10646
10647 { /* Europe */
10648 "ZZK",
10649 .bg_channels = 13,
10650 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10651 {2427, 4}, {2432, 5}, {2437, 6},
10652 {2442, 7}, {2447, 8}, {2452, 9},
10653 {2457, 10}, {2462, 11},
10654 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10655 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10656 .a_channels = 24,
10657 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10658 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10659 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10660 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10661 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10662 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10663 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10664 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10665 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10666 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10667 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10668 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10669 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10670 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10671 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10672 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10673 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10674 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10675 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10676 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10677 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10678 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10679 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10680 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10681 },
10682
10683 { /* Europe */
10684 "ZZL",
10685 .bg_channels = 11,
10686 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10687 {2427, 4}, {2432, 5}, {2437, 6},
10688 {2442, 7}, {2447, 8}, {2452, 9},
10689 {2457, 10}, {2462, 11}},
10690 .a_channels = 13,
10691 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10692 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10693 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10694 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10695 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10696 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10697 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10698 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10699 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10700 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10701 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10702 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10703 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10704 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010705};
10706
James Ketrenos43f66a62005-03-25 12:31:53 -060010707#define MAX_HW_RESTARTS 5
10708static int ipw_up(struct ipw_priv *priv)
10709{
James Ketrenos4f36f802005-08-03 20:36:56 -050010710 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010711
10712 if (priv->status & STATUS_EXIT_PENDING)
10713 return -EIO;
10714
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010715 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010716 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010717 * Also start the clocks. */
10718 rc = ipw_load(priv);
10719 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010720 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010721 return rc;
10722 }
10723
10724 ipw_init_ordinals(priv);
10725 if (!(priv->config & CFG_CUSTOM_MAC))
10726 eeprom_parse_mac(priv, priv->mac_addr);
10727 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10728
James Ketrenos4f36f802005-08-03 20:36:56 -050010729 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10730 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10731 ipw_geos[j].name, 3))
10732 break;
10733 }
10734 if (j == ARRAY_SIZE(ipw_geos))
10735 j = 0;
10736 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10737 IPW_WARNING("Could not set geography.");
10738 return 0;
10739 }
10740
10741 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10742 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010743
James Ketrenosb095c382005-08-24 22:04:42 -050010744 if (priv->status & STATUS_RF_KILL_SW) {
10745 IPW_WARNING("Radio disabled by module parameter.\n");
10746 return 0;
10747 } else if (rf_kill_active(priv)) {
10748 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10749 "Kill switch must be turned off for "
10750 "wireless networking to work.\n");
10751 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10752 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010753 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010754 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010755
10756 rc = ipw_config(priv);
10757 if (!rc) {
10758 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010759
James Ketrenose6666192005-08-12 09:17:04 -050010760 /* If configure to try and auto-associate, kick
10761 * off a scan. */
10762 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010763
James Ketrenos43f66a62005-03-25 12:31:53 -060010764 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010765 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010766
James Ketrenosc848d0a2005-08-24 21:56:24 -050010767 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010768 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10769 i, MAX_HW_RESTARTS);
10770
10771 /* We had an error bringing up the hardware, so take it
10772 * all the way back down so we can try again */
10773 ipw_down(priv);
10774 }
10775
Jeff Garzikbf794512005-07-31 13:07:26 -040010776 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010777 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010778 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010779
James Ketrenos43f66a62005-03-25 12:31:53 -060010780 return -EIO;
10781}
10782
James Ketrenosc848d0a2005-08-24 21:56:24 -050010783static void ipw_bg_up(void *data)
10784{
10785 struct ipw_priv *priv = data;
10786 down(&priv->sem);
10787 ipw_up(data);
10788 up(&priv->sem);
10789}
10790
James Ketrenosb095c382005-08-24 22:04:42 -050010791static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010792{
James Ketrenosb095c382005-08-24 22:04:42 -050010793 int i;
10794
10795 if (priv->status & STATUS_SCANNING) {
10796 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10797 ipw_abort_scan(priv);
10798 }
10799
10800 if (priv->status & STATUS_ASSOCIATED) {
10801 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10802 ipw_disassociate(priv);
10803 }
10804
10805 ipw_led_shutdown(priv);
10806
10807 /* Wait up to 1s for status to change to not scanning and not
10808 * associated (disassociation can take a while for a ful 802.11
10809 * exchange */
10810 for (i = 1000; i && (priv->status &
10811 (STATUS_DISASSOCIATING |
10812 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10813 udelay(10);
10814
10815 if (priv->status & (STATUS_DISASSOCIATING |
10816 STATUS_ASSOCIATED | STATUS_SCANNING))
10817 IPW_DEBUG_INFO("Still associated or scanning...\n");
10818 else
10819 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10820
James Ketrenosc848d0a2005-08-24 21:56:24 -050010821 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010822 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010823
10824 priv->status &= ~STATUS_INIT;
10825}
10826
10827static void ipw_down(struct ipw_priv *priv)
10828{
10829 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10830
10831 priv->status |= STATUS_EXIT_PENDING;
10832
10833 if (ipw_is_init(priv))
10834 ipw_deinit(priv);
10835
10836 /* Wipe out the EXIT_PENDING status bit if we are not actually
10837 * exiting the module */
10838 if (!exit_pending)
10839 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010840
10841 /* tell the device to stop sending interrupts */
10842 ipw_disable_interrupts(priv);
10843
10844 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010845 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010846 netif_carrier_off(priv->net_dev);
10847 netif_stop_queue(priv->net_dev);
10848
10849 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010850
10851 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010852}
10853
James Ketrenosc848d0a2005-08-24 21:56:24 -050010854static void ipw_bg_down(void *data)
10855{
10856 struct ipw_priv *priv = data;
10857 down(&priv->sem);
10858 ipw_down(data);
10859 up(&priv->sem);
10860}
10861
James Ketrenosafbf30a2005-08-25 00:05:33 -050010862#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050010863static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
10864{
James Ketrenosea2b26e2005-08-24 21:25:16 -050010865 struct iwreq *wrq = (struct iwreq *)rq;
10866 int ret = -1;
10867 switch (cmd) {
10868 case IPW_IOCTL_WPA_SUPPLICANT:
10869 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
10870 return ret;
10871
10872 default:
10873 return -EOPNOTSUPP;
10874 }
10875
James Ketrenosea2b26e2005-08-24 21:25:16 -050010876 return -EOPNOTSUPP;
10877}
James Ketrenosafbf30a2005-08-25 00:05:33 -050010878#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -050010879
James Ketrenos43f66a62005-03-25 12:31:53 -060010880/* Called by register_netdev() */
10881static int ipw_net_init(struct net_device *dev)
10882{
10883 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010884 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010885
James Ketrenosc848d0a2005-08-24 21:56:24 -050010886 if (ipw_up(priv)) {
10887 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010888 return -EIO;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010889 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010890
James Ketrenosc848d0a2005-08-24 21:56:24 -050010891 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010892 return 0;
10893}
10894
10895/* PCI driver stuff */
10896static struct pci_device_id card_ids[] = {
10897 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10898 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10899 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10900 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10901 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10902 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10903 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10904 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10905 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10906 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10907 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10908 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10909 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10910 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10911 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10912 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10913 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10914 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010915 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010916 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010917 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10918 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010919
James Ketrenos43f66a62005-03-25 12:31:53 -060010920 /* required last entry */
10921 {0,}
10922};
10923
10924MODULE_DEVICE_TABLE(pci, card_ids);
10925
10926static struct attribute *ipw_sysfs_entries[] = {
10927 &dev_attr_rf_kill.attr,
10928 &dev_attr_direct_dword.attr,
10929 &dev_attr_indirect_byte.attr,
10930 &dev_attr_indirect_dword.attr,
10931 &dev_attr_mem_gpio_reg.attr,
10932 &dev_attr_command_event_reg.attr,
10933 &dev_attr_nic_type.attr,
10934 &dev_attr_status.attr,
10935 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010936 &dev_attr_error.attr,
10937 &dev_attr_event_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010938 &dev_attr_eeprom_delay.attr,
10939 &dev_attr_ucode_version.attr,
10940 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010941 &dev_attr_scan_age.attr,
10942 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010943 &dev_attr_speed_scan.attr,
10944 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010945 NULL
10946};
10947
10948static struct attribute_group ipw_attribute_group = {
10949 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010950 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010951};
10952
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010953static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010954{
10955 int err = 0;
10956 struct net_device *net_dev;
10957 void __iomem *base;
10958 u32 length, val;
10959 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010960 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010961
10962 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10963 if (net_dev == NULL) {
10964 err = -ENOMEM;
10965 goto out;
10966 }
10967
10968 priv = ieee80211_priv(net_dev);
10969 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010970
James Ketrenos43f66a62005-03-25 12:31:53 -060010971 priv->net_dev = net_dev;
10972 priv->pci_dev = pdev;
10973#ifdef CONFIG_IPW_DEBUG
10974 ipw_debug_level = debug;
10975#endif
10976 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010977 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10978 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010979
James Ketrenosc848d0a2005-08-24 21:56:24 -050010980 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010981 if (pci_enable_device(pdev)) {
10982 err = -ENODEV;
10983 goto out_free_ieee80211;
10984 }
10985
10986 pci_set_master(pdev);
10987
Tobias Klauser0e08b442005-06-20 14:28:41 -070010988 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010989 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010990 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010991 if (err) {
10992 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10993 goto out_pci_disable_device;
10994 }
10995
10996 pci_set_drvdata(pdev, priv);
10997
10998 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040010999 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011000 goto out_pci_disable_device;
11001
Jeff Garzikbf794512005-07-31 13:07:26 -040011002 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011003 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011004 pci_read_config_dword(pdev, 0x40, &val);
11005 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011006 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011007
James Ketrenos43f66a62005-03-25 12:31:53 -060011008 length = pci_resource_len(pdev, 0);
11009 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011010
James Ketrenos43f66a62005-03-25 12:31:53 -060011011 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11012 if (!base) {
11013 err = -ENODEV;
11014 goto out_pci_release_regions;
11015 }
11016
11017 priv->hw_base = base;
11018 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11019 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11020
11021 err = ipw_setup_deferred_work(priv);
11022 if (err) {
11023 IPW_ERROR("Unable to setup deferred work\n");
11024 goto out_iounmap;
11025 }
11026
James Ketrenosb095c382005-08-24 22:04:42 -050011027 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011028
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011029 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011030 if (err) {
11031 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11032 goto out_destroy_workqueue;
11033 }
11034
11035 SET_MODULE_OWNER(net_dev);
11036 SET_NETDEV_DEV(net_dev, &pdev->dev);
11037
James Ketrenosa613bff2005-08-24 21:43:11 -050011038 ipw_wx_data.spy_data = &priv->ieee->spy_data;
11039 ipw_wx_data.ieee80211 = priv->ieee;
11040
James Ketrenosc848d0a2005-08-24 21:56:24 -050011041 down(&priv->sem);
11042
James Ketrenos43f66a62005-03-25 12:31:53 -060011043 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11044 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011045 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011046
James Ketrenosb095c382005-08-24 22:04:42 -050011047#ifdef CONFIG_IPW_QOS
James Ketrenos2b184d52005-08-03 20:33:14 -050011048 priv->ieee->handle_management = ipw_handle_management;
James Ketrenosb095c382005-08-24 22:04:42 -050011049#endif /* CONFIG_IPW_QOS */
11050
James Ketrenosc848d0a2005-08-24 21:56:24 -050011051 priv->ieee->perfect_rssi = -20;
11052 priv->ieee->worst_rssi = -85;
11053
James Ketrenos43f66a62005-03-25 12:31:53 -060011054 net_dev->open = ipw_net_open;
11055 net_dev->stop = ipw_net_stop;
11056 net_dev->init = ipw_net_init;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011057#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050011058 net_dev->do_ioctl = ipw_ioctl;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011059#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011060 net_dev->get_stats = ipw_net_get_stats;
11061 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11062 net_dev->set_mac_address = ipw_net_set_mac_address;
11063 net_dev->get_wireless_stats = ipw_get_wireless_stats;
James Ketrenosa613bff2005-08-24 21:43:11 -050011064 net_dev->wireless_data = &ipw_wx_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011065 net_dev->wireless_handlers = &ipw_wx_handler_def;
11066 net_dev->ethtool_ops = &ipw_ethtool_ops;
11067 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011068 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011069 net_dev->mem_start = pci_resource_start(pdev, 0);
11070 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11071
11072 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11073 if (err) {
11074 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011075 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011076 goto out_release_irq;
11077 }
11078
James Ketrenosc848d0a2005-08-24 21:56:24 -050011079 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011080 err = register_netdev(net_dev);
11081 if (err) {
11082 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011083 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011084 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011085 return 0;
11086
James Ketrenosa613bff2005-08-24 21:43:11 -050011087 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011088 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011089 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011091 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011092 destroy_workqueue(priv->workqueue);
11093 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011094 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011095 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011096 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011097 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011098 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011099 pci_disable_device(pdev);
11100 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011101 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011102 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011103 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011104 return err;
11105}
11106
11107static void ipw_pci_remove(struct pci_dev *pdev)
11108{
11109 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011110 struct list_head *p, *q;
11111 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011112
James Ketrenos43f66a62005-03-25 12:31:53 -060011113 if (!priv)
11114 return;
11115
James Ketrenosb095c382005-08-24 22:04:42 -050011116 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011117
11118 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011119 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -050011120 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011121
James Ketrenosb095c382005-08-24 22:04:42 -050011122 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011123
11124 unregister_netdev(priv->net_dev);
11125
11126 if (priv->rxq) {
11127 ipw_rx_queue_free(priv, priv->rxq);
11128 priv->rxq = NULL;
11129 }
11130 ipw_tx_queue_free(priv);
11131
11132 /* ipw_down will ensure that there is no more pending work
11133 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011134 cancel_delayed_work(&priv->adhoc_check);
11135 cancel_delayed_work(&priv->gather_stats);
11136 cancel_delayed_work(&priv->request_scan);
11137 cancel_delayed_work(&priv->rf_kill);
11138 cancel_delayed_work(&priv->scan_check);
11139 destroy_workqueue(priv->workqueue);
11140 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011141
James Ketrenosafbf30a2005-08-25 00:05:33 -050011142 /* Free MAC hash list for ADHOC */
11143 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11144 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11145 kfree(list_entry(p, struct ipw_ibss_seq, list));
11146 list_del(p);
11147 }
11148 }
11149
James Ketrenosb39860c2005-08-12 09:36:32 -050011150 if (priv->error) {
11151 ipw_free_error_log(priv->error);
11152 priv->error = NULL;
11153 }
11154
James Ketrenos43f66a62005-03-25 12:31:53 -060011155 free_irq(pdev->irq, priv);
11156 iounmap(priv->hw_base);
11157 pci_release_regions(pdev);
11158 pci_disable_device(pdev);
11159 pci_set_drvdata(pdev, NULL);
11160 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011161 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011162}
11163
James Ketrenos43f66a62005-03-25 12:31:53 -060011164#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011165static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011166{
11167 struct ipw_priv *priv = pci_get_drvdata(pdev);
11168 struct net_device *dev = priv->net_dev;
11169
11170 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11171
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011172 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011173 ipw_down(priv);
11174
11175 /* Remove the PRESENT state of the device */
11176 netif_device_detach(dev);
11177
James Ketrenos43f66a62005-03-25 12:31:53 -060011178 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011179 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011180 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011181
James Ketrenos43f66a62005-03-25 12:31:53 -060011182 return 0;
11183}
11184
11185static int ipw_pci_resume(struct pci_dev *pdev)
11186{
11187 struct ipw_priv *priv = pci_get_drvdata(pdev);
11188 struct net_device *dev = priv->net_dev;
11189 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011190
James Ketrenos43f66a62005-03-25 12:31:53 -060011191 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11192
James Ketrenosea2b26e2005-08-24 21:25:16 -050011193 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011194 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011195 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011196
James Ketrenos43f66a62005-03-25 12:31:53 -060011197 /*
11198 * Suspend/Resume resets the PCI configuration space, so we have to
11199 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11200 * from interfering with C3 CPU state. pci_restore_state won't help
11201 * here since it only restores the first 64 bytes pci config header.
11202 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011203 pci_read_config_dword(pdev, 0x40, &val);
11204 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011205 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11206
11207 /* Set the device back into the PRESENT state; this will also wake
11208 * the queue of needed */
11209 netif_device_attach(dev);
11210
11211 /* Bring the device back up */
11212 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011213
James Ketrenos43f66a62005-03-25 12:31:53 -060011214 return 0;
11215}
11216#endif
11217
11218/* driver initialization stuff */
11219static struct pci_driver ipw_driver = {
11220 .name = DRV_NAME,
11221 .id_table = card_ids,
11222 .probe = ipw_pci_probe,
11223 .remove = __devexit_p(ipw_pci_remove),
11224#ifdef CONFIG_PM
11225 .suspend = ipw_pci_suspend,
11226 .resume = ipw_pci_resume,
11227#endif
11228};
11229
11230static int __init ipw_init(void)
11231{
11232 int ret;
11233
11234 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11235 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11236
11237 ret = pci_module_init(&ipw_driver);
11238 if (ret) {
11239 IPW_ERROR("Unable to initialize PCI module\n");
11240 return ret;
11241 }
11242
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011243 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011244 if (ret) {
11245 IPW_ERROR("Unable to create driver sysfs file\n");
11246 pci_unregister_driver(&ipw_driver);
11247 return ret;
11248 }
11249
11250 return ret;
11251}
11252
11253static void __exit ipw_exit(void)
11254{
11255 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11256 pci_unregister_driver(&ipw_driver);
11257}
11258
11259module_param(disable, int, 0444);
11260MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11261
11262module_param(associate, int, 0444);
11263MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11264
11265module_param(auto_create, int, 0444);
11266MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11267
James Ketrenosa613bff2005-08-24 21:43:11 -050011268module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011269MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011270
James Ketrenos43f66a62005-03-25 12:31:53 -060011271module_param(debug, int, 0444);
11272MODULE_PARM_DESC(debug, "debug output mask");
11273
11274module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011275MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011276
James Ketrenosb095c382005-08-24 22:04:42 -050011277#ifdef CONFIG_IPW_QOS
11278module_param(qos_enable, int, 0444);
11279MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11280
11281module_param(qos_burst_enable, int, 0444);
11282MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11283
11284module_param(qos_no_ack_mask, int, 0444);
11285MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11286
11287module_param(burst_duration_CCK, int, 0444);
11288MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11289
11290module_param(burst_duration_OFDM, int, 0444);
11291MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11292#endif /* CONFIG_IPW_QOS */
11293
11294#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011295module_param(mode, int, 0444);
11296MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11297#else
11298module_param(mode, int, 0444);
11299MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11300#endif
11301
James Ketrenosb095c382005-08-24 22:04:42 -050011302module_param(hwcrypto, int, 0444);
11303MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11304
James Ketrenos43f66a62005-03-25 12:31:53 -060011305module_exit(ipw_exit);
11306module_init(ipw_init);