blob: 2633e0de7f7956728a5fc70bf96bd95795c5a5a5 [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
2087static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2088{
2089 struct ipw_rts_threshold rts_threshold = {
2090 .rts_threshold = rts,
2091 };
2092 struct host_cmd cmd = {
2093 .cmd = IPW_CMD_RTS_THRESHOLD,
2094 .len = sizeof(rts_threshold)
2095 };
2096
2097 if (!priv) {
2098 IPW_ERROR("Invalid args\n");
2099 return -1;
2100 }
2101
James Ketrenosafbf30a2005-08-25 00:05:33 -05002102 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002103 if (ipw_send_cmd(priv, &cmd)) {
2104 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
2105 return -1;
2106 }
2107
2108 return 0;
2109}
2110
2111static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2112{
2113 struct ipw_frag_threshold frag_threshold = {
2114 .frag_threshold = frag,
2115 };
2116 struct host_cmd cmd = {
2117 .cmd = IPW_CMD_FRAG_THRESHOLD,
2118 .len = sizeof(frag_threshold)
2119 };
2120
2121 if (!priv) {
2122 IPW_ERROR("Invalid args\n");
2123 return -1;
2124 }
2125
James Ketrenosafbf30a2005-08-25 00:05:33 -05002126 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
James Ketrenos43f66a62005-03-25 12:31:53 -06002127 if (ipw_send_cmd(priv, &cmd)) {
2128 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
2129 return -1;
2130 }
2131
2132 return 0;
2133}
2134
2135static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2136{
2137 struct host_cmd cmd = {
2138 .cmd = IPW_CMD_POWER_MODE,
2139 .len = sizeof(u32)
2140 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002141 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002142
2143 if (!priv) {
2144 IPW_ERROR("Invalid args\n");
2145 return -1;
2146 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002147
James Ketrenos43f66a62005-03-25 12:31:53 -06002148 /* If on battery, set to 3, if AC set to CAM, else user
2149 * level */
2150 switch (mode) {
2151 case IPW_POWER_BATTERY:
2152 *param = IPW_POWER_INDEX_3;
2153 break;
2154 case IPW_POWER_AC:
2155 *param = IPW_POWER_MODE_CAM;
2156 break;
2157 default:
2158 *param = mode;
2159 break;
2160 }
2161
2162 if (ipw_send_cmd(priv, &cmd)) {
2163 IPW_ERROR("failed to send POWER_MODE command\n");
2164 return -1;
2165 }
2166
2167 return 0;
2168}
2169
James Ketrenosafbf30a2005-08-25 00:05:33 -05002170static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2171{
2172 struct ipw_retry_limit retry_limit = {
2173 .short_retry_limit = slimit,
2174 .long_retry_limit = llimit
2175 };
2176 struct host_cmd cmd = {
2177 .cmd = IPW_CMD_RETRY_LIMIT,
2178 .len = sizeof(retry_limit)
2179 };
2180
2181 if (!priv) {
2182 IPW_ERROR("Invalid args\n");
2183 return -1;
2184 }
2185
2186 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
2187 if (ipw_send_cmd(priv, &cmd)) {
2188 IPW_ERROR("failed to send RETRY_LIMIT command\n");
2189 return -1;
2190 }
2191
2192 return 0;
2193}
2194
James Ketrenos43f66a62005-03-25 12:31:53 -06002195/*
2196 * The IPW device contains a Microwire compatible EEPROM that stores
2197 * various data like the MAC address. Usually the firmware has exclusive
2198 * access to the eeprom, but during device initialization (before the
2199 * device driver has sent the HostComplete command to the firmware) the
2200 * device driver has read access to the EEPROM by way of indirect addressing
2201 * through a couple of memory mapped registers.
2202 *
2203 * The following is a simplified implementation for pulling data out of the
2204 * the eeprom, along with some helper functions to find information in
2205 * the per device private data's copy of the eeprom.
2206 *
2207 * NOTE: To better understand how these functions work (i.e what is a chip
2208 * select and why do have to keep driving the eeprom clock?), read
2209 * just about any data sheet for a Microwire compatible EEPROM.
2210 */
2211
2212/* write a 32 bit value into the indirect accessor register */
2213static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2214{
2215 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002216
James Ketrenos43f66a62005-03-25 12:31:53 -06002217 /* the eeprom requires some time to complete the operation */
2218 udelay(p->eeprom_delay);
2219
2220 return;
2221}
2222
2223/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002224static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002225{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002226 eeprom_write_reg(priv, 0);
2227 eeprom_write_reg(priv, EEPROM_BIT_CS);
2228 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2229 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002230}
2231
2232/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002233static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002234{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002235 eeprom_write_reg(priv, EEPROM_BIT_CS);
2236 eeprom_write_reg(priv, 0);
2237 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002238}
2239
2240/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002241static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002242{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002243 int d = (bit ? EEPROM_BIT_DI : 0);
2244 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2245 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002246}
2247
2248/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002249static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002250{
2251 int i;
2252
2253 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002254 eeprom_write_bit(priv, 1);
2255 eeprom_write_bit(priv, op & 2);
2256 eeprom_write_bit(priv, op & 1);
2257 for (i = 7; i >= 0; i--) {
2258 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002259 }
2260}
2261
2262/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002263static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002264{
2265 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002266 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002267
James Ketrenos43f66a62005-03-25 12:31:53 -06002268 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002269 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002270
2271 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002272 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002273
2274 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002275 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002276 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002277 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2278 eeprom_write_reg(priv, EEPROM_BIT_CS);
2279 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2280 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002281 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002282
James Ketrenos43f66a62005-03-25 12:31:53 -06002283 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002284 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002285 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002286
James Ketrenos43f66a62005-03-25 12:31:53 -06002287 return r;
2288}
2289
2290/* helper function for pulling the mac address out of the private */
2291/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002292static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002293{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002294 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002295}
2296
2297/*
2298 * Either the device driver (i.e. the host) or the firmware can
2299 * load eeprom data into the designated region in SRAM. If neither
2300 * happens then the FW will shutdown with a fatal error.
2301 *
2302 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2303 * bit needs region of shared SRAM needs to be non-zero.
2304 */
2305static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2306{
2307 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002308 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002309
James Ketrenos43f66a62005-03-25 12:31:53 -06002310 IPW_DEBUG_TRACE(">>\n");
2311
2312 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002313 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002314 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002315
Jeff Garzikbf794512005-07-31 13:07:26 -04002316 /*
2317 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002318 copy. Otherwise let the firmware know to perform the operation
2319 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002320 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002321 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2322 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2323
2324 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002325 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002326 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002327
2328 /* Do not load eeprom data on fatal error or suspend */
2329 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2330 } else {
2331 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2332
2333 /* Load eeprom data on fatal error or suspend */
2334 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2335 }
2336
2337 IPW_DEBUG_TRACE("<<\n");
2338}
2339
James Ketrenos43f66a62005-03-25 12:31:53 -06002340static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2341{
2342 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002343 if (!count)
2344 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002345 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002346 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002347 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002348}
2349
2350static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2351{
James Ketrenosb095c382005-08-24 22:04:42 -05002352 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002353 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002354 sizeof(struct command_block));
2355}
2356
2357static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002358{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002359
2360 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002361
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 /* Start the dma */
2363 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002364
James Ketrenos43f66a62005-03-25 12:31:53 -06002365 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002366 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002367
2368 IPW_DEBUG_FW("<< : \n");
2369 return 0;
2370}
2371
2372static void ipw_fw_dma_abort(struct ipw_priv *priv)
2373{
2374 u32 control = 0;
2375
2376 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002377
2378 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002379 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002380 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002381 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002382
James Ketrenos43f66a62005-03-25 12:31:53 -06002383 IPW_DEBUG_FW("<< \n");
2384}
2385
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002386static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2387 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002388{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002389 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002390 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002391 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002392 IPW_DEBUG_FW(">> :\n");
2393
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002394 ipw_write_indirect(priv, address, (u8 *) cb,
2395 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002396
2397 IPW_DEBUG_FW("<< :\n");
2398 return 0;
2399
2400}
2401
2402static int ipw_fw_dma_kick(struct ipw_priv *priv)
2403{
2404 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002405 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002406
2407 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002408
James Ketrenos43f66a62005-03-25 12:31:53 -06002409 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002410 ipw_fw_dma_write_command_block(priv, index,
2411 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002412
2413 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002414 ipw_clear_bit(priv, IPW_RESET_REG,
2415 IPW_RESET_REG_MASTER_DISABLED |
2416 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002417
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002418 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002419 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002420 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002421
2422 IPW_DEBUG_FW("<< :\n");
2423 return 0;
2424}
2425
2426static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2427{
2428 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002429 u32 register_value = 0;
2430 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002431
2432 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002433 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002434 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002435
2436 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002437 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2438 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002439
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002440 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002441 cb_fields_address = address;
2442 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002443 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002444
2445 cb_fields_address += sizeof(u32);
2446 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002447 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002448
2449 cb_fields_address += sizeof(u32);
2450 register_value = ipw_read_reg32(priv, cb_fields_address);
2451 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2452 register_value);
2453
2454 cb_fields_address += sizeof(u32);
2455 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002456 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002457
2458 IPW_DEBUG_FW(">> :\n");
2459}
2460
2461static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2462{
2463 u32 current_cb_address = 0;
2464 u32 current_cb_index = 0;
2465
2466 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002467 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002468
James Ketrenosb095c382005-08-24 22:04:42 -05002469 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002470 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002471
James Ketrenos43f66a62005-03-25 12:31:53 -06002472 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002473 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002474
2475 IPW_DEBUG_FW(">> :\n");
2476 return current_cb_index;
2477
2478}
2479
2480static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2481 u32 src_address,
2482 u32 dest_address,
2483 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002484 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002485{
2486
Jeff Garzikbf794512005-07-31 13:07:26 -04002487 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002488 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2489 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002490 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002491 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002492
2493 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2494 src_address, dest_address, length);
2495
2496 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2497 return -1;
2498
2499 last_cb_element = priv->sram_desc.last_cb_index;
2500 cb = &priv->sram_desc.cb_list[last_cb_element];
2501 priv->sram_desc.last_cb_index++;
2502
2503 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002504 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002505 control |= CB_INT_ENABLED;
2506
2507 if (is_last)
2508 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002509
James Ketrenos43f66a62005-03-25 12:31:53 -06002510 control |= length;
2511
2512 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002513 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002514
2515 /* Copy the Source and Destination addresses */
2516 cb->dest_addr = dest_address;
2517 cb->source_addr = src_address;
2518
2519 /* Copy the Control Word last */
2520 cb->control = control;
2521
2522 return 0;
2523}
2524
2525static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002526 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002527{
2528 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002529 u32 src_offset = 0;
2530 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002531 int status = 0;
2532 IPW_DEBUG_FW(">> \n");
2533 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2534 src_phys, dest_address, length);
2535 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002536 status = ipw_fw_dma_add_command_block(priv,
2537 src_phys + src_offset,
2538 dest_address +
2539 dest_offset,
2540 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002541 if (status) {
2542 IPW_DEBUG_FW_INFO(": Failed\n");
2543 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002544 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002545 IPW_DEBUG_FW_INFO(": Added new cb\n");
2546
2547 src_offset += CB_MAX_LENGTH;
2548 dest_offset += CB_MAX_LENGTH;
2549 bytes_left -= CB_MAX_LENGTH;
2550 }
2551
2552 /* add the buffer tail */
2553 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002554 status =
2555 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2556 dest_address + dest_offset,
2557 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002558 if (status) {
2559 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2560 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002561 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002562 IPW_DEBUG_FW_INFO
2563 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002564 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002565
James Ketrenos43f66a62005-03-25 12:31:53 -06002566 IPW_DEBUG_FW("<< \n");
2567 return 0;
2568}
2569
2570static int ipw_fw_dma_wait(struct ipw_priv *priv)
2571{
2572 u32 current_index = 0;
2573 u32 watchdog = 0;
2574
2575 IPW_DEBUG_FW(">> : \n");
2576
2577 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002578 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002579 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002580
2581 while (current_index < priv->sram_desc.last_cb_index) {
2582 udelay(50);
2583 current_index = ipw_fw_dma_command_block_index(priv);
2584
2585 watchdog++;
2586
2587 if (watchdog > 400) {
2588 IPW_DEBUG_FW_INFO("Timeout\n");
2589 ipw_fw_dma_dump_command_block(priv);
2590 ipw_fw_dma_abort(priv);
2591 return -1;
2592 }
2593 }
2594
2595 ipw_fw_dma_abort(priv);
2596
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002597 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002598 ipw_set_bit(priv, IPW_RESET_REG,
2599 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002600
2601 IPW_DEBUG_FW("<< dmaWaitSync \n");
2602 return 0;
2603}
2604
Jeff Garzikbf794512005-07-31 13:07:26 -04002605static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002606{
2607 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002608 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002609 unsigned long flags;
2610
2611 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002612 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2613 network = list_entry(element, struct ieee80211_network, list);
2614 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2615 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002616 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002617 &priv->ieee->network_free_list);
2618 }
2619 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002620 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002621}
2622
2623/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002624 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002625 * Reads debug register from domain0.
2626 * If card is present, pre-defined value should
2627 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002628 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002629 * @param priv
2630 * @return 1 if card is present, 0 otherwise
2631 */
2632static inline int ipw_alive(struct ipw_priv *priv)
2633{
2634 return ipw_read32(priv, 0x90) == 0xd55555d5;
2635}
2636
2637static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2638 int timeout)
2639{
2640 int i = 0;
2641
2642 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002643 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002644 return i;
2645 mdelay(10);
2646 i += 10;
2647 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002648
James Ketrenos43f66a62005-03-25 12:31:53 -06002649 return -ETIME;
2650}
2651
Jeff Garzikbf794512005-07-31 13:07:26 -04002652/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002653 * the ipw hardware. It assumes the buffer has all the bits for the
2654 * image and the caller is handling the memory allocation and clean up.
2655 */
2656
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002657static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002658{
2659 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002660
James Ketrenos43f66a62005-03-25 12:31:53 -06002661 IPW_DEBUG_TRACE(">> \n");
2662 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002663 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002664
James Ketrenosb095c382005-08-24 22:04:42 -05002665 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2666 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002667 if (rc < 0) {
2668 IPW_ERROR("stop master failed in 10ms\n");
2669 return -1;
2670 }
2671
2672 IPW_DEBUG_INFO("stop master %dms\n", rc);
2673
2674 return rc;
2675}
2676
2677static void ipw_arc_release(struct ipw_priv *priv)
2678{
2679 IPW_DEBUG_TRACE(">> \n");
2680 mdelay(5);
2681
James Ketrenosb095c382005-08-24 22:04:42 -05002682 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002683
2684 /* no one knows timing, for safety add some delay */
2685 mdelay(5);
2686}
2687
2688struct fw_header {
2689 u32 version;
2690 u32 mode;
2691};
2692
2693struct fw_chunk {
2694 u32 address;
2695 u32 length;
2696};
2697
2698#define IPW_FW_MAJOR_VERSION 2
James Ketrenosb095c382005-08-24 22:04:42 -05002699#define IPW_FW_MINOR_VERSION 3
James Ketrenos43f66a62005-03-25 12:31:53 -06002700
2701#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2702#define IPW_FW_MAJOR(x) (x & 0xff)
2703
James Ketrenosafbf30a2005-08-25 00:05:33 -05002704#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002705
2706#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2707"." __stringify(IPW_FW_MINOR_VERSION) "-"
2708
2709#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2710#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2711#else
2712#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2713#endif
2714
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002715static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002716{
2717 int rc = 0, i, addr;
2718 u8 cr = 0;
2719 u16 *image;
2720
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002721 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002722
James Ketrenos43f66a62005-03-25 12:31:53 -06002723 IPW_DEBUG_TRACE(">> \n");
2724
2725 rc = ipw_stop_master(priv);
2726
2727 if (rc < 0)
2728 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002729
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002730// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002731
James Ketrenosb095c382005-08-24 22:04:42 -05002732 for (addr = IPW_SHARED_LOWER_BOUND;
2733 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002734 ipw_write32(priv, addr, 0);
2735 }
2736
2737 /* no ucode (yet) */
2738 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2739 /* destroy DMA queues */
2740 /* reset sequence */
2741
James Ketrenosb095c382005-08-24 22:04:42 -05002742 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002743 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002744 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002745 mdelay(1);
2746
2747 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002748 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002749 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002750
James Ketrenosb095c382005-08-24 22:04:42 -05002751 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002752 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002753
James Ketrenos43f66a62005-03-25 12:31:53 -06002754 /* enable ucode store */
2755 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2756 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2757 mdelay(1);
2758
2759 /* write ucode */
2760 /**
2761 * @bug
2762 * Do NOT set indirect address register once and then
2763 * store data to indirect data register in the loop.
2764 * It seems very reasonable, but in this case DINO do not
2765 * accept ucode. It is essential to set address each time.
2766 */
2767 /* load new ipw uCode */
2768 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002769 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002770 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002771
James Ketrenos43f66a62005-03-25 12:31:53 -06002772 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002773 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2774 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002777
2778 /* wait for alive response */
2779 for (i = 0; i < 100; i++) {
2780 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002781 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 if (cr & DINO_RXFIFO_DATA)
2783 break;
2784 mdelay(1);
2785 }
2786
2787 if (cr & DINO_RXFIFO_DATA) {
2788 /* alive_command_responce size is NOT multiple of 4 */
2789 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002790
2791 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002792 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002793 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002794 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 memcpy(&priv->dino_alive, response_buffer,
2796 sizeof(priv->dino_alive));
2797 if (priv->dino_alive.alive_command == 1
2798 && priv->dino_alive.ucode_valid == 1) {
2799 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800 IPW_DEBUG_INFO
2801 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2802 "of %02d/%02d/%02d %02d:%02d\n",
2803 priv->dino_alive.software_revision,
2804 priv->dino_alive.software_revision,
2805 priv->dino_alive.device_identifier,
2806 priv->dino_alive.device_identifier,
2807 priv->dino_alive.time_stamp[0],
2808 priv->dino_alive.time_stamp[1],
2809 priv->dino_alive.time_stamp[2],
2810 priv->dino_alive.time_stamp[3],
2811 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002812 } else {
2813 IPW_DEBUG_INFO("Microcode is not alive\n");
2814 rc = -EINVAL;
2815 }
2816 } else {
2817 IPW_DEBUG_INFO("No alive response from DINO\n");
2818 rc = -ETIME;
2819 }
2820
2821 /* disable DINO, otherwise for some reason
2822 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002823 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002824
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002825// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002826
2827 return rc;
2828}
2829
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002830static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002831{
2832 int rc = -1;
2833 int offset = 0;
2834 struct fw_chunk *chunk;
2835 dma_addr_t shared_phys;
2836 u8 *shared_virt;
2837
2838 IPW_DEBUG_TRACE("<< : \n");
2839 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2840
2841 if (!shared_virt)
2842 return -ENOMEM;
2843
2844 memmove(shared_virt, data, len);
2845
2846 /* Start the Dma */
2847 rc = ipw_fw_dma_enable(priv);
2848
2849 if (priv->sram_desc.last_cb_index > 0) {
2850 /* the DMA is already ready this would be a bug. */
2851 BUG();
2852 goto out;
2853 }
2854
2855 do {
2856 chunk = (struct fw_chunk *)(data + offset);
2857 offset += sizeof(struct fw_chunk);
2858 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002859 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002860 * offeset*/
2861 /* Dma loading */
2862 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05002863 le32_to_cpu(chunk->address),
2864 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06002865 if (rc) {
2866 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2867 goto out;
2868 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002869
James Ketrenosa613bff2005-08-24 21:43:11 -05002870 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06002871 } while (offset < len);
2872
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002873 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002874 rc = ipw_fw_dma_kick(priv);
2875 if (rc) {
2876 IPW_ERROR("dmaKick Failed\n");
2877 goto out;
2878 }
2879
2880 rc = ipw_fw_dma_wait(priv);
2881 if (rc) {
2882 IPW_ERROR("dmaWaitSync Failed\n");
2883 goto out;
2884 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002885 out:
2886 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887 return rc;
2888}
2889
2890/* stop nic */
2891static int ipw_stop_nic(struct ipw_priv *priv)
2892{
2893 int rc = 0;
2894
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002895 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05002896 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002897
James Ketrenosb095c382005-08-24 22:04:42 -05002898 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2899 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002900 if (rc < 0) {
2901 IPW_ERROR("wait for reg master disabled failed\n");
2902 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002903 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002904
James Ketrenosb095c382005-08-24 22:04:42 -05002905 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002906
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 return rc;
2908}
2909
2910static void ipw_start_nic(struct ipw_priv *priv)
2911{
2912 IPW_DEBUG_TRACE(">>\n");
2913
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002914 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05002915 ipw_clear_bit(priv, IPW_RESET_REG,
2916 IPW_RESET_REG_MASTER_DISABLED |
2917 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002918 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002919
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05002921 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
2922 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002923
2924 IPW_DEBUG_TRACE("<<\n");
2925}
Jeff Garzikbf794512005-07-31 13:07:26 -04002926
James Ketrenos43f66a62005-03-25 12:31:53 -06002927static int ipw_init_nic(struct ipw_priv *priv)
2928{
2929 int rc;
2930
2931 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002932 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002933 /*prvHwInitNic */
2934 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05002935 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002936
2937 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05002938 ipw_write32(priv, IPW_READ_INT_REGISTER,
2939 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002940
2941 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05002942 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
2943 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002944 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2946
2947 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05002948 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002949
2950 udelay(10);
2951
2952 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05002953 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002954
2955 IPW_DEBUG_TRACE(">>\n");
2956 return 0;
2957}
2958
Jeff Garzikbf794512005-07-31 13:07:26 -04002959/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06002960 * Probe is an ok place to call this from.
2961 */
2962static int ipw_reset_nic(struct ipw_priv *priv)
2963{
2964 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002965 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002966
2967 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002968
James Ketrenos43f66a62005-03-25 12:31:53 -06002969 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002970
James Ketrenosa613bff2005-08-24 21:43:11 -05002971 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002972 /* Clear the 'host command active' bit... */
2973 priv->status &= ~STATUS_HCMD_ACTIVE;
2974 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05002975 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
2976 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05002977 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002978
2979 IPW_DEBUG_TRACE("<<\n");
2980 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002981}
James Ketrenos43f66a62005-03-25 12:31:53 -06002982
Jeff Garzikbf794512005-07-31 13:07:26 -04002983static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002984 const struct firmware **fw, const char *name)
2985{
2986 struct fw_header *header;
2987 int rc;
2988
2989 /* ask firmware_class module to get the boot firmware off disk */
2990 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2991 if (rc < 0) {
2992 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2993 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002994 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002995
2996 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05002997 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002998 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2999 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003000 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3001 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003002 return -EINVAL;
3003 }
3004
Jiri Bencaaa4d302005-06-07 14:58:41 +02003005 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003007 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3008 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 (*fw)->size - sizeof(struct fw_header));
3010 return 0;
3011}
3012
James Ketrenosb095c382005-08-24 22:04:42 -05003013#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003014
3015static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
3016 struct ipw_rx_queue *rxq)
3017{
3018 unsigned long flags;
3019 int i;
3020
3021 spin_lock_irqsave(&rxq->lock, flags);
3022
3023 INIT_LIST_HEAD(&rxq->rx_free);
3024 INIT_LIST_HEAD(&rxq->rx_used);
3025
3026 /* Fill the rx_used queue with _all_ of the Rx buffers */
3027 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3028 /* In the reset function, these buffers may have been allocated
3029 * to an SKB, so we need to unmap and free potential storage */
3030 if (rxq->pool[i].skb != NULL) {
3031 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003032 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003033 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003034 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003035 }
3036 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3037 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003038
James Ketrenos43f66a62005-03-25 12:31:53 -06003039 /* Set us so that we have processed and used all buffers, but have
3040 * not restocked the Rx queue with fresh buffers */
3041 rxq->read = rxq->write = 0;
3042 rxq->processed = RX_QUEUE_SIZE - 1;
3043 rxq->free_count = 0;
3044 spin_unlock_irqrestore(&rxq->lock, flags);
3045}
3046
3047#ifdef CONFIG_PM
3048static int fw_loaded = 0;
3049static const struct firmware *bootfw = NULL;
3050static const struct firmware *firmware = NULL;
3051static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003052
3053static void free_firmware(void)
3054{
3055 if (fw_loaded) {
3056 release_firmware(bootfw);
3057 release_firmware(ucode);
3058 release_firmware(firmware);
3059 bootfw = ucode = firmware = NULL;
3060 fw_loaded = 0;
3061 }
3062}
3063#else
3064#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003065#endif
3066
3067static int ipw_load(struct ipw_priv *priv)
3068{
3069#ifndef CONFIG_PM
3070 const struct firmware *bootfw = NULL;
3071 const struct firmware *firmware = NULL;
3072 const struct firmware *ucode = NULL;
3073#endif
3074 int rc = 0, retries = 3;
3075
3076#ifdef CONFIG_PM
3077 if (!fw_loaded) {
3078#endif
3079 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003080 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003081 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003082
James Ketrenos43f66a62005-03-25 12:31:53 -06003083 switch (priv->ieee->iw_mode) {
3084 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04003085 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06003086 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003087 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003088 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003089
James Ketrenos43f66a62005-03-25 12:31:53 -06003090 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3091 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003092
James Ketrenosb095c382005-08-24 22:04:42 -05003093#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04003095 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003096 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003097 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003099
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003100 rc = ipw_get_fw(priv, &firmware,
3101 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06003102 break;
3103#endif
3104 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003105 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04003106 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003107 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04003108
James Ketrenos43f66a62005-03-25 12:31:53 -06003109 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3110 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003111
James Ketrenos43f66a62005-03-25 12:31:53 -06003112 default:
3113 rc = -EINVAL;
3114 }
3115
Jeff Garzikbf794512005-07-31 13:07:26 -04003116 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06003117 goto error;
3118
3119#ifdef CONFIG_PM
3120 fw_loaded = 1;
3121 }
3122#endif
3123
3124 if (!priv->rxq)
3125 priv->rxq = ipw_rx_queue_alloc(priv);
3126 else
3127 ipw_rx_queue_reset(priv, priv->rxq);
3128 if (!priv->rxq) {
3129 IPW_ERROR("Unable to initialize Rx queue\n");
3130 goto error;
3131 }
3132
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003133 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003134 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003135 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003136 priv->status &= ~STATUS_INT_ENABLED;
3137
3138 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003139 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003140
James Ketrenos43f66a62005-03-25 12:31:53 -06003141 ipw_stop_nic(priv);
3142
3143 rc = ipw_reset_nic(priv);
3144 if (rc) {
3145 IPW_ERROR("Unable to reset NIC\n");
3146 goto error;
3147 }
3148
James Ketrenosb095c382005-08-24 22:04:42 -05003149 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3150 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003151
3152 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003153 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003154 bootfw->size - sizeof(struct fw_header));
3155 if (rc < 0) {
3156 IPW_ERROR("Unable to load boot firmware\n");
3157 goto error;
3158 }
3159
3160 /* kick start the device */
3161 ipw_start_nic(priv);
3162
3163 /* wait for the device to finish it's initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003164 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3165 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003166 if (rc < 0) {
3167 IPW_ERROR("device failed to boot initial fw image\n");
3168 goto error;
3169 }
3170 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3171
Jeff Garzikbf794512005-07-31 13:07:26 -04003172 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003173 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003174
3175 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003176 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003177 ucode->size - sizeof(struct fw_header));
3178 if (rc < 0) {
3179 IPW_ERROR("Unable to load ucode\n");
3180 goto error;
3181 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003182
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 /* stop nic */
3184 ipw_stop_nic(priv);
3185
3186 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003187 rc = ipw_load_firmware(priv, firmware->data +
3188 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003189 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003190 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003191 IPW_ERROR("Unable to load firmware\n");
3192 goto error;
3193 }
3194
3195 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3196
3197 rc = ipw_queue_reset(priv);
3198 if (rc) {
3199 IPW_ERROR("Unable to initialize queues\n");
3200 goto error;
3201 }
3202
3203 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003204 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003205 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003206 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003207
James Ketrenos43f66a62005-03-25 12:31:53 -06003208 /* kick start the device */
3209 ipw_start_nic(priv);
3210
James Ketrenosb095c382005-08-24 22:04:42 -05003211 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003212 if (retries > 0) {
3213 IPW_WARNING("Parity error. Retrying init.\n");
3214 retries--;
3215 goto retry;
3216 }
3217
3218 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3219 rc = -EIO;
3220 goto error;
3221 }
3222
3223 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003224 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3225 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003226 if (rc < 0) {
3227 IPW_ERROR("device failed to start after 500ms\n");
3228 goto error;
3229 }
3230 IPW_DEBUG_INFO("device response after %dms\n", rc);
3231
3232 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003233 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003234
3235 /* read eeprom data and initialize the eeprom region of sram */
3236 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003237 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003238
3239 /* enable interrupts */
3240 ipw_enable_interrupts(priv);
3241
3242 /* Ensure our queue has valid packets */
3243 ipw_rx_queue_replenish(priv);
3244
James Ketrenosb095c382005-08-24 22:04:42 -05003245 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003246
3247 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003248 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003249
3250#ifndef CONFIG_PM
3251 release_firmware(bootfw);
3252 release_firmware(ucode);
3253 release_firmware(firmware);
3254#endif
3255 return 0;
3256
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003257 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003258 if (priv->rxq) {
3259 ipw_rx_queue_free(priv, priv->rxq);
3260 priv->rxq = NULL;
3261 }
3262 ipw_tx_queue_free(priv);
3263 if (bootfw)
3264 release_firmware(bootfw);
3265 if (ucode)
3266 release_firmware(ucode);
3267 if (firmware)
3268 release_firmware(firmware);
3269#ifdef CONFIG_PM
3270 fw_loaded = 0;
3271 bootfw = ucode = firmware = NULL;
3272#endif
3273
3274 return rc;
3275}
3276
Jeff Garzikbf794512005-07-31 13:07:26 -04003277/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003278 * DMA services
3279 *
3280 * Theory of operation
3281 *
3282 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3283 * 2 empty entries always kept in the buffer to protect from overflow.
3284 *
3285 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003286 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3287 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003288 * Tx queue resumed.
3289 *
3290 * The IPW operates with six queues, one receive queue in the device's
3291 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003292 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003293 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003294 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003295 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003296 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003297 * we only utilize the first data transmit queue (queue1).
3298 */
3299
3300/**
3301 * Driver allocates buffers of this size for Rx
3302 */
3303
3304static inline int ipw_queue_space(const struct clx2_queue *q)
3305{
3306 int s = q->last_used - q->first_empty;
3307 if (s <= 0)
3308 s += q->n_bd;
3309 s -= 2; /* keep some reserve to not confuse empty and full situations */
3310 if (s < 0)
3311 s = 0;
3312 return s;
3313}
3314
3315static inline int ipw_queue_inc_wrap(int index, int n_bd)
3316{
3317 return (++index == n_bd) ? 0 : index;
3318}
3319
3320/**
3321 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003322 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003323 * @param q queue to init
3324 * @param count Number of BD's to allocate. Should be power of 2
3325 * @param read_register Address for 'read' register
3326 * (not offset within BAR, full address)
3327 * @param write_register Address for 'write' register
3328 * (not offset within BAR, full address)
3329 * @param base_register Address for 'base' register
3330 * (not offset within BAR, full address)
3331 * @param size Address for 'size' register
3332 * (not offset within BAR, full address)
3333 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003334static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003335 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003336{
3337 q->n_bd = count;
3338
3339 q->low_mark = q->n_bd / 4;
3340 if (q->low_mark < 4)
3341 q->low_mark = 4;
3342
3343 q->high_mark = q->n_bd / 8;
3344 if (q->high_mark < 2)
3345 q->high_mark = 2;
3346
3347 q->first_empty = q->last_used = 0;
3348 q->reg_r = read;
3349 q->reg_w = write;
3350
3351 ipw_write32(priv, base, q->dma_addr);
3352 ipw_write32(priv, size, count);
3353 ipw_write32(priv, read, 0);
3354 ipw_write32(priv, write, 0);
3355
3356 _ipw_read32(priv, 0x90);
3357}
3358
Jeff Garzikbf794512005-07-31 13:07:26 -04003359static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003360 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003361 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003362{
3363 struct pci_dev *dev = priv->pci_dev;
3364
3365 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3366 if (!q->txb) {
3367 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3368 return -ENOMEM;
3369 }
3370
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003371 q->bd =
3372 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003373 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003374 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003375 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003376 kfree(q->txb);
3377 q->txb = NULL;
3378 return -ENOMEM;
3379 }
3380
3381 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3382 return 0;
3383}
3384
3385/**
3386 * Free one TFD, those at index [txq->q.last_used].
3387 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003388 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003389 * @param dev
3390 * @param txq
3391 */
3392static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3393 struct clx2_tx_queue *txq)
3394{
3395 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3396 struct pci_dev *dev = priv->pci_dev;
3397 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003398
James Ketrenos43f66a62005-03-25 12:31:53 -06003399 /* classify bd */
3400 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3401 /* nothing to cleanup after for host commands */
3402 return;
3403
3404 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003405 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3406 IPW_ERROR("Too many chunks: %i\n",
3407 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003408 /** @todo issue fatal error, it is quite serious situation */
3409 return;
3410 }
3411
3412 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003413 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3414 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3415 le16_to_cpu(bd->u.data.chunk_len[i]),
3416 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003417 if (txq->txb[txq->q.last_used]) {
3418 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3419 txq->txb[txq->q.last_used] = NULL;
3420 }
3421 }
3422}
3423
3424/**
3425 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003426 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003427 * Empty queue by removing and destroying all BD's.
3428 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003429 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003430 * @param dev
3431 * @param q
3432 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003433static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003434{
3435 struct clx2_queue *q = &txq->q;
3436 struct pci_dev *dev = priv->pci_dev;
3437
Jeff Garzikbf794512005-07-31 13:07:26 -04003438 if (q->n_bd == 0)
3439 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003440
3441 /* first, empty all BD's */
3442 for (; q->first_empty != q->last_used;
3443 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3444 ipw_queue_tx_free_tfd(priv, txq);
3445 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003446
James Ketrenos43f66a62005-03-25 12:31:53 -06003447 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003448 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003449 q->dma_addr);
3450 kfree(txq->txb);
3451
3452 /* 0 fill whole structure */
3453 memset(txq, 0, sizeof(*txq));
3454}
3455
James Ketrenos43f66a62005-03-25 12:31:53 -06003456/**
3457 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003458 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003459 * @param priv
3460 */
3461static void ipw_tx_queue_free(struct ipw_priv *priv)
3462{
3463 /* Tx CMD queue */
3464 ipw_queue_tx_free(priv, &priv->txq_cmd);
3465
3466 /* Tx queues */
3467 ipw_queue_tx_free(priv, &priv->txq[0]);
3468 ipw_queue_tx_free(priv, &priv->txq[1]);
3469 ipw_queue_tx_free(priv, &priv->txq[2]);
3470 ipw_queue_tx_free(priv, &priv->txq[3]);
3471}
3472
3473static void inline __maybe_wake_tx(struct ipw_priv *priv)
3474{
3475 if (netif_running(priv->net_dev)) {
3476 switch (priv->port_type) {
3477 case DCR_TYPE_MU_BSS:
3478 case DCR_TYPE_MU_IBSS:
James Ketrenosa613bff2005-08-24 21:43:11 -05003479 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003480 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003481 }
3482 netif_wake_queue(priv->net_dev);
3483 }
3484
3485}
3486
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003487static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003488{
3489 /* First 3 bytes are manufacturer */
3490 bssid[0] = priv->mac_addr[0];
3491 bssid[1] = priv->mac_addr[1];
3492 bssid[2] = priv->mac_addr[2];
3493
3494 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003495 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003496
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003497 bssid[0] &= 0xfe; /* clear multicast bit */
3498 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003499}
3500
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003501static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003502{
3503 struct ipw_station_entry entry;
3504 int i;
3505
3506 for (i = 0; i < priv->num_stations; i++) {
3507 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3508 /* Another node is active in network */
3509 priv->missed_adhoc_beacons = 0;
3510 if (!(priv->config & CFG_STATIC_CHANNEL))
3511 /* when other nodes drop out, we drop out */
3512 priv->config &= ~CFG_ADHOC_PERSIST;
3513
3514 return i;
3515 }
3516 }
3517
3518 if (i == MAX_STATIONS)
3519 return IPW_INVALID_STATION;
3520
3521 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3522
3523 entry.reserved = 0;
3524 entry.support_mode = 0;
3525 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3526 memcpy(priv->stations[i], bssid, ETH_ALEN);
3527 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003528 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003529 priv->num_stations++;
3530
3531 return i;
3532}
3533
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003534static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003535{
3536 int i;
3537
Jeff Garzikbf794512005-07-31 13:07:26 -04003538 for (i = 0; i < priv->num_stations; i++)
3539 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003540 return i;
3541
3542 return IPW_INVALID_STATION;
3543}
3544
3545static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3546{
3547 int err;
3548
3549 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3550 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3551 return;
3552 }
3553
3554 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3555 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003556 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 priv->assoc_request.channel);
3558
3559 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3560 priv->status |= STATUS_DISASSOCIATING;
3561
3562 if (quiet)
3563 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3564 else
3565 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3566 err = ipw_send_associate(priv, &priv->assoc_request);
3567 if (err) {
3568 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3569 "failed.\n");
3570 return;
3571 }
3572
3573}
3574
James Ketrenosc848d0a2005-08-24 21:56:24 -05003575static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003576{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003577 struct ipw_priv *priv = data;
3578 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3579 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003580 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003581 return 1;
3582}
3583
3584static void ipw_bg_disassociate(void *data)
3585{
3586 struct ipw_priv *priv = data;
3587 down(&priv->sem);
3588 ipw_disassociate(data);
3589 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06003590}
3591
Zhu Yid8bad6d2005-07-13 12:25:38 -05003592static void ipw_system_config(void *data)
3593{
3594 struct ipw_priv *priv = data;
3595 ipw_send_system_config(priv, &priv->sys_config);
3596}
3597
James Ketrenos43f66a62005-03-25 12:31:53 -06003598struct ipw_status_code {
3599 u16 status;
3600 const char *reason;
3601};
3602
3603static const struct ipw_status_code ipw_status_codes[] = {
3604 {0x00, "Successful"},
3605 {0x01, "Unspecified failure"},
3606 {0x0A, "Cannot support all requested capabilities in the "
3607 "Capability information field"},
3608 {0x0B, "Reassociation denied due to inability to confirm that "
3609 "association exists"},
3610 {0x0C, "Association denied due to reason outside the scope of this "
3611 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003612 {0x0D,
3613 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003614 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003615 {0x0E,
3616 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003617 "transaction sequence number out of expected sequence"},
3618 {0x0F, "Authentication rejected because of challenge failure"},
3619 {0x10, "Authentication rejected due to timeout waiting for next "
3620 "frame in sequence"},
3621 {0x11, "Association denied because AP is unable to handle additional "
3622 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003623 {0x12,
3624 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003625 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003626 {0x13,
3627 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003628 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003629 {0x14,
3630 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003631 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003632 {0x15,
3633 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003634 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003635 {0x19,
3636 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003637 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003638 {0x1A,
3639 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003640 "DSSS-OFDM operation"},
3641 {0x28, "Invalid Information Element"},
3642 {0x29, "Group Cipher is not valid"},
3643 {0x2A, "Pairwise Cipher is not valid"},
3644 {0x2B, "AKMP is not valid"},
3645 {0x2C, "Unsupported RSN IE version"},
3646 {0x2D, "Invalid RSN IE Capabilities"},
3647 {0x2E, "Cipher suite is rejected per security policy"},
3648};
3649
3650#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003651static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003652{
3653 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003654 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003655 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003656 return ipw_status_codes[i].reason;
3657 return "Unknown status value.";
3658}
3659#endif
3660
3661static void inline average_init(struct average *avg)
3662{
3663 memset(avg, 0, sizeof(*avg));
3664}
3665
3666static void inline average_add(struct average *avg, s16 val)
3667{
3668 avg->sum -= avg->entries[avg->pos];
3669 avg->sum += val;
3670 avg->entries[avg->pos++] = val;
3671 if (unlikely(avg->pos == AVG_ENTRIES)) {
3672 avg->init = 1;
3673 avg->pos = 0;
3674 }
3675}
3676
3677static s16 inline average_value(struct average *avg)
3678{
3679 if (!unlikely(avg->init)) {
3680 if (avg->pos)
3681 return avg->sum / avg->pos;
3682 return 0;
3683 }
3684
3685 return avg->sum / AVG_ENTRIES;
3686}
3687
3688static void ipw_reset_stats(struct ipw_priv *priv)
3689{
3690 u32 len = sizeof(u32);
3691
3692 priv->quality = 0;
3693
3694 average_init(&priv->average_missed_beacons);
3695 average_init(&priv->average_rssi);
3696 average_init(&priv->average_noise);
3697
3698 priv->last_rate = 0;
3699 priv->last_missed_beacons = 0;
3700 priv->last_rx_packets = 0;
3701 priv->last_tx_packets = 0;
3702 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003703
James Ketrenos43f66a62005-03-25 12:31:53 -06003704 /* Firmware managed, reset only when NIC is restarted, so we have to
3705 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003706 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003707 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003708 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003709 &priv->last_tx_failures, &len);
3710
3711 /* Driver managed, reset with each association */
3712 priv->missed_adhoc_beacons = 0;
3713 priv->missed_beacons = 0;
3714 priv->tx_packets = 0;
3715 priv->rx_packets = 0;
3716
3717}
3718
James Ketrenos43f66a62005-03-25 12:31:53 -06003719static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3720{
3721 u32 i = 0x80000000;
3722 u32 mask = priv->rates_mask;
3723 /* If currently associated in B mode, restrict the maximum
3724 * rate match to B rates */
3725 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3726 mask &= IEEE80211_CCK_RATES_MASK;
3727
3728 /* TODO: Verify that the rate is supported by the current rates
3729 * list. */
3730
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003731 while (i && !(mask & i))
3732 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003733 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003734 case IEEE80211_CCK_RATE_1MB_MASK:
3735 return 1000000;
3736 case IEEE80211_CCK_RATE_2MB_MASK:
3737 return 2000000;
3738 case IEEE80211_CCK_RATE_5MB_MASK:
3739 return 5500000;
3740 case IEEE80211_OFDM_RATE_6MB_MASK:
3741 return 6000000;
3742 case IEEE80211_OFDM_RATE_9MB_MASK:
3743 return 9000000;
3744 case IEEE80211_CCK_RATE_11MB_MASK:
3745 return 11000000;
3746 case IEEE80211_OFDM_RATE_12MB_MASK:
3747 return 12000000;
3748 case IEEE80211_OFDM_RATE_18MB_MASK:
3749 return 18000000;
3750 case IEEE80211_OFDM_RATE_24MB_MASK:
3751 return 24000000;
3752 case IEEE80211_OFDM_RATE_36MB_MASK:
3753 return 36000000;
3754 case IEEE80211_OFDM_RATE_48MB_MASK:
3755 return 48000000;
3756 case IEEE80211_OFDM_RATE_54MB_MASK:
3757 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003758 }
3759
Jeff Garzikbf794512005-07-31 13:07:26 -04003760 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003761 return 11000000;
3762 else
3763 return 54000000;
3764}
3765
3766static u32 ipw_get_current_rate(struct ipw_priv *priv)
3767{
3768 u32 rate, len = sizeof(rate);
3769 int err;
3770
Jeff Garzikbf794512005-07-31 13:07:26 -04003771 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003772 return 0;
3773
3774 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003775 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 &len);
3777 if (err) {
3778 IPW_DEBUG_INFO("failed querying ordinals.\n");
3779 return 0;
3780 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003781 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 return ipw_get_max_rate(priv);
3783
3784 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003785 case IPW_TX_RATE_1MB:
3786 return 1000000;
3787 case IPW_TX_RATE_2MB:
3788 return 2000000;
3789 case IPW_TX_RATE_5MB:
3790 return 5500000;
3791 case IPW_TX_RATE_6MB:
3792 return 6000000;
3793 case IPW_TX_RATE_9MB:
3794 return 9000000;
3795 case IPW_TX_RATE_11MB:
3796 return 11000000;
3797 case IPW_TX_RATE_12MB:
3798 return 12000000;
3799 case IPW_TX_RATE_18MB:
3800 return 18000000;
3801 case IPW_TX_RATE_24MB:
3802 return 24000000;
3803 case IPW_TX_RATE_36MB:
3804 return 36000000;
3805 case IPW_TX_RATE_48MB:
3806 return 48000000;
3807 case IPW_TX_RATE_54MB:
3808 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003809 }
3810
3811 return 0;
3812}
3813
James Ketrenos43f66a62005-03-25 12:31:53 -06003814#define IPW_STATS_INTERVAL (2 * HZ)
3815static void ipw_gather_stats(struct ipw_priv *priv)
3816{
3817 u32 rx_err, rx_err_delta, rx_packets_delta;
3818 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3819 u32 missed_beacons_percent, missed_beacons_delta;
3820 u32 quality = 0;
3821 u32 len = sizeof(u32);
3822 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003823 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003824 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003825 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003826
3827 if (!(priv->status & STATUS_ASSOCIATED)) {
3828 priv->quality = 0;
3829 return;
3830 }
3831
3832 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003833 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003834 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003835 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003836 priv->last_missed_beacons = priv->missed_beacons;
3837 if (priv->assoc_request.beacon_interval) {
3838 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003839 (HZ * priv->assoc_request.beacon_interval) /
3840 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003841 } else {
3842 missed_beacons_percent = 0;
3843 }
3844 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3845
3846 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3847 rx_err_delta = rx_err - priv->last_rx_err;
3848 priv->last_rx_err = rx_err;
3849
3850 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3851 tx_failures_delta = tx_failures - priv->last_tx_failures;
3852 priv->last_tx_failures = tx_failures;
3853
3854 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3855 priv->last_rx_packets = priv->rx_packets;
3856
3857 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3858 priv->last_tx_packets = priv->tx_packets;
3859
3860 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003861 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003862 * Missed beacon: 100% = 0, 0% = 70% missed
3863 * Rate: 60% = 1Mbs, 100% = Max
3864 * Rx and Tx errors represent a straight % of total Rx/Tx
3865 * RSSI: 100% = > -50, 0% = < -80
3866 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003867 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003868 * The lowest computed quality is used.
3869 *
3870 */
3871#define BEACON_THRESHOLD 5
3872 beacon_quality = 100 - missed_beacons_percent;
3873 if (beacon_quality < BEACON_THRESHOLD)
3874 beacon_quality = 0;
3875 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003876 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003877 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003878 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003879 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003880
James Ketrenos43f66a62005-03-25 12:31:53 -06003881 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05003882 max_rate = ipw_get_max_rate(priv);
3883 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003884 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3885 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003886
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003887 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003888 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003889 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003890 else
3891 rx_quality = 100;
3892 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3893 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003894
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003895 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003896 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003897 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003898 else
3899 tx_quality = 100;
3900 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3901 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003902
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003904 signal_quality =
3905 (100 *
3906 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3907 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
3908 (priv->ieee->perfect_rssi - rssi) *
3909 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
3910 62 * (priv->ieee->perfect_rssi - rssi))) /
3911 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3912 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
3913 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06003914 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05003915 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06003916 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003917
James Ketrenos43f66a62005-03-25 12:31:53 -06003918 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3919 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003920
3921 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003922 min(rate_quality,
3923 min(tx_quality, min(rx_quality, signal_quality))));
3924 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003925 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3926 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003927 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003928 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3929 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003930 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003931 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3932 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003933 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003934 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3935 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003936 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003937 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3938 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003939
3940 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003941
3942 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003943 IPW_STATS_INTERVAL);
3944}
3945
James Ketrenosc848d0a2005-08-24 21:56:24 -05003946static void ipw_bg_gather_stats(void *data)
3947{
3948 struct ipw_priv *priv = data;
3949 down(&priv->sem);
3950 ipw_gather_stats(data);
3951 up(&priv->sem);
3952}
3953
James Ketrenosea2b26e2005-08-24 21:25:16 -05003954static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3955 int missed_count)
3956{
3957 priv->notif_missed_beacons = missed_count;
3958
James Ketrenosafbf30a2005-08-25 00:05:33 -05003959 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05003960 priv->status & STATUS_ASSOCIATED) {
3961 /* If associated and we've hit the missed
3962 * beacon threshold, disassociate, turn
3963 * off roaming, and abort any active scans */
3964 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05003965 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05003966 "Missed beacon: %d - disassociate\n", missed_count);
3967 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05003968 if (priv->status & STATUS_SCANNING) {
3969 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3970 IPW_DL_STATE,
3971 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05003972 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05003973 }
3974
James Ketrenosea2b26e2005-08-24 21:25:16 -05003975 queue_work(priv->workqueue, &priv->disassociate);
3976 return;
3977 }
3978
3979 if (priv->status & STATUS_ROAMING) {
3980 /* If we are currently roaming, then just
3981 * print a debug statement... */
3982 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3983 "Missed beacon: %d - roam in progress\n",
3984 missed_count);
3985 return;
3986 }
3987
3988 if (missed_count > priv->roaming_threshold) {
3989 /* If we are not already roaming, set the ROAM
3990 * bit in the status and kick off a scan */
3991 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3992 "Missed beacon: %d - initiate "
3993 "roaming\n", missed_count);
3994 if (!(priv->status & STATUS_ROAMING)) {
3995 priv->status |= STATUS_ROAMING;
3996 if (!(priv->status & STATUS_SCANNING))
3997 queue_work(priv->workqueue,
3998 &priv->request_scan);
3999 }
4000 return;
4001 }
4002
4003 if (priv->status & STATUS_SCANNING) {
4004 /* Stop scan to keep fw from getting
4005 * stuck (only if we aren't roaming --
4006 * otherwise we'll never scan more than 2 or 3
4007 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004008 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4009 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004010 queue_work(priv->workqueue, &priv->abort_scan);
4011 }
4012
4013 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4014
4015}
4016
James Ketrenos43f66a62005-03-25 12:31:53 -06004017/**
4018 * Handle host notification packet.
4019 * Called from interrupt routine
4020 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004021static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004022 struct ipw_rx_notification *notif)
4023{
James Ketrenosa613bff2005-08-24 21:43:11 -05004024 notif->size = le16_to_cpu(notif->size);
4025
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004026 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004027
James Ketrenos43f66a62005-03-25 12:31:53 -06004028 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004029 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4030 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004031
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004032 switch (assoc->state) {
4033 case CMAS_ASSOCIATED:{
4034 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4035 IPW_DL_ASSOC,
4036 "associated: '%s' " MAC_FMT
4037 " \n",
4038 escape_essid(priv->essid,
4039 priv->essid_len),
4040 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004041
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004042 switch (priv->ieee->iw_mode) {
4043 case IW_MODE_INFRA:
4044 memcpy(priv->ieee->bssid,
4045 priv->bssid, ETH_ALEN);
4046 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004047
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004048 case IW_MODE_ADHOC:
4049 memcpy(priv->ieee->bssid,
4050 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004051
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004052 /* clear out the station table */
4053 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004054
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004055 IPW_DEBUG_ASSOC
4056 ("queueing adhoc check\n");
4057 queue_delayed_work(priv->
4058 workqueue,
4059 &priv->
4060 adhoc_check,
4061 priv->
4062 assoc_request.
4063 beacon_interval);
4064 break;
4065 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004066
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004067 priv->status &= ~STATUS_ASSOCIATING;
4068 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004069 queue_work(priv->workqueue,
4070 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004071
James Ketrenosb095c382005-08-24 22:04:42 -05004072#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004073#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4074 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4075 if ((priv->status & STATUS_AUTH) &&
4076 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4077 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004078 if ((sizeof
4079 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004080 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004081 <= notif->size)
4082 && (notif->size <= 2314)) {
4083 struct
4084 ieee80211_rx_stats
4085 stats = {
4086 .len =
4087 notif->
4088 size - 1,
4089 };
4090
4091 IPW_DEBUG_QOS
4092 ("QoS Associate "
4093 "size %d\n",
4094 notif->size);
4095 ieee80211_rx_mgt(priv->
4096 ieee,
4097 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004098 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004099 *)
4100 &notif->u.raw, &stats);
4101 }
4102 }
4103#endif
4104
James Ketrenosa613bff2005-08-24 21:43:11 -05004105 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004106
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004107 break;
4108 }
4109
4110 case CMAS_AUTHENTICATED:{
4111 if (priv->
4112 status & (STATUS_ASSOCIATED |
4113 STATUS_AUTH)) {
4114#ifdef CONFIG_IPW_DEBUG
4115 struct notif_authenticate *auth
4116 = &notif->u.auth;
4117 IPW_DEBUG(IPW_DL_NOTIF |
4118 IPW_DL_STATE |
4119 IPW_DL_ASSOC,
4120 "deauthenticated: '%s' "
4121 MAC_FMT
4122 ": (0x%04X) - %s \n",
4123 escape_essid(priv->
4124 essid,
4125 priv->
4126 essid_len),
4127 MAC_ARG(priv->bssid),
4128 ntohs(auth->status),
4129 ipw_get_status_code
4130 (ntohs
4131 (auth->status)));
4132#endif
4133
4134 priv->status &=
4135 ~(STATUS_ASSOCIATING |
4136 STATUS_AUTH |
4137 STATUS_ASSOCIATED);
4138
James Ketrenosa613bff2005-08-24 21:43:11 -05004139 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004140 break;
4141 }
4142
4143 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4144 IPW_DL_ASSOC,
4145 "authenticated: '%s' " MAC_FMT
4146 "\n",
4147 escape_essid(priv->essid,
4148 priv->essid_len),
4149 MAC_ARG(priv->bssid));
4150 break;
4151 }
4152
4153 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004154 if (priv->status & STATUS_AUTH) {
4155 struct
4156 ieee80211_assoc_response
4157 *resp;
4158 resp =
4159 (struct
4160 ieee80211_assoc_response
4161 *)&notif->u.raw;
4162 IPW_DEBUG(IPW_DL_NOTIF |
4163 IPW_DL_STATE |
4164 IPW_DL_ASSOC,
4165 "association failed (0x%04X): %s\n",
4166 ntohs(resp->status),
4167 ipw_get_status_code
4168 (ntohs
4169 (resp->status)));
4170 }
4171
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004172 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4173 IPW_DL_ASSOC,
4174 "disassociated: '%s' " MAC_FMT
4175 " \n",
4176 escape_essid(priv->essid,
4177 priv->essid_len),
4178 MAC_ARG(priv->bssid));
4179
4180 priv->status &=
4181 ~(STATUS_DISASSOCIATING |
4182 STATUS_ASSOCIATING |
4183 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004184 if (priv->assoc_network
4185 && (priv->assoc_network->
4186 capability &
4187 WLAN_CAPABILITY_IBSS))
4188 ipw_remove_current_network
4189 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004190
James Ketrenosa613bff2005-08-24 21:43:11 -05004191 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 break;
4194 }
4195
James Ketrenosb095c382005-08-24 22:04:42 -05004196 case CMAS_RX_ASSOC_RESP:
4197 break;
4198
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004199 default:
4200 IPW_ERROR("assoc: unknown (%d)\n",
4201 assoc->state);
4202 break;
4203 }
4204
James Ketrenos43f66a62005-03-25 12:31:53 -06004205 break;
4206 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004207
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004208 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4209 struct notif_authenticate *auth = &notif->u.auth;
4210 switch (auth->state) {
4211 case CMAS_AUTHENTICATED:
4212 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4213 "authenticated: '%s' " MAC_FMT " \n",
4214 escape_essid(priv->essid,
4215 priv->essid_len),
4216 MAC_ARG(priv->bssid));
4217 priv->status |= STATUS_AUTH;
4218 break;
4219
4220 case CMAS_INIT:
4221 if (priv->status & STATUS_AUTH) {
4222 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4223 IPW_DL_ASSOC,
4224 "authentication failed (0x%04X): %s\n",
4225 ntohs(auth->status),
4226 ipw_get_status_code(ntohs
4227 (auth->
4228 status)));
4229 }
4230 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4231 IPW_DL_ASSOC,
4232 "deauthenticated: '%s' " MAC_FMT "\n",
4233 escape_essid(priv->essid,
4234 priv->essid_len),
4235 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004236
4237 priv->status &= ~(STATUS_ASSOCIATING |
4238 STATUS_AUTH |
4239 STATUS_ASSOCIATED);
4240
James Ketrenosa613bff2005-08-24 21:43:11 -05004241 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004242 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004243
4244 case CMAS_TX_AUTH_SEQ_1:
4245 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4246 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4247 break;
4248 case CMAS_RX_AUTH_SEQ_2:
4249 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4250 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4251 break;
4252 case CMAS_AUTH_SEQ_1_PASS:
4253 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4254 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4255 break;
4256 case CMAS_AUTH_SEQ_1_FAIL:
4257 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4258 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4259 break;
4260 case CMAS_TX_AUTH_SEQ_3:
4261 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4262 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4263 break;
4264 case CMAS_RX_AUTH_SEQ_4:
4265 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4266 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4267 break;
4268 case CMAS_AUTH_SEQ_2_PASS:
4269 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4270 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4271 break;
4272 case CMAS_AUTH_SEQ_2_FAIL:
4273 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4274 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4275 break;
4276 case CMAS_TX_ASSOC:
4277 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4278 IPW_DL_ASSOC, "TX_ASSOC\n");
4279 break;
4280 case CMAS_RX_ASSOC_RESP:
4281 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4282 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004283
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004284 break;
4285 case CMAS_ASSOCIATED:
4286 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4287 IPW_DL_ASSOC, "ASSOCIATED\n");
4288 break;
4289 default:
4290 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4291 auth->state);
4292 break;
4293 }
4294 break;
4295 }
4296
4297 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4298 struct notif_channel_result *x =
4299 &notif->u.channel_result;
4300
4301 if (notif->size == sizeof(*x)) {
4302 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4303 x->channel_num);
4304 } else {
4305 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4306 "(should be %zd)\n",
4307 notif->size, sizeof(*x));
4308 }
4309 break;
4310 }
4311
4312 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4313 struct notif_scan_complete *x = &notif->u.scan_complete;
4314 if (notif->size == sizeof(*x)) {
4315 IPW_DEBUG_SCAN
4316 ("Scan completed: type %d, %d channels, "
4317 "%d status\n", x->scan_type,
4318 x->num_channels, x->status);
4319 } else {
4320 IPW_ERROR("Scan completed of wrong size %d "
4321 "(should be %zd)\n",
4322 notif->size, sizeof(*x));
4323 }
4324
4325 priv->status &=
4326 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4327
4328 cancel_delayed_work(&priv->scan_check);
4329
James Ketrenosb095c382005-08-24 22:04:42 -05004330 if (priv->status & STATUS_EXIT_PENDING)
4331 break;
4332
4333 priv->ieee->scans++;
4334
4335#ifdef CONFIG_IPW2200_MONITOR
4336 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004337 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004338 queue_work(priv->workqueue,
4339 &priv->request_scan);
4340 break;
4341 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004342 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004343#endif /* CONFIG_IPW2200_MONITOR */
4344
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004345 if (!(priv->status & (STATUS_ASSOCIATED |
4346 STATUS_ASSOCIATING |
4347 STATUS_ROAMING |
4348 STATUS_DISASSOCIATING)))
4349 queue_work(priv->workqueue, &priv->associate);
4350 else if (priv->status & STATUS_ROAMING) {
4351 /* If a scan completed and we are in roam mode, then
4352 * the scan that completed was the one requested as a
4353 * result of entering roam... so, schedule the
4354 * roam work */
4355 queue_work(priv->workqueue, &priv->roam);
4356 } else if (priv->status & STATUS_SCAN_PENDING)
4357 queue_work(priv->workqueue,
4358 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004359 else if (priv->config & CFG_BACKGROUND_SCAN
4360 && priv->status & STATUS_ASSOCIATED)
4361 queue_delayed_work(priv->workqueue,
4362 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004363 break;
4364 }
4365
4366 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4367 struct notif_frag_length *x = &notif->u.frag_len;
4368
James Ketrenosa613bff2005-08-24 21:43:11 -05004369 if (notif->size == sizeof(*x))
4370 IPW_ERROR("Frag length: %d\n",
4371 le16_to_cpu(x->frag_length));
4372 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004373 IPW_ERROR("Frag length of wrong size %d "
4374 "(should be %zd)\n",
4375 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004376 break;
4377 }
4378
4379 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4380 struct notif_link_deterioration *x =
4381 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004382
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004383 if (notif->size == sizeof(*x)) {
4384 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4385 "link deterioration: '%s' " MAC_FMT
4386 " \n", escape_essid(priv->essid,
4387 priv->essid_len),
4388 MAC_ARG(priv->bssid));
4389 memcpy(&priv->last_link_deterioration, x,
4390 sizeof(*x));
4391 } else {
4392 IPW_ERROR("Link Deterioration of wrong size %d "
4393 "(should be %zd)\n",
4394 notif->size, sizeof(*x));
4395 }
4396 break;
4397 }
4398
4399 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4400 IPW_ERROR("Dino config\n");
4401 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004402 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004403 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004404
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004405 break;
4406 }
4407
4408 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4409 struct notif_beacon_state *x = &notif->u.beacon_state;
4410 if (notif->size != sizeof(*x)) {
4411 IPW_ERROR
4412 ("Beacon state of wrong size %d (should "
4413 "be %zd)\n", notif->size, sizeof(*x));
4414 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004415 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004416
James Ketrenosa613bff2005-08-24 21:43:11 -05004417 if (le32_to_cpu(x->state) ==
4418 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4419 ipw_handle_missed_beacon(priv,
4420 le32_to_cpu(x->
4421 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004422
James Ketrenos43f66a62005-03-25 12:31:53 -06004423 break;
4424 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004425
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004426 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4427 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4428 if (notif->size == sizeof(*x)) {
4429 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4430 "0x%02x station %d\n",
4431 x->key_state, x->security_type,
4432 x->station_index);
4433 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004434 }
4435
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004436 IPW_ERROR
4437 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4438 notif->size, sizeof(*x));
4439 break;
4440 }
4441
4442 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4443 struct notif_calibration *x = &notif->u.calibration;
4444
4445 if (notif->size == sizeof(*x)) {
4446 memcpy(&priv->calib, x, sizeof(*x));
4447 IPW_DEBUG_INFO("TODO: Calibration\n");
4448 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004449 }
4450
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004451 IPW_ERROR
4452 ("Calibration of wrong size %d (should be %zd)\n",
4453 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004454 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004455 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004456
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004457 case HOST_NOTIFICATION_NOISE_STATS:{
4458 if (notif->size == sizeof(u32)) {
4459 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004460 (u8) (le32_to_cpu(notif->u.noise.value) &
4461 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004462 average_add(&priv->average_noise,
4463 priv->last_noise);
4464 break;
4465 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004466
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004467 IPW_ERROR
4468 ("Noise stat is wrong size %d (should be %zd)\n",
4469 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004470 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004471 }
4472
James Ketrenos43f66a62005-03-25 12:31:53 -06004473 default:
4474 IPW_ERROR("Unknown notification: "
4475 "subtype=%d,flags=0x%2x,size=%d\n",
4476 notif->subtype, notif->flags, notif->size);
4477 }
4478}
4479
4480/**
4481 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004482 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004483 * @param priv
4484 * @return error code
4485 */
4486static int ipw_queue_reset(struct ipw_priv *priv)
4487{
4488 int rc = 0;
4489 /** @todo customize queue sizes */
4490 int nTx = 64, nTxCmd = 8;
4491 ipw_tx_queue_free(priv);
4492 /* Tx CMD queue */
4493 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004494 IPW_TX_CMD_QUEUE_READ_INDEX,
4495 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4496 IPW_TX_CMD_QUEUE_BD_BASE,
4497 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004498 if (rc) {
4499 IPW_ERROR("Tx Cmd queue init failed\n");
4500 goto error;
4501 }
4502 /* Tx queue(s) */
4503 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004504 IPW_TX_QUEUE_0_READ_INDEX,
4505 IPW_TX_QUEUE_0_WRITE_INDEX,
4506 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004507 if (rc) {
4508 IPW_ERROR("Tx 0 queue init failed\n");
4509 goto error;
4510 }
4511 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004512 IPW_TX_QUEUE_1_READ_INDEX,
4513 IPW_TX_QUEUE_1_WRITE_INDEX,
4514 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004515 if (rc) {
4516 IPW_ERROR("Tx 1 queue init failed\n");
4517 goto error;
4518 }
4519 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004520 IPW_TX_QUEUE_2_READ_INDEX,
4521 IPW_TX_QUEUE_2_WRITE_INDEX,
4522 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004523 if (rc) {
4524 IPW_ERROR("Tx 2 queue init failed\n");
4525 goto error;
4526 }
4527 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004528 IPW_TX_QUEUE_3_READ_INDEX,
4529 IPW_TX_QUEUE_3_WRITE_INDEX,
4530 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004531 if (rc) {
4532 IPW_ERROR("Tx 3 queue init failed\n");
4533 goto error;
4534 }
4535 /* statistics */
4536 priv->rx_bufs_min = 0;
4537 priv->rx_pend_max = 0;
4538 return rc;
4539
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004540 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004541 ipw_tx_queue_free(priv);
4542 return rc;
4543}
4544
4545/**
4546 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004547 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004548 * When FW adwances 'R' index, all entries between old and
4549 * new 'R' index need to be reclaimed. As result, some free space
4550 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004551 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004552 * @note Need to protect against garbage in 'R' index
4553 * @param priv
4554 * @param txq
4555 * @param qindex
4556 * @return Number of used entries remains in the queue
4557 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004558static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004559 struct clx2_tx_queue *txq, int qindex)
4560{
4561 u32 hw_tail;
4562 int used;
4563 struct clx2_queue *q = &txq->q;
4564
4565 hw_tail = ipw_read32(priv, q->reg_r);
4566 if (hw_tail >= q->n_bd) {
4567 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004568 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4569 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004570 goto done;
4571 }
4572 for (; q->last_used != hw_tail;
4573 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4574 ipw_queue_tx_free_tfd(priv, txq);
4575 priv->tx_packets++;
4576 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004577 done:
James Ketrenosa613bff2005-08-24 21:43:11 -05004578 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004579 __maybe_wake_tx(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004580 used = q->first_empty - q->last_used;
4581 if (used < 0)
4582 used += q->n_bd;
4583
4584 return used;
4585}
4586
4587static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4588 int len, int sync)
4589{
4590 struct clx2_tx_queue *txq = &priv->txq_cmd;
4591 struct clx2_queue *q = &txq->q;
4592 struct tfd_frame *tfd;
4593
4594 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4595 IPW_ERROR("No space for Tx\n");
4596 return -EBUSY;
4597 }
4598
4599 tfd = &txq->bd[q->first_empty];
4600 txq->txb[q->first_empty] = NULL;
4601
4602 memset(tfd, 0, sizeof(*tfd));
4603 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4604 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4605 priv->hcmd_seq++;
4606 tfd->u.cmd.index = hcmd;
4607 tfd->u.cmd.length = len;
4608 memcpy(tfd->u.cmd.payload, buf, len);
4609 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4610 ipw_write32(priv, q->reg_w, q->first_empty);
4611 _ipw_read32(priv, 0x90);
4612
4613 return 0;
4614}
4615
Jeff Garzikbf794512005-07-31 13:07:26 -04004616/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004617 * Rx theory of operation
4618 *
4619 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004620 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004621 * 0 to 31
4622 *
4623 * Rx Queue Indexes
4624 * The host/firmware share two index registers for managing the Rx buffers.
4625 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004626 * The READ index maps to the first position that the firmware may be writing
4627 * to -- the driver can read up to (but not including) this position and get
4628 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004629 * The READ index is managed by the firmware once the card is enabled.
4630 *
4631 * The WRITE index maps to the last position the driver has read from -- the
4632 * position preceding WRITE is the last slot the firmware can place a packet.
4633 *
4634 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004635 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004636 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004637 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004638 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4639 *
4640 * When the firmware places a packet in a buffer it will advance the READ index
4641 * and fire the RX interrupt. The driver can then query the READ index and
4642 * process as many packets as possible, moving the WRITE index forward as it
4643 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004644 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004645 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004646 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004647 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004648 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004649 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4650 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4651 * 'processed' and 'read' driver indexes as well)
4652 * + A received packet is processed and handed to the kernel network stack,
4653 * detached from the ipw->rxq. The driver 'processed' index is updated.
4654 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004655 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4656 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004657 * were enough free buffers and RX_STALLED is set it is cleared.
4658 *
4659 *
4660 * Driver sequence:
4661 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004662 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004663 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4664 * ipw_rx_queue_restock
4665 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4666 * queue, updates firmware pointers, and updates
4667 * the WRITE index. If insufficient rx_free buffers
4668 * are available, schedules ipw_rx_queue_replenish
4669 *
4670 * -- enable interrupts --
4671 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004672 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004673 * Moves the packet buffer from queue to rx_used.
4674 * Calls ipw_rx_queue_restock to refill any empty
4675 * slots.
4676 * ...
4677 *
4678 */
4679
Jeff Garzikbf794512005-07-31 13:07:26 -04004680/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004681 * If there are slots in the RX queue that need to be restocked,
4682 * and we have free pre-allocated buffers, fill the ranks as much
4683 * as we can pulling from rx_free.
4684 *
4685 * This moves the 'write' index forward to catch up with 'processed', and
4686 * also updates the memory address in the firmware to reference the new
4687 * target buffer.
4688 */
4689static void ipw_rx_queue_restock(struct ipw_priv *priv)
4690{
4691 struct ipw_rx_queue *rxq = priv->rxq;
4692 struct list_head *element;
4693 struct ipw_rx_mem_buffer *rxb;
4694 unsigned long flags;
4695 int write;
4696
4697 spin_lock_irqsave(&rxq->lock, flags);
4698 write = rxq->write;
4699 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4700 element = rxq->rx_free.next;
4701 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4702 list_del(element);
4703
James Ketrenosb095c382005-08-24 22:04:42 -05004704 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004705 rxb->dma_addr);
4706 rxq->queue[rxq->write] = rxb;
4707 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4708 rxq->free_count--;
4709 }
4710 spin_unlock_irqrestore(&rxq->lock, flags);
4711
Jeff Garzikbf794512005-07-31 13:07:26 -04004712 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004713 * refill it */
4714 if (rxq->free_count <= RX_LOW_WATERMARK)
4715 queue_work(priv->workqueue, &priv->rx_replenish);
4716
4717 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004718 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004719 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004720}
4721
4722/*
4723 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004724 * Also restock the Rx queue via ipw_rx_queue_restock.
4725 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004726 * This is called as a scheduled work item (except for during intialization)
4727 */
4728static void ipw_rx_queue_replenish(void *data)
4729{
4730 struct ipw_priv *priv = data;
4731 struct ipw_rx_queue *rxq = priv->rxq;
4732 struct list_head *element;
4733 struct ipw_rx_mem_buffer *rxb;
4734 unsigned long flags;
4735
4736 spin_lock_irqsave(&rxq->lock, flags);
4737 while (!list_empty(&rxq->rx_used)) {
4738 element = rxq->rx_used.next;
4739 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004740 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004741 if (!rxb->skb) {
4742 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4743 priv->net_dev->name);
4744 /* We don't reschedule replenish work here -- we will
4745 * call the restock method and if it still needs
4746 * more buffers it will schedule replenish */
4747 break;
4748 }
4749 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004750
James Ketrenos43f66a62005-03-25 12:31:53 -06004751 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004752 rxb->dma_addr =
4753 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004754 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004755
James Ketrenos43f66a62005-03-25 12:31:53 -06004756 list_add_tail(&rxb->list, &rxq->rx_free);
4757 rxq->free_count++;
4758 }
4759 spin_unlock_irqrestore(&rxq->lock, flags);
4760
4761 ipw_rx_queue_restock(priv);
4762}
4763
James Ketrenosc848d0a2005-08-24 21:56:24 -05004764static void ipw_bg_rx_queue_replenish(void *data)
4765{
4766 struct ipw_priv *priv = data;
4767 down(&priv->sem);
4768 ipw_rx_queue_replenish(data);
4769 up(&priv->sem);
4770}
4771
James Ketrenos43f66a62005-03-25 12:31:53 -06004772/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4773 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004774 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004775 * non NULL it is unmapped and freed
4776 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004777static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004778{
4779 int i;
4780
4781 if (!rxq)
4782 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004783
James Ketrenos43f66a62005-03-25 12:31:53 -06004784 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4785 if (rxq->pool[i].skb != NULL) {
4786 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004787 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004788 dev_kfree_skb(rxq->pool[i].skb);
4789 }
4790 }
4791
4792 kfree(rxq);
4793}
4794
4795static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4796{
4797 struct ipw_rx_queue *rxq;
4798 int i;
4799
4800 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004801 if (unlikely(!rxq)) {
4802 IPW_ERROR("memory allocation failed\n");
4803 return NULL;
4804 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004805 memset(rxq, 0, sizeof(*rxq));
4806 spin_lock_init(&rxq->lock);
4807 INIT_LIST_HEAD(&rxq->rx_free);
4808 INIT_LIST_HEAD(&rxq->rx_used);
4809
4810 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004811 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004812 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4813
4814 /* Set us so that we have processed and used all buffers, but have
4815 * not restocked the Rx queue with fresh buffers */
4816 rxq->read = rxq->write = 0;
4817 rxq->processed = RX_QUEUE_SIZE - 1;
4818 rxq->free_count = 0;
4819
4820 return rxq;
4821}
4822
4823static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4824{
4825 rate &= ~IEEE80211_BASIC_RATE_MASK;
4826 if (ieee_mode == IEEE_A) {
4827 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004828 case IEEE80211_OFDM_RATE_6MB:
4829 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004830 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004831 case IEEE80211_OFDM_RATE_9MB:
4832 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004833 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004834 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004835 return priv->
4836 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004837 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004838 return priv->
4839 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004840 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004841 return priv->
4842 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004843 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004844 return priv->
4845 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004846 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004847 return priv->
4848 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004849 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004850 return priv->
4851 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004852 default:
4853 return 0;
4854 }
4855 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004856
James Ketrenos43f66a62005-03-25 12:31:53 -06004857 /* B and G mixed */
4858 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004859 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004860 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004861 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004862 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004863 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004864 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004865 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004866 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4867 }
4868
4869 /* If we are limited to B modulations, bail at this point */
4870 if (ieee_mode == IEEE_B)
4871 return 0;
4872
4873 /* G */
4874 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004875 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004877 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004878 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004879 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004880 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004881 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004882 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004883 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004884 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004885 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004886 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004887 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004888 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004889 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004890 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4891 }
4892
4893 return 0;
4894}
4895
Jeff Garzikbf794512005-07-31 13:07:26 -04004896static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004897 const struct ieee80211_network *network,
4898 struct ipw_supported_rates *rates)
4899{
4900 int num_rates, i;
4901
4902 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004903 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004904 rates->num_rates = 0;
4905 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004906 if (!ipw_is_rate_in_mask(priv, network->mode,
4907 network->rates[i])) {
4908
James Ketrenosea2b26e2005-08-24 21:25:16 -05004909 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004910 IPW_DEBUG_SCAN("Adding masked mandatory "
4911 "rate %02X\n",
4912 network->rates[i]);
4913 rates->supported_rates[rates->num_rates++] =
4914 network->rates[i];
4915 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004916 }
4917
James Ketrenos43f66a62005-03-25 12:31:53 -06004918 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4919 network->rates[i], priv->rates_mask);
4920 continue;
4921 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004922
James Ketrenos43f66a62005-03-25 12:31:53 -06004923 rates->supported_rates[rates->num_rates++] = network->rates[i];
4924 }
4925
James Ketrenosa613bff2005-08-24 21:43:11 -05004926 num_rates = min(network->rates_ex_len,
4927 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004929 if (!ipw_is_rate_in_mask(priv, network->mode,
4930 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004931 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004932 IPW_DEBUG_SCAN("Adding masked mandatory "
4933 "rate %02X\n",
4934 network->rates_ex[i]);
4935 rates->supported_rates[rates->num_rates++] =
4936 network->rates[i];
4937 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004938 }
4939
James Ketrenos43f66a62005-03-25 12:31:53 -06004940 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4941 network->rates_ex[i], priv->rates_mask);
4942 continue;
4943 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004944
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004945 rates->supported_rates[rates->num_rates++] =
4946 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004947 }
4948
James Ketrenosea2b26e2005-08-24 21:25:16 -05004949 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004950}
4951
4952static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4953 const struct ipw_supported_rates *src)
4954{
4955 u8 i;
4956 for (i = 0; i < src->num_rates; i++)
4957 dest->supported_rates[i] = src->supported_rates[i];
4958 dest->num_rates = src->num_rates;
4959}
4960
4961/* TODO: Look at sniffed packets in the air to determine if the basic rate
4962 * mask should ever be used -- right now all callers to add the scan rates are
4963 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4964static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004965 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004966{
Jeff Garzikbf794512005-07-31 13:07:26 -04004967 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004968 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004969
James Ketrenos43f66a62005-03-25 12:31:53 -06004970 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004971 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004972 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004973
4974 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004975 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004976 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004977
4978 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004979 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004980 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004981
4982 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004983 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004984 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004985}
4986
4987static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004988 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004989{
Jeff Garzikbf794512005-07-31 13:07:26 -04004990 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004991 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004992
4993 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004994 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004995 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004996
4997 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004998 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004999 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005000
5001 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005002 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005003 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005004
5005 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005006 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005007 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005008
5009 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005010 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005011 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005012
5013 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005014 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005015 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005016
5017 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005018 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005019 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005020
5021 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005022 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005023 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005024}
5025
5026struct ipw_network_match {
5027 struct ieee80211_network *network;
5028 struct ipw_supported_rates rates;
5029};
5030
James Ketrenosc848d0a2005-08-24 21:56:24 -05005031static int ipw_find_adhoc_network(struct ipw_priv *priv,
5032 struct ipw_network_match *match,
5033 struct ieee80211_network *network,
5034 int roaming)
5035{
5036 struct ipw_supported_rates rates;
5037
5038 /* Verify that this network's capability is compatible with the
5039 * current mode (AdHoc or Infrastructure) */
5040 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5041 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5042 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5043 "capability mismatch.\n",
5044 escape_essid(network->ssid, network->ssid_len),
5045 MAC_ARG(network->bssid));
5046 return 0;
5047 }
5048
5049 /* If we do not have an ESSID for this AP, we can not associate with
5050 * it */
5051 if (network->flags & NETWORK_EMPTY_ESSID) {
5052 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5053 "because of hidden ESSID.\n",
5054 escape_essid(network->ssid, network->ssid_len),
5055 MAC_ARG(network->bssid));
5056 return 0;
5057 }
5058
5059 if (unlikely(roaming)) {
5060 /* If we are roaming, then ensure check if this is a valid
5061 * network to try and roam to */
5062 if ((network->ssid_len != match->network->ssid_len) ||
5063 memcmp(network->ssid, match->network->ssid,
5064 network->ssid_len)) {
5065 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5066 "because of non-network ESSID.\n",
5067 escape_essid(network->ssid,
5068 network->ssid_len),
5069 MAC_ARG(network->bssid));
5070 return 0;
5071 }
5072 } else {
5073 /* If an ESSID has been configured then compare the broadcast
5074 * ESSID to ours */
5075 if ((priv->config & CFG_STATIC_ESSID) &&
5076 ((network->ssid_len != priv->essid_len) ||
5077 memcmp(network->ssid, priv->essid,
5078 min(network->ssid_len, priv->essid_len)))) {
5079 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005080
James Ketrenosc848d0a2005-08-24 21:56:24 -05005081 strncpy(escaped,
5082 escape_essid(network->ssid, network->ssid_len),
5083 sizeof(escaped));
5084 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5085 "because of ESSID mismatch: '%s'.\n",
5086 escaped, MAC_ARG(network->bssid),
5087 escape_essid(priv->essid,
5088 priv->essid_len));
5089 return 0;
5090 }
5091 }
5092
5093 /* If the old network rate is better than this one, don't bother
5094 * testing everything else. */
5095
5096 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005097 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5098 "current network.\n",
5099 escape_essid(match->network->ssid,
5100 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005101 return 0;
5102 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005103 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5104 "current network.\n",
5105 escape_essid(match->network->ssid,
5106 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005107 return 0;
5108 }
5109
5110 /* Now go through and see if the requested network is valid... */
5111 if (priv->ieee->scan_age != 0 &&
5112 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5113 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5114 "because of age: %lums.\n",
5115 escape_essid(network->ssid, network->ssid_len),
5116 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005117 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005118 return 0;
5119 }
5120
5121 if ((priv->config & CFG_STATIC_CHANNEL) &&
5122 (network->channel != priv->channel)) {
5123 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5124 "because of channel mismatch: %d != %d.\n",
5125 escape_essid(network->ssid, network->ssid_len),
5126 MAC_ARG(network->bssid),
5127 network->channel, priv->channel);
5128 return 0;
5129 }
5130
5131 /* Verify privacy compatability */
5132 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5133 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5134 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5135 "because of privacy mismatch: %s != %s.\n",
5136 escape_essid(network->ssid, network->ssid_len),
5137 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005138 priv->
5139 capability & CAP_PRIVACY_ON ? "on" : "off",
5140 network->
5141 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5142 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005143 return 0;
5144 }
5145
5146 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5147 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5148 "because of the same BSSID match: " MAC_FMT
5149 ".\n", escape_essid(network->ssid,
5150 network->ssid_len),
5151 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5152 return 0;
5153 }
5154
5155 /* Filter out any incompatible freq / mode combinations */
5156 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5157 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5158 "because of invalid frequency/mode "
5159 "combination.\n",
5160 escape_essid(network->ssid, network->ssid_len),
5161 MAC_ARG(network->bssid));
5162 return 0;
5163 }
5164
5165 /* Ensure that the rates supported by the driver are compatible with
5166 * this AP, including verification of basic rates (mandatory) */
5167 if (!ipw_compatible_rates(priv, network, &rates)) {
5168 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5169 "because configured rate mask excludes "
5170 "AP mandatory rate.\n",
5171 escape_essid(network->ssid, network->ssid_len),
5172 MAC_ARG(network->bssid));
5173 return 0;
5174 }
5175
5176 if (rates.num_rates == 0) {
5177 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5178 "because of no compatible rates.\n",
5179 escape_essid(network->ssid, network->ssid_len),
5180 MAC_ARG(network->bssid));
5181 return 0;
5182 }
5183
5184 /* TODO: Perform any further minimal comparititive tests. We do not
5185 * want to put too much policy logic here; intelligent scan selection
5186 * should occur within a generic IEEE 802.11 user space tool. */
5187
5188 /* Set up 'new' AP to this network */
5189 ipw_copy_rates(&match->rates, &rates);
5190 match->network = network;
5191 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5192 escape_essid(network->ssid, network->ssid_len),
5193 MAC_ARG(network->bssid));
5194
5195 return 1;
5196}
5197
5198static void ipw_merge_adhoc_network(void *data)
5199{
5200 struct ipw_priv *priv = data;
5201 struct ieee80211_network *network = NULL;
5202 struct ipw_network_match match = {
5203 .network = priv->assoc_network
5204 };
5205
James Ketrenosafbf30a2005-08-25 00:05:33 -05005206 if ((priv->status & STATUS_ASSOCIATED) &&
5207 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005208 /* First pass through ROAM process -- look for a better
5209 * network */
5210 unsigned long flags;
5211
5212 spin_lock_irqsave(&priv->ieee->lock, flags);
5213 list_for_each_entry(network, &priv->ieee->network_list, list) {
5214 if (network != priv->assoc_network)
5215 ipw_find_adhoc_network(priv, &match, network,
5216 1);
5217 }
5218 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5219
5220 if (match.network == priv->assoc_network) {
5221 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5222 "merge to.\n");
5223 return;
5224 }
5225
5226 down(&priv->sem);
5227 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5228 IPW_DEBUG_MERGE("remove network %s\n",
5229 escape_essid(priv->essid,
5230 priv->essid_len));
5231 ipw_remove_current_network(priv);
5232 }
5233
5234 ipw_disassociate(priv);
5235 priv->assoc_network = match.network;
5236 up(&priv->sem);
5237 return;
5238 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005239}
5240
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005241static int ipw_best_network(struct ipw_priv *priv,
5242 struct ipw_network_match *match,
5243 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005244{
5245 struct ipw_supported_rates rates;
5246
5247 /* Verify that this network's capability is compatible with the
5248 * current mode (AdHoc or Infrastructure) */
5249 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005250 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005251 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5252 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5253 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005254 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005255 escape_essid(network->ssid, network->ssid_len),
5256 MAC_ARG(network->bssid));
5257 return 0;
5258 }
5259
5260 /* If we do not have an ESSID for this AP, we can not associate with
5261 * it */
5262 if (network->flags & NETWORK_EMPTY_ESSID) {
5263 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5264 "because of hidden ESSID.\n",
5265 escape_essid(network->ssid, network->ssid_len),
5266 MAC_ARG(network->bssid));
5267 return 0;
5268 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005269
James Ketrenos43f66a62005-03-25 12:31:53 -06005270 if (unlikely(roaming)) {
5271 /* If we are roaming, then ensure check if this is a valid
5272 * network to try and roam to */
5273 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005274 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005275 network->ssid_len)) {
5276 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5277 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005278 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005279 network->ssid_len),
5280 MAC_ARG(network->bssid));
5281 return 0;
5282 }
5283 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005284 /* If an ESSID has been configured then compare the broadcast
5285 * ESSID to ours */
5286 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005287 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005288 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005289 min(network->ssid_len, priv->essid_len)))) {
5290 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005291 strncpy(escaped,
5292 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005293 sizeof(escaped));
5294 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005295 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005296 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005297 escape_essid(priv->essid,
5298 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005299 return 0;
5300 }
5301 }
5302
5303 /* If the old network rate is better than this one, don't bother
5304 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005305 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005306 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005307 strncpy(escaped,
5308 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005309 sizeof(escaped));
5310 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5311 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5312 escaped, MAC_ARG(network->bssid),
5313 escape_essid(match->network->ssid,
5314 match->network->ssid_len),
5315 MAC_ARG(match->network->bssid));
5316 return 0;
5317 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005318
James Ketrenos43f66a62005-03-25 12:31:53 -06005319 /* If this network has already had an association attempt within the
5320 * last 3 seconds, do not try and associate again... */
5321 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005322 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005323 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
James Ketrenosafbf30a2005-08-25 00:05:33 -05005324 "because of storming (%lus since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005325 "assoc attempt).\n",
5326 escape_essid(network->ssid, network->ssid_len),
5327 MAC_ARG(network->bssid),
5328 (jiffies - network->last_associate) / HZ);
5329 return 0;
5330 }
5331
5332 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005333 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005334 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005335 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5336 "because of age: %lums.\n",
5337 escape_essid(network->ssid, network->ssid_len),
5338 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005339 1000 * (jiffies - network->last_scanned) / HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -06005340 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005341 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005342
Jeff Garzikbf794512005-07-31 13:07:26 -04005343 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005344 (network->channel != priv->channel)) {
5345 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5346 "because of channel mismatch: %d != %d.\n",
5347 escape_essid(network->ssid, network->ssid_len),
5348 MAC_ARG(network->bssid),
5349 network->channel, priv->channel);
5350 return 0;
5351 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005352
James Ketrenos43f66a62005-03-25 12:31:53 -06005353 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005354 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005355 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5356 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5357 "because of privacy mismatch: %s != %s.\n",
5358 escape_essid(network->ssid, network->ssid_len),
5359 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005360 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005361 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005362 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005363 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005364 return 0;
5365 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005366
5367 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005368 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5369 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5370 "because of BSSID mismatch: " MAC_FMT ".\n",
5371 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005372 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005373 return 0;
5374 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005375
James Ketrenos43f66a62005-03-25 12:31:53 -06005376 /* Filter out any incompatible freq / mode combinations */
5377 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5378 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5379 "because of invalid frequency/mode "
5380 "combination.\n",
5381 escape_essid(network->ssid, network->ssid_len),
5382 MAC_ARG(network->bssid));
5383 return 0;
5384 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005385
James Ketrenosea2b26e2005-08-24 21:25:16 -05005386 /* Ensure that the rates supported by the driver are compatible with
5387 * this AP, including verification of basic rates (mandatory) */
5388 if (!ipw_compatible_rates(priv, network, &rates)) {
5389 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5390 "because configured rate mask excludes "
5391 "AP mandatory rate.\n",
5392 escape_essid(network->ssid, network->ssid_len),
5393 MAC_ARG(network->bssid));
5394 return 0;
5395 }
5396
James Ketrenos43f66a62005-03-25 12:31:53 -06005397 if (rates.num_rates == 0) {
5398 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5399 "because of no compatible rates.\n",
5400 escape_essid(network->ssid, network->ssid_len),
5401 MAC_ARG(network->bssid));
5402 return 0;
5403 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005404
James Ketrenos43f66a62005-03-25 12:31:53 -06005405 /* TODO: Perform any further minimal comparititive tests. We do not
5406 * want to put too much policy logic here; intelligent scan selection
5407 * should occur within a generic IEEE 802.11 user space tool. */
5408
5409 /* Set up 'new' AP to this network */
5410 ipw_copy_rates(&match->rates, &rates);
5411 match->network = network;
5412
5413 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5414 escape_essid(network->ssid, network->ssid_len),
5415 MAC_ARG(network->bssid));
5416
5417 return 1;
5418}
5419
Jeff Garzikbf794512005-07-31 13:07:26 -04005420static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005421 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005422{
James Ketrenosafbf30a2005-08-25 00:05:33 -05005423 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5424 int i;
5425
James Ketrenos43f66a62005-03-25 12:31:53 -06005426 /*
5427 * For the purposes of scanning, we can set our wireless mode
5428 * to trigger scans across combinations of bands, but when it
5429 * comes to creating a new ad-hoc network, we have tell the FW
5430 * exactly which band to use.
5431 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005432 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005433 * chossen band. Attempting to create a new ad-hoc network
5434 * with an invalid channel for wireless mode will trigger a
5435 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005436 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005437 */
James Ketrenosafbf30a2005-08-25 00:05:33 -05005438 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5439 case IEEE80211_52GHZ_BAND:
5440 network->mode = IEEE_A;
5441 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5442 if (i == -1)
5443 BUG();
5444 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5445 IPW_WARNING("Overriding invalid channel\n");
5446 priv->channel = geo->a[0].channel;
5447 }
5448 break;
5449
5450 case IEEE80211_24GHZ_BAND:
5451 if (priv->ieee->mode & IEEE_G)
5452 network->mode = IEEE_G;
5453 else
5454 network->mode = IEEE_B;
5455 break;
5456
5457 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005458 IPW_WARNING("Overriding invalid channel\n");
5459 if (priv->ieee->mode & IEEE_A) {
5460 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005461 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005462 } else if (priv->ieee->mode & IEEE_G) {
5463 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005464 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005465 } else {
5466 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005467 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005468 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005469 break;
5470 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005471
5472 network->channel = priv->channel;
5473 priv->config |= CFG_ADHOC_PERSIST;
5474 ipw_create_bssid(priv, network->bssid);
5475 network->ssid_len = priv->essid_len;
5476 memcpy(network->ssid, priv->essid, priv->essid_len);
5477 memset(&network->stats, 0, sizeof(network->stats));
5478 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005479 if (!(priv->config & CFG_PREAMBLE_LONG))
5480 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005481 if (priv->capability & CAP_PRIVACY_ON)
5482 network->capability |= WLAN_CAPABILITY_PRIVACY;
5483 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005484 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005485 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005486 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005487 &priv->rates.supported_rates[network->rates_len],
5488 network->rates_ex_len);
5489 network->last_scanned = 0;
5490 network->flags = 0;
5491 network->last_associate = 0;
5492 network->time_stamp[0] = 0;
5493 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005494 network->beacon_interval = 100; /* Default */
5495 network->listen_interval = 10; /* Default */
5496 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005497 network->wpa_ie_len = 0;
5498 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005499}
5500
James Ketrenosb095c382005-08-24 22:04:42 -05005501static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5502{
5503 struct ipw_tgi_tx_key *key;
5504 struct host_cmd cmd = {
5505 .cmd = IPW_CMD_TGI_TX_KEY,
5506 .len = sizeof(*key)
5507 };
5508
5509 if (!(priv->ieee->sec.flags & (1 << index)))
5510 return;
5511
5512 key = (struct ipw_tgi_tx_key *)&cmd.param;
5513 key->key_id = index;
5514 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5515 key->security_type = type;
5516 key->station_index = 0; /* always 0 for BSS */
5517 key->flags = 0;
5518 /* 0 for new key; previous value of counter (after fatal error) */
5519 key->tx_counter[0] = 0;
5520 key->tx_counter[1] = 0;
5521
5522 if (ipw_send_cmd(priv, &cmd)) {
5523 IPW_ERROR("failed to send TGI_TX_KEY command\n");
5524 return;
5525 }
5526}
5527
5528static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005529{
5530 struct ipw_wep_key *key;
5531 int i;
5532 struct host_cmd cmd = {
5533 .cmd = IPW_CMD_WEP_KEY,
5534 .len = sizeof(*key)
5535 };
5536
5537 key = (struct ipw_wep_key *)&cmd.param;
5538 key->cmd_id = DINO_CMD_WEP_KEY;
5539 key->seq_num = 0;
5540
James Ketrenosb095c382005-08-24 22:04:42 -05005541 /* Note: AES keys cannot be set for multiple times.
5542 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005543 for (i = 0; i < 4; i++) {
James Ketrenosb095c382005-08-24 22:04:42 -05005544 key->key_index = i | type;
5545 if (!(priv->ieee->sec.flags & (1 << i))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005546 key->key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005547 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005548 }
5549
James Ketrenosb095c382005-08-24 22:04:42 -05005550 key->key_size = priv->ieee->sec.key_sizes[i];
5551 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5552
James Ketrenos43f66a62005-03-25 12:31:53 -06005553 if (ipw_send_cmd(priv, &cmd)) {
5554 IPW_ERROR("failed to send WEP_KEY command\n");
5555 return;
5556 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005557 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005558}
5559
Zhu Yi1fbfea52005-08-05 17:22:56 +08005560static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5561{
5562 if (priv->ieee->host_encrypt)
5563 return;
5564
5565 switch (level) {
5566 case SEC_LEVEL_3:
5567 priv->sys_config.disable_unicast_decryption = 0;
5568 priv->ieee->host_decrypt = 0;
5569 break;
5570 case SEC_LEVEL_2:
5571 priv->sys_config.disable_unicast_decryption = 1;
5572 priv->ieee->host_decrypt = 1;
5573 break;
5574 case SEC_LEVEL_1:
5575 priv->sys_config.disable_unicast_decryption = 0;
5576 priv->ieee->host_decrypt = 0;
5577 break;
5578 case SEC_LEVEL_0:
5579 priv->sys_config.disable_unicast_decryption = 1;
5580 break;
5581 default:
5582 break;
5583 }
5584}
5585
5586static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5587{
5588 if (priv->ieee->host_encrypt)
5589 return;
5590
5591 switch (level) {
5592 case SEC_LEVEL_3:
5593 priv->sys_config.disable_multicast_decryption = 0;
5594 break;
5595 case SEC_LEVEL_2:
5596 priv->sys_config.disable_multicast_decryption = 1;
5597 break;
5598 case SEC_LEVEL_1:
5599 priv->sys_config.disable_multicast_decryption = 0;
5600 break;
5601 case SEC_LEVEL_0:
5602 priv->sys_config.disable_multicast_decryption = 1;
5603 break;
5604 default:
5605 break;
5606 }
5607}
5608
James Ketrenosb095c382005-08-24 22:04:42 -05005609static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5610{
5611 switch (priv->ieee->sec.level) {
5612 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005613 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5614 ipw_send_tgi_tx_key(priv,
5615 DCT_FLAG_EXT_SECURITY_CCM,
5616 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005617
James Ketrenosb095c382005-08-24 22:04:42 -05005618 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005619 break;
5620 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005621 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5622 ipw_send_tgi_tx_key(priv,
5623 DCT_FLAG_EXT_SECURITY_TKIP,
5624 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005625 break;
5626 case SEC_LEVEL_1:
5627 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenosb095c382005-08-24 22:04:42 -05005628 break;
5629 case SEC_LEVEL_0:
5630 default:
5631 break;
5632 }
Zhu Yi1fbfea52005-08-05 17:22:56 +08005633
5634 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5635 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005636}
5637
James Ketrenos43f66a62005-03-25 12:31:53 -06005638static void ipw_adhoc_check(void *data)
5639{
5640 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005641
James Ketrenosafbf30a2005-08-25 00:05:33 -05005642 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005643 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005644 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5645 IPW_DL_STATE | IPW_DL_ASSOC,
5646 "Missed beacon: %d - disassociate\n",
5647 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005648 ipw_remove_current_network(priv);
5649 ipw_disassociate(priv);
5650 return;
5651 }
5652
Jeff Garzikbf794512005-07-31 13:07:26 -04005653 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005654 priv->assoc_request.beacon_interval);
5655}
5656
James Ketrenosc848d0a2005-08-24 21:56:24 -05005657static void ipw_bg_adhoc_check(void *data)
5658{
5659 struct ipw_priv *priv = data;
5660 down(&priv->sem);
5661 ipw_adhoc_check(data);
5662 up(&priv->sem);
5663}
5664
James Ketrenos43f66a62005-03-25 12:31:53 -06005665#ifdef CONFIG_IPW_DEBUG
5666static void ipw_debug_config(struct ipw_priv *priv)
5667{
5668 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5669 "[CFG 0x%08X]\n", priv->config);
5670 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005671 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005672 else
5673 IPW_DEBUG_INFO("Channel unlocked.\n");
5674 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005675 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005676 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005677 else
5678 IPW_DEBUG_INFO("ESSID unlocked.\n");
5679 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005680 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5681 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005682 else
5683 IPW_DEBUG_INFO("BSSID unlocked.\n");
5684 if (priv->capability & CAP_PRIVACY_ON)
5685 IPW_DEBUG_INFO("PRIVACY on\n");
5686 else
5687 IPW_DEBUG_INFO("PRIVACY off\n");
5688 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5689}
5690#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005691#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005692#endif
5693
James Ketrenosb095c382005-08-24 22:04:42 -05005694static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005695{
5696 /* TODO: Verify that this works... */
5697 struct ipw_fixed_rate fr = {
5698 .tx_rates = priv->rates_mask
5699 };
5700 u32 reg;
5701 u16 mask = 0;
5702
Jeff Garzikbf794512005-07-31 13:07:26 -04005703 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005704 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005705
James Ketrenos43f66a62005-03-25 12:31:53 -06005706 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005707 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005708 /* IEEE_A */
5709 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5710 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005711 IPW_DEBUG_WX
5712 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005713 fr.tx_rates = 0;
5714 break;
5715 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005716
James Ketrenos43f66a62005-03-25 12:31:53 -06005717 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5718 break;
5719
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005720 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005721 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005722 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5724 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005725 IPW_DEBUG_WX
5726 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 fr.tx_rates = 0;
5728 }
5729 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005730 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005731
5732 /* IEEE_G */
5733 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5734 IEEE80211_OFDM_RATES_MASK)) {
5735 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005736 IPW_DEBUG_WX
5737 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005738 fr.tx_rates = 0;
5739 break;
5740 }
5741
5742 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5743 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5744 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5745 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005746
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5748 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5749 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5750 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005751
James Ketrenos43f66a62005-03-25 12:31:53 -06005752 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5753 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5754 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5755 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005756
James Ketrenos43f66a62005-03-25 12:31:53 -06005757 fr.tx_rates |= mask;
5758 break;
5759 }
5760
5761 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005762 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005763}
5764
James Ketrenosea2b26e2005-08-24 21:25:16 -05005765static void ipw_abort_scan(struct ipw_priv *priv)
5766{
5767 int err;
5768
5769 if (priv->status & STATUS_SCAN_ABORTING) {
5770 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5771 return;
5772 }
5773 priv->status |= STATUS_SCAN_ABORTING;
5774
5775 err = ipw_send_scan_abort(priv);
5776 if (err)
5777 IPW_DEBUG_HC("Request to abort scan failed.\n");
5778}
5779
James Ketrenosafbf30a2005-08-25 00:05:33 -05005780static void ipw_add_scan_channels(struct ipw_priv *priv,
5781 struct ipw_scan_request_ext *scan,
5782 int scan_type)
5783{
5784 int channel_index = 0;
5785 const struct ieee80211_geo *geo;
5786 int i;
5787
5788 geo = ieee80211_get_geo(priv->ieee);
5789
5790 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5791 int start = channel_index;
5792 for (i = 0; i < geo->a_channels; i++) {
5793 if ((priv->status & STATUS_ASSOCIATED) &&
5794 geo->a[i].channel == priv->channel)
5795 continue;
5796 channel_index++;
5797 scan->channels_list[channel_index] = geo->a[i].channel;
5798 ipw_set_scan_type(scan, channel_index, scan_type);
5799 }
5800
5801 if (start != channel_index) {
5802 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5803 (channel_index - start);
5804 channel_index++;
5805 }
5806 }
5807
5808 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5809 int start = channel_index;
5810 if (priv->config & CFG_SPEED_SCAN) {
5811 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5812 /* nop out the list */
5813 [0] = 0
5814 };
5815
5816 u8 channel;
5817 while (channel_index < IPW_SCAN_CHANNELS) {
5818 channel =
5819 priv->speed_scan[priv->speed_scan_pos];
5820 if (channel == 0) {
5821 priv->speed_scan_pos = 0;
5822 channel = priv->speed_scan[0];
5823 }
5824 if ((priv->status & STATUS_ASSOCIATED) &&
5825 channel == priv->channel) {
5826 priv->speed_scan_pos++;
5827 continue;
5828 }
5829
5830 /* If this channel has already been
5831 * added in scan, break from loop
5832 * and this will be the first channel
5833 * in the next scan.
5834 */
5835 if (channels[channel - 1] != 0)
5836 break;
5837
5838 channels[channel - 1] = 1;
5839 priv->speed_scan_pos++;
5840 channel_index++;
5841 scan->channels_list[channel_index] = channel;
5842 ipw_set_scan_type(scan, channel_index,
5843 scan_type);
5844 }
5845 } else {
5846 for (i = 0; i < geo->bg_channels; i++) {
5847 if ((priv->status & STATUS_ASSOCIATED) &&
5848 geo->bg[i].channel == priv->channel)
5849 continue;
5850 channel_index++;
5851 scan->channels_list[channel_index] =
5852 geo->bg[i].channel;
5853 ipw_set_scan_type(scan, channel_index,
5854 scan_type);
5855 }
5856 }
5857
5858 if (start != channel_index) {
5859 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
5860 (channel_index - start);
5861 }
5862 }
5863}
5864
James Ketrenosea2b26e2005-08-24 21:25:16 -05005865static int ipw_request_scan(struct ipw_priv *priv)
5866{
5867 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005868 int err = 0, scan_type;
5869
5870 if (!(priv->status & STATUS_INIT) ||
5871 (priv->status & STATUS_EXIT_PENDING))
5872 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005873
James Ketrenosb095c382005-08-24 22:04:42 -05005874 down(&priv->sem);
5875
James Ketrenosea2b26e2005-08-24 21:25:16 -05005876 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005877 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05005878 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005879 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005880 }
5881
James Ketrenosafbf30a2005-08-25 00:05:33 -05005882 if (!(priv->status & STATUS_SCAN_FORCED) &&
5883 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005884 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5885 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005886 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005887 }
5888
5889 if (priv->status & STATUS_RF_KILL_MASK) {
5890 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5891 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05005892 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005893 }
5894
5895 memset(&scan, 0, sizeof(scan));
5896
James Ketrenosb095c382005-08-24 22:04:42 -05005897 if (priv->config & CFG_SPEED_SCAN)
5898 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5899 cpu_to_le16(30);
5900 else
5901 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5902 cpu_to_le16(20);
5903
James Ketrenosa613bff2005-08-24 21:43:11 -05005904 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5905 cpu_to_le16(20);
5906 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005907
James Ketrenosa613bff2005-08-24 21:43:11 -05005908 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05005909
James Ketrenosb095c382005-08-24 22:04:42 -05005910#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05005911 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005912 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05005913 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005914
James Ketrenosb095c382005-08-24 22:04:42 -05005915 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5916 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005917 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005918 channel = priv->channel;
5919 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005920
James Ketrenosb095c382005-08-24 22:04:42 -05005921 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005922 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05005923 channel = priv->channel;
5924 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005925
James Ketrenosb095c382005-08-24 22:04:42 -05005926 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05005927 band = (u8) (IPW_B_MODE << 6) | 1;
5928 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05005929 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005930 }
5931
James Ketrenosb095c382005-08-24 22:04:42 -05005932 scan.channels_list[0] = band;
5933 scan.channels_list[1] = channel;
5934 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005935
James Ketrenosb095c382005-08-24 22:04:42 -05005936 /* NOTE: The card will sit on this channel for this time
5937 * period. Scan aborts are timing sensitive and frequently
5938 * result in firmware restarts. As such, it is best to
5939 * set a small dwell_time here and just keep re-issuing
5940 * scans. Otherwise fast channel hopping will not actually
5941 * hop channels.
5942 *
5943 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05005944 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5945 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005946 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05005947#endif /* CONFIG_IPW2200_MONITOR */
5948 /* If we are roaming, then make this a directed scan for the
5949 * current network. Otherwise, ensure that every other scan
5950 * is a fast channel hop scan */
5951 if ((priv->status & STATUS_ROAMING)
5952 || (!(priv->status & STATUS_ASSOCIATED)
5953 && (priv->config & CFG_STATIC_ESSID)
5954 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005955 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5956 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05005957 IPW_DEBUG_HC("Attempt to send SSID command "
5958 "failed.\n");
5959 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005960 }
5961
5962 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005963 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05005964 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005965
James Ketrenosafbf30a2005-08-25 00:05:33 -05005966 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05005967#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05005968 }
5969#endif
5970
5971 err = ipw_send_scan_request_ext(priv, &scan);
5972 if (err) {
5973 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05005974 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005975 }
5976
5977 priv->status |= STATUS_SCANNING;
5978 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005979 queue_delayed_work(priv->workqueue, &priv->scan_check,
5980 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05005981 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05005982 up(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05005983 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05005984}
5985
5986static void ipw_bg_abort_scan(void *data)
5987{
5988 struct ipw_priv *priv = data;
5989 down(&priv->sem);
5990 ipw_abort_scan(data);
5991 up(&priv->sem);
5992}
5993
James Ketrenosafbf30a2005-08-25 00:05:33 -05005994#if WIRELESS_EXT < 18
5995/* Support for wpa_supplicant before WE-18, deprecated. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005996
5997/* following definitions must match definitions in driver_ipw.c */
5998
5999#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
6000
6001#define IPW_CMD_SET_WPA_PARAM 1
6002#define IPW_CMD_SET_WPA_IE 2
6003#define IPW_CMD_SET_ENCRYPTION 3
6004#define IPW_CMD_MLME 4
6005
6006#define IPW_PARAM_WPA_ENABLED 1
6007#define IPW_PARAM_TKIP_COUNTERMEASURES 2
6008#define IPW_PARAM_DROP_UNENCRYPTED 3
6009#define IPW_PARAM_PRIVACY_INVOKED 4
6010#define IPW_PARAM_AUTH_ALGS 5
6011#define IPW_PARAM_IEEE_802_1X 6
6012
6013#define IPW_MLME_STA_DEAUTH 1
6014#define IPW_MLME_STA_DISASSOC 2
6015
6016#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
6017#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
6018#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
6019#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
6020#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
6021#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
6022
6023#define IPW_CRYPT_ALG_NAME_LEN 16
6024
6025struct ipw_param {
6026 u32 cmd;
6027 u8 sta_addr[ETH_ALEN];
6028 union {
6029 struct {
6030 u8 name;
6031 u32 value;
6032 } wpa_param;
6033 struct {
6034 u32 len;
James Ketrenosb095c382005-08-24 22:04:42 -05006035 u8 reserved[32];
6036 u8 data[0];
James Ketrenosea2b26e2005-08-24 21:25:16 -05006037 } wpa_ie;
6038 struct {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006039 u32 command;
6040 u32 reason_code;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006041 } mlme;
6042 struct {
6043 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
6044 u8 set_tx;
6045 u32 err;
6046 u8 idx;
6047 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
6048 u16 key_len;
6049 u8 key[0];
6050 } crypt;
6051
6052 } u;
6053};
6054
6055/* end of driver_ipw.c code */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006056#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006057
6058static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6059{
James Ketrenosb095c382005-08-24 22:04:42 -05006060 /* This is called when wpa_supplicant loads and closes the driver
6061 * interface. */
6062 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006063}
6064
James Ketrenosafbf30a2005-08-25 00:05:33 -05006065#if WIRELESS_EXT < 18
6066#define IW_AUTH_ALG_OPEN_SYSTEM 0x1
6067#define IW_AUTH_ALG_SHARED_KEY 0x2
6068#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006069
6070static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6071{
6072 struct ieee80211_device *ieee = priv->ieee;
6073 struct ieee80211_security sec = {
6074 .flags = SEC_AUTH_MODE,
6075 };
6076 int ret = 0;
6077
James Ketrenosafbf30a2005-08-25 00:05:33 -05006078 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006079 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6080 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006081 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006082 sec.auth_mode = WLAN_AUTH_OPEN;
6083 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006084 } else
6085 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006086
6087 if (ieee->set_security)
6088 ieee->set_security(ieee->dev, &sec);
6089 else
6090 ret = -EOPNOTSUPP;
6091
6092 return ret;
6093}
6094
James Ketrenosafbf30a2005-08-25 00:05:33 -05006095void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6096{
6097 /* make sure WPA is enabled */
6098 ipw_wpa_enable(priv, 1);
6099
6100 ipw_disassociate(priv);
6101}
6102
6103static int ipw_set_rsn_capa(struct ipw_priv *priv,
6104 char *capabilities, int length)
6105{
6106 struct host_cmd cmd = {
6107 .cmd = IPW_CMD_RSN_CAPABILITIES,
6108 .len = length,
6109 };
6110
6111 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6112
6113 memcpy(cmd.param, capabilities, length);
6114 if (ipw_send_cmd(priv, &cmd)) {
6115 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
6116 return -1;
6117 }
6118 return 0;
6119}
6120
6121#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -05006122static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
6123{
6124 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05006125 struct ieee80211_crypt_data *crypt;
6126 unsigned long flags;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006127 int ret = 0;
6128
6129 switch (name) {
6130 case IPW_PARAM_WPA_ENABLED:
6131 ret = ipw_wpa_enable(priv, value);
6132 break;
6133
6134 case IPW_PARAM_TKIP_COUNTERMEASURES:
James Ketrenosa613bff2005-08-24 21:43:11 -05006135 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6136 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6137 IPW_WARNING("Can't set TKIP countermeasures: "
6138 "crypt not set!\n");
6139 break;
6140 }
6141
6142 flags = crypt->ops->get_flags(crypt->priv);
6143
6144 if (value)
6145 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6146 else
6147 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6148
6149 crypt->ops->set_flags(flags, crypt->priv);
6150
James Ketrenosea2b26e2005-08-24 21:25:16 -05006151 break;
6152
James Ketrenosb095c382005-08-24 22:04:42 -05006153 case IPW_PARAM_DROP_UNENCRYPTED:{
6154 /* HACK:
6155 *
6156 * wpa_supplicant calls set_wpa_enabled when the driver
6157 * is loaded and unloaded, regardless of if WPA is being
6158 * used. No other calls are made which can be used to
6159 * determine if encryption will be used or not prior to
6160 * association being expected. If encryption is not being
6161 * used, drop_unencrypted is set to false, else true -- we
6162 * can use this to determine if the CAP_PRIVACY_ON bit should
6163 * be set.
6164 */
6165 struct ieee80211_security sec = {
6166 .flags = SEC_ENABLED,
6167 .enabled = value,
6168 };
6169 priv->ieee->drop_unencrypted = value;
6170 /* We only change SEC_LEVEL for open mode. Others
6171 * are set by ipw_wpa_set_encryption.
6172 */
6173 if (!value) {
6174 sec.flags |= SEC_LEVEL;
6175 sec.level = SEC_LEVEL_0;
6176 } else {
6177 sec.flags |= SEC_LEVEL;
6178 sec.level = SEC_LEVEL_1;
6179 }
6180 if (priv->ieee->set_security)
6181 priv->ieee->set_security(priv->ieee->dev, &sec);
6182 break;
6183 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05006184
6185 case IPW_PARAM_PRIVACY_INVOKED:
6186 priv->ieee->privacy_invoked = value;
6187 break;
6188
6189 case IPW_PARAM_AUTH_ALGS:
6190 ret = ipw_wpa_set_auth_algs(priv, value);
6191 break;
6192
6193 case IPW_PARAM_IEEE_802_1X:
6194 priv->ieee->ieee802_1x = value;
6195 break;
6196
6197 default:
6198 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
6199 ret = -EOPNOTSUPP;
6200 }
6201
6202 return ret;
6203}
6204
6205static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
6206{
6207 struct ipw_priv *priv = ieee80211_priv(dev);
6208 int ret = 0;
6209
6210 switch (command) {
6211 case IPW_MLME_STA_DEAUTH:
6212 // silently ignore
6213 break;
6214
6215 case IPW_MLME_STA_DISASSOC:
6216 ipw_disassociate(priv);
6217 break;
6218
6219 default:
6220 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
6221 ret = -EOPNOTSUPP;
6222 }
6223
6224 return ret;
6225}
6226
Zhu Yi1fbfea52005-08-05 17:22:56 +08006227static int ipw_wpa_ie_cipher2level(u8 cipher)
6228{
6229 switch (cipher) {
6230 case 4: /* CCMP */
6231 return SEC_LEVEL_3;
6232 case 2: /* TKIP */
6233 return SEC_LEVEL_2;
6234 case 5: /* WEP104 */
6235 case 1: /* WEP40 */
6236 return SEC_LEVEL_1;
6237 case 0: /* NONE */
6238 return SEC_LEVEL_0;
6239 default:
6240 return -1;
6241 }
6242}
6243
James Ketrenosea2b26e2005-08-24 21:25:16 -05006244static int ipw_wpa_set_wpa_ie(struct net_device *dev,
6245 struct ipw_param *param, int plen)
6246{
6247 struct ipw_priv *priv = ieee80211_priv(dev);
6248 struct ieee80211_device *ieee = priv->ieee;
6249 u8 *buf;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006250 u8 *ptk, *gtk;
6251 int level;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006252
James Ketrenosea2b26e2005-08-24 21:25:16 -05006253 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
6254 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
6255 return -EINVAL;
6256
6257 if (param->u.wpa_ie.len) {
6258 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
6259 if (buf == NULL)
6260 return -ENOMEM;
6261
6262 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
6263 kfree(ieee->wpa_ie);
6264 ieee->wpa_ie = buf;
6265 ieee->wpa_ie_len = param->u.wpa_ie.len;
6266 } else {
6267 kfree(ieee->wpa_ie);
6268 ieee->wpa_ie = NULL;
6269 ieee->wpa_ie_len = 0;
Zhu Yi1fbfea52005-08-05 17:22:56 +08006270 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006271 }
6272
Zhu Yi1fbfea52005-08-05 17:22:56 +08006273 if (priv->ieee->host_encrypt)
6274 goto done;
6275
6276 /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
6277 * we need to change driver_ipw.c from wpa_supplicant. This
6278 * is OK since -Dipw is deprecated. The -Dwext driver has a
6279 * clean way to handle this. */
6280 gtk = ptk = (u8 *) ieee->wpa_ie;
6281 if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
6282 gtk += 4 + 3;
6283 ptk += 4 + 4 + 2 + 3;
6284 } else { /* WPA IE */
6285 gtk += 8 + 3;
6286 ptk += 8 + 4 + 2 + 3;
6287 }
6288
6289 if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
6290 return -EINVAL;
6291
6292 level = ipw_wpa_ie_cipher2level(*gtk);
6293 ipw_set_hw_decrypt_multicast(priv, level);
6294
6295 level = ipw_wpa_ie_cipher2level(*ptk);
6296 ipw_set_hw_decrypt_unicast(priv, level);
6297
6298 done:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006299 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6300 return 0;
6301}
6302
6303/* implementation borrowed from hostap driver */
6304
6305static int ipw_wpa_set_encryption(struct net_device *dev,
6306 struct ipw_param *param, int param_len)
6307{
6308 int ret = 0;
6309 struct ipw_priv *priv = ieee80211_priv(dev);
6310 struct ieee80211_device *ieee = priv->ieee;
6311 struct ieee80211_crypto_ops *ops;
6312 struct ieee80211_crypt_data **crypt;
6313
6314 struct ieee80211_security sec = {
6315 .flags = 0,
6316 };
6317
6318 param->u.crypt.err = 0;
6319 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
6320
6321 if (param_len !=
6322 (int)((char *)param->u.crypt.key - (char *)param) +
6323 param->u.crypt.key_len) {
6324 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
6325 param->u.crypt.key_len);
6326 return -EINVAL;
6327 }
6328 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6329 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6330 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6331 if (param->u.crypt.idx >= WEP_KEYS)
6332 return -EINVAL;
6333 crypt = &ieee->crypt[param->u.crypt.idx];
6334 } else {
6335 return -EINVAL;
6336 }
6337
James Ketrenosafbf30a2005-08-25 00:05:33 -05006338 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006339 if (strcmp(param->u.crypt.alg, "none") == 0) {
6340 if (crypt) {
6341 sec.enabled = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006342 sec.encrypt = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006343 sec.level = SEC_LEVEL_0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006344 sec.flags |= SEC_LEVEL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006345 ieee80211_crypt_delayed_deinit(ieee, crypt);
6346 }
6347 goto done;
6348 }
6349 sec.enabled = 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006350 sec.encrypt = 1;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006351
James Ketrenosb095c382005-08-24 22:04:42 -05006352 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006353 if (strcmp(param->u.crypt.alg, "TKIP") == 0)
6354 ieee->host_encrypt_msdu = 1;
6355
6356 if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
6357 ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05006358 goto skip_host_crypt;
6359
James Ketrenosea2b26e2005-08-24 21:25:16 -05006360 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6361 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6362 request_module("ieee80211_crypt_wep");
6363 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6364 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6365 request_module("ieee80211_crypt_tkip");
6366 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6367 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6368 request_module("ieee80211_crypt_ccmp");
6369 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6370 }
6371 if (ops == NULL) {
6372 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6373 dev->name, param->u.crypt.alg);
6374 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
6375 ret = -EINVAL;
6376 goto done;
6377 }
6378
6379 if (*crypt == NULL || (*crypt)->ops != ops) {
6380 struct ieee80211_crypt_data *new_crypt;
6381
6382 ieee80211_crypt_delayed_deinit(ieee, crypt);
6383
6384 new_crypt = (struct ieee80211_crypt_data *)
6385 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
6386 if (new_crypt == NULL) {
6387 ret = -ENOMEM;
6388 goto done;
6389 }
6390 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6391 new_crypt->ops = ops;
6392 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6393 new_crypt->priv =
6394 new_crypt->ops->init(param->u.crypt.idx);
6395
6396 if (new_crypt->priv == NULL) {
6397 kfree(new_crypt);
6398 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
6399 ret = -EINVAL;
6400 goto done;
6401 }
6402
6403 *crypt = new_crypt;
6404 }
6405
6406 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6407 (*crypt)->ops->set_key(param->u.crypt.key,
6408 param->u.crypt.key_len, param->u.crypt.seq,
6409 (*crypt)->priv) < 0) {
6410 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
6411 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
6412 ret = -EINVAL;
6413 goto done;
6414 }
6415
James Ketrenosb095c382005-08-24 22:04:42 -05006416 skip_host_crypt:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006417 if (param->u.crypt.set_tx) {
6418 ieee->tx_keyidx = param->u.crypt.idx;
6419 sec.active_key = param->u.crypt.idx;
6420 sec.flags |= SEC_ACTIVE_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05006421 } else
6422 sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006423
James Ketrenosb095c382005-08-24 22:04:42 -05006424 if (param->u.crypt.alg != NULL) {
6425 memcpy(sec.keys[param->u.crypt.idx],
6426 param->u.crypt.key, param->u.crypt.key_len);
6427 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6428 sec.flags |= (1 << param->u.crypt.idx);
6429
6430 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006431 sec.flags |= SEC_LEVEL;
6432 sec.level = SEC_LEVEL_1;
James Ketrenosb095c382005-08-24 22:04:42 -05006433 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006434 sec.flags |= SEC_LEVEL;
6435 sec.level = SEC_LEVEL_2;
James Ketrenosb095c382005-08-24 22:04:42 -05006436 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006437 sec.flags |= SEC_LEVEL;
6438 sec.level = SEC_LEVEL_3;
6439 }
6440 }
6441 done:
6442 if (ieee->set_security)
6443 ieee->set_security(ieee->dev, &sec);
6444
6445 /* Do not reset port if card is in Managed mode since resetting will
6446 * generate new IEEE 802.11 authentication which may end up in looping
6447 * with IEEE 802.1X. If your hardware requires a reset after WEP
6448 * configuration (for example... Prism2), implement the reset_port in
6449 * the callbacks structures used to initialize the 802.11 stack. */
6450 if (ieee->reset_on_keychange &&
6451 ieee->iw_mode != IW_MODE_INFRA &&
6452 ieee->reset_port && ieee->reset_port(dev)) {
6453 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6454 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
6455 return -EINVAL;
6456 }
6457
6458 return ret;
6459}
6460
6461static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
6462{
6463 struct ipw_param *param;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006464 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006465 int ret = 0;
6466
6467 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
6468
6469 if (p->length < sizeof(struct ipw_param) || !p->pointer)
6470 return -EINVAL;
6471
6472 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
6473 if (param == NULL)
6474 return -ENOMEM;
6475
6476 if (copy_from_user(param, p->pointer, p->length)) {
6477 kfree(param);
6478 return -EFAULT;
6479 }
6480
James Ketrenosafbf30a2005-08-25 00:05:33 -05006481 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006482 switch (param->cmd) {
6483
6484 case IPW_CMD_SET_WPA_PARAM:
6485 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
6486 param->u.wpa_param.value);
6487 break;
6488
6489 case IPW_CMD_SET_WPA_IE:
6490 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
6491 break;
6492
6493 case IPW_CMD_SET_ENCRYPTION:
6494 ret = ipw_wpa_set_encryption(dev, param, p->length);
6495 break;
6496
6497 case IPW_CMD_MLME:
6498 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
6499 param->u.mlme.reason_code);
6500 break;
6501
6502 default:
6503 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6504 dev->name, param->cmd);
6505 ret = -EOPNOTSUPP;
6506 }
6507
James Ketrenosafbf30a2005-08-25 00:05:33 -05006508 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006509 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6510 ret = -EFAULT;
6511
6512 kfree(param);
6513 return ret;
6514}
James Ketrenosafbf30a2005-08-25 00:05:33 -05006515#else
6516/*
6517 * WE-18 support
6518 */
6519
6520/* SIOCSIWGENIE */
6521static int ipw_wx_set_genie(struct net_device *dev,
6522 struct iw_request_info *info,
6523 union iwreq_data *wrqu, char *extra)
6524{
6525 struct ipw_priv *priv = ieee80211_priv(dev);
6526 struct ieee80211_device *ieee = priv->ieee;
6527 u8 *buf;
6528 int err = 0;
6529
6530 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6531 (wrqu->data.length && extra == NULL))
6532 return -EINVAL;
6533
6534 //down(&priv->sem);
6535
6536 //if (!ieee->wpa_enabled) {
6537 // err = -EOPNOTSUPP;
6538 // goto out;
6539 //}
6540
6541 if (wrqu->data.length) {
6542 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6543 if (buf == NULL) {
6544 err = -ENOMEM;
6545 goto out;
6546 }
6547
6548 memcpy(buf, extra, wrqu->data.length);
6549 kfree(ieee->wpa_ie);
6550 ieee->wpa_ie = buf;
6551 ieee->wpa_ie_len = wrqu->data.length;
6552 } else {
6553 kfree(ieee->wpa_ie);
6554 ieee->wpa_ie = NULL;
6555 ieee->wpa_ie_len = 0;
6556 }
6557
6558 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6559 out:
6560 //up(&priv->sem);
6561 return err;
6562}
6563
6564/* SIOCGIWGENIE */
6565static int ipw_wx_get_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 int err = 0;
6572
6573 //down(&priv->sem);
6574
6575 //if (!ieee->wpa_enabled) {
6576 // err = -EOPNOTSUPP;
6577 // goto out;
6578 //}
6579
6580 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6581 wrqu->data.length = 0;
6582 goto out;
6583 }
6584
6585 if (wrqu->data.length < ieee->wpa_ie_len) {
6586 err = -E2BIG;
6587 goto out;
6588 }
6589
6590 wrqu->data.length = ieee->wpa_ie_len;
6591 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6592
6593 out:
6594 //up(&priv->sem);
6595 return err;
6596}
6597
Zhu Yi1fbfea52005-08-05 17:22:56 +08006598static int wext_cipher2level(int cipher)
6599{
6600 switch (cipher) {
6601 case IW_AUTH_CIPHER_NONE:
6602 return SEC_LEVEL_0;
6603 case IW_AUTH_CIPHER_WEP40:
6604 case IW_AUTH_CIPHER_WEP104:
6605 return SEC_LEVEL_1;
6606 case IW_AUTH_CIPHER_TKIP:
6607 return SEC_LEVEL_2;
6608 case IW_AUTH_CIPHER_CCMP:
6609 return SEC_LEVEL_3;
6610 default:
6611 return -1;
6612 }
6613}
6614
James Ketrenosafbf30a2005-08-25 00:05:33 -05006615/* SIOCSIWAUTH */
6616static int ipw_wx_set_auth(struct net_device *dev,
6617 struct iw_request_info *info,
6618 union iwreq_data *wrqu, char *extra)
6619{
6620 struct ipw_priv *priv = ieee80211_priv(dev);
6621 struct ieee80211_device *ieee = priv->ieee;
6622 struct iw_param *param = &wrqu->param;
6623 struct ieee80211_crypt_data *crypt;
6624 unsigned long flags;
6625 int ret = 0;
6626
6627 switch (param->flags & IW_AUTH_INDEX) {
6628 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006629 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006630 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006631 ipw_set_hw_decrypt_unicast(priv,
6632 wext_cipher2level(param->value));
6633 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006634 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006635 ipw_set_hw_decrypt_multicast(priv,
6636 wext_cipher2level(param->value));
6637 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006638 case IW_AUTH_KEY_MGMT:
6639 /*
6640 * ipw2200 does not use these parameters
6641 */
6642 break;
6643
6644 case IW_AUTH_TKIP_COUNTERMEASURES:
6645 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6646 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
6647 IPW_WARNING("Can't set TKIP countermeasures: "
6648 "crypt not set!\n");
6649 break;
6650 }
6651
6652 flags = crypt->ops->get_flags(crypt->priv);
6653
6654 if (param->value)
6655 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6656 else
6657 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6658
6659 crypt->ops->set_flags(flags, crypt->priv);
6660
6661 break;
6662
6663 case IW_AUTH_DROP_UNENCRYPTED:{
6664 /* HACK:
6665 *
6666 * wpa_supplicant calls set_wpa_enabled when the driver
6667 * is loaded and unloaded, regardless of if WPA is being
6668 * used. No other calls are made which can be used to
6669 * determine if encryption will be used or not prior to
6670 * association being expected. If encryption is not being
6671 * used, drop_unencrypted is set to false, else true -- we
6672 * can use this to determine if the CAP_PRIVACY_ON bit should
6673 * be set.
6674 */
6675 struct ieee80211_security sec = {
6676 .flags = SEC_ENABLED,
6677 .enabled = param->value,
6678 };
6679 priv->ieee->drop_unencrypted = param->value;
6680 /* We only change SEC_LEVEL for open mode. Others
6681 * are set by ipw_wpa_set_encryption.
6682 */
6683 if (!param->value) {
6684 sec.flags |= SEC_LEVEL;
6685 sec.level = SEC_LEVEL_0;
6686 } else {
6687 sec.flags |= SEC_LEVEL;
6688 sec.level = SEC_LEVEL_1;
6689 }
6690 if (priv->ieee->set_security)
6691 priv->ieee->set_security(priv->ieee->dev, &sec);
6692 break;
6693 }
6694
6695 case IW_AUTH_80211_AUTH_ALG:
6696 ret = ipw_wpa_set_auth_algs(priv, param->value);
6697 break;
6698
6699 case IW_AUTH_WPA_ENABLED:
6700 ret = ipw_wpa_enable(priv, param->value);
6701 break;
6702
6703 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6704 ieee->ieee802_1x = param->value;
6705 break;
6706
6707 //case IW_AUTH_ROAMING_CONTROL:
6708 case IW_AUTH_PRIVACY_INVOKED:
6709 ieee->privacy_invoked = param->value;
6710 break;
6711
6712 default:
6713 return -EOPNOTSUPP;
6714 }
6715 return ret;
6716}
6717
6718/* SIOCGIWAUTH */
6719static int ipw_wx_get_auth(struct net_device *dev,
6720 struct iw_request_info *info,
6721 union iwreq_data *wrqu, char *extra)
6722{
6723 struct ipw_priv *priv = ieee80211_priv(dev);
6724 struct ieee80211_device *ieee = priv->ieee;
6725 struct ieee80211_crypt_data *crypt;
6726 struct iw_param *param = &wrqu->param;
6727 int ret = 0;
6728
6729 switch (param->flags & IW_AUTH_INDEX) {
6730 case IW_AUTH_WPA_VERSION:
6731 case IW_AUTH_CIPHER_PAIRWISE:
6732 case IW_AUTH_CIPHER_GROUP:
6733 case IW_AUTH_KEY_MGMT:
6734 /*
6735 * wpa_supplicant will control these internally
6736 */
6737 ret = -EOPNOTSUPP;
6738 break;
6739
6740 case IW_AUTH_TKIP_COUNTERMEASURES:
6741 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6742 if (!crypt || !crypt->ops->get_flags) {
6743 IPW_WARNING("Can't get TKIP countermeasures: "
6744 "crypt not set!\n");
6745 break;
6746 }
6747
6748 param->value = (crypt->ops->get_flags(crypt->priv) &
6749 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6750
6751 break;
6752
6753 case IW_AUTH_DROP_UNENCRYPTED:
6754 param->value = ieee->drop_unencrypted;
6755 break;
6756
6757 case IW_AUTH_80211_AUTH_ALG:
6758 param->value = ieee->sec.auth_mode;
6759 break;
6760
6761 case IW_AUTH_WPA_ENABLED:
6762 param->value = ieee->wpa_enabled;
6763 break;
6764
6765 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6766 param->value = ieee->ieee802_1x;
6767 break;
6768
6769 case IW_AUTH_ROAMING_CONTROL:
6770 case IW_AUTH_PRIVACY_INVOKED:
6771 param->value = ieee->privacy_invoked;
6772 break;
6773
6774 default:
6775 return -EOPNOTSUPP;
6776 }
6777 return 0;
6778}
6779
6780/* SIOCSIWENCODEEXT */
6781static int ipw_wx_set_encodeext(struct net_device *dev,
6782 struct iw_request_info *info,
6783 union iwreq_data *wrqu, char *extra)
6784{
6785 struct ipw_priv *priv = ieee80211_priv(dev);
6786 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6787
6788 if (hwcrypto) {
6789 /* IPW HW can't build TKIP MIC, host decryption still needed */
6790 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6791 priv->ieee->host_encrypt = 0;
6792 priv->ieee->host_encrypt_msdu = 1;
6793 priv->ieee->host_decrypt = 1;
6794 } else {
6795 priv->ieee->host_encrypt = 0;
6796 priv->ieee->host_encrypt_msdu = 0;
6797 priv->ieee->host_decrypt = 0;
6798 }
6799 }
6800
6801 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6802}
6803
6804/* SIOCGIWENCODEEXT */
6805static int ipw_wx_get_encodeext(struct net_device *dev,
6806 struct iw_request_info *info,
6807 union iwreq_data *wrqu, char *extra)
6808{
6809 struct ipw_priv *priv = ieee80211_priv(dev);
6810 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6811}
6812
6813/* SIOCSIWMLME */
6814static int ipw_wx_set_mlme(struct net_device *dev,
6815 struct iw_request_info *info,
6816 union iwreq_data *wrqu, char *extra)
6817{
6818 struct ipw_priv *priv = ieee80211_priv(dev);
6819 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6820 u16 reason;
6821
6822 reason = cpu_to_le16(mlme->reason_code);
6823
6824 switch (mlme->cmd) {
6825 case IW_MLME_DEAUTH:
6826 // silently ignore
6827 break;
6828
6829 case IW_MLME_DISASSOC:
6830 ipw_disassociate(priv);
6831 break;
6832
6833 default:
6834 return -EOPNOTSUPP;
6835 }
6836 return 0;
6837}
6838#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -05006839
James Ketrenosb095c382005-08-24 22:04:42 -05006840#ifdef CONFIG_IPW_QOS
6841
6842/* QoS */
6843/*
6844* get the modulation type of the current network or
6845* the card current mode
6846*/
6847u8 ipw_qos_current_mode(struct ipw_priv * priv)
6848{
6849 u8 mode = 0;
6850
6851 if (priv->status & STATUS_ASSOCIATED) {
6852 unsigned long flags;
6853
6854 spin_lock_irqsave(&priv->ieee->lock, flags);
6855 mode = priv->assoc_network->mode;
6856 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6857 } else {
6858 mode = priv->ieee->mode;
6859 }
6860 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6861 return mode;
6862}
6863
6864/*
6865* Handle management frame beacon and probe response
6866*/
6867static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
6868 int active_network,
6869 struct ieee80211_network *network)
6870{
6871 u32 size = sizeof(struct ieee80211_qos_parameters);
6872
James Ketrenosafbf30a2005-08-25 00:05:33 -05006873 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006874 network->qos_data.active = network->qos_data.supported;
6875
6876 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006877 if (active_network &&
6878 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006879 network->qos_data.active = network->qos_data.supported;
6880
6881 if ((network->qos_data.active == 1) && (active_network == 1) &&
6882 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6883 (network->qos_data.old_param_count !=
6884 network->qos_data.param_count)) {
6885 network->qos_data.old_param_count =
6886 network->qos_data.param_count;
6887 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006888 IPW_DEBUG_QOS("QoS parameters change call "
6889 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006890 }
6891 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006892 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6893 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006894 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006895 else
6896 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006897 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006898
James Ketrenosb095c382005-08-24 22:04:42 -05006899 if ((network->qos_data.active == 1) && (active_network == 1)) {
6900 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6901 schedule_work(&priv->qos_activate);
6902 }
6903
6904 network->qos_data.active = 0;
6905 network->qos_data.supported = 0;
6906 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006907 if ((priv->status & STATUS_ASSOCIATED) &&
6908 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6909 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6910 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6911 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006912 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006913 priv->assoc_network->ssid_len) &&
6914 !memcmp(network->ssid,
6915 priv->assoc_network->ssid,
6916 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006917 queue_work(priv->workqueue,
6918 &priv->merge_networks);
6919 }
James Ketrenosb095c382005-08-24 22:04:42 -05006920 }
6921
6922 return 0;
6923}
6924
6925/*
6926* This function set up the firmware to support QoS. It sends
6927* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6928*/
6929static int ipw_qos_activate(struct ipw_priv *priv,
6930 struct ieee80211_qos_data *qos_network_data)
6931{
6932 int err;
6933 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6934 struct ieee80211_qos_parameters *active_one = NULL;
6935 u32 size = sizeof(struct ieee80211_qos_parameters);
6936 u32 burst_duration;
6937 int i;
6938 u8 type;
6939
6940 type = ipw_qos_current_mode(priv);
6941
6942 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6943 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6944 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6945 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6946
6947 if (qos_network_data == NULL) {
6948 if (type == IEEE_B) {
6949 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6950 active_one = &def_parameters_CCK;
6951 } else
6952 active_one = &def_parameters_OFDM;
6953
James Ketrenosafbf30a2005-08-25 00:05:33 -05006954 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006955 burst_duration = ipw_qos_get_burst_duration(priv);
6956 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006957 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6958 (u16) burst_duration;
6959 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006960 if (type == IEEE_B) {
6961 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6962 type);
6963 if (priv->qos_data.qos_enable == 0)
6964 active_one = &def_parameters_CCK;
6965 else
6966 active_one = priv->qos_data.def_qos_parm_CCK;
6967 } else {
6968 if (priv->qos_data.qos_enable == 0)
6969 active_one = &def_parameters_OFDM;
6970 else
6971 active_one = priv->qos_data.def_qos_parm_OFDM;
6972 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006973 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006974 } else {
6975 unsigned long flags;
6976 int active;
6977
6978 spin_lock_irqsave(&priv->ieee->lock, flags);
6979 active_one = &(qos_network_data->parameters);
6980 qos_network_data->old_param_count =
6981 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006982 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006983 active = qos_network_data->supported;
6984 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6985
6986 if (active == 0) {
6987 burst_duration = ipw_qos_get_burst_duration(priv);
6988 for (i = 0; i < QOS_QUEUE_NUM; i++)
6989 qos_parameters[QOS_PARAM_SET_ACTIVE].
6990 tx_op_limit[i] = (u16) burst_duration;
6991 }
6992 }
6993
6994 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006995 err = ipw_send_qos_params_command(priv,
6996 (struct ieee80211_qos_parameters *)
6997 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006998 if (err)
6999 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7000
7001 return err;
7002}
7003
7004/*
7005* send IPW_CMD_WME_INFO to the firmware
7006*/
7007static int ipw_qos_set_info_element(struct ipw_priv *priv)
7008{
7009 int ret = 0;
7010 struct ieee80211_qos_information_element qos_info;
7011
7012 if (priv == NULL)
7013 return -1;
7014
7015 qos_info.elementID = QOS_ELEMENT_ID;
7016 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
7017
7018 qos_info.version = QOS_VERSION_1;
7019 qos_info.ac_info = 0;
7020
7021 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7022 qos_info.qui_type = QOS_OUI_TYPE;
7023 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7024
7025 ret = ipw_send_qos_info_command(priv, &qos_info);
7026 if (ret != 0) {
7027 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7028 }
7029 return ret;
7030}
7031
7032/*
7033* Set the QoS parameter with the association request structure
7034*/
7035static int ipw_qos_association(struct ipw_priv *priv,
7036 struct ieee80211_network *network)
7037{
7038 int err = 0;
7039 struct ieee80211_qos_data *qos_data = NULL;
7040 struct ieee80211_qos_data ibss_data = {
7041 .supported = 1,
7042 .active = 1,
7043 };
7044
7045 switch (priv->ieee->iw_mode) {
7046 case IW_MODE_ADHOC:
7047 if (!(network->capability & WLAN_CAPABILITY_IBSS))
7048 BUG();
7049
7050 qos_data = &ibss_data;
7051 break;
7052
7053 case IW_MODE_INFRA:
7054 qos_data = &network->qos_data;
7055 break;
7056
7057 default:
7058 BUG();
7059 break;
7060 }
7061
7062 err = ipw_qos_activate(priv, qos_data);
7063 if (err) {
7064 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7065 return err;
7066 }
7067
7068 if (priv->qos_data.qos_enable && qos_data->supported) {
7069 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7070 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7071 return ipw_qos_set_info_element(priv);
7072 }
7073
7074 return 0;
7075}
7076
7077/*
7078* handling the beaconing responces. if we get different QoS setting
7079* of the network from the the associated setting adjust the QoS
7080* setting
7081*/
7082static int ipw_qos_association_resp(struct ipw_priv *priv,
7083 struct ieee80211_network *network)
7084{
7085 int ret = 0;
7086 unsigned long flags;
7087 u32 size = sizeof(struct ieee80211_qos_parameters);
7088 int set_qos_param = 0;
7089
James Ketrenosafbf30a2005-08-25 00:05:33 -05007090 if ((priv == NULL) || (network == NULL) ||
7091 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05007092 return ret;
7093
7094 if (!(priv->status & STATUS_ASSOCIATED))
7095 return ret;
7096
James Ketrenosafbf30a2005-08-25 00:05:33 -05007097 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05007098 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05007099
7100 spin_lock_irqsave(&priv->ieee->lock, flags);
7101 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007102 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05007103 sizeof(struct ieee80211_qos_data));
7104 priv->assoc_network->qos_data.active = 1;
7105 if ((network->qos_data.old_param_count !=
7106 network->qos_data.param_count)) {
7107 set_qos_param = 1;
7108 network->qos_data.old_param_count =
7109 network->qos_data.param_count;
7110 }
7111
7112 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007113 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7114 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007115 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05007116 else
7117 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05007118 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05007119 priv->assoc_network->qos_data.active = 0;
7120 priv->assoc_network->qos_data.supported = 0;
7121 set_qos_param = 1;
7122 }
7123
7124 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7125
7126 if (set_qos_param == 1)
7127 schedule_work(&priv->qos_activate);
7128
7129 return ret;
7130}
7131
7132static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7133{
7134 u32 ret = 0;
7135
7136 if ((priv == NULL))
7137 return 0;
7138
James Ketrenosafbf30a2005-08-25 00:05:33 -05007139 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007140 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007141 else
James Ketrenosb095c382005-08-24 22:04:42 -05007142 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007143
James Ketrenosb095c382005-08-24 22:04:42 -05007144 return ret;
7145}
7146
7147/*
7148* Initialize the setting of QoS global
7149*/
7150static void ipw_qos_init(struct ipw_priv *priv, int enable,
7151 int burst_enable, u32 burst_duration_CCK,
7152 u32 burst_duration_OFDM)
7153{
7154 priv->qos_data.qos_enable = enable;
7155
7156 if (priv->qos_data.qos_enable) {
7157 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7158 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7159 IPW_DEBUG_QOS("QoS is enabled\n");
7160 } else {
7161 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7162 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7163 IPW_DEBUG_QOS("QoS is not enabled\n");
7164 }
7165
7166 priv->qos_data.burst_enable = burst_enable;
7167
7168 if (burst_enable) {
7169 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7170 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7171 } else {
7172 priv->qos_data.burst_duration_CCK = 0;
7173 priv->qos_data.burst_duration_OFDM = 0;
7174 }
7175}
7176
7177/*
7178* map the packet priority to the right TX Queue
7179*/
7180static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7181{
7182 if (priority > 7 || !priv->qos_data.qos_enable)
7183 priority = 0;
7184
7185 return from_priority_to_tx_queue[priority] - 1;
7186}
7187
7188/*
7189* add QoS parameter to the TX command
7190*/
7191static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7192 u16 priority,
7193 struct tfd_data *tfd, u8 unicast)
7194{
7195 int ret = 0;
7196 int tx_queue_id = 0;
7197 struct ieee80211_qos_data *qos_data = NULL;
7198 int active, supported;
7199 unsigned long flags;
7200
7201 if (!(priv->status & STATUS_ASSOCIATED))
7202 return 0;
7203
7204 qos_data = &priv->assoc_network->qos_data;
7205
7206 spin_lock_irqsave(&priv->ieee->lock, flags);
7207
7208 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7209 if (unicast == 0)
7210 qos_data->active = 0;
7211 else
7212 qos_data->active = qos_data->supported;
7213 }
7214
7215 active = qos_data->active;
7216 supported = qos_data->supported;
7217
7218 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7219
James Ketrenosafbf30a2005-08-25 00:05:33 -05007220 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7221 "unicast %d\n",
7222 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05007223 if (active && priv->qos_data.qos_enable) {
7224 ret = from_priority_to_tx_queue[priority];
7225 tx_queue_id = ret - 1;
7226 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
7227 if (priority <= 7) {
7228 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7229 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
7230 tfd->tfd.tfd_26.mchdr.frame_ctl |=
7231 IEEE80211_STYPE_QOS_DATA;
7232
7233 if (priv->qos_data.qos_no_ack_mask &
7234 (1UL << tx_queue_id)) {
7235 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7236 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
7237 CTRL_QOS_NO_ACK;
7238 }
7239 }
7240 }
7241
7242 return ret;
7243}
7244
7245/*
7246* background support to run QoS activate functionality
7247*/
7248static void ipw_bg_qos_activate(void *data)
7249{
7250 struct ipw_priv *priv = data;
7251
7252 if (priv == NULL)
7253 return;
7254
7255 down(&priv->sem);
7256
7257 if (priv->status & STATUS_ASSOCIATED)
7258 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7259
7260 up(&priv->sem);
7261}
7262
7263/*
7264* Handler for probe responce and beacon frame
7265*/
James Ketrenos2b184d52005-08-03 20:33:14 -05007266static int ipw_handle_management(struct net_device *dev,
7267 struct ieee80211_network *network, u16 type)
James Ketrenosb095c382005-08-24 22:04:42 -05007268{
7269 struct ipw_priv *priv = ieee80211_priv(dev);
7270 int active_network;
7271
7272 if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
7273 active_network = 1;
7274 else
7275 active_network = 0;
7276
7277 switch (type) {
7278 case IEEE80211_STYPE_PROBE_RESP:
7279 case IEEE80211_STYPE_BEACON:
7280 ipw_qos_handle_probe_reponse(priv, active_network, network);
7281 break;
7282 case IEEE80211_STYPE_ASSOC_RESP:
7283 ipw_qos_association_resp(priv, network);
7284 break;
7285 default:
7286 break;
7287 }
7288
7289 return 0;
7290}
7291
7292static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7293 *qos_param)
7294{
7295 struct host_cmd cmd = {
7296 .cmd = IPW_CMD_QOS_PARAMETERS,
7297 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7298 };
7299
7300 if (!priv || !qos_param) {
7301 IPW_ERROR("Invalid args\n");
7302 return -1;
7303 }
7304
James Ketrenosafbf30a2005-08-25 00:05:33 -05007305 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
James Ketrenosb095c382005-08-24 22:04:42 -05007306 if (ipw_send_cmd(priv, &cmd)) {
7307 IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
7308 return -1;
7309 }
7310
7311 return 0;
7312}
7313
7314static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7315 *qos_param)
7316{
7317 struct host_cmd cmd = {
7318 .cmd = IPW_CMD_WME_INFO,
7319 .len = sizeof(*qos_param)
7320 };
7321
7322 if (!priv || !qos_param) {
7323 IPW_ERROR("Invalid args\n");
7324 return -1;
7325 }
7326
James Ketrenosafbf30a2005-08-25 00:05:33 -05007327 memcpy(cmd.param, qos_param, sizeof(*qos_param));
James Ketrenosb095c382005-08-24 22:04:42 -05007328 if (ipw_send_cmd(priv, &cmd)) {
7329 IPW_ERROR("failed to send CMD_QOS_INFO command\n");
7330 return -1;
7331 }
7332
7333 return 0;
7334}
7335
7336#endif /* CONFIG_IPW_QOS */
7337
James Ketrenos43f66a62005-03-25 12:31:53 -06007338static int ipw_associate_network(struct ipw_priv *priv,
7339 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007340 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007341{
7342 int err;
7343
7344 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007345 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007346
7347 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007348 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007349 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007350 memcpy(priv->essid, network->ssid, priv->essid_len);
7351 }
7352
7353 network->last_associate = jiffies;
7354
7355 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7356 priv->assoc_request.channel = network->channel;
7357 if ((priv->capability & CAP_PRIVACY_ON) &&
7358 (priv->capability & CAP_SHARED_KEY)) {
7359 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007360 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7361
7362 if ((priv->capability & CAP_PRIVACY_ON) &&
7363 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7364 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7365 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
James Ketrenos43f66a62005-03-25 12:31:53 -06007366 } else {
7367 priv->assoc_request.auth_type = AUTH_OPEN;
7368 priv->assoc_request.auth_key = 0;
7369 }
7370
James Ketrenosa613bff2005-08-24 21:43:11 -05007371 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007372 priv->assoc_request.policy_support = 0x02; /* RSN active */
7373 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7374 priv->ieee->wpa_ie_len);
7375 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05007376
Jeff Garzikbf794512005-07-31 13:07:26 -04007377 /*
7378 * It is valid for our ieee device to support multiple modes, but
7379 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007380 * just one mode.
7381 */
7382 if (network->mode & priv->ieee->mode & IEEE_A)
7383 priv->assoc_request.ieee_mode = IPW_A_MODE;
7384 else if (network->mode & priv->ieee->mode & IEEE_G)
7385 priv->assoc_request.ieee_mode = IPW_G_MODE;
7386 else if (network->mode & priv->ieee->mode & IEEE_B)
7387 priv->assoc_request.ieee_mode = IPW_B_MODE;
7388
James Ketrenosea2b26e2005-08-24 21:25:16 -05007389 priv->assoc_request.capability = network->capability;
7390 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7391 && !(priv->config & CFG_PREAMBLE_LONG)) {
7392 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7393 } else {
7394 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7395
7396 /* Clear the short preamble if we won't be supporting it */
7397 priv->assoc_request.capability &=
7398 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7399 }
7400
James Ketrenosafbf30a2005-08-25 00:05:33 -05007401 /* Clear capability bits that aren't used in Ad Hoc */
7402 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7403 priv->assoc_request.capability &=
7404 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7405
James Ketrenos43f66a62005-03-25 12:31:53 -06007406 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007407 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007408 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007409 escape_essid(priv->essid, priv->essid_len),
7410 network->channel,
7411 ipw_modes[priv->assoc_request.ieee_mode],
7412 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007413 (priv->assoc_request.preamble_length ==
7414 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7415 network->capability &
7416 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007417 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007418 priv->capability & CAP_PRIVACY_ON ?
7419 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007420 "(open)") : "",
7421 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007422 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007423 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007424 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007425
7426 priv->assoc_request.beacon_interval = network->beacon_interval;
7427 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007428 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007429 priv->assoc_request.assoc_type = HC_IBSS_START;
7430 priv->assoc_request.assoc_tsf_msw = 0;
7431 priv->assoc_request.assoc_tsf_lsw = 0;
7432 } else {
7433 if (unlikely(roaming))
7434 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7435 else
7436 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7437 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7438 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7439 }
7440
James Ketrenosafbf30a2005-08-25 00:05:33 -05007441 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007442
7443 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7444 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7445 priv->assoc_request.atim_window = network->atim_window;
7446 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007447 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007448 priv->assoc_request.atim_window = 0;
7449 }
7450
James Ketrenos43f66a62005-03-25 12:31:53 -06007451 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007452
James Ketrenos43f66a62005-03-25 12:31:53 -06007453 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7454 if (err) {
7455 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7456 return err;
7457 }
7458
7459 rates->ieee_mode = priv->assoc_request.ieee_mode;
7460 rates->purpose = IPW_RATE_CONNECT;
7461 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007462
James Ketrenos43f66a62005-03-25 12:31:53 -06007463 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7464 priv->sys_config.dot11g_auto_detection = 1;
7465 else
7466 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007467
7468 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7469 priv->sys_config.answer_broadcast_ssid_probe = 1;
7470 else
7471 priv->sys_config.answer_broadcast_ssid_probe = 0;
7472
James Ketrenos43f66a62005-03-25 12:31:53 -06007473 err = ipw_send_system_config(priv, &priv->sys_config);
7474 if (err) {
7475 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7476 return err;
7477 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007478
James Ketrenos43f66a62005-03-25 12:31:53 -06007479 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007480 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007481 if (err) {
7482 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7483 return err;
7484 }
7485
7486 /*
7487 * If preemption is enabled, it is possible for the association
7488 * to complete before we return from ipw_send_associate. Therefore
7489 * we have to be sure and update our priviate data first.
7490 */
7491 priv->channel = network->channel;
7492 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007493 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007494 priv->status &= ~STATUS_SECURITY_UPDATED;
7495
7496 priv->assoc_network = network;
7497
James Ketrenosb095c382005-08-24 22:04:42 -05007498#ifdef CONFIG_IPW_QOS
7499 ipw_qos_association(priv, network);
7500#endif
7501
James Ketrenos43f66a62005-03-25 12:31:53 -06007502 err = ipw_send_associate(priv, &priv->assoc_request);
7503 if (err) {
7504 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7505 return err;
7506 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007507
7508 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007509 escape_essid(priv->essid, priv->essid_len),
7510 MAC_ARG(priv->bssid));
7511
7512 return 0;
7513}
7514
7515static void ipw_roam(void *data)
7516{
7517 struct ipw_priv *priv = data;
7518 struct ieee80211_network *network = NULL;
7519 struct ipw_network_match match = {
7520 .network = priv->assoc_network
7521 };
7522
7523 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007524 *
7525 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007526 * setting the status ROAM bit and requesting a scan.
7527 * 2. When the scan completes, it schedules the ROAM work
7528 * 3. The ROAM work looks at all of the known networks for one that
7529 * is a better network than the currently associated. If none
7530 * found, the ROAM process is over (ROAM bit cleared)
7531 * 4. If a better network is found, a disassociation request is
7532 * sent.
7533 * 5. When the disassociation completes, the roam work is again
7534 * scheduled. The second time through, the driver is no longer
7535 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007536 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007537 * 6. At this point ,the roaming process is complete and the ROAM
7538 * status bit is cleared.
7539 */
7540
7541 /* If we are no longer associated, and the roaming bit is no longer
7542 * set, then we are not actively roaming, so just return */
7543 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7544 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007545
James Ketrenos43f66a62005-03-25 12:31:53 -06007546 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007547 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007548 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007549 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007550 u8 rssi = priv->assoc_network->stats.rssi;
7551 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007552 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007553 list_for_each_entry(network, &priv->ieee->network_list, list) {
7554 if (network != priv->assoc_network)
7555 ipw_best_network(priv, &match, network, 1);
7556 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007557 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007558 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007559
James Ketrenos43f66a62005-03-25 12:31:53 -06007560 if (match.network == priv->assoc_network) {
7561 IPW_DEBUG_ASSOC("No better APs in this network to "
7562 "roam to.\n");
7563 priv->status &= ~STATUS_ROAMING;
7564 ipw_debug_config(priv);
7565 return;
7566 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007567
James Ketrenos43f66a62005-03-25 12:31:53 -06007568 ipw_send_disassociate(priv, 1);
7569 priv->assoc_network = match.network;
7570
7571 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007572 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007573
7574 /* Second pass through ROAM process -- request association */
7575 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7576 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7577 priv->status &= ~STATUS_ROAMING;
7578}
7579
James Ketrenosc848d0a2005-08-24 21:56:24 -05007580static void ipw_bg_roam(void *data)
7581{
7582 struct ipw_priv *priv = data;
7583 down(&priv->sem);
7584 ipw_roam(data);
7585 up(&priv->sem);
7586}
7587
7588static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007589{
7590 struct ipw_priv *priv = data;
7591
7592 struct ieee80211_network *network = NULL;
7593 struct ipw_network_match match = {
7594 .network = NULL
7595 };
7596 struct ipw_supported_rates *rates;
7597 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007598 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007599
James Ketrenosb095c382005-08-24 22:04:42 -05007600 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7601 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7602 return 0;
7603 }
7604
James Ketrenosc848d0a2005-08-24 21:56:24 -05007605 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007606 IPW_DEBUG_ASSOC("Not attempting association (already in "
7607 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007608 return 0;
7609 }
7610
7611 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007612 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7613 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007614 return 0;
7615 }
7616
James Ketrenos43f66a62005-03-25 12:31:53 -06007617 if (!(priv->config & CFG_ASSOCIATE) &&
7618 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007619 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007620 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007621 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007622 }
7623
James Ketrenosa613bff2005-08-24 21:43:11 -05007624 /* Protect our use of the network_list */
7625 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007626 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007627 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007628
7629 network = match.network;
7630 rates = &match.rates;
7631
7632 if (network == NULL &&
7633 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7634 priv->config & CFG_ADHOC_CREATE &&
7635 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007636 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007637 !list_empty(&priv->ieee->network_free_list)) {
7638 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007639 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007640 ipw_adhoc_create(priv, network);
7641 rates = &priv->rates;
7642 list_del(element);
7643 list_add_tail(&network->list, &priv->ieee->network_list);
7644 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007645 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007646
James Ketrenos43f66a62005-03-25 12:31:53 -06007647 /* If we reached the end of the list, then we don't have any valid
7648 * matching APs */
7649 if (!network) {
7650 ipw_debug_config(priv);
7651
James Ketrenosb095c382005-08-24 22:04:42 -05007652 if (!(priv->status & STATUS_SCANNING)) {
7653 if (!(priv->config & CFG_SPEED_SCAN))
7654 queue_delayed_work(priv->workqueue,
7655 &priv->request_scan,
7656 SCAN_INTERVAL);
7657 else
7658 queue_work(priv->workqueue,
7659 &priv->request_scan);
7660 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007661
James Ketrenosc848d0a2005-08-24 21:56:24 -05007662 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007663 }
7664
7665 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007666
7667 return 1;
7668}
7669
7670static void ipw_bg_associate(void *data)
7671{
7672 struct ipw_priv *priv = data;
7673 down(&priv->sem);
7674 ipw_associate(data);
7675 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06007676}
Jeff Garzikbf794512005-07-31 13:07:26 -04007677
James Ketrenosb095c382005-08-24 22:04:42 -05007678static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7679 struct sk_buff *skb)
7680{
7681 struct ieee80211_hdr *hdr;
7682 u16 fc;
7683
7684 hdr = (struct ieee80211_hdr *)skb->data;
7685 fc = le16_to_cpu(hdr->frame_ctl);
7686 if (!(fc & IEEE80211_FCTL_PROTECTED))
7687 return;
7688
7689 fc &= ~IEEE80211_FCTL_PROTECTED;
7690 hdr->frame_ctl = cpu_to_le16(fc);
7691 switch (priv->ieee->sec.level) {
7692 case SEC_LEVEL_3:
7693 /* Remove CCMP HDR */
7694 memmove(skb->data + IEEE80211_3ADDR_LEN,
7695 skb->data + IEEE80211_3ADDR_LEN + 8,
7696 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yia2d73e62005-07-13 12:24:51 -05007697 if (fc & IEEE80211_FCTL_MOREFRAGS)
7698 skb_trim(skb, skb->len - 16); /* 2*MIC */
7699 else
7700 skb_trim(skb, skb->len - 8); /* MIC */
James Ketrenosb095c382005-08-24 22:04:42 -05007701 break;
7702 case SEC_LEVEL_2:
7703 break;
7704 case SEC_LEVEL_1:
7705 /* Remove IV */
7706 memmove(skb->data + IEEE80211_3ADDR_LEN,
7707 skb->data + IEEE80211_3ADDR_LEN + 4,
7708 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yia2d73e62005-07-13 12:24:51 -05007709 if (fc & IEEE80211_FCTL_MOREFRAGS)
7710 skb_trim(skb, skb->len - 8); /* 2*ICV */
7711 else
7712 skb_trim(skb, skb->len - 4); /* ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007713 break;
7714 case SEC_LEVEL_0:
7715 break;
7716 default:
7717 printk(KERN_ERR "Unknow security level %d\n",
7718 priv->ieee->sec.level);
7719 break;
7720 }
7721}
7722
7723static void ipw_handle_data_packet(struct ipw_priv *priv,
7724 struct ipw_rx_mem_buffer *rxb,
7725 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007726{
7727 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7728
7729 /* We received data from the HW, so stop the watchdog */
7730 priv->net_dev->trans_start = jiffies;
7731
Jeff Garzikbf794512005-07-31 13:07:26 -04007732 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007733 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007734 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007735 skb_tailroom(rxb->skb))) {
7736 priv->ieee->stats.rx_errors++;
7737 priv->wstats.discard.misc++;
7738 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7739 return;
7740 } else if (unlikely(!netif_running(priv->net_dev))) {
7741 priv->ieee->stats.rx_dropped++;
7742 priv->wstats.discard.misc++;
7743 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7744 return;
7745 }
7746
7747 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007748 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007749
7750 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007751 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007752
7753 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7754
James Ketrenosb095c382005-08-24 22:04:42 -05007755 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7756 if (!priv->ieee->host_decrypt)
7757 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7758
Jeff Garzikbf794512005-07-31 13:07:26 -04007759 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007760 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007761 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007762 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007763 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007764 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007765}
7766
James Ketrenosea2b26e2005-08-24 21:25:16 -05007767static inline int is_network_packet(struct ipw_priv *priv,
7768 struct ieee80211_hdr_4addr *header)
7769{
7770 /* Filter incoming packets to determine if they are targetted toward
7771 * this network, discarding packets coming from ourselves */
7772 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007773 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007774 /* packets from our adapter are dropped (echo) */
7775 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7776 return 0;
7777
James Ketrenosafbf30a2005-08-25 00:05:33 -05007778 /* multicast packets to our IBSS go through */
7779 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007780 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007781
7782 /* packets to our adapter go through */
7783 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7784 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007785
7786 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007787 /* packets from our adapter are dropped (echo) */
7788 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7789 return 0;
7790
James Ketrenosa613bff2005-08-24 21:43:11 -05007791 /* {broad,multi}cast packets to our IBSS go through */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007792 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007793 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7794
7795 /* packets to our adapter go through */
7796 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7797 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007798 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007799
James Ketrenosea2b26e2005-08-24 21:25:16 -05007800 return 1;
7801}
7802
James Ketrenosafbf30a2005-08-25 00:05:33 -05007803#define IPW_PACKET_RETRY_TIME HZ
7804
7805static inline int is_duplicate_packet(struct ipw_priv *priv,
7806 struct ieee80211_hdr_4addr *header)
7807{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007808 u16 sc = le16_to_cpu(header->seq_ctl);
7809 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7810 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7811 u16 *last_seq, *last_frag;
7812 unsigned long *last_time;
7813
7814 switch (priv->ieee->iw_mode) {
7815 case IW_MODE_ADHOC:
7816 {
7817 struct list_head *p;
7818 struct ipw_ibss_seq *entry = NULL;
7819 u8 *mac = header->addr2;
7820 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7821
7822 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7823 entry =
7824 list_entry(p, struct ipw_ibss_seq, list);
7825 if (!memcmp(entry->mac, mac, ETH_ALEN))
7826 break;
7827 }
7828 if (p == &priv->ibss_mac_hash[index]) {
7829 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7830 if (!entry) {
7831 IPW_ERROR
7832 ("Cannot malloc new mac entry\n");
7833 return 0;
7834 }
7835 memcpy(entry->mac, mac, ETH_ALEN);
7836 entry->seq_num = seq;
7837 entry->frag_num = frag;
7838 entry->packet_time = jiffies;
7839 list_add(&entry->list,
7840 &priv->ibss_mac_hash[index]);
7841 return 0;
7842 }
7843 last_seq = &entry->seq_num;
7844 last_frag = &entry->frag_num;
7845 last_time = &entry->packet_time;
7846 break;
7847 }
7848 case IW_MODE_INFRA:
7849 last_seq = &priv->last_seq_num;
7850 last_frag = &priv->last_frag_num;
7851 last_time = &priv->last_packet_time;
7852 break;
7853 default:
7854 return 0;
7855 }
7856 if ((*last_seq == seq) &&
7857 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7858 if (*last_frag == frag)
7859 goto drop;
7860 if (*last_frag + 1 != frag)
7861 /* out-of-order fragment */
7862 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007863 } else
7864 *last_seq = seq;
7865
Zhu Yif57ce7c2005-07-13 12:22:15 -05007866 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007867 *last_time = jiffies;
7868 return 0;
7869
7870 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007871 /* Comment this line now since we observed the card receives
7872 * duplicate packets but the FCTL_RETRY bit is not set in the
7873 * IBSS mode with fragmentation enabled.
7874 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007875 return 1;
7876}
7877
James Ketrenosb095c382005-08-24 22:04:42 -05007878static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7879 struct ipw_rx_mem_buffer *rxb,
7880 struct ieee80211_rx_stats *stats)
7881{
7882 struct sk_buff *skb = rxb->skb;
7883 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7884 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7885 (skb->data + IPW_RX_FRAME_SIZE);
7886
7887 ieee80211_rx_mgt(priv->ieee, header, stats);
7888
7889 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7890 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7891 IEEE80211_STYPE_PROBE_RESP) ||
7892 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7893 IEEE80211_STYPE_BEACON))) {
7894 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7895 ipw_add_station(priv, header->addr2);
7896 }
7897
7898 if (priv->config & CFG_NET_STATS) {
7899 IPW_DEBUG_HC("sending stat packet\n");
7900
7901 /* Set the size of the skb to the size of the full
7902 * ipw header and 802.11 frame */
7903 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7904 IPW_RX_FRAME_SIZE);
7905
7906 /* Advance past the ipw packet header to the 802.11 frame */
7907 skb_pull(skb, IPW_RX_FRAME_SIZE);
7908
7909 /* Push the ieee80211_rx_stats before the 802.11 frame */
7910 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7911
7912 skb->dev = priv->ieee->dev;
7913
7914 /* Point raw at the ieee80211_stats */
7915 skb->mac.raw = skb->data;
7916
7917 skb->pkt_type = PACKET_OTHERHOST;
7918 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7919 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7920 netif_rx(skb);
7921 rxb->skb = NULL;
7922 }
7923}
7924
James Ketrenos43f66a62005-03-25 12:31:53 -06007925/*
7926 * Main entry function for recieving a packet with 80211 headers. This
7927 * should be called when ever the FW has notified us that there is a new
7928 * skb in the recieve queue.
7929 */
7930static void ipw_rx(struct ipw_priv *priv)
7931{
7932 struct ipw_rx_mem_buffer *rxb;
7933 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007934 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007935 u32 r, w, i;
7936 u8 network_packet;
7937
James Ketrenosb095c382005-08-24 22:04:42 -05007938 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7939 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007940 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7941
7942 while (i != r) {
7943 rxb = priv->rxq->queue[i];
7944#ifdef CONFIG_IPW_DEBUG
7945 if (unlikely(rxb == NULL)) {
7946 printk(KERN_CRIT "Queue not allocated!\n");
7947 break;
7948 }
7949#endif
7950 priv->rxq->queue[i] = NULL;
7951
7952 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007953 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007954 PCI_DMA_FROMDEVICE);
7955
7956 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7957 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7958 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007959 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007960
7961 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007962 case RX_FRAME_TYPE: /* 802.11 frame */ {
7963 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007964 .rssi =
7965 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007966 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007967 .signal =
7968 le16_to_cpu(pkt->u.frame.signal),
7969 .noise =
7970 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007971 .rate = pkt->u.frame.rate,
7972 .mac_time = jiffies,
7973 .received_channel =
7974 pkt->u.frame.received_channel,
7975 .freq =
7976 (pkt->u.frame.
7977 control & (1 << 0)) ?
7978 IEEE80211_24GHZ_BAND :
7979 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007980 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007981 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007982
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007983 if (stats.rssi != 0)
7984 stats.mask |= IEEE80211_STATMASK_RSSI;
7985 if (stats.signal != 0)
7986 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007987 if (stats.noise != 0)
7988 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007989 if (stats.rate != 0)
7990 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007991
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007992 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007993
James Ketrenosb095c382005-08-24 22:04:42 -05007994#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007995 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7996 ipw_handle_data_packet(priv, rxb,
7997 &stats);
7998 break;
7999 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008000#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008001
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008002 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008003 (struct ieee80211_hdr_4addr *)(rxb->skb->
8004 data +
8005 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008006 /* TODO: Check Ad-Hoc dest/source and make sure
8007 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008008 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008009 * frame control of the packet and disregard
8010 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008011
James Ketrenosea2b26e2005-08-24 21:25:16 -05008012 network_packet =
8013 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008014 if (network_packet && priv->assoc_network) {
8015 priv->assoc_network->stats.rssi =
8016 stats.rssi;
8017 average_add(&priv->average_rssi,
8018 stats.rssi);
8019 priv->last_rx_rssi = stats.rssi;
8020 }
8021
8022 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008023 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008024
James Ketrenosa613bff2005-08-24 21:43:11 -05008025 if (le16_to_cpu(pkt->u.frame.length) <
8026 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008027 IPW_DEBUG_DROP
8028 ("Received packet is too small. "
8029 "Dropping.\n");
8030 priv->ieee->stats.rx_errors++;
8031 priv->wstats.discard.misc++;
8032 break;
8033 }
8034
James Ketrenosa613bff2005-08-24 21:43:11 -05008035 switch (WLAN_FC_GET_TYPE
8036 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008037
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008038 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008039 ipw_handle_mgmt_packet(priv, rxb,
8040 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008041 break;
8042
8043 case IEEE80211_FTYPE_CTL:
8044 break;
8045
8046 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008047 if (unlikely(!network_packet ||
8048 is_duplicate_packet(priv,
8049 header)))
8050 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008051 IPW_DEBUG_DROP("Dropping: "
8052 MAC_FMT ", "
8053 MAC_FMT ", "
8054 MAC_FMT "\n",
8055 MAC_ARG(header->
8056 addr1),
8057 MAC_ARG(header->
8058 addr2),
8059 MAC_ARG(header->
8060 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008061 break;
8062 }
8063
8064 ipw_handle_data_packet(priv, rxb,
8065 &stats);
8066
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008067 break;
8068 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008069 break;
8070 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008071
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008072 case RX_HOST_NOTIFICATION_TYPE:{
8073 IPW_DEBUG_RX
8074 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008075 pkt->u.notification.subtype,
8076 pkt->u.notification.flags,
8077 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008078 ipw_rx_notification(priv, &pkt->u.notification);
8079 break;
8080 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008081
8082 default:
8083 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8084 pkt->header.message_type);
8085 break;
8086 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008087
8088 /* For now we just don't re-use anything. We can tweak this
8089 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008090 * fail to Rx correctly */
8091 if (rxb->skb != NULL) {
8092 dev_kfree_skb_any(rxb->skb);
8093 rxb->skb = NULL;
8094 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008095
James Ketrenos43f66a62005-03-25 12:31:53 -06008096 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008097 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008098 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008099
James Ketrenos43f66a62005-03-25 12:31:53 -06008100 i = (i + 1) % RX_QUEUE_SIZE;
8101 }
8102
8103 /* Backtrack one entry */
8104 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8105
8106 ipw_rx_queue_restock(priv);
8107}
8108
James Ketrenosafbf30a2005-08-25 00:05:33 -05008109#define DEFAULT_RTS_THRESHOLD 2304U
8110#define MIN_RTS_THRESHOLD 1U
8111#define MAX_RTS_THRESHOLD 2304U
8112#define DEFAULT_BEACON_INTERVAL 100U
8113#define DEFAULT_SHORT_RETRY_LIMIT 7U
8114#define DEFAULT_LONG_RETRY_LIMIT 4U
8115
8116static int ipw_sw_reset(struct ipw_priv *priv, int init)
8117{
8118 int band, modulation;
8119 int old_mode = priv->ieee->iw_mode;
8120
8121 /* Initialize module parameter values here */
8122 priv->config = 0;
8123
8124 /* We default to disabling the LED code as right now it causes
8125 * too many systems to lock up... */
8126 if (!led)
8127 priv->config |= CFG_NO_LED;
8128
8129 if (associate)
8130 priv->config |= CFG_ASSOCIATE;
8131 else
8132 IPW_DEBUG_INFO("Auto associate disabled.\n");
8133
8134 if (auto_create)
8135 priv->config |= CFG_ADHOC_CREATE;
8136 else
8137 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8138
8139 if (disable) {
8140 priv->status |= STATUS_RF_KILL_SW;
8141 IPW_DEBUG_INFO("Radio disabled.\n");
8142 }
8143
8144 if (channel != 0) {
8145 priv->config |= CFG_STATIC_CHANNEL;
8146 priv->channel = channel;
8147 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8148 /* TODO: Validate that provided channel is in range */
8149 }
8150#ifdef CONFIG_IPW_QOS
8151 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8152 burst_duration_CCK, burst_duration_OFDM);
8153#endif /* CONFIG_IPW_QOS */
8154
8155 switch (mode) {
8156 case 1:
8157 priv->ieee->iw_mode = IW_MODE_ADHOC;
8158 priv->net_dev->type = ARPHRD_ETHER;
8159
8160 break;
8161#ifdef CONFIG_IPW2200_MONITOR
8162 case 2:
8163 priv->ieee->iw_mode = IW_MODE_MONITOR;
8164 priv->net_dev->type = ARPHRD_IEEE80211;
8165 break;
8166#endif
8167 default:
8168 case 0:
8169 priv->net_dev->type = ARPHRD_ETHER;
8170 priv->ieee->iw_mode = IW_MODE_INFRA;
8171 break;
8172 }
8173
8174 if (hwcrypto) {
8175 priv->ieee->host_encrypt = 0;
8176 priv->ieee->host_encrypt_msdu = 0;
8177 priv->ieee->host_decrypt = 0;
8178 }
8179 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8180
Zhu Yie402c932005-08-05 17:20:40 +08008181 /* IPW2200/2915 is abled to do hardware fragmentation. */
8182 priv->ieee->host_open_frag = 0;
8183
James Ketrenosafbf30a2005-08-25 00:05:33 -05008184 if ((priv->pci_dev->device == 0x4223) ||
8185 (priv->pci_dev->device == 0x4224)) {
8186 if (init)
8187 printk(KERN_INFO DRV_NAME
8188 ": Detected Intel PRO/Wireless 2915ABG Network "
8189 "Connection\n");
8190 priv->ieee->abg_true = 1;
8191 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8192 modulation = IEEE80211_OFDM_MODULATION |
8193 IEEE80211_CCK_MODULATION;
8194 priv->adapter = IPW_2915ABG;
8195 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8196 } else {
8197 if (init)
8198 printk(KERN_INFO DRV_NAME
8199 ": Detected Intel PRO/Wireless 2200BG Network "
8200 "Connection\n");
8201
8202 priv->ieee->abg_true = 0;
8203 band = IEEE80211_24GHZ_BAND;
8204 modulation = IEEE80211_OFDM_MODULATION |
8205 IEEE80211_CCK_MODULATION;
8206 priv->adapter = IPW_2200BG;
8207 priv->ieee->mode = IEEE_G | IEEE_B;
8208 }
8209
8210 priv->ieee->freq_band = band;
8211 priv->ieee->modulation = modulation;
8212
8213 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8214
8215 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8216 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8217
8218 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8219 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8220 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8221
8222 /* If power management is turned on, default to AC mode */
8223 priv->power_mode = IPW_POWER_AC;
8224 priv->tx_power = IPW_TX_POWER_DEFAULT;
8225
Zhu Yi0ece35b2005-08-05 17:26:51 +08008226 return old_mode == priv->ieee->iw_mode;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008227}
8228
James Ketrenos43f66a62005-03-25 12:31:53 -06008229/*
8230 * This file defines the Wireless Extension handlers. It does not
8231 * define any methods of hardware manipulation and relies on the
8232 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008233 *
8234 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008235 * function used to poll the hardware vs. making unecessary calls.
8236 *
8237 */
8238
Jeff Garzikbf794512005-07-31 13:07:26 -04008239static int ipw_wx_get_name(struct net_device *dev,
8240 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008241 union iwreq_data *wrqu, char *extra)
8242{
8243 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008244 down(&priv->sem);
8245 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008246 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008247 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008248 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008249 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008250 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8251 ipw_modes[priv->assoc_request.ieee_mode]);
8252 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008253 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008254 return 0;
8255}
8256
8257static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8258{
8259 if (channel == 0) {
8260 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8261 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008262 IPW_DEBUG_ASSOC("Attempting to associate with new "
8263 "parameters.\n");
8264 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008265 return 0;
8266 }
8267
8268 priv->config |= CFG_STATIC_CHANNEL;
8269
8270 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008271 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8272 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008273 return 0;
8274 }
8275
8276 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8277 priv->channel = channel;
8278
James Ketrenosb095c382005-08-24 22:04:42 -05008279#ifdef CONFIG_IPW2200_MONITOR
8280 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008281 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008282 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008283 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008284 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008285 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008286 }
8287
8288 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8289 udelay(10);
8290
8291 if (priv->status & STATUS_SCANNING)
8292 IPW_DEBUG_SCAN("Still scanning...\n");
8293 else
8294 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8295 1000 - i);
8296
8297 return 0;
8298 }
8299#endif /* CONFIG_IPW2200_MONITOR */
8300
James Ketrenosc848d0a2005-08-24 21:56:24 -05008301 /* Network configuration changed -- force [re]association */
8302 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8303 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008304 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008305
8306 return 0;
8307}
8308
Jeff Garzikbf794512005-07-31 13:07:26 -04008309static int ipw_wx_set_freq(struct net_device *dev,
8310 struct iw_request_info *info,
8311 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008312{
8313 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008314 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008315 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008316 int ret = 0, i;
James Ketrenosb095c382005-08-24 22:04:42 -05008317 u8 channel;
8318
8319 if (fwrq->m == 0) {
8320 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8321 down(&priv->sem);
8322 ret = ipw_set_channel(priv, 0);
8323 up(&priv->sem);
8324 return ret;
8325 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008326 /* if setting by freq convert to channel */
8327 if (fwrq->e == 1) {
James Ketrenosb095c382005-08-24 22:04:42 -05008328 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8329 if (channel == 0)
8330 return -EINVAL;
8331 } else
8332 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008333
James Ketrenosb095c382005-08-24 22:04:42 -05008334 if (!ieee80211_is_valid_channel(priv->ieee, channel))
8335 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008336
James Ketrenosafbf30a2005-08-25 00:05:33 -05008337 if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
8338 i = ieee80211_channel_to_index(priv->ieee, channel);
8339 if (i == -1)
8340 return -EINVAL;
8341 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
8342 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8343 return -EINVAL;
8344 }
8345 }
8346
James Ketrenos43f66a62005-03-25 12:31:53 -06008347 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008348 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008349 ret = ipw_set_channel(priv, channel);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008350 up(&priv->sem);
8351 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008352}
8353
Jeff Garzikbf794512005-07-31 13:07:26 -04008354static int ipw_wx_get_freq(struct net_device *dev,
8355 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008356 union iwreq_data *wrqu, char *extra)
8357{
8358 struct ipw_priv *priv = ieee80211_priv(dev);
8359
8360 wrqu->freq.e = 0;
8361
8362 /* If we are associated, trying to associate, or have a statically
8363 * configured CHANNEL then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008364 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008365 if (priv->config & CFG_STATIC_CHANNEL ||
8366 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8367 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008368 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008369 wrqu->freq.m = 0;
8370
James Ketrenosc848d0a2005-08-24 21:56:24 -05008371 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008372 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8373 return 0;
8374}
8375
Jeff Garzikbf794512005-07-31 13:07:26 -04008376static int ipw_wx_set_mode(struct net_device *dev,
8377 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008378 union iwreq_data *wrqu, char *extra)
8379{
8380 struct ipw_priv *priv = ieee80211_priv(dev);
8381 int err = 0;
8382
8383 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06008384
8385 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008386#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008387 case IW_MODE_MONITOR:
8388#endif
8389 case IW_MODE_ADHOC:
8390 case IW_MODE_INFRA:
8391 break;
8392 case IW_MODE_AUTO:
8393 wrqu->mode = IW_MODE_INFRA;
8394 break;
8395 default:
8396 return -EINVAL;
8397 }
James Ketrenosb095c382005-08-24 22:04:42 -05008398 if (wrqu->mode == priv->ieee->iw_mode)
8399 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008400
James Ketrenosb095c382005-08-24 22:04:42 -05008401 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008402
8403 ipw_sw_reset(priv, 0);
8404
James Ketrenosb095c382005-08-24 22:04:42 -05008405#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008406 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008407 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008408
8409 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008410 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosb095c382005-08-24 22:04:42 -05008411#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008412
Jeff Garzikbf794512005-07-31 13:07:26 -04008413 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008414 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008415 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008416
8417 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008418
James Ketrenosc848d0a2005-08-24 21:56:24 -05008419 queue_work(priv->workqueue, &priv->adapter_restart);
8420 up(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008421 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008422}
8423
Jeff Garzikbf794512005-07-31 13:07:26 -04008424static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008425 struct iw_request_info *info,
8426 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008427{
8428 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008429 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008430 wrqu->mode = priv->ieee->iw_mode;
8431 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008432 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008433 return 0;
8434}
8435
James Ketrenos43f66a62005-03-25 12:31:53 -06008436/* Values are in microsecond */
8437static const s32 timeout_duration[] = {
8438 350000,
8439 250000,
8440 75000,
8441 37000,
8442 25000,
8443};
8444
8445static const s32 period_duration[] = {
8446 400000,
8447 700000,
8448 1000000,
8449 1000000,
8450 1000000
8451};
8452
Jeff Garzikbf794512005-07-31 13:07:26 -04008453static int ipw_wx_get_range(struct net_device *dev,
8454 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008455 union iwreq_data *wrqu, char *extra)
8456{
8457 struct ipw_priv *priv = ieee80211_priv(dev);
8458 struct iw_range *range = (struct iw_range *)extra;
James Ketrenosb095c382005-08-24 22:04:42 -05008459 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8460 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008461
8462 wrqu->data.length = sizeof(*range);
8463 memset(range, 0, sizeof(*range));
8464
8465 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008466 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008467
8468 range->max_qual.qual = 100;
8469 /* TODO: Find real max RSSI and stick here */
8470 range->max_qual.level = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008471 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008472 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008473
8474 range->avg_qual.qual = 70;
8475 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008476 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008477 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008478 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008479 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008480 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008481
Jeff Garzikbf794512005-07-31 13:07:26 -04008482 for (i = 0; i < range->num_bitrates; i++)
8483 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008484 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008485
James Ketrenos43f66a62005-03-25 12:31:53 -06008486 range->max_rts = DEFAULT_RTS_THRESHOLD;
8487 range->min_frag = MIN_FRAG_THRESHOLD;
8488 range->max_frag = MAX_FRAG_THRESHOLD;
8489
8490 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008491 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008492 range->num_encoding_sizes = 2;
8493 range->max_encoding_tokens = WEP_KEYS;
8494
8495 /* Set the Wireless Extension versions */
8496 range->we_version_compiled = WIRELESS_EXT;
8497 range->we_version_source = 16;
8498
James Ketrenosb095c382005-08-24 22:04:42 -05008499 i = 0;
8500 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8501 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8502 i++, j++) {
8503 range->freq[i].i = geo->bg[j].channel;
8504 range->freq[i].m = geo->bg[j].freq * 100000;
8505 range->freq[i].e = 1;
8506 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008507 }
James Ketrenosb095c382005-08-24 22:04:42 -05008508
8509 if (priv->ieee->mode & IEEE_A) {
8510 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8511 i++, j++) {
8512 range->freq[i].i = geo->a[j].channel;
8513 range->freq[i].m = geo->a[j].freq * 100000;
8514 range->freq[i].e = 1;
8515 }
8516 }
8517
8518 range->num_channels = i;
8519 range->num_frequency = i;
8520
James Ketrenosc848d0a2005-08-24 21:56:24 -05008521 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008522 IPW_DEBUG_WX("GET Range\n");
8523 return 0;
8524}
8525
Jeff Garzikbf794512005-07-31 13:07:26 -04008526static int ipw_wx_set_wap(struct net_device *dev,
8527 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008528 union iwreq_data *wrqu, char *extra)
8529{
8530 struct ipw_priv *priv = ieee80211_priv(dev);
8531
8532 static const unsigned char any[] = {
8533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8534 };
8535 static const unsigned char off[] = {
8536 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8537 };
8538
Jeff Garzikbf794512005-07-31 13:07:26 -04008539 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008540 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008541 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8543 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8544 /* we disable mandatory BSSID association */
8545 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8546 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008547 IPW_DEBUG_ASSOC("Attempting to associate with new "
8548 "parameters.\n");
8549 ipw_associate(priv);
8550 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008551 return 0;
8552 }
8553
8554 priv->config |= CFG_STATIC_BSSID;
8555 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8556 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008557 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008558 return 0;
8559 }
8560
8561 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8562 MAC_ARG(wrqu->ap_addr.sa_data));
8563
8564 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8565
James Ketrenosc848d0a2005-08-24 21:56:24 -05008566 /* Network configuration changed -- force [re]association */
8567 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8568 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008569 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008570
James Ketrenosc848d0a2005-08-24 21:56:24 -05008571 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008572 return 0;
8573}
8574
Jeff Garzikbf794512005-07-31 13:07:26 -04008575static int ipw_wx_get_wap(struct net_device *dev,
8576 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 union iwreq_data *wrqu, char *extra)
8578{
8579 struct ipw_priv *priv = ieee80211_priv(dev);
8580 /* If we are associated, trying to associate, or have a statically
8581 * configured BSSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008582 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04008583 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8585 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008586 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008587 } else
8588 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8589
8590 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8591 MAC_ARG(wrqu->ap_addr.sa_data));
James Ketrenosc848d0a2005-08-24 21:56:24 -05008592 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 return 0;
8594}
8595
Jeff Garzikbf794512005-07-31 13:07:26 -04008596static int ipw_wx_set_essid(struct net_device *dev,
8597 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008598 union iwreq_data *wrqu, char *extra)
8599{
8600 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008601 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 int length = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008603 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008604 if (wrqu->essid.flags && wrqu->essid.length) {
8605 length = wrqu->essid.length - 1;
8606 essid = extra;
8607 }
8608 if (length == 0) {
8609 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008610 if ((priv->config & CFG_STATIC_ESSID) &&
8611 !(priv->status & (STATUS_ASSOCIATED |
8612 STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008613 IPW_DEBUG_ASSOC("Attempting to associate with new "
8614 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008615 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008616 ipw_associate(priv);
8617 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008618 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008619 return 0;
8620 }
8621
8622 length = min(length, IW_ESSID_MAX_SIZE);
8623
8624 priv->config |= CFG_STATIC_ESSID;
8625
8626 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8627 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008628 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008629 return 0;
8630 }
8631
8632 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8633 length);
8634
8635 priv->essid_len = length;
8636 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008637
James Ketrenosc848d0a2005-08-24 21:56:24 -05008638 /* Network configuration changed -- force [re]association */
8639 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8640 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008641 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008642
James Ketrenosc848d0a2005-08-24 21:56:24 -05008643 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008644 return 0;
8645}
8646
Jeff Garzikbf794512005-07-31 13:07:26 -04008647static int ipw_wx_get_essid(struct net_device *dev,
8648 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008649 union iwreq_data *wrqu, char *extra)
8650{
8651 struct ipw_priv *priv = ieee80211_priv(dev);
8652
8653 /* If we are associated, trying to associate, or have a statically
8654 * configured ESSID then return that; otherwise return ANY */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008655 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008656 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008657 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8658 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008659 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008660 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008661 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008662 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008663 } else {
8664 IPW_DEBUG_WX("Getting essid: ANY\n");
8665 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008666 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008667 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05008668 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008669 return 0;
8670}
8671
Jeff Garzikbf794512005-07-31 13:07:26 -04008672static int ipw_wx_set_nick(struct net_device *dev,
8673 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008674 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008675{
James Ketrenos43f66a62005-03-25 12:31:53 -06008676 struct ipw_priv *priv = ieee80211_priv(dev);
8677
8678 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8679 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8680 return -E2BIG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008681 down(&priv->sem);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008682 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008683 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008684 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008685 IPW_DEBUG_TRACE("<<\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008686 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008687 return 0;
8688
8689}
8690
Jeff Garzikbf794512005-07-31 13:07:26 -04008691static int ipw_wx_get_nick(struct net_device *dev,
8692 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008693 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008694{
James Ketrenos43f66a62005-03-25 12:31:53 -06008695 struct ipw_priv *priv = ieee80211_priv(dev);
8696 IPW_DEBUG_WX("Getting nick\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008697 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008698 wrqu->data.length = strlen(priv->nick) + 1;
8699 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008700 wrqu->data.flags = 1; /* active */
James Ketrenosc848d0a2005-08-24 21:56:24 -05008701 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008702 return 0;
8703}
8704
James Ketrenos43f66a62005-03-25 12:31:53 -06008705static int ipw_wx_set_rate(struct net_device *dev,
8706 struct iw_request_info *info,
8707 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008708{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008709 /* TODO: We should use semaphores or locks for access to priv */
8710 struct ipw_priv *priv = ieee80211_priv(dev);
8711 u32 target_rate = wrqu->bitrate.value;
8712 u32 fixed, mask;
8713
8714 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8715 /* value = X, fixed = 1 means only rate X */
8716 /* value = X, fixed = 0 means all rates lower equal X */
8717
8718 if (target_rate == -1) {
8719 fixed = 0;
8720 mask = IEEE80211_DEFAULT_RATES_MASK;
8721 /* Now we should reassociate */
8722 goto apply;
8723 }
8724
8725 mask = 0;
8726 fixed = wrqu->bitrate.fixed;
8727
8728 if (target_rate == 1000000 || !fixed)
8729 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8730 if (target_rate == 1000000)
8731 goto apply;
8732
8733 if (target_rate == 2000000 || !fixed)
8734 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8735 if (target_rate == 2000000)
8736 goto apply;
8737
8738 if (target_rate == 5500000 || !fixed)
8739 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8740 if (target_rate == 5500000)
8741 goto apply;
8742
8743 if (target_rate == 6000000 || !fixed)
8744 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8745 if (target_rate == 6000000)
8746 goto apply;
8747
8748 if (target_rate == 9000000 || !fixed)
8749 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8750 if (target_rate == 9000000)
8751 goto apply;
8752
8753 if (target_rate == 11000000 || !fixed)
8754 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8755 if (target_rate == 11000000)
8756 goto apply;
8757
8758 if (target_rate == 12000000 || !fixed)
8759 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8760 if (target_rate == 12000000)
8761 goto apply;
8762
8763 if (target_rate == 18000000 || !fixed)
8764 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8765 if (target_rate == 18000000)
8766 goto apply;
8767
8768 if (target_rate == 24000000 || !fixed)
8769 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8770 if (target_rate == 24000000)
8771 goto apply;
8772
8773 if (target_rate == 36000000 || !fixed)
8774 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8775 if (target_rate == 36000000)
8776 goto apply;
8777
8778 if (target_rate == 48000000 || !fixed)
8779 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8780 if (target_rate == 48000000)
8781 goto apply;
8782
8783 if (target_rate == 54000000 || !fixed)
8784 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8785 if (target_rate == 54000000)
8786 goto apply;
8787
8788 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8789 return -EINVAL;
8790
8791 apply:
8792 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8793 mask, fixed ? "fixed" : "sub-rates");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008794 down(&priv->sem);
James Ketrenosb095c382005-08-24 22:04:42 -05008795 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008796 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008797 ipw_set_fixed_rate(priv, priv->ieee->mode);
8798 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008799 priv->config |= CFG_FIXED_RATE;
8800
James Ketrenosc848d0a2005-08-24 21:56:24 -05008801 if (priv->rates_mask == mask) {
8802 IPW_DEBUG_WX("Mask set to current mask.\n");
8803 up(&priv->sem);
8804 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008805 }
8806
James Ketrenosc848d0a2005-08-24 21:56:24 -05008807 priv->rates_mask = mask;
8808
8809 /* Network configuration changed -- force [re]association */
8810 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8811 if (!ipw_disassociate(priv))
8812 ipw_associate(priv);
8813
8814 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008815 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008816}
8817
Jeff Garzikbf794512005-07-31 13:07:26 -04008818static int ipw_wx_get_rate(struct net_device *dev,
8819 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008820 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008821{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008822 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008823 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008824 wrqu->bitrate.value = priv->last_rate;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008825 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008826 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8827 return 0;
8828}
8829
Jeff Garzikbf794512005-07-31 13:07:26 -04008830static int ipw_wx_set_rts(struct net_device *dev,
8831 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008833{
James Ketrenos43f66a62005-03-25 12:31:53 -06008834 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008835 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 if (wrqu->rts.disabled)
8837 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8838 else {
8839 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008840 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8841 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008843 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 priv->rts_threshold = wrqu->rts.value;
8845 }
8846
8847 ipw_send_rts_threshold(priv, priv->rts_threshold);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008848 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008849 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8850 return 0;
8851}
8852
Jeff Garzikbf794512005-07-31 13:07:26 -04008853static int ipw_wx_get_rts(struct net_device *dev,
8854 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008855 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008856{
James Ketrenos43f66a62005-03-25 12:31:53 -06008857 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008858 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008859 wrqu->rts.value = priv->rts_threshold;
8860 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008861 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008862 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008863 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8864 return 0;
8865}
8866
Jeff Garzikbf794512005-07-31 13:07:26 -04008867static int ipw_wx_set_txpow(struct net_device *dev,
8868 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008869 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008870{
James Ketrenos43f66a62005-03-25 12:31:53 -06008871 struct ipw_priv *priv = ieee80211_priv(dev);
Liu Hong8400a1c2005-07-13 12:27:17 -05008872 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008873 struct ipw_tx_power tx_power;
8874 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008875
James Ketrenosc848d0a2005-08-24 21:56:24 -05008876 down(&priv->sem);
8877 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
8878 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 return -EINPROGRESS;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008880 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008881
James Ketrenosb095c382005-08-24 22:04:42 -05008882 if (!wrqu->power.fixed)
8883 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8884
James Ketrenosc848d0a2005-08-24 21:56:24 -05008885 if (wrqu->power.flags != IW_TXPOW_DBM) {
8886 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008887 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008888 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008889
James Ketrenosb095c382005-08-24 22:04:42 -05008890 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008891 (wrqu->power.value < IPW_TX_POWER_MIN)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008892 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008893 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008894 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008895
8896 priv->tx_power = wrqu->power.value;
8897
8898 memset(&tx_power, 0, sizeof(tx_power));
8899
8900 /* configure device for 'G' band */
8901 tx_power.ieee_mode = IPW_G_MODE;
Liu Hong8400a1c2005-07-13 12:27:17 -05008902 tx_power.num_channels = geo->bg_channels;
8903 for (i = 0; i < geo->bg_channels; i++) {
8904 int max_power = geo->bg[i].max_power;
8905
James Ketrenos43f66a62005-03-25 12:31:53 -06008906 tx_power.channels_tx_power[i].channel_number = i + 1;
Liu Hong8400a1c2005-07-13 12:27:17 -05008907 if (max_power != 0 && priv->tx_power > max_power)
8908 tx_power.channels_tx_power[i].tx_power = max_power;
8909 else
8910 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
James Ketrenos43f66a62005-03-25 12:31:53 -06008911 }
8912 if (ipw_send_tx_power(priv, &tx_power))
8913 goto error;
8914
8915 /* configure device to also handle 'B' band */
8916 tx_power.ieee_mode = IPW_B_MODE;
8917 if (ipw_send_tx_power(priv, &tx_power))
8918 goto error;
8919
Liu Hong8400a1c2005-07-13 12:27:17 -05008920 /* configure device to also handle 'A' band */
8921 if (priv->ieee->abg_true) {
8922 tx_power.ieee_mode = IPW_A_MODE;
8923 tx_power.num_channels = geo->a_channels;
8924 for (i = 0; i < geo->a_channels; i++) {
8925 int max_power = geo->a[i].max_power;
8926
8927 tx_power.channels_tx_power[i].channel_number = i + 1;
8928 if (max_power != 0 && priv->tx_power > max_power)
8929 tx_power.channels_tx_power[i].tx_power =
8930 max_power;
8931 else
8932 tx_power.channels_tx_power[i].tx_power =
8933 priv->tx_power;
8934 }
8935 if (ipw_send_tx_power(priv, &tx_power))
8936 goto error;
8937 }
8938
James Ketrenosc848d0a2005-08-24 21:56:24 -05008939 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008940 return 0;
8941
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008942 error:
James Ketrenosc848d0a2005-08-24 21:56:24 -05008943 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008944 return -EIO;
8945}
8946
Jeff Garzikbf794512005-07-31 13:07:26 -04008947static int ipw_wx_get_txpow(struct net_device *dev,
8948 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008949 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008950{
James Ketrenos43f66a62005-03-25 12:31:53 -06008951 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008952 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008953 wrqu->power.value = priv->tx_power;
8954 wrqu->power.fixed = 1;
8955 wrqu->power.flags = IW_TXPOW_DBM;
8956 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008957 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008958
Jeff Garzikbf794512005-07-31 13:07:26 -04008959 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008960 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008961
8962 return 0;
8963}
8964
Jeff Garzikbf794512005-07-31 13:07:26 -04008965static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008966 struct iw_request_info *info,
8967 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008968{
8969 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008970 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008971 if (wrqu->frag.disabled)
8972 priv->ieee->fts = DEFAULT_FTS;
8973 else {
8974 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008975 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8976 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008977 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008978 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008979
James Ketrenos43f66a62005-03-25 12:31:53 -06008980 priv->ieee->fts = wrqu->frag.value & ~0x1;
8981 }
8982
8983 ipw_send_frag_threshold(priv, wrqu->frag.value);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008984 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008985 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8986 return 0;
8987}
8988
Jeff Garzikbf794512005-07-31 13:07:26 -04008989static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008990 struct iw_request_info *info,
8991 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008992{
8993 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008994 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008995 wrqu->frag.value = priv->ieee->fts;
8996 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008997 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008998 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06008999 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9000
9001 return 0;
9002}
9003
Jeff Garzikbf794512005-07-31 13:07:26 -04009004static int ipw_wx_set_retry(struct net_device *dev,
9005 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009006 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009007{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009008 struct ipw_priv *priv = ieee80211_priv(dev);
9009
9010 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9011 return -EINVAL;
9012
9013 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9014 return 0;
9015
9016 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9017 return -EINVAL;
9018
9019 down(&priv->sem);
9020 if (wrqu->retry.flags & IW_RETRY_MIN)
9021 priv->short_retry_limit = (u8) wrqu->retry.value;
9022 else if (wrqu->retry.flags & IW_RETRY_MAX)
9023 priv->long_retry_limit = (u8) wrqu->retry.value;
9024 else {
9025 priv->short_retry_limit = (u8) wrqu->retry.value;
9026 priv->long_retry_limit = (u8) wrqu->retry.value;
9027 }
9028
9029 ipw_send_retry_limit(priv, priv->short_retry_limit,
9030 priv->long_retry_limit);
9031 up(&priv->sem);
9032 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9033 priv->short_retry_limit, priv->long_retry_limit);
9034 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009035}
9036
Jeff Garzikbf794512005-07-31 13:07:26 -04009037static int ipw_wx_get_retry(struct net_device *dev,
9038 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009039 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009040{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009041 struct ipw_priv *priv = ieee80211_priv(dev);
9042
9043 down(&priv->sem);
9044 wrqu->retry.disabled = 0;
9045
9046 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9047 up(&priv->sem);
9048 return -EINVAL;
9049 }
9050
9051 if (wrqu->retry.flags & IW_RETRY_MAX) {
9052 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9053 wrqu->retry.value = priv->long_retry_limit;
9054 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9055 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9056 wrqu->retry.value = priv->short_retry_limit;
9057 } else {
9058 wrqu->retry.flags = IW_RETRY_LIMIT;
9059 wrqu->retry.value = priv->short_retry_limit;
9060 }
9061 up(&priv->sem);
9062
9063 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9064
9065 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009066}
9067
James Ketrenosafbf30a2005-08-25 00:05:33 -05009068#if WIRELESS_EXT > 17
9069static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9070 int essid_len)
9071{
9072 struct ipw_scan_request_ext scan;
9073 int err = 0, scan_type;
9074
9075 down(&priv->sem);
9076
9077 if (priv->status & STATUS_RF_KILL_MASK) {
9078 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9079 priv->status |= STATUS_SCAN_PENDING;
9080 goto done;
9081 }
9082
9083 IPW_DEBUG_HC("starting request direct scan!\n");
9084
9085 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9086 err = wait_event_interruptible(priv->wait_state,
9087 !(priv->
9088 status & (STATUS_SCANNING |
9089 STATUS_SCAN_ABORTING)));
9090 if (err) {
9091 IPW_DEBUG_HC("aborting direct scan");
9092 goto done;
9093 }
9094 }
9095 memset(&scan, 0, sizeof(scan));
9096
9097 if (priv->config & CFG_SPEED_SCAN)
9098 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9099 cpu_to_le16(30);
9100 else
9101 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9102 cpu_to_le16(20);
9103
9104 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9105 cpu_to_le16(20);
9106 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
9107 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9108
9109 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9110
9111 err = ipw_send_ssid(priv, essid, essid_len);
9112 if (err) {
9113 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9114 goto done;
9115 }
9116 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9117
9118 ipw_add_scan_channels(priv, &scan, scan_type);
9119
9120 err = ipw_send_scan_request_ext(priv, &scan);
9121 if (err) {
9122 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9123 goto done;
9124 }
9125
9126 priv->status |= STATUS_SCANNING;
9127
9128 done:
9129 up(&priv->sem);
9130 return err;
9131}
9132#endif /* WIRELESS_EXT > 17 */
9133
Jeff Garzikbf794512005-07-31 13:07:26 -04009134static int ipw_wx_set_scan(struct net_device *dev,
9135 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 union iwreq_data *wrqu, char *extra)
9137{
9138 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009139#if WIRELESS_EXT > 17
9140 struct iw_scan_req *req = NULL;
9141 if (wrqu->data.length
9142 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9143 req = (struct iw_scan_req *)extra;
9144 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9145 ipw_request_direct_scan(priv, req->essid,
9146 req->essid_len);
9147 return 0;
9148 }
9149 }
9150#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009151 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009152
9153 queue_work(priv->workqueue, &priv->request_scan);
9154
James Ketrenos43f66a62005-03-25 12:31:53 -06009155 return 0;
9156}
9157
Jeff Garzikbf794512005-07-31 13:07:26 -04009158static int ipw_wx_get_scan(struct net_device *dev,
9159 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009160 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009161{
James Ketrenos43f66a62005-03-25 12:31:53 -06009162 struct ipw_priv *priv = ieee80211_priv(dev);
9163 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9164}
9165
Jeff Garzikbf794512005-07-31 13:07:26 -04009166static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 struct iw_request_info *info,
9168 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009169{
9170 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009171 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009172 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009173
9174 down(&priv->sem);
9175 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009176
Hong Liucaeff812005-08-05 17:25:50 +08009177 /* In IBSS mode, we need to notify the firmware to update
9178 * the beacon info after we changed the capability. */
9179 if (cap != priv->capability &&
9180 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9181 priv->status & STATUS_ASSOCIATED)
9182 ipw_disassociate(priv);
9183
9184 up(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009185 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009186}
9187
Jeff Garzikbf794512005-07-31 13:07:26 -04009188static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009189 struct iw_request_info *info,
9190 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009191{
9192 struct ipw_priv *priv = ieee80211_priv(dev);
9193 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9194}
9195
Jeff Garzikbf794512005-07-31 13:07:26 -04009196static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009197 struct iw_request_info *info,
9198 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009199{
9200 struct ipw_priv *priv = ieee80211_priv(dev);
9201 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009202 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009203 if (wrqu->power.disabled) {
9204 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9205 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9206 if (err) {
9207 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009208 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009209 return err;
9210 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009211 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009212 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009213 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009214 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009215
9216 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009217 case IW_POWER_ON: /* If not specified */
9218 case IW_POWER_MODE: /* If set all mask */
9219 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009220 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009221 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009222 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9223 wrqu->power.flags);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009224 up(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009225 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009226 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009227
James Ketrenos43f66a62005-03-25 12:31:53 -06009228 /* If the user hasn't specified a power management mode yet, default
9229 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009230 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009232 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009233 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9234 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9235 if (err) {
9236 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009237 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009238 return err;
9239 }
9240
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009241 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009242 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009243 return 0;
9244}
9245
Jeff Garzikbf794512005-07-31 13:07:26 -04009246static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009247 struct iw_request_info *info,
9248 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009249{
9250 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009251 down(&priv->sem);
James Ketrenosa613bff2005-08-24 21:43:11 -05009252 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009253 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009254 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009255 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009256
James Ketrenosc848d0a2005-08-24 21:56:24 -05009257 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009258 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009259
James Ketrenos43f66a62005-03-25 12:31:53 -06009260 return 0;
9261}
9262
Jeff Garzikbf794512005-07-31 13:07:26 -04009263static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009264 struct iw_request_info *info,
9265 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009266{
9267 struct ipw_priv *priv = ieee80211_priv(dev);
9268 int mode = *(int *)extra;
9269 int err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009270 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009271 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9272 mode = IPW_POWER_AC;
9273 priv->power_mode = mode;
9274 } else {
9275 priv->power_mode = IPW_POWER_ENABLED | mode;
9276 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009277
James Ketrenos43f66a62005-03-25 12:31:53 -06009278 if (priv->power_mode != mode) {
9279 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009280
James Ketrenos43f66a62005-03-25 12:31:53 -06009281 if (err) {
9282 IPW_DEBUG_WX("failed setting power mode.\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009283 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009284 return err;
9285 }
9286 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009287 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009288 return 0;
9289}
9290
9291#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009292static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009293 struct iw_request_info *info,
9294 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009295{
9296 struct ipw_priv *priv = ieee80211_priv(dev);
9297 int level = IPW_POWER_LEVEL(priv->power_mode);
9298 char *p = extra;
9299
9300 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9301
9302 switch (level) {
9303 case IPW_POWER_AC:
9304 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9305 break;
9306 case IPW_POWER_BATTERY:
9307 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9308 break;
9309 default:
9310 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009311 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009312 timeout_duration[level - 1] / 1000,
9313 period_duration[level - 1] / 1000);
9314 }
9315
9316 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009317 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009318
9319 wrqu->data.length = p - extra + 1;
9320
9321 return 0;
9322}
9323
9324static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009325 struct iw_request_info *info,
9326 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009327{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009328 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009329 int mode = *(int *)extra;
9330 u8 band = 0, modulation = 0;
9331
9332 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009333 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009334 return -EINVAL;
9335 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009336 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009337 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009338 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009339 if (mode & IEEE_A) {
9340 band |= IEEE80211_52GHZ_BAND;
9341 modulation |= IEEE80211_OFDM_MODULATION;
9342 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009343 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009344 } else {
9345 if (mode & IEEE_A) {
9346 IPW_WARNING("Attempt to set 2200BG into "
9347 "802.11a mode\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009348 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009349 return -EINVAL;
9350 }
9351
James Ketrenosa33a1982005-09-14 14:28:59 -05009352 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009353 }
9354
9355 if (mode & IEEE_B) {
9356 band |= IEEE80211_24GHZ_BAND;
9357 modulation |= IEEE80211_CCK_MODULATION;
9358 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009359 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009360
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 if (mode & IEEE_G) {
9362 band |= IEEE80211_24GHZ_BAND;
9363 modulation |= IEEE80211_OFDM_MODULATION;
9364 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009365 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009366
9367 priv->ieee->mode = mode;
9368 priv->ieee->freq_band = band;
9369 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009370 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009371
James Ketrenosc848d0a2005-08-24 21:56:24 -05009372 /* Network configuration changed -- force [re]association */
9373 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9374 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009376 ipw_associate(priv);
9377 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009378
James Ketrenosa613bff2005-08-24 21:43:11 -05009379 /* Update the band LEDs */
9380 ipw_led_band_on(priv);
9381
Jeff Garzikbf794512005-07-31 13:07:26 -04009382 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009383 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009384 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenosc848d0a2005-08-24 21:56:24 -05009385 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009386 return 0;
9387}
9388
9389static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009390 struct iw_request_info *info,
9391 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009392{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009393 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009394 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009395 switch (priv->ieee->mode) {
9396 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009397 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9398 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009399 case IEEE_B:
9400 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9401 break;
9402 case IEEE_A | IEEE_B:
9403 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9404 break;
9405 case IEEE_G:
9406 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9407 break;
9408 case IEEE_A | IEEE_G:
9409 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9410 break;
9411 case IEEE_B | IEEE_G:
9412 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9413 break;
9414 case IEEE_A | IEEE_B | IEEE_G:
9415 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9416 break;
9417 default:
9418 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009419 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009420 }
9421
James Ketrenos43f66a62005-03-25 12:31:53 -06009422 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9423
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009424 wrqu->data.length = strlen(extra) + 1;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009425 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009426
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009427 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009428}
9429
James Ketrenosea2b26e2005-08-24 21:25:16 -05009430static int ipw_wx_set_preamble(struct net_device *dev,
9431 struct iw_request_info *info,
9432 union iwreq_data *wrqu, char *extra)
9433{
9434 struct ipw_priv *priv = ieee80211_priv(dev);
9435 int mode = *(int *)extra;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009436 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009437 /* Switching from SHORT -> LONG requires a disassociation */
9438 if (mode == 1) {
9439 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9440 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009441
9442 /* Network configuration changed -- force [re]association */
9443 IPW_DEBUG_ASSOC
9444 ("[re]association triggered due to preamble change.\n");
9445 if (!ipw_disassociate(priv))
9446 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009447 }
9448 goto done;
9449 }
9450
9451 if (mode == 0) {
9452 priv->config &= ~CFG_PREAMBLE_LONG;
9453 goto done;
9454 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009455 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009456 return -EINVAL;
9457
9458 done:
James Ketrenosc848d0a2005-08-24 21:56:24 -05009459 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009460 return 0;
9461}
9462
9463static int ipw_wx_get_preamble(struct net_device *dev,
9464 struct iw_request_info *info,
9465 union iwreq_data *wrqu, char *extra)
9466{
9467 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009468 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009469 if (priv->config & CFG_PREAMBLE_LONG)
9470 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9471 else
9472 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
James Ketrenosc848d0a2005-08-24 21:56:24 -05009473 up(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009474 return 0;
9475}
9476
James Ketrenosb095c382005-08-24 22:04:42 -05009477#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009478static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009479 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009480 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009481{
James Ketrenos43f66a62005-03-25 12:31:53 -06009482 struct ipw_priv *priv = ieee80211_priv(dev);
9483 int *parms = (int *)extra;
9484 int enable = (parms[0] > 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009485 down(&priv->sem);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009486 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009487 if (enable) {
9488 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9489 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosa613bff2005-08-24 21:43:11 -05009490 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009491 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009492
James Ketrenos43f66a62005-03-25 12:31:53 -06009493 ipw_set_channel(priv, parms[1]);
9494 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009495 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9496 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009497 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009498 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009499 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009500 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009501 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05009502 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009503 return 0;
9504}
9505
James Ketrenosb095c382005-08-24 22:04:42 -05009506#endif // CONFIG_IPW2200_MONITOR
9507
Jeff Garzikbf794512005-07-31 13:07:26 -04009508static int ipw_wx_reset(struct net_device *dev,
9509 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009510 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009511{
James Ketrenos43f66a62005-03-25 12:31:53 -06009512 struct ipw_priv *priv = ieee80211_priv(dev);
9513 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009514 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009515 return 0;
9516}
James Ketrenosb095c382005-08-24 22:04:42 -05009517
James Ketrenosb095c382005-08-24 22:04:42 -05009518static int ipw_wx_sw_reset(struct net_device *dev,
9519 struct iw_request_info *info,
9520 union iwreq_data *wrqu, char *extra)
9521{
9522 struct ipw_priv *priv = ieee80211_priv(dev);
9523 union iwreq_data wrqu_sec = {
9524 .encoding = {
9525 .flags = IW_ENCODE_DISABLED,
9526 },
9527 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009528 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009529
9530 IPW_DEBUG_WX("SW_RESET\n");
9531
9532 down(&priv->sem);
9533
James Ketrenosafbf30a2005-08-25 00:05:33 -05009534 ret = ipw_sw_reset(priv, 0);
9535 if (!ret) {
9536 free_firmware();
9537 ipw_adapter_restart(priv);
9538 }
James Ketrenosb095c382005-08-24 22:04:42 -05009539
9540 /* The SW reset bit might have been toggled on by the 'disable'
9541 * module parameter, so take appropriate action */
9542 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9543
9544 up(&priv->sem);
9545 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9546 down(&priv->sem);
9547
9548 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9549 /* Configuration likely changed -- force [re]association */
9550 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9551 "reset.\n");
9552 if (!ipw_disassociate(priv))
9553 ipw_associate(priv);
9554 }
9555
9556 up(&priv->sem);
9557
9558 return 0;
9559}
James Ketrenos43f66a62005-03-25 12:31:53 -06009560
9561/* Rebase the WE IOCTLs to zero for the handler array */
9562#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009563static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009564 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9565 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9566 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9567 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9568 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9569 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9570 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9571 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9572 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9573 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9574 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9575 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9576 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9577 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9578 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9579 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9580 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9581 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9582 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9583 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9584 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9585 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9586 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9587 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9588 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9589 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9590 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9591 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009592 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9593 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9594 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9595 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009596#if WIRELESS_EXT > 17
9597 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9598 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9599 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9600 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9601 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9602 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9603 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9604#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009605};
9606
James Ketrenosb095c382005-08-24 22:04:42 -05009607enum {
9608 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9609 IPW_PRIV_GET_POWER,
9610 IPW_PRIV_SET_MODE,
9611 IPW_PRIV_GET_MODE,
9612 IPW_PRIV_SET_PREAMBLE,
9613 IPW_PRIV_GET_PREAMBLE,
9614 IPW_PRIV_RESET,
9615 IPW_PRIV_SW_RESET,
9616#ifdef CONFIG_IPW2200_MONITOR
9617 IPW_PRIV_SET_MONITOR,
9618#endif
9619};
James Ketrenos43f66a62005-03-25 12:31:53 -06009620
Jeff Garzikbf794512005-07-31 13:07:26 -04009621static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009622 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009623 .cmd = IPW_PRIV_SET_POWER,
9624 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9625 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009626 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009627 .cmd = IPW_PRIV_GET_POWER,
9628 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9629 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009630 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009631 .cmd = IPW_PRIV_SET_MODE,
9632 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9633 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009635 .cmd = IPW_PRIV_GET_MODE,
9636 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9637 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009638 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009639 .cmd = IPW_PRIV_SET_PREAMBLE,
9640 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9641 .name = "set_preamble"},
9642 {
9643 .cmd = IPW_PRIV_GET_PREAMBLE,
9644 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9645 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009646 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009647 IPW_PRIV_RESET,
9648 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009649 {
9650 IPW_PRIV_SW_RESET,
9651 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9652#ifdef CONFIG_IPW2200_MONITOR
9653 {
9654 IPW_PRIV_SET_MONITOR,
9655 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9656#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009657};
9658
9659static iw_handler ipw_priv_handler[] = {
9660 ipw_wx_set_powermode,
9661 ipw_wx_get_powermode,
9662 ipw_wx_set_wireless_mode,
9663 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009664 ipw_wx_set_preamble,
9665 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009666 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009667 ipw_wx_sw_reset,
9668#ifdef CONFIG_IPW2200_MONITOR
9669 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009670#endif
9671};
9672
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009673static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009674 .standard = ipw_wx_handlers,
9675 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9676 .num_private = ARRAY_SIZE(ipw_priv_handler),
9677 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9678 .private = ipw_priv_handler,
9679 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06009680};
9681
James Ketrenosa613bff2005-08-24 21:43:11 -05009682static struct iw_public_data ipw_wx_data;
9683
James Ketrenos43f66a62005-03-25 12:31:53 -06009684/*
9685 * Get wireless statistics.
9686 * Called by /proc/net/wireless
9687 * Also called by SIOCGIWSTATS
9688 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009689static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009690{
9691 struct ipw_priv *priv = ieee80211_priv(dev);
9692 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009693
James Ketrenos43f66a62005-03-25 12:31:53 -06009694 wstats = &priv->wstats;
9695
James Ketrenosea2b26e2005-08-24 21:25:16 -05009696 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009697 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009698 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9699 * and associated; if not associcated, the values are all meaningless
9700 * anyway, so set them all to NULL and INVALID */
9701 if (!(priv->status & STATUS_ASSOCIATED)) {
9702 wstats->miss.beacon = 0;
9703 wstats->discard.retries = 0;
9704 wstats->qual.qual = 0;
9705 wstats->qual.level = 0;
9706 wstats->qual.noise = 0;
9707 wstats->qual.updated = 7;
9708 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009709 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009710 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009711 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009712
9713 wstats->qual.qual = priv->quality;
9714 wstats->qual.level = average_value(&priv->average_rssi);
9715 wstats->qual.noise = average_value(&priv->average_noise);
9716 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009717 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06009718
9719 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9720 wstats->discard.retries = priv->last_tx_failures;
9721 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009722
James Ketrenos43f66a62005-03-25 12:31:53 -06009723/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9724 goto fail_get_ordinal;
9725 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009726
James Ketrenos43f66a62005-03-25 12:31:53 -06009727 return wstats;
9728}
9729
James Ketrenos43f66a62005-03-25 12:31:53 -06009730/* net device stuff */
9731
9732static inline void init_sys_config(struct ipw_sys_config *sys_config)
9733{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009734 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9735 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06009736 sys_config->answer_broadcast_ssid_probe = 0;
9737 sys_config->accept_all_data_frames = 0;
9738 sys_config->accept_non_directed_frames = 1;
9739 sys_config->exclude_unicast_unencrypted = 0;
9740 sys_config->disable_unicast_decryption = 1;
9741 sys_config->exclude_multicast_unencrypted = 0;
9742 sys_config->disable_multicast_decryption = 1;
9743 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009744 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009745 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009746 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009747 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009748 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009749}
9750
9751static int ipw_net_open(struct net_device *dev)
9752{
9753 struct ipw_priv *priv = ieee80211_priv(dev);
9754 IPW_DEBUG_INFO("dev->open\n");
9755 /* we should be verifying the device is ready to be opened */
James Ketrenosc848d0a2005-08-24 21:56:24 -05009756 down(&priv->sem);
Jeff Garzikbf794512005-07-31 13:07:26 -04009757 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9758 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 netif_start_queue(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009760 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -06009761 return 0;
9762}
9763
9764static int ipw_net_stop(struct net_device *dev)
9765{
9766 IPW_DEBUG_INFO("dev->close\n");
9767 netif_stop_queue(dev);
9768 return 0;
9769}
9770
9771/*
9772todo:
9773
9774modify to send one tfd per fragment instead of using chunking. otherwise
9775we need to heavily modify the ieee80211_skb_to_txb.
9776*/
9777
James Ketrenos227d2dc2005-07-28 16:25:55 -05009778static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9779 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009780{
James Ketrenos0dacca12005-09-21 12:23:41 -05009781 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009782 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009783 int i = 0;
9784 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009785#ifdef CONFIG_IPW_QOS
9786 int tx_id = ipw_get_tx_queue_number(priv, pri);
9787 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9788#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009789 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009790#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009791 struct clx2_queue *q = &txq->q;
9792 u8 id, hdr_len, unicast;
9793 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009794 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009795
James Ketrenos227d2dc2005-07-28 16:25:55 -05009796 /* If there isn't room in the queue, we return busy and let the
9797 * network stack requeue the packet for us */
9798 if (ipw_queue_space(q) < q->high_mark)
9799 return NETDEV_TX_BUSY;
9800
James Ketrenos43f66a62005-03-25 12:31:53 -06009801 switch (priv->ieee->iw_mode) {
9802 case IW_MODE_ADHOC:
9803 hdr_len = IEEE80211_3ADDR_LEN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009804 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009805 id = ipw_find_station(priv, hdr->addr1);
9806 if (id == IPW_INVALID_STATION) {
9807 id = ipw_add_station(priv, hdr->addr1);
9808 if (id == IPW_INVALID_STATION) {
9809 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009810 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009811 MAC_ARG(hdr->addr1));
9812 goto drop;
9813 }
9814 }
9815 break;
9816
9817 case IW_MODE_INFRA:
9818 default:
James Ketrenosafbf30a2005-08-25 00:05:33 -05009819 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009820 hdr_len = IEEE80211_3ADDR_LEN;
9821 id = 0;
9822 break;
9823 }
9824
9825 tfd = &txq->bd[q->first_empty];
9826 txq->txb[q->first_empty] = txb;
9827 memset(tfd, 0, sizeof(*tfd));
9828 tfd->u.data.station_number = id;
9829
9830 tfd->control_flags.message_type = TX_FRAME_TYPE;
9831 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9832
9833 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009834 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009835 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009836
James Ketrenos43f66a62005-03-25 12:31:53 -06009837 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009838 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009839 else
James Ketrenosb095c382005-08-24 22:04:42 -05009840 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009841
James Ketrenosea2b26e2005-08-24 21:25:16 -05009842 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9843 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009844
James Ketrenosc848d0a2005-08-24 21:56:24 -05009845 fc = le16_to_cpu(hdr->frame_ctl);
9846 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9847
James Ketrenos43f66a62005-03-25 12:31:53 -06009848 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9849
James Ketrenosb095c382005-08-24 22:04:42 -05009850 if (likely(unicast))
9851 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9852
9853 if (txb->encrypted && !priv->ieee->host_encrypt) {
9854 switch (priv->ieee->sec.level) {
9855 case SEC_LEVEL_3:
9856 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9857 IEEE80211_FCTL_PROTECTED;
9858 /* XXX: ACK flag must be set for CCMP even if it
9859 * is a multicast/broadcast packet, because CCMP
9860 * group communication encrypted by GTK is
9861 * actually done by the AP. */
9862 if (!unicast)
9863 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9864
9865 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9866 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9867 tfd->u.data.key_index = 0;
9868 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9869 break;
9870 case SEC_LEVEL_2:
9871 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9872 IEEE80211_FCTL_PROTECTED;
9873 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9874 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9875 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9876 break;
9877 case SEC_LEVEL_1:
9878 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9879 IEEE80211_FCTL_PROTECTED;
9880 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9881 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9882 40)
9883 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9884 else
9885 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9886 break;
9887 case SEC_LEVEL_0:
9888 break;
9889 default:
9890 printk(KERN_ERR "Unknow security level %d\n",
9891 priv->ieee->sec.level);
9892 break;
9893 }
9894 } else
9895 /* No hardware encryption */
9896 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9897
9898#ifdef CONFIG_IPW_QOS
9899 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9900#endif /* CONFIG_IPW_QOS */
9901
James Ketrenos43f66a62005-03-25 12:31:53 -06009902 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009903 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9904 txb->nr_frags));
9905 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9906 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9907 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9908 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9909 i, le32_to_cpu(tfd->u.data.num_chunks),
9910 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009911 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009912 i, tfd->u.data.num_chunks,
9913 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009914 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009915 txb->fragments[i]->len - hdr_len);
9916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009917 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009918 cpu_to_le32(pci_map_single
9919 (priv->pci_dev,
9920 txb->fragments[i]->data + hdr_len,
9921 txb->fragments[i]->len - hdr_len,
9922 PCI_DMA_TODEVICE));
9923 tfd->u.data.chunk_len[i] =
9924 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009925 }
9926
9927 if (i != txb->nr_frags) {
9928 struct sk_buff *skb;
9929 u16 remaining_bytes = 0;
9930 int j;
9931
9932 for (j = i; j < txb->nr_frags; j++)
9933 remaining_bytes += txb->fragments[j]->len - hdr_len;
9934
9935 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9936 remaining_bytes);
9937 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9938 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009939 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009940 for (j = i; j < txb->nr_frags; j++) {
9941 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009942
James Ketrenos43f66a62005-03-25 12:31:53 -06009943 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009944 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009945 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009946 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009947 }
9948 dev_kfree_skb_any(txb->fragments[i]);
9949 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009950 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009951 cpu_to_le32(pci_map_single
9952 (priv->pci_dev, skb->data,
9953 tfd->u.data.chunk_len[i],
9954 PCI_DMA_TODEVICE));
9955
9956 tfd->u.data.num_chunks =
9957 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9958 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009959 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009960 }
9961
9962 /* kick DMA */
9963 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9964 ipw_write32(priv, q->reg_w, q->first_empty);
9965
James Ketrenos227d2dc2005-07-28 16:25:55 -05009966 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009967
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009968 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009969 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9970 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009971 return NETDEV_TX_OK;
9972}
9973
9974static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9975{
9976 struct ipw_priv *priv = ieee80211_priv(dev);
9977#ifdef CONFIG_IPW_QOS
9978 int tx_id = ipw_get_tx_queue_number(priv, pri);
9979 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9980#else
9981 struct clx2_tx_queue *txq = &priv->txq[0];
9982#endif /* CONFIG_IPW_QOS */
9983
9984 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9985 return 1;
9986
9987 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009988}
9989
9990static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009991 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009992{
9993 struct ipw_priv *priv = ieee80211_priv(dev);
9994 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009995 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009996
9997 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009998 spin_lock_irqsave(&priv->lock, flags);
9999
10000 if (!(priv->status & STATUS_ASSOCIATED)) {
10001 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10002 priv->ieee->stats.tx_carrier_errors++;
10003 netif_stop_queue(dev);
10004 goto fail_unlock;
10005 }
10006
James Ketrenos227d2dc2005-07-28 16:25:55 -050010007 ret = ipw_tx_skb(priv, txb, pri);
10008 if (ret == NETDEV_TX_OK)
10009 __ipw_led_activity_on(priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010010 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010011
James Ketrenos227d2dc2005-07-28 16:25:55 -050010012 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010013
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010014 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010015 spin_unlock_irqrestore(&priv->lock, flags);
10016 return 1;
10017}
10018
10019static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10020{
10021 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010022
James Ketrenos43f66a62005-03-25 12:31:53 -060010023 priv->ieee->stats.tx_packets = priv->tx_packets;
10024 priv->ieee->stats.rx_packets = priv->rx_packets;
10025 return &priv->ieee->stats;
10026}
10027
10028static void ipw_net_set_multicast_list(struct net_device *dev)
10029{
10030
10031}
10032
10033static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10034{
10035 struct ipw_priv *priv = ieee80211_priv(dev);
10036 struct sockaddr *addr = p;
10037 if (!is_valid_ether_addr(addr->sa_data))
10038 return -EADDRNOTAVAIL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010039 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010040 priv->config |= CFG_CUSTOM_MAC;
10041 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10042 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10043 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010044 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010045 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 return 0;
10047}
10048
Jeff Garzikbf794512005-07-31 13:07:26 -040010049static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 struct ethtool_drvinfo *info)
10051{
10052 struct ipw_priv *p = ieee80211_priv(dev);
10053 char vers[64];
10054 char date[32];
10055 u32 len;
10056
10057 strcpy(info->driver, DRV_NAME);
10058 strcpy(info->version, DRV_VERSION);
10059
10060 len = sizeof(vers);
10061 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10062 len = sizeof(date);
10063 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10064
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010065 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010066 vers, date);
10067 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010068 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010069}
10070
10071static u32 ipw_ethtool_get_link(struct net_device *dev)
10072{
10073 struct ipw_priv *priv = ieee80211_priv(dev);
10074 return (priv->status & STATUS_ASSOCIATED) != 0;
10075}
10076
10077static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10078{
James Ketrenosb095c382005-08-24 22:04:42 -050010079 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010080}
10081
10082static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010083 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010084{
10085 struct ipw_priv *p = ieee80211_priv(dev);
10086
James Ketrenosb095c382005-08-24 22:04:42 -050010087 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010088 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010089 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010090 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010091 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010092 return 0;
10093}
10094
10095static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010096 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010097{
10098 struct ipw_priv *p = ieee80211_priv(dev);
10099 int i;
10100
James Ketrenosb095c382005-08-24 22:04:42 -050010101 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010102 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010103 down(&p->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010104 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010105 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -050010106 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -060010107 ipw_write8(p, i, p->eeprom[i]);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010108 up(&p->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010109 return 0;
10110}
10111
10112static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010113 .get_link = ipw_ethtool_get_link,
10114 .get_drvinfo = ipw_ethtool_get_drvinfo,
10115 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10116 .get_eeprom = ipw_ethtool_get_eeprom,
10117 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010118};
10119
10120static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10121{
10122 struct ipw_priv *priv = data;
10123 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010124
James Ketrenos43f66a62005-03-25 12:31:53 -060010125 if (!priv)
10126 return IRQ_NONE;
10127
10128 spin_lock(&priv->lock);
10129
10130 if (!(priv->status & STATUS_INT_ENABLED)) {
10131 /* Shared IRQ */
10132 goto none;
10133 }
10134
James Ketrenosb095c382005-08-24 22:04:42 -050010135 inta = ipw_read32(priv, IPW_INTA_RW);
10136 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010137
James Ketrenos43f66a62005-03-25 12:31:53 -060010138 if (inta == 0xFFFFFFFF) {
10139 /* Hardware disappeared */
10140 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10141 goto none;
10142 }
10143
James Ketrenosb095c382005-08-24 22:04:42 -050010144 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010145 /* Shared interrupt */
10146 goto none;
10147 }
10148
10149 /* tell the device to stop sending interrupts */
10150 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010151
James Ketrenos43f66a62005-03-25 12:31:53 -060010152 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010153 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10154 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010155
James Ketrenos43f66a62005-03-25 12:31:53 -060010156 /* Cache INTA value for our tasklet */
10157 priv->isr_inta = inta;
10158
10159 tasklet_schedule(&priv->irq_tasklet);
10160
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010161 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010162
10163 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010164 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010165 spin_unlock(&priv->lock);
10166 return IRQ_NONE;
10167}
10168
10169static void ipw_rf_kill(void *adapter)
10170{
10171 struct ipw_priv *priv = adapter;
10172 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010173
James Ketrenos43f66a62005-03-25 12:31:53 -060010174 spin_lock_irqsave(&priv->lock, flags);
10175
10176 if (rf_kill_active(priv)) {
10177 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10178 if (priv->workqueue)
10179 queue_delayed_work(priv->workqueue,
10180 &priv->rf_kill, 2 * HZ);
10181 goto exit_unlock;
10182 }
10183
10184 /* RF Kill is now disabled, so bring the device back up */
10185
10186 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10187 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10188 "device\n");
10189
10190 /* we can not do an adapter restart while inside an irq lock */
10191 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010192 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010193 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10194 "enabled\n");
10195
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010196 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010197 spin_unlock_irqrestore(&priv->lock, flags);
10198}
10199
James Ketrenosc848d0a2005-08-24 21:56:24 -050010200static void ipw_bg_rf_kill(void *data)
10201{
10202 struct ipw_priv *priv = data;
10203 down(&priv->sem);
10204 ipw_rf_kill(data);
10205 up(&priv->sem);
10206}
10207
James Ketrenosa613bff2005-08-24 21:43:11 -050010208void ipw_link_up(struct ipw_priv *priv)
10209{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010210 priv->last_seq_num = -1;
10211 priv->last_frag_num = -1;
10212 priv->last_packet_time = 0;
10213
James Ketrenosa613bff2005-08-24 21:43:11 -050010214 netif_carrier_on(priv->net_dev);
10215 if (netif_queue_stopped(priv->net_dev)) {
10216 IPW_DEBUG_NOTIF("waking queue\n");
10217 netif_wake_queue(priv->net_dev);
10218 } else {
10219 IPW_DEBUG_NOTIF("starting queue\n");
10220 netif_start_queue(priv->net_dev);
10221 }
10222
James Ketrenosc848d0a2005-08-24 21:56:24 -050010223 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010224 ipw_reset_stats(priv);
10225 /* Ensure the rate is updated immediately */
10226 priv->last_rate = ipw_get_current_rate(priv);
10227 ipw_gather_stats(priv);
10228 ipw_led_link_up(priv);
10229 notify_wx_assoc_event(priv);
10230
10231 if (priv->config & CFG_BACKGROUND_SCAN)
10232 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10233}
10234
James Ketrenosc848d0a2005-08-24 21:56:24 -050010235static void ipw_bg_link_up(void *data)
10236{
10237 struct ipw_priv *priv = data;
10238 down(&priv->sem);
10239 ipw_link_up(data);
10240 up(&priv->sem);
10241}
10242
James Ketrenosa613bff2005-08-24 21:43:11 -050010243void ipw_link_down(struct ipw_priv *priv)
10244{
10245 ipw_led_link_down(priv);
10246 netif_carrier_off(priv->net_dev);
10247 netif_stop_queue(priv->net_dev);
10248 notify_wx_assoc_event(priv);
10249
10250 /* Cancel any queued work ... */
10251 cancel_delayed_work(&priv->request_scan);
10252 cancel_delayed_work(&priv->adhoc_check);
10253 cancel_delayed_work(&priv->gather_stats);
10254
10255 ipw_reset_stats(priv);
10256
James Ketrenosafbf30a2005-08-25 00:05:33 -050010257 if (!(priv->status & STATUS_EXIT_PENDING)) {
10258 /* Queue up another scan... */
10259 queue_work(priv->workqueue, &priv->request_scan);
10260 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010261}
10262
James Ketrenosc848d0a2005-08-24 21:56:24 -050010263static void ipw_bg_link_down(void *data)
10264{
10265 struct ipw_priv *priv = data;
10266 down(&priv->sem);
10267 ipw_link_down(data);
10268 up(&priv->sem);
10269}
10270
James Ketrenos43f66a62005-03-25 12:31:53 -060010271static int ipw_setup_deferred_work(struct ipw_priv *priv)
10272{
10273 int ret = 0;
10274
James Ketrenos43f66a62005-03-25 12:31:53 -060010275 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010276 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010277 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010278
James Ketrenosc848d0a2005-08-24 21:56:24 -050010279 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10280 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10281 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010282 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010283 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10284 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10285 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10286 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10287 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010288 INIT_WORK(&priv->request_scan,
James Ketrenosb095c382005-08-24 22:04:42 -050010289 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010290 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010291 (void (*)(void *))ipw_bg_gather_stats, priv);
10292 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10293 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10294 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10295 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10296 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10297 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010298 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010299 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010300 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010301 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10302 priv);
10303 INIT_WORK(&priv->merge_networks,
10304 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010305
James Ketrenosb095c382005-08-24 22:04:42 -050010306#ifdef CONFIG_IPW_QOS
10307 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10308 priv);
10309#endif /* CONFIG_IPW_QOS */
10310
James Ketrenos43f66a62005-03-25 12:31:53 -060010311 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10312 ipw_irq_tasklet, (unsigned long)priv);
10313
10314 return ret;
10315}
10316
James Ketrenos43f66a62005-03-25 12:31:53 -060010317static void shim__set_security(struct net_device *dev,
10318 struct ieee80211_security *sec)
10319{
10320 struct ipw_priv *priv = ieee80211_priv(dev);
10321 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010322 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010324 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010325 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010326 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010327 priv->ieee->sec.flags &= ~(1 << i);
10328 else {
10329 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010330 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010331 priv->ieee->sec.flags |= (1 << i);
10332 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010333 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010334 } else if (sec->level != SEC_LEVEL_1)
10335 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010336 }
10337
James Ketrenosb095c382005-08-24 22:04:42 -050010338 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010339 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010340 priv->ieee->sec.active_key = sec->active_key;
10341 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010342 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010343 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010344 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010345 } else
10346 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010347
10348 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010349 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10350 priv->ieee->sec.auth_mode = sec->auth_mode;
10351 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010352 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10353 priv->capability |= CAP_SHARED_KEY;
10354 else
10355 priv->capability &= ~CAP_SHARED_KEY;
10356 priv->status |= STATUS_SECURITY_UPDATED;
10357 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010358
James Ketrenosb095c382005-08-24 22:04:42 -050010359 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10360 priv->ieee->sec.flags |= SEC_ENABLED;
10361 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010362 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010363 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010364 priv->capability |= CAP_PRIVACY_ON;
10365 else
10366 priv->capability &= ~CAP_PRIVACY_ON;
10367 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010368
10369 if (sec->flags & SEC_ENCRYPT)
10370 priv->ieee->sec.encrypt = sec->encrypt;
Jeff Garzikbf794512005-07-31 13:07:26 -040010371
James Ketrenosb095c382005-08-24 22:04:42 -050010372 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10373 priv->ieee->sec.level = sec->level;
10374 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010375 priv->status |= STATUS_SECURITY_UPDATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -050010376 }
James Ketrenosb095c382005-08-24 22:04:42 -050010377
Zhu Yi1fbfea52005-08-05 17:22:56 +080010378 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10379 ipw_set_hwcrypto_keys(priv);
10380
Jeff Garzikbf794512005-07-31 13:07:26 -040010381 /* To match current functionality of ipw2100 (which works well w/
10382 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010383 * privacy capability changes ... */
10384#if 0
10385 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010386 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010387 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010388 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010389 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010390 IPW_DEBUG_ASSOC("Disassociating due to capability "
10391 "change.\n");
10392 ipw_disassociate(priv);
10393 }
10394#endif
10395}
10396
Jeff Garzikbf794512005-07-31 13:07:26 -040010397static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010398 struct ipw_supported_rates *rates)
10399{
10400 /* TODO: Mask out rates based on priv->rates_mask */
10401
10402 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010403 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010404 switch (priv->ieee->freq_band) {
10405 case IEEE80211_52GHZ_BAND:
10406 rates->ieee_mode = IPW_A_MODE;
10407 rates->purpose = IPW_RATE_CAPABILITIES;
10408 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10409 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10410 break;
10411
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010412 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010413 rates->ieee_mode = IPW_G_MODE;
10414 rates->purpose = IPW_RATE_CAPABILITIES;
10415 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10416 IEEE80211_CCK_DEFAULT_RATES_MASK);
10417 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10418 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10419 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10420 }
10421 break;
10422 }
10423
10424 return 0;
10425}
10426
Jeff Garzikbf794512005-07-31 13:07:26 -040010427static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010428{
10429 int i;
10430 struct ipw_tx_power tx_power;
10431
10432 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
10433 memset(&tx_power, 0, sizeof(tx_power));
10434
10435 /* This is only called from ipw_up, which resets/reloads the firmware
10436 so, we don't need to first disable the card before we configure
10437 it */
10438
10439 /* configure device for 'G' band */
10440 tx_power.ieee_mode = IPW_G_MODE;
10441 tx_power.num_channels = 11;
10442 for (i = 0; i < 11; i++) {
10443 tx_power.channels_tx_power[i].channel_number = i + 1;
10444 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
10445 }
10446 if (ipw_send_tx_power(priv, &tx_power))
10447 goto error;
10448
10449 /* configure device to also handle 'B' band */
10450 tx_power.ieee_mode = IPW_B_MODE;
10451 if (ipw_send_tx_power(priv, &tx_power))
10452 goto error;
10453
10454 /* initialize adapter address */
10455 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10456 goto error;
10457
10458 /* set basic system config settings */
10459 init_sys_config(&priv->sys_config);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010460 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10461 priv->sys_config.answer_broadcast_ssid_probe = 1;
10462 else
10463 priv->sys_config.answer_broadcast_ssid_probe = 0;
10464
James Ketrenos43f66a62005-03-25 12:31:53 -060010465 if (ipw_send_system_config(priv, &priv->sys_config))
10466 goto error;
10467
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010468 init_supported_rates(priv, &priv->rates);
10469 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010470 goto error;
10471
10472 /* Set request-to-send threshold */
10473 if (priv->rts_threshold) {
10474 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10475 goto error;
10476 }
James Ketrenosb095c382005-08-24 22:04:42 -050010477#ifdef CONFIG_IPW_QOS
10478 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10479 ipw_qos_activate(priv, NULL);
10480#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010481
10482 if (ipw_set_random_seed(priv))
10483 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010484
James Ketrenos43f66a62005-03-25 12:31:53 -060010485 /* final state transition to the RUN state */
10486 if (ipw_send_host_complete(priv))
10487 goto error;
10488
10489 /* If configured to try and auto-associate, kick off a scan */
James Ketrenosb095c382005-08-24 22:04:42 -050010490 if (priv->config & CFG_ASSOCIATE)
10491 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -060010492
10493 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010494
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010495 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010496 return -EIO;
10497}
10498
James Ketrenos4f36f802005-08-03 20:36:56 -050010499/*
10500 * NOTE:
10501 *
10502 * These tables have been tested in conjunction with the
10503 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10504 *
10505 * Altering this values, using it on other hardware, or in geographies
10506 * not intended for resale of the above mentioned Intel adapters has
10507 * not been tested.
10508 *
10509 */
10510static const struct ieee80211_geo ipw_geos[] = {
10511 { /* Restricted */
10512 "---",
10513 .bg_channels = 11,
10514 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10515 {2427, 4}, {2432, 5}, {2437, 6},
10516 {2442, 7}, {2447, 8}, {2452, 9},
10517 {2457, 10}, {2462, 11}},
10518 },
10519
10520 { /* Custom US/Canada */
10521 "ZZF",
10522 .bg_channels = 11,
10523 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10524 {2427, 4}, {2432, 5}, {2437, 6},
10525 {2442, 7}, {2447, 8}, {2452, 9},
10526 {2457, 10}, {2462, 11}},
10527 .a_channels = 8,
10528 .a = {{5180, 36},
10529 {5200, 40},
10530 {5220, 44},
10531 {5240, 48},
10532 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10533 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10534 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10535 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10536 },
10537
10538 { /* Rest of World */
10539 "ZZD",
10540 .bg_channels = 13,
10541 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10542 {2427, 4}, {2432, 5}, {2437, 6},
10543 {2442, 7}, {2447, 8}, {2452, 9},
10544 {2457, 10}, {2462, 11}, {2467, 12},
10545 {2472, 13}},
10546 },
10547
10548 { /* Custom USA & Europe & High */
10549 "ZZA",
10550 .bg_channels = 11,
10551 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10552 {2427, 4}, {2432, 5}, {2437, 6},
10553 {2442, 7}, {2447, 8}, {2452, 9},
10554 {2457, 10}, {2462, 11}},
10555 .a_channels = 13,
10556 .a = {{5180, 36},
10557 {5200, 40},
10558 {5220, 44},
10559 {5240, 48},
10560 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10561 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10562 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10563 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10564 {5745, 149},
10565 {5765, 153},
10566 {5785, 157},
10567 {5805, 161},
10568 {5825, 165}},
10569 },
10570
10571 { /* Custom NA & Europe */
10572 "ZZB",
10573 .bg_channels = 11,
10574 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10575 {2427, 4}, {2432, 5}, {2437, 6},
10576 {2442, 7}, {2447, 8}, {2452, 9},
10577 {2457, 10}, {2462, 11}},
10578 .a_channels = 13,
10579 .a = {{5180, 36},
10580 {5200, 40},
10581 {5220, 44},
10582 {5240, 48},
10583 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10584 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10585 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10586 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10587 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10588 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10589 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10590 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10591 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10592 },
10593
10594 { /* Custom Japan */
10595 "ZZC",
10596 .bg_channels = 11,
10597 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10598 {2427, 4}, {2432, 5}, {2437, 6},
10599 {2442, 7}, {2447, 8}, {2452, 9},
10600 {2457, 10}, {2462, 11}},
10601 .a_channels = 4,
10602 .a = {{5170, 34}, {5190, 38},
10603 {5210, 42}, {5230, 46}},
10604 },
10605
10606 { /* Custom */
10607 "ZZM",
10608 .bg_channels = 11,
10609 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10610 {2427, 4}, {2432, 5}, {2437, 6},
10611 {2442, 7}, {2447, 8}, {2452, 9},
10612 {2457, 10}, {2462, 11}},
10613 },
10614
10615 { /* Europe */
10616 "ZZE",
10617 .bg_channels = 13,
10618 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10619 {2427, 4}, {2432, 5}, {2437, 6},
10620 {2442, 7}, {2447, 8}, {2452, 9},
10621 {2457, 10}, {2462, 11}, {2467, 12},
10622 {2472, 13}},
10623 .a_channels = 19,
10624 .a = {{5180, 36},
10625 {5200, 40},
10626 {5220, 44},
10627 {5240, 48},
10628 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10629 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10630 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10631 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10632 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10633 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10634 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10635 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10636 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10637 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10638 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10639 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10640 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10641 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10642 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10643 },
10644
10645 { /* Custom Japan */
10646 "ZZJ",
10647 .bg_channels = 14,
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}, {2467, 12},
10652 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10653 .a_channels = 4,
10654 .a = {{5170, 34}, {5190, 38},
10655 {5210, 42}, {5230, 46}},
10656 },
10657
10658 { /* High Band */
10659 "ZZH",
10660 .bg_channels = 13,
10661 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10662 {2427, 4}, {2432, 5}, {2437, 6},
10663 {2442, 7}, {2447, 8}, {2452, 9},
10664 {2457, 10}, {2462, 11},
10665 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10666 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10667 .a_channels = 4,
10668 .a = {{5745, 149}, {5765, 153},
10669 {5785, 157}, {5805, 161}},
10670 },
10671
10672 { /* Custom Europe */
10673 "ZZG",
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}, {2472, 13}},
10680 .a_channels = 4,
10681 .a = {{5180, 36}, {5200, 40},
10682 {5220, 44}, {5240, 48}},
10683 },
10684
10685 { /* Europe */
10686 "ZZK",
10687 .bg_channels = 13,
10688 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10689 {2427, 4}, {2432, 5}, {2437, 6},
10690 {2442, 7}, {2447, 8}, {2452, 9},
10691 {2457, 10}, {2462, 11},
10692 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10693 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10694 .a_channels = 24,
10695 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10696 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10697 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10698 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10699 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10700 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10701 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10702 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10703 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10704 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10705 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10706 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10707 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10708 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10709 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10710 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10711 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10712 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10713 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10714 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10715 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10716 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10717 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10718 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10719 },
10720
10721 { /* Europe */
10722 "ZZL",
10723 .bg_channels = 11,
10724 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10725 {2427, 4}, {2432, 5}, {2437, 6},
10726 {2442, 7}, {2447, 8}, {2452, 9},
10727 {2457, 10}, {2462, 11}},
10728 .a_channels = 13,
10729 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10730 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10731 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10732 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10733 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10734 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10735 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10736 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10737 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10738 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10739 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10740 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10741 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10742 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010743};
10744
James Ketrenos43f66a62005-03-25 12:31:53 -060010745#define MAX_HW_RESTARTS 5
10746static int ipw_up(struct ipw_priv *priv)
10747{
James Ketrenos4f36f802005-08-03 20:36:56 -050010748 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010749
10750 if (priv->status & STATUS_EXIT_PENDING)
10751 return -EIO;
10752
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010753 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010754 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010755 * Also start the clocks. */
10756 rc = ipw_load(priv);
10757 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010758 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010759 return rc;
10760 }
10761
10762 ipw_init_ordinals(priv);
10763 if (!(priv->config & CFG_CUSTOM_MAC))
10764 eeprom_parse_mac(priv, priv->mac_addr);
10765 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10766
James Ketrenos4f36f802005-08-03 20:36:56 -050010767 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10768 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10769 ipw_geos[j].name, 3))
10770 break;
10771 }
10772 if (j == ARRAY_SIZE(ipw_geos))
10773 j = 0;
10774 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10775 IPW_WARNING("Could not set geography.");
10776 return 0;
10777 }
10778
10779 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10780 j, priv->ieee->geo.name);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010781
James Ketrenosb095c382005-08-24 22:04:42 -050010782 if (priv->status & STATUS_RF_KILL_SW) {
10783 IPW_WARNING("Radio disabled by module parameter.\n");
10784 return 0;
10785 } else if (rf_kill_active(priv)) {
10786 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10787 "Kill switch must be turned off for "
10788 "wireless networking to work.\n");
10789 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10790 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010791 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010792 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010793
10794 rc = ipw_config(priv);
10795 if (!rc) {
10796 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosa613bff2005-08-24 21:43:11 -050010797 ipw_led_init(priv);
10798 ipw_led_radio_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010799 priv->notif_missed_beacons = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010800 priv->status |= STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010801
10802 /* Set hardware WEP key if it is configured. */
10803 if ((priv->capability & CAP_PRIVACY_ON) &&
10804 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10805 !(priv->ieee->host_encrypt ||
10806 priv->ieee->host_decrypt))
10807 ipw_set_hwcrypto_keys(priv);
10808
James Ketrenos43f66a62005-03-25 12:31:53 -060010809 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010810 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010811
James Ketrenosc848d0a2005-08-24 21:56:24 -050010812 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010813 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10814 i, MAX_HW_RESTARTS);
10815
10816 /* We had an error bringing up the hardware, so take it
10817 * all the way back down so we can try again */
10818 ipw_down(priv);
10819 }
10820
Jeff Garzikbf794512005-07-31 13:07:26 -040010821 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010822 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010823 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010824
James Ketrenos43f66a62005-03-25 12:31:53 -060010825 return -EIO;
10826}
10827
James Ketrenosc848d0a2005-08-24 21:56:24 -050010828static void ipw_bg_up(void *data)
10829{
10830 struct ipw_priv *priv = data;
10831 down(&priv->sem);
10832 ipw_up(data);
10833 up(&priv->sem);
10834}
10835
James Ketrenosb095c382005-08-24 22:04:42 -050010836static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010837{
James Ketrenosb095c382005-08-24 22:04:42 -050010838 int i;
10839
10840 if (priv->status & STATUS_SCANNING) {
10841 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10842 ipw_abort_scan(priv);
10843 }
10844
10845 if (priv->status & STATUS_ASSOCIATED) {
10846 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10847 ipw_disassociate(priv);
10848 }
10849
10850 ipw_led_shutdown(priv);
10851
10852 /* Wait up to 1s for status to change to not scanning and not
10853 * associated (disassociation can take a while for a ful 802.11
10854 * exchange */
10855 for (i = 1000; i && (priv->status &
10856 (STATUS_DISASSOCIATING |
10857 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10858 udelay(10);
10859
10860 if (priv->status & (STATUS_DISASSOCIATING |
10861 STATUS_ASSOCIATED | STATUS_SCANNING))
10862 IPW_DEBUG_INFO("Still associated or scanning...\n");
10863 else
10864 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10865
James Ketrenosc848d0a2005-08-24 21:56:24 -050010866 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010867 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010868
10869 priv->status &= ~STATUS_INIT;
10870}
10871
10872static void ipw_down(struct ipw_priv *priv)
10873{
10874 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10875
10876 priv->status |= STATUS_EXIT_PENDING;
10877
10878 if (ipw_is_init(priv))
10879 ipw_deinit(priv);
10880
10881 /* Wipe out the EXIT_PENDING status bit if we are not actually
10882 * exiting the module */
10883 if (!exit_pending)
10884 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010885
10886 /* tell the device to stop sending interrupts */
10887 ipw_disable_interrupts(priv);
10888
10889 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010890 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010891 netif_carrier_off(priv->net_dev);
10892 netif_stop_queue(priv->net_dev);
10893
10894 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010895
10896 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010897}
10898
James Ketrenosc848d0a2005-08-24 21:56:24 -050010899static void ipw_bg_down(void *data)
10900{
10901 struct ipw_priv *priv = data;
10902 down(&priv->sem);
10903 ipw_down(data);
10904 up(&priv->sem);
10905}
10906
James Ketrenosafbf30a2005-08-25 00:05:33 -050010907#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050010908static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
10909{
James Ketrenosea2b26e2005-08-24 21:25:16 -050010910 struct iwreq *wrq = (struct iwreq *)rq;
10911 int ret = -1;
10912 switch (cmd) {
10913 case IPW_IOCTL_WPA_SUPPLICANT:
10914 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
10915 return ret;
10916
10917 default:
10918 return -EOPNOTSUPP;
10919 }
10920
James Ketrenosea2b26e2005-08-24 21:25:16 -050010921 return -EOPNOTSUPP;
10922}
James Ketrenosafbf30a2005-08-25 00:05:33 -050010923#endif
James Ketrenosea2b26e2005-08-24 21:25:16 -050010924
James Ketrenos43f66a62005-03-25 12:31:53 -060010925/* Called by register_netdev() */
10926static int ipw_net_init(struct net_device *dev)
10927{
10928 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010929 down(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010930
James Ketrenosc848d0a2005-08-24 21:56:24 -050010931 if (ipw_up(priv)) {
10932 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010933 return -EIO;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010934 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010935
James Ketrenosc848d0a2005-08-24 21:56:24 -050010936 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060010937 return 0;
10938}
10939
10940/* PCI driver stuff */
10941static struct pci_device_id card_ids[] = {
10942 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10943 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10944 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10945 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10946 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10947 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10948 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10949 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10950 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10951 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10952 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10953 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10954 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10955 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10956 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10957 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10958 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10959 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010960 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010961 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010962 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10963 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010964
James Ketrenos43f66a62005-03-25 12:31:53 -060010965 /* required last entry */
10966 {0,}
10967};
10968
10969MODULE_DEVICE_TABLE(pci, card_ids);
10970
10971static struct attribute *ipw_sysfs_entries[] = {
10972 &dev_attr_rf_kill.attr,
10973 &dev_attr_direct_dword.attr,
10974 &dev_attr_indirect_byte.attr,
10975 &dev_attr_indirect_dword.attr,
10976 &dev_attr_mem_gpio_reg.attr,
10977 &dev_attr_command_event_reg.attr,
10978 &dev_attr_nic_type.attr,
10979 &dev_attr_status.attr,
10980 &dev_attr_cfg.attr,
10981 &dev_attr_dump_errors.attr,
10982 &dev_attr_dump_events.attr,
10983 &dev_attr_eeprom_delay.attr,
10984 &dev_attr_ucode_version.attr,
10985 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010986 &dev_attr_scan_age.attr,
10987 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010988 &dev_attr_speed_scan.attr,
10989 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010990 NULL
10991};
10992
10993static struct attribute_group ipw_attribute_group = {
10994 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010995 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010996};
10997
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010998static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010999{
11000 int err = 0;
11001 struct net_device *net_dev;
11002 void __iomem *base;
11003 u32 length, val;
11004 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011005 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011006
11007 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11008 if (net_dev == NULL) {
11009 err = -ENOMEM;
11010 goto out;
11011 }
11012
11013 priv = ieee80211_priv(net_dev);
11014 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011015
James Ketrenos43f66a62005-03-25 12:31:53 -060011016 priv->net_dev = net_dev;
11017 priv->pci_dev = pdev;
11018#ifdef CONFIG_IPW_DEBUG
11019 ipw_debug_level = debug;
11020#endif
11021 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011022 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11023 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011024
James Ketrenosc848d0a2005-08-24 21:56:24 -050011025 init_MUTEX(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011026 if (pci_enable_device(pdev)) {
11027 err = -ENODEV;
11028 goto out_free_ieee80211;
11029 }
11030
11031 pci_set_master(pdev);
11032
Tobias Klauser0e08b442005-06-20 14:28:41 -070011033 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011034 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011035 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011036 if (err) {
11037 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11038 goto out_pci_disable_device;
11039 }
11040
11041 pci_set_drvdata(pdev, priv);
11042
11043 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011044 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011045 goto out_pci_disable_device;
11046
Jeff Garzikbf794512005-07-31 13:07:26 -040011047 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011048 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011049 pci_read_config_dword(pdev, 0x40, &val);
11050 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011051 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011052
James Ketrenos43f66a62005-03-25 12:31:53 -060011053 length = pci_resource_len(pdev, 0);
11054 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011055
James Ketrenos43f66a62005-03-25 12:31:53 -060011056 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11057 if (!base) {
11058 err = -ENODEV;
11059 goto out_pci_release_regions;
11060 }
11061
11062 priv->hw_base = base;
11063 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11064 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11065
11066 err = ipw_setup_deferred_work(priv);
11067 if (err) {
11068 IPW_ERROR("Unable to setup deferred work\n");
11069 goto out_iounmap;
11070 }
11071
James Ketrenosb095c382005-08-24 22:04:42 -050011072 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011073
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011074 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011075 if (err) {
11076 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11077 goto out_destroy_workqueue;
11078 }
11079
11080 SET_MODULE_OWNER(net_dev);
11081 SET_NETDEV_DEV(net_dev, &pdev->dev);
11082
James Ketrenosa613bff2005-08-24 21:43:11 -050011083 ipw_wx_data.spy_data = &priv->ieee->spy_data;
11084 ipw_wx_data.ieee80211 = priv->ieee;
11085
James Ketrenosc848d0a2005-08-24 21:56:24 -050011086 down(&priv->sem);
11087
James Ketrenos43f66a62005-03-25 12:31:53 -060011088 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11089 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011090 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011091
James Ketrenosb095c382005-08-24 22:04:42 -050011092#ifdef CONFIG_IPW_QOS
James Ketrenos2b184d52005-08-03 20:33:14 -050011093 priv->ieee->handle_management = ipw_handle_management;
James Ketrenosb095c382005-08-24 22:04:42 -050011094#endif /* CONFIG_IPW_QOS */
11095
James Ketrenosc848d0a2005-08-24 21:56:24 -050011096 priv->ieee->perfect_rssi = -20;
11097 priv->ieee->worst_rssi = -85;
11098
James Ketrenos43f66a62005-03-25 12:31:53 -060011099 net_dev->open = ipw_net_open;
11100 net_dev->stop = ipw_net_stop;
11101 net_dev->init = ipw_net_init;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011102#if WIRELESS_EXT < 18
James Ketrenosea2b26e2005-08-24 21:25:16 -050011103 net_dev->do_ioctl = ipw_ioctl;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011104#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011105 net_dev->get_stats = ipw_net_get_stats;
11106 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11107 net_dev->set_mac_address = ipw_net_set_mac_address;
11108 net_dev->get_wireless_stats = ipw_get_wireless_stats;
James Ketrenosa613bff2005-08-24 21:43:11 -050011109 net_dev->wireless_data = &ipw_wx_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011110 net_dev->wireless_handlers = &ipw_wx_handler_def;
11111 net_dev->ethtool_ops = &ipw_ethtool_ops;
11112 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011113 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011114 net_dev->mem_start = pci_resource_start(pdev, 0);
11115 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11116
11117 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11118 if (err) {
11119 IPW_ERROR("failed to create sysfs device attributes\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -050011120 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011121 goto out_release_irq;
11122 }
11123
James Ketrenosc848d0a2005-08-24 21:56:24 -050011124 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011125 err = register_netdev(net_dev);
11126 if (err) {
11127 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011128 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011129 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011130 return 0;
11131
James Ketrenosa613bff2005-08-24 21:43:11 -050011132 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011133 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011134 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011135 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011136 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011137 destroy_workqueue(priv->workqueue);
11138 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011139 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011140 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011141 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011142 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011143 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011144 pci_disable_device(pdev);
11145 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011146 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011147 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011148 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011149 return err;
11150}
11151
11152static void ipw_pci_remove(struct pci_dev *pdev)
11153{
11154 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011155 struct list_head *p, *q;
11156 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011157
James Ketrenos43f66a62005-03-25 12:31:53 -060011158 if (!priv)
11159 return;
11160
James Ketrenosb095c382005-08-24 22:04:42 -050011161 down(&priv->sem);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011162
11163 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011164 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -050011165 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011166
James Ketrenosb095c382005-08-24 22:04:42 -050011167 up(&priv->sem);
James Ketrenos43f66a62005-03-25 12:31:53 -060011168
11169 unregister_netdev(priv->net_dev);
11170
11171 if (priv->rxq) {
11172 ipw_rx_queue_free(priv, priv->rxq);
11173 priv->rxq = NULL;
11174 }
11175 ipw_tx_queue_free(priv);
11176
11177 /* ipw_down will ensure that there is no more pending work
11178 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011179 cancel_delayed_work(&priv->adhoc_check);
11180 cancel_delayed_work(&priv->gather_stats);
11181 cancel_delayed_work(&priv->request_scan);
11182 cancel_delayed_work(&priv->rf_kill);
11183 cancel_delayed_work(&priv->scan_check);
11184 destroy_workqueue(priv->workqueue);
11185 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011186
James Ketrenosafbf30a2005-08-25 00:05:33 -050011187 /* Free MAC hash list for ADHOC */
11188 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11189 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11190 kfree(list_entry(p, struct ipw_ibss_seq, list));
11191 list_del(p);
11192 }
11193 }
11194
James Ketrenos43f66a62005-03-25 12:31:53 -060011195 free_irq(pdev->irq, priv);
11196 iounmap(priv->hw_base);
11197 pci_release_regions(pdev);
11198 pci_disable_device(pdev);
11199 pci_set_drvdata(pdev, NULL);
11200 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011201 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011202}
11203
James Ketrenos43f66a62005-03-25 12:31:53 -060011204#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011205static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011206{
11207 struct ipw_priv *priv = pci_get_drvdata(pdev);
11208 struct net_device *dev = priv->net_dev;
11209
11210 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11211
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011212 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011213 ipw_down(priv);
11214
11215 /* Remove the PRESENT state of the device */
11216 netif_device_detach(dev);
11217
James Ketrenos43f66a62005-03-25 12:31:53 -060011218 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011219 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011220 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011221
James Ketrenos43f66a62005-03-25 12:31:53 -060011222 return 0;
11223}
11224
11225static int ipw_pci_resume(struct pci_dev *pdev)
11226{
11227 struct ipw_priv *priv = pci_get_drvdata(pdev);
11228 struct net_device *dev = priv->net_dev;
11229 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011230
James Ketrenos43f66a62005-03-25 12:31:53 -060011231 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11232
James Ketrenosea2b26e2005-08-24 21:25:16 -050011233 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011234 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011235 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011236
James Ketrenos43f66a62005-03-25 12:31:53 -060011237 /*
11238 * Suspend/Resume resets the PCI configuration space, so we have to
11239 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11240 * from interfering with C3 CPU state. pci_restore_state won't help
11241 * here since it only restores the first 64 bytes pci config header.
11242 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011243 pci_read_config_dword(pdev, 0x40, &val);
11244 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011245 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11246
11247 /* Set the device back into the PRESENT state; this will also wake
11248 * the queue of needed */
11249 netif_device_attach(dev);
11250
11251 /* Bring the device back up */
11252 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011253
James Ketrenos43f66a62005-03-25 12:31:53 -060011254 return 0;
11255}
11256#endif
11257
11258/* driver initialization stuff */
11259static struct pci_driver ipw_driver = {
11260 .name = DRV_NAME,
11261 .id_table = card_ids,
11262 .probe = ipw_pci_probe,
11263 .remove = __devexit_p(ipw_pci_remove),
11264#ifdef CONFIG_PM
11265 .suspend = ipw_pci_suspend,
11266 .resume = ipw_pci_resume,
11267#endif
11268};
11269
11270static int __init ipw_init(void)
11271{
11272 int ret;
11273
11274 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11275 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11276
11277 ret = pci_module_init(&ipw_driver);
11278 if (ret) {
11279 IPW_ERROR("Unable to initialize PCI module\n");
11280 return ret;
11281 }
11282
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011283 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011284 if (ret) {
11285 IPW_ERROR("Unable to create driver sysfs file\n");
11286 pci_unregister_driver(&ipw_driver);
11287 return ret;
11288 }
11289
11290 return ret;
11291}
11292
11293static void __exit ipw_exit(void)
11294{
11295 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11296 pci_unregister_driver(&ipw_driver);
11297}
11298
11299module_param(disable, int, 0444);
11300MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11301
11302module_param(associate, int, 0444);
11303MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11304
11305module_param(auto_create, int, 0444);
11306MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11307
James Ketrenosa613bff2005-08-24 21:43:11 -050011308module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011309MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011310
James Ketrenos43f66a62005-03-25 12:31:53 -060011311module_param(debug, int, 0444);
11312MODULE_PARM_DESC(debug, "debug output mask");
11313
11314module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011315MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011316
James Ketrenosb095c382005-08-24 22:04:42 -050011317#ifdef CONFIG_IPW_QOS
11318module_param(qos_enable, int, 0444);
11319MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11320
11321module_param(qos_burst_enable, int, 0444);
11322MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11323
11324module_param(qos_no_ack_mask, int, 0444);
11325MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11326
11327module_param(burst_duration_CCK, int, 0444);
11328MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11329
11330module_param(burst_duration_OFDM, int, 0444);
11331MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11332#endif /* CONFIG_IPW_QOS */
11333
11334#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011335module_param(mode, int, 0444);
11336MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11337#else
11338module_param(mode, int, 0444);
11339MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11340#endif
11341
James Ketrenosb095c382005-08-24 22:04:42 -050011342module_param(hwcrypto, int, 0444);
11343MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11344
James Ketrenos43f66a62005-03-25 12:31:53 -060011345module_exit(ipw_exit);
11346module_init(ipw_init);