blob: 6e862c2905deb2b12e7c4e3a165dc3e946ab2d83 [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
431static char *ipw_error_desc(u32 val)
432{
433 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400434 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600435 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400436 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600437 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400438 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600439 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400440 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600441 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400442 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500443 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400444 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500445 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400446 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500447 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400448 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500449 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400450 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500451 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400452 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500453 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400454 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500455 return "DMA_STATUS";
456 case IPW_FW_ERROR_DINO_ERROR:
457 return "DINO_ERROR";
458 case IPW_FW_ERROR_EEPROM_ERROR:
459 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400460 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500461 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400462 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500463 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400464 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500465 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600466 }
467}
468
469static void ipw_dump_nic_error_log(struct ipw_priv *priv)
470{
471 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
472
473 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
474 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400475
James Ketrenos43f66a62005-03-25 12:31:53 -0600476 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
477 IPW_ERROR("Start IPW Error Log Dump:\n");
478 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
479 priv->status, priv->config);
480 }
481
Jeff Garzikbf794512005-07-31 13:07:26 -0400482 for (i = ERROR_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400483 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
484 desc = ipw_read_reg32(priv, base + i);
485 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
486 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
487 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
488 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
489 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
490 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600491
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400492 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
493 ipw_error_desc(desc), time, blink1, blink2,
494 ilink1, ilink2, idata);
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 }
496}
497
498static void ipw_dump_nic_event_log(struct ipw_priv *priv)
499{
500 u32 ev, time, data, i, count, base;
501
502 base = ipw_read32(priv, IPW_EVENT_LOG);
503 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400504
James Ketrenos43f66a62005-03-25 12:31:53 -0600505 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
506 IPW_ERROR("Start IPW Event Log Dump:\n");
507
Jeff Garzikbf794512005-07-31 13:07:26 -0400508 for (i = EVENT_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400509 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600510 ev = ipw_read_reg32(priv, base + i);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400511 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
512 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600513
514#ifdef CONFIG_IPW_DEBUG
515 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
516#endif
517 }
518}
519
James Ketrenosc848d0a2005-08-24 21:56:24 -0500520static inline int ipw_is_init(struct ipw_priv *priv)
521{
522 return (priv->status & STATUS_INIT) ? 1 : 0;
523}
524
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400525static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600526{
527 u32 addr, field_info, field_len, field_count, total_len;
528
529 IPW_DEBUG_ORD("ordinal = %i\n", ord);
530
531 if (!priv || !val || !len) {
532 IPW_DEBUG_ORD("Invalid argument\n");
533 return -EINVAL;
534 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400535
James Ketrenos43f66a62005-03-25 12:31:53 -0600536 /* verify device ordinal tables have been initialized */
537 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
538 IPW_DEBUG_ORD("Access ordinals before initialization\n");
539 return -EINVAL;
540 }
541
542 switch (IPW_ORD_TABLE_ID_MASK & ord) {
543 case IPW_ORD_TABLE_0_MASK:
544 /*
545 * TABLE 0: Direct access to a table of 32 bit values
546 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400547 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600548 * read from the table
549 */
550
551 /* remove the table id from the ordinal */
552 ord &= IPW_ORD_TABLE_VALUE_MASK;
553
554 /* boundary check */
555 if (ord > priv->table0_len) {
556 IPW_DEBUG_ORD("ordinal value (%i) longer then "
557 "max (%i)\n", ord, priv->table0_len);
558 return -EINVAL;
559 }
560
561 /* verify we have enough room to store the value */
562 if (*len < sizeof(u32)) {
563 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200564 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600565 return -EINVAL;
566 }
567
568 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400569 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600570
571 *len = sizeof(u32);
572 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400573 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600574 break;
575
576 case IPW_ORD_TABLE_1_MASK:
577 /*
578 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400579 *
580 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600581 * representing starting addr for the data (which is
582 * also a u32)
583 */
584
585 /* remove the table id from the ordinal */
586 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400587
James Ketrenos43f66a62005-03-25 12:31:53 -0600588 /* boundary check */
589 if (ord > priv->table1_len) {
590 IPW_DEBUG_ORD("ordinal value too long\n");
591 return -EINVAL;
592 }
593
594 /* verify we have enough room to store the value */
595 if (*len < sizeof(u32)) {
596 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200597 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600598 return -EINVAL;
599 }
600
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400601 *((u32 *) val) =
602 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600603 *len = sizeof(u32);
604 break;
605
606 case IPW_ORD_TABLE_2_MASK:
607 /*
608 * TABLE 2: Indirect access to a table of variable sized values
609 *
610 * This table consist of six values, each containing
611 * - dword containing the starting offset of the data
612 * - dword containing the lengh in the first 16bits
613 * and the count in the second 16bits
614 */
615
616 /* remove the table id from the ordinal */
617 ord &= IPW_ORD_TABLE_VALUE_MASK;
618
619 /* boundary check */
620 if (ord > priv->table2_len) {
621 IPW_DEBUG_ORD("ordinal value too long\n");
622 return -EINVAL;
623 }
624
625 /* get the address of statistic */
626 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400627
628 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600629 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400630 field_info =
631 ipw_read_reg32(priv,
632 priv->table2_addr + (ord << 3) +
633 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400634
James Ketrenos43f66a62005-03-25 12:31:53 -0600635 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400636 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400637
James Ketrenos43f66a62005-03-25 12:31:53 -0600638 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400639 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400640
James Ketrenos43f66a62005-03-25 12:31:53 -0600641 /* abort if not enought memory */
642 total_len = field_len * field_count;
643 if (total_len > *len) {
644 *len = total_len;
645 return -EINVAL;
646 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400647
James Ketrenos43f66a62005-03-25 12:31:53 -0600648 *len = total_len;
649 if (!total_len)
650 return 0;
651
652 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400653 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600654 addr, total_len, field_info);
655 ipw_read_indirect(priv, addr, val, total_len);
656 break;
657
658 default:
659 IPW_DEBUG_ORD("Invalid ordinal!\n");
660 return -EINVAL;
661
662 }
663
James Ketrenos43f66a62005-03-25 12:31:53 -0600664 return 0;
665}
666
667static void ipw_init_ordinals(struct ipw_priv *priv)
668{
669 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400670 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600671
672 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
673 priv->table0_addr, priv->table0_len);
674
675 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
676 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
677
678 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
679 priv->table1_addr, priv->table1_len);
680
681 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
682 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400683 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600684
685 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
686 priv->table2_addr, priv->table2_len);
687
688}
689
James Ketrenosa613bff2005-08-24 21:43:11 -0500690u32 ipw_register_toggle(u32 reg)
691{
James Ketrenosb095c382005-08-24 22:04:42 -0500692 reg &= ~IPW_START_STANDBY;
693 if (reg & IPW_GATE_ODMA)
694 reg &= ~IPW_GATE_ODMA;
695 if (reg & IPW_GATE_IDMA)
696 reg &= ~IPW_GATE_IDMA;
697 if (reg & IPW_GATE_ADMA)
698 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500699 return reg;
700}
701
702/*
703 * LED behavior:
704 * - On radio ON, turn on any LEDs that require to be on during start
705 * - On initialization, start unassociated blink
706 * - On association, disable unassociated blink
707 * - On disassociation, start unassociated blink
708 * - On radio OFF, turn off any LEDs started during radio on
709 *
710 */
711#define LD_TIME_LINK_ON 300
712#define LD_TIME_LINK_OFF 2700
713#define LD_TIME_ACT_ON 250
714
715void ipw_led_link_on(struct ipw_priv *priv)
716{
717 unsigned long flags;
718 u32 led;
719
720 /* If configured to not use LEDs, or nic_type is 1,
721 * then we don't toggle a LINK led */
722 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
723 return;
724
725 spin_lock_irqsave(&priv->lock, flags);
726
727 if (!(priv->status & STATUS_RF_KILL_MASK) &&
728 !(priv->status & STATUS_LED_LINK_ON)) {
729 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500730 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500731 led |= priv->led_association_on;
732
733 led = ipw_register_toggle(led);
734
735 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500736 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500737
738 priv->status |= STATUS_LED_LINK_ON;
739
740 /* If we aren't associated, schedule turning the LED off */
741 if (!(priv->status & STATUS_ASSOCIATED))
742 queue_delayed_work(priv->workqueue,
743 &priv->led_link_off,
744 LD_TIME_LINK_ON);
745 }
746
747 spin_unlock_irqrestore(&priv->lock, flags);
748}
749
James Ketrenosc848d0a2005-08-24 21:56:24 -0500750static void ipw_bg_led_link_on(void *data)
751{
752 struct ipw_priv *priv = data;
753 down(&priv->sem);
754 ipw_led_link_on(data);
755 up(&priv->sem);
756}
757
James Ketrenosa613bff2005-08-24 21:43:11 -0500758void ipw_led_link_off(struct ipw_priv *priv)
759{
760 unsigned long flags;
761 u32 led;
762
763 /* If configured not to use LEDs, or nic type is 1,
764 * then we don't goggle the LINK led. */
765 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
766 return;
767
768 spin_lock_irqsave(&priv->lock, flags);
769
770 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500771 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500772 led &= priv->led_association_off;
773 led = ipw_register_toggle(led);
774
775 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500776 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500777
778 IPW_DEBUG_LED("Link LED Off\n");
779
780 priv->status &= ~STATUS_LED_LINK_ON;
781
782 /* If we aren't associated and the radio is on, schedule
783 * turning the LED on (blink while unassociated) */
784 if (!(priv->status & STATUS_RF_KILL_MASK) &&
785 !(priv->status & STATUS_ASSOCIATED))
786 queue_delayed_work(priv->workqueue, &priv->led_link_on,
787 LD_TIME_LINK_OFF);
788
789 }
790
791 spin_unlock_irqrestore(&priv->lock, flags);
792}
793
James Ketrenosc848d0a2005-08-24 21:56:24 -0500794static void ipw_bg_led_link_off(void *data)
795{
796 struct ipw_priv *priv = data;
797 down(&priv->sem);
798 ipw_led_link_off(data);
799 up(&priv->sem);
800}
801
James Ketrenosb095c382005-08-24 22:04:42 -0500802static inline void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500803{
James Ketrenosa613bff2005-08-24 21:43:11 -0500804 u32 led;
805
806 if (priv->config & CFG_NO_LED)
807 return;
808
James Ketrenosb095c382005-08-24 22:04:42 -0500809 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500810 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500811
812 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500813 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500814 led |= priv->led_activity_on;
815
816 led = ipw_register_toggle(led);
817
818 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500819 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500820
821 IPW_DEBUG_LED("Activity LED On\n");
822
823 priv->status |= STATUS_LED_ACT_ON;
824
James Ketrenosc848d0a2005-08-24 21:56:24 -0500825 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500826 queue_delayed_work(priv->workqueue, &priv->led_act_off,
827 LD_TIME_ACT_ON);
828 } else {
829 /* Reschedule LED off for full time period */
830 cancel_delayed_work(&priv->led_act_off);
831 queue_delayed_work(priv->workqueue, &priv->led_act_off,
832 LD_TIME_ACT_ON);
833 }
James Ketrenosb095c382005-08-24 22:04:42 -0500834}
James Ketrenosa613bff2005-08-24 21:43:11 -0500835
James Ketrenosb095c382005-08-24 22:04:42 -0500836void ipw_led_activity_on(struct ipw_priv *priv)
837{
838 unsigned long flags;
839 spin_lock_irqsave(&priv->lock, flags);
840 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500841 spin_unlock_irqrestore(&priv->lock, flags);
842}
843
844void ipw_led_activity_off(struct ipw_priv *priv)
845{
846 unsigned long flags;
847 u32 led;
848
849 if (priv->config & CFG_NO_LED)
850 return;
851
852 spin_lock_irqsave(&priv->lock, flags);
853
854 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500855 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500856 led &= priv->led_activity_off;
857
858 led = ipw_register_toggle(led);
859
860 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500861 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500862
863 IPW_DEBUG_LED("Activity LED Off\n");
864
865 priv->status &= ~STATUS_LED_ACT_ON;
866 }
867
868 spin_unlock_irqrestore(&priv->lock, flags);
869}
870
James Ketrenosc848d0a2005-08-24 21:56:24 -0500871static void ipw_bg_led_activity_off(void *data)
872{
873 struct ipw_priv *priv = data;
874 down(&priv->sem);
875 ipw_led_activity_off(data);
876 up(&priv->sem);
877}
878
James Ketrenosa613bff2005-08-24 21:43:11 -0500879void ipw_led_band_on(struct ipw_priv *priv)
880{
881 unsigned long flags;
882 u32 led;
883
884 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500885 if (priv->config & CFG_NO_LED ||
886 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500887 return;
888
889 spin_lock_irqsave(&priv->lock, flags);
890
James Ketrenosb095c382005-08-24 22:04:42 -0500891 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500892 if (priv->assoc_network->mode == IEEE_A) {
893 led |= priv->led_ofdm_on;
894 led &= priv->led_association_off;
895 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
896 } else if (priv->assoc_network->mode == IEEE_G) {
897 led |= priv->led_ofdm_on;
898 led |= priv->led_association_on;
899 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
900 } else {
901 led &= priv->led_ofdm_off;
902 led |= priv->led_association_on;
903 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
904 }
905
906 led = ipw_register_toggle(led);
907
908 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500909 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500910
911 spin_unlock_irqrestore(&priv->lock, flags);
912}
913
914void ipw_led_band_off(struct ipw_priv *priv)
915{
916 unsigned long flags;
917 u32 led;
918
919 /* Only nic type 1 supports mode LEDs */
920 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
921 return;
922
923 spin_lock_irqsave(&priv->lock, flags);
924
James Ketrenosb095c382005-08-24 22:04:42 -0500925 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500926 led &= priv->led_ofdm_off;
927 led &= priv->led_association_off;
928
929 led = ipw_register_toggle(led);
930
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500932 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933
934 spin_unlock_irqrestore(&priv->lock, flags);
935}
936
937void ipw_led_radio_on(struct ipw_priv *priv)
938{
939 ipw_led_link_on(priv);
940}
941
942void ipw_led_radio_off(struct ipw_priv *priv)
943{
944 ipw_led_activity_off(priv);
945 ipw_led_link_off(priv);
946}
947
948void ipw_led_link_up(struct ipw_priv *priv)
949{
950 /* Set the Link Led on for all nic types */
951 ipw_led_link_on(priv);
952}
953
954void ipw_led_link_down(struct ipw_priv *priv)
955{
956 ipw_led_activity_off(priv);
957 ipw_led_link_off(priv);
958
959 if (priv->status & STATUS_RF_KILL_MASK)
960 ipw_led_radio_off(priv);
961}
962
963void ipw_led_init(struct ipw_priv *priv)
964{
965 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
966
967 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500968 priv->led_activity_on = IPW_ACTIVITY_LED;
969 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500970
James Ketrenosb095c382005-08-24 22:04:42 -0500971 priv->led_association_on = IPW_ASSOCIATED_LED;
972 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500973
974 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -0500975 priv->led_ofdm_on = IPW_OFDM_LED;
976 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500977
978 switch (priv->nic_type) {
979 case EEPROM_NIC_TYPE_1:
980 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -0500981 priv->led_activity_on = IPW_ASSOCIATED_LED;
982 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
983 priv->led_association_on = IPW_ACTIVITY_LED;
984 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -0500985
986 if (!(priv->config & CFG_NO_LED))
987 ipw_led_band_on(priv);
988
989 /* And we don't blink link LEDs for this nic, so
990 * just return here */
991 return;
992
993 case EEPROM_NIC_TYPE_3:
994 case EEPROM_NIC_TYPE_2:
995 case EEPROM_NIC_TYPE_4:
996 case EEPROM_NIC_TYPE_0:
997 break;
998
999 default:
1000 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1001 priv->nic_type);
1002 priv->nic_type = EEPROM_NIC_TYPE_0;
1003 break;
1004 }
1005
1006 if (!(priv->config & CFG_NO_LED)) {
1007 if (priv->status & STATUS_ASSOCIATED)
1008 ipw_led_link_on(priv);
1009 else
1010 ipw_led_link_off(priv);
1011 }
1012}
1013
1014void ipw_led_shutdown(struct ipw_priv *priv)
1015{
James Ketrenosa613bff2005-08-24 21:43:11 -05001016 ipw_led_activity_off(priv);
1017 ipw_led_link_off(priv);
1018 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001019 cancel_delayed_work(&priv->led_link_on);
1020 cancel_delayed_work(&priv->led_link_off);
1021 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001022}
1023
James Ketrenos43f66a62005-03-25 12:31:53 -06001024/*
1025 * The following adds a new attribute to the sysfs representation
1026 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1027 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001028 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001029 * See the level definitions in ipw for details.
1030 */
1031static ssize_t show_debug_level(struct device_driver *d, char *buf)
1032{
1033 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1034}
James Ketrenosa613bff2005-08-24 21:43:11 -05001035
1036static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1037 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001038{
1039 char *p = (char *)buf;
1040 u32 val;
1041
1042 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1043 p++;
1044 if (p[0] == 'x' || p[0] == 'X')
1045 p++;
1046 val = simple_strtoul(p, &p, 16);
1047 } else
1048 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001049 if (p == buf)
1050 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001051 ": %s is not in hex or decimal form.\n", buf);
1052 else
1053 ipw_debug_level = val;
1054
1055 return strnlen(buf, count);
1056}
1057
Jeff Garzikbf794512005-07-31 13:07:26 -04001058static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001059 show_debug_level, store_debug_level);
1060
James Ketrenosa613bff2005-08-24 21:43:11 -05001061static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1062 char *buf)
1063{
1064 struct ipw_priv *priv = dev_get_drvdata(d);
1065 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1066}
1067
1068static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1069 const char *buf, size_t count)
1070{
1071 struct ipw_priv *priv = dev_get_drvdata(d);
James Ketrenosc848d0a2005-08-24 21:56:24 -05001072#ifdef CONFIG_IPW_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001073 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001074#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001075 char buffer[] = "00000000";
1076 unsigned long len =
1077 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1078 unsigned long val;
1079 char *p = buffer;
1080
1081 IPW_DEBUG_INFO("enter\n");
1082
1083 strncpy(buffer, buf, len);
1084 buffer[len] = 0;
1085
1086 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1087 p++;
1088 if (p[0] == 'x' || p[0] == 'X')
1089 p++;
1090 val = simple_strtoul(p, &p, 16);
1091 } else
1092 val = simple_strtoul(p, &p, 10);
1093 if (p == buffer) {
1094 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1095 } else {
1096 priv->ieee->scan_age = val;
1097 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1098 }
1099
1100 IPW_DEBUG_INFO("exit\n");
1101 return len;
1102}
1103
1104static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1105
1106static ssize_t show_led(struct device *d, struct device_attribute *attr,
1107 char *buf)
1108{
1109 struct ipw_priv *priv = dev_get_drvdata(d);
1110 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1111}
1112
1113static ssize_t store_led(struct device *d, struct device_attribute *attr,
1114 const char *buf, size_t count)
1115{
1116 struct ipw_priv *priv = dev_get_drvdata(d);
1117
1118 IPW_DEBUG_INFO("enter\n");
1119
1120 if (count == 0)
1121 return 0;
1122
1123 if (*buf == 0) {
1124 IPW_DEBUG_LED("Disabling LED control.\n");
1125 priv->config |= CFG_NO_LED;
1126 ipw_led_shutdown(priv);
1127 } else {
1128 IPW_DEBUG_LED("Enabling LED control.\n");
1129 priv->config &= ~CFG_NO_LED;
1130 ipw_led_init(priv);
1131 }
1132
1133 IPW_DEBUG_INFO("exit\n");
1134 return count;
1135}
1136
1137static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1138
Andrew Mortonad3fee52005-06-20 14:30:36 -07001139static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001140 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001141{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001142 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001143 return sprintf(buf, "0x%08x\n", (int)p->status);
1144}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001145
James Ketrenos43f66a62005-03-25 12:31:53 -06001146static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1147
Andrew Mortonad3fee52005-06-20 14:30:36 -07001148static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1149 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001150{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001151 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001152 return sprintf(buf, "0x%08x\n", (int)p->config);
1153}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001154
James Ketrenos43f66a62005-03-25 12:31:53 -06001155static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1156
Andrew Mortonad3fee52005-06-20 14:30:36 -07001157static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001158 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001159{
James Ketrenosa613bff2005-08-24 21:43:11 -05001160 struct ipw_priv *priv = d->driver_data;
1161 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001162}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001163
James Ketrenos43f66a62005-03-25 12:31:53 -06001164static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1165
Andrew Mortonad3fee52005-06-20 14:30:36 -07001166static ssize_t dump_error_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001167 struct device_attribute *attr, const char *buf,
1168 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001169{
1170 char *p = (char *)buf;
1171
Jeff Garzikbf794512005-07-31 13:07:26 -04001172 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001173 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06001174
1175 return strnlen(buf, count);
1176}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001177
James Ketrenos43f66a62005-03-25 12:31:53 -06001178static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
1179
Andrew Mortonad3fee52005-06-20 14:30:36 -07001180static ssize_t dump_event_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001181 struct device_attribute *attr, const char *buf,
1182 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001183{
1184 char *p = (char *)buf;
1185
Jeff Garzikbf794512005-07-31 13:07:26 -04001186 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001187 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06001188
1189 return strnlen(buf, count);
1190}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001191
James Ketrenos43f66a62005-03-25 12:31:53 -06001192static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
1193
Andrew Mortonad3fee52005-06-20 14:30:36 -07001194static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001195 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001196{
1197 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001198 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001199
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001200 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001201 return 0;
1202
1203 return sprintf(buf, "0x%08x\n", tmp);
1204}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001205
1206static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001207
Andrew Mortonad3fee52005-06-20 14:30:36 -07001208static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1209 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001210{
1211 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001212 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001213
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001214 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001215 return 0;
1216
1217 return sprintf(buf, "0x%08x\n", tmp);
1218}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001219
1220static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001221
1222/*
1223 * Add a device attribute to view/control the delay between eeprom
1224 * operations.
1225 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001226static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001227 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001228{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001229 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001230 return sprintf(buf, "%i\n", n);
1231}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001232static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001233 struct device_attribute *attr,
1234 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001235{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001236 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001237 sscanf(buf, "%i", &p->eeprom_delay);
1238 return strnlen(buf, count);
1239}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001240
1241static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1242 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001243
Andrew Mortonad3fee52005-06-20 14:30:36 -07001244static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001245 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001246{
1247 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001248 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001249
James Ketrenosb095c382005-08-24 22:04:42 -05001250 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001251 return sprintf(buf, "0x%08x\n", reg);
1252}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001253static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001254 struct device_attribute *attr,
1255 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001256{
1257 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001258 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001259
1260 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001261 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001262 return strnlen(buf, count);
1263}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001264
1265static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1266 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001267
Andrew Mortonad3fee52005-06-20 14:30:36 -07001268static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001269 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001270{
1271 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001272 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001273
1274 reg = ipw_read_reg32(p, 0x301100);
1275 return sprintf(buf, "0x%08x\n", reg);
1276}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001277static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001278 struct device_attribute *attr,
1279 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001280{
1281 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001282 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001283
1284 sscanf(buf, "%x", &reg);
1285 ipw_write_reg32(p, 0x301100, reg);
1286 return strnlen(buf, count);
1287}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001288
1289static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1290 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001291
Andrew Mortonad3fee52005-06-20 14:30:36 -07001292static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001293 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001294{
1295 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001296 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001297
Jeff Garzikbf794512005-07-31 13:07:26 -04001298 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001299 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001300 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001301 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001302
James Ketrenos43f66a62005-03-25 12:31:53 -06001303 return sprintf(buf, "0x%08x\n", reg);
1304}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001305static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001306 struct device_attribute *attr,
1307 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001308{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001309 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001310
1311 sscanf(buf, "%x", &priv->indirect_dword);
1312 priv->status |= STATUS_INDIRECT_DWORD;
1313 return strnlen(buf, count);
1314}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001315
1316static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1317 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001318
Andrew Mortonad3fee52005-06-20 14:30:36 -07001319static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001320 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001321{
1322 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001323 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001324
Jeff Garzikbf794512005-07-31 13:07:26 -04001325 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001326 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001327 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001328 reg = 0;
1329
1330 return sprintf(buf, "0x%02x\n", reg);
1331}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001332static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001333 struct device_attribute *attr,
1334 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001335{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001336 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001337
1338 sscanf(buf, "%x", &priv->indirect_byte);
1339 priv->status |= STATUS_INDIRECT_BYTE;
1340 return strnlen(buf, count);
1341}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001342
1343static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001344 show_indirect_byte, store_indirect_byte);
1345
Andrew Mortonad3fee52005-06-20 14:30:36 -07001346static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001347 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001348{
1349 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001350 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001351
Jeff Garzikbf794512005-07-31 13:07:26 -04001352 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001353 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001354 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001355 reg = 0;
1356
1357 return sprintf(buf, "0x%08x\n", reg);
1358}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001359static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001360 struct device_attribute *attr,
1361 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001362{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001363 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001364
1365 sscanf(buf, "%x", &priv->direct_dword);
1366 priv->status |= STATUS_DIRECT_DWORD;
1367 return strnlen(buf, count);
1368}
James Ketrenos43f66a62005-03-25 12:31:53 -06001369
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001370static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1371 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001372
1373static inline int rf_kill_active(struct ipw_priv *priv)
1374{
1375 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1376 priv->status |= STATUS_RF_KILL_HW;
1377 else
1378 priv->status &= ~STATUS_RF_KILL_HW;
1379
1380 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1381}
1382
Andrew Mortonad3fee52005-06-20 14:30:36 -07001383static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001384 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001385{
1386 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001387 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001388 2 - HW based RF kill active
1389 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001390 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001391 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001392 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001393 return sprintf(buf, "%i\n", val);
1394}
1395
1396static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1397{
Jeff Garzikbf794512005-07-31 13:07:26 -04001398 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001399 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001400 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001401
1402 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1403 disable_radio ? "OFF" : "ON");
1404
1405 if (disable_radio) {
1406 priv->status |= STATUS_RF_KILL_SW;
1407
James Ketrenosa613bff2005-08-24 21:43:11 -05001408 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001409 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001410 queue_work(priv->workqueue, &priv->down);
1411 } else {
1412 priv->status &= ~STATUS_RF_KILL_SW;
1413 if (rf_kill_active(priv)) {
1414 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1415 "disabled by HW switch\n");
1416 /* Make sure the RF_KILL check timer is running */
1417 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001418 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001419 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001420 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001421 queue_work(priv->workqueue, &priv->up);
1422 }
1423
1424 return 1;
1425}
1426
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001427static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1428 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001429{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001430 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001431
James Ketrenos43f66a62005-03-25 12:31:53 -06001432 ipw_radio_kill_sw(priv, buf[0] == '1');
1433
1434 return count;
1435}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001436
1437static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001438
James Ketrenosb095c382005-08-24 22:04:42 -05001439static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1440 char *buf)
1441{
1442 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1443 int pos = 0, len = 0;
1444 if (priv->config & CFG_SPEED_SCAN) {
1445 while (priv->speed_scan[pos] != 0)
1446 len += sprintf(&buf[len], "%d ",
1447 priv->speed_scan[pos++]);
1448 return len + sprintf(&buf[len], "\n");
1449 }
1450
1451 return sprintf(buf, "0\n");
1452}
1453
1454static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1455 const char *buf, size_t count)
1456{
1457 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1458 int channel, pos = 0;
1459 const char *p = buf;
1460
1461 /* list of space separated channels to scan, optionally ending with 0 */
1462 while ((channel = simple_strtol(p, NULL, 0))) {
1463 if (pos == MAX_SPEED_SCAN - 1) {
1464 priv->speed_scan[pos] = 0;
1465 break;
1466 }
1467
1468 if (ieee80211_is_valid_channel(priv->ieee, channel))
1469 priv->speed_scan[pos++] = channel;
1470 else
1471 IPW_WARNING("Skipping invalid channel request: %d\n",
1472 channel);
1473 p = strchr(p, ' ');
1474 if (!p)
1475 break;
1476 while (*p == ' ' || *p == '\t')
1477 p++;
1478 }
1479
1480 if (pos == 0)
1481 priv->config &= ~CFG_SPEED_SCAN;
1482 else {
1483 priv->speed_scan_pos = 0;
1484 priv->config |= CFG_SPEED_SCAN;
1485 }
1486
1487 return count;
1488}
1489
1490static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1491 store_speed_scan);
1492
1493static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1494 char *buf)
1495{
1496 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1497 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1498}
1499
1500static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1501 const char *buf, size_t count)
1502{
1503 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1504 if (buf[0] == '1')
1505 priv->config |= CFG_NET_STATS;
1506 else
1507 priv->config &= ~CFG_NET_STATS;
1508
1509 return count;
1510}
1511
James Ketrenosafbf30a2005-08-25 00:05:33 -05001512static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1513 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001514
James Ketrenosea2b26e2005-08-24 21:25:16 -05001515static void notify_wx_assoc_event(struct ipw_priv *priv)
1516{
1517 union iwreq_data wrqu;
1518 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1519 if (priv->status & STATUS_ASSOCIATED)
1520 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1521 else
1522 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1523 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1524}
1525
James Ketrenos43f66a62005-03-25 12:31:53 -06001526static void ipw_irq_tasklet(struct ipw_priv *priv)
1527{
1528 u32 inta, inta_mask, handled = 0;
1529 unsigned long flags;
1530 int rc = 0;
1531
1532 spin_lock_irqsave(&priv->lock, flags);
1533
James Ketrenosb095c382005-08-24 22:04:42 -05001534 inta = ipw_read32(priv, IPW_INTA_RW);
1535 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1536 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001537
1538 /* Add any cached INTA values that need to be handled */
1539 inta |= priv->isr_inta;
1540
1541 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001542 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001543 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001544 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001545 }
1546
James Ketrenosb095c382005-08-24 22:04:42 -05001547 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001548 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001549 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001550 priv->status &= ~STATUS_HCMD_ACTIVE;
1551 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001552 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001553 }
1554
James Ketrenosb095c382005-08-24 22:04:42 -05001555 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001556 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001558 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001559 }
1560
James Ketrenosb095c382005-08-24 22:04:42 -05001561 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001562 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001563 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001564 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001565 }
1566
James Ketrenosb095c382005-08-24 22:04:42 -05001567 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001568 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001569 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001570 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001571 }
1572
James Ketrenosb095c382005-08-24 22:04:42 -05001573 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001574 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001576 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001577 }
1578
James Ketrenosb095c382005-08-24 22:04:42 -05001579 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001580 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001581 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001582 }
1583
James Ketrenosb095c382005-08-24 22:04:42 -05001584 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001585 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001586 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001587 }
1588
James Ketrenosb095c382005-08-24 22:04:42 -05001589 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001590 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001591 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001592 }
1593
James Ketrenosb095c382005-08-24 22:04:42 -05001594 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001595 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001596 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001597 }
1598
James Ketrenosb095c382005-08-24 22:04:42 -05001599 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001600 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001601 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001602 }
1603
James Ketrenosb095c382005-08-24 22:04:42 -05001604 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001605 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1606 priv->status |= STATUS_RF_KILL_HW;
1607 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001608 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001609 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001610 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001611 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001612 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001613 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001614
James Ketrenosb095c382005-08-24 22:04:42 -05001615 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001616 IPW_ERROR("Firmware error detected. Restarting.\n");
1617#ifdef CONFIG_IPW_DEBUG
1618 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1619 ipw_dump_nic_error_log(priv);
1620 ipw_dump_nic_event_log(priv);
1621 }
1622#endif
James Ketrenosb095c382005-08-24 22:04:42 -05001623 /* XXX: If hardware encryption is for WPA/WPA2,
1624 * we have to notify the supplicant. */
1625 if (priv->ieee->sec.encrypt) {
1626 priv->status &= ~STATUS_ASSOCIATED;
1627 notify_wx_assoc_event(priv);
1628 }
1629
1630 /* Keep the restart process from trying to send host
1631 * commands by clearing the INIT status bit */
1632 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001633
1634 /* Cancel currently queued command. */
1635 priv->status &= ~STATUS_HCMD_ACTIVE;
1636 wake_up_interruptible(&priv->wait_command_queue);
1637
James Ketrenos43f66a62005-03-25 12:31:53 -06001638 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001639 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001640 }
1641
James Ketrenosb095c382005-08-24 22:04:42 -05001642 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001643 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001644 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001645 }
1646
1647 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001648 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001649 }
1650
1651 /* enable all interrupts */
1652 ipw_enable_interrupts(priv);
1653
1654 spin_unlock_irqrestore(&priv->lock, flags);
1655}
Jeff Garzikbf794512005-07-31 13:07:26 -04001656
James Ketrenos43f66a62005-03-25 12:31:53 -06001657#ifdef CONFIG_IPW_DEBUG
1658#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1659static char *get_cmd_string(u8 cmd)
1660{
1661 switch (cmd) {
1662 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001663 IPW_CMD(POWER_DOWN);
1664 IPW_CMD(SYSTEM_CONFIG);
1665 IPW_CMD(MULTICAST_ADDRESS);
1666 IPW_CMD(SSID);
1667 IPW_CMD(ADAPTER_ADDRESS);
1668 IPW_CMD(PORT_TYPE);
1669 IPW_CMD(RTS_THRESHOLD);
1670 IPW_CMD(FRAG_THRESHOLD);
1671 IPW_CMD(POWER_MODE);
1672 IPW_CMD(WEP_KEY);
1673 IPW_CMD(TGI_TX_KEY);
1674 IPW_CMD(SCAN_REQUEST);
1675 IPW_CMD(SCAN_REQUEST_EXT);
1676 IPW_CMD(ASSOCIATE);
1677 IPW_CMD(SUPPORTED_RATES);
1678 IPW_CMD(SCAN_ABORT);
1679 IPW_CMD(TX_FLUSH);
1680 IPW_CMD(QOS_PARAMETERS);
1681 IPW_CMD(DINO_CONFIG);
1682 IPW_CMD(RSN_CAPABILITIES);
1683 IPW_CMD(RX_KEY);
1684 IPW_CMD(CARD_DISABLE);
1685 IPW_CMD(SEED_NUMBER);
1686 IPW_CMD(TX_POWER);
1687 IPW_CMD(COUNTRY_INFO);
1688 IPW_CMD(AIRONET_INFO);
1689 IPW_CMD(AP_TX_POWER);
1690 IPW_CMD(CCKM_INFO);
1691 IPW_CMD(CCX_VER_INFO);
1692 IPW_CMD(SET_CALIBRATION);
1693 IPW_CMD(SENSITIVITY_CALIB);
1694 IPW_CMD(RETRY_LIMIT);
1695 IPW_CMD(IPW_PRE_POWER_DOWN);
1696 IPW_CMD(VAP_BEACON_TEMPLATE);
1697 IPW_CMD(VAP_DTIM_PERIOD);
1698 IPW_CMD(EXT_SUPPORTED_RATES);
1699 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1700 IPW_CMD(VAP_QUIET_INTERVALS);
1701 IPW_CMD(VAP_CHANNEL_SWITCH);
1702 IPW_CMD(VAP_MANDATORY_CHANNELS);
1703 IPW_CMD(VAP_CELL_PWR_LIMIT);
1704 IPW_CMD(VAP_CF_PARAM_SET);
1705 IPW_CMD(VAP_SET_BEACONING_STATE);
1706 IPW_CMD(MEASUREMENT);
1707 IPW_CMD(POWER_CAPABILITY);
1708 IPW_CMD(SUPPORTED_CHANNELS);
1709 IPW_CMD(TPC_REPORT);
1710 IPW_CMD(WME_INFO);
1711 IPW_CMD(PRODUCTION_COMMAND);
1712 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001713 return "UNKNOWN";
1714 }
1715}
James Ketrenosea2b26e2005-08-24 21:25:16 -05001716#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06001717
1718#define HOST_COMPLETE_TIMEOUT HZ
1719static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1720{
1721 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001722 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001723
James Ketrenosa613bff2005-08-24 21:43:11 -05001724 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001725 if (priv->status & STATUS_HCMD_ACTIVE) {
1726 IPW_ERROR("Already sending a command\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05001727 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001728 return -1;
1729 }
1730
1731 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001732
James Ketrenosb095c382005-08-24 22:04:42 -05001733 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1734 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1735 priv->status);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001736 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001737
1738 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001739 if (rc) {
1740 priv->status &= ~STATUS_HCMD_ACTIVE;
1741 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 return rc;
James Ketrenosa613bff2005-08-24 21:43:11 -05001743 }
1744 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001745
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001746 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1747 !(priv->
1748 status & STATUS_HCMD_ACTIVE),
1749 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001750 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001751 spin_lock_irqsave(&priv->lock, flags);
1752 if (priv->status & STATUS_HCMD_ACTIVE) {
1753 IPW_DEBUG_INFO("Command completion failed out after "
1754 "%dms.\n",
1755 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
1756 priv->status &= ~STATUS_HCMD_ACTIVE;
1757 spin_unlock_irqrestore(&priv->lock, flags);
1758 return -EIO;
1759 }
1760 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001761 }
James Ketrenosa613bff2005-08-24 21:43:11 -05001762
James Ketrenosb095c382005-08-24 22:04:42 -05001763 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001764 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1765 return -EIO;
1766 }
1767
1768 return 0;
1769}
1770
1771static int ipw_send_host_complete(struct ipw_priv *priv)
1772{
1773 struct host_cmd cmd = {
1774 .cmd = IPW_CMD_HOST_COMPLETE,
1775 .len = 0
1776 };
1777
1778 if (!priv) {
1779 IPW_ERROR("Invalid args\n");
1780 return -1;
1781 }
1782
1783 if (ipw_send_cmd(priv, &cmd)) {
1784 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1785 return -1;
1786 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001787
James Ketrenos43f66a62005-03-25 12:31:53 -06001788 return 0;
1789}
1790
Jeff Garzikbf794512005-07-31 13:07:26 -04001791static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001792 struct ipw_sys_config *config)
1793{
1794 struct host_cmd cmd = {
1795 .cmd = IPW_CMD_SYSTEM_CONFIG,
1796 .len = sizeof(*config)
1797 };
1798
1799 if (!priv || !config) {
1800 IPW_ERROR("Invalid args\n");
1801 return -1;
1802 }
1803
James Ketrenosafbf30a2005-08-25 00:05:33 -05001804 memcpy(cmd.param, config, sizeof(*config));
James Ketrenos43f66a62005-03-25 12:31:53 -06001805 if (ipw_send_cmd(priv, &cmd)) {
1806 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1807 return -1;
1808 }
1809
1810 return 0;
1811}
1812
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001813static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001814{
1815 struct host_cmd cmd = {
1816 .cmd = IPW_CMD_SSID,
1817 .len = min(len, IW_ESSID_MAX_SIZE)
1818 };
1819
1820 if (!priv || !ssid) {
1821 IPW_ERROR("Invalid args\n");
1822 return -1;
1823 }
1824
James Ketrenosafbf30a2005-08-25 00:05:33 -05001825 memcpy(cmd.param, ssid, cmd.len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001826 if (ipw_send_cmd(priv, &cmd)) {
1827 IPW_ERROR("failed to send SSID command\n");
1828 return -1;
1829 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001830
James Ketrenos43f66a62005-03-25 12:31:53 -06001831 return 0;
1832}
1833
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001834static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001835{
1836 struct host_cmd cmd = {
1837 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1838 .len = ETH_ALEN
1839 };
1840
1841 if (!priv || !mac) {
1842 IPW_ERROR("Invalid args\n");
1843 return -1;
1844 }
1845
1846 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1847 priv->net_dev->name, MAC_ARG(mac));
1848
James Ketrenosafbf30a2005-08-25 00:05:33 -05001849 memcpy(cmd.param, mac, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06001850 if (ipw_send_cmd(priv, &cmd)) {
1851 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1852 return -1;
1853 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001854
James Ketrenos43f66a62005-03-25 12:31:53 -06001855 return 0;
1856}
1857
James Ketrenosa613bff2005-08-24 21:43:11 -05001858/*
1859 * NOTE: This must be executed from our workqueue as it results in udelay
1860 * being called which may corrupt the keyboard if executed on default
1861 * workqueue
1862 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001863static void ipw_adapter_restart(void *adapter)
1864{
1865 struct ipw_priv *priv = adapter;
1866
1867 if (priv->status & STATUS_RF_KILL_MASK)
1868 return;
1869
1870 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001871
1872 if (priv->assoc_network &&
1873 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
1874 ipw_remove_current_network(priv);
1875
James Ketrenos43f66a62005-03-25 12:31:53 -06001876 if (ipw_up(priv)) {
1877 IPW_ERROR("Failed to up device\n");
1878 return;
1879 }
1880}
1881
James Ketrenosc848d0a2005-08-24 21:56:24 -05001882static void ipw_bg_adapter_restart(void *data)
1883{
1884 struct ipw_priv *priv = data;
1885 down(&priv->sem);
1886 ipw_adapter_restart(data);
1887 up(&priv->sem);
1888}
1889
James Ketrenos43f66a62005-03-25 12:31:53 -06001890#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1891
1892static void ipw_scan_check(void *data)
1893{
1894 struct ipw_priv *priv = data;
1895 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1896 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001897 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001898 IPW_SCAN_CHECK_WATCHDOG / 100);
James Ketrenosa613bff2005-08-24 21:43:11 -05001899 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06001900 }
1901}
1902
James Ketrenosc848d0a2005-08-24 21:56:24 -05001903static void ipw_bg_scan_check(void *data)
1904{
1905 struct ipw_priv *priv = data;
1906 down(&priv->sem);
1907 ipw_scan_check(data);
1908 up(&priv->sem);
1909}
1910
James Ketrenos43f66a62005-03-25 12:31:53 -06001911static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1912 struct ipw_scan_request_ext *request)
1913{
1914 struct host_cmd cmd = {
1915 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1916 .len = sizeof(*request)
1917 };
1918
James Ketrenosafbf30a2005-08-25 00:05:33 -05001919 memcpy(cmd.param, request, sizeof(*request));
James Ketrenos43f66a62005-03-25 12:31:53 -06001920 if (ipw_send_cmd(priv, &cmd)) {
1921 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1922 return -1;
1923 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001924
James Ketrenos43f66a62005-03-25 12:31:53 -06001925 return 0;
1926}
1927
1928static int ipw_send_scan_abort(struct ipw_priv *priv)
1929{
1930 struct host_cmd cmd = {
1931 .cmd = IPW_CMD_SCAN_ABORT,
1932 .len = 0
1933 };
1934
1935 if (!priv) {
1936 IPW_ERROR("Invalid args\n");
1937 return -1;
1938 }
1939
1940 if (ipw_send_cmd(priv, &cmd)) {
1941 IPW_ERROR("failed to send SCAN_ABORT command\n");
1942 return -1;
1943 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001944
James Ketrenos43f66a62005-03-25 12:31:53 -06001945 return 0;
1946}
1947
1948static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1949{
1950 struct host_cmd cmd = {
1951 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1952 .len = sizeof(struct ipw_sensitivity_calib)
1953 };
1954 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001955 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06001956 calib->beacon_rssi_raw = sens;
1957 if (ipw_send_cmd(priv, &cmd)) {
1958 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1959 return -1;
1960 }
1961
1962 return 0;
1963}
1964
1965static int ipw_send_associate(struct ipw_priv *priv,
1966 struct ipw_associate *associate)
1967{
1968 struct host_cmd cmd = {
1969 .cmd = IPW_CMD_ASSOCIATE,
1970 .len = sizeof(*associate)
1971 };
1972
James Ketrenosa613bff2005-08-24 21:43:11 -05001973 struct ipw_associate tmp_associate;
1974 memcpy(&tmp_associate, associate, sizeof(*associate));
1975 tmp_associate.policy_support =
1976 cpu_to_le16(tmp_associate.policy_support);
1977 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
1978 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
1979 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
1980 tmp_associate.listen_interval =
1981 cpu_to_le16(tmp_associate.listen_interval);
1982 tmp_associate.beacon_interval =
1983 cpu_to_le16(tmp_associate.beacon_interval);
1984 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
1985
James Ketrenos43f66a62005-03-25 12:31:53 -06001986 if (!priv || !associate) {
1987 IPW_ERROR("Invalid args\n");
1988 return -1;
1989 }
1990
James Ketrenosafbf30a2005-08-25 00:05:33 -05001991 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06001992 if (ipw_send_cmd(priv, &cmd)) {
1993 IPW_ERROR("failed to send ASSOCIATE command\n");
1994 return -1;
1995 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001996
James Ketrenos43f66a62005-03-25 12:31:53 -06001997 return 0;
1998}
1999
2000static int ipw_send_supported_rates(struct ipw_priv *priv,
2001 struct ipw_supported_rates *rates)
2002{
2003 struct host_cmd cmd = {
2004 .cmd = IPW_CMD_SUPPORTED_RATES,
2005 .len = sizeof(*rates)
2006 };
2007
2008 if (!priv || !rates) {
2009 IPW_ERROR("Invalid args\n");
2010 return -1;
2011 }
2012
James Ketrenosafbf30a2005-08-25 00:05:33 -05002013 memcpy(cmd.param, rates, sizeof(*rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06002014 if (ipw_send_cmd(priv, &cmd)) {
2015 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
2016 return -1;
2017 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002018
James Ketrenos43f66a62005-03-25 12:31:53 -06002019 return 0;
2020}
2021
2022static int ipw_set_random_seed(struct ipw_priv *priv)
2023{
2024 struct host_cmd cmd = {
2025 .cmd = IPW_CMD_SEED_NUMBER,
2026 .len = sizeof(u32)
2027 };
2028
2029 if (!priv) {
2030 IPW_ERROR("Invalid args\n");
2031 return -1;
2032 }
2033
2034 get_random_bytes(&cmd.param, sizeof(u32));
2035
2036 if (ipw_send_cmd(priv, &cmd)) {
2037 IPW_ERROR("failed to send SEED_NUMBER command\n");
2038 return -1;
2039 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002040
James Ketrenos43f66a62005-03-25 12:31:53 -06002041 return 0;
2042}
2043
James Ketrenos43f66a62005-03-25 12:31:53 -06002044static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2045{
2046 struct host_cmd cmd = {
2047 .cmd = IPW_CMD_CARD_DISABLE,
2048 .len = sizeof(u32)
2049 };
2050
2051 if (!priv) {
2052 IPW_ERROR("Invalid args\n");
2053 return -1;
2054 }
2055
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002056 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06002057
2058 if (ipw_send_cmd(priv, &cmd)) {
2059 IPW_ERROR("failed to send CARD_DISABLE command\n");
2060 return -1;
2061 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002062
James Ketrenos43f66a62005-03-25 12:31:53 -06002063 return 0;
2064}
James Ketrenos43f66a62005-03-25 12:31:53 -06002065
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002066static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002067{
2068 struct host_cmd cmd = {
2069 .cmd = IPW_CMD_TX_POWER,
2070 .len = sizeof(*power)
2071 };
2072
2073 if (!priv || !power) {
2074 IPW_ERROR("Invalid args\n");
2075 return -1;
2076 }
2077
James Ketrenosafbf30a2005-08-25 00:05:33 -05002078 memcpy(cmd.param, power, sizeof(*power));
James Ketrenos43f66a62005-03-25 12:31:53 -06002079 if (ipw_send_cmd(priv, &cmd)) {
2080 IPW_ERROR("failed to send TX_POWER command\n");
2081 return -1;
2082 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002083
James Ketrenos43f66a62005-03-25 12:31:53 -06002084 return 0;
2085}
2086
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002087static int ipw_set_tx_power(struct ipw_priv *priv)
2088{
2089 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2090 struct ipw_tx_power tx_power;
2091 s8 max_power;
2092 int i;
2093
2094 memset(&tx_power, 0, sizeof(tx_power));
2095
2096 /* configure device for 'G' band */
2097 tx_power.ieee_mode = IPW_G_MODE;
2098 tx_power.num_channels = geo->bg_channels;
2099 for (i = 0; i < geo->bg_channels; i++) {
2100 max_power = geo->bg[i].max_power;
2101 tx_power.channels_tx_power[i].channel_number =
2102 geo->bg[i].channel;
2103 tx_power.channels_tx_power[i].tx_power = max_power ?
2104 min(max_power, priv->tx_power) : priv->tx_power;
2105 }
2106 if (ipw_send_tx_power(priv, &tx_power))
2107 return -EIO;
2108
2109 /* configure device to also handle 'B' band */
2110 tx_power.ieee_mode = IPW_B_MODE;
2111 if (ipw_send_tx_power(priv, &tx_power))
2112 return -EIO;
2113
2114 /* configure device to also handle 'A' band */
2115 if (priv->ieee->abg_true) {
2116 tx_power.ieee_mode = IPW_A_MODE;
2117 tx_power.num_channels = geo->a_channels;
2118 for (i = 0; i < tx_power.num_channels; i++) {
2119 max_power = geo->a[i].max_power;
2120 tx_power.channels_tx_power[i].channel_number =
2121 geo->a[i].channel;
2122 tx_power.channels_tx_power[i].tx_power = max_power ?
2123 min(max_power, priv->tx_power) : priv->tx_power;
2124 }
2125 if (ipw_send_tx_power(priv, &tx_power))
2126 return -EIO;
2127 }
2128 return 0;
2129}
2130
James Ketrenos43f66a62005-03-25 12:31:53 -06002131static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2132{
2133 struct ipw_rts_threshold rts_threshold = {
2134 .rts_threshold = rts,
2135 };
2136 struct host_cmd cmd = {
2137 .cmd = IPW_CMD_RTS_THRESHOLD,
2138 .len = sizeof(rts_threshold)
2139 };
2140
2141 if (!priv) {
2142 IPW_ERROR("Invalid args\n");
2143 return -1;
2144 }
2145
James Ketrenosafbf30a2005-08-25 00:05:33 -05002146 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002147 if (ipw_send_cmd(priv, &cmd)) {
2148 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
2149 return -1;
2150 }
2151
2152 return 0;
2153}
2154
2155static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2156{
2157 struct ipw_frag_threshold frag_threshold = {
2158 .frag_threshold = frag,
2159 };
2160 struct host_cmd cmd = {
2161 .cmd = IPW_CMD_FRAG_THRESHOLD,
2162 .len = sizeof(frag_threshold)
2163 };
2164
2165 if (!priv) {
2166 IPW_ERROR("Invalid args\n");
2167 return -1;
2168 }
2169
James Ketrenosafbf30a2005-08-25 00:05:33 -05002170 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002171 if (ipw_send_cmd(priv, &cmd)) {
2172 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
2173 return -1;
2174 }
2175
2176 return 0;
2177}
2178
2179static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2180{
2181 struct host_cmd cmd = {
2182 .cmd = IPW_CMD_POWER_MODE,
2183 .len = sizeof(u32)
2184 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002185 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002186
2187 if (!priv) {
2188 IPW_ERROR("Invalid args\n");
2189 return -1;
2190 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002191
James Ketrenos43f66a62005-03-25 12:31:53 -06002192 /* If on battery, set to 3, if AC set to CAM, else user
2193 * level */
2194 switch (mode) {
2195 case IPW_POWER_BATTERY:
2196 *param = IPW_POWER_INDEX_3;
2197 break;
2198 case IPW_POWER_AC:
2199 *param = IPW_POWER_MODE_CAM;
2200 break;
2201 default:
2202 *param = mode;
2203 break;
2204 }
2205
2206 if (ipw_send_cmd(priv, &cmd)) {
2207 IPW_ERROR("failed to send POWER_MODE command\n");
2208 return -1;
2209 }
2210
2211 return 0;
2212}
2213
James Ketrenosafbf30a2005-08-25 00:05:33 -05002214static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2215{
2216 struct ipw_retry_limit retry_limit = {
2217 .short_retry_limit = slimit,
2218 .long_retry_limit = llimit
2219 };
2220 struct host_cmd cmd = {
2221 .cmd = IPW_CMD_RETRY_LIMIT,
2222 .len = sizeof(retry_limit)
2223 };
2224
2225 if (!priv) {
2226 IPW_ERROR("Invalid args\n");
2227 return -1;
2228 }
2229
2230 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
2231 if (ipw_send_cmd(priv, &cmd)) {
2232 IPW_ERROR("failed to send RETRY_LIMIT command\n");
2233 return -1;
2234 }
2235
2236 return 0;
2237}
2238
James Ketrenos43f66a62005-03-25 12:31:53 -06002239/*
2240 * The IPW device contains a Microwire compatible EEPROM that stores
2241 * various data like the MAC address. Usually the firmware has exclusive
2242 * access to the eeprom, but during device initialization (before the
2243 * device driver has sent the HostComplete command to the firmware) the
2244 * device driver has read access to the EEPROM by way of indirect addressing
2245 * through a couple of memory mapped registers.
2246 *
2247 * The following is a simplified implementation for pulling data out of the
2248 * the eeprom, along with some helper functions to find information in
2249 * the per device private data's copy of the eeprom.
2250 *
2251 * NOTE: To better understand how these functions work (i.e what is a chip
2252 * select and why do have to keep driving the eeprom clock?), read
2253 * just about any data sheet for a Microwire compatible EEPROM.
2254 */
2255
2256/* write a 32 bit value into the indirect accessor register */
2257static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2258{
2259 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002260
James Ketrenos43f66a62005-03-25 12:31:53 -06002261 /* the eeprom requires some time to complete the operation */
2262 udelay(p->eeprom_delay);
2263
2264 return;
2265}
2266
2267/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002268static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002269{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002270 eeprom_write_reg(priv, 0);
2271 eeprom_write_reg(priv, EEPROM_BIT_CS);
2272 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2273 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002274}
2275
2276/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002277static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002278{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002279 eeprom_write_reg(priv, EEPROM_BIT_CS);
2280 eeprom_write_reg(priv, 0);
2281 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002282}
2283
2284/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002285static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002286{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002287 int d = (bit ? EEPROM_BIT_DI : 0);
2288 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2289 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002290}
2291
2292/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002293static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002294{
2295 int i;
2296
2297 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002298 eeprom_write_bit(priv, 1);
2299 eeprom_write_bit(priv, op & 2);
2300 eeprom_write_bit(priv, op & 1);
2301 for (i = 7; i >= 0; i--) {
2302 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002303 }
2304}
2305
2306/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002307static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002308{
2309 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002310 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002311
James Ketrenos43f66a62005-03-25 12:31:53 -06002312 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002313 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002314
2315 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002316 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002317
2318 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002319 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002320 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002321 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2322 eeprom_write_reg(priv, EEPROM_BIT_CS);
2323 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2324 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002325 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002326
James Ketrenos43f66a62005-03-25 12:31:53 -06002327 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002328 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002329 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002330
James Ketrenos43f66a62005-03-25 12:31:53 -06002331 return r;
2332}
2333
2334/* helper function for pulling the mac address out of the private */
2335/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002336static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002337{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002338 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002339}
2340
2341/*
2342 * Either the device driver (i.e. the host) or the firmware can
2343 * load eeprom data into the designated region in SRAM. If neither
2344 * happens then the FW will shutdown with a fatal error.
2345 *
2346 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2347 * bit needs region of shared SRAM needs to be non-zero.
2348 */
2349static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2350{
2351 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002352 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002353
James Ketrenos43f66a62005-03-25 12:31:53 -06002354 IPW_DEBUG_TRACE(">>\n");
2355
2356 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002357 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002358 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002359
Jeff Garzikbf794512005-07-31 13:07:26 -04002360 /*
2361 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 copy. Otherwise let the firmware know to perform the operation
2363 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002364 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002365 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2366 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2367
2368 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002369 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002370 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002371
2372 /* Do not load eeprom data on fatal error or suspend */
2373 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2374 } else {
2375 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2376
2377 /* Load eeprom data on fatal error or suspend */
2378 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2379 }
2380
2381 IPW_DEBUG_TRACE("<<\n");
2382}
2383
James Ketrenos43f66a62005-03-25 12:31:53 -06002384static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2385{
2386 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002387 if (!count)
2388 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002389 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002390 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002391 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002392}
2393
2394static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2395{
James Ketrenosb095c382005-08-24 22:04:42 -05002396 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002397 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002398 sizeof(struct command_block));
2399}
2400
2401static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002402{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002403
2404 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002405
James Ketrenos43f66a62005-03-25 12:31:53 -06002406 /* Start the dma */
2407 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002408
James Ketrenos43f66a62005-03-25 12:31:53 -06002409 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002410 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002411
2412 IPW_DEBUG_FW("<< : \n");
2413 return 0;
2414}
2415
2416static void ipw_fw_dma_abort(struct ipw_priv *priv)
2417{
2418 u32 control = 0;
2419
2420 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002421
2422 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002424 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002425 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002426
James Ketrenos43f66a62005-03-25 12:31:53 -06002427 IPW_DEBUG_FW("<< \n");
2428}
2429
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002430static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2431 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002432{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002433 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002434 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002435 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002436 IPW_DEBUG_FW(">> :\n");
2437
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002438 ipw_write_indirect(priv, address, (u8 *) cb,
2439 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002440
2441 IPW_DEBUG_FW("<< :\n");
2442 return 0;
2443
2444}
2445
2446static int ipw_fw_dma_kick(struct ipw_priv *priv)
2447{
2448 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002449 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002450
2451 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002452
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002454 ipw_fw_dma_write_command_block(priv, index,
2455 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002456
2457 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002458 ipw_clear_bit(priv, IPW_RESET_REG,
2459 IPW_RESET_REG_MASTER_DISABLED |
2460 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002461
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002462 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002463 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002464 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002465
2466 IPW_DEBUG_FW("<< :\n");
2467 return 0;
2468}
2469
2470static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2471{
2472 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002473 u32 register_value = 0;
2474 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002475
2476 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002477 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002478 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002479
2480 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002481 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2482 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002483
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002484 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002485 cb_fields_address = address;
2486 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002487 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002488
2489 cb_fields_address += sizeof(u32);
2490 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002491 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002492
2493 cb_fields_address += sizeof(u32);
2494 register_value = ipw_read_reg32(priv, cb_fields_address);
2495 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2496 register_value);
2497
2498 cb_fields_address += sizeof(u32);
2499 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002500 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002501
2502 IPW_DEBUG_FW(">> :\n");
2503}
2504
2505static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2506{
2507 u32 current_cb_address = 0;
2508 u32 current_cb_index = 0;
2509
2510 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002511 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002512
James Ketrenosb095c382005-08-24 22:04:42 -05002513 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002514 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002515
James Ketrenos43f66a62005-03-25 12:31:53 -06002516 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002517 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002518
2519 IPW_DEBUG_FW(">> :\n");
2520 return current_cb_index;
2521
2522}
2523
2524static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2525 u32 src_address,
2526 u32 dest_address,
2527 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002528 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002529{
2530
Jeff Garzikbf794512005-07-31 13:07:26 -04002531 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002532 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2533 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002534 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002535 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002536
2537 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2538 src_address, dest_address, length);
2539
2540 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2541 return -1;
2542
2543 last_cb_element = priv->sram_desc.last_cb_index;
2544 cb = &priv->sram_desc.cb_list[last_cb_element];
2545 priv->sram_desc.last_cb_index++;
2546
2547 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002548 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002549 control |= CB_INT_ENABLED;
2550
2551 if (is_last)
2552 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002553
James Ketrenos43f66a62005-03-25 12:31:53 -06002554 control |= length;
2555
2556 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002557 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002558
2559 /* Copy the Source and Destination addresses */
2560 cb->dest_addr = dest_address;
2561 cb->source_addr = src_address;
2562
2563 /* Copy the Control Word last */
2564 cb->control = control;
2565
2566 return 0;
2567}
2568
2569static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002570 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002571{
2572 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002573 u32 src_offset = 0;
2574 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002575 int status = 0;
2576 IPW_DEBUG_FW(">> \n");
2577 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2578 src_phys, dest_address, length);
2579 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002580 status = ipw_fw_dma_add_command_block(priv,
2581 src_phys + src_offset,
2582 dest_address +
2583 dest_offset,
2584 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002585 if (status) {
2586 IPW_DEBUG_FW_INFO(": Failed\n");
2587 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002588 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002589 IPW_DEBUG_FW_INFO(": Added new cb\n");
2590
2591 src_offset += CB_MAX_LENGTH;
2592 dest_offset += CB_MAX_LENGTH;
2593 bytes_left -= CB_MAX_LENGTH;
2594 }
2595
2596 /* add the buffer tail */
2597 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002598 status =
2599 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2600 dest_address + dest_offset,
2601 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002602 if (status) {
2603 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2604 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002605 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002606 IPW_DEBUG_FW_INFO
2607 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002608 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002609
James Ketrenos43f66a62005-03-25 12:31:53 -06002610 IPW_DEBUG_FW("<< \n");
2611 return 0;
2612}
2613
2614static int ipw_fw_dma_wait(struct ipw_priv *priv)
2615{
2616 u32 current_index = 0;
2617 u32 watchdog = 0;
2618
2619 IPW_DEBUG_FW(">> : \n");
2620
2621 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002622 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002623 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002624
2625 while (current_index < priv->sram_desc.last_cb_index) {
2626 udelay(50);
2627 current_index = ipw_fw_dma_command_block_index(priv);
2628
2629 watchdog++;
2630
2631 if (watchdog > 400) {
2632 IPW_DEBUG_FW_INFO("Timeout\n");
2633 ipw_fw_dma_dump_command_block(priv);
2634 ipw_fw_dma_abort(priv);
2635 return -1;
2636 }
2637 }
2638
2639 ipw_fw_dma_abort(priv);
2640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002641 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002642 ipw_set_bit(priv, IPW_RESET_REG,
2643 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002644
2645 IPW_DEBUG_FW("<< dmaWaitSync \n");
2646 return 0;
2647}
2648
Jeff Garzikbf794512005-07-31 13:07:26 -04002649static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002650{
2651 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002652 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002653 unsigned long flags;
2654
2655 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002656 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2657 network = list_entry(element, struct ieee80211_network, list);
2658 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2659 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002660 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002661 &priv->ieee->network_free_list);
2662 }
2663 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002664 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002665}
2666
2667/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002668 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002669 * Reads debug register from domain0.
2670 * If card is present, pre-defined value should
2671 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002672 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 * @param priv
2674 * @return 1 if card is present, 0 otherwise
2675 */
2676static inline int ipw_alive(struct ipw_priv *priv)
2677{
2678 return ipw_read32(priv, 0x90) == 0xd55555d5;
2679}
2680
2681static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2682 int timeout)
2683{
2684 int i = 0;
2685
2686 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002687 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002688 return i;
2689 mdelay(10);
2690 i += 10;
2691 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002692
James Ketrenos43f66a62005-03-25 12:31:53 -06002693 return -ETIME;
2694}
2695
Jeff Garzikbf794512005-07-31 13:07:26 -04002696/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002697 * the ipw hardware. It assumes the buffer has all the bits for the
2698 * image and the caller is handling the memory allocation and clean up.
2699 */
2700
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002701static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002702{
2703 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002704
James Ketrenos43f66a62005-03-25 12:31:53 -06002705 IPW_DEBUG_TRACE(">> \n");
2706 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002707 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002708
James Ketrenosb095c382005-08-24 22:04:42 -05002709 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2710 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002711 if (rc < 0) {
2712 IPW_ERROR("stop master failed in 10ms\n");
2713 return -1;
2714 }
2715
2716 IPW_DEBUG_INFO("stop master %dms\n", rc);
2717
2718 return rc;
2719}
2720
2721static void ipw_arc_release(struct ipw_priv *priv)
2722{
2723 IPW_DEBUG_TRACE(">> \n");
2724 mdelay(5);
2725
James Ketrenosb095c382005-08-24 22:04:42 -05002726 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002727
2728 /* no one knows timing, for safety add some delay */
2729 mdelay(5);
2730}
2731
2732struct fw_header {
2733 u32 version;
2734 u32 mode;
2735};
2736
2737struct fw_chunk {
2738 u32 address;
2739 u32 length;
2740};
2741
2742#define IPW_FW_MAJOR_VERSION 2
James Ketrenosb095c382005-08-24 22:04:42 -05002743#define IPW_FW_MINOR_VERSION 3
James Ketrenos43f66a62005-03-25 12:31:53 -06002744
2745#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2746#define IPW_FW_MAJOR(x) (x & 0xff)
2747
James Ketrenosafbf30a2005-08-25 00:05:33 -05002748#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
2750#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2751"." __stringify(IPW_FW_MINOR_VERSION) "-"
2752
2753#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2754#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2755#else
2756#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2757#endif
2758
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002759static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002760{
2761 int rc = 0, i, addr;
2762 u8 cr = 0;
2763 u16 *image;
2764
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002765 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002766
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 IPW_DEBUG_TRACE(">> \n");
2768
2769 rc = ipw_stop_master(priv);
2770
2771 if (rc < 0)
2772 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002773
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002774// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002775
James Ketrenosb095c382005-08-24 22:04:42 -05002776 for (addr = IPW_SHARED_LOWER_BOUND;
2777 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002778 ipw_write32(priv, addr, 0);
2779 }
2780
2781 /* no ucode (yet) */
2782 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2783 /* destroy DMA queues */
2784 /* reset sequence */
2785
James Ketrenosb095c382005-08-24 22:04:42 -05002786 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002788 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002789 mdelay(1);
2790
2791 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002792 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002793 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002794
James Ketrenosb095c382005-08-24 22:04:42 -05002795 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002796 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002797
James Ketrenos43f66a62005-03-25 12:31:53 -06002798 /* enable ucode store */
2799 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2800 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2801 mdelay(1);
2802
2803 /* write ucode */
2804 /**
2805 * @bug
2806 * Do NOT set indirect address register once and then
2807 * store data to indirect data register in the loop.
2808 * It seems very reasonable, but in this case DINO do not
2809 * accept ucode. It is essential to set address each time.
2810 */
2811 /* load new ipw uCode */
2812 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002813 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002814 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002815
James Ketrenos43f66a62005-03-25 12:31:53 -06002816 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002817 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2818 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002819
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002820 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002821
2822 /* wait for alive response */
2823 for (i = 0; i < 100; i++) {
2824 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002825 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002826 if (cr & DINO_RXFIFO_DATA)
2827 break;
2828 mdelay(1);
2829 }
2830
2831 if (cr & DINO_RXFIFO_DATA) {
2832 /* alive_command_responce size is NOT multiple of 4 */
2833 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002834
2835 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002836 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002837 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002838 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002839 memcpy(&priv->dino_alive, response_buffer,
2840 sizeof(priv->dino_alive));
2841 if (priv->dino_alive.alive_command == 1
2842 && priv->dino_alive.ucode_valid == 1) {
2843 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002844 IPW_DEBUG_INFO
2845 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2846 "of %02d/%02d/%02d %02d:%02d\n",
2847 priv->dino_alive.software_revision,
2848 priv->dino_alive.software_revision,
2849 priv->dino_alive.device_identifier,
2850 priv->dino_alive.device_identifier,
2851 priv->dino_alive.time_stamp[0],
2852 priv->dino_alive.time_stamp[1],
2853 priv->dino_alive.time_stamp[2],
2854 priv->dino_alive.time_stamp[3],
2855 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 } else {
2857 IPW_DEBUG_INFO("Microcode is not alive\n");
2858 rc = -EINVAL;
2859 }
2860 } else {
2861 IPW_DEBUG_INFO("No alive response from DINO\n");
2862 rc = -ETIME;
2863 }
2864
2865 /* disable DINO, otherwise for some reason
2866 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002867 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002868
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002869// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002870
2871 return rc;
2872}
2873
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002874static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002875{
2876 int rc = -1;
2877 int offset = 0;
2878 struct fw_chunk *chunk;
2879 dma_addr_t shared_phys;
2880 u8 *shared_virt;
2881
2882 IPW_DEBUG_TRACE("<< : \n");
2883 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2884
2885 if (!shared_virt)
2886 return -ENOMEM;
2887
2888 memmove(shared_virt, data, len);
2889
2890 /* Start the Dma */
2891 rc = ipw_fw_dma_enable(priv);
2892
2893 if (priv->sram_desc.last_cb_index > 0) {
2894 /* the DMA is already ready this would be a bug. */
2895 BUG();
2896 goto out;
2897 }
2898
2899 do {
2900 chunk = (struct fw_chunk *)(data + offset);
2901 offset += sizeof(struct fw_chunk);
2902 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002903 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002904 * offeset*/
2905 /* Dma loading */
2906 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05002907 le32_to_cpu(chunk->address),
2908 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06002909 if (rc) {
2910 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2911 goto out;
2912 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002913
James Ketrenosa613bff2005-08-24 21:43:11 -05002914 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06002915 } while (offset < len);
2916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002917 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002918 rc = ipw_fw_dma_kick(priv);
2919 if (rc) {
2920 IPW_ERROR("dmaKick Failed\n");
2921 goto out;
2922 }
2923
2924 rc = ipw_fw_dma_wait(priv);
2925 if (rc) {
2926 IPW_ERROR("dmaWaitSync Failed\n");
2927 goto out;
2928 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002929 out:
2930 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002931 return rc;
2932}
2933
2934/* stop nic */
2935static int ipw_stop_nic(struct ipw_priv *priv)
2936{
2937 int rc = 0;
2938
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002939 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05002940 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002941
James Ketrenosb095c382005-08-24 22:04:42 -05002942 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2943 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002944 if (rc < 0) {
2945 IPW_ERROR("wait for reg master disabled failed\n");
2946 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002947 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002948
James Ketrenosb095c382005-08-24 22:04:42 -05002949 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002950
James Ketrenos43f66a62005-03-25 12:31:53 -06002951 return rc;
2952}
2953
2954static void ipw_start_nic(struct ipw_priv *priv)
2955{
2956 IPW_DEBUG_TRACE(">>\n");
2957
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002958 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05002959 ipw_clear_bit(priv, IPW_RESET_REG,
2960 IPW_RESET_REG_MASTER_DISABLED |
2961 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002962 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002963
James Ketrenos43f66a62005-03-25 12:31:53 -06002964 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05002965 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
2966 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002967
2968 IPW_DEBUG_TRACE("<<\n");
2969}
Jeff Garzikbf794512005-07-31 13:07:26 -04002970
James Ketrenos43f66a62005-03-25 12:31:53 -06002971static int ipw_init_nic(struct ipw_priv *priv)
2972{
2973 int rc;
2974
2975 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002976 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002977 /*prvHwInitNic */
2978 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05002979 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002980
2981 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05002982 ipw_write32(priv, IPW_READ_INT_REGISTER,
2983 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002984
2985 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05002986 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
2987 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002988 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06002989 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2990
2991 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05002992 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002993
2994 udelay(10);
2995
2996 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05002997 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002998
2999 IPW_DEBUG_TRACE(">>\n");
3000 return 0;
3001}
3002
Jeff Garzikbf794512005-07-31 13:07:26 -04003003/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003004 * Probe is an ok place to call this from.
3005 */
3006static int ipw_reset_nic(struct ipw_priv *priv)
3007{
3008 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003009 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003010
3011 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003012
James Ketrenos43f66a62005-03-25 12:31:53 -06003013 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003014
James Ketrenosa613bff2005-08-24 21:43:11 -05003015 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003016 /* Clear the 'host command active' bit... */
3017 priv->status &= ~STATUS_HCMD_ACTIVE;
3018 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003019 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3020 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003021 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003022
3023 IPW_DEBUG_TRACE("<<\n");
3024 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003025}
James Ketrenos43f66a62005-03-25 12:31:53 -06003026
Jeff Garzikbf794512005-07-31 13:07:26 -04003027static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003028 const struct firmware **fw, const char *name)
3029{
3030 struct fw_header *header;
3031 int rc;
3032
3033 /* ask firmware_class module to get the boot firmware off disk */
3034 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3035 if (rc < 0) {
3036 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3037 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003038 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003039
3040 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003041 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003042 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3043 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003044 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3045 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003046 return -EINVAL;
3047 }
3048
Jiri Bencaaa4d302005-06-07 14:58:41 +02003049 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003050 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003051 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3052 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003053 (*fw)->size - sizeof(struct fw_header));
3054 return 0;
3055}
3056
James Ketrenosb095c382005-08-24 22:04:42 -05003057#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003058
3059static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
3060 struct ipw_rx_queue *rxq)
3061{
3062 unsigned long flags;
3063 int i;
3064
3065 spin_lock_irqsave(&rxq->lock, flags);
3066
3067 INIT_LIST_HEAD(&rxq->rx_free);
3068 INIT_LIST_HEAD(&rxq->rx_used);
3069
3070 /* Fill the rx_used queue with _all_ of the Rx buffers */
3071 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3072 /* In the reset function, these buffers may have been allocated
3073 * to an SKB, so we need to unmap and free potential storage */
3074 if (rxq->pool[i].skb != NULL) {
3075 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003076 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003077 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003078 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003079 }
3080 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3081 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003082
James Ketrenos43f66a62005-03-25 12:31:53 -06003083 /* Set us so that we have processed and used all buffers, but have
3084 * not restocked the Rx queue with fresh buffers */
3085 rxq->read = rxq->write = 0;
3086 rxq->processed = RX_QUEUE_SIZE - 1;
3087 rxq->free_count = 0;
3088 spin_unlock_irqrestore(&rxq->lock, flags);
3089}
3090
3091#ifdef CONFIG_PM
3092static int fw_loaded = 0;
3093static const struct firmware *bootfw = NULL;
3094static const struct firmware *firmware = NULL;
3095static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003096
3097static void free_firmware(void)
3098{
3099 if (fw_loaded) {
3100 release_firmware(bootfw);
3101 release_firmware(ucode);
3102 release_firmware(firmware);
3103 bootfw = ucode = firmware = NULL;
3104 fw_loaded = 0;
3105 }
3106}
3107#else
3108#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003109#endif
3110
3111static int ipw_load(struct ipw_priv *priv)
3112{
3113#ifndef CONFIG_PM
3114 const struct firmware *bootfw = NULL;
3115 const struct firmware *firmware = NULL;
3116 const struct firmware *ucode = NULL;
3117#endif
3118 int rc = 0, retries = 3;
3119
3120#ifdef CONFIG_PM
3121 if (!fw_loaded) {
3122#endif
3123 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003124 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003125 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003126
James Ketrenos43f66a62005-03-25 12:31:53 -06003127 switch (priv->ieee->iw_mode) {
3128 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003129 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003130 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003131 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003132 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003133
James Ketrenos43f66a62005-03-25 12:31:53 -06003134 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3135 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003136
James Ketrenosb095c382005-08-24 22:04:42 -05003137#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003138 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003139 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003140 IPW_FW_NAME("sniffer_ucode"));
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
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003144 rc = ipw_get_fw(priv, &firmware,
3145 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003146 break;
3147#endif
3148 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003149 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003150 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003151 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003152
James Ketrenos43f66a62005-03-25 12:31:53 -06003153 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3154 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003155
James Ketrenos43f66a62005-03-25 12:31:53 -06003156 default:
3157 rc = -EINVAL;
3158 }
3159
Jeff Garzikbf794512005-07-31 13:07:26 -04003160 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003161 goto error;
3162
3163#ifdef CONFIG_PM
3164 fw_loaded = 1;
3165 }
3166#endif
3167
3168 if (!priv->rxq)
3169 priv->rxq = ipw_rx_queue_alloc(priv);
3170 else
3171 ipw_rx_queue_reset(priv, priv->rxq);
3172 if (!priv->rxq) {
3173 IPW_ERROR("Unable to initialize Rx queue\n");
3174 goto error;
3175 }
3176
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003177 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003178 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003179 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003180 priv->status &= ~STATUS_INT_ENABLED;
3181
3182 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003183 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003184
James Ketrenos43f66a62005-03-25 12:31:53 -06003185 ipw_stop_nic(priv);
3186
3187 rc = ipw_reset_nic(priv);
3188 if (rc) {
3189 IPW_ERROR("Unable to reset NIC\n");
3190 goto error;
3191 }
3192
James Ketrenosb095c382005-08-24 22:04:42 -05003193 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3194 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003195
3196 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003197 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003198 bootfw->size - sizeof(struct fw_header));
3199 if (rc < 0) {
3200 IPW_ERROR("Unable to load boot firmware\n");
3201 goto error;
3202 }
3203
3204 /* kick start the device */
3205 ipw_start_nic(priv);
3206
3207 /* wait for the device to finish it's initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003208 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3209 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003210 if (rc < 0) {
3211 IPW_ERROR("device failed to boot initial fw image\n");
3212 goto error;
3213 }
3214 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3215
Jeff Garzikbf794512005-07-31 13:07:26 -04003216 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003217 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003218
3219 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003220 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003221 ucode->size - sizeof(struct fw_header));
3222 if (rc < 0) {
3223 IPW_ERROR("Unable to load ucode\n");
3224 goto error;
3225 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003226
James Ketrenos43f66a62005-03-25 12:31:53 -06003227 /* stop nic */
3228 ipw_stop_nic(priv);
3229
3230 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003231 rc = ipw_load_firmware(priv, firmware->data +
3232 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003233 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003234 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003235 IPW_ERROR("Unable to load firmware\n");
3236 goto error;
3237 }
3238
3239 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3240
3241 rc = ipw_queue_reset(priv);
3242 if (rc) {
3243 IPW_ERROR("Unable to initialize queues\n");
3244 goto error;
3245 }
3246
3247 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003248 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003249 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003250 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003251
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 /* kick start the device */
3253 ipw_start_nic(priv);
3254
James Ketrenosb095c382005-08-24 22:04:42 -05003255 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003256 if (retries > 0) {
3257 IPW_WARNING("Parity error. Retrying init.\n");
3258 retries--;
3259 goto retry;
3260 }
3261
3262 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3263 rc = -EIO;
3264 goto error;
3265 }
3266
3267 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003268 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3269 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003270 if (rc < 0) {
3271 IPW_ERROR("device failed to start after 500ms\n");
3272 goto error;
3273 }
3274 IPW_DEBUG_INFO("device response after %dms\n", rc);
3275
3276 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003277 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003278
3279 /* read eeprom data and initialize the eeprom region of sram */
3280 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003281 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003282
3283 /* enable interrupts */
3284 ipw_enable_interrupts(priv);
3285
3286 /* Ensure our queue has valid packets */
3287 ipw_rx_queue_replenish(priv);
3288
James Ketrenosb095c382005-08-24 22:04:42 -05003289 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003290
3291 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003292 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003293
3294#ifndef CONFIG_PM
3295 release_firmware(bootfw);
3296 release_firmware(ucode);
3297 release_firmware(firmware);
3298#endif
3299 return 0;
3300
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003301 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003302 if (priv->rxq) {
3303 ipw_rx_queue_free(priv, priv->rxq);
3304 priv->rxq = NULL;
3305 }
3306 ipw_tx_queue_free(priv);
3307 if (bootfw)
3308 release_firmware(bootfw);
3309 if (ucode)
3310 release_firmware(ucode);
3311 if (firmware)
3312 release_firmware(firmware);
3313#ifdef CONFIG_PM
3314 fw_loaded = 0;
3315 bootfw = ucode = firmware = NULL;
3316#endif
3317
3318 return rc;
3319}
3320
Jeff Garzikbf794512005-07-31 13:07:26 -04003321/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003322 * DMA services
3323 *
3324 * Theory of operation
3325 *
3326 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3327 * 2 empty entries always kept in the buffer to protect from overflow.
3328 *
3329 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003330 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3331 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 * Tx queue resumed.
3333 *
3334 * The IPW operates with six queues, one receive queue in the device's
3335 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003336 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003337 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003338 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003339 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003340 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003341 * we only utilize the first data transmit queue (queue1).
3342 */
3343
3344/**
3345 * Driver allocates buffers of this size for Rx
3346 */
3347
3348static inline int ipw_queue_space(const struct clx2_queue *q)
3349{
3350 int s = q->last_used - q->first_empty;
3351 if (s <= 0)
3352 s += q->n_bd;
3353 s -= 2; /* keep some reserve to not confuse empty and full situations */
3354 if (s < 0)
3355 s = 0;
3356 return s;
3357}
3358
3359static inline int ipw_queue_inc_wrap(int index, int n_bd)
3360{
3361 return (++index == n_bd) ? 0 : index;
3362}
3363
3364/**
3365 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003366 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003367 * @param q queue to init
3368 * @param count Number of BD's to allocate. Should be power of 2
3369 * @param read_register Address for 'read' register
3370 * (not offset within BAR, full address)
3371 * @param write_register Address for 'write' register
3372 * (not offset within BAR, full address)
3373 * @param base_register Address for 'base' register
3374 * (not offset within BAR, full address)
3375 * @param size Address for 'size' register
3376 * (not offset within BAR, full address)
3377 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003378static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003379 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003380{
3381 q->n_bd = count;
3382
3383 q->low_mark = q->n_bd / 4;
3384 if (q->low_mark < 4)
3385 q->low_mark = 4;
3386
3387 q->high_mark = q->n_bd / 8;
3388 if (q->high_mark < 2)
3389 q->high_mark = 2;
3390
3391 q->first_empty = q->last_used = 0;
3392 q->reg_r = read;
3393 q->reg_w = write;
3394
3395 ipw_write32(priv, base, q->dma_addr);
3396 ipw_write32(priv, size, count);
3397 ipw_write32(priv, read, 0);
3398 ipw_write32(priv, write, 0);
3399
3400 _ipw_read32(priv, 0x90);
3401}
3402
Jeff Garzikbf794512005-07-31 13:07:26 -04003403static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003404 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003405 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003406{
3407 struct pci_dev *dev = priv->pci_dev;
3408
3409 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3410 if (!q->txb) {
3411 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3412 return -ENOMEM;
3413 }
3414
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003415 q->bd =
3416 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003417 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003418 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003419 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003420 kfree(q->txb);
3421 q->txb = NULL;
3422 return -ENOMEM;
3423 }
3424
3425 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3426 return 0;
3427}
3428
3429/**
3430 * Free one TFD, those at index [txq->q.last_used].
3431 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003432 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003433 * @param dev
3434 * @param txq
3435 */
3436static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3437 struct clx2_tx_queue *txq)
3438{
3439 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3440 struct pci_dev *dev = priv->pci_dev;
3441 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003442
James Ketrenos43f66a62005-03-25 12:31:53 -06003443 /* classify bd */
3444 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3445 /* nothing to cleanup after for host commands */
3446 return;
3447
3448 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003449 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3450 IPW_ERROR("Too many chunks: %i\n",
3451 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003452 /** @todo issue fatal error, it is quite serious situation */
3453 return;
3454 }
3455
3456 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003457 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3458 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3459 le16_to_cpu(bd->u.data.chunk_len[i]),
3460 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003461 if (txq->txb[txq->q.last_used]) {
3462 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3463 txq->txb[txq->q.last_used] = NULL;
3464 }
3465 }
3466}
3467
3468/**
3469 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003470 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003471 * Empty queue by removing and destroying all BD's.
3472 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003473 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003474 * @param dev
3475 * @param q
3476 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003477static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003478{
3479 struct clx2_queue *q = &txq->q;
3480 struct pci_dev *dev = priv->pci_dev;
3481
Jeff Garzikbf794512005-07-31 13:07:26 -04003482 if (q->n_bd == 0)
3483 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003484
3485 /* first, empty all BD's */
3486 for (; q->first_empty != q->last_used;
3487 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3488 ipw_queue_tx_free_tfd(priv, txq);
3489 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003490
James Ketrenos43f66a62005-03-25 12:31:53 -06003491 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003492 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003493 q->dma_addr);
3494 kfree(txq->txb);
3495
3496 /* 0 fill whole structure */
3497 memset(txq, 0, sizeof(*txq));
3498}
3499
James Ketrenos43f66a62005-03-25 12:31:53 -06003500/**
3501 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003502 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003503 * @param priv
3504 */
3505static void ipw_tx_queue_free(struct ipw_priv *priv)
3506{
3507 /* Tx CMD queue */
3508 ipw_queue_tx_free(priv, &priv->txq_cmd);
3509
3510 /* Tx queues */
3511 ipw_queue_tx_free(priv, &priv->txq[0]);
3512 ipw_queue_tx_free(priv, &priv->txq[1]);
3513 ipw_queue_tx_free(priv, &priv->txq[2]);
3514 ipw_queue_tx_free(priv, &priv->txq[3]);
3515}
3516
3517static void inline __maybe_wake_tx(struct ipw_priv *priv)
3518{
3519 if (netif_running(priv->net_dev)) {
3520 switch (priv->port_type) {
3521 case DCR_TYPE_MU_BSS:
3522 case DCR_TYPE_MU_IBSS:
James Ketrenosa613bff2005-08-24 21:43:11 -05003523 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003524 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003525 }
3526 netif_wake_queue(priv->net_dev);
3527 }
3528
3529}
3530
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003531static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003532{
3533 /* First 3 bytes are manufacturer */
3534 bssid[0] = priv->mac_addr[0];
3535 bssid[1] = priv->mac_addr[1];
3536 bssid[2] = priv->mac_addr[2];
3537
3538 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003539 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003540
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003541 bssid[0] &= 0xfe; /* clear multicast bit */
3542 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003543}
3544
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003545static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003546{
3547 struct ipw_station_entry entry;
3548 int i;
3549
3550 for (i = 0; i < priv->num_stations; i++) {
3551 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3552 /* Another node is active in network */
3553 priv->missed_adhoc_beacons = 0;
3554 if (!(priv->config & CFG_STATIC_CHANNEL))
3555 /* when other nodes drop out, we drop out */
3556 priv->config &= ~CFG_ADHOC_PERSIST;
3557
3558 return i;
3559 }
3560 }
3561
3562 if (i == MAX_STATIONS)
3563 return IPW_INVALID_STATION;
3564
3565 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3566
3567 entry.reserved = 0;
3568 entry.support_mode = 0;
3569 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3570 memcpy(priv->stations[i], bssid, ETH_ALEN);
3571 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003572 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003573 priv->num_stations++;
3574
3575 return i;
3576}
3577
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003578static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003579{
3580 int i;
3581
Jeff Garzikbf794512005-07-31 13:07:26 -04003582 for (i = 0; i < priv->num_stations; i++)
3583 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003584 return i;
3585
3586 return IPW_INVALID_STATION;
3587}
3588
3589static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3590{
3591 int err;
3592
3593 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3594 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3595 return;
3596 }
3597
3598 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3599 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003600 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003601 priv->assoc_request.channel);
3602
3603 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3604 priv->status |= STATUS_DISASSOCIATING;
3605
3606 if (quiet)
3607 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3608 else
3609 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3610 err = ipw_send_associate(priv, &priv->assoc_request);
3611 if (err) {
3612 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3613 "failed.\n");
3614 return;
3615 }
3616
3617}
3618
James Ketrenosc848d0a2005-08-24 21:56:24 -05003619static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003620{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003621 struct ipw_priv *priv = data;
3622 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3623 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003624 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003625 return 1;
3626}
3627
3628static void ipw_bg_disassociate(void *data)
3629{
3630 struct ipw_priv *priv = data;
3631 down(&priv->sem);
3632 ipw_disassociate(data);
3633 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003634}
3635
Zhu Yid8bad6d2005-07-13 12:25:38 -05003636static void ipw_system_config(void *data)
3637{
3638 struct ipw_priv *priv = data;
3639 ipw_send_system_config(priv, &priv->sys_config);
3640}
3641
James Ketrenos43f66a62005-03-25 12:31:53 -06003642struct ipw_status_code {
3643 u16 status;
3644 const char *reason;
3645};
3646
3647static const struct ipw_status_code ipw_status_codes[] = {
3648 {0x00, "Successful"},
3649 {0x01, "Unspecified failure"},
3650 {0x0A, "Cannot support all requested capabilities in the "
3651 "Capability information field"},
3652 {0x0B, "Reassociation denied due to inability to confirm that "
3653 "association exists"},
3654 {0x0C, "Association denied due to reason outside the scope of this "
3655 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003656 {0x0D,
3657 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003658 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003659 {0x0E,
3660 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003661 "transaction sequence number out of expected sequence"},
3662 {0x0F, "Authentication rejected because of challenge failure"},
3663 {0x10, "Authentication rejected due to timeout waiting for next "
3664 "frame in sequence"},
3665 {0x11, "Association denied because AP is unable to handle additional "
3666 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003667 {0x12,
3668 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003669 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003670 {0x13,
3671 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003672 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003673 {0x14,
3674 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003675 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003676 {0x15,
3677 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003678 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003679 {0x19,
3680 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003681 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003682 {0x1A,
3683 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 "DSSS-OFDM operation"},
3685 {0x28, "Invalid Information Element"},
3686 {0x29, "Group Cipher is not valid"},
3687 {0x2A, "Pairwise Cipher is not valid"},
3688 {0x2B, "AKMP is not valid"},
3689 {0x2C, "Unsupported RSN IE version"},
3690 {0x2D, "Invalid RSN IE Capabilities"},
3691 {0x2E, "Cipher suite is rejected per security policy"},
3692};
3693
3694#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003695static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003696{
3697 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003698 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003699 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003700 return ipw_status_codes[i].reason;
3701 return "Unknown status value.";
3702}
3703#endif
3704
3705static void inline average_init(struct average *avg)
3706{
3707 memset(avg, 0, sizeof(*avg));
3708}
3709
3710static void inline average_add(struct average *avg, s16 val)
3711{
3712 avg->sum -= avg->entries[avg->pos];
3713 avg->sum += val;
3714 avg->entries[avg->pos++] = val;
3715 if (unlikely(avg->pos == AVG_ENTRIES)) {
3716 avg->init = 1;
3717 avg->pos = 0;
3718 }
3719}
3720
3721static s16 inline average_value(struct average *avg)
3722{
3723 if (!unlikely(avg->init)) {
3724 if (avg->pos)
3725 return avg->sum / avg->pos;
3726 return 0;
3727 }
3728
3729 return avg->sum / AVG_ENTRIES;
3730}
3731
3732static void ipw_reset_stats(struct ipw_priv *priv)
3733{
3734 u32 len = sizeof(u32);
3735
3736 priv->quality = 0;
3737
3738 average_init(&priv->average_missed_beacons);
3739 average_init(&priv->average_rssi);
3740 average_init(&priv->average_noise);
3741
3742 priv->last_rate = 0;
3743 priv->last_missed_beacons = 0;
3744 priv->last_rx_packets = 0;
3745 priv->last_tx_packets = 0;
3746 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003747
James Ketrenos43f66a62005-03-25 12:31:53 -06003748 /* Firmware managed, reset only when NIC is restarted, so we have to
3749 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003750 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003751 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003752 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003753 &priv->last_tx_failures, &len);
3754
3755 /* Driver managed, reset with each association */
3756 priv->missed_adhoc_beacons = 0;
3757 priv->missed_beacons = 0;
3758 priv->tx_packets = 0;
3759 priv->rx_packets = 0;
3760
3761}
3762
James Ketrenos43f66a62005-03-25 12:31:53 -06003763static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3764{
3765 u32 i = 0x80000000;
3766 u32 mask = priv->rates_mask;
3767 /* If currently associated in B mode, restrict the maximum
3768 * rate match to B rates */
3769 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3770 mask &= IEEE80211_CCK_RATES_MASK;
3771
3772 /* TODO: Verify that the rate is supported by the current rates
3773 * list. */
3774
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003775 while (i && !(mask & i))
3776 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003777 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003778 case IEEE80211_CCK_RATE_1MB_MASK:
3779 return 1000000;
3780 case IEEE80211_CCK_RATE_2MB_MASK:
3781 return 2000000;
3782 case IEEE80211_CCK_RATE_5MB_MASK:
3783 return 5500000;
3784 case IEEE80211_OFDM_RATE_6MB_MASK:
3785 return 6000000;
3786 case IEEE80211_OFDM_RATE_9MB_MASK:
3787 return 9000000;
3788 case IEEE80211_CCK_RATE_11MB_MASK:
3789 return 11000000;
3790 case IEEE80211_OFDM_RATE_12MB_MASK:
3791 return 12000000;
3792 case IEEE80211_OFDM_RATE_18MB_MASK:
3793 return 18000000;
3794 case IEEE80211_OFDM_RATE_24MB_MASK:
3795 return 24000000;
3796 case IEEE80211_OFDM_RATE_36MB_MASK:
3797 return 36000000;
3798 case IEEE80211_OFDM_RATE_48MB_MASK:
3799 return 48000000;
3800 case IEEE80211_OFDM_RATE_54MB_MASK:
3801 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003802 }
3803
Jeff Garzikbf794512005-07-31 13:07:26 -04003804 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003805 return 11000000;
3806 else
3807 return 54000000;
3808}
3809
3810static u32 ipw_get_current_rate(struct ipw_priv *priv)
3811{
3812 u32 rate, len = sizeof(rate);
3813 int err;
3814
Jeff Garzikbf794512005-07-31 13:07:26 -04003815 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003816 return 0;
3817
3818 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003819 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003820 &len);
3821 if (err) {
3822 IPW_DEBUG_INFO("failed querying ordinals.\n");
3823 return 0;
3824 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003825 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003826 return ipw_get_max_rate(priv);
3827
3828 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003829 case IPW_TX_RATE_1MB:
3830 return 1000000;
3831 case IPW_TX_RATE_2MB:
3832 return 2000000;
3833 case IPW_TX_RATE_5MB:
3834 return 5500000;
3835 case IPW_TX_RATE_6MB:
3836 return 6000000;
3837 case IPW_TX_RATE_9MB:
3838 return 9000000;
3839 case IPW_TX_RATE_11MB:
3840 return 11000000;
3841 case IPW_TX_RATE_12MB:
3842 return 12000000;
3843 case IPW_TX_RATE_18MB:
3844 return 18000000;
3845 case IPW_TX_RATE_24MB:
3846 return 24000000;
3847 case IPW_TX_RATE_36MB:
3848 return 36000000;
3849 case IPW_TX_RATE_48MB:
3850 return 48000000;
3851 case IPW_TX_RATE_54MB:
3852 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003853 }
3854
3855 return 0;
3856}
3857
James Ketrenos43f66a62005-03-25 12:31:53 -06003858#define IPW_STATS_INTERVAL (2 * HZ)
3859static void ipw_gather_stats(struct ipw_priv *priv)
3860{
3861 u32 rx_err, rx_err_delta, rx_packets_delta;
3862 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3863 u32 missed_beacons_percent, missed_beacons_delta;
3864 u32 quality = 0;
3865 u32 len = sizeof(u32);
3866 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003867 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003868 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003869 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003870
3871 if (!(priv->status & STATUS_ASSOCIATED)) {
3872 priv->quality = 0;
3873 return;
3874 }
3875
3876 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003877 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003878 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003879 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003880 priv->last_missed_beacons = priv->missed_beacons;
3881 if (priv->assoc_request.beacon_interval) {
3882 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003883 (HZ * priv->assoc_request.beacon_interval) /
3884 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003885 } else {
3886 missed_beacons_percent = 0;
3887 }
3888 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3889
3890 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3891 rx_err_delta = rx_err - priv->last_rx_err;
3892 priv->last_rx_err = rx_err;
3893
3894 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3895 tx_failures_delta = tx_failures - priv->last_tx_failures;
3896 priv->last_tx_failures = tx_failures;
3897
3898 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3899 priv->last_rx_packets = priv->rx_packets;
3900
3901 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3902 priv->last_tx_packets = priv->tx_packets;
3903
3904 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003905 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003906 * Missed beacon: 100% = 0, 0% = 70% missed
3907 * Rate: 60% = 1Mbs, 100% = Max
3908 * Rx and Tx errors represent a straight % of total Rx/Tx
3909 * RSSI: 100% = > -50, 0% = < -80
3910 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003911 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003912 * The lowest computed quality is used.
3913 *
3914 */
3915#define BEACON_THRESHOLD 5
3916 beacon_quality = 100 - missed_beacons_percent;
3917 if (beacon_quality < BEACON_THRESHOLD)
3918 beacon_quality = 0;
3919 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003920 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003921 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003922 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003923 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003924
James Ketrenos43f66a62005-03-25 12:31:53 -06003925 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05003926 max_rate = ipw_get_max_rate(priv);
3927 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003928 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3929 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003930
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003931 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003932 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003933 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003934 else
3935 rx_quality = 100;
3936 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3937 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003938
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003939 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003940 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003941 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003942 else
3943 tx_quality = 100;
3944 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3945 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003946
James Ketrenos43f66a62005-03-25 12:31:53 -06003947 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003948 signal_quality =
3949 (100 *
3950 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3951 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
3952 (priv->ieee->perfect_rssi - rssi) *
3953 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
3954 62 * (priv->ieee->perfect_rssi - rssi))) /
3955 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3956 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
3957 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06003958 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05003959 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06003960 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003961
James Ketrenos43f66a62005-03-25 12:31:53 -06003962 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3963 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003964
3965 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003966 min(rate_quality,
3967 min(tx_quality, min(rx_quality, signal_quality))));
3968 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003969 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3970 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003971 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003972 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3973 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003975 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3976 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003977 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003978 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3979 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003980 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003981 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3982 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003983
3984 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003985
3986 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003987 IPW_STATS_INTERVAL);
3988}
3989
James Ketrenosc848d0a2005-08-24 21:56:24 -05003990static void ipw_bg_gather_stats(void *data)
3991{
3992 struct ipw_priv *priv = data;
3993 down(&priv->sem);
3994 ipw_gather_stats(data);
3995 up(&priv->sem);
3996}
3997
James Ketrenosea2b26e2005-08-24 21:25:16 -05003998static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3999 int missed_count)
4000{
4001 priv->notif_missed_beacons = missed_count;
4002
James Ketrenosafbf30a2005-08-25 00:05:33 -05004003 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004004 priv->status & STATUS_ASSOCIATED) {
4005 /* If associated and we've hit the missed
4006 * beacon threshold, disassociate, turn
4007 * off roaming, and abort any active scans */
4008 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004009 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004010 "Missed beacon: %d - disassociate\n", missed_count);
4011 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004012 if (priv->status & STATUS_SCANNING) {
4013 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4014 IPW_DL_STATE,
4015 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004016 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004017 }
4018
James Ketrenosea2b26e2005-08-24 21:25:16 -05004019 queue_work(priv->workqueue, &priv->disassociate);
4020 return;
4021 }
4022
4023 if (priv->status & STATUS_ROAMING) {
4024 /* If we are currently roaming, then just
4025 * print a debug statement... */
4026 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4027 "Missed beacon: %d - roam in progress\n",
4028 missed_count);
4029 return;
4030 }
4031
4032 if (missed_count > priv->roaming_threshold) {
4033 /* If we are not already roaming, set the ROAM
4034 * bit in the status and kick off a scan */
4035 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4036 "Missed beacon: %d - initiate "
4037 "roaming\n", missed_count);
4038 if (!(priv->status & STATUS_ROAMING)) {
4039 priv->status |= STATUS_ROAMING;
4040 if (!(priv->status & STATUS_SCANNING))
4041 queue_work(priv->workqueue,
4042 &priv->request_scan);
4043 }
4044 return;
4045 }
4046
4047 if (priv->status & STATUS_SCANNING) {
4048 /* Stop scan to keep fw from getting
4049 * stuck (only if we aren't roaming --
4050 * otherwise we'll never scan more than 2 or 3
4051 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004052 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4053 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004054 queue_work(priv->workqueue, &priv->abort_scan);
4055 }
4056
4057 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4058
4059}
4060
James Ketrenos43f66a62005-03-25 12:31:53 -06004061/**
4062 * Handle host notification packet.
4063 * Called from interrupt routine
4064 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004065static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004066 struct ipw_rx_notification *notif)
4067{
James Ketrenosa613bff2005-08-24 21:43:11 -05004068 notif->size = le16_to_cpu(notif->size);
4069
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004070 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004071
James Ketrenos43f66a62005-03-25 12:31:53 -06004072 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004073 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4074 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004075
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004076 switch (assoc->state) {
4077 case CMAS_ASSOCIATED:{
4078 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4079 IPW_DL_ASSOC,
4080 "associated: '%s' " MAC_FMT
4081 " \n",
4082 escape_essid(priv->essid,
4083 priv->essid_len),
4084 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004085
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004086 switch (priv->ieee->iw_mode) {
4087 case IW_MODE_INFRA:
4088 memcpy(priv->ieee->bssid,
4089 priv->bssid, ETH_ALEN);
4090 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004091
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004092 case IW_MODE_ADHOC:
4093 memcpy(priv->ieee->bssid,
4094 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004095
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004096 /* clear out the station table */
4097 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004098
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004099 IPW_DEBUG_ASSOC
4100 ("queueing adhoc check\n");
4101 queue_delayed_work(priv->
4102 workqueue,
4103 &priv->
4104 adhoc_check,
4105 priv->
4106 assoc_request.
4107 beacon_interval);
4108 break;
4109 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004110
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004111 priv->status &= ~STATUS_ASSOCIATING;
4112 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004113 queue_work(priv->workqueue,
4114 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004115
James Ketrenosb095c382005-08-24 22:04:42 -05004116#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004117#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4118 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4119 if ((priv->status & STATUS_AUTH) &&
4120 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4121 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004122 if ((sizeof
4123 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004124 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004125 <= notif->size)
4126 && (notif->size <= 2314)) {
4127 struct
4128 ieee80211_rx_stats
4129 stats = {
4130 .len =
4131 notif->
4132 size - 1,
4133 };
4134
4135 IPW_DEBUG_QOS
4136 ("QoS Associate "
4137 "size %d\n",
4138 notif->size);
4139 ieee80211_rx_mgt(priv->
4140 ieee,
4141 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004142 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004143 *)
4144 &notif->u.raw, &stats);
4145 }
4146 }
4147#endif
4148
James Ketrenosa613bff2005-08-24 21:43:11 -05004149 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004150
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004151 break;
4152 }
4153
4154 case CMAS_AUTHENTICATED:{
4155 if (priv->
4156 status & (STATUS_ASSOCIATED |
4157 STATUS_AUTH)) {
4158#ifdef CONFIG_IPW_DEBUG
4159 struct notif_authenticate *auth
4160 = &notif->u.auth;
4161 IPW_DEBUG(IPW_DL_NOTIF |
4162 IPW_DL_STATE |
4163 IPW_DL_ASSOC,
4164 "deauthenticated: '%s' "
4165 MAC_FMT
4166 ": (0x%04X) - %s \n",
4167 escape_essid(priv->
4168 essid,
4169 priv->
4170 essid_len),
4171 MAC_ARG(priv->bssid),
4172 ntohs(auth->status),
4173 ipw_get_status_code
4174 (ntohs
4175 (auth->status)));
4176#endif
4177
4178 priv->status &=
4179 ~(STATUS_ASSOCIATING |
4180 STATUS_AUTH |
4181 STATUS_ASSOCIATED);
4182
James Ketrenosa613bff2005-08-24 21:43:11 -05004183 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004184 break;
4185 }
4186
4187 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4188 IPW_DL_ASSOC,
4189 "authenticated: '%s' " MAC_FMT
4190 "\n",
4191 escape_essid(priv->essid,
4192 priv->essid_len),
4193 MAC_ARG(priv->bssid));
4194 break;
4195 }
4196
4197 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004198 if (priv->status & STATUS_AUTH) {
4199 struct
4200 ieee80211_assoc_response
4201 *resp;
4202 resp =
4203 (struct
4204 ieee80211_assoc_response
4205 *)&notif->u.raw;
4206 IPW_DEBUG(IPW_DL_NOTIF |
4207 IPW_DL_STATE |
4208 IPW_DL_ASSOC,
4209 "association failed (0x%04X): %s\n",
4210 ntohs(resp->status),
4211 ipw_get_status_code
4212 (ntohs
4213 (resp->status)));
4214 }
4215
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004216 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4217 IPW_DL_ASSOC,
4218 "disassociated: '%s' " MAC_FMT
4219 " \n",
4220 escape_essid(priv->essid,
4221 priv->essid_len),
4222 MAC_ARG(priv->bssid));
4223
4224 priv->status &=
4225 ~(STATUS_DISASSOCIATING |
4226 STATUS_ASSOCIATING |
4227 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004228 if (priv->assoc_network
4229 && (priv->assoc_network->
4230 capability &
4231 WLAN_CAPABILITY_IBSS))
4232 ipw_remove_current_network
4233 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004234
James Ketrenosa613bff2005-08-24 21:43:11 -05004235 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004236
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004237 break;
4238 }
4239
James Ketrenosb095c382005-08-24 22:04:42 -05004240 case CMAS_RX_ASSOC_RESP:
4241 break;
4242
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004243 default:
4244 IPW_ERROR("assoc: unknown (%d)\n",
4245 assoc->state);
4246 break;
4247 }
4248
James Ketrenos43f66a62005-03-25 12:31:53 -06004249 break;
4250 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004251
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004252 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4253 struct notif_authenticate *auth = &notif->u.auth;
4254 switch (auth->state) {
4255 case CMAS_AUTHENTICATED:
4256 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4257 "authenticated: '%s' " MAC_FMT " \n",
4258 escape_essid(priv->essid,
4259 priv->essid_len),
4260 MAC_ARG(priv->bssid));
4261 priv->status |= STATUS_AUTH;
4262 break;
4263
4264 case CMAS_INIT:
4265 if (priv->status & STATUS_AUTH) {
4266 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4267 IPW_DL_ASSOC,
4268 "authentication failed (0x%04X): %s\n",
4269 ntohs(auth->status),
4270 ipw_get_status_code(ntohs
4271 (auth->
4272 status)));
4273 }
4274 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4275 IPW_DL_ASSOC,
4276 "deauthenticated: '%s' " MAC_FMT "\n",
4277 escape_essid(priv->essid,
4278 priv->essid_len),
4279 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004280
4281 priv->status &= ~(STATUS_ASSOCIATING |
4282 STATUS_AUTH |
4283 STATUS_ASSOCIATED);
4284
James Ketrenosa613bff2005-08-24 21:43:11 -05004285 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004286 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004287
4288 case CMAS_TX_AUTH_SEQ_1:
4289 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4290 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4291 break;
4292 case CMAS_RX_AUTH_SEQ_2:
4293 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4294 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4295 break;
4296 case CMAS_AUTH_SEQ_1_PASS:
4297 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4298 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4299 break;
4300 case CMAS_AUTH_SEQ_1_FAIL:
4301 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4302 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4303 break;
4304 case CMAS_TX_AUTH_SEQ_3:
4305 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4306 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4307 break;
4308 case CMAS_RX_AUTH_SEQ_4:
4309 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4310 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4311 break;
4312 case CMAS_AUTH_SEQ_2_PASS:
4313 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4314 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4315 break;
4316 case CMAS_AUTH_SEQ_2_FAIL:
4317 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4318 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4319 break;
4320 case CMAS_TX_ASSOC:
4321 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4322 IPW_DL_ASSOC, "TX_ASSOC\n");
4323 break;
4324 case CMAS_RX_ASSOC_RESP:
4325 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4326 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004327
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004328 break;
4329 case CMAS_ASSOCIATED:
4330 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4331 IPW_DL_ASSOC, "ASSOCIATED\n");
4332 break;
4333 default:
4334 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4335 auth->state);
4336 break;
4337 }
4338 break;
4339 }
4340
4341 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4342 struct notif_channel_result *x =
4343 &notif->u.channel_result;
4344
4345 if (notif->size == sizeof(*x)) {
4346 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4347 x->channel_num);
4348 } else {
4349 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4350 "(should be %zd)\n",
4351 notif->size, sizeof(*x));
4352 }
4353 break;
4354 }
4355
4356 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4357 struct notif_scan_complete *x = &notif->u.scan_complete;
4358 if (notif->size == sizeof(*x)) {
4359 IPW_DEBUG_SCAN
4360 ("Scan completed: type %d, %d channels, "
4361 "%d status\n", x->scan_type,
4362 x->num_channels, x->status);
4363 } else {
4364 IPW_ERROR("Scan completed of wrong size %d "
4365 "(should be %zd)\n",
4366 notif->size, sizeof(*x));
4367 }
4368
4369 priv->status &=
4370 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4371
4372 cancel_delayed_work(&priv->scan_check);
4373
James Ketrenosb095c382005-08-24 22:04:42 -05004374 if (priv->status & STATUS_EXIT_PENDING)
4375 break;
4376
4377 priv->ieee->scans++;
4378
4379#ifdef CONFIG_IPW2200_MONITOR
4380 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004381 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004382 queue_work(priv->workqueue,
4383 &priv->request_scan);
4384 break;
4385 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004386 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004387#endif /* CONFIG_IPW2200_MONITOR */
4388
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004389 if (!(priv->status & (STATUS_ASSOCIATED |
4390 STATUS_ASSOCIATING |
4391 STATUS_ROAMING |
4392 STATUS_DISASSOCIATING)))
4393 queue_work(priv->workqueue, &priv->associate);
4394 else if (priv->status & STATUS_ROAMING) {
4395 /* If a scan completed and we are in roam mode, then
4396 * the scan that completed was the one requested as a
4397 * result of entering roam... so, schedule the
4398 * roam work */
4399 queue_work(priv->workqueue, &priv->roam);
4400 } else if (priv->status & STATUS_SCAN_PENDING)
4401 queue_work(priv->workqueue,
4402 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004403 else if (priv->config & CFG_BACKGROUND_SCAN
4404 && priv->status & STATUS_ASSOCIATED)
4405 queue_delayed_work(priv->workqueue,
4406 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004407 break;
4408 }
4409
4410 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4411 struct notif_frag_length *x = &notif->u.frag_len;
4412
James Ketrenosa613bff2005-08-24 21:43:11 -05004413 if (notif->size == sizeof(*x))
4414 IPW_ERROR("Frag length: %d\n",
4415 le16_to_cpu(x->frag_length));
4416 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004417 IPW_ERROR("Frag length of wrong size %d "
4418 "(should be %zd)\n",
4419 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004420 break;
4421 }
4422
4423 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4424 struct notif_link_deterioration *x =
4425 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004426
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004427 if (notif->size == sizeof(*x)) {
4428 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4429 "link deterioration: '%s' " MAC_FMT
4430 " \n", escape_essid(priv->essid,
4431 priv->essid_len),
4432 MAC_ARG(priv->bssid));
4433 memcpy(&priv->last_link_deterioration, x,
4434 sizeof(*x));
4435 } else {
4436 IPW_ERROR("Link Deterioration of wrong size %d "
4437 "(should be %zd)\n",
4438 notif->size, sizeof(*x));
4439 }
4440 break;
4441 }
4442
4443 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4444 IPW_ERROR("Dino config\n");
4445 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004446 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004447 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004448
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004449 break;
4450 }
4451
4452 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4453 struct notif_beacon_state *x = &notif->u.beacon_state;
4454 if (notif->size != sizeof(*x)) {
4455 IPW_ERROR
4456 ("Beacon state of wrong size %d (should "
4457 "be %zd)\n", notif->size, sizeof(*x));
4458 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004459 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004460
James Ketrenosa613bff2005-08-24 21:43:11 -05004461 if (le32_to_cpu(x->state) ==
4462 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4463 ipw_handle_missed_beacon(priv,
4464 le32_to_cpu(x->
4465 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004466
James Ketrenos43f66a62005-03-25 12:31:53 -06004467 break;
4468 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004469
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004470 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4471 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4472 if (notif->size == sizeof(*x)) {
4473 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4474 "0x%02x station %d\n",
4475 x->key_state, x->security_type,
4476 x->station_index);
4477 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004478 }
4479
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004480 IPW_ERROR
4481 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4482 notif->size, sizeof(*x));
4483 break;
4484 }
4485
4486 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4487 struct notif_calibration *x = &notif->u.calibration;
4488
4489 if (notif->size == sizeof(*x)) {
4490 memcpy(&priv->calib, x, sizeof(*x));
4491 IPW_DEBUG_INFO("TODO: Calibration\n");
4492 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004493 }
4494
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004495 IPW_ERROR
4496 ("Calibration of wrong size %d (should be %zd)\n",
4497 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004498 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004499 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004501 case HOST_NOTIFICATION_NOISE_STATS:{
4502 if (notif->size == sizeof(u32)) {
4503 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004504 (u8) (le32_to_cpu(notif->u.noise.value) &
4505 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004506 average_add(&priv->average_noise,
4507 priv->last_noise);
4508 break;
4509 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004510
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004511 IPW_ERROR
4512 ("Noise stat is wrong size %d (should be %zd)\n",
4513 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004514 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004515 }
4516
James Ketrenos43f66a62005-03-25 12:31:53 -06004517 default:
4518 IPW_ERROR("Unknown notification: "
4519 "subtype=%d,flags=0x%2x,size=%d\n",
4520 notif->subtype, notif->flags, notif->size);
4521 }
4522}
4523
4524/**
4525 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004526 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004527 * @param priv
4528 * @return error code
4529 */
4530static int ipw_queue_reset(struct ipw_priv *priv)
4531{
4532 int rc = 0;
4533 /** @todo customize queue sizes */
4534 int nTx = 64, nTxCmd = 8;
4535 ipw_tx_queue_free(priv);
4536 /* Tx CMD queue */
4537 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004538 IPW_TX_CMD_QUEUE_READ_INDEX,
4539 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4540 IPW_TX_CMD_QUEUE_BD_BASE,
4541 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004542 if (rc) {
4543 IPW_ERROR("Tx Cmd queue init failed\n");
4544 goto error;
4545 }
4546 /* Tx queue(s) */
4547 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004548 IPW_TX_QUEUE_0_READ_INDEX,
4549 IPW_TX_QUEUE_0_WRITE_INDEX,
4550 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004551 if (rc) {
4552 IPW_ERROR("Tx 0 queue init failed\n");
4553 goto error;
4554 }
4555 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004556 IPW_TX_QUEUE_1_READ_INDEX,
4557 IPW_TX_QUEUE_1_WRITE_INDEX,
4558 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004559 if (rc) {
4560 IPW_ERROR("Tx 1 queue init failed\n");
4561 goto error;
4562 }
4563 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004564 IPW_TX_QUEUE_2_READ_INDEX,
4565 IPW_TX_QUEUE_2_WRITE_INDEX,
4566 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004567 if (rc) {
4568 IPW_ERROR("Tx 2 queue init failed\n");
4569 goto error;
4570 }
4571 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004572 IPW_TX_QUEUE_3_READ_INDEX,
4573 IPW_TX_QUEUE_3_WRITE_INDEX,
4574 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004575 if (rc) {
4576 IPW_ERROR("Tx 3 queue init failed\n");
4577 goto error;
4578 }
4579 /* statistics */
4580 priv->rx_bufs_min = 0;
4581 priv->rx_pend_max = 0;
4582 return rc;
4583
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004584 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004585 ipw_tx_queue_free(priv);
4586 return rc;
4587}
4588
4589/**
4590 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004591 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004592 * When FW adwances 'R' index, all entries between old and
4593 * new 'R' index need to be reclaimed. As result, some free space
4594 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004595 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004596 * @note Need to protect against garbage in 'R' index
4597 * @param priv
4598 * @param txq
4599 * @param qindex
4600 * @return Number of used entries remains in the queue
4601 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004602static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004603 struct clx2_tx_queue *txq, int qindex)
4604{
4605 u32 hw_tail;
4606 int used;
4607 struct clx2_queue *q = &txq->q;
4608
4609 hw_tail = ipw_read32(priv, q->reg_r);
4610 if (hw_tail >= q->n_bd) {
4611 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004612 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4613 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004614 goto done;
4615 }
4616 for (; q->last_used != hw_tail;
4617 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4618 ipw_queue_tx_free_tfd(priv, txq);
4619 priv->tx_packets++;
4620 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004621 done:
James Ketrenosa613bff2005-08-24 21:43:11 -05004622 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004623 __maybe_wake_tx(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004624 used = q->first_empty - q->last_used;
4625 if (used < 0)
4626 used += q->n_bd;
4627
4628 return used;
4629}
4630
4631static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4632 int len, int sync)
4633{
4634 struct clx2_tx_queue *txq = &priv->txq_cmd;
4635 struct clx2_queue *q = &txq->q;
4636 struct tfd_frame *tfd;
4637
4638 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4639 IPW_ERROR("No space for Tx\n");
4640 return -EBUSY;
4641 }
4642
4643 tfd = &txq->bd[q->first_empty];
4644 txq->txb[q->first_empty] = NULL;
4645
4646 memset(tfd, 0, sizeof(*tfd));
4647 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4648 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4649 priv->hcmd_seq++;
4650 tfd->u.cmd.index = hcmd;
4651 tfd->u.cmd.length = len;
4652 memcpy(tfd->u.cmd.payload, buf, len);
4653 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4654 ipw_write32(priv, q->reg_w, q->first_empty);
4655 _ipw_read32(priv, 0x90);
4656
4657 return 0;
4658}
4659
Jeff Garzikbf794512005-07-31 13:07:26 -04004660/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004661 * Rx theory of operation
4662 *
4663 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004664 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004665 * 0 to 31
4666 *
4667 * Rx Queue Indexes
4668 * The host/firmware share two index registers for managing the Rx buffers.
4669 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004670 * The READ index maps to the first position that the firmware may be writing
4671 * to -- the driver can read up to (but not including) this position and get
4672 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004673 * The READ index is managed by the firmware once the card is enabled.
4674 *
4675 * The WRITE index maps to the last position the driver has read from -- the
4676 * position preceding WRITE is the last slot the firmware can place a packet.
4677 *
4678 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004679 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004680 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004681 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004682 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4683 *
4684 * When the firmware places a packet in a buffer it will advance the READ index
4685 * and fire the RX interrupt. The driver can then query the READ index and
4686 * process as many packets as possible, moving the WRITE index forward as it
4687 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004688 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004689 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004690 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004691 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004692 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004693 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4694 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4695 * 'processed' and 'read' driver indexes as well)
4696 * + A received packet is processed and handed to the kernel network stack,
4697 * detached from the ipw->rxq. The driver 'processed' index is updated.
4698 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004699 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4700 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004701 * were enough free buffers and RX_STALLED is set it is cleared.
4702 *
4703 *
4704 * Driver sequence:
4705 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004706 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004707 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4708 * ipw_rx_queue_restock
4709 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4710 * queue, updates firmware pointers, and updates
4711 * the WRITE index. If insufficient rx_free buffers
4712 * are available, schedules ipw_rx_queue_replenish
4713 *
4714 * -- enable interrupts --
4715 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004716 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 * Moves the packet buffer from queue to rx_used.
4718 * Calls ipw_rx_queue_restock to refill any empty
4719 * slots.
4720 * ...
4721 *
4722 */
4723
Jeff Garzikbf794512005-07-31 13:07:26 -04004724/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004725 * If there are slots in the RX queue that need to be restocked,
4726 * and we have free pre-allocated buffers, fill the ranks as much
4727 * as we can pulling from rx_free.
4728 *
4729 * This moves the 'write' index forward to catch up with 'processed', and
4730 * also updates the memory address in the firmware to reference the new
4731 * target buffer.
4732 */
4733static void ipw_rx_queue_restock(struct ipw_priv *priv)
4734{
4735 struct ipw_rx_queue *rxq = priv->rxq;
4736 struct list_head *element;
4737 struct ipw_rx_mem_buffer *rxb;
4738 unsigned long flags;
4739 int write;
4740
4741 spin_lock_irqsave(&rxq->lock, flags);
4742 write = rxq->write;
4743 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4744 element = rxq->rx_free.next;
4745 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4746 list_del(element);
4747
James Ketrenosb095c382005-08-24 22:04:42 -05004748 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004749 rxb->dma_addr);
4750 rxq->queue[rxq->write] = rxb;
4751 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4752 rxq->free_count--;
4753 }
4754 spin_unlock_irqrestore(&rxq->lock, flags);
4755
Jeff Garzikbf794512005-07-31 13:07:26 -04004756 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004757 * refill it */
4758 if (rxq->free_count <= RX_LOW_WATERMARK)
4759 queue_work(priv->workqueue, &priv->rx_replenish);
4760
4761 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004762 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004763 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004764}
4765
4766/*
4767 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004768 * Also restock the Rx queue via ipw_rx_queue_restock.
4769 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004770 * This is called as a scheduled work item (except for during intialization)
4771 */
4772static void ipw_rx_queue_replenish(void *data)
4773{
4774 struct ipw_priv *priv = data;
4775 struct ipw_rx_queue *rxq = priv->rxq;
4776 struct list_head *element;
4777 struct ipw_rx_mem_buffer *rxb;
4778 unsigned long flags;
4779
4780 spin_lock_irqsave(&rxq->lock, flags);
4781 while (!list_empty(&rxq->rx_used)) {
4782 element = rxq->rx_used.next;
4783 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004784 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004785 if (!rxb->skb) {
4786 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4787 priv->net_dev->name);
4788 /* We don't reschedule replenish work here -- we will
4789 * call the restock method and if it still needs
4790 * more buffers it will schedule replenish */
4791 break;
4792 }
4793 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004794
James Ketrenos43f66a62005-03-25 12:31:53 -06004795 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004796 rxb->dma_addr =
4797 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004798 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004799
James Ketrenos43f66a62005-03-25 12:31:53 -06004800 list_add_tail(&rxb->list, &rxq->rx_free);
4801 rxq->free_count++;
4802 }
4803 spin_unlock_irqrestore(&rxq->lock, flags);
4804
4805 ipw_rx_queue_restock(priv);
4806}
4807
James Ketrenosc848d0a2005-08-24 21:56:24 -05004808static void ipw_bg_rx_queue_replenish(void *data)
4809{
4810 struct ipw_priv *priv = data;
4811 down(&priv->sem);
4812 ipw_rx_queue_replenish(data);
4813 up(&priv->sem);
4814}
4815
James Ketrenos43f66a62005-03-25 12:31:53 -06004816/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4817 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004818 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004819 * non NULL it is unmapped and freed
4820 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004821static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004822{
4823 int i;
4824
4825 if (!rxq)
4826 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004827
James Ketrenos43f66a62005-03-25 12:31:53 -06004828 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4829 if (rxq->pool[i].skb != NULL) {
4830 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004831 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004832 dev_kfree_skb(rxq->pool[i].skb);
4833 }
4834 }
4835
4836 kfree(rxq);
4837}
4838
4839static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4840{
4841 struct ipw_rx_queue *rxq;
4842 int i;
4843
4844 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004845 if (unlikely(!rxq)) {
4846 IPW_ERROR("memory allocation failed\n");
4847 return NULL;
4848 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004849 memset(rxq, 0, sizeof(*rxq));
4850 spin_lock_init(&rxq->lock);
4851 INIT_LIST_HEAD(&rxq->rx_free);
4852 INIT_LIST_HEAD(&rxq->rx_used);
4853
4854 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004855 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004856 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4857
4858 /* Set us so that we have processed and used all buffers, but have
4859 * not restocked the Rx queue with fresh buffers */
4860 rxq->read = rxq->write = 0;
4861 rxq->processed = RX_QUEUE_SIZE - 1;
4862 rxq->free_count = 0;
4863
4864 return rxq;
4865}
4866
4867static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4868{
4869 rate &= ~IEEE80211_BASIC_RATE_MASK;
4870 if (ieee_mode == IEEE_A) {
4871 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004872 case IEEE80211_OFDM_RATE_6MB:
4873 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004874 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004875 case IEEE80211_OFDM_RATE_9MB:
4876 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004877 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004878 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004879 return priv->
4880 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004881 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004882 return priv->
4883 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004884 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 return priv->
4886 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004887 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004888 return priv->
4889 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004890 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004891 return priv->
4892 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004893 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004894 return priv->
4895 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004896 default:
4897 return 0;
4898 }
4899 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004900
James Ketrenos43f66a62005-03-25 12:31:53 -06004901 /* B and G mixed */
4902 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004903 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004904 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004905 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004906 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004907 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004908 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004909 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004910 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4911 }
4912
4913 /* If we are limited to B modulations, bail at this point */
4914 if (ieee_mode == IEEE_B)
4915 return 0;
4916
4917 /* G */
4918 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004919 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004920 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004921 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004922 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004923 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004924 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004925 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004926 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004927 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004929 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004930 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004931 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004932 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004933 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004934 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4935 }
4936
4937 return 0;
4938}
4939
Jeff Garzikbf794512005-07-31 13:07:26 -04004940static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 const struct ieee80211_network *network,
4942 struct ipw_supported_rates *rates)
4943{
4944 int num_rates, i;
4945
4946 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004947 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004948 rates->num_rates = 0;
4949 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004950 if (!ipw_is_rate_in_mask(priv, network->mode,
4951 network->rates[i])) {
4952
James Ketrenosea2b26e2005-08-24 21:25:16 -05004953 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004954 IPW_DEBUG_SCAN("Adding masked mandatory "
4955 "rate %02X\n",
4956 network->rates[i]);
4957 rates->supported_rates[rates->num_rates++] =
4958 network->rates[i];
4959 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004960 }
4961
James Ketrenos43f66a62005-03-25 12:31:53 -06004962 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4963 network->rates[i], priv->rates_mask);
4964 continue;
4965 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004966
James Ketrenos43f66a62005-03-25 12:31:53 -06004967 rates->supported_rates[rates->num_rates++] = network->rates[i];
4968 }
4969
James Ketrenosa613bff2005-08-24 21:43:11 -05004970 num_rates = min(network->rates_ex_len,
4971 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004972 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004973 if (!ipw_is_rate_in_mask(priv, network->mode,
4974 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004975 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004976 IPW_DEBUG_SCAN("Adding masked mandatory "
4977 "rate %02X\n",
4978 network->rates_ex[i]);
4979 rates->supported_rates[rates->num_rates++] =
4980 network->rates[i];
4981 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004982 }
4983
James Ketrenos43f66a62005-03-25 12:31:53 -06004984 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4985 network->rates_ex[i], priv->rates_mask);
4986 continue;
4987 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004988
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004989 rates->supported_rates[rates->num_rates++] =
4990 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004991 }
4992
James Ketrenosea2b26e2005-08-24 21:25:16 -05004993 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004994}
4995
4996static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4997 const struct ipw_supported_rates *src)
4998{
4999 u8 i;
5000 for (i = 0; i < src->num_rates; i++)
5001 dest->supported_rates[i] = src->supported_rates[i];
5002 dest->num_rates = src->num_rates;
5003}
5004
5005/* TODO: Look at sniffed packets in the air to determine if the basic rate
5006 * mask should ever be used -- right now all callers to add the scan rates are
5007 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5008static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005009 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005010{
Jeff Garzikbf794512005-07-31 13:07:26 -04005011 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005012 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005013
James Ketrenos43f66a62005-03-25 12:31:53 -06005014 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005015 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005016 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005017
5018 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005019 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005020 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005021
5022 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005024 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005025
5026 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005027 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005028 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005029}
5030
5031static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005032 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005033{
Jeff Garzikbf794512005-07-31 13:07:26 -04005034 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005035 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005036
5037 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005038 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005039 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005040
5041 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005042 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005043 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005044
5045 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005046 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005047 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005048
5049 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005050 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005051 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005052
5053 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005054 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005055 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005056
5057 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005058 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005059 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005060
5061 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005062 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005063 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005064
5065 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005066 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005067 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005068}
5069
5070struct ipw_network_match {
5071 struct ieee80211_network *network;
5072 struct ipw_supported_rates rates;
5073};
5074
James Ketrenosc848d0a2005-08-24 21:56:24 -05005075static int ipw_find_adhoc_network(struct ipw_priv *priv,
5076 struct ipw_network_match *match,
5077 struct ieee80211_network *network,
5078 int roaming)
5079{
5080 struct ipw_supported_rates rates;
5081
5082 /* Verify that this network's capability is compatible with the
5083 * current mode (AdHoc or Infrastructure) */
5084 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5085 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5086 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5087 "capability mismatch.\n",
5088 escape_essid(network->ssid, network->ssid_len),
5089 MAC_ARG(network->bssid));
5090 return 0;
5091 }
5092
5093 /* If we do not have an ESSID for this AP, we can not associate with
5094 * it */
5095 if (network->flags & NETWORK_EMPTY_ESSID) {
5096 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5097 "because of hidden ESSID.\n",
5098 escape_essid(network->ssid, network->ssid_len),
5099 MAC_ARG(network->bssid));
5100 return 0;
5101 }
5102
5103 if (unlikely(roaming)) {
5104 /* If we are roaming, then ensure check if this is a valid
5105 * network to try and roam to */
5106 if ((network->ssid_len != match->network->ssid_len) ||
5107 memcmp(network->ssid, match->network->ssid,
5108 network->ssid_len)) {
5109 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5110 "because of non-network ESSID.\n",
5111 escape_essid(network->ssid,
5112 network->ssid_len),
5113 MAC_ARG(network->bssid));
5114 return 0;
5115 }
5116 } else {
5117 /* If an ESSID has been configured then compare the broadcast
5118 * ESSID to ours */
5119 if ((priv->config & CFG_STATIC_ESSID) &&
5120 ((network->ssid_len != priv->essid_len) ||
5121 memcmp(network->ssid, priv->essid,
5122 min(network->ssid_len, priv->essid_len)))) {
5123 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005124
James Ketrenosc848d0a2005-08-24 21:56:24 -05005125 strncpy(escaped,
5126 escape_essid(network->ssid, network->ssid_len),
5127 sizeof(escaped));
5128 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5129 "because of ESSID mismatch: '%s'.\n",
5130 escaped, MAC_ARG(network->bssid),
5131 escape_essid(priv->essid,
5132 priv->essid_len));
5133 return 0;
5134 }
5135 }
5136
5137 /* If the old network rate is better than this one, don't bother
5138 * testing everything else. */
5139
5140 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005141 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5142 "current network.\n",
5143 escape_essid(match->network->ssid,
5144 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005145 return 0;
5146 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005147 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5148 "current network.\n",
5149 escape_essid(match->network->ssid,
5150 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005151 return 0;
5152 }
5153
5154 /* Now go through and see if the requested network is valid... */
5155 if (priv->ieee->scan_age != 0 &&
5156 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5157 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5158 "because of age: %lums.\n",
5159 escape_essid(network->ssid, network->ssid_len),
5160 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005161 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005162 return 0;
5163 }
5164
5165 if ((priv->config & CFG_STATIC_CHANNEL) &&
5166 (network->channel != priv->channel)) {
5167 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5168 "because of channel mismatch: %d != %d.\n",
5169 escape_essid(network->ssid, network->ssid_len),
5170 MAC_ARG(network->bssid),
5171 network->channel, priv->channel);
5172 return 0;
5173 }
5174
5175 /* Verify privacy compatability */
5176 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5177 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5178 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5179 "because of privacy mismatch: %s != %s.\n",
5180 escape_essid(network->ssid, network->ssid_len),
5181 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005182 priv->
5183 capability & CAP_PRIVACY_ON ? "on" : "off",
5184 network->
5185 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5186 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005187 return 0;
5188 }
5189
5190 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5191 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5192 "because of the same BSSID match: " MAC_FMT
5193 ".\n", escape_essid(network->ssid,
5194 network->ssid_len),
5195 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5196 return 0;
5197 }
5198
5199 /* Filter out any incompatible freq / mode combinations */
5200 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5201 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5202 "because of invalid frequency/mode "
5203 "combination.\n",
5204 escape_essid(network->ssid, network->ssid_len),
5205 MAC_ARG(network->bssid));
5206 return 0;
5207 }
5208
5209 /* Ensure that the rates supported by the driver are compatible with
5210 * this AP, including verification of basic rates (mandatory) */
5211 if (!ipw_compatible_rates(priv, network, &rates)) {
5212 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5213 "because configured rate mask excludes "
5214 "AP mandatory rate.\n",
5215 escape_essid(network->ssid, network->ssid_len),
5216 MAC_ARG(network->bssid));
5217 return 0;
5218 }
5219
5220 if (rates.num_rates == 0) {
5221 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5222 "because of no compatible rates.\n",
5223 escape_essid(network->ssid, network->ssid_len),
5224 MAC_ARG(network->bssid));
5225 return 0;
5226 }
5227
5228 /* TODO: Perform any further minimal comparititive tests. We do not
5229 * want to put too much policy logic here; intelligent scan selection
5230 * should occur within a generic IEEE 802.11 user space tool. */
5231
5232 /* Set up 'new' AP to this network */
5233 ipw_copy_rates(&match->rates, &rates);
5234 match->network = network;
5235 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5236 escape_essid(network->ssid, network->ssid_len),
5237 MAC_ARG(network->bssid));
5238
5239 return 1;
5240}
5241
5242static void ipw_merge_adhoc_network(void *data)
5243{
5244 struct ipw_priv *priv = data;
5245 struct ieee80211_network *network = NULL;
5246 struct ipw_network_match match = {
5247 .network = priv->assoc_network
5248 };
5249
James Ketrenosafbf30a2005-08-25 00:05:33 -05005250 if ((priv->status & STATUS_ASSOCIATED) &&
5251 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005252 /* First pass through ROAM process -- look for a better
5253 * network */
5254 unsigned long flags;
5255
5256 spin_lock_irqsave(&priv->ieee->lock, flags);
5257 list_for_each_entry(network, &priv->ieee->network_list, list) {
5258 if (network != priv->assoc_network)
5259 ipw_find_adhoc_network(priv, &match, network,
5260 1);
5261 }
5262 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5263
5264 if (match.network == priv->assoc_network) {
5265 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5266 "merge to.\n");
5267 return;
5268 }
5269
5270 down(&priv->sem);
5271 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5272 IPW_DEBUG_MERGE("remove network %s\n",
5273 escape_essid(priv->essid,
5274 priv->essid_len));
5275 ipw_remove_current_network(priv);
5276 }
5277
5278 ipw_disassociate(priv);
5279 priv->assoc_network = match.network;
5280 up(&priv->sem);
5281 return;
5282 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005283}
5284
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005285static int ipw_best_network(struct ipw_priv *priv,
5286 struct ipw_network_match *match,
5287 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005288{
5289 struct ipw_supported_rates rates;
5290
5291 /* Verify that this network's capability is compatible with the
5292 * current mode (AdHoc or Infrastructure) */
5293 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005294 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005295 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5296 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5297 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005298 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005299 escape_essid(network->ssid, network->ssid_len),
5300 MAC_ARG(network->bssid));
5301 return 0;
5302 }
5303
5304 /* If we do not have an ESSID for this AP, we can not associate with
5305 * it */
5306 if (network->flags & NETWORK_EMPTY_ESSID) {
5307 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5308 "because of hidden ESSID.\n",
5309 escape_essid(network->ssid, network->ssid_len),
5310 MAC_ARG(network->bssid));
5311 return 0;
5312 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005313
James Ketrenos43f66a62005-03-25 12:31:53 -06005314 if (unlikely(roaming)) {
5315 /* If we are roaming, then ensure check if this is a valid
5316 * network to try and roam to */
5317 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005318 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005319 network->ssid_len)) {
5320 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5321 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005322 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005323 network->ssid_len),
5324 MAC_ARG(network->bssid));
5325 return 0;
5326 }
5327 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005328 /* If an ESSID has been configured then compare the broadcast
5329 * ESSID to ours */
5330 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005331 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005332 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005333 min(network->ssid_len, priv->essid_len)))) {
5334 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005335 strncpy(escaped,
5336 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005337 sizeof(escaped));
5338 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005339 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005340 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005341 escape_essid(priv->essid,
5342 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005343 return 0;
5344 }
5345 }
5346
5347 /* If the old network rate is better than this one, don't bother
5348 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005349 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005350 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005351 strncpy(escaped,
5352 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005353 sizeof(escaped));
5354 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5355 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5356 escaped, MAC_ARG(network->bssid),
5357 escape_essid(match->network->ssid,
5358 match->network->ssid_len),
5359 MAC_ARG(match->network->bssid));
5360 return 0;
5361 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005362
James Ketrenos43f66a62005-03-25 12:31:53 -06005363 /* If this network has already had an association attempt within the
5364 * last 3 seconds, do not try and associate again... */
5365 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005366 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005367 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
James Ketrenosafbf30a2005-08-25 00:05:33 -05005368 "because of storming (%lus since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005369 "assoc attempt).\n",
5370 escape_essid(network->ssid, network->ssid_len),
5371 MAC_ARG(network->bssid),
5372 (jiffies - network->last_associate) / HZ);
5373 return 0;
5374 }
5375
5376 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005377 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005378 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005379 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5380 "because of age: %lums.\n",
5381 escape_essid(network->ssid, network->ssid_len),
5382 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005383 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06005384 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005385 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005386
Jeff Garzikbf794512005-07-31 13:07:26 -04005387 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005388 (network->channel != priv->channel)) {
5389 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5390 "because of channel mismatch: %d != %d.\n",
5391 escape_essid(network->ssid, network->ssid_len),
5392 MAC_ARG(network->bssid),
5393 network->channel, priv->channel);
5394 return 0;
5395 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005396
James Ketrenos43f66a62005-03-25 12:31:53 -06005397 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005398 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005399 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5400 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5401 "because of privacy mismatch: %s != %s.\n",
5402 escape_essid(network->ssid, network->ssid_len),
5403 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005404 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005405 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005406 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005407 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005408 return 0;
5409 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005410
5411 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005412 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5413 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5414 "because of BSSID mismatch: " MAC_FMT ".\n",
5415 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005416 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005417 return 0;
5418 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005419
James Ketrenos43f66a62005-03-25 12:31:53 -06005420 /* Filter out any incompatible freq / mode combinations */
5421 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5422 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5423 "because of invalid frequency/mode "
5424 "combination.\n",
5425 escape_essid(network->ssid, network->ssid_len),
5426 MAC_ARG(network->bssid));
5427 return 0;
5428 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005429
James Ketrenosea2b26e2005-08-24 21:25:16 -05005430 /* Ensure that the rates supported by the driver are compatible with
5431 * this AP, including verification of basic rates (mandatory) */
5432 if (!ipw_compatible_rates(priv, network, &rates)) {
5433 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5434 "because configured rate mask excludes "
5435 "AP mandatory rate.\n",
5436 escape_essid(network->ssid, network->ssid_len),
5437 MAC_ARG(network->bssid));
5438 return 0;
5439 }
5440
James Ketrenos43f66a62005-03-25 12:31:53 -06005441 if (rates.num_rates == 0) {
5442 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5443 "because of no compatible rates.\n",
5444 escape_essid(network->ssid, network->ssid_len),
5445 MAC_ARG(network->bssid));
5446 return 0;
5447 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005448
James Ketrenos43f66a62005-03-25 12:31:53 -06005449 /* TODO: Perform any further minimal comparititive tests. We do not
5450 * want to put too much policy logic here; intelligent scan selection
5451 * should occur within a generic IEEE 802.11 user space tool. */
5452
5453 /* Set up 'new' AP to this network */
5454 ipw_copy_rates(&match->rates, &rates);
5455 match->network = network;
5456
5457 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5458 escape_essid(network->ssid, network->ssid_len),
5459 MAC_ARG(network->bssid));
5460
5461 return 1;
5462}
5463
Jeff Garzikbf794512005-07-31 13:07:26 -04005464static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005465 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005466{
James Ketrenosafbf30a2005-08-25 00:05:33 -05005467 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5468 int i;
5469
James Ketrenos43f66a62005-03-25 12:31:53 -06005470 /*
5471 * For the purposes of scanning, we can set our wireless mode
5472 * to trigger scans across combinations of bands, but when it
5473 * comes to creating a new ad-hoc network, we have tell the FW
5474 * exactly which band to use.
5475 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005476 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005477 * chossen band. Attempting to create a new ad-hoc network
5478 * with an invalid channel for wireless mode will trigger a
5479 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005480 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005481 */
James Ketrenosafbf30a2005-08-25 00:05:33 -05005482 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5483 case IEEE80211_52GHZ_BAND:
5484 network->mode = IEEE_A;
5485 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5486 if (i == -1)
5487 BUG();
5488 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5489 IPW_WARNING("Overriding invalid channel\n");
5490 priv->channel = geo->a[0].channel;
5491 }
5492 break;
5493
5494 case IEEE80211_24GHZ_BAND:
5495 if (priv->ieee->mode & IEEE_G)
5496 network->mode = IEEE_G;
5497 else
5498 network->mode = IEEE_B;
5499 break;
5500
5501 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005502 IPW_WARNING("Overriding invalid channel\n");
5503 if (priv->ieee->mode & IEEE_A) {
5504 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005505 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005506 } else if (priv->ieee->mode & IEEE_G) {
5507 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005508 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005509 } else {
5510 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005511 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005512 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005513 break;
5514 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005515
5516 network->channel = priv->channel;
5517 priv->config |= CFG_ADHOC_PERSIST;
5518 ipw_create_bssid(priv, network->bssid);
5519 network->ssid_len = priv->essid_len;
5520 memcpy(network->ssid, priv->essid, priv->essid_len);
5521 memset(&network->stats, 0, sizeof(network->stats));
5522 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005523 if (!(priv->config & CFG_PREAMBLE_LONG))
5524 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005525 if (priv->capability & CAP_PRIVACY_ON)
5526 network->capability |= WLAN_CAPABILITY_PRIVACY;
5527 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005528 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005529 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005530 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005531 &priv->rates.supported_rates[network->rates_len],
5532 network->rates_ex_len);
5533 network->last_scanned = 0;
5534 network->flags = 0;
5535 network->last_associate = 0;
5536 network->time_stamp[0] = 0;
5537 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005538 network->beacon_interval = 100; /* Default */
5539 network->listen_interval = 10; /* Default */
5540 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005541 network->wpa_ie_len = 0;
5542 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005543}
5544
James Ketrenosb095c382005-08-24 22:04:42 -05005545static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5546{
5547 struct ipw_tgi_tx_key *key;
5548 struct host_cmd cmd = {
5549 .cmd = IPW_CMD_TGI_TX_KEY,
5550 .len = sizeof(*key)
5551 };
5552
5553 if (!(priv->ieee->sec.flags & (1 << index)))
5554 return;
5555
5556 key = (struct ipw_tgi_tx_key *)&cmd.param;
5557 key->key_id = index;
5558 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5559 key->security_type = type;
5560 key->station_index = 0; /* always 0 for BSS */
5561 key->flags = 0;
5562 /* 0 for new key; previous value of counter (after fatal error) */
5563 key->tx_counter[0] = 0;
5564 key->tx_counter[1] = 0;
5565
5566 if (ipw_send_cmd(priv, &cmd)) {
5567 IPW_ERROR("failed to send TGI_TX_KEY command\n");
5568 return;
5569 }
5570}
5571
5572static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005573{
5574 struct ipw_wep_key *key;
5575 int i;
5576 struct host_cmd cmd = {
5577 .cmd = IPW_CMD_WEP_KEY,
5578 .len = sizeof(*key)
5579 };
5580
5581 key = (struct ipw_wep_key *)&cmd.param;
5582 key->cmd_id = DINO_CMD_WEP_KEY;
5583 key->seq_num = 0;
5584
James Ketrenosb095c382005-08-24 22:04:42 -05005585 /* Note: AES keys cannot be set for multiple times.
5586 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005587 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005588 key->key_index = i | type;
5589 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005590 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005591 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005592 }
5593
James Ketrenosb095c382005-08-24 22:04:42 -05005594 key->key_size = priv->ieee->sec.key_sizes[i];
5595 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5596
James Ketrenos43f66a62005-03-25 12:31:53 -06005597 if (ipw_send_cmd(priv, &cmd)) {
5598 IPW_ERROR("failed to send WEP_KEY command\n");
5599 return;
5600 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005601 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005602}
5603
Zhu Yi1fbfea52005-08-05 17:22:56 +08005604static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5605{
5606 if (priv->ieee->host_encrypt)
5607 return;
5608
5609 switch (level) {
5610 case SEC_LEVEL_3:
5611 priv->sys_config.disable_unicast_decryption = 0;
5612 priv->ieee->host_decrypt = 0;
5613 break;
5614 case SEC_LEVEL_2:
5615 priv->sys_config.disable_unicast_decryption = 1;
5616 priv->ieee->host_decrypt = 1;
5617 break;
5618 case SEC_LEVEL_1:
5619 priv->sys_config.disable_unicast_decryption = 0;
5620 priv->ieee->host_decrypt = 0;
5621 break;
5622 case SEC_LEVEL_0:
5623 priv->sys_config.disable_unicast_decryption = 1;
5624 break;
5625 default:
5626 break;
5627 }
5628}
5629
5630static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5631{
5632 if (priv->ieee->host_encrypt)
5633 return;
5634
5635 switch (level) {
5636 case SEC_LEVEL_3:
5637 priv->sys_config.disable_multicast_decryption = 0;
5638 break;
5639 case SEC_LEVEL_2:
5640 priv->sys_config.disable_multicast_decryption = 1;
5641 break;
5642 case SEC_LEVEL_1:
5643 priv->sys_config.disable_multicast_decryption = 0;
5644 break;
5645 case SEC_LEVEL_0:
5646 priv->sys_config.disable_multicast_decryption = 1;
5647 break;
5648 default:
5649 break;
5650 }
5651}
5652
James Ketrenosb095c382005-08-24 22:04:42 -05005653static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5654{
5655 switch (priv->ieee->sec.level) {
5656 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005657 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5658 ipw_send_tgi_tx_key(priv,
5659 DCT_FLAG_EXT_SECURITY_CCM,
5660 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005661
James Ketrenosb095c382005-08-24 22:04:42 -05005662 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005663 break;
5664 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005665 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5666 ipw_send_tgi_tx_key(priv,
5667 DCT_FLAG_EXT_SECURITY_TKIP,
5668 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005669 break;
5670 case SEC_LEVEL_1:
5671 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenosb095c382005-08-24 22:04:42 -05005672 break;
5673 case SEC_LEVEL_0:
5674 default:
5675 break;
5676 }
Zhu Yi1fbfea52005-08-05 17:22:56 +08005677
5678 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5679 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005680}
5681
James Ketrenos43f66a62005-03-25 12:31:53 -06005682static void ipw_adhoc_check(void *data)
5683{
5684 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005685
James Ketrenosafbf30a2005-08-25 00:05:33 -05005686 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005687 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005688 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5689 IPW_DL_STATE | IPW_DL_ASSOC,
5690 "Missed beacon: %d - disassociate\n",
5691 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005692 ipw_remove_current_network(priv);
5693 ipw_disassociate(priv);
5694 return;
5695 }
5696
Jeff Garzikbf794512005-07-31 13:07:26 -04005697 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005698 priv->assoc_request.beacon_interval);
5699}
5700
James Ketrenosc848d0a2005-08-24 21:56:24 -05005701static void ipw_bg_adhoc_check(void *data)
5702{
5703 struct ipw_priv *priv = data;
5704 down(&priv->sem);
5705 ipw_adhoc_check(data);
5706 up(&priv->sem);
5707}
5708
James Ketrenos43f66a62005-03-25 12:31:53 -06005709#ifdef CONFIG_IPW_DEBUG
5710static void ipw_debug_config(struct ipw_priv *priv)
5711{
5712 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5713 "[CFG 0x%08X]\n", priv->config);
5714 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005715 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005716 else
5717 IPW_DEBUG_INFO("Channel unlocked.\n");
5718 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005719 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005720 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005721 else
5722 IPW_DEBUG_INFO("ESSID unlocked.\n");
5723 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005724 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5725 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005726 else
5727 IPW_DEBUG_INFO("BSSID unlocked.\n");
5728 if (priv->capability & CAP_PRIVACY_ON)
5729 IPW_DEBUG_INFO("PRIVACY on\n");
5730 else
5731 IPW_DEBUG_INFO("PRIVACY off\n");
5732 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5733}
5734#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005735#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005736#endif
5737
James Ketrenosb095c382005-08-24 22:04:42 -05005738static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005739{
5740 /* TODO: Verify that this works... */
5741 struct ipw_fixed_rate fr = {
5742 .tx_rates = priv->rates_mask
5743 };
5744 u32 reg;
5745 u16 mask = 0;
5746
Jeff Garzikbf794512005-07-31 13:07:26 -04005747 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005749
James Ketrenos43f66a62005-03-25 12:31:53 -06005750 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005751 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005752 /* IEEE_A */
5753 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5754 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005755 IPW_DEBUG_WX
5756 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005757 fr.tx_rates = 0;
5758 break;
5759 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005760
James Ketrenos43f66a62005-03-25 12:31:53 -06005761 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5762 break;
5763
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005764 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005765 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005766 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005767 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5768 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005769 IPW_DEBUG_WX
5770 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005771 fr.tx_rates = 0;
5772 }
5773 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005774 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005775
5776 /* IEEE_G */
5777 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5778 IEEE80211_OFDM_RATES_MASK)) {
5779 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005780 IPW_DEBUG_WX
5781 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005782 fr.tx_rates = 0;
5783 break;
5784 }
5785
5786 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5787 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5788 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5789 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005790
James Ketrenos43f66a62005-03-25 12:31:53 -06005791 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5792 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5793 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5794 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005795
James Ketrenos43f66a62005-03-25 12:31:53 -06005796 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5797 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5798 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5799 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005800
James Ketrenos43f66a62005-03-25 12:31:53 -06005801 fr.tx_rates |= mask;
5802 break;
5803 }
5804
5805 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005806 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005807}
5808
James Ketrenosea2b26e2005-08-24 21:25:16 -05005809static void ipw_abort_scan(struct ipw_priv *priv)
5810{
5811 int err;
5812
5813 if (priv->status & STATUS_SCAN_ABORTING) {
5814 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5815 return;
5816 }
5817 priv->status |= STATUS_SCAN_ABORTING;
5818
5819 err = ipw_send_scan_abort(priv);
5820 if (err)
5821 IPW_DEBUG_HC("Request to abort scan failed.\n");
5822}
5823
James Ketrenosafbf30a2005-08-25 00:05:33 -05005824static void ipw_add_scan_channels(struct ipw_priv *priv,
5825 struct ipw_scan_request_ext *scan,
5826 int scan_type)
5827{
5828 int channel_index = 0;
5829 const struct ieee80211_geo *geo;
5830 int i;
5831
5832 geo = ieee80211_get_geo(priv->ieee);
5833
5834 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5835 int start = channel_index;
5836 for (i = 0; i < geo->a_channels; i++) {
5837 if ((priv->status & STATUS_ASSOCIATED) &&
5838 geo->a[i].channel == priv->channel)
5839 continue;
5840 channel_index++;
5841 scan->channels_list[channel_index] = geo->a[i].channel;
5842 ipw_set_scan_type(scan, channel_index, scan_type);
5843 }
5844
5845 if (start != channel_index) {
5846 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5847 (channel_index - start);
5848 channel_index++;
5849 }
5850 }
5851
5852 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5853 int start = channel_index;
5854 if (priv->config & CFG_SPEED_SCAN) {
5855 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5856 /* nop out the list */
5857 [0] = 0
5858 };
5859
5860 u8 channel;
5861 while (channel_index < IPW_SCAN_CHANNELS) {
5862 channel =
5863 priv->speed_scan[priv->speed_scan_pos];
5864 if (channel == 0) {
5865 priv->speed_scan_pos = 0;
5866 channel = priv->speed_scan[0];
5867 }
5868 if ((priv->status & STATUS_ASSOCIATED) &&
5869 channel == priv->channel) {
5870 priv->speed_scan_pos++;
5871 continue;
5872 }
5873
5874 /* If this channel has already been
5875 * added in scan, break from loop
5876 * and this will be the first channel
5877 * in the next scan.
5878 */
5879 if (channels[channel - 1] != 0)
5880 break;
5881
5882 channels[channel - 1] = 1;
5883 priv->speed_scan_pos++;
5884 channel_index++;
5885 scan->channels_list[channel_index] = channel;
5886 ipw_set_scan_type(scan, channel_index,
5887 scan_type);
5888 }
5889 } else {
5890 for (i = 0; i < geo->bg_channels; i++) {
5891 if ((priv->status & STATUS_ASSOCIATED) &&
5892 geo->bg[i].channel == priv->channel)
5893 continue;
5894 channel_index++;
5895 scan->channels_list[channel_index] =
5896 geo->bg[i].channel;
5897 ipw_set_scan_type(scan, channel_index,
5898 scan_type);
5899 }
5900 }
5901
5902 if (start != channel_index) {
5903 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
5904 (channel_index - start);
5905 }
5906 }
5907}
5908
James Ketrenosea2b26e2005-08-24 21:25:16 -05005909static int ipw_request_scan(struct ipw_priv *priv)
5910{
5911 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005912 int err = 0, scan_type;
5913
5914 if (!(priv->status & STATUS_INIT) ||
5915 (priv->status & STATUS_EXIT_PENDING))
5916 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005917
James Ketrenosb095c382005-08-24 22:04:42 -05005918 down(&priv->sem);
5919
James Ketrenosea2b26e2005-08-24 21:25:16 -05005920 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005921 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05005922 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005923 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005924 }
5925
James Ketrenosafbf30a2005-08-25 00:05:33 -05005926 if (!(priv->status & STATUS_SCAN_FORCED) &&
5927 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005928 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5929 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005930 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005931 }
5932
5933 if (priv->status & STATUS_RF_KILL_MASK) {
5934 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5935 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005936 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005937 }
5938
5939 memset(&scan, 0, sizeof(scan));
5940
James Ketrenosb095c382005-08-24 22:04:42 -05005941 if (priv->config & CFG_SPEED_SCAN)
5942 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5943 cpu_to_le16(30);
5944 else
5945 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5946 cpu_to_le16(20);
5947
James Ketrenosa613bff2005-08-24 21:43:11 -05005948 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5949 cpu_to_le16(20);
5950 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005951
James Ketrenosa613bff2005-08-24 21:43:11 -05005952 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05005953
James Ketrenosb095c382005-08-24 22:04:42 -05005954#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05005955 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005956 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05005957 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005958
James Ketrenosb095c382005-08-24 22:04:42 -05005959 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5960 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005961 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005962 channel = priv->channel;
5963 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005964
James Ketrenosb095c382005-08-24 22:04:42 -05005965 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005966 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005967 channel = priv->channel;
5968 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005969
James Ketrenosb095c382005-08-24 22:04:42 -05005970 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005971 band = (u8) (IPW_B_MODE << 6) | 1;
5972 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05005973 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005974 }
5975
James Ketrenosb095c382005-08-24 22:04:42 -05005976 scan.channels_list[0] = band;
5977 scan.channels_list[1] = channel;
5978 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005979
James Ketrenosb095c382005-08-24 22:04:42 -05005980 /* NOTE: The card will sit on this channel for this time
5981 * period. Scan aborts are timing sensitive and frequently
5982 * result in firmware restarts. As such, it is best to
5983 * set a small dwell_time here and just keep re-issuing
5984 * scans. Otherwise fast channel hopping will not actually
5985 * hop channels.
5986 *
5987 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05005988 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5989 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005990 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05005991#endif /* CONFIG_IPW2200_MONITOR */
5992 /* If we are roaming, then make this a directed scan for the
5993 * current network. Otherwise, ensure that every other scan
5994 * is a fast channel hop scan */
5995 if ((priv->status & STATUS_ROAMING)
5996 || (!(priv->status & STATUS_ASSOCIATED)
5997 && (priv->config & CFG_STATIC_ESSID)
5998 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005999 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6000 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006001 IPW_DEBUG_HC("Attempt to send SSID command "
6002 "failed.\n");
6003 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006004 }
6005
6006 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006007 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006008 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006009
James Ketrenosafbf30a2005-08-25 00:05:33 -05006010 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006011#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006012 }
6013#endif
6014
6015 err = ipw_send_scan_request_ext(priv, &scan);
6016 if (err) {
6017 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006018 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006019 }
6020
6021 priv->status |= STATUS_SCANNING;
6022 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006023 queue_delayed_work(priv->workqueue, &priv->scan_check,
6024 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006025 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05006026 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05006027 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006028}
6029
6030static void ipw_bg_abort_scan(void *data)
6031{
6032 struct ipw_priv *priv = data;
6033 down(&priv->sem);
6034 ipw_abort_scan(data);
6035 up(&priv->sem);
6036}
6037
James Ketrenosafbf30a2005-08-25 00:05:33 -05006038#if WIRELESS_EXT < 18
6039/* Support for wpa_supplicant before WE-18, deprecated. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006040
6041/* following definitions must match definitions in driver_ipw.c */
6042
6043#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
6044
6045#define IPW_CMD_SET_WPA_PARAM 1
6046#define IPW_CMD_SET_WPA_IE 2
6047#define IPW_CMD_SET_ENCRYPTION 3
6048#define IPW_CMD_MLME 4
6049
6050#define IPW_PARAM_WPA_ENABLED 1
6051#define IPW_PARAM_TKIP_COUNTERMEASURES 2
6052#define IPW_PARAM_DROP_UNENCRYPTED 3
6053#define IPW_PARAM_PRIVACY_INVOKED 4
6054#define IPW_PARAM_AUTH_ALGS 5
6055#define IPW_PARAM_IEEE_802_1X 6
6056
6057#define IPW_MLME_STA_DEAUTH 1
6058#define IPW_MLME_STA_DISASSOC 2
6059
6060#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
6061#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
6062#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
6063#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
6064#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
6065#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
6066
6067#define IPW_CRYPT_ALG_NAME_LEN 16
6068
6069struct ipw_param {
6070 u32 cmd;
6071 u8 sta_addr[ETH_ALEN];
6072 union {
6073 struct {
6074 u8 name;
6075 u32 value;
6076 } wpa_param;
6077 struct {
6078 u32 len;
James Ketrenosb095c382005-08-24 22:04:42 -05006079 u8 reserved[32];
6080 u8 data[0];
James Ketrenosea2b26e2005-08-24 21:25:16 -05006081 } wpa_ie;
6082 struct {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006083 u32 command;
6084 u32 reason_code;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006085 } mlme;
6086 struct {
6087 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
6088 u8 set_tx;
6089 u32 err;
6090 u8 idx;
6091 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
6092 u16 key_len;
6093 u8 key[0];
6094 } crypt;
6095
6096 } u;
6097};
6098
6099/* end of driver_ipw.c code */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006100#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006101
6102static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6103{
James Ketrenosb095c382005-08-24 22:04:42 -05006104 /* This is called when wpa_supplicant loads and closes the driver
6105 * interface. */
6106 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006107}
6108
James Ketrenosafbf30a2005-08-25 00:05:33 -05006109#if WIRELESS_EXT < 18
6110#define IW_AUTH_ALG_OPEN_SYSTEM 0x1
6111#define IW_AUTH_ALG_SHARED_KEY 0x2
6112#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006113
6114static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6115{
6116 struct ieee80211_device *ieee = priv->ieee;
6117 struct ieee80211_security sec = {
6118 .flags = SEC_AUTH_MODE,
6119 };
6120 int ret = 0;
6121
James Ketrenosafbf30a2005-08-25 00:05:33 -05006122 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006123 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6124 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006125 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006126 sec.auth_mode = WLAN_AUTH_OPEN;
6127 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006128 } else
6129 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006130
6131 if (ieee->set_security)
6132 ieee->set_security(ieee->dev, &sec);
6133 else
6134 ret = -EOPNOTSUPP;
6135
6136 return ret;
6137}
6138
James Ketrenosafbf30a2005-08-25 00:05:33 -05006139void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6140{
6141 /* make sure WPA is enabled */
6142 ipw_wpa_enable(priv, 1);
6143
6144 ipw_disassociate(priv);
6145}
6146
6147static int ipw_set_rsn_capa(struct ipw_priv *priv,
6148 char *capabilities, int length)
6149{
6150 struct host_cmd cmd = {
6151 .cmd = IPW_CMD_RSN_CAPABILITIES,
6152 .len = length,
6153 };
6154
6155 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6156
6157 memcpy(cmd.param, capabilities, length);
6158 if (ipw_send_cmd(priv, &cmd)) {
6159 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
6160 return -1;
6161 }
6162 return 0;
6163}
6164
6165#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -05006166static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
6167{
6168 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05006169 struct ieee80211_crypt_data *crypt;
6170 unsigned long flags;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006171 int ret = 0;
6172
6173 switch (name) {
6174 case IPW_PARAM_WPA_ENABLED:
6175 ret = ipw_wpa_enable(priv, value);
6176 break;
6177
6178 case IPW_PARAM_TKIP_COUNTERMEASURES:
James Ketrenosa613bff2005-08-24 21:43:11 -05006179 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6180 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6181 IPW_WARNING("Can't set TKIP countermeasures: "
6182 "crypt not set!\n");
6183 break;
6184 }
6185
6186 flags = crypt->ops->get_flags(crypt->priv);
6187
6188 if (value)
6189 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6190 else
6191 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6192
6193 crypt->ops->set_flags(flags, crypt->priv);
6194
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195 break;
6196
James Ketrenosb095c382005-08-24 22:04:42 -05006197 case IPW_PARAM_DROP_UNENCRYPTED:{
6198 /* HACK:
6199 *
6200 * wpa_supplicant calls set_wpa_enabled when the driver
6201 * is loaded and unloaded, regardless of if WPA is being
6202 * used. No other calls are made which can be used to
6203 * determine if encryption will be used or not prior to
6204 * association being expected. If encryption is not being
6205 * used, drop_unencrypted is set to false, else true -- we
6206 * can use this to determine if the CAP_PRIVACY_ON bit should
6207 * be set.
6208 */
6209 struct ieee80211_security sec = {
6210 .flags = SEC_ENABLED,
6211 .enabled = value,
6212 };
6213 priv->ieee->drop_unencrypted = value;
6214 /* We only change SEC_LEVEL for open mode. Others
6215 * are set by ipw_wpa_set_encryption.
6216 */
6217 if (!value) {
6218 sec.flags |= SEC_LEVEL;
6219 sec.level = SEC_LEVEL_0;
6220 } else {
6221 sec.flags |= SEC_LEVEL;
6222 sec.level = SEC_LEVEL_1;
6223 }
6224 if (priv->ieee->set_security)
6225 priv->ieee->set_security(priv->ieee->dev, &sec);
6226 break;
6227 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05006228
6229 case IPW_PARAM_PRIVACY_INVOKED:
6230 priv->ieee->privacy_invoked = value;
6231 break;
6232
6233 case IPW_PARAM_AUTH_ALGS:
6234 ret = ipw_wpa_set_auth_algs(priv, value);
6235 break;
6236
6237 case IPW_PARAM_IEEE_802_1X:
6238 priv->ieee->ieee802_1x = value;
6239 break;
6240
6241 default:
6242 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
6243 ret = -EOPNOTSUPP;
6244 }
6245
6246 return ret;
6247}
6248
6249static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
6250{
6251 struct ipw_priv *priv = ieee80211_priv(dev);
6252 int ret = 0;
6253
6254 switch (command) {
6255 case IPW_MLME_STA_DEAUTH:
6256 // silently ignore
6257 break;
6258
6259 case IPW_MLME_STA_DISASSOC:
6260 ipw_disassociate(priv);
6261 break;
6262
6263 default:
6264 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
6265 ret = -EOPNOTSUPP;
6266 }
6267
6268 return ret;
6269}
6270
Zhu Yi1fbfea52005-08-05 17:22:56 +08006271static int ipw_wpa_ie_cipher2level(u8 cipher)
6272{
6273 switch (cipher) {
6274 case 4: /* CCMP */
6275 return SEC_LEVEL_3;
6276 case 2: /* TKIP */
6277 return SEC_LEVEL_2;
6278 case 5: /* WEP104 */
6279 case 1: /* WEP40 */
6280 return SEC_LEVEL_1;
6281 case 0: /* NONE */
6282 return SEC_LEVEL_0;
6283 default:
6284 return -1;
6285 }
6286}
6287
James Ketrenosea2b26e2005-08-24 21:25:16 -05006288static int ipw_wpa_set_wpa_ie(struct net_device *dev,
6289 struct ipw_param *param, int plen)
6290{
6291 struct ipw_priv *priv = ieee80211_priv(dev);
6292 struct ieee80211_device *ieee = priv->ieee;
6293 u8 *buf;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006294 u8 *ptk, *gtk;
6295 int level;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006296
James Ketrenosea2b26e2005-08-24 21:25:16 -05006297 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
6298 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
6299 return -EINVAL;
6300
6301 if (param->u.wpa_ie.len) {
6302 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
6303 if (buf == NULL)
6304 return -ENOMEM;
6305
6306 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
6307 kfree(ieee->wpa_ie);
6308 ieee->wpa_ie = buf;
6309 ieee->wpa_ie_len = param->u.wpa_ie.len;
6310 } else {
6311 kfree(ieee->wpa_ie);
6312 ieee->wpa_ie = NULL;
6313 ieee->wpa_ie_len = 0;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006314 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006315 }
6316
Zhu Yi1fbfea52005-08-05 17:22:56 +08006317 if (priv->ieee->host_encrypt)
6318 goto done;
6319
6320 /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
6321 * we need to change driver_ipw.c from wpa_supplicant. This
6322 * is OK since -Dipw is deprecated. The -Dwext driver has a
6323 * clean way to handle this. */
6324 gtk = ptk = (u8 *) ieee->wpa_ie;
6325 if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
6326 gtk += 4 + 3;
6327 ptk += 4 + 4 + 2 + 3;
6328 } else { /* WPA IE */
6329 gtk += 8 + 3;
6330 ptk += 8 + 4 + 2 + 3;
6331 }
6332
6333 if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
6334 return -EINVAL;
6335
6336 level = ipw_wpa_ie_cipher2level(*gtk);
6337 ipw_set_hw_decrypt_multicast(priv, level);
6338
6339 level = ipw_wpa_ie_cipher2level(*ptk);
6340 ipw_set_hw_decrypt_unicast(priv, level);
6341
6342 done:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006343 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6344 return 0;
6345}
6346
6347/* implementation borrowed from hostap driver */
6348
6349static int ipw_wpa_set_encryption(struct net_device *dev,
6350 struct ipw_param *param, int param_len)
6351{
6352 int ret = 0;
6353 struct ipw_priv *priv = ieee80211_priv(dev);
6354 struct ieee80211_device *ieee = priv->ieee;
6355 struct ieee80211_crypto_ops *ops;
6356 struct ieee80211_crypt_data **crypt;
6357
6358 struct ieee80211_security sec = {
6359 .flags = 0,
6360 };
6361
6362 param->u.crypt.err = 0;
6363 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
6364
6365 if (param_len !=
6366 (int)((char *)param->u.crypt.key - (char *)param) +
6367 param->u.crypt.key_len) {
6368 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
6369 param->u.crypt.key_len);
6370 return -EINVAL;
6371 }
6372 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6373 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6374 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6375 if (param->u.crypt.idx >= WEP_KEYS)
6376 return -EINVAL;
6377 crypt = &ieee->crypt[param->u.crypt.idx];
6378 } else {
6379 return -EINVAL;
6380 }
6381
James Ketrenosafbf30a2005-08-25 00:05:33 -05006382 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006383 if (strcmp(param->u.crypt.alg, "none") == 0) {
6384 if (crypt) {
6385 sec.enabled = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006386 sec.encrypt = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006387 sec.level = SEC_LEVEL_0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006388 sec.flags |= SEC_LEVEL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006389 ieee80211_crypt_delayed_deinit(ieee, crypt);
6390 }
6391 goto done;
6392 }
6393 sec.enabled = 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006394 sec.encrypt = 1;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395
James Ketrenosb095c382005-08-24 22:04:42 -05006396 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006397 if (strcmp(param->u.crypt.alg, "TKIP") == 0)
6398 ieee->host_encrypt_msdu = 1;
6399
6400 if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
6401 ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05006402 goto skip_host_crypt;
6403
James Ketrenosea2b26e2005-08-24 21:25:16 -05006404 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6405 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6406 request_module("ieee80211_crypt_wep");
6407 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6408 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6409 request_module("ieee80211_crypt_tkip");
6410 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6411 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6412 request_module("ieee80211_crypt_ccmp");
6413 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6414 }
6415 if (ops == NULL) {
6416 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6417 dev->name, param->u.crypt.alg);
6418 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
6419 ret = -EINVAL;
6420 goto done;
6421 }
6422
6423 if (*crypt == NULL || (*crypt)->ops != ops) {
6424 struct ieee80211_crypt_data *new_crypt;
6425
6426 ieee80211_crypt_delayed_deinit(ieee, crypt);
6427
6428 new_crypt = (struct ieee80211_crypt_data *)
6429 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
6430 if (new_crypt == NULL) {
6431 ret = -ENOMEM;
6432 goto done;
6433 }
6434 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6435 new_crypt->ops = ops;
6436 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6437 new_crypt->priv =
6438 new_crypt->ops->init(param->u.crypt.idx);
6439
6440 if (new_crypt->priv == NULL) {
6441 kfree(new_crypt);
6442 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
6443 ret = -EINVAL;
6444 goto done;
6445 }
6446
6447 *crypt = new_crypt;
6448 }
6449
6450 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6451 (*crypt)->ops->set_key(param->u.crypt.key,
6452 param->u.crypt.key_len, param->u.crypt.seq,
6453 (*crypt)->priv) < 0) {
6454 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
6455 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
6456 ret = -EINVAL;
6457 goto done;
6458 }
6459
James Ketrenosb095c382005-08-24 22:04:42 -05006460 skip_host_crypt:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006461 if (param->u.crypt.set_tx) {
6462 ieee->tx_keyidx = param->u.crypt.idx;
6463 sec.active_key = param->u.crypt.idx;
6464 sec.flags |= SEC_ACTIVE_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05006465 } else
6466 sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006467
James Ketrenosb095c382005-08-24 22:04:42 -05006468 if (param->u.crypt.alg != NULL) {
6469 memcpy(sec.keys[param->u.crypt.idx],
6470 param->u.crypt.key, param->u.crypt.key_len);
6471 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6472 sec.flags |= (1 << param->u.crypt.idx);
6473
6474 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006475 sec.flags |= SEC_LEVEL;
6476 sec.level = SEC_LEVEL_1;
James Ketrenosb095c382005-08-24 22:04:42 -05006477 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006478 sec.flags |= SEC_LEVEL;
6479 sec.level = SEC_LEVEL_2;
James Ketrenosb095c382005-08-24 22:04:42 -05006480 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006481 sec.flags |= SEC_LEVEL;
6482 sec.level = SEC_LEVEL_3;
6483 }
6484 }
6485 done:
6486 if (ieee->set_security)
6487 ieee->set_security(ieee->dev, &sec);
6488
6489 /* Do not reset port if card is in Managed mode since resetting will
6490 * generate new IEEE 802.11 authentication which may end up in looping
6491 * with IEEE 802.1X. If your hardware requires a reset after WEP
6492 * configuration (for example... Prism2), implement the reset_port in
6493 * the callbacks structures used to initialize the 802.11 stack. */
6494 if (ieee->reset_on_keychange &&
6495 ieee->iw_mode != IW_MODE_INFRA &&
6496 ieee->reset_port && ieee->reset_port(dev)) {
6497 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6498 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
6499 return -EINVAL;
6500 }
6501
6502 return ret;
6503}
6504
6505static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
6506{
6507 struct ipw_param *param;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006508 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006509 int ret = 0;
6510
6511 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
6512
6513 if (p->length < sizeof(struct ipw_param) || !p->pointer)
6514 return -EINVAL;
6515
6516 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
6517 if (param == NULL)
6518 return -ENOMEM;
6519
6520 if (copy_from_user(param, p->pointer, p->length)) {
6521 kfree(param);
6522 return -EFAULT;
6523 }
6524
James Ketrenosafbf30a2005-08-25 00:05:33 -05006525 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006526 switch (param->cmd) {
6527
6528 case IPW_CMD_SET_WPA_PARAM:
6529 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
6530 param->u.wpa_param.value);
6531 break;
6532
6533 case IPW_CMD_SET_WPA_IE:
6534 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
6535 break;
6536
6537 case IPW_CMD_SET_ENCRYPTION:
6538 ret = ipw_wpa_set_encryption(dev, param, p->length);
6539 break;
6540
6541 case IPW_CMD_MLME:
6542 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
6543 param->u.mlme.reason_code);
6544 break;
6545
6546 default:
6547 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6548 dev->name, param->cmd);
6549 ret = -EOPNOTSUPP;
6550 }
6551
James Ketrenosafbf30a2005-08-25 00:05:33 -05006552 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006553 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6554 ret = -EFAULT;
6555
6556 kfree(param);
6557 return ret;
6558}
James Ketrenosafbf30a2005-08-25 00:05:33 -05006559#else
6560/*
6561 * WE-18 support
6562 */
6563
6564/* SIOCSIWGENIE */
6565static int ipw_wx_set_genie(struct net_device *dev,
6566 struct iw_request_info *info,
6567 union iwreq_data *wrqu, char *extra)
6568{
6569 struct ipw_priv *priv = ieee80211_priv(dev);
6570 struct ieee80211_device *ieee = priv->ieee;
6571 u8 *buf;
6572 int err = 0;
6573
6574 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6575 (wrqu->data.length && extra == NULL))
6576 return -EINVAL;
6577
6578 //down(&priv->sem);
6579
6580 //if (!ieee->wpa_enabled) {
6581 // err = -EOPNOTSUPP;
6582 // goto out;
6583 //}
6584
6585 if (wrqu->data.length) {
6586 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6587 if (buf == NULL) {
6588 err = -ENOMEM;
6589 goto out;
6590 }
6591
6592 memcpy(buf, extra, wrqu->data.length);
6593 kfree(ieee->wpa_ie);
6594 ieee->wpa_ie = buf;
6595 ieee->wpa_ie_len = wrqu->data.length;
6596 } else {
6597 kfree(ieee->wpa_ie);
6598 ieee->wpa_ie = NULL;
6599 ieee->wpa_ie_len = 0;
6600 }
6601
6602 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6603 out:
6604 //up(&priv->sem);
6605 return err;
6606}
6607
6608/* SIOCGIWGENIE */
6609static int ipw_wx_get_genie(struct net_device *dev,
6610 struct iw_request_info *info,
6611 union iwreq_data *wrqu, char *extra)
6612{
6613 struct ipw_priv *priv = ieee80211_priv(dev);
6614 struct ieee80211_device *ieee = priv->ieee;
6615 int err = 0;
6616
6617 //down(&priv->sem);
6618
6619 //if (!ieee->wpa_enabled) {
6620 // err = -EOPNOTSUPP;
6621 // goto out;
6622 //}
6623
6624 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6625 wrqu->data.length = 0;
6626 goto out;
6627 }
6628
6629 if (wrqu->data.length < ieee->wpa_ie_len) {
6630 err = -E2BIG;
6631 goto out;
6632 }
6633
6634 wrqu->data.length = ieee->wpa_ie_len;
6635 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6636
6637 out:
6638 //up(&priv->sem);
6639 return err;
6640}
6641
Zhu Yi1fbfea52005-08-05 17:22:56 +08006642static int wext_cipher2level(int cipher)
6643{
6644 switch (cipher) {
6645 case IW_AUTH_CIPHER_NONE:
6646 return SEC_LEVEL_0;
6647 case IW_AUTH_CIPHER_WEP40:
6648 case IW_AUTH_CIPHER_WEP104:
6649 return SEC_LEVEL_1;
6650 case IW_AUTH_CIPHER_TKIP:
6651 return SEC_LEVEL_2;
6652 case IW_AUTH_CIPHER_CCMP:
6653 return SEC_LEVEL_3;
6654 default:
6655 return -1;
6656 }
6657}
6658
James Ketrenosafbf30a2005-08-25 00:05:33 -05006659/* SIOCSIWAUTH */
6660static int ipw_wx_set_auth(struct net_device *dev,
6661 struct iw_request_info *info,
6662 union iwreq_data *wrqu, char *extra)
6663{
6664 struct ipw_priv *priv = ieee80211_priv(dev);
6665 struct ieee80211_device *ieee = priv->ieee;
6666 struct iw_param *param = &wrqu->param;
6667 struct ieee80211_crypt_data *crypt;
6668 unsigned long flags;
6669 int ret = 0;
6670
6671 switch (param->flags & IW_AUTH_INDEX) {
6672 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006673 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006674 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006675 ipw_set_hw_decrypt_unicast(priv,
6676 wext_cipher2level(param->value));
6677 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006678 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006679 ipw_set_hw_decrypt_multicast(priv,
6680 wext_cipher2level(param->value));
6681 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006682 case IW_AUTH_KEY_MGMT:
6683 /*
6684 * ipw2200 does not use these parameters
6685 */
6686 break;
6687
6688 case IW_AUTH_TKIP_COUNTERMEASURES:
6689 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6690 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6691 IPW_WARNING("Can't set TKIP countermeasures: "
6692 "crypt not set!\n");
6693 break;
6694 }
6695
6696 flags = crypt->ops->get_flags(crypt->priv);
6697
6698 if (param->value)
6699 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6700 else
6701 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6702
6703 crypt->ops->set_flags(flags, crypt->priv);
6704
6705 break;
6706
6707 case IW_AUTH_DROP_UNENCRYPTED:{
6708 /* HACK:
6709 *
6710 * wpa_supplicant calls set_wpa_enabled when the driver
6711 * is loaded and unloaded, regardless of if WPA is being
6712 * used. No other calls are made which can be used to
6713 * determine if encryption will be used or not prior to
6714 * association being expected. If encryption is not being
6715 * used, drop_unencrypted is set to false, else true -- we
6716 * can use this to determine if the CAP_PRIVACY_ON bit should
6717 * be set.
6718 */
6719 struct ieee80211_security sec = {
6720 .flags = SEC_ENABLED,
6721 .enabled = param->value,
6722 };
6723 priv->ieee->drop_unencrypted = param->value;
6724 /* We only change SEC_LEVEL for open mode. Others
6725 * are set by ipw_wpa_set_encryption.
6726 */
6727 if (!param->value) {
6728 sec.flags |= SEC_LEVEL;
6729 sec.level = SEC_LEVEL_0;
6730 } else {
6731 sec.flags |= SEC_LEVEL;
6732 sec.level = SEC_LEVEL_1;
6733 }
6734 if (priv->ieee->set_security)
6735 priv->ieee->set_security(priv->ieee->dev, &sec);
6736 break;
6737 }
6738
6739 case IW_AUTH_80211_AUTH_ALG:
6740 ret = ipw_wpa_set_auth_algs(priv, param->value);
6741 break;
6742
6743 case IW_AUTH_WPA_ENABLED:
6744 ret = ipw_wpa_enable(priv, param->value);
6745 break;
6746
6747 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6748 ieee->ieee802_1x = param->value;
6749 break;
6750
6751 //case IW_AUTH_ROAMING_CONTROL:
6752 case IW_AUTH_PRIVACY_INVOKED:
6753 ieee->privacy_invoked = param->value;
6754 break;
6755
6756 default:
6757 return -EOPNOTSUPP;
6758 }
6759 return ret;
6760}
6761
6762/* SIOCGIWAUTH */
6763static int ipw_wx_get_auth(struct net_device *dev,
6764 struct iw_request_info *info,
6765 union iwreq_data *wrqu, char *extra)
6766{
6767 struct ipw_priv *priv = ieee80211_priv(dev);
6768 struct ieee80211_device *ieee = priv->ieee;
6769 struct ieee80211_crypt_data *crypt;
6770 struct iw_param *param = &wrqu->param;
6771 int ret = 0;
6772
6773 switch (param->flags & IW_AUTH_INDEX) {
6774 case IW_AUTH_WPA_VERSION:
6775 case IW_AUTH_CIPHER_PAIRWISE:
6776 case IW_AUTH_CIPHER_GROUP:
6777 case IW_AUTH_KEY_MGMT:
6778 /*
6779 * wpa_supplicant will control these internally
6780 */
6781 ret = -EOPNOTSUPP;
6782 break;
6783
6784 case IW_AUTH_TKIP_COUNTERMEASURES:
6785 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6786 if (!crypt || !crypt->ops->get_flags) {
6787 IPW_WARNING("Can't get TKIP countermeasures: "
6788 "crypt not set!\n");
6789 break;
6790 }
6791
6792 param->value = (crypt->ops->get_flags(crypt->priv) &
6793 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6794
6795 break;
6796
6797 case IW_AUTH_DROP_UNENCRYPTED:
6798 param->value = ieee->drop_unencrypted;
6799 break;
6800
6801 case IW_AUTH_80211_AUTH_ALG:
6802 param->value = ieee->sec.auth_mode;
6803 break;
6804
6805 case IW_AUTH_WPA_ENABLED:
6806 param->value = ieee->wpa_enabled;
6807 break;
6808
6809 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6810 param->value = ieee->ieee802_1x;
6811 break;
6812
6813 case IW_AUTH_ROAMING_CONTROL:
6814 case IW_AUTH_PRIVACY_INVOKED:
6815 param->value = ieee->privacy_invoked;
6816 break;
6817
6818 default:
6819 return -EOPNOTSUPP;
6820 }
6821 return 0;
6822}
6823
6824/* SIOCSIWENCODEEXT */
6825static int ipw_wx_set_encodeext(struct net_device *dev,
6826 struct iw_request_info *info,
6827 union iwreq_data *wrqu, char *extra)
6828{
6829 struct ipw_priv *priv = ieee80211_priv(dev);
6830 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6831
6832 if (hwcrypto) {
6833 /* IPW HW can't build TKIP MIC, host decryption still needed */
6834 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6835 priv->ieee->host_encrypt = 0;
6836 priv->ieee->host_encrypt_msdu = 1;
6837 priv->ieee->host_decrypt = 1;
6838 } else {
6839 priv->ieee->host_encrypt = 0;
6840 priv->ieee->host_encrypt_msdu = 0;
6841 priv->ieee->host_decrypt = 0;
6842 }
6843 }
6844
6845 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6846}
6847
6848/* SIOCGIWENCODEEXT */
6849static int ipw_wx_get_encodeext(struct net_device *dev,
6850 struct iw_request_info *info,
6851 union iwreq_data *wrqu, char *extra)
6852{
6853 struct ipw_priv *priv = ieee80211_priv(dev);
6854 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6855}
6856
6857/* SIOCSIWMLME */
6858static int ipw_wx_set_mlme(struct net_device *dev,
6859 struct iw_request_info *info,
6860 union iwreq_data *wrqu, char *extra)
6861{
6862 struct ipw_priv *priv = ieee80211_priv(dev);
6863 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6864 u16 reason;
6865
6866 reason = cpu_to_le16(mlme->reason_code);
6867
6868 switch (mlme->cmd) {
6869 case IW_MLME_DEAUTH:
6870 // silently ignore
6871 break;
6872
6873 case IW_MLME_DISASSOC:
6874 ipw_disassociate(priv);
6875 break;
6876
6877 default:
6878 return -EOPNOTSUPP;
6879 }
6880 return 0;
6881}
6882#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006883
James Ketrenosb095c382005-08-24 22:04:42 -05006884#ifdef CONFIG_IPW_QOS
6885
6886/* QoS */
6887/*
6888* get the modulation type of the current network or
6889* the card current mode
6890*/
6891u8 ipw_qos_current_mode(struct ipw_priv * priv)
6892{
6893 u8 mode = 0;
6894
6895 if (priv->status & STATUS_ASSOCIATED) {
6896 unsigned long flags;
6897
6898 spin_lock_irqsave(&priv->ieee->lock, flags);
6899 mode = priv->assoc_network->mode;
6900 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6901 } else {
6902 mode = priv->ieee->mode;
6903 }
6904 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6905 return mode;
6906}
6907
6908/*
6909* Handle management frame beacon and probe response
6910*/
6911static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
6912 int active_network,
6913 struct ieee80211_network *network)
6914{
6915 u32 size = sizeof(struct ieee80211_qos_parameters);
6916
James Ketrenosafbf30a2005-08-25 00:05:33 -05006917 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006918 network->qos_data.active = network->qos_data.supported;
6919
6920 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006921 if (active_network &&
6922 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006923 network->qos_data.active = network->qos_data.supported;
6924
6925 if ((network->qos_data.active == 1) && (active_network == 1) &&
6926 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6927 (network->qos_data.old_param_count !=
6928 network->qos_data.param_count)) {
6929 network->qos_data.old_param_count =
6930 network->qos_data.param_count;
6931 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006932 IPW_DEBUG_QOS("QoS parameters change call "
6933 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006934 }
6935 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006936 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6937 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006938 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006939 else
6940 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006941 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006942
James Ketrenosb095c382005-08-24 22:04:42 -05006943 if ((network->qos_data.active == 1) && (active_network == 1)) {
6944 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6945 schedule_work(&priv->qos_activate);
6946 }
6947
6948 network->qos_data.active = 0;
6949 network->qos_data.supported = 0;
6950 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006951 if ((priv->status & STATUS_ASSOCIATED) &&
6952 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6953 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6954 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6955 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006956 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006957 priv->assoc_network->ssid_len) &&
6958 !memcmp(network->ssid,
6959 priv->assoc_network->ssid,
6960 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006961 queue_work(priv->workqueue,
6962 &priv->merge_networks);
6963 }
James Ketrenosb095c382005-08-24 22:04:42 -05006964 }
6965
6966 return 0;
6967}
6968
6969/*
6970* This function set up the firmware to support QoS. It sends
6971* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6972*/
6973static int ipw_qos_activate(struct ipw_priv *priv,
6974 struct ieee80211_qos_data *qos_network_data)
6975{
6976 int err;
6977 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6978 struct ieee80211_qos_parameters *active_one = NULL;
6979 u32 size = sizeof(struct ieee80211_qos_parameters);
6980 u32 burst_duration;
6981 int i;
6982 u8 type;
6983
6984 type = ipw_qos_current_mode(priv);
6985
6986 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6987 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6988 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6989 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6990
6991 if (qos_network_data == NULL) {
6992 if (type == IEEE_B) {
6993 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6994 active_one = &def_parameters_CCK;
6995 } else
6996 active_one = &def_parameters_OFDM;
6997
James Ketrenosafbf30a2005-08-25 00:05:33 -05006998 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006999 burst_duration = ipw_qos_get_burst_duration(priv);
7000 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05007001 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
7002 (u16) burst_duration;
7003 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05007004 if (type == IEEE_B) {
7005 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7006 type);
7007 if (priv->qos_data.qos_enable == 0)
7008 active_one = &def_parameters_CCK;
7009 else
7010 active_one = priv->qos_data.def_qos_parm_CCK;
7011 } else {
7012 if (priv->qos_data.qos_enable == 0)
7013 active_one = &def_parameters_OFDM;
7014 else
7015 active_one = priv->qos_data.def_qos_parm_OFDM;
7016 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05007017 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007018 } else {
7019 unsigned long flags;
7020 int active;
7021
7022 spin_lock_irqsave(&priv->ieee->lock, flags);
7023 active_one = &(qos_network_data->parameters);
7024 qos_network_data->old_param_count =
7025 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007026 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007027 active = qos_network_data->supported;
7028 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7029
7030 if (active == 0) {
7031 burst_duration = ipw_qos_get_burst_duration(priv);
7032 for (i = 0; i < QOS_QUEUE_NUM; i++)
7033 qos_parameters[QOS_PARAM_SET_ACTIVE].
7034 tx_op_limit[i] = (u16) burst_duration;
7035 }
7036 }
7037
7038 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05007039 err = ipw_send_qos_params_command(priv,
7040 (struct ieee80211_qos_parameters *)
7041 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05007042 if (err)
7043 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7044
7045 return err;
7046}
7047
7048/*
7049* send IPW_CMD_WME_INFO to the firmware
7050*/
7051static int ipw_qos_set_info_element(struct ipw_priv *priv)
7052{
7053 int ret = 0;
7054 struct ieee80211_qos_information_element qos_info;
7055
7056 if (priv == NULL)
7057 return -1;
7058
7059 qos_info.elementID = QOS_ELEMENT_ID;
7060 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
7061
7062 qos_info.version = QOS_VERSION_1;
7063 qos_info.ac_info = 0;
7064
7065 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7066 qos_info.qui_type = QOS_OUI_TYPE;
7067 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7068
7069 ret = ipw_send_qos_info_command(priv, &qos_info);
7070 if (ret != 0) {
7071 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7072 }
7073 return ret;
7074}
7075
7076/*
7077* Set the QoS parameter with the association request structure
7078*/
7079static int ipw_qos_association(struct ipw_priv *priv,
7080 struct ieee80211_network *network)
7081{
7082 int err = 0;
7083 struct ieee80211_qos_data *qos_data = NULL;
7084 struct ieee80211_qos_data ibss_data = {
7085 .supported = 1,
7086 .active = 1,
7087 };
7088
7089 switch (priv->ieee->iw_mode) {
7090 case IW_MODE_ADHOC:
7091 if (!(network->capability & WLAN_CAPABILITY_IBSS))
7092 BUG();
7093
7094 qos_data = &ibss_data;
7095 break;
7096
7097 case IW_MODE_INFRA:
7098 qos_data = &network->qos_data;
7099 break;
7100
7101 default:
7102 BUG();
7103 break;
7104 }
7105
7106 err = ipw_qos_activate(priv, qos_data);
7107 if (err) {
7108 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7109 return err;
7110 }
7111
7112 if (priv->qos_data.qos_enable && qos_data->supported) {
7113 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7114 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7115 return ipw_qos_set_info_element(priv);
7116 }
7117
7118 return 0;
7119}
7120
7121/*
7122* handling the beaconing responces. if we get different QoS setting
7123* of the network from the the associated setting adjust the QoS
7124* setting
7125*/
7126static int ipw_qos_association_resp(struct ipw_priv *priv,
7127 struct ieee80211_network *network)
7128{
7129 int ret = 0;
7130 unsigned long flags;
7131 u32 size = sizeof(struct ieee80211_qos_parameters);
7132 int set_qos_param = 0;
7133
James Ketrenosafbf30a2005-08-25 00:05:33 -05007134 if ((priv == NULL) || (network == NULL) ||
7135 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007136 return ret;
7137
7138 if (!(priv->status & STATUS_ASSOCIATED))
7139 return ret;
7140
James Ketrenosafbf30a2005-08-25 00:05:33 -05007141 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007142 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007143
7144 spin_lock_irqsave(&priv->ieee->lock, flags);
7145 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007146 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05007147 sizeof(struct ieee80211_qos_data));
7148 priv->assoc_network->qos_data.active = 1;
7149 if ((network->qos_data.old_param_count !=
7150 network->qos_data.param_count)) {
7151 set_qos_param = 1;
7152 network->qos_data.old_param_count =
7153 network->qos_data.param_count;
7154 }
7155
7156 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007157 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7158 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007159 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007160 else
7161 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007162 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007163 priv->assoc_network->qos_data.active = 0;
7164 priv->assoc_network->qos_data.supported = 0;
7165 set_qos_param = 1;
7166 }
7167
7168 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7169
7170 if (set_qos_param == 1)
7171 schedule_work(&priv->qos_activate);
7172
7173 return ret;
7174}
7175
7176static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7177{
7178 u32 ret = 0;
7179
7180 if ((priv == NULL))
7181 return 0;
7182
James Ketrenosafbf30a2005-08-25 00:05:33 -05007183 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007184 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007185 else
James Ketrenosb095c382005-08-24 22:04:42 -05007186 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007187
James Ketrenosb095c382005-08-24 22:04:42 -05007188 return ret;
7189}
7190
7191/*
7192* Initialize the setting of QoS global
7193*/
7194static void ipw_qos_init(struct ipw_priv *priv, int enable,
7195 int burst_enable, u32 burst_duration_CCK,
7196 u32 burst_duration_OFDM)
7197{
7198 priv->qos_data.qos_enable = enable;
7199
7200 if (priv->qos_data.qos_enable) {
7201 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7202 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7203 IPW_DEBUG_QOS("QoS is enabled\n");
7204 } else {
7205 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7206 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7207 IPW_DEBUG_QOS("QoS is not enabled\n");
7208 }
7209
7210 priv->qos_data.burst_enable = burst_enable;
7211
7212 if (burst_enable) {
7213 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7214 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7215 } else {
7216 priv->qos_data.burst_duration_CCK = 0;
7217 priv->qos_data.burst_duration_OFDM = 0;
7218 }
7219}
7220
7221/*
7222* map the packet priority to the right TX Queue
7223*/
7224static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7225{
7226 if (priority > 7 || !priv->qos_data.qos_enable)
7227 priority = 0;
7228
7229 return from_priority_to_tx_queue[priority] - 1;
7230}
7231
7232/*
7233* add QoS parameter to the TX command
7234*/
7235static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7236 u16 priority,
7237 struct tfd_data *tfd, u8 unicast)
7238{
7239 int ret = 0;
7240 int tx_queue_id = 0;
7241 struct ieee80211_qos_data *qos_data = NULL;
7242 int active, supported;
7243 unsigned long flags;
7244
7245 if (!(priv->status & STATUS_ASSOCIATED))
7246 return 0;
7247
7248 qos_data = &priv->assoc_network->qos_data;
7249
7250 spin_lock_irqsave(&priv->ieee->lock, flags);
7251
7252 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7253 if (unicast == 0)
7254 qos_data->active = 0;
7255 else
7256 qos_data->active = qos_data->supported;
7257 }
7258
7259 active = qos_data->active;
7260 supported = qos_data->supported;
7261
7262 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7263
James Ketrenosafbf30a2005-08-25 00:05:33 -05007264 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7265 "unicast %d\n",
7266 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05007267 if (active && priv->qos_data.qos_enable) {
7268 ret = from_priority_to_tx_queue[priority];
7269 tx_queue_id = ret - 1;
7270 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
7271 if (priority <= 7) {
7272 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7273 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
7274 tfd->tfd.tfd_26.mchdr.frame_ctl |=
7275 IEEE80211_STYPE_QOS_DATA;
7276
7277 if (priv->qos_data.qos_no_ack_mask &
7278 (1UL << tx_queue_id)) {
7279 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7280 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
7281 CTRL_QOS_NO_ACK;
7282 }
7283 }
7284 }
7285
7286 return ret;
7287}
7288
7289/*
7290* background support to run QoS activate functionality
7291*/
7292static void ipw_bg_qos_activate(void *data)
7293{
7294 struct ipw_priv *priv = data;
7295
7296 if (priv == NULL)
7297 return;
7298
7299 down(&priv->sem);
7300
7301 if (priv->status & STATUS_ASSOCIATED)
7302 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7303
7304 up(&priv->sem);
7305}
7306
7307/*
7308* Handler for probe responce and beacon frame
7309*/
James Ketrenos2b184d52005-08-03 20:33:14 -05007310static int ipw_handle_management(struct net_device *dev,
7311 struct ieee80211_network *network, u16 type)
James Ketrenosb095c382005-08-24 22:04:42 -05007312{
7313 struct ipw_priv *priv = ieee80211_priv(dev);
7314 int active_network;
7315
7316 if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
7317 active_network = 1;
7318 else
7319 active_network = 0;
7320
7321 switch (type) {
7322 case IEEE80211_STYPE_PROBE_RESP:
7323 case IEEE80211_STYPE_BEACON:
7324 ipw_qos_handle_probe_reponse(priv, active_network, network);
7325 break;
7326 case IEEE80211_STYPE_ASSOC_RESP:
7327 ipw_qos_association_resp(priv, network);
7328 break;
7329 default:
7330 break;
7331 }
7332
7333 return 0;
7334}
7335
7336static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7337 *qos_param)
7338{
7339 struct host_cmd cmd = {
7340 .cmd = IPW_CMD_QOS_PARAMETERS,
7341 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7342 };
7343
7344 if (!priv || !qos_param) {
7345 IPW_ERROR("Invalid args\n");
7346 return -1;
7347 }
7348
James Ketrenosafbf30a2005-08-25 00:05:33 -05007349 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenosb095c382005-08-24 22:04:42 -05007350 if (ipw_send_cmd(priv, &cmd)) {
7351 IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
7352 return -1;
7353 }
7354
7355 return 0;
7356}
7357
7358static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7359 *qos_param)
7360{
7361 struct host_cmd cmd = {
7362 .cmd = IPW_CMD_WME_INFO,
7363 .len = sizeof(*qos_param)
7364 };
7365
7366 if (!priv || !qos_param) {
7367 IPW_ERROR("Invalid args\n");
7368 return -1;
7369 }
7370
James Ketrenosafbf30a2005-08-25 00:05:33 -05007371 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenosb095c382005-08-24 22:04:42 -05007372 if (ipw_send_cmd(priv, &cmd)) {
7373 IPW_ERROR("failed to send CMD_QOS_INFO command\n");
7374 return -1;
7375 }
7376
7377 return 0;
7378}
7379
7380#endif /* CONFIG_IPW_QOS */
7381
James Ketrenos43f66a62005-03-25 12:31:53 -06007382static int ipw_associate_network(struct ipw_priv *priv,
7383 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007384 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007385{
7386 int err;
7387
7388 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007389 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007390
7391 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007392 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007393 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007394 memcpy(priv->essid, network->ssid, priv->essid_len);
7395 }
7396
7397 network->last_associate = jiffies;
7398
7399 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7400 priv->assoc_request.channel = network->channel;
7401 if ((priv->capability & CAP_PRIVACY_ON) &&
7402 (priv->capability & CAP_SHARED_KEY)) {
7403 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007404 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7405
7406 if ((priv->capability & CAP_PRIVACY_ON) &&
7407 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7408 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7409 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenos43f66a62005-03-25 12:31:53 -06007410 } else {
7411 priv->assoc_request.auth_type = AUTH_OPEN;
7412 priv->assoc_request.auth_key = 0;
7413 }
7414
James Ketrenosa613bff2005-08-24 21:43:11 -05007415 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007416 priv->assoc_request.policy_support = 0x02; /* RSN active */
7417 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7418 priv->ieee->wpa_ie_len);
7419 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05007420
Jeff Garzikbf794512005-07-31 13:07:26 -04007421 /*
7422 * It is valid for our ieee device to support multiple modes, but
7423 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007424 * just one mode.
7425 */
7426 if (network->mode & priv->ieee->mode & IEEE_A)
7427 priv->assoc_request.ieee_mode = IPW_A_MODE;
7428 else if (network->mode & priv->ieee->mode & IEEE_G)
7429 priv->assoc_request.ieee_mode = IPW_G_MODE;
7430 else if (network->mode & priv->ieee->mode & IEEE_B)
7431 priv->assoc_request.ieee_mode = IPW_B_MODE;
7432
James Ketrenosea2b26e2005-08-24 21:25:16 -05007433 priv->assoc_request.capability = network->capability;
7434 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7435 && !(priv->config & CFG_PREAMBLE_LONG)) {
7436 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7437 } else {
7438 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7439
7440 /* Clear the short preamble if we won't be supporting it */
7441 priv->assoc_request.capability &=
7442 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7443 }
7444
James Ketrenosafbf30a2005-08-25 00:05:33 -05007445 /* Clear capability bits that aren't used in Ad Hoc */
7446 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7447 priv->assoc_request.capability &=
7448 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7449
James Ketrenos43f66a62005-03-25 12:31:53 -06007450 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007451 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007452 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007453 escape_essid(priv->essid, priv->essid_len),
7454 network->channel,
7455 ipw_modes[priv->assoc_request.ieee_mode],
7456 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007457 (priv->assoc_request.preamble_length ==
7458 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7459 network->capability &
7460 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007461 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007462 priv->capability & CAP_PRIVACY_ON ?
7463 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 "(open)") : "",
7465 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007466 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007467 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007468 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007469
7470 priv->assoc_request.beacon_interval = network->beacon_interval;
7471 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007472 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007473 priv->assoc_request.assoc_type = HC_IBSS_START;
7474 priv->assoc_request.assoc_tsf_msw = 0;
7475 priv->assoc_request.assoc_tsf_lsw = 0;
7476 } else {
7477 if (unlikely(roaming))
7478 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7479 else
7480 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7481 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7482 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7483 }
7484
James Ketrenosafbf30a2005-08-25 00:05:33 -05007485 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007486
7487 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7488 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7489 priv->assoc_request.atim_window = network->atim_window;
7490 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007491 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007492 priv->assoc_request.atim_window = 0;
7493 }
7494
James Ketrenos43f66a62005-03-25 12:31:53 -06007495 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007496
James Ketrenos43f66a62005-03-25 12:31:53 -06007497 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7498 if (err) {
7499 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7500 return err;
7501 }
7502
7503 rates->ieee_mode = priv->assoc_request.ieee_mode;
7504 rates->purpose = IPW_RATE_CONNECT;
7505 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007506
James Ketrenos43f66a62005-03-25 12:31:53 -06007507 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7508 priv->sys_config.dot11g_auto_detection = 1;
7509 else
7510 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007511
7512 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7513 priv->sys_config.answer_broadcast_ssid_probe = 1;
7514 else
7515 priv->sys_config.answer_broadcast_ssid_probe = 0;
7516
James Ketrenos43f66a62005-03-25 12:31:53 -06007517 err = ipw_send_system_config(priv, &priv->sys_config);
7518 if (err) {
7519 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7520 return err;
7521 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007522
James Ketrenos43f66a62005-03-25 12:31:53 -06007523 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007524 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007525 if (err) {
7526 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7527 return err;
7528 }
7529
7530 /*
7531 * If preemption is enabled, it is possible for the association
7532 * to complete before we return from ipw_send_associate. Therefore
7533 * we have to be sure and update our priviate data first.
7534 */
7535 priv->channel = network->channel;
7536 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007537 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007538 priv->status &= ~STATUS_SECURITY_UPDATED;
7539
7540 priv->assoc_network = network;
7541
James Ketrenosb095c382005-08-24 22:04:42 -05007542#ifdef CONFIG_IPW_QOS
7543 ipw_qos_association(priv, network);
7544#endif
7545
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 err = ipw_send_associate(priv, &priv->assoc_request);
7547 if (err) {
7548 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7549 return err;
7550 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007551
7552 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007553 escape_essid(priv->essid, priv->essid_len),
7554 MAC_ARG(priv->bssid));
7555
7556 return 0;
7557}
7558
7559static void ipw_roam(void *data)
7560{
7561 struct ipw_priv *priv = data;
7562 struct ieee80211_network *network = NULL;
7563 struct ipw_network_match match = {
7564 .network = priv->assoc_network
7565 };
7566
7567 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007568 *
7569 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007570 * setting the status ROAM bit and requesting a scan.
7571 * 2. When the scan completes, it schedules the ROAM work
7572 * 3. The ROAM work looks at all of the known networks for one that
7573 * is a better network than the currently associated. If none
7574 * found, the ROAM process is over (ROAM bit cleared)
7575 * 4. If a better network is found, a disassociation request is
7576 * sent.
7577 * 5. When the disassociation completes, the roam work is again
7578 * scheduled. The second time through, the driver is no longer
7579 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007580 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007581 * 6. At this point ,the roaming process is complete and the ROAM
7582 * status bit is cleared.
7583 */
7584
7585 /* If we are no longer associated, and the roaming bit is no longer
7586 * set, then we are not actively roaming, so just return */
7587 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7588 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007589
James Ketrenos43f66a62005-03-25 12:31:53 -06007590 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007591 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007592 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007593 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007594 u8 rssi = priv->assoc_network->stats.rssi;
7595 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007596 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007597 list_for_each_entry(network, &priv->ieee->network_list, list) {
7598 if (network != priv->assoc_network)
7599 ipw_best_network(priv, &match, network, 1);
7600 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007601 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007602 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007603
James Ketrenos43f66a62005-03-25 12:31:53 -06007604 if (match.network == priv->assoc_network) {
7605 IPW_DEBUG_ASSOC("No better APs in this network to "
7606 "roam to.\n");
7607 priv->status &= ~STATUS_ROAMING;
7608 ipw_debug_config(priv);
7609 return;
7610 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007611
James Ketrenos43f66a62005-03-25 12:31:53 -06007612 ipw_send_disassociate(priv, 1);
7613 priv->assoc_network = match.network;
7614
7615 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007616 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007617
7618 /* Second pass through ROAM process -- request association */
7619 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7620 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7621 priv->status &= ~STATUS_ROAMING;
7622}
7623
James Ketrenosc848d0a2005-08-24 21:56:24 -05007624static void ipw_bg_roam(void *data)
7625{
7626 struct ipw_priv *priv = data;
7627 down(&priv->sem);
7628 ipw_roam(data);
7629 up(&priv->sem);
7630}
7631
7632static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007633{
7634 struct ipw_priv *priv = data;
7635
7636 struct ieee80211_network *network = NULL;
7637 struct ipw_network_match match = {
7638 .network = NULL
7639 };
7640 struct ipw_supported_rates *rates;
7641 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007642 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007643
James Ketrenosb095c382005-08-24 22:04:42 -05007644 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7645 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7646 return 0;
7647 }
7648
James Ketrenosc848d0a2005-08-24 21:56:24 -05007649 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007650 IPW_DEBUG_ASSOC("Not attempting association (already in "
7651 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007652 return 0;
7653 }
7654
7655 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007656 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7657 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007658 return 0;
7659 }
7660
James Ketrenos43f66a62005-03-25 12:31:53 -06007661 if (!(priv->config & CFG_ASSOCIATE) &&
7662 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007663 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007664 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007665 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007666 }
7667
James Ketrenosa613bff2005-08-24 21:43:11 -05007668 /* Protect our use of the network_list */
7669 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007670 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007671 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007672
7673 network = match.network;
7674 rates = &match.rates;
7675
7676 if (network == NULL &&
7677 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7678 priv->config & CFG_ADHOC_CREATE &&
7679 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007680 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007681 !list_empty(&priv->ieee->network_free_list)) {
7682 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007683 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007684 ipw_adhoc_create(priv, network);
7685 rates = &priv->rates;
7686 list_del(element);
7687 list_add_tail(&network->list, &priv->ieee->network_list);
7688 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007689 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007690
James Ketrenos43f66a62005-03-25 12:31:53 -06007691 /* If we reached the end of the list, then we don't have any valid
7692 * matching APs */
7693 if (!network) {
7694 ipw_debug_config(priv);
7695
James Ketrenosb095c382005-08-24 22:04:42 -05007696 if (!(priv->status & STATUS_SCANNING)) {
7697 if (!(priv->config & CFG_SPEED_SCAN))
7698 queue_delayed_work(priv->workqueue,
7699 &priv->request_scan,
7700 SCAN_INTERVAL);
7701 else
7702 queue_work(priv->workqueue,
7703 &priv->request_scan);
7704 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007705
James Ketrenosc848d0a2005-08-24 21:56:24 -05007706 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007707 }
7708
7709 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007710
7711 return 1;
7712}
7713
7714static void ipw_bg_associate(void *data)
7715{
7716 struct ipw_priv *priv = data;
7717 down(&priv->sem);
7718 ipw_associate(data);
7719 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007720}
Jeff Garzikbf794512005-07-31 13:07:26 -04007721
James Ketrenosb095c382005-08-24 22:04:42 -05007722static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7723 struct sk_buff *skb)
7724{
7725 struct ieee80211_hdr *hdr;
7726 u16 fc;
7727
7728 hdr = (struct ieee80211_hdr *)skb->data;
7729 fc = le16_to_cpu(hdr->frame_ctl);
7730 if (!(fc & IEEE80211_FCTL_PROTECTED))
7731 return;
7732
7733 fc &= ~IEEE80211_FCTL_PROTECTED;
7734 hdr->frame_ctl = cpu_to_le16(fc);
7735 switch (priv->ieee->sec.level) {
7736 case SEC_LEVEL_3:
7737 /* Remove CCMP HDR */
7738 memmove(skb->data + IEEE80211_3ADDR_LEN,
7739 skb->data + IEEE80211_3ADDR_LEN + 8,
7740 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yia2d73e62005-07-13 12:24:51 -05007741 if (fc & IEEE80211_FCTL_MOREFRAGS)
7742 skb_trim(skb, skb->len - 16); /* 2*MIC */
7743 else
7744 skb_trim(skb, skb->len - 8); /* MIC */
James Ketrenosb095c382005-08-24 22:04:42 -05007745 break;
7746 case SEC_LEVEL_2:
7747 break;
7748 case SEC_LEVEL_1:
7749 /* Remove IV */
7750 memmove(skb->data + IEEE80211_3ADDR_LEN,
7751 skb->data + IEEE80211_3ADDR_LEN + 4,
7752 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yia2d73e62005-07-13 12:24:51 -05007753 if (fc & IEEE80211_FCTL_MOREFRAGS)
7754 skb_trim(skb, skb->len - 8); /* 2*ICV */
7755 else
7756 skb_trim(skb, skb->len - 4); /* ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007757 break;
7758 case SEC_LEVEL_0:
7759 break;
7760 default:
7761 printk(KERN_ERR "Unknow security level %d\n",
7762 priv->ieee->sec.level);
7763 break;
7764 }
7765}
7766
7767static void ipw_handle_data_packet(struct ipw_priv *priv,
7768 struct ipw_rx_mem_buffer *rxb,
7769 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007770{
7771 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7772
7773 /* We received data from the HW, so stop the watchdog */
7774 priv->net_dev->trans_start = jiffies;
7775
Jeff Garzikbf794512005-07-31 13:07:26 -04007776 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007777 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007778 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007779 skb_tailroom(rxb->skb))) {
7780 priv->ieee->stats.rx_errors++;
7781 priv->wstats.discard.misc++;
7782 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7783 return;
7784 } else if (unlikely(!netif_running(priv->net_dev))) {
7785 priv->ieee->stats.rx_dropped++;
7786 priv->wstats.discard.misc++;
7787 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7788 return;
7789 }
7790
7791 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007792 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007793
7794 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007795 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007796
7797 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7798
James Ketrenosb095c382005-08-24 22:04:42 -05007799 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7800 if (!priv->ieee->host_decrypt)
7801 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7802
Jeff Garzikbf794512005-07-31 13:07:26 -04007803 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007804 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007805 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007806 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007807 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007808 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007809}
7810
James Ketrenosea2b26e2005-08-24 21:25:16 -05007811static inline int is_network_packet(struct ipw_priv *priv,
7812 struct ieee80211_hdr_4addr *header)
7813{
7814 /* Filter incoming packets to determine if they are targetted toward
7815 * this network, discarding packets coming from ourselves */
7816 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007817 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007818 /* packets from our adapter are dropped (echo) */
7819 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7820 return 0;
7821
James Ketrenosafbf30a2005-08-25 00:05:33 -05007822 /* multicast packets to our IBSS go through */
7823 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007824 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007825
7826 /* packets to our adapter go through */
7827 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7828 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007829
7830 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007831 /* packets from our adapter are dropped (echo) */
7832 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7833 return 0;
7834
James Ketrenosa613bff2005-08-24 21:43:11 -05007835 /* {broad,multi}cast packets to our IBSS go through */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007836 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007837 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7838
7839 /* packets to our adapter go through */
7840 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7841 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007842 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007843
James Ketrenosea2b26e2005-08-24 21:25:16 -05007844 return 1;
7845}
7846
James Ketrenosafbf30a2005-08-25 00:05:33 -05007847#define IPW_PACKET_RETRY_TIME HZ
7848
7849static inline int is_duplicate_packet(struct ipw_priv *priv,
7850 struct ieee80211_hdr_4addr *header)
7851{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007852 u16 sc = le16_to_cpu(header->seq_ctl);
7853 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7854 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7855 u16 *last_seq, *last_frag;
7856 unsigned long *last_time;
7857
7858 switch (priv->ieee->iw_mode) {
7859 case IW_MODE_ADHOC:
7860 {
7861 struct list_head *p;
7862 struct ipw_ibss_seq *entry = NULL;
7863 u8 *mac = header->addr2;
7864 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7865
7866 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7867 entry =
7868 list_entry(p, struct ipw_ibss_seq, list);
7869 if (!memcmp(entry->mac, mac, ETH_ALEN))
7870 break;
7871 }
7872 if (p == &priv->ibss_mac_hash[index]) {
7873 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7874 if (!entry) {
7875 IPW_ERROR
7876 ("Cannot malloc new mac entry\n");
7877 return 0;
7878 }
7879 memcpy(entry->mac, mac, ETH_ALEN);
7880 entry->seq_num = seq;
7881 entry->frag_num = frag;
7882 entry->packet_time = jiffies;
7883 list_add(&entry->list,
7884 &priv->ibss_mac_hash[index]);
7885 return 0;
7886 }
7887 last_seq = &entry->seq_num;
7888 last_frag = &entry->frag_num;
7889 last_time = &entry->packet_time;
7890 break;
7891 }
7892 case IW_MODE_INFRA:
7893 last_seq = &priv->last_seq_num;
7894 last_frag = &priv->last_frag_num;
7895 last_time = &priv->last_packet_time;
7896 break;
7897 default:
7898 return 0;
7899 }
7900 if ((*last_seq == seq) &&
7901 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7902 if (*last_frag == frag)
7903 goto drop;
7904 if (*last_frag + 1 != frag)
7905 /* out-of-order fragment */
7906 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007907 } else
7908 *last_seq = seq;
7909
Zhu Yif57ce7c2005-07-13 12:22:15 -05007910 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007911 *last_time = jiffies;
7912 return 0;
7913
7914 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007915 /* Comment this line now since we observed the card receives
7916 * duplicate packets but the FCTL_RETRY bit is not set in the
7917 * IBSS mode with fragmentation enabled.
7918 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007919 return 1;
7920}
7921
James Ketrenosb095c382005-08-24 22:04:42 -05007922static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7923 struct ipw_rx_mem_buffer *rxb,
7924 struct ieee80211_rx_stats *stats)
7925{
7926 struct sk_buff *skb = rxb->skb;
7927 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7928 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7929 (skb->data + IPW_RX_FRAME_SIZE);
7930
7931 ieee80211_rx_mgt(priv->ieee, header, stats);
7932
7933 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7934 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7935 IEEE80211_STYPE_PROBE_RESP) ||
7936 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7937 IEEE80211_STYPE_BEACON))) {
7938 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7939 ipw_add_station(priv, header->addr2);
7940 }
7941
7942 if (priv->config & CFG_NET_STATS) {
7943 IPW_DEBUG_HC("sending stat packet\n");
7944
7945 /* Set the size of the skb to the size of the full
7946 * ipw header and 802.11 frame */
7947 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7948 IPW_RX_FRAME_SIZE);
7949
7950 /* Advance past the ipw packet header to the 802.11 frame */
7951 skb_pull(skb, IPW_RX_FRAME_SIZE);
7952
7953 /* Push the ieee80211_rx_stats before the 802.11 frame */
7954 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7955
7956 skb->dev = priv->ieee->dev;
7957
7958 /* Point raw at the ieee80211_stats */
7959 skb->mac.raw = skb->data;
7960
7961 skb->pkt_type = PACKET_OTHERHOST;
7962 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7963 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7964 netif_rx(skb);
7965 rxb->skb = NULL;
7966 }
7967}
7968
James Ketrenos43f66a62005-03-25 12:31:53 -06007969/*
7970 * Main entry function for recieving a packet with 80211 headers. This
7971 * should be called when ever the FW has notified us that there is a new
7972 * skb in the recieve queue.
7973 */
7974static void ipw_rx(struct ipw_priv *priv)
7975{
7976 struct ipw_rx_mem_buffer *rxb;
7977 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007978 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007979 u32 r, w, i;
7980 u8 network_packet;
7981
James Ketrenosb095c382005-08-24 22:04:42 -05007982 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7983 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007984 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7985
7986 while (i != r) {
7987 rxb = priv->rxq->queue[i];
7988#ifdef CONFIG_IPW_DEBUG
7989 if (unlikely(rxb == NULL)) {
7990 printk(KERN_CRIT "Queue not allocated!\n");
7991 break;
7992 }
7993#endif
7994 priv->rxq->queue[i] = NULL;
7995
7996 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007997 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007998 PCI_DMA_FROMDEVICE);
7999
8000 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8001 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8002 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008003 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008004
8005 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008006 case RX_FRAME_TYPE: /* 802.11 frame */ {
8007 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008008 .rssi =
8009 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008010 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008011 .signal =
8012 le16_to_cpu(pkt->u.frame.signal),
8013 .noise =
8014 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008015 .rate = pkt->u.frame.rate,
8016 .mac_time = jiffies,
8017 .received_channel =
8018 pkt->u.frame.received_channel,
8019 .freq =
8020 (pkt->u.frame.
8021 control & (1 << 0)) ?
8022 IEEE80211_24GHZ_BAND :
8023 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008024 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008025 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008026
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008027 if (stats.rssi != 0)
8028 stats.mask |= IEEE80211_STATMASK_RSSI;
8029 if (stats.signal != 0)
8030 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008031 if (stats.noise != 0)
8032 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008033 if (stats.rate != 0)
8034 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008035
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008036 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008037
James Ketrenosb095c382005-08-24 22:04:42 -05008038#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008039 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8040 ipw_handle_data_packet(priv, rxb,
8041 &stats);
8042 break;
8043 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008044#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008045
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008046 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008047 (struct ieee80211_hdr_4addr *)(rxb->skb->
8048 data +
8049 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008050 /* TODO: Check Ad-Hoc dest/source and make sure
8051 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008052 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008053 * frame control of the packet and disregard
8054 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008055
James Ketrenosea2b26e2005-08-24 21:25:16 -05008056 network_packet =
8057 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008058 if (network_packet && priv->assoc_network) {
8059 priv->assoc_network->stats.rssi =
8060 stats.rssi;
8061 average_add(&priv->average_rssi,
8062 stats.rssi);
8063 priv->last_rx_rssi = stats.rssi;
8064 }
8065
8066 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008067 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008068
James Ketrenosa613bff2005-08-24 21:43:11 -05008069 if (le16_to_cpu(pkt->u.frame.length) <
8070 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008071 IPW_DEBUG_DROP
8072 ("Received packet is too small. "
8073 "Dropping.\n");
8074 priv->ieee->stats.rx_errors++;
8075 priv->wstats.discard.misc++;
8076 break;
8077 }
8078
James Ketrenosa613bff2005-08-24 21:43:11 -05008079 switch (WLAN_FC_GET_TYPE
8080 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008081
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008082 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008083 ipw_handle_mgmt_packet(priv, rxb,
8084 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008085 break;
8086
8087 case IEEE80211_FTYPE_CTL:
8088 break;
8089
8090 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008091 if (unlikely(!network_packet ||
8092 is_duplicate_packet(priv,
8093 header)))
8094 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008095 IPW_DEBUG_DROP("Dropping: "
8096 MAC_FMT ", "
8097 MAC_FMT ", "
8098 MAC_FMT "\n",
8099 MAC_ARG(header->
8100 addr1),
8101 MAC_ARG(header->
8102 addr2),
8103 MAC_ARG(header->
8104 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008105 break;
8106 }
8107
8108 ipw_handle_data_packet(priv, rxb,
8109 &stats);
8110
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008111 break;
8112 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008113 break;
8114 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008115
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008116 case RX_HOST_NOTIFICATION_TYPE:{
8117 IPW_DEBUG_RX
8118 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008119 pkt->u.notification.subtype,
8120 pkt->u.notification.flags,
8121 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008122 ipw_rx_notification(priv, &pkt->u.notification);
8123 break;
8124 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008125
8126 default:
8127 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8128 pkt->header.message_type);
8129 break;
8130 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008131
8132 /* For now we just don't re-use anything. We can tweak this
8133 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008134 * fail to Rx correctly */
8135 if (rxb->skb != NULL) {
8136 dev_kfree_skb_any(rxb->skb);
8137 rxb->skb = NULL;
8138 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008139
James Ketrenos43f66a62005-03-25 12:31:53 -06008140 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008141 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008142 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008143
James Ketrenos43f66a62005-03-25 12:31:53 -06008144 i = (i + 1) % RX_QUEUE_SIZE;
8145 }
8146
8147 /* Backtrack one entry */
8148 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8149
8150 ipw_rx_queue_restock(priv);
8151}
8152
James Ketrenosafbf30a2005-08-25 00:05:33 -05008153#define DEFAULT_RTS_THRESHOLD 2304U
8154#define MIN_RTS_THRESHOLD 1U
8155#define MAX_RTS_THRESHOLD 2304U
8156#define DEFAULT_BEACON_INTERVAL 100U
8157#define DEFAULT_SHORT_RETRY_LIMIT 7U
8158#define DEFAULT_LONG_RETRY_LIMIT 4U
8159
8160static int ipw_sw_reset(struct ipw_priv *priv, int init)
8161{
8162 int band, modulation;
8163 int old_mode = priv->ieee->iw_mode;
8164
8165 /* Initialize module parameter values here */
8166 priv->config = 0;
8167
8168 /* We default to disabling the LED code as right now it causes
8169 * too many systems to lock up... */
8170 if (!led)
8171 priv->config |= CFG_NO_LED;
8172
8173 if (associate)
8174 priv->config |= CFG_ASSOCIATE;
8175 else
8176 IPW_DEBUG_INFO("Auto associate disabled.\n");
8177
8178 if (auto_create)
8179 priv->config |= CFG_ADHOC_CREATE;
8180 else
8181 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8182
8183 if (disable) {
8184 priv->status |= STATUS_RF_KILL_SW;
8185 IPW_DEBUG_INFO("Radio disabled.\n");
8186 }
8187
8188 if (channel != 0) {
8189 priv->config |= CFG_STATIC_CHANNEL;
8190 priv->channel = channel;
8191 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8192 /* TODO: Validate that provided channel is in range */
8193 }
8194#ifdef CONFIG_IPW_QOS
8195 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8196 burst_duration_CCK, burst_duration_OFDM);
8197#endif /* CONFIG_IPW_QOS */
8198
8199 switch (mode) {
8200 case 1:
8201 priv->ieee->iw_mode = IW_MODE_ADHOC;
8202 priv->net_dev->type = ARPHRD_ETHER;
8203
8204 break;
8205#ifdef CONFIG_IPW2200_MONITOR
8206 case 2:
8207 priv->ieee->iw_mode = IW_MODE_MONITOR;
8208 priv->net_dev->type = ARPHRD_IEEE80211;
8209 break;
8210#endif
8211 default:
8212 case 0:
8213 priv->net_dev->type = ARPHRD_ETHER;
8214 priv->ieee->iw_mode = IW_MODE_INFRA;
8215 break;
8216 }
8217
8218 if (hwcrypto) {
8219 priv->ieee->host_encrypt = 0;
8220 priv->ieee->host_encrypt_msdu = 0;
8221 priv->ieee->host_decrypt = 0;
8222 }
8223 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8224
Zhu Yie402c932005-08-05 17:20:40 +08008225 /* IPW2200/2915 is abled to do hardware fragmentation. */
8226 priv->ieee->host_open_frag = 0;
8227
James Ketrenosafbf30a2005-08-25 00:05:33 -05008228 if ((priv->pci_dev->device == 0x4223) ||
8229 (priv->pci_dev->device == 0x4224)) {
8230 if (init)
8231 printk(KERN_INFO DRV_NAME
8232 ": Detected Intel PRO/Wireless 2915ABG Network "
8233 "Connection\n");
8234 priv->ieee->abg_true = 1;
8235 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8236 modulation = IEEE80211_OFDM_MODULATION |
8237 IEEE80211_CCK_MODULATION;
8238 priv->adapter = IPW_2915ABG;
8239 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8240 } else {
8241 if (init)
8242 printk(KERN_INFO DRV_NAME
8243 ": Detected Intel PRO/Wireless 2200BG Network "
8244 "Connection\n");
8245
8246 priv->ieee->abg_true = 0;
8247 band = IEEE80211_24GHZ_BAND;
8248 modulation = IEEE80211_OFDM_MODULATION |
8249 IEEE80211_CCK_MODULATION;
8250 priv->adapter = IPW_2200BG;
8251 priv->ieee->mode = IEEE_G | IEEE_B;
8252 }
8253
8254 priv->ieee->freq_band = band;
8255 priv->ieee->modulation = modulation;
8256
8257 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8258
8259 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8260 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8261
8262 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8263 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8264 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8265
8266 /* If power management is turned on, default to AC mode */
8267 priv->power_mode = IPW_POWER_AC;
8268 priv->tx_power = IPW_TX_POWER_DEFAULT;
8269
Zhu Yi0ece35b2005-08-05 17:26:51 +08008270 return old_mode == priv->ieee->iw_mode;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008271}
8272
James Ketrenos43f66a62005-03-25 12:31:53 -06008273/*
8274 * This file defines the Wireless Extension handlers. It does not
8275 * define any methods of hardware manipulation and relies on the
8276 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008277 *
8278 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008279 * function used to poll the hardware vs. making unecessary calls.
8280 *
8281 */
8282
Jeff Garzikbf794512005-07-31 13:07:26 -04008283static int ipw_wx_get_name(struct net_device *dev,
8284 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008285 union iwreq_data *wrqu, char *extra)
8286{
8287 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008288 down(&priv->sem);
8289 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008290 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008291 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008292 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008293 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008294 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8295 ipw_modes[priv->assoc_request.ieee_mode]);
8296 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008297 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008298 return 0;
8299}
8300
8301static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8302{
8303 if (channel == 0) {
8304 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8305 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008306 IPW_DEBUG_ASSOC("Attempting to associate with new "
8307 "parameters.\n");
8308 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008309 return 0;
8310 }
8311
8312 priv->config |= CFG_STATIC_CHANNEL;
8313
8314 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008315 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8316 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008317 return 0;
8318 }
8319
8320 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8321 priv->channel = channel;
8322
James Ketrenosb095c382005-08-24 22:04:42 -05008323#ifdef CONFIG_IPW2200_MONITOR
8324 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008325 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008326 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008327 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008328 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008329 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008330 }
8331
8332 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8333 udelay(10);
8334
8335 if (priv->status & STATUS_SCANNING)
8336 IPW_DEBUG_SCAN("Still scanning...\n");
8337 else
8338 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8339 1000 - i);
8340
8341 return 0;
8342 }
8343#endif /* CONFIG_IPW2200_MONITOR */
8344
James Ketrenosc848d0a2005-08-24 21:56:24 -05008345 /* Network configuration changed -- force [re]association */
8346 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8347 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008348 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008349
8350 return 0;
8351}
8352
Jeff Garzikbf794512005-07-31 13:07:26 -04008353static int ipw_wx_set_freq(struct net_device *dev,
8354 struct iw_request_info *info,
8355 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008356{
8357 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008358 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008359 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008360 int ret = 0, i;
James Ketrenosb095c382005-08-24 22:04:42 -05008361 u8 channel;
8362
8363 if (fwrq->m == 0) {
8364 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8365 down(&priv->sem);
8366 ret = ipw_set_channel(priv, 0);
8367 up(&priv->sem);
8368 return ret;
8369 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008370 /* if setting by freq convert to channel */
8371 if (fwrq->e == 1) {
James Ketrenosb095c382005-08-24 22:04:42 -05008372 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8373 if (channel == 0)
8374 return -EINVAL;
8375 } else
8376 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008377
James Ketrenosb095c382005-08-24 22:04:42 -05008378 if (!ieee80211_is_valid_channel(priv->ieee, channel))
8379 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008380
James Ketrenosafbf30a2005-08-25 00:05:33 -05008381 if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
8382 i = ieee80211_channel_to_index(priv->ieee, channel);
8383 if (i == -1)
8384 return -EINVAL;
8385 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
8386 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8387 return -EINVAL;
8388 }
8389 }
8390
James Ketrenos43f66a62005-03-25 12:31:53 -06008391 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008392 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008393 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008394 up(&priv->sem);
8395 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008396}
8397
Jeff Garzikbf794512005-07-31 13:07:26 -04008398static int ipw_wx_get_freq(struct net_device *dev,
8399 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008400 union iwreq_data *wrqu, char *extra)
8401{
8402 struct ipw_priv *priv = ieee80211_priv(dev);
8403
8404 wrqu->freq.e = 0;
8405
8406 /* If we are associated, trying to associate, or have a statically
8407 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008408 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008409 if (priv->config & CFG_STATIC_CHANNEL ||
8410 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8411 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008412 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008413 wrqu->freq.m = 0;
8414
James Ketrenosc848d0a2005-08-24 21:56:24 -05008415 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008416 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8417 return 0;
8418}
8419
Jeff Garzikbf794512005-07-31 13:07:26 -04008420static int ipw_wx_set_mode(struct net_device *dev,
8421 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008422 union iwreq_data *wrqu, char *extra)
8423{
8424 struct ipw_priv *priv = ieee80211_priv(dev);
8425 int err = 0;
8426
8427 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06008428
8429 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008430#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008431 case IW_MODE_MONITOR:
8432#endif
8433 case IW_MODE_ADHOC:
8434 case IW_MODE_INFRA:
8435 break;
8436 case IW_MODE_AUTO:
8437 wrqu->mode = IW_MODE_INFRA;
8438 break;
8439 default:
8440 return -EINVAL;
8441 }
James Ketrenosb095c382005-08-24 22:04:42 -05008442 if (wrqu->mode == priv->ieee->iw_mode)
8443 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008444
James Ketrenosb095c382005-08-24 22:04:42 -05008445 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008446
8447 ipw_sw_reset(priv, 0);
8448
James Ketrenosb095c382005-08-24 22:04:42 -05008449#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008450 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008451 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008452
8453 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008454 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosb095c382005-08-24 22:04:42 -05008455#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008456
Jeff Garzikbf794512005-07-31 13:07:26 -04008457 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008458 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008459 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008460
8461 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008462
James Ketrenosc848d0a2005-08-24 21:56:24 -05008463 queue_work(priv->workqueue, &priv->adapter_restart);
8464 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008465 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008466}
8467
Jeff Garzikbf794512005-07-31 13:07:26 -04008468static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008469 struct iw_request_info *info,
8470 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008471{
8472 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008473 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008474 wrqu->mode = priv->ieee->iw_mode;
8475 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008476 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008477 return 0;
8478}
8479
James Ketrenos43f66a62005-03-25 12:31:53 -06008480/* Values are in microsecond */
8481static const s32 timeout_duration[] = {
8482 350000,
8483 250000,
8484 75000,
8485 37000,
8486 25000,
8487};
8488
8489static const s32 period_duration[] = {
8490 400000,
8491 700000,
8492 1000000,
8493 1000000,
8494 1000000
8495};
8496
Jeff Garzikbf794512005-07-31 13:07:26 -04008497static int ipw_wx_get_range(struct net_device *dev,
8498 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008499 union iwreq_data *wrqu, char *extra)
8500{
8501 struct ipw_priv *priv = ieee80211_priv(dev);
8502 struct iw_range *range = (struct iw_range *)extra;
James Ketrenosb095c382005-08-24 22:04:42 -05008503 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8504 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008505
8506 wrqu->data.length = sizeof(*range);
8507 memset(range, 0, sizeof(*range));
8508
8509 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008510 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008511
8512 range->max_qual.qual = 100;
8513 /* TODO: Find real max RSSI and stick here */
8514 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008515 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008516 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008517
8518 range->avg_qual.qual = 70;
8519 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008520 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008521 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008522 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008523 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008524 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008525
Jeff Garzikbf794512005-07-31 13:07:26 -04008526 for (i = 0; i < range->num_bitrates; i++)
8527 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008528 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008529
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 range->max_rts = DEFAULT_RTS_THRESHOLD;
8531 range->min_frag = MIN_FRAG_THRESHOLD;
8532 range->max_frag = MAX_FRAG_THRESHOLD;
8533
8534 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008535 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008536 range->num_encoding_sizes = 2;
8537 range->max_encoding_tokens = WEP_KEYS;
8538
8539 /* Set the Wireless Extension versions */
8540 range->we_version_compiled = WIRELESS_EXT;
8541 range->we_version_source = 16;
8542
James Ketrenosb095c382005-08-24 22:04:42 -05008543 i = 0;
8544 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8545 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8546 i++, j++) {
8547 range->freq[i].i = geo->bg[j].channel;
8548 range->freq[i].m = geo->bg[j].freq * 100000;
8549 range->freq[i].e = 1;
8550 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008551 }
James Ketrenosb095c382005-08-24 22:04:42 -05008552
8553 if (priv->ieee->mode & IEEE_A) {
8554 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8555 i++, j++) {
8556 range->freq[i].i = geo->a[j].channel;
8557 range->freq[i].m = geo->a[j].freq * 100000;
8558 range->freq[i].e = 1;
8559 }
8560 }
8561
8562 range->num_channels = i;
8563 range->num_frequency = i;
8564
James Ketrenosc848d0a2005-08-24 21:56:24 -05008565 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008566 IPW_DEBUG_WX("GET Range\n");
8567 return 0;
8568}
8569
Jeff Garzikbf794512005-07-31 13:07:26 -04008570static int ipw_wx_set_wap(struct net_device *dev,
8571 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008572 union iwreq_data *wrqu, char *extra)
8573{
8574 struct ipw_priv *priv = ieee80211_priv(dev);
8575
8576 static const unsigned char any[] = {
8577 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8578 };
8579 static const unsigned char off[] = {
8580 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8581 };
8582
Jeff Garzikbf794512005-07-31 13:07:26 -04008583 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008585 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008586 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8587 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8588 /* we disable mandatory BSSID association */
8589 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8590 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008591 IPW_DEBUG_ASSOC("Attempting to associate with new "
8592 "parameters.\n");
8593 ipw_associate(priv);
8594 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008595 return 0;
8596 }
8597
8598 priv->config |= CFG_STATIC_BSSID;
8599 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8600 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008601 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 return 0;
8603 }
8604
8605 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8606 MAC_ARG(wrqu->ap_addr.sa_data));
8607
8608 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8609
James Ketrenosc848d0a2005-08-24 21:56:24 -05008610 /* Network configuration changed -- force [re]association */
8611 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8612 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008613 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008614
James Ketrenosc848d0a2005-08-24 21:56:24 -05008615 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008616 return 0;
8617}
8618
Jeff Garzikbf794512005-07-31 13:07:26 -04008619static int ipw_wx_get_wap(struct net_device *dev,
8620 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008621 union iwreq_data *wrqu, char *extra)
8622{
8623 struct ipw_priv *priv = ieee80211_priv(dev);
8624 /* If we are associated, trying to associate, or have a statically
8625 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008626 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008627 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008628 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8629 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008630 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008631 } else
8632 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8633
8634 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8635 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008636 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008637 return 0;
8638}
8639
Jeff Garzikbf794512005-07-31 13:07:26 -04008640static int ipw_wx_set_essid(struct net_device *dev,
8641 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008642 union iwreq_data *wrqu, char *extra)
8643{
8644 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008645 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008646 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008647 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008648 if (wrqu->essid.flags && wrqu->essid.length) {
8649 length = wrqu->essid.length - 1;
8650 essid = extra;
8651 }
8652 if (length == 0) {
8653 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008654 if ((priv->config & CFG_STATIC_ESSID) &&
8655 !(priv->status & (STATUS_ASSOCIATED |
8656 STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008657 IPW_DEBUG_ASSOC("Attempting to associate with new "
8658 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008659 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008660 ipw_associate(priv);
8661 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008662 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008663 return 0;
8664 }
8665
8666 length = min(length, IW_ESSID_MAX_SIZE);
8667
8668 priv->config |= CFG_STATIC_ESSID;
8669
8670 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8671 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008672 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008673 return 0;
8674 }
8675
8676 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8677 length);
8678
8679 priv->essid_len = length;
8680 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008681
James Ketrenosc848d0a2005-08-24 21:56:24 -05008682 /* Network configuration changed -- force [re]association */
8683 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8684 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008685 ipw_associate(priv);
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_get_essid(struct net_device *dev,
8692 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008693 union iwreq_data *wrqu, char *extra)
8694{
8695 struct ipw_priv *priv = ieee80211_priv(dev);
8696
8697 /* If we are associated, trying to associate, or have a statically
8698 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008699 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008700 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008701 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8702 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008703 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008704 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008705 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008706 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008707 } else {
8708 IPW_DEBUG_WX("Getting essid: ANY\n");
8709 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008710 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008711 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008712 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008713 return 0;
8714}
8715
Jeff Garzikbf794512005-07-31 13:07:26 -04008716static int ipw_wx_set_nick(struct net_device *dev,
8717 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008718 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008719{
James Ketrenos43f66a62005-03-25 12:31:53 -06008720 struct ipw_priv *priv = ieee80211_priv(dev);
8721
8722 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8723 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8724 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008725 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008726 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008727 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008728 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008729 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008730 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008731 return 0;
8732
8733}
8734
Jeff Garzikbf794512005-07-31 13:07:26 -04008735static int ipw_wx_get_nick(struct net_device *dev,
8736 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008737 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008738{
James Ketrenos43f66a62005-03-25 12:31:53 -06008739 struct ipw_priv *priv = ieee80211_priv(dev);
8740 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008741 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008742 wrqu->data.length = strlen(priv->nick) + 1;
8743 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008744 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008745 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008746 return 0;
8747}
8748
James Ketrenos43f66a62005-03-25 12:31:53 -06008749static int ipw_wx_set_rate(struct net_device *dev,
8750 struct iw_request_info *info,
8751 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008752{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008753 /* TODO: We should use semaphores or locks for access to priv */
8754 struct ipw_priv *priv = ieee80211_priv(dev);
8755 u32 target_rate = wrqu->bitrate.value;
8756 u32 fixed, mask;
8757
8758 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8759 /* value = X, fixed = 1 means only rate X */
8760 /* value = X, fixed = 0 means all rates lower equal X */
8761
8762 if (target_rate == -1) {
8763 fixed = 0;
8764 mask = IEEE80211_DEFAULT_RATES_MASK;
8765 /* Now we should reassociate */
8766 goto apply;
8767 }
8768
8769 mask = 0;
8770 fixed = wrqu->bitrate.fixed;
8771
8772 if (target_rate == 1000000 || !fixed)
8773 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8774 if (target_rate == 1000000)
8775 goto apply;
8776
8777 if (target_rate == 2000000 || !fixed)
8778 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8779 if (target_rate == 2000000)
8780 goto apply;
8781
8782 if (target_rate == 5500000 || !fixed)
8783 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8784 if (target_rate == 5500000)
8785 goto apply;
8786
8787 if (target_rate == 6000000 || !fixed)
8788 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8789 if (target_rate == 6000000)
8790 goto apply;
8791
8792 if (target_rate == 9000000 || !fixed)
8793 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8794 if (target_rate == 9000000)
8795 goto apply;
8796
8797 if (target_rate == 11000000 || !fixed)
8798 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8799 if (target_rate == 11000000)
8800 goto apply;
8801
8802 if (target_rate == 12000000 || !fixed)
8803 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8804 if (target_rate == 12000000)
8805 goto apply;
8806
8807 if (target_rate == 18000000 || !fixed)
8808 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8809 if (target_rate == 18000000)
8810 goto apply;
8811
8812 if (target_rate == 24000000 || !fixed)
8813 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8814 if (target_rate == 24000000)
8815 goto apply;
8816
8817 if (target_rate == 36000000 || !fixed)
8818 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8819 if (target_rate == 36000000)
8820 goto apply;
8821
8822 if (target_rate == 48000000 || !fixed)
8823 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8824 if (target_rate == 48000000)
8825 goto apply;
8826
8827 if (target_rate == 54000000 || !fixed)
8828 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8829 if (target_rate == 54000000)
8830 goto apply;
8831
8832 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8833 return -EINVAL;
8834
8835 apply:
8836 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8837 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008838 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008839 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008840 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008841 ipw_set_fixed_rate(priv, priv->ieee->mode);
8842 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008843 priv->config |= CFG_FIXED_RATE;
8844
James Ketrenosc848d0a2005-08-24 21:56:24 -05008845 if (priv->rates_mask == mask) {
8846 IPW_DEBUG_WX("Mask set to current mask.\n");
8847 up(&priv->sem);
8848 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008849 }
8850
James Ketrenosc848d0a2005-08-24 21:56:24 -05008851 priv->rates_mask = mask;
8852
8853 /* Network configuration changed -- force [re]association */
8854 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8855 if (!ipw_disassociate(priv))
8856 ipw_associate(priv);
8857
8858 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008859 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008860}
8861
Jeff Garzikbf794512005-07-31 13:07:26 -04008862static int ipw_wx_get_rate(struct net_device *dev,
8863 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008864 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008865{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008866 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008867 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008869 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008870 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8871 return 0;
8872}
8873
Jeff Garzikbf794512005-07-31 13:07:26 -04008874static int ipw_wx_set_rts(struct net_device *dev,
8875 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008876 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008877{
James Ketrenos43f66a62005-03-25 12:31:53 -06008878 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008879 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008880 if (wrqu->rts.disabled)
8881 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8882 else {
8883 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008884 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8885 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008886 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008887 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008888 priv->rts_threshold = wrqu->rts.value;
8889 }
8890
8891 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008892 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008893 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8894 return 0;
8895}
8896
Jeff Garzikbf794512005-07-31 13:07:26 -04008897static int ipw_wx_get_rts(struct net_device *dev,
8898 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008899 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008900{
James Ketrenos43f66a62005-03-25 12:31:53 -06008901 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008902 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008903 wrqu->rts.value = priv->rts_threshold;
8904 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008905 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008906 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8908 return 0;
8909}
8910
Jeff Garzikbf794512005-07-31 13:07:26 -04008911static int ipw_wx_set_txpow(struct net_device *dev,
8912 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008913 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008914{
James Ketrenos43f66a62005-03-25 12:31:53 -06008915 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008916 int err = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05008917
James Ketrenosc848d0a2005-08-24 21:56:24 -05008918 down(&priv->sem);
8919 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008920 err = -EINPROGRESS;
8921 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008922 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008923
James Ketrenosb095c382005-08-24 22:04:42 -05008924 if (!wrqu->power.fixed)
8925 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8926
James Ketrenosc848d0a2005-08-24 21:56:24 -05008927 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008928 err = -EINVAL;
8929 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008930 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008931
James Ketrenosb095c382005-08-24 22:04:42 -05008932 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008933 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008934 err = -EINVAL;
8935 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008936 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008937
8938 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008939 err = ipw_set_tx_power(priv);
8940 out:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008941 up(&priv->sem);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008942 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008943}
8944
Jeff Garzikbf794512005-07-31 13:07:26 -04008945static int ipw_wx_get_txpow(struct net_device *dev,
8946 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008947 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008948{
James Ketrenos43f66a62005-03-25 12:31:53 -06008949 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008950 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008951 wrqu->power.value = priv->tx_power;
8952 wrqu->power.fixed = 1;
8953 wrqu->power.flags = IW_TXPOW_DBM;
8954 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008955 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008956
Jeff Garzikbf794512005-07-31 13:07:26 -04008957 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008958 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008959
8960 return 0;
8961}
8962
Jeff Garzikbf794512005-07-31 13:07:26 -04008963static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008964 struct iw_request_info *info,
8965 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008966{
8967 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008968 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008969 if (wrqu->frag.disabled)
8970 priv->ieee->fts = DEFAULT_FTS;
8971 else {
8972 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008973 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8974 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008975 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008976 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008977
James Ketrenos43f66a62005-03-25 12:31:53 -06008978 priv->ieee->fts = wrqu->frag.value & ~0x1;
8979 }
8980
8981 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008982 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008983 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8984 return 0;
8985}
8986
Jeff Garzikbf794512005-07-31 13:07:26 -04008987static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008988 struct iw_request_info *info,
8989 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008990{
8991 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008992 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008993 wrqu->frag.value = priv->ieee->fts;
8994 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008995 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008996 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008997 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8998
8999 return 0;
9000}
9001
Jeff Garzikbf794512005-07-31 13:07:26 -04009002static int ipw_wx_set_retry(struct net_device *dev,
9003 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009004 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009005{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009006 struct ipw_priv *priv = ieee80211_priv(dev);
9007
9008 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9009 return -EINVAL;
9010
9011 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9012 return 0;
9013
9014 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9015 return -EINVAL;
9016
9017 down(&priv->sem);
9018 if (wrqu->retry.flags & IW_RETRY_MIN)
9019 priv->short_retry_limit = (u8) wrqu->retry.value;
9020 else if (wrqu->retry.flags & IW_RETRY_MAX)
9021 priv->long_retry_limit = (u8) wrqu->retry.value;
9022 else {
9023 priv->short_retry_limit = (u8) wrqu->retry.value;
9024 priv->long_retry_limit = (u8) wrqu->retry.value;
9025 }
9026
9027 ipw_send_retry_limit(priv, priv->short_retry_limit,
9028 priv->long_retry_limit);
9029 up(&priv->sem);
9030 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9031 priv->short_retry_limit, priv->long_retry_limit);
9032 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009033}
9034
Jeff Garzikbf794512005-07-31 13:07:26 -04009035static int ipw_wx_get_retry(struct net_device *dev,
9036 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009037 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009038{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009039 struct ipw_priv *priv = ieee80211_priv(dev);
9040
9041 down(&priv->sem);
9042 wrqu->retry.disabled = 0;
9043
9044 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9045 up(&priv->sem);
9046 return -EINVAL;
9047 }
9048
9049 if (wrqu->retry.flags & IW_RETRY_MAX) {
9050 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9051 wrqu->retry.value = priv->long_retry_limit;
9052 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9053 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9054 wrqu->retry.value = priv->short_retry_limit;
9055 } else {
9056 wrqu->retry.flags = IW_RETRY_LIMIT;
9057 wrqu->retry.value = priv->short_retry_limit;
9058 }
9059 up(&priv->sem);
9060
9061 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9062
9063 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009064}
9065
James Ketrenosafbf30a2005-08-25 00:05:33 -05009066#if WIRELESS_EXT > 17
9067static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9068 int essid_len)
9069{
9070 struct ipw_scan_request_ext scan;
9071 int err = 0, scan_type;
9072
9073 down(&priv->sem);
9074
9075 if (priv->status & STATUS_RF_KILL_MASK) {
9076 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9077 priv->status |= STATUS_SCAN_PENDING;
9078 goto done;
9079 }
9080
9081 IPW_DEBUG_HC("starting request direct scan!\n");
9082
9083 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9084 err = wait_event_interruptible(priv->wait_state,
9085 !(priv->
9086 status & (STATUS_SCANNING |
9087 STATUS_SCAN_ABORTING)));
9088 if (err) {
9089 IPW_DEBUG_HC("aborting direct scan");
9090 goto done;
9091 }
9092 }
9093 memset(&scan, 0, sizeof(scan));
9094
9095 if (priv->config & CFG_SPEED_SCAN)
9096 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9097 cpu_to_le16(30);
9098 else
9099 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9100 cpu_to_le16(20);
9101
9102 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9103 cpu_to_le16(20);
9104 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
9105 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9106
9107 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9108
9109 err = ipw_send_ssid(priv, essid, essid_len);
9110 if (err) {
9111 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9112 goto done;
9113 }
9114 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9115
9116 ipw_add_scan_channels(priv, &scan, scan_type);
9117
9118 err = ipw_send_scan_request_ext(priv, &scan);
9119 if (err) {
9120 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9121 goto done;
9122 }
9123
9124 priv->status |= STATUS_SCANNING;
9125
9126 done:
9127 up(&priv->sem);
9128 return err;
9129}
9130#endif /* WIRELESS_EXT > 17 */
9131
Jeff Garzikbf794512005-07-31 13:07:26 -04009132static int ipw_wx_set_scan(struct net_device *dev,
9133 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009134 union iwreq_data *wrqu, char *extra)
9135{
9136 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009137#if WIRELESS_EXT > 17
9138 struct iw_scan_req *req = NULL;
9139 if (wrqu->data.length
9140 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9141 req = (struct iw_scan_req *)extra;
9142 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9143 ipw_request_direct_scan(priv, req->essid,
9144 req->essid_len);
9145 return 0;
9146 }
9147 }
9148#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009149 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009150
9151 queue_work(priv->workqueue, &priv->request_scan);
9152
James Ketrenos43f66a62005-03-25 12:31:53 -06009153 return 0;
9154}
9155
Jeff Garzikbf794512005-07-31 13:07:26 -04009156static int ipw_wx_get_scan(struct net_device *dev,
9157 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009158 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009159{
James Ketrenos43f66a62005-03-25 12:31:53 -06009160 struct ipw_priv *priv = ieee80211_priv(dev);
9161 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9162}
9163
Jeff Garzikbf794512005-07-31 13:07:26 -04009164static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009165 struct iw_request_info *info,
9166 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009167{
9168 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009169 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009170 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009171
9172 down(&priv->sem);
9173 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009174
Hong Liucaeff812005-08-05 17:25:50 +08009175 /* In IBSS mode, we need to notify the firmware to update
9176 * the beacon info after we changed the capability. */
9177 if (cap != priv->capability &&
9178 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9179 priv->status & STATUS_ASSOCIATED)
9180 ipw_disassociate(priv);
9181
9182 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009183 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009184}
9185
Jeff Garzikbf794512005-07-31 13:07:26 -04009186static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009187 struct iw_request_info *info,
9188 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009189{
9190 struct ipw_priv *priv = ieee80211_priv(dev);
9191 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9192}
9193
Jeff Garzikbf794512005-07-31 13:07:26 -04009194static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009195 struct iw_request_info *info,
9196 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009197{
9198 struct ipw_priv *priv = ieee80211_priv(dev);
9199 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009200 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009201 if (wrqu->power.disabled) {
9202 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9203 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9204 if (err) {
9205 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009206 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009207 return err;
9208 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009209 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009210 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009211 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009212 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009213
9214 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009215 case IW_POWER_ON: /* If not specified */
9216 case IW_POWER_MODE: /* If set all mask */
9217 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009218 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009219 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009220 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9221 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009222 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009223 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009224 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009225
James Ketrenos43f66a62005-03-25 12:31:53 -06009226 /* If the user hasn't specified a power management mode yet, default
9227 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009228 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009229 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009230 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9232 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9233 if (err) {
9234 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009235 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009236 return err;
9237 }
9238
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009239 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009240 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009241 return 0;
9242}
9243
Jeff Garzikbf794512005-07-31 13:07:26 -04009244static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009245 struct iw_request_info *info,
9246 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009247{
9248 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009249 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009250 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009251 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009252 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009253 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009254
James Ketrenosc848d0a2005-08-24 21:56:24 -05009255 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009256 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009257
James Ketrenos43f66a62005-03-25 12:31:53 -06009258 return 0;
9259}
9260
Jeff Garzikbf794512005-07-31 13:07:26 -04009261static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009262 struct iw_request_info *info,
9263 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009264{
9265 struct ipw_priv *priv = ieee80211_priv(dev);
9266 int mode = *(int *)extra;
9267 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009268 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009269 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9270 mode = IPW_POWER_AC;
9271 priv->power_mode = mode;
9272 } else {
9273 priv->power_mode = IPW_POWER_ENABLED | mode;
9274 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009275
James Ketrenos43f66a62005-03-25 12:31:53 -06009276 if (priv->power_mode != mode) {
9277 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009278
James Ketrenos43f66a62005-03-25 12:31:53 -06009279 if (err) {
9280 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009281 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009282 return err;
9283 }
9284 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009285 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009286 return 0;
9287}
9288
9289#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009290static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009291 struct iw_request_info *info,
9292 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009293{
9294 struct ipw_priv *priv = ieee80211_priv(dev);
9295 int level = IPW_POWER_LEVEL(priv->power_mode);
9296 char *p = extra;
9297
9298 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9299
9300 switch (level) {
9301 case IPW_POWER_AC:
9302 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9303 break;
9304 case IPW_POWER_BATTERY:
9305 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9306 break;
9307 default:
9308 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009309 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009310 timeout_duration[level - 1] / 1000,
9311 period_duration[level - 1] / 1000);
9312 }
9313
9314 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009315 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009316
9317 wrqu->data.length = p - extra + 1;
9318
9319 return 0;
9320}
9321
9322static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009323 struct iw_request_info *info,
9324 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009325{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009326 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009327 int mode = *(int *)extra;
9328 u8 band = 0, modulation = 0;
9329
9330 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009331 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009332 return -EINVAL;
9333 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009334 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009335 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009336 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009337 if (mode & IEEE_A) {
9338 band |= IEEE80211_52GHZ_BAND;
9339 modulation |= IEEE80211_OFDM_MODULATION;
9340 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009341 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009342 } else {
9343 if (mode & IEEE_A) {
9344 IPW_WARNING("Attempt to set 2200BG into "
9345 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009346 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009347 return -EINVAL;
9348 }
9349
James Ketrenosa33a1982005-09-14 14:28:59 -05009350 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 }
9352
9353 if (mode & IEEE_B) {
9354 band |= IEEE80211_24GHZ_BAND;
9355 modulation |= IEEE80211_CCK_MODULATION;
9356 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009357 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009358
James Ketrenos43f66a62005-03-25 12:31:53 -06009359 if (mode & IEEE_G) {
9360 band |= IEEE80211_24GHZ_BAND;
9361 modulation |= IEEE80211_OFDM_MODULATION;
9362 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009363 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009364
9365 priv->ieee->mode = mode;
9366 priv->ieee->freq_band = band;
9367 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009368 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009369
James Ketrenosc848d0a2005-08-24 21:56:24 -05009370 /* Network configuration changed -- force [re]association */
9371 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9372 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009374 ipw_associate(priv);
9375 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009376
James Ketrenosa613bff2005-08-24 21:43:11 -05009377 /* Update the band LEDs */
9378 ipw_led_band_on(priv);
9379
Jeff Garzikbf794512005-07-31 13:07:26 -04009380 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009381 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009382 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009383 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009384 return 0;
9385}
9386
9387static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009388 struct iw_request_info *info,
9389 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009390{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009391 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009392 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009393 switch (priv->ieee->mode) {
9394 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009395 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9396 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009397 case IEEE_B:
9398 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9399 break;
9400 case IEEE_A | IEEE_B:
9401 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9402 break;
9403 case IEEE_G:
9404 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9405 break;
9406 case IEEE_A | IEEE_G:
9407 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9408 break;
9409 case IEEE_B | IEEE_G:
9410 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9411 break;
9412 case IEEE_A | IEEE_B | IEEE_G:
9413 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9414 break;
9415 default:
9416 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009417 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009418 }
9419
James Ketrenos43f66a62005-03-25 12:31:53 -06009420 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9421
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009422 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009423 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009424
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009425 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009426}
9427
James Ketrenosea2b26e2005-08-24 21:25:16 -05009428static int ipw_wx_set_preamble(struct net_device *dev,
9429 struct iw_request_info *info,
9430 union iwreq_data *wrqu, char *extra)
9431{
9432 struct ipw_priv *priv = ieee80211_priv(dev);
9433 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009434 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009435 /* Switching from SHORT -> LONG requires a disassociation */
9436 if (mode == 1) {
9437 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9438 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009439
9440 /* Network configuration changed -- force [re]association */
9441 IPW_DEBUG_ASSOC
9442 ("[re]association triggered due to preamble change.\n");
9443 if (!ipw_disassociate(priv))
9444 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009445 }
9446 goto done;
9447 }
9448
9449 if (mode == 0) {
9450 priv->config &= ~CFG_PREAMBLE_LONG;
9451 goto done;
9452 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009453 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009454 return -EINVAL;
9455
9456 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009457 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009458 return 0;
9459}
9460
9461static int ipw_wx_get_preamble(struct net_device *dev,
9462 struct iw_request_info *info,
9463 union iwreq_data *wrqu, char *extra)
9464{
9465 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009466 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009467 if (priv->config & CFG_PREAMBLE_LONG)
9468 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9469 else
9470 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009471 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009472 return 0;
9473}
9474
James Ketrenosb095c382005-08-24 22:04:42 -05009475#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009476static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009477 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009478 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009479{
James Ketrenos43f66a62005-03-25 12:31:53 -06009480 struct ipw_priv *priv = ieee80211_priv(dev);
9481 int *parms = (int *)extra;
9482 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009483 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009484 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009485 if (enable) {
9486 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9487 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosa613bff2005-08-24 21:43:11 -05009488 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009489 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009490
James Ketrenos43f66a62005-03-25 12:31:53 -06009491 ipw_set_channel(priv, parms[1]);
9492 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009493 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9494 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009495 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009496 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009497 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009498 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009499 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009500 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009501 return 0;
9502}
9503
James Ketrenosb095c382005-08-24 22:04:42 -05009504#endif // CONFIG_IPW2200_MONITOR
9505
Jeff Garzikbf794512005-07-31 13:07:26 -04009506static int ipw_wx_reset(struct net_device *dev,
9507 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009508 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009509{
James Ketrenos43f66a62005-03-25 12:31:53 -06009510 struct ipw_priv *priv = ieee80211_priv(dev);
9511 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009512 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009513 return 0;
9514}
James Ketrenosb095c382005-08-24 22:04:42 -05009515
James Ketrenosb095c382005-08-24 22:04:42 -05009516static int ipw_wx_sw_reset(struct net_device *dev,
9517 struct iw_request_info *info,
9518 union iwreq_data *wrqu, char *extra)
9519{
9520 struct ipw_priv *priv = ieee80211_priv(dev);
9521 union iwreq_data wrqu_sec = {
9522 .encoding = {
9523 .flags = IW_ENCODE_DISABLED,
9524 },
9525 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009526 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009527
9528 IPW_DEBUG_WX("SW_RESET\n");
9529
9530 down(&priv->sem);
9531
James Ketrenosafbf30a2005-08-25 00:05:33 -05009532 ret = ipw_sw_reset(priv, 0);
9533 if (!ret) {
9534 free_firmware();
9535 ipw_adapter_restart(priv);
9536 }
James Ketrenosb095c382005-08-24 22:04:42 -05009537
9538 /* The SW reset bit might have been toggled on by the 'disable'
9539 * module parameter, so take appropriate action */
9540 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9541
9542 up(&priv->sem);
9543 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9544 down(&priv->sem);
9545
9546 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9547 /* Configuration likely changed -- force [re]association */
9548 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9549 "reset.\n");
9550 if (!ipw_disassociate(priv))
9551 ipw_associate(priv);
9552 }
9553
9554 up(&priv->sem);
9555
9556 return 0;
9557}
James Ketrenos43f66a62005-03-25 12:31:53 -06009558
9559/* Rebase the WE IOCTLs to zero for the handler array */
9560#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009561static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009562 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9563 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9564 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9565 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9566 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9567 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9568 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9569 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9570 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9571 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9572 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9573 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9574 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9575 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9576 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9577 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9578 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9579 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9580 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9581 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9582 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9583 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9584 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9585 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9586 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9587 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9588 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9589 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009590 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9591 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9592 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9593 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009594#if WIRELESS_EXT > 17
9595 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9596 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9597 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9598 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9599 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9600 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9601 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9602#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009603};
9604
James Ketrenosb095c382005-08-24 22:04:42 -05009605enum {
9606 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9607 IPW_PRIV_GET_POWER,
9608 IPW_PRIV_SET_MODE,
9609 IPW_PRIV_GET_MODE,
9610 IPW_PRIV_SET_PREAMBLE,
9611 IPW_PRIV_GET_PREAMBLE,
9612 IPW_PRIV_RESET,
9613 IPW_PRIV_SW_RESET,
9614#ifdef CONFIG_IPW2200_MONITOR
9615 IPW_PRIV_SET_MONITOR,
9616#endif
9617};
James Ketrenos43f66a62005-03-25 12:31:53 -06009618
Jeff Garzikbf794512005-07-31 13:07:26 -04009619static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009620 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009621 .cmd = IPW_PRIV_SET_POWER,
9622 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9623 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009624 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009625 .cmd = IPW_PRIV_GET_POWER,
9626 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9627 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009628 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009629 .cmd = IPW_PRIV_SET_MODE,
9630 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9631 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009632 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009633 .cmd = IPW_PRIV_GET_MODE,
9634 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9635 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009636 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009637 .cmd = IPW_PRIV_SET_PREAMBLE,
9638 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9639 .name = "set_preamble"},
9640 {
9641 .cmd = IPW_PRIV_GET_PREAMBLE,
9642 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9643 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009645 IPW_PRIV_RESET,
9646 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009647 {
9648 IPW_PRIV_SW_RESET,
9649 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9650#ifdef CONFIG_IPW2200_MONITOR
9651 {
9652 IPW_PRIV_SET_MONITOR,
9653 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9654#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009655};
9656
9657static iw_handler ipw_priv_handler[] = {
9658 ipw_wx_set_powermode,
9659 ipw_wx_get_powermode,
9660 ipw_wx_set_wireless_mode,
9661 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009662 ipw_wx_set_preamble,
9663 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009664 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009665 ipw_wx_sw_reset,
9666#ifdef CONFIG_IPW2200_MONITOR
9667 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009668#endif
9669};
9670
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009671static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009672 .standard = ipw_wx_handlers,
9673 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9674 .num_private = ARRAY_SIZE(ipw_priv_handler),
9675 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9676 .private = ipw_priv_handler,
9677 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06009678};
9679
James Ketrenosa613bff2005-08-24 21:43:11 -05009680static struct iw_public_data ipw_wx_data;
9681
James Ketrenos43f66a62005-03-25 12:31:53 -06009682/*
9683 * Get wireless statistics.
9684 * Called by /proc/net/wireless
9685 * Also called by SIOCGIWSTATS
9686 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009687static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009688{
9689 struct ipw_priv *priv = ieee80211_priv(dev);
9690 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009691
James Ketrenos43f66a62005-03-25 12:31:53 -06009692 wstats = &priv->wstats;
9693
James Ketrenosea2b26e2005-08-24 21:25:16 -05009694 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009695 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009696 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9697 * and associated; if not associcated, the values are all meaningless
9698 * anyway, so set them all to NULL and INVALID */
9699 if (!(priv->status & STATUS_ASSOCIATED)) {
9700 wstats->miss.beacon = 0;
9701 wstats->discard.retries = 0;
9702 wstats->qual.qual = 0;
9703 wstats->qual.level = 0;
9704 wstats->qual.noise = 0;
9705 wstats->qual.updated = 7;
9706 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009707 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009708 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009709 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009710
9711 wstats->qual.qual = priv->quality;
9712 wstats->qual.level = average_value(&priv->average_rssi);
9713 wstats->qual.noise = average_value(&priv->average_noise);
9714 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009715 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009716
9717 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9718 wstats->discard.retries = priv->last_tx_failures;
9719 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009720
James Ketrenos43f66a62005-03-25 12:31:53 -06009721/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9722 goto fail_get_ordinal;
9723 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009724
James Ketrenos43f66a62005-03-25 12:31:53 -06009725 return wstats;
9726}
9727
James Ketrenos43f66a62005-03-25 12:31:53 -06009728/* net device stuff */
9729
9730static inline void init_sys_config(struct ipw_sys_config *sys_config)
9731{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009732 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9733 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06009734 sys_config->answer_broadcast_ssid_probe = 0;
9735 sys_config->accept_all_data_frames = 0;
9736 sys_config->accept_non_directed_frames = 1;
9737 sys_config->exclude_unicast_unencrypted = 0;
9738 sys_config->disable_unicast_decryption = 1;
9739 sys_config->exclude_multicast_unencrypted = 0;
9740 sys_config->disable_multicast_decryption = 1;
9741 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009742 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009743 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009744 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009745 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009746 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009747}
9748
9749static int ipw_net_open(struct net_device *dev)
9750{
9751 struct ipw_priv *priv = ieee80211_priv(dev);
9752 IPW_DEBUG_INFO("dev->open\n");
9753 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009754 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009755 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9756 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009757 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009758 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 return 0;
9760}
9761
9762static int ipw_net_stop(struct net_device *dev)
9763{
9764 IPW_DEBUG_INFO("dev->close\n");
9765 netif_stop_queue(dev);
9766 return 0;
9767}
9768
9769/*
9770todo:
9771
9772modify to send one tfd per fragment instead of using chunking. otherwise
9773we need to heavily modify the ieee80211_skb_to_txb.
9774*/
9775
James Ketrenos227d2dc2005-07-28 16:25:55 -05009776static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9777 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009778{
James Ketrenos0dacca12005-09-21 12:23:41 -05009779 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009780 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009781 int i = 0;
9782 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009783#ifdef CONFIG_IPW_QOS
9784 int tx_id = ipw_get_tx_queue_number(priv, pri);
9785 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9786#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009787 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009788#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009789 struct clx2_queue *q = &txq->q;
9790 u8 id, hdr_len, unicast;
9791 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009792 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009793
James Ketrenos227d2dc2005-07-28 16:25:55 -05009794 /* If there isn't room in the queue, we return busy and let the
9795 * network stack requeue the packet for us */
9796 if (ipw_queue_space(q) < q->high_mark)
9797 return NETDEV_TX_BUSY;
9798
James Ketrenos43f66a62005-03-25 12:31:53 -06009799 switch (priv->ieee->iw_mode) {
9800 case IW_MODE_ADHOC:
9801 hdr_len = IEEE80211_3ADDR_LEN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009802 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009803 id = ipw_find_station(priv, hdr->addr1);
9804 if (id == IPW_INVALID_STATION) {
9805 id = ipw_add_station(priv, hdr->addr1);
9806 if (id == IPW_INVALID_STATION) {
9807 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009808 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009809 MAC_ARG(hdr->addr1));
9810 goto drop;
9811 }
9812 }
9813 break;
9814
9815 case IW_MODE_INFRA:
9816 default:
James Ketrenosafbf30a2005-08-25 00:05:33 -05009817 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009818 hdr_len = IEEE80211_3ADDR_LEN;
9819 id = 0;
9820 break;
9821 }
9822
9823 tfd = &txq->bd[q->first_empty];
9824 txq->txb[q->first_empty] = txb;
9825 memset(tfd, 0, sizeof(*tfd));
9826 tfd->u.data.station_number = id;
9827
9828 tfd->control_flags.message_type = TX_FRAME_TYPE;
9829 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9830
9831 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009832 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009833 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009834
James Ketrenos43f66a62005-03-25 12:31:53 -06009835 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009836 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009837 else
James Ketrenosb095c382005-08-24 22:04:42 -05009838 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009839
James Ketrenosea2b26e2005-08-24 21:25:16 -05009840 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9841 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009842
James Ketrenosc848d0a2005-08-24 21:56:24 -05009843 fc = le16_to_cpu(hdr->frame_ctl);
9844 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9845
James Ketrenos43f66a62005-03-25 12:31:53 -06009846 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9847
James Ketrenosb095c382005-08-24 22:04:42 -05009848 if (likely(unicast))
9849 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9850
9851 if (txb->encrypted && !priv->ieee->host_encrypt) {
9852 switch (priv->ieee->sec.level) {
9853 case SEC_LEVEL_3:
9854 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9855 IEEE80211_FCTL_PROTECTED;
9856 /* XXX: ACK flag must be set for CCMP even if it
9857 * is a multicast/broadcast packet, because CCMP
9858 * group communication encrypted by GTK is
9859 * actually done by the AP. */
9860 if (!unicast)
9861 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9862
9863 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9864 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9865 tfd->u.data.key_index = 0;
9866 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9867 break;
9868 case SEC_LEVEL_2:
9869 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9870 IEEE80211_FCTL_PROTECTED;
9871 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9872 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9873 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9874 break;
9875 case SEC_LEVEL_1:
9876 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9877 IEEE80211_FCTL_PROTECTED;
9878 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9879 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9880 40)
9881 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9882 else
9883 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9884 break;
9885 case SEC_LEVEL_0:
9886 break;
9887 default:
9888 printk(KERN_ERR "Unknow security level %d\n",
9889 priv->ieee->sec.level);
9890 break;
9891 }
9892 } else
9893 /* No hardware encryption */
9894 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9895
9896#ifdef CONFIG_IPW_QOS
9897 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9898#endif /* CONFIG_IPW_QOS */
9899
James Ketrenos43f66a62005-03-25 12:31:53 -06009900 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009901 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9902 txb->nr_frags));
9903 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9904 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9905 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9906 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9907 i, le32_to_cpu(tfd->u.data.num_chunks),
9908 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009909 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009910 i, tfd->u.data.num_chunks,
9911 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009912 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009913 txb->fragments[i]->len - hdr_len);
9914
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009915 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009916 cpu_to_le32(pci_map_single
9917 (priv->pci_dev,
9918 txb->fragments[i]->data + hdr_len,
9919 txb->fragments[i]->len - hdr_len,
9920 PCI_DMA_TODEVICE));
9921 tfd->u.data.chunk_len[i] =
9922 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009923 }
9924
9925 if (i != txb->nr_frags) {
9926 struct sk_buff *skb;
9927 u16 remaining_bytes = 0;
9928 int j;
9929
9930 for (j = i; j < txb->nr_frags; j++)
9931 remaining_bytes += txb->fragments[j]->len - hdr_len;
9932
9933 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9934 remaining_bytes);
9935 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9936 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009937 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009938 for (j = i; j < txb->nr_frags; j++) {
9939 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009940
James Ketrenos43f66a62005-03-25 12:31:53 -06009941 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009942 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009943 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009944 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009945 }
9946 dev_kfree_skb_any(txb->fragments[i]);
9947 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009948 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009949 cpu_to_le32(pci_map_single
9950 (priv->pci_dev, skb->data,
9951 tfd->u.data.chunk_len[i],
9952 PCI_DMA_TODEVICE));
9953
9954 tfd->u.data.num_chunks =
9955 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9956 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009957 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009958 }
9959
9960 /* kick DMA */
9961 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9962 ipw_write32(priv, q->reg_w, q->first_empty);
9963
James Ketrenos227d2dc2005-07-28 16:25:55 -05009964 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009965
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009966 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009967 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9968 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009969 return NETDEV_TX_OK;
9970}
9971
9972static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9973{
9974 struct ipw_priv *priv = ieee80211_priv(dev);
9975#ifdef CONFIG_IPW_QOS
9976 int tx_id = ipw_get_tx_queue_number(priv, pri);
9977 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9978#else
9979 struct clx2_tx_queue *txq = &priv->txq[0];
9980#endif /* CONFIG_IPW_QOS */
9981
9982 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9983 return 1;
9984
9985 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009986}
9987
9988static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009989 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009990{
9991 struct ipw_priv *priv = ieee80211_priv(dev);
9992 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009993 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009994
9995 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009996 spin_lock_irqsave(&priv->lock, flags);
9997
9998 if (!(priv->status & STATUS_ASSOCIATED)) {
9999 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10000 priv->ieee->stats.tx_carrier_errors++;
10001 netif_stop_queue(dev);
10002 goto fail_unlock;
10003 }
10004
James Ketrenos227d2dc2005-07-28 16:25:55 -050010005 ret = ipw_tx_skb(priv, txb, pri);
10006 if (ret == NETDEV_TX_OK)
10007 __ipw_led_activity_on(priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010008 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010009
James Ketrenos227d2dc2005-07-28 16:25:55 -050010010 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010011
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010012 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010013 spin_unlock_irqrestore(&priv->lock, flags);
10014 return 1;
10015}
10016
10017static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10018{
10019 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010020
James Ketrenos43f66a62005-03-25 12:31:53 -060010021 priv->ieee->stats.tx_packets = priv->tx_packets;
10022 priv->ieee->stats.rx_packets = priv->rx_packets;
10023 return &priv->ieee->stats;
10024}
10025
10026static void ipw_net_set_multicast_list(struct net_device *dev)
10027{
10028
10029}
10030
10031static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10032{
10033 struct ipw_priv *priv = ieee80211_priv(dev);
10034 struct sockaddr *addr = p;
10035 if (!is_valid_ether_addr(addr->sa_data))
10036 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010037 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010038 priv->config |= CFG_CUSTOM_MAC;
10039 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10040 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10041 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010042 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010043 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010044 return 0;
10045}
10046
Jeff Garzikbf794512005-07-31 13:07:26 -040010047static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010048 struct ethtool_drvinfo *info)
10049{
10050 struct ipw_priv *p = ieee80211_priv(dev);
10051 char vers[64];
10052 char date[32];
10053 u32 len;
10054
10055 strcpy(info->driver, DRV_NAME);
10056 strcpy(info->version, DRV_VERSION);
10057
10058 len = sizeof(vers);
10059 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10060 len = sizeof(date);
10061 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10062
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010063 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010064 vers, date);
10065 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010066 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010067}
10068
10069static u32 ipw_ethtool_get_link(struct net_device *dev)
10070{
10071 struct ipw_priv *priv = ieee80211_priv(dev);
10072 return (priv->status & STATUS_ASSOCIATED) != 0;
10073}
10074
10075static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10076{
James Ketrenosb095c382005-08-24 22:04:42 -050010077 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010078}
10079
10080static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010081 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010082{
10083 struct ipw_priv *p = ieee80211_priv(dev);
10084
James Ketrenosb095c382005-08-24 22:04:42 -050010085 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010086 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010087 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010088 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010089 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010090 return 0;
10091}
10092
10093static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010094 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010095{
10096 struct ipw_priv *p = ieee80211_priv(dev);
10097 int i;
10098
James Ketrenosb095c382005-08-24 22:04:42 -050010099 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010100 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010101 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010102 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010103 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -050010104 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -060010105 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010106 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010107 return 0;
10108}
10109
10110static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010111 .get_link = ipw_ethtool_get_link,
10112 .get_drvinfo = ipw_ethtool_get_drvinfo,
10113 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10114 .get_eeprom = ipw_ethtool_get_eeprom,
10115 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010116};
10117
10118static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10119{
10120 struct ipw_priv *priv = data;
10121 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010122
James Ketrenos43f66a62005-03-25 12:31:53 -060010123 if (!priv)
10124 return IRQ_NONE;
10125
10126 spin_lock(&priv->lock);
10127
10128 if (!(priv->status & STATUS_INT_ENABLED)) {
10129 /* Shared IRQ */
10130 goto none;
10131 }
10132
James Ketrenosb095c382005-08-24 22:04:42 -050010133 inta = ipw_read32(priv, IPW_INTA_RW);
10134 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010135
James Ketrenos43f66a62005-03-25 12:31:53 -060010136 if (inta == 0xFFFFFFFF) {
10137 /* Hardware disappeared */
10138 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10139 goto none;
10140 }
10141
James Ketrenosb095c382005-08-24 22:04:42 -050010142 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010143 /* Shared interrupt */
10144 goto none;
10145 }
10146
10147 /* tell the device to stop sending interrupts */
10148 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010149
James Ketrenos43f66a62005-03-25 12:31:53 -060010150 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010151 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10152 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010153
James Ketrenos43f66a62005-03-25 12:31:53 -060010154 /* Cache INTA value for our tasklet */
10155 priv->isr_inta = inta;
10156
10157 tasklet_schedule(&priv->irq_tasklet);
10158
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010159 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010160
10161 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010162 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010163 spin_unlock(&priv->lock);
10164 return IRQ_NONE;
10165}
10166
10167static void ipw_rf_kill(void *adapter)
10168{
10169 struct ipw_priv *priv = adapter;
10170 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010171
James Ketrenos43f66a62005-03-25 12:31:53 -060010172 spin_lock_irqsave(&priv->lock, flags);
10173
10174 if (rf_kill_active(priv)) {
10175 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10176 if (priv->workqueue)
10177 queue_delayed_work(priv->workqueue,
10178 &priv->rf_kill, 2 * HZ);
10179 goto exit_unlock;
10180 }
10181
10182 /* RF Kill is now disabled, so bring the device back up */
10183
10184 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10185 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10186 "device\n");
10187
10188 /* we can not do an adapter restart while inside an irq lock */
10189 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010190 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010191 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10192 "enabled\n");
10193
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010194 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 spin_unlock_irqrestore(&priv->lock, flags);
10196}
10197
James Ketrenosc848d0a2005-08-24 21:56:24 -050010198static void ipw_bg_rf_kill(void *data)
10199{
10200 struct ipw_priv *priv = data;
10201 down(&priv->sem);
10202 ipw_rf_kill(data);
10203 up(&priv->sem);
10204}
10205
James Ketrenosa613bff2005-08-24 21:43:11 -050010206void ipw_link_up(struct ipw_priv *priv)
10207{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010208 priv->last_seq_num = -1;
10209 priv->last_frag_num = -1;
10210 priv->last_packet_time = 0;
10211
James Ketrenosa613bff2005-08-24 21:43:11 -050010212 netif_carrier_on(priv->net_dev);
10213 if (netif_queue_stopped(priv->net_dev)) {
10214 IPW_DEBUG_NOTIF("waking queue\n");
10215 netif_wake_queue(priv->net_dev);
10216 } else {
10217 IPW_DEBUG_NOTIF("starting queue\n");
10218 netif_start_queue(priv->net_dev);
10219 }
10220
James Ketrenosc848d0a2005-08-24 21:56:24 -050010221 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010222 ipw_reset_stats(priv);
10223 /* Ensure the rate is updated immediately */
10224 priv->last_rate = ipw_get_current_rate(priv);
10225 ipw_gather_stats(priv);
10226 ipw_led_link_up(priv);
10227 notify_wx_assoc_event(priv);
10228
10229 if (priv->config & CFG_BACKGROUND_SCAN)
10230 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10231}
10232
James Ketrenosc848d0a2005-08-24 21:56:24 -050010233static void ipw_bg_link_up(void *data)
10234{
10235 struct ipw_priv *priv = data;
10236 down(&priv->sem);
10237 ipw_link_up(data);
10238 up(&priv->sem);
10239}
10240
James Ketrenosa613bff2005-08-24 21:43:11 -050010241void ipw_link_down(struct ipw_priv *priv)
10242{
10243 ipw_led_link_down(priv);
10244 netif_carrier_off(priv->net_dev);
10245 netif_stop_queue(priv->net_dev);
10246 notify_wx_assoc_event(priv);
10247
10248 /* Cancel any queued work ... */
10249 cancel_delayed_work(&priv->request_scan);
10250 cancel_delayed_work(&priv->adhoc_check);
10251 cancel_delayed_work(&priv->gather_stats);
10252
10253 ipw_reset_stats(priv);
10254
James Ketrenosafbf30a2005-08-25 00:05:33 -050010255 if (!(priv->status & STATUS_EXIT_PENDING)) {
10256 /* Queue up another scan... */
10257 queue_work(priv->workqueue, &priv->request_scan);
10258 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010259}
10260
James Ketrenosc848d0a2005-08-24 21:56:24 -050010261static void ipw_bg_link_down(void *data)
10262{
10263 struct ipw_priv *priv = data;
10264 down(&priv->sem);
10265 ipw_link_down(data);
10266 up(&priv->sem);
10267}
10268
James Ketrenos43f66a62005-03-25 12:31:53 -060010269static int ipw_setup_deferred_work(struct ipw_priv *priv)
10270{
10271 int ret = 0;
10272
James Ketrenos43f66a62005-03-25 12:31:53 -060010273 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010274 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010275 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010276
James Ketrenosc848d0a2005-08-24 21:56:24 -050010277 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10278 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10279 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010280 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010281 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10282 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10283 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10284 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10285 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010286 INIT_WORK(&priv->request_scan,
James Ketrenosb095c382005-08-24 22:04:42 -050010287 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010288 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010289 (void (*)(void *))ipw_bg_gather_stats, priv);
10290 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10291 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10292 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10293 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10294 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10295 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010296 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010297 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010298 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010299 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10300 priv);
10301 INIT_WORK(&priv->merge_networks,
10302 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010303
James Ketrenosb095c382005-08-24 22:04:42 -050010304#ifdef CONFIG_IPW_QOS
10305 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10306 priv);
10307#endif /* CONFIG_IPW_QOS */
10308
James Ketrenos43f66a62005-03-25 12:31:53 -060010309 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10310 ipw_irq_tasklet, (unsigned long)priv);
10311
10312 return ret;
10313}
10314
James Ketrenos43f66a62005-03-25 12:31:53 -060010315static void shim__set_security(struct net_device *dev,
10316 struct ieee80211_security *sec)
10317{
10318 struct ipw_priv *priv = ieee80211_priv(dev);
10319 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010320 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010321 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010322 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010323 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010324 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010325 priv->ieee->sec.flags &= ~(1 << i);
10326 else {
10327 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010328 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010329 priv->ieee->sec.flags |= (1 << i);
10330 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010331 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010332 } else if (sec->level != SEC_LEVEL_1)
10333 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010334 }
10335
James Ketrenosb095c382005-08-24 22:04:42 -050010336 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010337 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010338 priv->ieee->sec.active_key = sec->active_key;
10339 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010340 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010341 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010342 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010343 } else
10344 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010345
10346 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010347 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10348 priv->ieee->sec.auth_mode = sec->auth_mode;
10349 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010350 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10351 priv->capability |= CAP_SHARED_KEY;
10352 else
10353 priv->capability &= ~CAP_SHARED_KEY;
10354 priv->status |= STATUS_SECURITY_UPDATED;
10355 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010356
James Ketrenosb095c382005-08-24 22:04:42 -050010357 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10358 priv->ieee->sec.flags |= SEC_ENABLED;
10359 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010360 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010361 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010362 priv->capability |= CAP_PRIVACY_ON;
10363 else
10364 priv->capability &= ~CAP_PRIVACY_ON;
10365 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010366
10367 if (sec->flags & SEC_ENCRYPT)
10368 priv->ieee->sec.encrypt = sec->encrypt;
Jeff Garzikbf794512005-07-31 13:07:26 -040010369
James Ketrenosb095c382005-08-24 22:04:42 -050010370 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10371 priv->ieee->sec.level = sec->level;
10372 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010373 priv->status |= STATUS_SECURITY_UPDATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -050010374 }
James Ketrenosb095c382005-08-24 22:04:42 -050010375
Zhu Yi1fbfea52005-08-05 17:22:56 +080010376 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10377 ipw_set_hwcrypto_keys(priv);
10378
Jeff Garzikbf794512005-07-31 13:07:26 -040010379 /* To match current functionality of ipw2100 (which works well w/
10380 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010381 * privacy capability changes ... */
10382#if 0
10383 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010384 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010385 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010386 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010387 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010388 IPW_DEBUG_ASSOC("Disassociating due to capability "
10389 "change.\n");
10390 ipw_disassociate(priv);
10391 }
10392#endif
10393}
10394
Jeff Garzikbf794512005-07-31 13:07:26 -040010395static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010396 struct ipw_supported_rates *rates)
10397{
10398 /* TODO: Mask out rates based on priv->rates_mask */
10399
10400 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010401 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010402 switch (priv->ieee->freq_band) {
10403 case IEEE80211_52GHZ_BAND:
10404 rates->ieee_mode = IPW_A_MODE;
10405 rates->purpose = IPW_RATE_CAPABILITIES;
10406 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10407 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10408 break;
10409
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010410 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010411 rates->ieee_mode = IPW_G_MODE;
10412 rates->purpose = IPW_RATE_CAPABILITIES;
10413 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10414 IEEE80211_CCK_DEFAULT_RATES_MASK);
10415 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10416 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10417 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10418 }
10419 break;
10420 }
10421
10422 return 0;
10423}
10424
Jeff Garzikbf794512005-07-31 13:07:26 -040010425static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010426{
James Ketrenos43f66a62005-03-25 12:31:53 -060010427 /* This is only called from ipw_up, which resets/reloads the firmware
10428 so, we don't need to first disable the card before we configure
10429 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010430 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010431 goto error;
10432
10433 /* initialize adapter address */
10434 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10435 goto error;
10436
10437 /* set basic system config settings */
10438 init_sys_config(&priv->sys_config);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010439 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10440 priv->sys_config.answer_broadcast_ssid_probe = 1;
10441 else
10442 priv->sys_config.answer_broadcast_ssid_probe = 0;
10443
James Ketrenos43f66a62005-03-25 12:31:53 -060010444 if (ipw_send_system_config(priv, &priv->sys_config))
10445 goto error;
10446
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010447 init_supported_rates(priv, &priv->rates);
10448 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010449 goto error;
10450
10451 /* Set request-to-send threshold */
10452 if (priv->rts_threshold) {
10453 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10454 goto error;
10455 }
James Ketrenosb095c382005-08-24 22:04:42 -050010456#ifdef CONFIG_IPW_QOS
10457 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10458 ipw_qos_activate(priv, NULL);
10459#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010460
10461 if (ipw_set_random_seed(priv))
10462 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010463
James Ketrenos43f66a62005-03-25 12:31:53 -060010464 /* final state transition to the RUN state */
10465 if (ipw_send_host_complete(priv))
10466 goto error;
10467
James Ketrenose6666192005-08-12 09:17:04 -050010468 priv->status |= STATUS_INIT;
10469
10470 ipw_led_init(priv);
10471 ipw_led_radio_on(priv);
10472 priv->notif_missed_beacons = 0;
10473
10474 /* Set hardware WEP key if it is configured. */
10475 if ((priv->capability & CAP_PRIVACY_ON) &&
10476 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10477 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10478 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010479
10480 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010481
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010482 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010483 return -EIO;
10484}
10485
James Ketrenos4f36f802005-08-03 20:36:56 -050010486/*
10487 * NOTE:
10488 *
10489 * These tables have been tested in conjunction with the
10490 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10491 *
10492 * Altering this values, using it on other hardware, or in geographies
10493 * not intended for resale of the above mentioned Intel adapters has
10494 * not been tested.
10495 *
10496 */
10497static const struct ieee80211_geo ipw_geos[] = {
10498 { /* Restricted */
10499 "---",
10500 .bg_channels = 11,
10501 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10502 {2427, 4}, {2432, 5}, {2437, 6},
10503 {2442, 7}, {2447, 8}, {2452, 9},
10504 {2457, 10}, {2462, 11}},
10505 },
10506
10507 { /* Custom US/Canada */
10508 "ZZF",
10509 .bg_channels = 11,
10510 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10511 {2427, 4}, {2432, 5}, {2437, 6},
10512 {2442, 7}, {2447, 8}, {2452, 9},
10513 {2457, 10}, {2462, 11}},
10514 .a_channels = 8,
10515 .a = {{5180, 36},
10516 {5200, 40},
10517 {5220, 44},
10518 {5240, 48},
10519 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10520 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10521 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10522 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10523 },
10524
10525 { /* Rest of World */
10526 "ZZD",
10527 .bg_channels = 13,
10528 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10529 {2427, 4}, {2432, 5}, {2437, 6},
10530 {2442, 7}, {2447, 8}, {2452, 9},
10531 {2457, 10}, {2462, 11}, {2467, 12},
10532 {2472, 13}},
10533 },
10534
10535 { /* Custom USA & Europe & High */
10536 "ZZA",
10537 .bg_channels = 11,
10538 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10539 {2427, 4}, {2432, 5}, {2437, 6},
10540 {2442, 7}, {2447, 8}, {2452, 9},
10541 {2457, 10}, {2462, 11}},
10542 .a_channels = 13,
10543 .a = {{5180, 36},
10544 {5200, 40},
10545 {5220, 44},
10546 {5240, 48},
10547 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10548 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10549 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10550 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10551 {5745, 149},
10552 {5765, 153},
10553 {5785, 157},
10554 {5805, 161},
10555 {5825, 165}},
10556 },
10557
10558 { /* Custom NA & Europe */
10559 "ZZB",
10560 .bg_channels = 11,
10561 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10562 {2427, 4}, {2432, 5}, {2437, 6},
10563 {2442, 7}, {2447, 8}, {2452, 9},
10564 {2457, 10}, {2462, 11}},
10565 .a_channels = 13,
10566 .a = {{5180, 36},
10567 {5200, 40},
10568 {5220, 44},
10569 {5240, 48},
10570 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10571 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10572 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10573 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10574 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10575 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10576 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10577 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10578 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10579 },
10580
10581 { /* Custom Japan */
10582 "ZZC",
10583 .bg_channels = 11,
10584 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10585 {2427, 4}, {2432, 5}, {2437, 6},
10586 {2442, 7}, {2447, 8}, {2452, 9},
10587 {2457, 10}, {2462, 11}},
10588 .a_channels = 4,
10589 .a = {{5170, 34}, {5190, 38},
10590 {5210, 42}, {5230, 46}},
10591 },
10592
10593 { /* Custom */
10594 "ZZM",
10595 .bg_channels = 11,
10596 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10597 {2427, 4}, {2432, 5}, {2437, 6},
10598 {2442, 7}, {2447, 8}, {2452, 9},
10599 {2457, 10}, {2462, 11}},
10600 },
10601
10602 { /* Europe */
10603 "ZZE",
10604 .bg_channels = 13,
10605 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10606 {2427, 4}, {2432, 5}, {2437, 6},
10607 {2442, 7}, {2447, 8}, {2452, 9},
10608 {2457, 10}, {2462, 11}, {2467, 12},
10609 {2472, 13}},
10610 .a_channels = 19,
10611 .a = {{5180, 36},
10612 {5200, 40},
10613 {5220, 44},
10614 {5240, 48},
10615 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10616 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10617 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10618 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10619 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10620 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10621 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10622 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10623 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10624 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10625 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10626 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10627 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10628 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10629 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10630 },
10631
10632 { /* Custom Japan */
10633 "ZZJ",
10634 .bg_channels = 14,
10635 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10636 {2427, 4}, {2432, 5}, {2437, 6},
10637 {2442, 7}, {2447, 8}, {2452, 9},
10638 {2457, 10}, {2462, 11}, {2467, 12},
10639 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10640 .a_channels = 4,
10641 .a = {{5170, 34}, {5190, 38},
10642 {5210, 42}, {5230, 46}},
10643 },
10644
10645 { /* High Band */
10646 "ZZH",
10647 .bg_channels = 13,
10648 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10649 {2427, 4}, {2432, 5}, {2437, 6},
10650 {2442, 7}, {2447, 8}, {2452, 9},
10651 {2457, 10}, {2462, 11},
10652 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10653 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10654 .a_channels = 4,
10655 .a = {{5745, 149}, {5765, 153},
10656 {5785, 157}, {5805, 161}},
10657 },
10658
10659 { /* Custom Europe */
10660 "ZZG",
10661 .bg_channels = 13,
10662 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10663 {2427, 4}, {2432, 5}, {2437, 6},
10664 {2442, 7}, {2447, 8}, {2452, 9},
10665 {2457, 10}, {2462, 11},
10666 {2467, 12}, {2472, 13}},
10667 .a_channels = 4,
10668 .a = {{5180, 36}, {5200, 40},
10669 {5220, 44}, {5240, 48}},
10670 },
10671
10672 { /* Europe */
10673 "ZZK",
10674 .bg_channels = 13,
10675 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10676 {2427, 4}, {2432, 5}, {2437, 6},
10677 {2442, 7}, {2447, 8}, {2452, 9},
10678 {2457, 10}, {2462, 11},
10679 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10680 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10681 .a_channels = 24,
10682 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10683 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10684 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10685 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10686 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10687 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10688 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10689 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10690 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10691 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10692 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10693 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10694 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10695 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10696 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10697 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10698 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10699 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10700 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10701 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10702 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10703 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10704 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10705 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10706 },
10707
10708 { /* Europe */
10709 "ZZL",
10710 .bg_channels = 11,
10711 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10712 {2427, 4}, {2432, 5}, {2437, 6},
10713 {2442, 7}, {2447, 8}, {2452, 9},
10714 {2457, 10}, {2462, 11}},
10715 .a_channels = 13,
10716 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10717 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10718 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10719 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10720 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10721 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10722 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10723 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10724 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10725 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10726 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10727 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10728 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10729 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010730};
10731
James Ketrenos43f66a62005-03-25 12:31:53 -060010732#define MAX_HW_RESTARTS 5
10733static int ipw_up(struct ipw_priv *priv)
10734{
James Ketrenos4f36f802005-08-03 20:36:56 -050010735 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010736
10737 if (priv->status & STATUS_EXIT_PENDING)
10738 return -EIO;
10739
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010740 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010741 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010742 * Also start the clocks. */
10743 rc = ipw_load(priv);
10744 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010745 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010746 return rc;
10747 }
10748
10749 ipw_init_ordinals(priv);
10750 if (!(priv->config & CFG_CUSTOM_MAC))
10751 eeprom_parse_mac(priv, priv->mac_addr);
10752 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10753
James Ketrenos4f36f802005-08-03 20:36:56 -050010754 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10755 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10756 ipw_geos[j].name, 3))
10757 break;
10758 }
10759 if (j == ARRAY_SIZE(ipw_geos))
10760 j = 0;
10761 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10762 IPW_WARNING("Could not set geography.");
10763 return 0;
10764 }
10765
10766 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10767 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010768
James Ketrenosb095c382005-08-24 22:04:42 -050010769 if (priv->status & STATUS_RF_KILL_SW) {
10770 IPW_WARNING("Radio disabled by module parameter.\n");
10771 return 0;
10772 } else if (rf_kill_active(priv)) {
10773 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10774 "Kill switch must be turned off for "
10775 "wireless networking to work.\n");
10776 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10777 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010778 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010779 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010780
10781 rc = ipw_config(priv);
10782 if (!rc) {
10783 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010784
James Ketrenose6666192005-08-12 09:17:04 -050010785 /* If configure to try and auto-associate, kick
10786 * off a scan. */
10787 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010788
James Ketrenos43f66a62005-03-25 12:31:53 -060010789 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010790 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010791
James Ketrenosc848d0a2005-08-24 21:56:24 -050010792 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010793 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10794 i, MAX_HW_RESTARTS);
10795
10796 /* We had an error bringing up the hardware, so take it
10797 * all the way back down so we can try again */
10798 ipw_down(priv);
10799 }
10800
Jeff Garzikbf794512005-07-31 13:07:26 -040010801 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010802 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010803 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010804
James Ketrenos43f66a62005-03-25 12:31:53 -060010805 return -EIO;
10806}
10807
James Ketrenosc848d0a2005-08-24 21:56:24 -050010808static void ipw_bg_up(void *data)
10809{
10810 struct ipw_priv *priv = data;
10811 down(&priv->sem);
10812 ipw_up(data);
10813 up(&priv->sem);
10814}
10815
James Ketrenosb095c382005-08-24 22:04:42 -050010816static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010817{
James Ketrenosb095c382005-08-24 22:04:42 -050010818 int i;
10819
10820 if (priv->status & STATUS_SCANNING) {
10821 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10822 ipw_abort_scan(priv);
10823 }
10824
10825 if (priv->status & STATUS_ASSOCIATED) {
10826 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10827 ipw_disassociate(priv);
10828 }
10829
10830 ipw_led_shutdown(priv);
10831
10832 /* Wait up to 1s for status to change to not scanning and not
10833 * associated (disassociation can take a while for a ful 802.11
10834 * exchange */
10835 for (i = 1000; i && (priv->status &
10836 (STATUS_DISASSOCIATING |
10837 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10838 udelay(10);
10839
10840 if (priv->status & (STATUS_DISASSOCIATING |
10841 STATUS_ASSOCIATED | STATUS_SCANNING))
10842 IPW_DEBUG_INFO("Still associated or scanning...\n");
10843 else
10844 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10845
James Ketrenosc848d0a2005-08-24 21:56:24 -050010846 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010847 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010848
10849 priv->status &= ~STATUS_INIT;
10850}
10851
10852static void ipw_down(struct ipw_priv *priv)
10853{
10854 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10855
10856 priv->status |= STATUS_EXIT_PENDING;
10857
10858 if (ipw_is_init(priv))
10859 ipw_deinit(priv);
10860
10861 /* Wipe out the EXIT_PENDING status bit if we are not actually
10862 * exiting the module */
10863 if (!exit_pending)
10864 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010865
10866 /* tell the device to stop sending interrupts */
10867 ipw_disable_interrupts(priv);
10868
10869 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010870 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010871 netif_carrier_off(priv->net_dev);
10872 netif_stop_queue(priv->net_dev);
10873
10874 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010875
10876 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010877}
10878
James Ketrenosc848d0a2005-08-24 21:56:24 -050010879static void ipw_bg_down(void *data)
10880{
10881 struct ipw_priv *priv = data;
10882 down(&priv->sem);
10883 ipw_down(data);
10884 up(&priv->sem);
10885}
10886
James Ketrenosafbf30a2005-08-25 00:05:33 -050010887#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050010888static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
10889{
James Ketrenosea2b26e2005-08-24 21:25:16 -050010890 struct iwreq *wrq = (struct iwreq *)rq;
10891 int ret = -1;
10892 switch (cmd) {
10893 case IPW_IOCTL_WPA_SUPPLICANT:
10894 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
10895 return ret;
10896
10897 default:
10898 return -EOPNOTSUPP;
10899 }
10900
James Ketrenosea2b26e2005-08-24 21:25:16 -050010901 return -EOPNOTSUPP;
10902}
James Ketrenosafbf30a2005-08-25 00:05:33 -050010903#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -050010904
James Ketrenos43f66a62005-03-25 12:31:53 -060010905/* Called by register_netdev() */
10906static int ipw_net_init(struct net_device *dev)
10907{
10908 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010909 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010910
James Ketrenosc848d0a2005-08-24 21:56:24 -050010911 if (ipw_up(priv)) {
10912 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010913 return -EIO;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010914 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010915
James Ketrenosc848d0a2005-08-24 21:56:24 -050010916 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010917 return 0;
10918}
10919
10920/* PCI driver stuff */
10921static struct pci_device_id card_ids[] = {
10922 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10923 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10924 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10925 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10926 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10927 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10928 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10929 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10930 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10931 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10932 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10933 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10934 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10935 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10936 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10937 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10938 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10939 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010940 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010941 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010942 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10943 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010944
James Ketrenos43f66a62005-03-25 12:31:53 -060010945 /* required last entry */
10946 {0,}
10947};
10948
10949MODULE_DEVICE_TABLE(pci, card_ids);
10950
10951static struct attribute *ipw_sysfs_entries[] = {
10952 &dev_attr_rf_kill.attr,
10953 &dev_attr_direct_dword.attr,
10954 &dev_attr_indirect_byte.attr,
10955 &dev_attr_indirect_dword.attr,
10956 &dev_attr_mem_gpio_reg.attr,
10957 &dev_attr_command_event_reg.attr,
10958 &dev_attr_nic_type.attr,
10959 &dev_attr_status.attr,
10960 &dev_attr_cfg.attr,
10961 &dev_attr_dump_errors.attr,
10962 &dev_attr_dump_events.attr,
10963 &dev_attr_eeprom_delay.attr,
10964 &dev_attr_ucode_version.attr,
10965 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010966 &dev_attr_scan_age.attr,
10967 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010968 &dev_attr_speed_scan.attr,
10969 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010970 NULL
10971};
10972
10973static struct attribute_group ipw_attribute_group = {
10974 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010975 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010976};
10977
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010978static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010979{
10980 int err = 0;
10981 struct net_device *net_dev;
10982 void __iomem *base;
10983 u32 length, val;
10984 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010985 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010986
10987 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10988 if (net_dev == NULL) {
10989 err = -ENOMEM;
10990 goto out;
10991 }
10992
10993 priv = ieee80211_priv(net_dev);
10994 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010995
James Ketrenos43f66a62005-03-25 12:31:53 -060010996 priv->net_dev = net_dev;
10997 priv->pci_dev = pdev;
10998#ifdef CONFIG_IPW_DEBUG
10999 ipw_debug_level = debug;
11000#endif
11001 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011002 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11003 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011004
James Ketrenosc848d0a2005-08-24 21:56:24 -050011005 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011006 if (pci_enable_device(pdev)) {
11007 err = -ENODEV;
11008 goto out_free_ieee80211;
11009 }
11010
11011 pci_set_master(pdev);
11012
Tobias Klauser0e08b442005-06-20 14:28:41 -070011013 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011014 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011015 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011016 if (err) {
11017 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11018 goto out_pci_disable_device;
11019 }
11020
11021 pci_set_drvdata(pdev, priv);
11022
11023 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011024 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011025 goto out_pci_disable_device;
11026
Jeff Garzikbf794512005-07-31 13:07:26 -040011027 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011028 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011029 pci_read_config_dword(pdev, 0x40, &val);
11030 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011031 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011032
James Ketrenos43f66a62005-03-25 12:31:53 -060011033 length = pci_resource_len(pdev, 0);
11034 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011035
James Ketrenos43f66a62005-03-25 12:31:53 -060011036 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11037 if (!base) {
11038 err = -ENODEV;
11039 goto out_pci_release_regions;
11040 }
11041
11042 priv->hw_base = base;
11043 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11044 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11045
11046 err = ipw_setup_deferred_work(priv);
11047 if (err) {
11048 IPW_ERROR("Unable to setup deferred work\n");
11049 goto out_iounmap;
11050 }
11051
James Ketrenosb095c382005-08-24 22:04:42 -050011052 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011053
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011054 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011055 if (err) {
11056 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11057 goto out_destroy_workqueue;
11058 }
11059
11060 SET_MODULE_OWNER(net_dev);
11061 SET_NETDEV_DEV(net_dev, &pdev->dev);
11062
James Ketrenosa613bff2005-08-24 21:43:11 -050011063 ipw_wx_data.spy_data = &priv->ieee->spy_data;
11064 ipw_wx_data.ieee80211 = priv->ieee;
11065
James Ketrenosc848d0a2005-08-24 21:56:24 -050011066 down(&priv->sem);
11067
James Ketrenos43f66a62005-03-25 12:31:53 -060011068 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11069 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011070 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011071
James Ketrenosb095c382005-08-24 22:04:42 -050011072#ifdef CONFIG_IPW_QOS
James Ketrenos2b184d52005-08-03 20:33:14 -050011073 priv->ieee->handle_management = ipw_handle_management;
James Ketrenosb095c382005-08-24 22:04:42 -050011074#endif /* CONFIG_IPW_QOS */
11075
James Ketrenosc848d0a2005-08-24 21:56:24 -050011076 priv->ieee->perfect_rssi = -20;
11077 priv->ieee->worst_rssi = -85;
11078
James Ketrenos43f66a62005-03-25 12:31:53 -060011079 net_dev->open = ipw_net_open;
11080 net_dev->stop = ipw_net_stop;
11081 net_dev->init = ipw_net_init;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011082#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050011083 net_dev->do_ioctl = ipw_ioctl;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011084#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011085 net_dev->get_stats = ipw_net_get_stats;
11086 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11087 net_dev->set_mac_address = ipw_net_set_mac_address;
11088 net_dev->get_wireless_stats = ipw_get_wireless_stats;
James Ketrenosa613bff2005-08-24 21:43:11 -050011089 net_dev->wireless_data = &ipw_wx_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 net_dev->wireless_handlers = &ipw_wx_handler_def;
11091 net_dev->ethtool_ops = &ipw_ethtool_ops;
11092 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011093 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011094 net_dev->mem_start = pci_resource_start(pdev, 0);
11095 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11096
11097 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11098 if (err) {
11099 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011100 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011101 goto out_release_irq;
11102 }
11103
James Ketrenosc848d0a2005-08-24 21:56:24 -050011104 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011105 err = register_netdev(net_dev);
11106 if (err) {
11107 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011108 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011109 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011110 return 0;
11111
James Ketrenosa613bff2005-08-24 21:43:11 -050011112 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011113 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011114 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011115 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011116 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011117 destroy_workqueue(priv->workqueue);
11118 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011119 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011120 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011121 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011122 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011123 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011124 pci_disable_device(pdev);
11125 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011126 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011127 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011128 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011129 return err;
11130}
11131
11132static void ipw_pci_remove(struct pci_dev *pdev)
11133{
11134 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011135 struct list_head *p, *q;
11136 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011137
James Ketrenos43f66a62005-03-25 12:31:53 -060011138 if (!priv)
11139 return;
11140
James Ketrenosb095c382005-08-24 22:04:42 -050011141 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011142
11143 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011144 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -050011145 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011146
James Ketrenosb095c382005-08-24 22:04:42 -050011147 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011148
11149 unregister_netdev(priv->net_dev);
11150
11151 if (priv->rxq) {
11152 ipw_rx_queue_free(priv, priv->rxq);
11153 priv->rxq = NULL;
11154 }
11155 ipw_tx_queue_free(priv);
11156
11157 /* ipw_down will ensure that there is no more pending work
11158 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011159 cancel_delayed_work(&priv->adhoc_check);
11160 cancel_delayed_work(&priv->gather_stats);
11161 cancel_delayed_work(&priv->request_scan);
11162 cancel_delayed_work(&priv->rf_kill);
11163 cancel_delayed_work(&priv->scan_check);
11164 destroy_workqueue(priv->workqueue);
11165 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011166
James Ketrenosafbf30a2005-08-25 00:05:33 -050011167 /* Free MAC hash list for ADHOC */
11168 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11169 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11170 kfree(list_entry(p, struct ipw_ibss_seq, list));
11171 list_del(p);
11172 }
11173 }
11174
James Ketrenos43f66a62005-03-25 12:31:53 -060011175 free_irq(pdev->irq, priv);
11176 iounmap(priv->hw_base);
11177 pci_release_regions(pdev);
11178 pci_disable_device(pdev);
11179 pci_set_drvdata(pdev, NULL);
11180 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011181 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011182}
11183
James Ketrenos43f66a62005-03-25 12:31:53 -060011184#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011185static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011186{
11187 struct ipw_priv *priv = pci_get_drvdata(pdev);
11188 struct net_device *dev = priv->net_dev;
11189
11190 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11191
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011192 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011193 ipw_down(priv);
11194
11195 /* Remove the PRESENT state of the device */
11196 netif_device_detach(dev);
11197
James Ketrenos43f66a62005-03-25 12:31:53 -060011198 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011199 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011200 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011201
James Ketrenos43f66a62005-03-25 12:31:53 -060011202 return 0;
11203}
11204
11205static int ipw_pci_resume(struct pci_dev *pdev)
11206{
11207 struct ipw_priv *priv = pci_get_drvdata(pdev);
11208 struct net_device *dev = priv->net_dev;
11209 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011210
James Ketrenos43f66a62005-03-25 12:31:53 -060011211 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11212
James Ketrenosea2b26e2005-08-24 21:25:16 -050011213 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011214 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011215 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011216
James Ketrenos43f66a62005-03-25 12:31:53 -060011217 /*
11218 * Suspend/Resume resets the PCI configuration space, so we have to
11219 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11220 * from interfering with C3 CPU state. pci_restore_state won't help
11221 * here since it only restores the first 64 bytes pci config header.
11222 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011223 pci_read_config_dword(pdev, 0x40, &val);
11224 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011225 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11226
11227 /* Set the device back into the PRESENT state; this will also wake
11228 * the queue of needed */
11229 netif_device_attach(dev);
11230
11231 /* Bring the device back up */
11232 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011233
James Ketrenos43f66a62005-03-25 12:31:53 -060011234 return 0;
11235}
11236#endif
11237
11238/* driver initialization stuff */
11239static struct pci_driver ipw_driver = {
11240 .name = DRV_NAME,
11241 .id_table = card_ids,
11242 .probe = ipw_pci_probe,
11243 .remove = __devexit_p(ipw_pci_remove),
11244#ifdef CONFIG_PM
11245 .suspend = ipw_pci_suspend,
11246 .resume = ipw_pci_resume,
11247#endif
11248};
11249
11250static int __init ipw_init(void)
11251{
11252 int ret;
11253
11254 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11255 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11256
11257 ret = pci_module_init(&ipw_driver);
11258 if (ret) {
11259 IPW_ERROR("Unable to initialize PCI module\n");
11260 return ret;
11261 }
11262
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011263 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011264 if (ret) {
11265 IPW_ERROR("Unable to create driver sysfs file\n");
11266 pci_unregister_driver(&ipw_driver);
11267 return ret;
11268 }
11269
11270 return ret;
11271}
11272
11273static void __exit ipw_exit(void)
11274{
11275 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11276 pci_unregister_driver(&ipw_driver);
11277}
11278
11279module_param(disable, int, 0444);
11280MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11281
11282module_param(associate, int, 0444);
11283MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11284
11285module_param(auto_create, int, 0444);
11286MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11287
James Ketrenosa613bff2005-08-24 21:43:11 -050011288module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011289MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011290
James Ketrenos43f66a62005-03-25 12:31:53 -060011291module_param(debug, int, 0444);
11292MODULE_PARM_DESC(debug, "debug output mask");
11293
11294module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011295MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011296
James Ketrenosb095c382005-08-24 22:04:42 -050011297#ifdef CONFIG_IPW_QOS
11298module_param(qos_enable, int, 0444);
11299MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11300
11301module_param(qos_burst_enable, int, 0444);
11302MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11303
11304module_param(qos_no_ack_mask, int, 0444);
11305MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11306
11307module_param(burst_duration_CCK, int, 0444);
11308MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11309
11310module_param(burst_duration_OFDM, int, 0444);
11311MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11312#endif /* CONFIG_IPW_QOS */
11313
11314#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011315module_param(mode, int, 0444);
11316MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11317#else
11318module_param(mode, int, 0444);
11319MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11320#endif
11321
James Ketrenosb095c382005-08-24 22:04:42 -050011322module_param(hwcrypto, int, 0444);
11323MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11324
James Ketrenos43f66a62005-03-25 12:31:53 -060011325module_exit(ipw_exit);
11326module_init(ipw_init);